Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

rjrios915
Copy link

@rjrios915 rjrios915 commented Aug 27, 2024

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

@menon-karthik
Copy link
Member

@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 ClosedLoopHeartPulmonary block has this implemented within the block. It might make more sense to do this because the cycle period is not a parameter of the entire simulation really, it is only a parameter of the block that is driving the heart beat.

@menon-karthik
Copy link
Member

@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?

@rjrios915
Copy link
Author

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.

Copy link
Member

@menon-karthik menon-karthik left a 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:

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) {
Copy link
Member

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:

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:

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);
Copy link
Member

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:

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants