Example: 3Compartment Model
Prerequisites
- A Python environment with libcuflynx installed (see Getting Started).
- The example resource files in
resources/.

A schematic view of this model is shown above with details of boundary conditions, parts' names, vein connection, and direction of blood flow through. The heart is modeled as a simple valve module in this example. According to this schematic, the vessel and parameters files are designed as shown in below figures.


In the module_array file, there are five columns: name, module_subtype, module_type, inp_instances, and out_instances
name is the user-chosen module's name, for example "heart" or "aortic_root".
module_subtype is the boundary condition type for circulatory system vessels. The BC of vessel modules should be one of the "vv", "vp", "pv", and "pp" types. The first letter defines input pressure (p) or flow (v) boundary condition, the second letter defines output pressure (p) or flow (v) boundary condition. For example the pulmonary vein (pvn) in the above example has a vp BC type, meaning it has input flow and output pressure boundary conditions.
Info
A vessel with "output flow" BC must be connected to a vessel with "input pressure" BC and vice versa. E.g. a "vp" can only have either a "vv" or "vp" vessel as ouputs. This is checked in the software, and will throw an error if there are incorrect BC connections.
The module_type and module_subtype must match a module with the same module_type and module_subtype in the modules config JSON files defined at [CA_dir]/src/libcuflynx/generators/resources/.
These files define the variables of each module and the connection ports that allow linking between modules; each module links to a CellML module. For more information, refer to Designing a model.
inp_instances and out_instances are the inputs and outputs of each module, respectively. Some modules have multiple inputs and outputs, like split_type vessels that split from one to two vessels.
Note
A module's inputs take its entrance ports of one port type in the order inp_instances lists them, and its outputs its exit ports in out_instances order. The heart module's vessel ports are, in order:
inp_instances:
- inferior vena cava
- superior vena cava
- pulmonary vein
out_instances:
- aorta
- pulmonary artery
This model has no inferior vena cava, so its heart lists a zero_flow instance first, which
sets the first port's flow to zero. Nothing is added for the heart: every module it connects
to is in the module array. A port left unconnected is a boundary condition, which needs a
value in the parameters file.
Tip
Currently, the terminal vessels should only have a module_subtype starting with "pp".
Results:
In the below figure, three different variables are plotted versus time. The step size was adjusted to 0.01 seconds. These variables are the "Aortic_root flow rate", "pvn flow rate", and the "volume of the heart", respectively.
This is the model before doing model calibration. See section Parameter Identification for info on the parameter identification.

Expected outcome
You should be able to generate and simulate the 3-compartment model and reproduce the example outputs.