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