7#ifndef SVZERODSOLVER_SIMULATIONPARAMETERS_HPP_
8#define SVZERODSOLVER_SIMULATIONPARAMETERS_HPP_
11#include <nlohmann/json.hpp>
87 JsonWrapper(
const nlohmann::json& json,
const std::string& component,
88 const std::string& name_str,
const int&
id)
89 : nlohmann::json(json[component][id]),
102 if (!this->contains(key)) {
103 if (this->contains(name_str)) {
104 const std::string name = this->at(name_str);
105 throw std::runtime_error(
"Key " + std::string(key) +
106 " not found in element " + name +
107 " of component " + component);
109 throw std::runtime_error(
110 "Key " + std::string(key) +
" not found in element number " +
111 std::to_string(block_id) +
" of component " + component);
114 return this->at(key);
118 using nlohmann::json::contains;
119 using nlohmann::json::value;
120 using nlohmann::json::operator[];
123 std::string component;
124 std::string name_str;
143 const std::string& block_type,
const std::string_view& name,
144 bool internal =
false,
bool periodic =
true);
159 Model& model,
const nlohmann::json& j,
const std::string& chamber_name);
206 std::vector<std::tuple<std::string, std::string>>& connections,
207 const nlohmann::json& config,
const std::string& component,
208 std::map<int, std::string>& vessel_id_map);
223 std::vector<std::tuple<std::string, std::string>>& connections,
224 const nlohmann::json& config,
const std::string& component,
225 std::map<int, std::string>& vessel_id_map,
226 std::map<std::string, std::string>& bc_type_map);
239 const std::string& component,
240 std::map<std::string, std::string>& bc_type_map,
241 std::vector<std::string>& closed_loop_bcs);
254 std::vector<std::tuple<std::string, std::string>>& connections,
255 const nlohmann::json& config,
const std::string& component,
256 std::map<int, std::string>& vessel_id_map);
270 std::vector<std::tuple<std::string, std::string>>& connections,
271 const nlohmann::json& config,
const std::string& component,
272 std::vector<std::string>& closed_loop_bcs);
284 std::vector<std::tuple<std::string, std::string>>& connections,
285 const nlohmann::json& config,
const std::string& component);
297 std::vector<std::tuple<std::string, std::string>>& connections,
298 const nlohmann::json& config,
const std::string& component);
Activation function classes for cardiac chamber models.
void create_chambers(Model &model, std::vector< std::tuple< std::string, std::string > > &connections, const nlohmann::json &config, const std::string &component)
Handle the creation of chambers.
Definition SimulationParameters.cpp:600
void create_junctions(Model &model, std::vector< std::tuple< std::string, std::string > > &connections, const nlohmann::json &config, const std::string &component, std::map< int, std::string > &vessel_id_map)
Handle the creation of junctions and their connections.
Definition SimulationParameters.cpp:484
void create_boundary_conditions(Model &model, const nlohmann::json &config, const std::string &component, std::map< std::string, std::string > &bc_type_map, std::vector< std::string > &closed_loop_bcs)
Handle the creation of boundary condition blocks.
Definition SimulationParameters.cpp:364
void create_valves(Model &model, std::vector< std::tuple< std::string, std::string > > &connections, const nlohmann::json &config, const std::string &component)
Handle the creation of valves and their associated connections.
Definition SimulationParameters.cpp:582
State load_initial_condition(const nlohmann::json &config, Model &model)
Load initial conditions from a JSON configuration.
Definition SimulationParameters.cpp:634
void create_vessels(Model &model, std::vector< std::tuple< std::string, std::string > > &connections, const nlohmann::json &config, const std::string &component, std::map< int, std::string > &vessel_id_map)
Handle the creation of vessel blocks and connections with boundary conditions.
Definition SimulationParameters.cpp:329
void create_closed_loop(Model &model, std::vector< std::tuple< std::string, std::string > > &connections, const nlohmann::json &config, const std::string &component, std::vector< std::string > &closed_loop_bcs)
Handle the creation of closed-loop blocks and associated connections.
Definition SimulationParameters.cpp:526
void load_simulation_model(const nlohmann::json &config, Model &model)
Load the 0D block in the model from a configuration.
Definition SimulationParameters.cpp:255
std::unique_ptr< ActivationFunction > generate_activation_function(Model &model, const nlohmann::json &j, const std::string &chamber_name)
Create an activation function from JSON (analogous to generate_block).
Definition SimulationParameters.cpp:142
SimulationParameters load_simulation_params(const nlohmann::json &config)
Load the simulation parameters from a JSON configuration.
Definition SimulationParameters.cpp:210
int generate_block(Model &model, const nlohmann::json &block_params_json, const std::string &block_type, const std::string_view &name, bool internal=false, bool periodic=true)
Generate a new block and add its parameters to the model.
Definition SimulationParameters.cpp:44
void create_external_coupling(Model &model, std::vector< std::tuple< std::string, std::string > > &connections, const nlohmann::json &config, const std::string &component, std::map< int, std::string > &vessel_id_map, std::map< std::string, std::string > &bc_type_map)
Handle the creation of external coupling blocks and connections with other blocks.
Definition SimulationParameters.cpp:399
void validate_input(const nlohmann::json &config)
Check that the JSON configuration has the required inputs.
Definition SimulationParameters.cpp:201
const nlohmann::json & operator[](const char *key) const
Wrap error check around key retrieval (throws detailed error if key doesn't exist).
Definition SimulationParameters.h:101
JsonWrapper(const nlohmann::json &json, const std::string &component, const std::string &name_str, const int &id)
Wrap around JSON configuration with detailed error message in case key is not found in configuration.
Definition SimulationParameters.h:87
Model of 0D elements.
Definition Model.h:55
State of the system.
Definition State.h:19
Simulation parameters.
Definition SimulationParameters.h:38
bool sim_coupled
Running 0D simulation coupled with external solver.
Definition SimulationParameters.h:66
int sim_nliter
Definition SimulationParameters.h:54
bool output_all_cycles
Output all cardiac cycles.
Definition SimulationParameters.h:64
int sim_pts_per_cycle
Number of time steps per cardiac cycle.
Definition SimulationParameters.h:45
int sim_num_time_steps
Total number of time steps.
Definition SimulationParameters.h:53
double sim_external_step_size
Definition SimulationParameters.h:68
double sim_time_step_size
Simulation time step size.
Definition SimulationParameters.h:41
int sim_num_cycles
Number of cardiac cycles to simulate.
Definition SimulationParameters.h:44
bool output_mean_only
Output only the mean value.
Definition SimulationParameters.h:62
bool sim_max_iter_error_to_warning
Definition SimulationParameters.h:70
bool sim_steady_initial
Start from steady solution.
Definition SimulationParameters.h:59
int output_interval
Interval of writing output.
Definition SimulationParameters.h:57
bool output_variable_based
Output variable based instead of vessel based.
Definition SimulationParameters.h:60
double sim_abs_tol
Absolute tolerance for simulation.
Definition SimulationParameters.h:42
double sim_cardiac_period
Cardiac period.
Definition SimulationParameters.h:43
bool output_derivative
Output derivatives.
Definition SimulationParameters.h:63
double sim_cycle_to_cycle_error
Cycle-to-cycle error.
Definition SimulationParameters.h:52
bool use_cycle_to_cycle_error
Definition SimulationParameters.h:46
double sim_rho_infty
Spectral radius of generalized-alpha.
Definition SimulationParameters.h:56