svZeroDSolver
Loading...
Searching...
No Matches
ChamberSphere.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 ChamberSphere.h
5 * @brief model::ChamberSphere source file
6 */
7#ifndef SVZERODSOLVER_MODEL_ChamberSphere_HPP_
8#define SVZERODSOLVER_MODEL_ChamberSphere_HPP_
9
10#include <math.h>
11#include <map>
12#include <memory>
13#include <string>
14
15#include "ActivationFunction.h"
16#include "Block.h"
17#include "SphereMaterial.h"
18#include "SparseSystem.h"
19
20/**
21 * @brief Spherical heart chamber model
22 *
23 * Models the mechanical behavior of a spherical heart chamber with active
24 * contraction. For reference, see \cite caruel13 Equations (13a-b) for
25 * continuum mechanics (without length-dependent contraction valves, vessels)
26 * and \cite pfaller2019importance Equations (12-16) for the simplified active
27 * contraction model.
28 *
29 * ### Helper Functions
30 *
31 * Cauchy-Green deformation tensor and time derivative:
32 * \f[
33 * C = \left(1 + \frac{r}{r_0} \right)^2
34 * \f]
35 * \f[
36 * \dot{C} = 2 \left(1 + \frac{r}{r_0} \right) \frac{\dot{r}}{r_0}
37 * \f]
38 *
39 * ### Governing equations
40 *
41 * 1. Balance of linear momentum:
42 * \f[
43 * \rho d_0 \dot{v} + \frac{d_0}{r_0} \left(1 + \frac{r}{r_0} \right) S -
44 P_\text{out} C = 0
45 * \f]
46 *
47 * 2. Spherical stress:
48 * \f[
49 * -S + \tau + S_\text{el}(r, r_0) + \eta \dot{C}
50 * (1 + 2 C^{-6}) = 0
51 * \f]
52 * where \f$S_\text{el}\f$ is the elastic stress term supplied by the
53 * chamber's \ref SphereMaterial.
54 *
55 * 3. Volume change:
56 * \f[
57 * 4 \pi r_0^2 Cv - \dot{V} = 0
58 * \f]
59 *
60 * 4. Active stress:
61 * \f[
62 * \dot{\tau} + a \tau - \sigma_\text{max} a_+ = 0, \quad a_+ = \max(a, 0),
63 \quad a = f\alpha_\text{max} + (1 - f)\alpha_\text{min}
64 * \f]
65 * where \f$f \in [0, 1]\f$ is the activation function, evaluated by a
66 * separate \ref ActivationFunction object (e.g. two_hill, half_cosine,
67 * piecewise_cosine) selected in the JSON configuration.
68 *
69 * 5. Acceleration:
70 * \f[
71 * \dot{r} - v = 0
72 * \f]
73 *
74 * 6. Conservation of mass:
75 * \f[
76 * Q_\text{in} - Q_\text{out} - \dot{V} = 0
77 * \f]
78 *
79 * 7. Pressure equality:
80 * \f[
81 * P_\text{in} - P_\text{out} = 0
82 * \f]
83 *
84 * ### Parameters
85 *
86 * Parameter sequence for constructing this block:
87 *
88 * * `rho` - Density \f$\rho\f$
89 * * `thick0` - Wall thickness \f$d_0\f$
90 * * `radius0` - Reference radius \f$r_0\f$
91 * * `eta` - Viscosity parameter \f$\eta\f$
92 * * `sigma_max` - Maximum active stress \f$\sigma_\text{max}\f$
93 * * `alpha_max` - Maximum activation parameter \f$\alpha_\text{max}\f$
94 * * `alpha_min` - Minimum activation parameter \f$\alpha_\text{min}\f$
95 *
96 * An `activation_function` object is also required alongside
97 * `zero_d_element_values` to select and parameterize the activation function
98 * \f$f(t)\f$ (see \ref ActivationFunction, e.g. `two_hill`, `half_cosine`,
99 * `piecewise_cosine`, `wrapping_cosine`, `fourier`, `double_tanh`).
100 *
101 * Furthermore, a `material` object is required to select and parameterize
102 * the material model for the elastic stress term \f$S_\text{el}(r, r_0)\f$
103 * (see \ref SphereMaterial, e.g. `exponential`, `mooney_rivlin`).
104 *
105 * ### Usage in json configuration file
106 *
107 * "chambers": [
108 * {
109 * "type": "ChamberSphere",
110 * "name": "ventricle",
111 * "values": {
112 * "rho" : 1e3,
113 * "thick0" : 0.01,
114 * "radius0" : 0.05,
115 * "eta" : 10.0,
116 * "sigma_max" : 185e3,
117 * "alpha_max": 30.0,
118 * "alpha_min": -30.0
119 * },
120 * "activation_function": {},
121 * "material": {}
122 * }
123 * ]
124 *
125 * A chamber is connected to the rest of the circuit via valve blocks (see
126 * \ref ValveTanh, \ref PiecewiseValve) referencing its `name` as their
127 * `upstream_block`/`downstream_block`.
128 *
129 * ### Internal variables
130 *
131 * Names of internal variables in this block's output:
132 *
133 * * `radius` - Chamber radius \f$r\f$
134 * * `velo` - Chamber velocity \f$\dot{r}\f$
135 * * `stress` - Spherical stress \f$S\f$
136 * * `tau` - Active stress \f$\tau\f$
137 * * `volume` - Chamber volume \f$V\f$
138 *
139 */
140class ChamberSphere : public Block {
141 public:
142 /**
143 * @brief Local IDs of the parameters
144 *
145 */
146 enum ParamId {
147 rho = 0,
148 thick0 = 1,
149 radius0 = 2,
150 eta = 3,
151 sigma_max = 4,
152 alpha_max = 5,
153 alpha_min = 6,
154 };
155
156 /**
157 * @brief Construct a new ChamberSphere object
158 *
159 * @param id Global ID of the block
160 * @param model The model to which the block belongs
161 */
163 : Block(id, model, BlockType::chamber_sphere, BlockClass::chamber,
164 {{"rho", InputParameter()},
165 {"thick0", InputParameter()},
166 {"radius0", InputParameter()},
167 {"eta", InputParameter()},
168 {"sigma_max", InputParameter()},
169 {"alpha_max", InputParameter()},
170 {"alpha_min", InputParameter()}}) {}
171
172 /**
173 * @brief Set up the degrees of freedom (DOF) of the block
174 *
175 * Set \ref global_var_ids and \ref global_eqn_ids of the element based on the
176 * number of equations and the number of internal variables of the
177 * element.
178 *
179 * @param dofhandler Degree-of-freedom handler to register variables and
180 * equations at
181 */
182 void setup_dofs(DOFHandler& dofhandler) override;
183
184 /**
185 * @brief Update the constant contributions of the element in a sparse
186 system
187 *
188 * @param system System to update contributions at
189 * @param parameters Parameters of the model
190 */
191 void update_constant(SparseSystem& system,
192 std::vector<double>& parameters) override;
193
194 /**
195 * @brief Update the time-dependent contributions of the element in a sparse
196 * system
197 *
198 * @param system System to update contributions at
199 * @param parameters Parameters of the model
200 */
201 void update_time(SparseSystem& system,
202 std::vector<double>& parameters) override;
203
204 /**
205 * @brief Update the solution-dependent contributions of the element in a
206 * sparse system
207 *
208 * @param system System to update contributions at
209 * @param parameters Parameters of the model
210 * @param y Current solution
211 * @param dy Current derivate of the solution
212 */
213 void update_solution(
214 SparseSystem& system, std::vector<double>& parameters,
215 const Eigen::Matrix<double, Eigen::Dynamic, 1>& y,
216 const Eigen::Matrix<double, Eigen::Dynamic, 1>& dy) override;
217
218 /**
219 * @brief Update the elastance functions which depend on time
220 *
221 * @param parameters Parameters of the model
222 */
223 void get_elastance_values(std::vector<double>& parameters);
224
225 void set_activation_function(std::unique_ptr<ActivationFunction> af) override;
226
227 void set_material(std::unique_ptr<SphereMaterial> m) override;
228
229 private:
230 double act = 0.0; // activation function
231 double act_plus = 0.0; // act_plus = max(act, 0)
232 std::unique_ptr<ActivationFunction> activation_function_;
233
234 std::unique_ptr<SphereMaterial> material_;
235
236 /**
237 * @brief Number of triplets of element
238 *
239 * Number of triplets that the element contributes to the global system
240 * (relevant for sparse memory reservation)
241 */
242 TripletsContributions num_triplets{0, 0, 18};
243};
244
245#endif // SVZERODSOLVER_MODEL_ChamberSphere_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:44
SparseSystem source file.
Material models for the ChamberSphere block.
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:102
const int id
Global ID of the block.
Definition Block.h:79
const Model * model
The model to which the block belongs.
Definition Block.h:80
ChamberSphere(int id, Model *model)
Construct a new ChamberSphere object.
Definition ChamberSphere.h:162
void update_constant(SparseSystem &system, std::vector< double > &parameters) override
Update the constant contributions of the element in a sparse system.
Definition ChamberSphere.cpp:13
ParamId
Local IDs of the parameters.
Definition ChamberSphere.h:146
void set_activation_function(std::unique_ptr< ActivationFunction > af) override
Set activation function (for chamber blocks that use one).
Definition ChamberSphere.cpp:124
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) override
Update the solution-dependent contributions of the element in a sparse system.
Definition ChamberSphere.cpp:52
void get_elastance_values(std::vector< double > &parameters)
Update the elastance functions which depend on time.
Definition ChamberSphere.cpp:113
void update_time(SparseSystem &system, std::vector< double > &parameters) override
Update the time-dependent contributions of the element in a sparse system.
Definition ChamberSphere.cpp:45
void setup_dofs(DOFHandler &dofhandler) override
Set up the degrees of freedom (DOF) of the block.
Definition ChamberSphere.cpp:8
void set_material(std::unique_ptr< SphereMaterial > m) override
Set wall material (for ChamberSphere blocks).
Definition ChamberSphere.cpp:109
Model of 0D elements.
Definition Model.h:55
Handles the properties of input parameters.
Definition Parameter.h:100