svZeroDSolver
Loading...
Searching...
No Matches
ClosedLoopHeartPulmonary.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the
2// University of California, and others. SPDX-License-Identifier: BSD-3-Clause
3/**
4 * @file ClosedLoopHeartPulmonary.h
5 * @brief model::ClosedLoopHeartPulmonary source file
6 */
7#ifndef SVZERODSOLVER_MODEL_CLOSEDLOOPHEARTPULMONARY_HPP_
8#define SVZERODSOLVER_MODEL_CLOSEDLOOPHEARTPULMONARY_HPP_
9
10#include "Block.h"
11#include "SparseSystem.h"
12
13/**
14 * @brief Define math constants (for M_PI)
15 *
16 */
17#define _USE_MATH_DEFINES
18
19#include <cmath>
20
21/**
22 * @brief Heart and pulmonary circulation model
23 *
24 * Models the mechanics of the 4 heart chambers and pulmonary circulation
25 *
26 * References: \cite sankaran2012patient and \cite menon2023predictors
27 *
28 * TODO: Equations and circuit diagram
29 *
30 * ### Parameters
31 *
32 * Parameter sequence for constructing this block
33 *
34 * * `0` Atrial systole time fraction
35 * * `1` Time for P-wave
36 * * `2` Scaling for right ventricle elastance
37 * * `3` Scaling for left ventricle elastance
38 * * `4` Scaling for intramyocardial pressure (left coronaries)
39 * * `5` Scaling for intramyocardial pressure (right coronaries)
40 * * `6` Right atrium inductance
41 * * `7` Right atrium outflow resistance
42 * * `8` Right ventricle inductance
43 * * `9` Right ventricle outflow resistance
44 * * `10` Left atrium inductance
45 * * `11` Left atrium outflow resistance
46 * * `12` Left ventricle inductance
47 * * `13` Left ventricle outflow resistance
48 * * `14` Right ventricle unstressed volume
49 * * `15` Left ventricle unstressed volume
50 * * `16` Pulmonary resistance
51 * * `17` Pulmonary capacitance
52 * * `18` Aortic capacitance
53 * * `19` Right atrium pressure scaling
54 * * `20` Right atrium volume scaling
55 * * `21` Left atrium pressure scaling
56 * * `22` Left atrium volume scaling
57 * * `23` Right atrium elastance
58 * * `24` Left atrium elastance
59 * * `25` Right atrium resting volume
60 * * `26` Left atrium resting volume
61 *
62 * ### Internal variables
63 *
64 * Names of internal variables in this block's output:
65 *
66 * * `V_RA`: Right atrium volume
67 * * `Q_RA`: Right atrium outflow
68 * * `P_RV`: Right ventricle pressure
69 * * `V_RV`: Right ventricle volume
70 * * `Q_RV`: Right ventricle outflow
71 * * `P_pul`: Pulmonary pressure
72 * * `P_LA`: Left atrium pressure
73 * * `V_LA`: Left atrium volume
74 * * `Q_LA`: Left atrium outflow
75 * * `P_LV`: Left ventricle pressure
76 * * `V_LV`: Left ventricle volume
77 * * `Q_LV`: Left ventricle outflow
78 *
79 */
81 public:
82 /**
83 * @brief Construct a new ClosedLoopHeartPulmonary object
84 *
85 * @param id Global ID of the block
86 * @param model The model to which the block belongs
87 */
89 : Block(id, model, BlockType::closed_loop_heart_pulmonary,
90 BlockClass::closed_loop,
91 {{"Tsa", InputParameter()}, {"tpwave", InputParameter()},
92 {"Erv_s", InputParameter()}, {"Elv_s", InputParameter()},
93 {"iml", InputParameter()}, {"imr", InputParameter()},
94 {"Lra_v", InputParameter()}, {"Rra_v", InputParameter()},
95 {"Lrv_a", InputParameter()}, {"Rrv_a", InputParameter()},
96 {"Lla_v", InputParameter()}, {"Rla_v", InputParameter()},
97 {"Llv_a", InputParameter()}, {"Rlv_ao", InputParameter()},
98 {"Vrv_u", InputParameter()}, {"Vlv_u", InputParameter()},
99 {"Rpd", InputParameter()}, {"Cp", InputParameter()},
100 {"Cpa", InputParameter()}, {"Kxp_ra", InputParameter()},
101 {"Kxv_ra", InputParameter()}, {"Kxp_la", InputParameter()},
102 {"Kxv_la", InputParameter()}, {"Emax_ra", InputParameter()},
103 {"Emax_la", InputParameter()}, {"Vaso_ra", InputParameter()},
104 {"Vaso_la", InputParameter()}}) {}
105
106 /**
107 * @brief Local IDs of the parameters
108 *
109 */
110 enum ParamId {
111 TSA = 0, ///< Fractions of cardiac cycle (not sure)
112 TPWAVE = 1, ///< Fraction of cardiac cycle (P-wave)
113 ERV_S = 2, ///< Scaling for right ventricle elastance
114 ELV_S = 3, ///< Scaling for left ventricle elastance
115 IML = 4, ///< Scaling for intramyocardial pressure (left coronaries)
116 IMR = 5, ///< Scaling for intramyocardial pressure (right coronaries)
117 LRA_V = 6, ///< Right atrium inductance
118 RRA_V = 7, ///< Right atrium outflow resistance
119 LRV_A = 8, ///< Right ventricle inductance
120 RRV_A = 9, ///< Right ventricle outflow resistance
121 LLA_V = 10, ///< Left atrium inductance
122 RLA_V = 11, ///< Left atrium outflow resistance
123 LLV_A = 12, ///< Left ventricle inductance
124 RLV_AO = 13, ///< Left ventricle outflow resistance
125 VRV_U = 14, ///< Right ventricle unstressed volume
126 VLV_U = 15, ///< Left ventricle unstressed volume
127 RPD = 16, ///< Pulmonary resistance
128 CP = 17, ///< Pulmonary capacitance
129 CPA = 18, ///< Aortic capacitance
130 KXP_RA = 19, ///< Right atrium pressure-volume relationship (?)
131 KXV_RA = 20, ///< Right atrium pressure-volume relationship (?)
132 KXP_LA = 21, ///< Left atrium pressure-volume relationship (?)
133 KXV_LA = 22, ///< Left atrium pressure-volume relationship (?)
134 EMAX_RA = 23, ///< Right atrium elastance (?)
135 EMAX_LA = 24, ///< Left atrium elastance (?)
136 VASO_RA = 25, ///< Right atrium rest volume (?)
137 VASO_LA = 26, ///< Left atrium rest volume (?)
138 };
139
140 /**
141 * @brief Set up the degrees of freedom (DOF) of the block
142 *
143 * Set \ref global_var_ids and \ref global_eqn_ids of the element based on the
144 * number of equations and the number of internal variables of the
145 * element.
146 *
147 * @param dofhandler Degree-of-freedom handler to register variables and
148 * equations at
149 */
150 void setup_dofs(DOFHandler &dofhandler);
151
152 /**
153 * @brief Update the constant contributions of the element in a sparse
154 system
155 *
156 * @param system System to update contributions at
157 * @param parameters Parameters of the model
158 */
159 void update_constant(SparseSystem &system, std::vector<double> &parameters);
160
161 /**
162 * @brief Update the time-dependent contributions of the element in a sparse
163 * system
164 *
165 * @param system System to update contributions at
166 * @param parameters Parameters of the model
167 */
168 void update_time(SparseSystem &system, std::vector<double> &parameters);
169
170 /**
171 * @brief Update the solution-dependent contributions of the element in a
172 * sparse system
173 *
174 * @param system System to update contributions at
175 * @param parameters Parameters of the model
176 * @param y Current solution
177 * @param dy Current derivate of the solution
178 */
179 void update_solution(SparseSystem &system, std::vector<double> &parameters,
180 const Eigen::Matrix<double, Eigen::Dynamic, 1> &y,
181 const Eigen::Matrix<double, Eigen::Dynamic, 1> &dy);
182
183 /**
184 * @brief Modify the solution after solving it
185 *
186 * @param y Current solution
187 */
188 void post_solve(Eigen::Matrix<double, Eigen::Dynamic, 1> &y);
189
190 /**
191 * @brief Number of triplets of element
192 *
193 * Number of triplets that the element contributes to the global system
194 * (relevant for sparse memory reservation)
195 */
197
198 private:
199 // Below variables change every timestep and are then combined with
200 // expressions that are updated with solution
201 double AA = 0.0; // Atrial activation function
202 double Elv = 0.0; // LV elastance
203 double Erv = 0.0; // RV elastance
204 double psi_ra, psi_la, psi_ra_derivative,
205 psi_la_derivative; // Expressions for atrial activation
206 double valves[16];
207
208 /**
209 * @brief Update the atrial activation and LV/RV elastance functions which
210 * depend on time
211 *
212 * @param parameters Parameters of the model
213 */
214 void get_activation_and_elastance_functions(std::vector<double> &parameters);
215
216 /**
217 * @brief Compute sub-expressions that are part of atrial elastance and
218 * depends on atrial volume from the solution vector
219 *
220 * @param parameters Parameters of the model
221 * @param y Current solution
222 */
223 void get_psi_ra_la(std::vector<double> &parameters,
224 const Eigen::Matrix<double, Eigen::Dynamic, 1> &y);
225
226 /**
227 * @brief Valve positions for each heart chamber
228 *
229 * @param y Current solution
230 */
231 void get_valve_positions(const Eigen::Matrix<double, Eigen::Dynamic, 1> &y);
232};
233
234#endif // SVZERODSOLVER_MODEL_CLOSEDLOOPHEARTPULMONARY_HPP_
model::Block source file
BlockType
The types of blocks supported by the solver.
Definition BlockType.h:15
BlockClass
The classes/categories of blocks supported. Some classes require special handling (e....
Definition BlockType.h:37
SparseSystem source file.
Block(int id, Model *model, BlockType block_type, BlockClass block_class, std::vector< std::pair< std::string, InputParameter > > input_params)
Construct a new Block object.
Definition Block.h:100
const int id
Global ID of the block.
Definition Block.h:77
const Model * model
The model to which the block belongs.
Definition Block.h:78
ClosedLoopHeartPulmonary(int id, Model *model)
Construct a new ClosedLoopHeartPulmonary object.
Definition ClosedLoopHeartPulmonary.h:88
void setup_dofs(DOFHandler &dofhandler)
Set up the degrees of freedom (DOF) of the block.
Definition ClosedLoopHeartPulmonary.cpp:7
void update_solution(SparseSystem &system, std::vector< double > &parameters, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &y, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &dy)
Update the solution-dependent contributions of the element in a sparse system.
Definition ClosedLoopHeartPulmonary.cpp:101
void post_solve(Eigen::Matrix< double, Eigen::Dynamic, 1 > &y)
Modify the solution after solving it.
Definition ClosedLoopHeartPulmonary.cpp:282
ParamId
Local IDs of the parameters.
Definition ClosedLoopHeartPulmonary.h:110
@ KXV_RA
Right atrium pressure-volume relationship (?)
Definition ClosedLoopHeartPulmonary.h:131
@ RRA_V
Right atrium outflow resistance.
Definition ClosedLoopHeartPulmonary.h:118
@ KXP_RA
Right atrium pressure-volume relationship (?)
Definition ClosedLoopHeartPulmonary.h:130
@ VRV_U
Right ventricle unstressed volume.
Definition ClosedLoopHeartPulmonary.h:125
@ LRV_A
Right ventricle inductance.
Definition ClosedLoopHeartPulmonary.h:119
@ RLV_AO
Left ventricle outflow resistance.
Definition ClosedLoopHeartPulmonary.h:124
@ EMAX_RA
Right atrium elastance (?)
Definition ClosedLoopHeartPulmonary.h:134
@ TPWAVE
Fraction of cardiac cycle (P-wave)
Definition ClosedLoopHeartPulmonary.h:112
@ IML
Scaling for intramyocardial pressure (left coronaries)
Definition ClosedLoopHeartPulmonary.h:115
@ IMR
Scaling for intramyocardial pressure (right coronaries)
Definition ClosedLoopHeartPulmonary.h:116
@ VASO_LA
Left atrium rest volume (?)
Definition ClosedLoopHeartPulmonary.h:137
@ LLV_A
Left ventricle inductance.
Definition ClosedLoopHeartPulmonary.h:123
@ ELV_S
Scaling for left ventricle elastance.
Definition ClosedLoopHeartPulmonary.h:114
@ CP
Pulmonary capacitance.
Definition ClosedLoopHeartPulmonary.h:128
@ VLV_U
Left ventricle unstressed volume.
Definition ClosedLoopHeartPulmonary.h:126
@ RLA_V
Left atrium outflow resistance.
Definition ClosedLoopHeartPulmonary.h:122
@ EMAX_LA
Left atrium elastance (?)
Definition ClosedLoopHeartPulmonary.h:135
@ TSA
Fractions of cardiac cycle (not sure)
Definition ClosedLoopHeartPulmonary.h:111
@ KXP_LA
Left atrium pressure-volume relationship (?)
Definition ClosedLoopHeartPulmonary.h:132
@ CPA
Aortic capacitance.
Definition ClosedLoopHeartPulmonary.h:129
@ RPD
Pulmonary resistance.
Definition ClosedLoopHeartPulmonary.h:127
@ LLA_V
Left atrium inductance.
Definition ClosedLoopHeartPulmonary.h:121
@ ERV_S
Scaling for right ventricle elastance.
Definition ClosedLoopHeartPulmonary.h:113
@ VASO_RA
Right atrium rest volume (?)
Definition ClosedLoopHeartPulmonary.h:136
@ KXV_LA
Left atrium pressure-volume relationship (?)
Definition ClosedLoopHeartPulmonary.h:133
@ RRV_A
Right ventricle outflow resistance.
Definition ClosedLoopHeartPulmonary.h:120
@ LRA_V
Right atrium inductance.
Definition ClosedLoopHeartPulmonary.h:117
void update_time(SparseSystem &system, std::vector< double > &parameters)
Update the time-dependent contributions of the element in a sparse system.
Definition ClosedLoopHeartPulmonary.cpp:78
TripletsContributions num_triplets
Number of triplets of element.
Definition ClosedLoopHeartPulmonary.h:196
void update_constant(SparseSystem &system, std::vector< double > &parameters)
Update the constant contributions of the element in a sparse system.
Definition ClosedLoopHeartPulmonary.cpp:13
Degree-of-freedom handler.
Definition DOFHandler.h:21
Model of 0D elements.
Definition Model.h:48
Sparse system.
Definition SparseSystem.h:30
Handles the properties of input parameters.
Definition Parameter.h:100
The number of triplets that the element contributes to the global system.
Definition Block.h:26