Skip to content

Commit eb38101

Browse files
committed
rebase Solver.cpp and SimulationParameters.cpp, remove redundancy in Model.cpp
1 parent 8363828 commit eb38101

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

src/solve/SimulationParameters.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ SimulationParameters load_simulation_params(const nlohmann::json& config) {
186186
sim_params.output_mean_only = sim_config.value("output_mean_only", false);
187187
sim_params.output_derivative = sim_config.value("output_derivative", false);
188188
sim_params.output_all_cycles = sim_config.value("output_all_cycles", false);
189-
sim_params.sim_cardiac_period = sim_config.value("cardiac_period", 0.0);
189+
sim_params.sim_cardiac_period = sim_config.value("cardiac_period", -1.0);
190190
DEBUG_MSG("Finished loading simulation parameters");
191191
return sim_params;
192192
}
@@ -402,20 +402,18 @@ void create_external_coupling(
402402
connections.push_back({coupling_name, connected_block});
403403
} else if (coupling_loc == "outlet") {
404404
std::vector<std::string> possible_types = {
405-
"ClosedLoopRCR", "ClosedLoopHeartAndPulmonary", "BloodVessel",
406-
"BloodVesselCRL", "BloodVessel"};
405+
"ClosedLoopRCR", "ClosedLoopHeartAndPulmonary", "BloodVessel"};
407406
if (std::find(std::begin(possible_types), std::end(possible_types),
408407
connected_type) == std::end(possible_types)) {
409408
throw std::runtime_error(
410409
"Error: The specified connection type for outlet "
411410
"external_coupling_block is invalid.");
412411
}
413-
// Add connection only for closedLoopRCR and BloodVessel
414-
// Connection to ClosedLoopHeartAndPulmonary will be
415-
// handled in ClosedLoopHeartAndPulmonary creation.
412+
// Add connection only for closedLoopRCR and BloodVessel. Connection to
413+
// ClosedLoopHeartAndPulmonary will be handled in
414+
// ClosedLoopHeartAndPulmonary creation.
416415
if ((connected_type == "ClosedLoopRCR") ||
417-
(connected_type == "BloodVessel") ||
418-
(connected_type == "BloodVesselA")) {
416+
(connected_type == "BloodVessel")) {
419417
connections.push_back({connected_block, coupling_name});
420418
} // connected_type == "ClosedLoopRCR"
421419
} // coupling_loc

src/solve/SimulationParameters.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
struct SimulationParameters {
3838
// Negative value indicates this has not
3939
// been read from config file yet.
40-
double sim_time_step_size{0.0}; ///< Simulation time step size
41-
double sim_abs_tol{0.0}; ///< Absolute tolerance for simulation
42-
double sim_cardiac_period{0.0}; ///< Cardiac period
43-
int sim_num_cycles{0}; ///< Number of cardiac cycles to simulate
44-
int sim_pts_per_cycle{0}; ///< Number of time steps per cardiac cycle
40+
double sim_time_step_size{0.0}; ///< Simulation time step size
41+
double sim_abs_tol{0.0}; ///< Absolute tolerance for simulation
42+
double sim_cardiac_period{-1.0}; ///< Cardiac period
43+
int sim_num_cycles{0}; ///< Number of cardiac cycles to simulate
44+
int sim_pts_per_cycle{0}; ///< Number of time steps per cardiac cycle
4545
bool use_cycle_to_cycle_error{
4646
false}; ///< If model does not have RCR boundary conditions, simulate
4747
///< model to convergence (based on cycle-to-cycle error of last

src/solve/Solver.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,20 @@ Solver::Solver(const nlohmann::json& config) {
1212
DEBUG_MSG("Load model");
1313
this->model = std::shared_ptr<Model>(new Model());
1414
load_simulation_model(config, *this->model.get());
15-
if (simparams.sim_cardiac_period > 0) {
15+
16+
// If period isn't specified anywhere, set to 1
17+
if (simparams.sim_cardiac_period < 0 &&
18+
this->model->cardiac_cycle_period < 0) {
19+
this->model->cardiac_cycle_period = 1;
20+
} else if (this->model->cardiac_cycle_period >= 0) {
21+
// Check for inconsistent period definition
22+
if (simparams.sim_cardiac_period >= 0 &&
23+
(this->model->cardiac_cycle_period != simparams.sim_cardiac_period)) {
24+
throw std::runtime_error(
25+
"Inconsistent cardiac cycle period defined in parameters");
26+
}
27+
// If period is only defined in parameters, set value in model
28+
} else {
1629
this->model->cardiac_cycle_period = simparams.sim_cardiac_period;
1730
}
1831
DEBUG_MSG("Load initial condition");

0 commit comments

Comments
 (0)