Model modularity¶
When using the SUND toolbox, it is possible to combine models into a single simulation. Furthermore, the outputs from some models can be used as input in other models. These are defined in the INPUTS
header and in the OUTPUTS
header.
In the example below, the model m1
has an internal variable named plasma_ins
which it provides as an output insulin_plasma
to a "shared pool" of variables that other models can use. The model m2
needs ins
as an input, which it can take from the "shared pool". Below is a graphical example:
graph LR
%% Add text above the boxes
subgraph "Model 1"
m1["plasma_ins"]
end
subgraph "Shared variables"
shared["insulin_plasma"]
end
subgraph "Model 2"
m2["ins"]
end
%% Define the variable renaming flow
m1 -->|plasma_ins=insulin_plasma| shared
shared -->|insulin_plasma=ins| m2
Below is an example from the corresponding model files:
########## NAME
m1
...
########## OUTPUTS
insulin_plasma = plasma_ins
########## NAME
m2
...
########## INPUTS
ins = insulin_plasma
Now, if the models are put together in a simulation, the plasma insulin provided by m1
will be used by m2
automatically:
m1 = sund.load_model('m1')
m2 = sund.load_model('m2')
sim = sund.Simulation(time_unit = 'm', models = [m1, m2])
Using default values for inputs:¶
It is also possible to define default values that the model should take if the input is not supplied from another model or activity. This is done by using @ value
. So, e.g. to set ins
to 0 if no input is given for m2:
########## NAME
m2
...
########## INPUTS
ins = insulin_plasma @ 0
Inputs from other sources than models¶
In many cases, the inputs needed to model might not be available from other models. For example, if simulating an experiment with time-dependent stimulations. To avoid having to create an extra model for these stimulation inputs, you can instead use an activity object which only provides static time-dependent outputs to the shared pool.