Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions models/arrays_cname/arrays_cname.dat
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,24 @@ s3iii[A1,B1,C1]
SAVEPER
0 1
1 1
sc[C1,C1]
0 11
sc[C1,C2]
0 12
sc[C1,C3]
0 13
sc[C2,C1]
0 21
sc[C2,C2]
0 22
sc[C2,C3]
0 23
sc[C3,C1]
0 31
sc[C3,C2]
0 32
sc[C3,C3]
0 33
t[A2]
0 1
t[A3]
Expand Down
9 changes: 9 additions & 0 deletions models/arrays_cname/arrays_cname.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
DimA: A1, A2, A3 -> DimB ~~|
DimB: B1, B2, B3 ~~|
DimC: C1, C2, C3 ~~|
DimC': DimC ~~|
DimD: D1, D2, D3, D4 ~~|
SubA: A2, A3 ~~|
DimX: SubA, A1 ~~|
Expand Down Expand Up @@ -93,6 +94,14 @@ s[DimA,DimD]=
~ 2D constant array
|

sc[DimC,DimC']=
11,12,13;
21,22,23;
31,32,33;
~
~ 2D constant array where dimensions have matching subscript names
|

s1d[DimA] = 1 ~~|
s1i[A1] = 1 ~~|

Expand Down
32 changes: 31 additions & 1 deletion models/arrays_cname/arrays_cname_spec.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
{
"name": "Arrays test model (where the spec file contains C names with numeric subscript indices)",
"inputVars": ["_inputa[0]", "_inputa[1]", "_inputa[2]"],
"outputVars": ["_time", "_a[0]", "_a[1]", "_a[2]", "_f[0][0]", "_f[0][1]", "_f[0][2]", "_h"]
"outputVars": [
"_time",
"_a[0]",
"_a[1]",
"_a[2]",
"_f[0][0]",
"_f[0][1]",
"_f[0][2]",
"_h",
"_s[0][0]",
"_s[0][1]",
"_s[0][2]",
"_s[0][3]",
"_s[1][0]",
"_s[1][1]",
"_s[1][2]",
"_s[1][3]",
"_s[2][0]",
"_s[2][1]",
"_s[2][2]",
"_s[2][3]",
"_sc[0][0]",
"_sc[0][1]",
"_sc[0][2]",
"_sc[1][0]",
"_sc[1][1]",
"_sc[1][2]",
"_sc[2][0]",
"_sc[2][1]",
"_sc[2][2]"
]
}
23 changes: 11 additions & 12 deletions src/EquationGen.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,18 +958,17 @@ export default class EquationGen extends ModelReader {
modelLHSReader.read(this.var.modelLHS)
let cNames = modelLHSReader.names().map(Model.cName)
// Visit dims in normal order. Find the ind in the dim. Compose the C array expression with numeric indices.
for (let dim of this.var.separationDims) {
let sepDim = sub(dim)
for (let ind of this.var.subscripts) {
let i = sepDim.value.indexOf(ind)
if (i >= 0) {
let indexNum = sub(ind).value
if (!cVarName) {
cVarName = `${this.var.varName}[${indexNum}]`
} else {
cVarName += `[${indexNum}]`
}
break
for (let i = 0; i < this.var.separationDims.length; i++) {
const dim = this.var.separationDims[i]
const sepDim = sub(dim)
const ind = this.var.subscripts[i]
const j = sepDim.value.indexOf(ind)
if (j >= 0) {
const indexNum = sub(ind).value
if (!cVarName) {
cVarName = `${this.var.varName}[${indexNum}]`
} else {
cVarName += `[${indexNum}]`
}
}
}
Expand Down