The python interface has two ways to run a 0D simulation (see below) and both of them should produce the same result. However, for some cases where one or more blocks need to access members of Model (which itself is a member of Block), the two methods do not produce the same result.
When running cases that use ChamberElastanceInductor and ClosedLoopHeartPulmonary blocks, they need to access model->cardiac_cycle_period inside their respective update_time() functions. While the second method works fine, the first method produces weird results.
Expected behavior
The above two methods should produce the same result. I found that the problem in the first method is that when solver is returned to Python, and solver.run() is subsequently executed, the *model pointer in Block has somehow lost track of the model object it was supposed to be pointing to within Solver.
This is happening because Solver has a member that is a model object, not a pointer to model. But Block has a pointer to model. While solver is returned from C++ to Python, although Solver still keeps track of its model member, that memory address seems to change and Block therefore loses track of it.
Additional context
TL;DR - Pointers work better when interfacing between different codes. I made the model object in Solver a pointer, so both Solver and Block are now pointing to the same address.
Code of Conduct
[X] I agree to follow this project's Code of Conduct and Contributing Guidelines
Description
The python interface has two ways to run a 0D simulation (see below) and both of them should produce the same result. However, for some cases where one or more blocks need to access members of
Model
(which itself is a member ofBlock
), the two methods do not produce the same result.Reproduction
Two ways to run a 0D simulation from Python are:
and
When running cases that use
ChamberElastanceInductor
andClosedLoopHeartPulmonary
blocks, they need to accessmodel->cardiac_cycle_period
inside their respectiveupdate_time()
functions. While the second method works fine, the first method produces weird results.Expected behavior
The above two methods should produce the same result. I found that the problem in the first method is that when
solver
is returned to Python, andsolver.run()
is subsequently executed, the*model
pointer inBlock
has somehow lost track of themodel
object it was supposed to be pointing to withinSolver
.This is happening because
Solver
has a member that is amodel
object, not a pointer tomodel
. ButBlock
has a pointer tomodel
. Whilesolver
is returned from C++ to Python, althoughSolver
still keeps track of itsmodel
member, that memory address seems to change andBlock
therefore loses track of it.Additional context
TL;DR - Pointers work better when interfacing between different codes. I made the
model
object inSolver
a pointer, so bothSolver
andBlock
are now pointing to the same address.Code of Conduct