svZeroDSolver
Loading...
Searching...
No Matches
PiecewiseCosineChamber.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/**
5 * @file PiecewiseCosineChamber.h
6 * @brief model::PiecewiseCosineChamber source file
7 */
8
9#ifndef SVZERODSOLVER_MODEL_PIECEWISECOSINECHAMBER_HPP_
10#define SVZERODSOLVER_MODEL_PIECEWISECOSINECHAMBER_HPP_
11
12#include <math.h>
13
14#include "Block.h"
15#include "Model.h"
16#include "SparseSystem.h"
17#include "debug.h"
18
19/**
20 * @brief Cardiac chamber with piecewise elastance and inductor.
21 *
22 * Models a cardiac chamber as a time-varying capacitor (elastance with
23 * specified resting volumes) and an inductor. See \cite Regazzoni2022
24 *
25 * This chamber block can be connected to other blocks using junctions.
26 *
27 * \f[
28 * \begin{circuitikz}
29 * \draw node[left] {$Q_{in}$} [-latex] (0,0) -- (0.8,0);
30 * \draw (1,0) node[anchor=south]{$P_{in}$}
31 * to[short, *-*] (3,0) node[anchor=south]{$P_{out}$}
32 * (1,0) to [vC, l=$E$, *-] (1,-1.5)
33 * node[ground]{};
34 * \draw (3.2,0) -- (4.0,0) node[right] {$Q_{out}$} [-latex];
35 * \end{circuitikz}
36 * \f]
37 *
38 * ### Governing equations
39 *
40 * \f[
41 * P_{in}-E(t)(V_c-V_{rest})=0
42 * \f]
43 *
44 * \f[
45 * P_{in}-P_{out}=0
46 * \f]
47 *
48 * \f[
49 * Q_{in}-Q_{out}-\dot{V}_c=0
50 * \f]
51 *
52 * ### Local contributions
53 *
54 * \f[
55 * \mathbf{y}^{e}=\left[\begin{array}{lllll}P_{in} & Q_{in} &
56 * P_{out} & Q_{out} & V_c\end{array}\right]^{T} \f]
57 *
58 * \f[
59 * \mathbf{E}^{e}=\left[\begin{array}{ccccc}
60 * 0 & 0 & 0 & 0 & 0\\
61 * 0 & 0 & 0 & 0 & 0\\
62 * 0 & 0 & 0 & 0 & -1
63 * \end{array}\right]
64 * \f]
65 *
66 * \f[
67 * \mathbf{F}^{e}=\left[\begin{array}{ccccc}
68 * 1 & 0 & 0 & 0 & E(t) \\
69 * 1 & 0 & -1 & 0 & 0 \\
70 * 0 & 1 & 0 & -1 & 0
71 * \end{array}\right]
72 * \f]
73 *
74 * \f[
75 * \mathbf{c}^{e}=\left[\begin{array}{c}
76 * E(t)V_{rest} \\
77 * 0 \\
78 * 0
79 * \end{array}\right]
80 * \f]
81 *
82 * In the above equations,
83 *
84 * \f[
85 * E_i(t) = E_i^{\text{pass}} + E_i^{\text{act,max}} \,
86 * \phi\!\left(t, t_C^i, t_R^i, T_C^i, T_R^i\right),
87 * \f]
88 *
89 * \f[
90 * \phi(t, t_C, t_R, T_C, T_R) =
91 * \begin{cases}
92 * \frac{1}{2}\left[1 - \cos\!\left(\frac{\pi}{T_C} \operatorname{mod}(t - t_C,
93 * T_{\mathrm{HB}})\right)\right], & \text{if } 0 \le \operatorname{mod}(t -
94 * t_C, T_{\mathrm{HB}}) < T_C, \\[1.2em] \frac{1}{2}\left[1 +
95 * \cos\!\left(\frac{\pi}{T_R} \operatorname{mod}(t - t_R,
96 * T_{\mathrm{HB}})\right)\right], & \text{if } 0 \le \operatorname{mod}(t -
97 * t_R, T_{\mathrm{HB}}) < T_R, \\[1.2em] 0, & \text{otherwise.} \end{cases} \f]
98 *
99 * ### Parameters
100 *
101 * Parameter sequence for constructing this block
102 *
103 * * `0` Emax: Maximum elastance
104 * * `1` Epass: Passive elastance
105 * * `2` Vrest: Rest diastolic volume
106 * * `3` contract_start: Contract start time
107 * * `4` relax_start: Relax start time
108 * * `5` contract_duration: Contract duration
109 * * `6` relax_duration: Relaxation duration
110 *
111 * ### Internal variables
112 *
113 * Names of internal variables in this block's output:
114 *
115 * * `Vc`: Chamber volume
116 *
117 */
119 public:
120 /**
121 * @brief Construct a new BloodVessel object
122 *
123 * @param id Global ID of the block
124 * @param model The model to which the block belongs
125 */
127 : Block(id, model, BlockType::piecewise_cosine_chamber,
128 BlockClass::chamber,
129 {{"Emax", InputParameter()},
130 {"Epass", InputParameter()},
131 {"Vrest", InputParameter()},
132 {"contract_start", InputParameter()},
133 {"relax_start", InputParameter()},
134 {"contract_duration", InputParameter()},
135 {"relax_duration", InputParameter()}}) {}
136
137 /**
138 * @brief Local IDs of the parameters
139 *
140 */
141 enum ParamId {
142 EMAX = 0,
143 EPASS = 1,
144 VREST = 2,
145 CSTART = 3,
146 RSTART = 4,
147 CDUR = 5,
148 RDUR = 6
149 };
150
151 /**
152 * @brief Set up the degrees of freedom (DOF) of the block
153 *
154 * Set global_var_ids and global_eqn_ids of the element based on the
155 * number of equations and the number of internal variables of the
156 * element.
157 *
158 * @param dofhandler Degree-of-freedom handler to register variables and
159 * equations at
160 */
161 void setup_dofs(DOFHandler& dofhandler);
162
163 /**
164 * @brief Update the constant contributions of the element in a sparse
165 system
166 *
167 * @param system System to update contributions at
168 * @param parameters Parameters of the model
169 */
170 void update_constant(SparseSystem& system, std::vector<double>& parameters);
171
172 /**
173 * @brief Update the time-dependent contributions of the element in a sparse
174 * system
175 *
176 * @param system System to update contributions at
177 * @param parameters Parameters of the model
178 */
179 void update_time(SparseSystem& system, std::vector<double>& parameters);
180
181 /**
182 * @brief Number of triplets of element
183 *
184 * Number of triplets that the element contributes to the global system
185 * (relevant for sparse memory reservation)
186 */
188
189 private:
190 double Elas; // Chamber Elastance
191
192 /**
193 * @brief Update the elastance functions which depend on time
194 *
195 * @param parameters Parameters of the model
196 */
197 void get_elastance_values(std::vector<double>& parameters);
198};
199
200#endif // SVZERODSOLVER_MODEL_PIECEWISECOSINECHAMBER_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: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: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
Degree-of-freedom handler.
Definition DOFHandler.h:21
Model of 0D elements.
Definition Model.h:52
void setup_dofs(DOFHandler &dofhandler)
Set up the degrees of freedom (DOF) of the block.
Definition PiecewiseCosineChamber.cpp:6
PiecewiseCosineChamber(int id, Model *model)
Construct a new BloodVessel object.
Definition PiecewiseCosineChamber.h:126
TripletsContributions num_triplets
Number of triplets of element.
Definition PiecewiseCosineChamber.h:187
ParamId
Local IDs of the parameters.
Definition PiecewiseCosineChamber.h:141
void update_time(SparseSystem &system, std::vector< double > &parameters)
Update the time-dependent contributions of the element in a sparse system.
Definition PiecewiseCosineChamber.cpp:26
void update_constant(SparseSystem &system, std::vector< double > &parameters)
Update the constant contributions of the element in a sparse system.
Definition PiecewiseCosineChamber.cpp:11
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:26