-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added option to specify cardiac period #127
base: master
Are you sure you want to change the base?
Conversation
@rjrios915 @JonathanPham Please make sure the tests are passing! Also, just wondering if it might be better to specify the cardiac cycle period within the relevant block that is driving the cardiac cycle (like the cardiac chamber)? For example, the currently implemented |
@rjrios915 @JonathanPham Not sure why the tests are still failing but can you rebase this branch with the master so it it using the most recent version please? |
Hello! All test cases except the data visualization should now be passing. As for where the cardiac period is defined, I think it could be useful to do so globally. The solver already utilizes a global period to calculate step size, number of cycles, and the time per cycle when outputting a single cardiac cycle even when there is no heart block, so I was thinking adding it to simulation parameters would make it easy for users to change the value if needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rjrios915 We should make sure your changes are consistent with what the code is currently doing. I have commented on specific changes and added links to where they might be inconsistent with the current code. Here's a quick summary:
Currently, model->cardiac_cycle_period
is initialized as -1.0 here:
svZeroDSolver/src/model/Model.h
Line 94 in edd6156
double cardiac_cycle_period = -1.0; ///< Cardiac cycle period |
model->cardiac_cycle_period
remains -1.0 until it is specified by a block, at which point we make sure that the newly specified value matches the value read previously from any other block (if any). I have provided examples of how that is checked in my comments below.
If no value has been specified after all blocks have been read, a default value of 1.0 is set. This is in Model::finalize
and I have also provided a link to that code block in my comments below.
Please make sure your current changes are consistent with that. Mainly, the default should be 1.0 and you should check that any newly specified value is consistent with previously specified values (if any).
@@ -9,6 +9,9 @@ Solver::Solver(const nlohmann::json& config) { | |||
DEBUG_MSG("Load model"); | |||
this->model = std::shared_ptr<Model>(new Model()); | |||
load_simulation_model(config, *this->model.get()); | |||
if (simparams.sim_cardiac_period > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are now specifying cardiac cycle period in multiple places, add a condition to check that they are all consistent. See two examples below.
For time-varying parameters:
svZeroDSolver/src/model/Model.cpp
Lines 169 to 175 in edd6156
if ((this->cardiac_cycle_period > 0.0) && | |
(param.cycle_period != this->cardiac_cycle_period)) { | |
throw std::runtime_error( | |
"Inconsistent cardiac cycle period defined in parameters"); | |
} | |
this->cardiac_cycle_period = param.cycle_period; | |
} |
For closed-loop heart block:
svZeroDSolver/src/solve/SimulationParameters.cpp
Lines 510 to 517 in edd6156
if ((model.cardiac_cycle_period > 0.0) && | |
(cycle_period != model.cardiac_cycle_period)) { | |
throw std::runtime_error( | |
"Inconsistent cardiac cycle period defined in " | |
"ClosedLoopHeartAndPulmonary."); | |
} else { | |
model.cardiac_cycle_period = cycle_period; | |
} |
@@ -215,6 +215,7 @@ SimulationParameters load_simulation_params(const nlohmann::json& config) { | |||
sim_params.output_mean_only = sim_config.value("output_mean_only", false); | |||
sim_params.output_derivative = sim_config.value("output_derivative", false); | |||
sim_params.output_all_cycles = sim_config.value("output_all_cycles", false); | |||
sim_params.sim_cardiac_period = sim_config.value("cardiac_period", 0.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the default value be 1.0? That is consistent with the code below:
svZeroDSolver/src/model/Model.cpp
Lines 205 to 207 in edd6156
if (cardiac_cycle_period < 0.0) { | |
cardiac_cycle_period = 1.0; | |
} |
@@ -52,6 +52,7 @@ struct SimulationParameters { | |||
// been read from config file yet. | |||
double sim_time_step_size{0.0}; ///< Simulation time step size | |||
double sim_abs_tol{0.0}; ///< Absolute tolerance for simulation | |||
double sim_cardiac_period{0.0}; ///< Cardiac period |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above about the default value.
Addresses #126
Added option to specify cardiac period under simulation parameters
Current situation
Link any open issues or PRs related to this PR. Please ensure that all non-trivial PRs are first tracked and discussed in an existing GitHub issue or discussion.
Release Notes
Add a bullet point list summary of the feature and possible migration guides if this is a breaking change so this section can be added to the release notes.
Documentation
Please ensure that you properly document any additions.
Testing
Please ensure that the PR meets the testing requirements set by GitHub Actions.
In addition, please ensure all modified and new code is covered by tests.
Code of Conduct & Contributing Guidelines