svZeroDSolver
Loading...
Searching...
No Matches
ChamberElastanceInductor.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 ChamberElastanceInductor.h
5 * @brief model::ChamberElastanceInductor source file
6 */
7#ifndef SVZERODSOLVER_MODEL_CHAMBERELASTANCEINDUCTOR_HPP_
8#define SVZERODSOLVER_MODEL_CHAMBERELASTANCEINDUCTOR_HPP_
9
10#include <math.h>
11
12#include <memory>
13
14#include "ActivationFunction.h"
15#include "Block.h"
16#include "Model.h"
17#include "SparseSystem.h"
18#include "debug.h"
19
20/**
21 * @brief Cardiac chamber with elastance and inductor.
22 *
23 * Models a cardiac chamber as a time-varying capacitor (elastance with
24 * specified resting volumes) and an inductor. See \cite kerckhoffs2007coupling
25 * (equations 1 and 2). The addition of the inductor is similar to the models in
26 * \cite sankaran2012patient and \cite menon2023predictors.
27 *
28 * This chamber block can be connected to other blocks using junctions.
29 *
30 * \f[
31 * \begin{circuitikz} \draw
32 * node[left] {$Q_{in}$} [-latex] (0,0) -- (0.8,0);
33 * \draw (1,0) node[anchor=south]{$P_{in}$}
34 * to (1,0)
35 * node[anchor=south]{}
36 * to [L, l=$L$, *-*] (3,0)
37 * node[anchor=south]{$P_{out}$}
38 * (1,0) to [vC, l=$E$, *-] (1,-1.5)
39 * node[ground]{};
40 * \draw [-latex] (3.2,0) -- (4.0,0) node[right] {$Q_{out}$} ;
41 * \end{circuitikz}
42 * \f]
43 *
44 * ### Governing equations
45 *
46 * \f[
47 * P_{in}-E(t)(V_c-V_{rest})=0
48 * \f]
49 *
50 * \f[
51 * P_{in}-P_{out}-L\dot{Q}_{out}=0
52 * \f]
53 *
54 * \f[
55 * Q_{in}-Q_{out}-\dot{V}_c=0
56 * \f]
57 *
58 * ### Local contributions
59 *
60 * \f[
61 * \mathbf{y}^{e}=\left[\begin{array}{lllll}P_{in} & Q_{in} &
62 * P_{out} & Q_{out} & V_c\end{array}\right]^{T} \f]
63 *
64 * \f[
65 * \mathbf{E}^{e}=\left[\begin{array}{ccccc}
66 * 0 & 0 & 0 & 0 & 0\\
67 * 0 & 0 & 0 & -L & 0\\
68 * 0 & 0 & 0 & 0 & -1
69 * \end{array}\right]
70 * \f]
71 *
72 * \f[
73 * \mathbf{F}^{e}=\left[\begin{array}{ccccc}
74 * 1 & 0 & 0 & 0 & E(t) \\
75 * 1 & 0 & -1 & 0 & 0 \\
76 * 0 & 1 & 0 & -1 & 0
77 * \end{array}\right]
78 * \f]
79 *
80 * \f[
81 * \mathbf{c}^{e}=\left[\begin{array}{c}
82 * E(t)V_{rest} \\
83 * 0 \\
84 * 0
85 * \end{array}\right]
86 * \f]
87 *
88 * In the above equations,
89 *
90 * \f[
91 * V_{rest}(t)= \{1-A(t)\}(V_{rd}-V_{rs})+V_{rs}
92 * \f]
93 *
94 * \f[
95 * A(t)=-\frac{1}{2}cos(2 \pi T_{contract}/T_{twitch})
96 * \f]
97 *
98 * \f[
99 * E(t)=(E_{max}-E_{min})A(t) + E_{min}
100 * \f]
101 *
102 *
103 * ### Parameters
104 *
105 * Parameter sequence for constructing this block
106 *
107 * * `0` Emax: Maximum elastance
108 * * `1` Emin: Minimum elastance
109 * * `2` Vrd: Rest diastolic volume
110 * * `3` Vrs: Rest systolic volume
111 * * `4` t_active: Activation time
112 * * `5` t_twitch: Twitch time
113 * * `6` Impedance: Impedance of the outflow
114 *
115 * ### Usage in json configuration file
116 *
117 * "chambers": [
118 * {
119 * "type": "ChamberElastanceInductor",
120 * "name": "ventricle",
121 * "values": {
122 * "Emax": 1.057,
123 * "Emin": 0.091,
124 * "Vrd": 26.1,
125 * "Vrs": 18.0,
126 * "Impedance": 0.000351787
127 * },
128 * "activation_function": {
129 * "type": "half_cosine",
130 * "t_active": 0.2,
131 * "t_twitch": 0.3
132 * }
133 * }
134 * ],
135 * "initial_condition": {
136 * "Vc:ventricle": 96.07
137 * }
138 *
139 * ### Internal variables
140 *
141 * Names of internal variables in this block's output:
142 *
143 * * `Vc`: Chamber volume
144 *
145 */
147 public:
148 /**
149 * @brief Construct a new ChamberElastanceInductor object
150 *
151 * @param id Global ID of the block
152 * @param model The model to which the block belongs
153 */
155 : Block(id, model, BlockType::chamber_elastance_inductor,
156 BlockClass::chamber,
157 {{"Emax", InputParameter()},
158 {"Emin", InputParameter()},
159 {"Vrd", InputParameter()},
160 {"Vrs", InputParameter()},
161 {"Impedance", InputParameter()}}) {}
162
163 /**
164 * @brief Local IDs of the parameters
165 *
166 */
167 enum ParamId { EMAX = 0, EMIN = 1, VRD = 2, VRS = 3, IMPEDANCE = 4 };
168
169 /**
170 * @brief Set up the degrees of freedom (DOF) of the block
171 *
172 * Set global_var_ids and global_eqn_ids of the element based on the
173 * number of equations and the number of internal variables of the
174 * element.
175 *
176 * @param dofhandler Degree-of-freedom handler to register variables and
177 * equations at
178 */
179 void setup_dofs(DOFHandler& dofhandler);
180
181 /**
182 * @brief Update the constant contributions of the element in a sparse
183 system
184 *
185 * @param system System to update contributions at
186 * @param parameters Parameters of the model
187 */
188 void update_constant(SparseSystem& system, std::vector<double>& parameters);
189
190 /**
191 * @brief Update the time-dependent contributions of the element in a sparse
192 * system
193 *
194 * @param system System to update contributions at
195 * @param parameters Parameters of the model
196 */
197 void update_time(SparseSystem& system, std::vector<double>& parameters);
198
199 /**
200 * @brief Number of triplets of element
201 *
202 * Number of triplets that the element contributes to the global system
203 * (relevant for sparse memory reservation)
204 */
206
207 private:
208 double Elas; // Chamber Elastance
209 double Vrest; // Rest Volume
210 std::unique_ptr<ActivationFunction> activation_func_; // Activation function
211
212 public:
213 /**
214 * @brief Set the activation function (takes ownership)
215 *
216 * @param af Unique pointer to the activation function
217 */
218 void set_activation_function(std::unique_ptr<ActivationFunction> af) override;
219
220 private:
221 /**
222 * @brief Update the elastance functions which depend on time
223 *
224 * @param parameters Parameters of the model
225 */
226 void get_elastance_values(std::vector<double>& parameters);
227};
228
229#endif // SVZERODSOLVER_MODEL_CHAMBERELASTANCEINDUCTOR_HPP_
Activation function classes for cardiac chamber models.
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:41
model::Model source file
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:101
const int id
Global ID of the block.
Definition Block.h:78
const Model * model
The model to which the block belongs.
Definition Block.h:79
void setup_dofs(DOFHandler &dofhandler)
Set up the degrees of freedom (DOF) of the block.
Definition ChamberElastanceInductor.cpp:5
TripletsContributions num_triplets
Number of triplets of element.
Definition ChamberElastanceInductor.h:205
void update_time(SparseSystem &system, std::vector< double > &parameters)
Update the time-dependent contributions of the element in a sparse system.
Definition ChamberElastanceInductor.cpp:28
ChamberElastanceInductor(int id, Model *model)
Construct a new ChamberElastanceInductor object.
Definition ChamberElastanceInductor.h:154
ParamId
Local IDs of the parameters.
Definition ChamberElastanceInductor.h:167
void update_constant(SparseSystem &system, std::vector< double > &parameters)
Update the constant contributions of the element in a sparse system.
Definition ChamberElastanceInductor.cpp:10
void set_activation_function(std::unique_ptr< ActivationFunction > af) override
Set the activation function (takes ownership)
Definition ChamberElastanceInductor.cpp:51
Degree-of-freedom handler.
Definition DOFHandler.h:21
Model of 0D elements.
Definition Model.h:52
Sparse system.
Definition SparseSystem.h:30
DEBUG_MSG source file.
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:27