diff --git a/models/vector/vector.dat b/models/vector/vector.dat index 8c865ab1..d944904d 100644 --- a/models/vector/vector.dat +++ b/models/vector/vector.dat @@ -192,3 +192,12 @@ x[four] 0 4 x[five] 0 5 +y[A1] +0 3 +1 3 +y[A2] +0 4 +1 4 +y[A3] +0 5 +1 5 diff --git a/models/vector/vector.mdl b/models/vector/vector.mdl index b4440c0e..2fd118c7 100644 --- a/models/vector/vector.mdl +++ b/models/vector/vector.mdl @@ -46,7 +46,33 @@ v = VMAX(x[SubX!]) ~~| w = VMIN(x[DimX!]) ~~| x[DimX] = 1, 2, 3, 4, 5 ~~| +y[DimA] = VECTOR ELM MAP(x[three], (DimA - 1)) ~~| + INITIAL TIME = 0 ~~| FINAL TIME = 1 ~~| TIME STEP = 1 ~~| SAVEPER = TIME STEP ~~| + +\\\---/// Sketch information - do not modify anything except names +V300 Do not put anything below this section - it will be ignored +*View 1 +$0-0-0,0,|0||0-0-0|0-0-0|0-0-0|0-0-0|0-0-0|0,0,100,0 +///---\\\ +:L<%^E!@ +9:vector +15:0,0,0,0,0,0 +19:100,0 +27:2, +34:0, +5:FINAL TIME +35:Date +36:YYYY-MM-DD +37:2000 +38:1 +39:1 +40:2 +41:0 +42:1 +24:0 +25:0 +26:0 diff --git a/models/vector/vector_vars.txt b/models/vector/vector_vars.txt index e5bbfa99..002bedf2 100644 --- a/models/vector/vector_vars.txt +++ b/models/vector/vector_vars.txt @@ -1,107 +1,10 @@ -_dima: -{ modelName: 'DimA', - modelValue: [ 'A1', 'A2', 'A3' ], - modelMappings: [], - name: '_dima', - value: [ '_a1', '_a2', '_a3' ], - size: 3, - family: '_dima', - mappings: {} } - -_dimb: -{ modelName: 'DimB', - modelValue: [ 'B1', 'B2' ], - modelMappings: [], - name: '_dimb', - value: [ '_b1', '_b2' ], - size: 2, - family: '_dimb', - mappings: {} } - -_dimx: -{ modelName: 'DimX', - modelValue: [ 'one', 'two', 'three', 'four', 'five' ], - modelMappings: [], - name: '_dimx', - value: [ '_one', '_two', '_three', '_four', '_five' ], - size: 5, - family: '_dimx', - mappings: {} } - -_subx: -{ modelName: 'SubX', - modelValue: [ 'two', 'three', 'four' ], - modelMappings: [], - name: '_subx', - value: [ '_two', '_three', '_four' ], - size: 3, - family: '_dimx', - mappings: {} } - -_a1: -{ name: '_a1', value: 0, size: 1, family: '_dima', mappings: {} } - -_a2: -{ name: '_a2', value: 1, size: 1, family: '_dima', mappings: {} } - -_a3: -{ name: '_a3', value: 2, size: 1, family: '_dima', mappings: {} } - -_b1: -{ name: '_b1', value: 0, size: 1, family: '_dimb', mappings: {} } - -_b2: -{ name: '_b2', value: 1, size: 1, family: '_dimb', mappings: {} } - -_one: -{ name: '_one', value: 0, size: 1, family: '_dimx', mappings: {} } - -_two: -{ name: '_two', value: 1, size: 1, family: '_dimx', mappings: {} } - -_three: -{ name: '_three', - value: 2, - size: 1, - family: '_dimx', - mappings: {} } - -_four: -{ name: '_four', value: 3, size: 1, family: '_dimx', mappings: {} } - -_five: -{ name: '_five', value: 4, size: 1, family: '_dimx', mappings: {} } - -ASCENDING: const -= 1 -refId(_ascending) - -DESCENDING: const -= 0 -refId(_descending) - -VSSUM: const -= 0 -refId(_vssum) - -VSMAX: const -= 3 -refId(_vsmax) - -VSERRNONE: const -= 0 -refId(_vserrnone) - -VSERRATLEASTONE: const -= 1 -refId(_vserratleastone) - a[DimA]: const (non-apply-to-all) = 0,1,1 refId(_a[_a1]) families(_dima) subscripts(_a1) separationDims(_dima) +hasInitValue(false) a[DimA]: const (non-apply-to-all) = 0,1,1 @@ -109,6 +12,7 @@ refId(_a[_a2]) families(_dima) subscripts(_a2) separationDims(_dima) +hasInitValue(false) a[DimA]: const (non-apply-to-all) = 0,1,1 @@ -116,6 +20,12 @@ refId(_a[_a3]) families(_dima) subscripts(_a3) separationDims(_dima) +hasInitValue(false) + +ASCENDING: const += 1 +refId(_ascending) +hasInitValue(false) b[DimB]: const (non-apply-to-all) = 1,2 @@ -123,6 +33,7 @@ refId(_b[_b1]) families(_dimb) subscripts(_b1) separationDims(_dimb) +hasInitValue(false) b[DimB]: const (non-apply-to-all) = 1,2 @@ -130,96 +41,125 @@ refId(_b[_b2]) families(_dimb) subscripts(_b2) separationDims(_dimb) +hasInitValue(false) c[DimA]: aux = 10+VECTOR ELM MAP(b[B1],a[DimA]) refId(_c) families(_dima) subscripts(_dima) +hasInitValue(false) +refs(_b[_b1], _a[_a1], _a[_a2], _a[_a3]) d[A1,B1]: const (non-apply-to-all) = 1 refId(_d[_a1,_b1]) families(_dima, _dimb) subscripts(_a1, _b1) - -d[A2,B1]: const (non-apply-to-all) -= 2 -refId(_d[_a2,_b1]) -families(_dima, _dimb) -subscripts(_a2, _b1) - -d[A3,B1]: const (non-apply-to-all) -= 3 -refId(_d[_a3,_b1]) -families(_dima, _dimb) -subscripts(_a3, _b1) +hasInitValue(false) d[A1,B2]: const (non-apply-to-all) = 4 refId(_d[_a1,_b2]) families(_dima, _dimb) subscripts(_a1, _b2) +hasInitValue(false) + +d[A2,B1]: const (non-apply-to-all) += 2 +refId(_d[_a2,_b1]) +families(_dima, _dimb) +subscripts(_a2, _b1) +hasInitValue(false) d[A2,B2]: const (non-apply-to-all) = 5 refId(_d[_a2,_b2]) families(_dima, _dimb) subscripts(_a2, _b2) +hasInitValue(false) + +d[A3,B1]: const (non-apply-to-all) += 3 +refId(_d[_a3,_b1]) +families(_dima, _dimb) +subscripts(_a3, _b1) +hasInitValue(false) d[A3,B2]: const (non-apply-to-all) = 6 refId(_d[_a3,_b2]) families(_dima, _dimb) subscripts(_a3, _b2) +hasInitValue(false) + +DESCENDING: const += 0 +refId(_descending) +hasInitValue(false) e[A1,B1]: const (non-apply-to-all) = 0 refId(_e[_a1,_b1]) families(_dima, _dimb) subscripts(_a1, _b1) - -e[A2,B1]: const (non-apply-to-all) -= 1 -refId(_e[_a2,_b1]) -families(_dima, _dimb) -subscripts(_a2, _b1) - -e[A3,B1]: const (non-apply-to-all) -= 0 -refId(_e[_a3,_b1]) -families(_dima, _dimb) -subscripts(_a3, _b1) +hasInitValue(false) e[A1,B2]: const (non-apply-to-all) = 1 refId(_e[_a1,_b2]) families(_dima, _dimb) subscripts(_a1, _b2) +hasInitValue(false) + +e[A2,B1]: const (non-apply-to-all) += 1 +refId(_e[_a2,_b1]) +families(_dima, _dimb) +subscripts(_a2, _b1) +hasInitValue(false) e[A2,B2]: const (non-apply-to-all) = 0 refId(_e[_a2,_b2]) families(_dima, _dimb) subscripts(_a2, _b2) +hasInitValue(false) + +e[A3,B1]: const (non-apply-to-all) += 0 +refId(_e[_a3,_b1]) +families(_dima, _dimb) +subscripts(_a3, _b1) +hasInitValue(false) e[A3,B2]: const (non-apply-to-all) = 1 refId(_e[_a3,_b2]) families(_dima, _dimb) subscripts(_a3, _b2) +hasInitValue(false) f[DimA,DimB]: aux = VECTOR ELM MAP(d[DimA,B1],a[DimA]) refId(_f) families(_dima, _dimb) subscripts(_dima, _dimb) +hasInitValue(false) +refs(_d[_a1,_b1], _d[_a2,_b1], _d[_a3,_b1], _a[_a1], _a[_a2], _a[_a3]) + +FINAL TIME: const += 1 +refId(_final_time) +hasInitValue(false) g[DimA,DimB]: aux = VECTOR ELM MAP(d[DimA,B1],e[DimA,DimB]) refId(_g) families(_dima, _dimb) subscripts(_dima, _dimb) +hasInitValue(false) +refs(_d[_a1,_b1], _d[_a2,_b1], _d[_a3,_b1], _e[_a1,_b1], _e[_a1,_b2], _e[_a2,_b1], _e[_a2,_b2], _e[_a3,_b1], _e[_a3,_b2]) h[DimA]: const (non-apply-to-all) = 2100,2010,2020 @@ -227,6 +167,7 @@ refId(_h[_a1]) families(_dima) subscripts(_a1) separationDims(_dima) +hasInitValue(false) h[DimA]: const (non-apply-to-all) = 2100,2010,2020 @@ -234,6 +175,7 @@ refId(_h[_a2]) families(_dima) subscripts(_a2) separationDims(_dima) +hasInitValue(false) h[DimA]: const (non-apply-to-all) = 2100,2010,2020 @@ -241,145 +183,202 @@ refId(_h[_a3]) families(_dima) subscripts(_a3) separationDims(_dima) +hasInitValue(false) + +INITIAL TIME: const += 0 +refId(_initial_time) +hasInitValue(false) l[DimA]: aux = VECTOR SORT ORDER(h[DimA],ASCENDING) refId(_l) families(_dima) subscripts(_dima) +hasInitValue(false) +refs(_h[_a1], _h[_a2], _h[_a3], _ascending) m[DimA]: aux = VECTOR SORT ORDER(h[DimA],0) refId(_m) families(_dima) subscripts(_dima) +hasInitValue(false) +refs(_h[_a1], _h[_a2], _h[_a3]) o[A1,B1]: const (non-apply-to-all) = 1 refId(_o[_a1,_b1]) families(_dima, _dimb) subscripts(_a1, _b1) +hasInitValue(false) o[A1,B2]: const (non-apply-to-all) = 2 refId(_o[_a1,_b2]) families(_dima, _dimb) subscripts(_a1, _b2) +hasInitValue(false) o[A2,B1]: const (non-apply-to-all) = 4 refId(_o[_a2,_b1]) families(_dima, _dimb) subscripts(_a2, _b1) +hasInitValue(false) o[A2,B2]: const (non-apply-to-all) = 3 refId(_o[_a2,_b2]) families(_dima, _dimb) subscripts(_a2, _b2) +hasInitValue(false) o[A3,B1]: const (non-apply-to-all) = 5 refId(_o[_a3,_b1]) families(_dima, _dimb) subscripts(_a3, _b1) +hasInitValue(false) o[A3,B2]: const (non-apply-to-all) = 5 refId(_o[_a3,_b2]) families(_dima, _dimb) subscripts(_a3, _b2) +hasInitValue(false) p[DimA,DimB]: aux = VECTOR SORT ORDER(o[DimA,DimB],ASCENDING) refId(_p) families(_dima, _dimb) subscripts(_dima, _dimb) +hasInitValue(false) +refs(_o[_a1,_b1], _o[_a1,_b2], _o[_a2,_b1], _o[_a2,_b2], _o[_a3,_b1], _o[_a3,_b2], _ascending) q[DimB]: aux = VECTOR SELECT(e[DimA!,DimB],c[DimA!],0,VSSUM,VSERRNONE) refId(_q) families(_dimb) subscripts(_dimb) -refs(_c) +hasInitValue(false) +refs(_e[_a1,_b1], _e[_a1,_b2], _e[_a2,_b1], _e[_a2,_b2], _e[_a3,_b1], _e[_a3,_b2], _c, _vssum, _vserrnone) r[DimA]: aux = VECTOR SELECT(e[DimA,DimB!],d[DimA,DimB!],:NA:,VSMAX,VSERRNONE) refId(_r) families(_dima) subscripts(_dima) +hasInitValue(false) +refs(_e[_a1,_b1], _e[_a1,_b2], _e[_a2,_b1], _e[_a2,_b2], _e[_a3,_b1], _e[_a3,_b2], _d[_a1,_b1], _d[_a1,_b2], _d[_a2,_b1], _d[_a2,_b2], _d[_a3,_b1], _d[_a3,_b2], _vsmax, _vserrnone) s[DimB]: aux = SUM(c[DimA!]*e[DimA!,DimB]) refId(_s) families(_dimb) subscripts(_dimb) -refs(_c) +hasInitValue(false) +refs(_c, _e[_a1,_b1], _e[_a1,_b2], _e[_a2,_b1], _e[_a2,_b2], _e[_a3,_b1], _e[_a3,_b2]) + +SAVEPER: aux += TIME STEP +refId(_saveper) +hasInitValue(false) +refs(_time_step) + +Time: const += +refId(_time) +hasInitValue(false) + +TIME STEP: const += 1 +refId(_time_step) +hasInitValue(false) u: aux = VMAX(x[DimX!]) refId(_u) +hasInitValue(false) +refs(_x[_five], _x[_four], _x[_one], _x[_three], _x[_two]) v: aux = VMAX(x[SubX!]) refId(_v) +hasInitValue(false) +refs(_x[_four], _x[_three], _x[_two]) + +VSERRATLEASTONE: const += 1 +refId(_vserratleastone) +hasInitValue(false) + +VSERRNONE: const += 0 +refId(_vserrnone) +hasInitValue(false) + +VSMAX: const += 3 +refId(_vsmax) +hasInitValue(false) + +VSSUM: const += 0 +refId(_vssum) +hasInitValue(false) w: aux = VMIN(x[DimX!]) refId(_w) +hasInitValue(false) +refs(_x[_five], _x[_four], _x[_one], _x[_three], _x[_two]) x[DimX]: const (non-apply-to-all) = 1,2,3,4,5 -refId(_x[_one]) +refId(_x[_five]) families(_dimx) -subscripts(_one) +subscripts(_five) separationDims(_dimx) +hasInitValue(false) x[DimX]: const (non-apply-to-all) = 1,2,3,4,5 -refId(_x[_two]) +refId(_x[_four]) families(_dimx) -subscripts(_two) +subscripts(_four) separationDims(_dimx) +hasInitValue(false) x[DimX]: const (non-apply-to-all) = 1,2,3,4,5 -refId(_x[_three]) +refId(_x[_one]) families(_dimx) -subscripts(_three) +subscripts(_one) separationDims(_dimx) +hasInitValue(false) x[DimX]: const (non-apply-to-all) = 1,2,3,4,5 -refId(_x[_four]) +refId(_x[_three]) families(_dimx) -subscripts(_four) +subscripts(_three) separationDims(_dimx) +hasInitValue(false) x[DimX]: const (non-apply-to-all) = 1,2,3,4,5 -refId(_x[_five]) +refId(_x[_two]) families(_dimx) -subscripts(_five) +subscripts(_two) separationDims(_dimx) +hasInitValue(false) -INITIAL TIME: const -= 0 -refId(_initial_time) - -FINAL TIME: const -= 1 -refId(_final_time) - -TIME STEP: const -= 1 -refId(_time_step) - -SAVEPER: aux -= TIME STEP -refId(_saveper) - -Time: const -= -refId(_time) +y[DimA]: aux += VECTOR ELM MAP(x[three],(DimA-1)) +refId(_y) +families(_dima) +subscripts(_dima) +hasInitValue(false) +refs(_x[_three]) diff --git a/src/EquationGen.js b/src/EquationGen.js index 43de4c9b..0b3ef0eb 100644 --- a/src/EquationGen.js +++ b/src/EquationGen.js @@ -161,6 +161,9 @@ export default class EquationGen extends ModelReader { if (this.currentArrayFunctionName) { // Emit code to the array function code buffer if we are in an array function. this.arrayFunctionCode += text + } else if (this.argIndexForFunctionName('_VECTOR_ELM_MAP') === 1) { + // Emit expression code in the second argument of VECTOR ELM MAP to vemOffset. + this.vemOffset += text } else { // Otherwise emit code to the expression code channel. this.exprCode += text @@ -299,7 +302,7 @@ export default class EquationGen extends ModelReader { let cSubscripts = R.map(rhsSub => { if (isIndex(rhsSub)) { // Emit the index vemOffset from VECTOR ELM MAP for the index subscript. - return `[${this.vemIndexDim}[${this.vemIndexBase} + ${this.vemOffset}]]` + return `[${this.vemIndexDim}[(size_t)(${this.vemIndexBase} + ${this.vemOffset})]]` } else { let i = this.loopIndexVars.index(rhsSub) return `[${rhsSub}[${i}]]` @@ -694,8 +697,8 @@ export default class EquationGen extends ModelReader { } } else if (fn === '_VECTOR_ELM_MAP') { super.visitCall(ctx) - this.emit(`${this.vemVarName}${this.vemSubscriptGen()}`) this.callStack.pop() + this.emit(`${this.vemVarName}${this.vemSubscriptGen()}`) this.vemVarName = '' this.vemSubscripts = [] this.vemIndexDim = '' @@ -933,7 +936,7 @@ export default class EquationGen extends ModelReader { } } else if (this.currentFunctionName() === '_VECTOR_ELM_MAP') { if (this.argIndexForFunctionName('_VECTOR_ELM_MAP') === 1) { - this.vemOffset = `(size_t)${this.currentVarName()}` + this.vemOffset = this.currentVarName() } super.visitVar(ctx) } else if (this.currentFunctionName() === '_VECTOR_SORT_ORDER') {