Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split initialization results in duplicate declarations #115

Closed
ToddFincannon opened this issue Sep 17, 2021 · 1 comment · Fixed by #116 or #190
Closed

Split initialization results in duplicate declarations #115

ToddFincannon opened this issue Sep 17, 2021 · 1 comment · Fixed by #116 or #190
Assignees
Labels
Milestone

Comments

@ToddFincannon
Copy link
Collaborator

When some variable subcripts are ready from a data file but other are initialized from a constant, usually as a shortcut override, SDEverywhere generates two declarations for the same array variable. For instance, in this model:

DimA: A1, A2 ~~|
DimB: B1, B2 ~~|

h[A1, DimB] = GET DIRECT DATA('e_data.csv', ',', 'A', 'B2') ~~|
h[A2, DimB] = 0 ~~|
i[DimA, DimB] = h[DimA, DimB] ~~|

INITIAL TIME = 1990 ~~|
FINAL TIME = 2050 ~~|
TIME STEP = 1 ~~|
SAVEPER = TIME STEP ~~|

h is initialized both from direct data as a lookup and from a constant. SDEverywhere generates two declarations:

Lookup* _h[2][2];
double _h[2][2];
@ToddFincannon ToddFincannon added this to the 0.6.0 milestone Sep 17, 2021
@ToddFincannon ToddFincannon self-assigned this Sep 17, 2021
@ToddFincannon
Copy link
Collaborator Author

All subscript range elements need to be set to a variable of the same type to collapse the C decl to a single declaration of a single type. To do this, convert constant elements to lookups over the entire x axis. A new test case along the lines shown above was added to directdata.mdl.

The h[A2, DimB] = 0 equation starts out as two separated const variables. A new function at the very end of the analysis stage checks for const vars with the same var name as data vars. The var type is changed to data and lookup points are added. Because the separated array vars now all have type "data", they result in a single lookup array decl.

In EquationGen, the present of the lookup points triggers special code generation, resulting in this code in initLookups:

for (size_t i = 0; i < 2; i++) {
  _h[1][i] = __new_lookup(2, /*copy=*/true, (double[]){ -1e+308, 0.0, 1e+308, 0.0 });;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment