climateinteractive / SDEverywhere

SDEverywhere translates System Dynamics models from Vensim to C, JavaScript, and WebAssembly
http://sdeverywhere.org/
MIT License
54 stars 21 forks source link

Allow for overriding constants at runtime #470

Open chrispcampbell opened 2 months ago

chrispcampbell commented 2 months ago

To enable rapid prototyping and calibration of our models, we would like to have:

The first one can be implemented similar to how I added support for capturing any variable as an output at runtime (see #105), i.e., generate a big switch statement that allows for overriding any constant value (referenced by "variable index").

The second one can also be implemented in a similar way. I prototyped this in my work-in-progress "generate JS" branch because I needed it for a small model we were working on. I believe that @ToddFincannonEI already has a related branch, so we should put our heads together on this.

I'm lumping these two things together into one feature because we will need to touch the same parts of the compile and runtime package, and it should be easier to implement them together instead of separately.

This will require changes to the code generation phase of the compiler, and will also require improvements and refactoring in the runtime packages.

chrispcampbell commented 2 months ago

I started working on this but realized that it would be better if we divided the work into a few distinct parts, so I changed the focus of this issue to be on the first part only (overriding constants at runtime), and then filed two new issues:

I will come back to this issue once #471 is complete, and then after this issue is finished, it will be more straightforward to work on #472.