You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue only applies to the runModelWithBuffers entrypoint that is used by the @sdeverywhere/runtime package.
The problem is that some (many?) Vensim models have SAVEPER set to TIME STEP rather than a constant value (typically 1). In the case where it's a constant, then there's no problem. But when it is set to TIME STEP, then it is treated like any other "aux" variable, which means its value isn't computed in initConstants but rather in evalAux. But we have code that initializes numSavePoints before that first call to evalAux, which means that it's getting set to the wrong value for the initial model run, which causes incorrect outputs.
The fix (for now) is to move the initialization of this value to just after the first evalAux:
while (step <= lastStep) {
evalAux();
if (fmod(_time, _saveper) <1e-6) {
// Note that many Vensim models set `SAVEPER = TIME STEP`, in which case SDE// treats `SAVEPER` as an aux rather than a constant. Therefore, we need to// initialize `numSavePoints` here, after the first `evalAux` call, to be// certain that `_saveper` has been initialized before it is used.if (numSavePoints==0) {
numSavePoints= (size_t)(round((_final_time-_initial_time) / _saveper)) +1;
}
outputVarIndex=0;
storeOutputData();
savePointIndex++;
}
I won't be including a test case for this with this PR but tests that exercise this case will be added soon (as part of a set of integration tests that exercise the runtime and runtime-async packages).
The text was updated successfully, but these errors were encountered:
This issue only applies to the
runModelWithBuffers
entrypoint that is used by the@sdeverywhere/runtime
package.The problem is that some (many?) Vensim models have
SAVEPER
set toTIME STEP
rather than a constant value (typically 1). In the case where it's a constant, then there's no problem. But when it is set toTIME STEP
, then it is treated like any other "aux" variable, which means its value isn't computed ininitConstants
but rather inevalAux
. But we have code that initializesnumSavePoints
before that first call toevalAux
, which means that it's getting set to the wrong value for the initial model run, which causes incorrect outputs.The fix (for now) is to move the initialization of this value to just after the first
evalAux
:I won't be including a test case for this with this PR but tests that exercise this case will be added soon (as part of a set of integration tests that exercise the runtime and runtime-async packages).
The text was updated successfully, but these errors were encountered: