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