The Challenge
Posted by Hannah Rolston in the InsightMaker Forum referring to https://insightmaker.com/insight/67206/CSTRs-in-series
Predict the outflow of the last Continuous stirred-tank reactor (CSTR) in a series of N by only modeling the process of a single one (https://en.wikipedia.org/wiki/Continuous_stirred-tank_reactor).
The Process
A fluid is fed into a [CSTR] and after a given amount of time (p) the mix is fed into the next [CSTR]:
[Feed] = [C_in]{ Time() / TimeStep() + 1}
Where,
For the nth CSTR, [C_in] is the list/array/vector of the upstream (n-1) [CSTR]
Time() / TimeStep() + 1 is the indices for a given step in the simulation (note that in insightMaker, the first element of a vector has an index of 1, not 0 like for javascript arrays)
The first [CSTR] has an initial quantity [Initial CSTR], while the downstream ones are empty [CSTR]=0, initially.
The Model
The idea is to model a single CSTR and run the simulation N times, ensuring that [C_in] contains the time series for [CSTR] from the previous simulation run.
This is done using javascript to call the insightMaker API functions. The script is in the button [Simulate Recursively] (https://insightmaker.com/sites/default/files/API/files/API-js.html)
We use the following API functions
Caveats, Tips & Tricks
In javascript, an array looks like [0.3,23,47,12] which in InsightMaker would be written as {0.3,23,47,12}
We created the function array2Vector() to do the conversion.
Initially, the vector [C_in] should have 0 (or whatever [Initial C_in] contains) for each time step, which we accomplish with:
(new Array(getTimeLength()/getTimeStep() + 1)).fill(Number(initialValue))
If you change the name of a primitive in the model you must also change the name in the script.