svZeroDSolver
Loading...
Searching...
No Matches
ActiveStress.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 ActiveStress.h
6 * @brief Active stress models for chamber blocks
7 */
8
9#ifndef SVZERODSOLVER_MODEL_ACTIVESTRESS_HPP_
10#define SVZERODSOLVER_MODEL_ACTIVESTRESS_HPP_
11
12#include <Eigen/Core>
13#include <list>
14#include <memory>
15#include <string>
16#include <vector>
17
18#include "ActivationFunction.h"
19#include "Parameter.h"
20#include "ParameterHolder.h"
21#include "SparseSystem.h"
22
23/**
24 * @brief Base class for chamber active stress models
25 *
26 * An ActiveStress owns the dynamics of a chamber's active stress \f$\tau\f$.
27 * Subclasses may introduce additional internal variables and equations
28 * beyond ChamberSphere's fixed core state, and write directly into the same
29 * global SparseSystem that ChamberSphere writes into, using indices that are
30 * a fixed offset into ChamberSphere's own \ref Block::global_var_ids and
31 * \ref Block::global_eqn_ids arrays (which are passed down unchanged).
32 *
33 * ChamberSphere::setup_dofs() always registers, in this order:
34 * internal variables `radius, velo, stress, active_stress, volume,
35 * <extra_var_names()...>` and equations `momentum, spherical_stress,
36 * volume_change, acceleration, mass_conservation, pressure_equality,
37 * <this model's equations...>`, so the offsets below are invariant across
38 * ActiveStress subclasses.
39 *
40 * Post-processing variables are registered separately and land at the end
41 * of global_var_ids: `passive_stress, <extra_output_names()...>`. Their
42 * indices are therefore not fixed, so ChamberSphere passes the offset of
43 * the first one down to \ref update_outputs.
44 */
46 public:
47 /**
48 * @name Fixed layout of ChamberSphere's always-present ("core") state
49 *
50 * Indices into the full \ref Block::global_var_ids / \ref
51 * Block::global_eqn_ids arrays that ChamberSphere passes down unchanged.
52 */
53 ///@{
54 static constexpr int RADIUS_VAR =
55 4; ///< Radius position within ChamberSphere's own global_var_ids array
56 static constexpr int VELO_VAR =
57 5; ///< Radial velocity position within ChamberSphere's own
58 ///< global_var_ids array
59 ///<
60 static constexpr int STRESS_VAR =
61 6; ///< Total wall stress position within ChamberSphere's own
62 ///< global_var_ids array
63 ///<
64 static constexpr int TAU_VAR =
65 7; ///< Active stress \f$\tau\f$ position within ChamberSphere's own
66 ///< global_var_ids array
67 ///<
68 static constexpr int VOLUME_VAR =
69 8; ///< Volume position within ChamberSphere's own global_var_ids array
70 static constexpr int NUM_CORE_VARS =
71 9; ///< A subclass's own extra
72 ///< variables start at
73 ///< global_var_ids[NUM_CORE_VARS + i]
74 static constexpr int NUM_CORE_EQNS =
75 6; ///< A subclass's own extra
76 ///< equations start at
77 ///< global_eqn_ids[NUM_CORE_EQNS + i]
78 ///@}
79
80 /**
81 * @brief Construct an ActiveStress model
82 *
83 * @param props Parameter name/spec pairs for this active stress type
84 */
85 explicit ActiveStress(
86 const std::vector<std::pair<std::string, InputParameter>>& props);
87
88 /**
89 * @brief Number of internal variables this model owns beyond
90 * ChamberSphere's fixed 5 (radius, velo, stress, active_stress, volume)
91 *
92 * @return Number of extra internal variables
93 */
94 virtual int num_extra_vars() const { return 0; }
95
96 /**
97 * @brief Names of this model's extra internal variables, in registration
98 * order (appended immediately after "volume")
99 *
100 * @return List of extra internal variable names
101 */
102 virtual std::list<std::string> extra_var_names() const { return {}; }
103
104 /**
105 * @brief Names of this model's post-processing variables, in registration
106 * order (appended immediately after "passive_stress")
107 *
108 * @return List of extra post-processing variable names
109 */
110 virtual std::list<std::string> extra_output_names() const { return {}; }
111
112 /**
113 * @brief Compute this model's post-processing variables
114 *
115 * @param y Accepted state vector, written into
116 * @param ydot Accepted derivative of the state vector
117 * @param global_var_ids ChamberSphere's global variable indices
118 * @param output_base Position of this model's first post-processing
119 * variable within \p global_var_ids
120 */
121 virtual void update_outputs(
122 Eigen::Matrix<double, Eigen::Dynamic, 1>& y,
123 const Eigen::Matrix<double, Eigen::Dynamic, 1>& ydot,
124 const std::vector<int>& global_var_ids, int output_base) {
125 (void)y;
126 (void)ydot;
127 (void)global_var_ids;
128 (void)output_base;
129 }
130
131 /**
132 * @brief Number of equations this model owns beyond ChamberSphere's fixed
133 * 6 core equations. Every ActiveStress supplies at least the equation
134 * defining \f$\tau\f$.
135 *
136 * @return Number of extra equations
137 */
138 virtual int num_extra_equations() const = 0;
139
140 /**
141 * @brief Constant (time- and solution-independent) contributions
142 *
143 * @param system System to update contributions at
144 * @param global_eqn_ids ChamberSphere's global equation indices
145 * @param global_var_ids ChamberSphere's global variable indices
146 */
147 virtual void update_constant(SparseSystem& system,
148 const std::vector<int>& global_eqn_ids,
149 const std::vector<int>& global_var_ids) {
150 (void)system;
151 (void)global_eqn_ids;
152 (void)global_var_ids;
153 }
154
155 /**
156 * @brief Time-dependent contributions
157 *
158 * @param system System to update contributions at
159 * @param global_eqn_ids ChamberSphere's global equation indices
160 * @param global_var_ids ChamberSphere's global variable indices
161 * @param activation_signal The chamber's ActivationFunction evaluated at
162 * the current time
163 */
164 virtual void update_time(SparseSystem& system,
165 const std::vector<int>& global_eqn_ids,
166 const std::vector<int>& global_var_ids,
167 double activation_signal) {
168 (void)system;
169 (void)global_eqn_ids;
170 (void)global_var_ids;
171 (void)activation_signal;
172 }
173
174 /**
175 * @brief Solution-dependent contributions
176 *
177 * @param system System to update contributions at
178 * @param global_eqn_ids ChamberSphere's global equation indices
179 * @param global_var_ids ChamberSphere's global variable indices
180 * @param y Current solution
181 * @param dy Current derivative of the solution
182 * @param radius0 Reference radius \f$r_0\f$ of the chamber
183 * @param activation_signal The chamber's ActivationFunction evaluated at
184 * the current time
185 */
186 virtual void update_solution(
187 SparseSystem& system, const std::vector<int>& global_eqn_ids,
188 const std::vector<int>& global_var_ids,
189 const Eigen::Matrix<double, Eigen::Dynamic, 1>& y,
190 const Eigen::Matrix<double, Eigen::Dynamic, 1>& dy, double radius0,
191 double activation_signal) = 0;
192
193 /**
194 * @brief Type of activation signal this active stress model needs
195 *
196 * Checked against the chamber's ActivationFunction::signal_type in
197 * ChamberSphere::setup_dofs to catch mismatched pairings (e.g.
198 * strain_dependent active stress with a normalized activation function).
199 *
200 * @return The required ActivationSignalType
201 */
203
204 /**
205 * @brief Factory: create an active stress model from a type string
206 *
207 * @param type_str One of: "strain_independent", "strain_dependent"
208 * @return Unique pointer to the created active stress model
209 */
210 static std::unique_ptr<ActiveStress> create(const std::string& type_str);
211};
212
213/**
214 * @brief Strain-independent active stress model
215 *
216 * Owns 1 extra equation (the \f$\tau\f$ ODE) and 0 extra variables:
217 * \f[
218 * \dot{\tau} + |a| \tau - \sigma_\text{max} a_+ = 0, \quad a_+ = \max(a, 0),
219 * \quad a = f \alpha_\text{max} + (1 - f) \alpha_\text{min}
220 * \f]
221 * where \f$f \in [0, 1]\f$ is the activation function.
222 *
223 * Parameters: `alpha_max`, `alpha_min`, `sigma_max`
224 */
225class StrainIndependentActiveStress : public ActiveStress {
226 public:
227 StrainIndependentActiveStress()
228 : ActiveStress({{"alpha_max", InputParameter()},
229 {"alpha_min", InputParameter()},
230 {"sigma_max", InputParameter()}}) {}
231
232 int num_extra_equations() const override { return 1; }
233
237
238 void update_constant(SparseSystem& system,
239 const std::vector<int>& global_eqn_ids,
240 const std::vector<int>& global_var_ids) override;
241
242 void update_time(SparseSystem& system, const std::vector<int>& global_eqn_ids,
243 const std::vector<int>& global_var_ids,
244 double activation_signal) override;
245
246 void update_solution(SparseSystem& system,
247 const std::vector<int>& global_eqn_ids,
248 const std::vector<int>& global_var_ids,
249 const Eigen::Matrix<double, Eigen::Dynamic, 1>& y,
250 const Eigen::Matrix<double, Eigen::Dynamic, 1>& dy,
251 double radius0, double activation_signal) override;
252
253 private:
254 double act_ = 0.0; ///< Rate coefficient
255 double act_plus_ = 0.0; ///< Positive part of act_, act_plus_ = max(act_, 0)
256};
257
258/**
259 * @brief Strain-dependent active stress model from \cite caruel13
260 *
261 * Owns 8 extra equations and 7 extra variables (\f$e_c, \tau_c, k_c,
262 * \omega, \sigma_c, \sigma_s, e_s\f$, in that order):
263 * \f[
264 * \tau = E_s \frac{e_{1D} - e_c}{(1 + 2 e_c)^2}
265 * \f]
266 * with \f$e_{1D}\f$ the strain in fiber direction (a function of the
267 * chamber's radius), and evolution equations
268 * \f[
269 * \dot{\omega} = \frac{1}{\alpha_r}(m_0 - \omega)
270 * \f]
271 * \f[
272 * \dot{e}_c = \frac{1}{\mu}\left(E_s \frac{(e_{1D} - e_c)(1 + 2 e_{1D})}
273 * {(1 + 2 e_c)^3} - \tau_c\right)
274 * \f]
275 * \f[
276 * \dot{k}_c = -(|u|_+ + \omega |u|_- + \alpha |\dot{e}_c|) k_c + n_0 k_0 |u|_+
277 * \f]
278 * \f[
279 * \dot{\tau}_c = -(|u|_+ + \omega |u|_- + \alpha |\dot{e}_c|) \tau_c + n_0
280 * \sigma_0 |u|_+ + k_c \dot{e}_c
281 * \f]
282 * and the additional outputs (sarcomere stress, series element stress and
283 * strain)
284 * \f[
285 * \sigma_c = \tau_c + \mu \dot{e}_c, \quad
286 * \sigma_s = \tau (1 + 2 e_c), \quad
287 * e_s = \frac{\sigma_s}{E_s}
288 * \f]
289 * where \f$n_0\f$ (activation strain-dependence) and \f$m_0\f$ (relaxation
290 * strain-dependence) are piecewise-linear functions of \f$e_c\f$, given as
291 * break point tables (`n0_e_c`/`n0_values` and `m0_e_c`/`m0_values`) and
292 * evaluated with \ref linear_interpolate, and \f$u(t)\f$ is a reaction-rate
293 * signal supplied by the chamber's ActivationFunction (e.g. \ref
294 * PiecewiseRateActivation).
295 *
296 * Parameters: `E_s`, `mu`, `alpha_r`, `alpha`, `k_0`, `sigma_0`, `n0_e_c`,
297 * `n0_values`, `m0_e_c`, `m0_values`
298 */
299class StrainDependentActiveStress : public ActiveStress {
300 public:
301 StrainDependentActiveStress()
302 : ActiveStress({{"E_s", InputParameter()},
303 {"mu", InputParameter()},
304 {"alpha_r", InputParameter()},
305 {"alpha", InputParameter()},
306 {"k_0", InputParameter()},
307 {"sigma_0", InputParameter()},
308 {"n0_e_c", InputParameter(false, true)},
309 {"n0_values", InputParameter(false, true)},
310 {"m0_e_c", InputParameter(false, true)},
311 {"m0_values", InputParameter(false, true)}}) {}
312
313 int num_extra_vars() const override { return 4; }
314 std::list<std::string> extra_var_names() const override {
315 return {"e_c", "tau_c", "k_c", "omega"};
316 }
317 std::list<std::string> extra_output_names() const override {
318 return {"sigma_c", "sigma_s", "e_s"};
319 }
320 int num_extra_equations() const override { return 5; }
321
322 void update_outputs(Eigen::Matrix<double, Eigen::Dynamic, 1>& y,
323 const Eigen::Matrix<double, Eigen::Dynamic, 1>& ydot,
324 const std::vector<int>& global_var_ids,
325 int output_base) override;
326
330
331 void update_constant(SparseSystem& system,
332 const std::vector<int>& global_eqn_ids,
333 const std::vector<int>& global_var_ids) override;
334
335 void update_time(SparseSystem& system, const std::vector<int>& global_eqn_ids,
336 const std::vector<int>& global_var_ids,
337 double activation_signal) override;
338
339 void update_solution(SparseSystem& system,
340 const std::vector<int>& global_eqn_ids,
341 const std::vector<int>& global_var_ids,
342 const Eigen::Matrix<double, Eigen::Dynamic, 1>& y,
343 const Eigen::Matrix<double, Eigen::Dynamic, 1>& dy,
344 double radius0, double activation_signal) override;
345
346 private:
347 /**
348 * @name Extra variable/equation positions within the full ChamberSphere
349 * global_var_ids/global_eqn_ids arrays
350 *
351 * Reproduce the exact global_var_ids/global_eqn_ids indices that the
352 * ChamberSphere used.
353 */
354 ///@{
355 static constexpr int E_C_VAR = NUM_CORE_VARS + 0; // 9
356 static constexpr int TAU_C_VAR = NUM_CORE_VARS + 1; // 10
357 static constexpr int K_C_VAR = NUM_CORE_VARS + 2; // 11
358 static constexpr int OMEGA_VAR = NUM_CORE_VARS + 3; // 12
359 static constexpr int TAU_EQN = NUM_CORE_EQNS + 0; // 6
360 static constexpr int OMEGA_EQN = NUM_CORE_EQNS + 1; // 7
361 static constexpr int E_C_EQN = NUM_CORE_EQNS + 2; // 8
362 static constexpr int K_C_EQN = NUM_CORE_EQNS + 3; // 9
363 static constexpr int TAU_C_EQN = NUM_CORE_EQNS + 4; // 10
364 // Post-processing variables, offset from the first one ChamberSphere
365 // passes to update_outputs
366 static constexpr int SIGMA_C_OUT = 0;
367 static constexpr int SIGMA_S_OUT = 1;
368 static constexpr int E_S_OUT = 2;
369 ///@}
370
371 /**
372 * @brief Update the strain-dependent coefficients used across this
373 * model's equations
374 *
375 * @param e_c Current sarcomere element strain
376 */
377 void update_active_stress_values(double e_c);
378
379 double n_0_ = 0.0; // activation strain-dependence
380 double m_0_ = 0.0; // relaxation strain-dependence
381 double dn_0_de_c_ = 0.0; // d(n_0)/d(e_c), local slope of n0_e_c/n0_values
382 double dm_0_de_c_ = 0.0; // d(m_0)/d(e_c), local slope of m0_e_c/m0_values
383 double u_plus_ = 0.0; // positive part of the reaction-rate signal
384 double u_minus_ = 0.0; // negative part of the reaction-rate signal
385};
386
387#endif // SVZERODSOLVER_MODEL_ACTIVESTRESS_HPP_
Activation function classes for cardiac chamber models.
ActivationSignalType
Type of signal an ActivationFunction produces.
Definition ActivationFunction.h:27
@ normalized
f(t) in [0, 1], used by most activation functions
Definition ActivationFunction.h:28
@ rate
Definition ActivationFunction.h:29
model::Parameter source file
Common base for chamber sub-components configured from input parameters.
SparseSystem source file.
static constexpr int TAU_VAR
Definition ActiveStress.h:64
virtual std::list< std::string > extra_output_names() const
Names of this model's post-processing variables, in registration order (appended immediately after "p...
Definition ActiveStress.h:110
virtual int num_extra_equations() const =0
Number of equations this model owns beyond ChamberSphere's fixed 6 core equations....
static constexpr int VELO_VAR
Definition ActiveStress.h:56
virtual ActivationSignalType required_signal_type() const =0
Type of activation signal this active stress model needs.
virtual void update_constant(SparseSystem &system, const std::vector< int > &global_eqn_ids, const std::vector< int > &global_var_ids)
Constant (time- and solution-independent) contributions.
Definition ActiveStress.h:147
virtual int num_extra_vars() const
Number of internal variables this model owns beyond ChamberSphere's fixed 5 (radius,...
Definition ActiveStress.h:94
static std::unique_ptr< ActiveStress > create(const std::string &type_str)
Factory: create an active stress model from a type string.
Definition ActiveStress.cpp:14
virtual void update_outputs(Eigen::Matrix< double, Eigen::Dynamic, 1 > &y, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &ydot, const std::vector< int > &global_var_ids, int output_base)
Compute this model's post-processing variables.
Definition ActiveStress.h:121
static constexpr int NUM_CORE_VARS
Definition ActiveStress.h:70
virtual void update_time(SparseSystem &system, const std::vector< int > &global_eqn_ids, const std::vector< int > &global_var_ids, double activation_signal)
Time-dependent contributions.
Definition ActiveStress.h:164
ActiveStress(const std::vector< std::pair< std::string, InputParameter > > &props)
Construct an ActiveStress model.
Definition ActiveStress.cpp:10
virtual void update_solution(SparseSystem &system, const std::vector< int > &global_eqn_ids, const std::vector< int > &global_var_ids, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &y, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &dy, double radius0, double activation_signal)=0
Solution-dependent contributions.
static constexpr int STRESS_VAR
Definition ActiveStress.h:60
static constexpr int RADIUS_VAR
Radius position within ChamberSphere's own global_var_ids array.
Definition ActiveStress.h:54
virtual std::list< std::string > extra_var_names() const
Names of this model's extra internal variables, in registration order (appended immediately after "vo...
Definition ActiveStress.h:102
static constexpr int VOLUME_VAR
Volume position within ChamberSphere's own global_var_ids array.
Definition ActiveStress.h:68
static constexpr int NUM_CORE_EQNS
Definition ActiveStress.h:74
ParameterHolder(const std::vector< std::pair< std::string, InputParameter > > &props)
Construct a ParameterHolder.
Definition ParameterHolder.cpp:5
Sparse system.
Definition SparseSystem.h:30
void update_time(SparseSystem &system, const std::vector< int > &global_eqn_ids, const std::vector< int > &global_var_ids, double activation_signal) override
Time-dependent contributions.
Definition ActiveStress.cpp:97
void update_solution(SparseSystem &system, const std::vector< int > &global_eqn_ids, const std::vector< int > &global_var_ids, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &y, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &dy, double radius0, double activation_signal) override
Solution-dependent contributions.
Definition ActiveStress.cpp:128
ActivationSignalType required_signal_type() const override
Type of activation signal this active stress model needs.
Definition ActiveStress.h:327
std::list< std::string > extra_var_names() const override
Names of this model's extra internal variables, in registration order (appended immediately after "vo...
Definition ActiveStress.h:314
int num_extra_vars() const override
Number of internal variables this model owns beyond ChamberSphere's fixed 5 (radius,...
Definition ActiveStress.h:313
void update_outputs(Eigen::Matrix< double, Eigen::Dynamic, 1 > &y, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &ydot, const std::vector< int > &global_var_ids, int output_base) override
Compute this model's post-processing variables.
Definition ActiveStress.cpp:216
std::list< std::string > extra_output_names() const override
Names of this model's post-processing variables, in registration order (appended immediately after "p...
Definition ActiveStress.h:317
void update_constant(SparseSystem &system, const std::vector< int > &global_eqn_ids, const std::vector< int > &global_var_ids) override
Constant (time- and solution-independent) contributions.
Definition ActiveStress.cpp:72
int num_extra_equations() const override
Number of equations this model owns beyond ChamberSphere's fixed 6 core equations....
Definition ActiveStress.h:320
ActivationSignalType required_signal_type() const override
Type of activation signal this active stress model needs.
Definition ActiveStress.h:234
int num_extra_equations() const override
Number of equations this model owns beyond ChamberSphere's fixed 6 core equations....
Definition ActiveStress.h:232
void update_time(SparseSystem &system, const std::vector< int > &global_eqn_ids, const std::vector< int > &global_var_ids, double activation_signal) override
Time-dependent contributions.
Definition ActiveStress.cpp:37
void update_solution(SparseSystem &system, const std::vector< int > &global_eqn_ids, const std::vector< int > &global_var_ids, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &y, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &dy, double radius0, double activation_signal) override
Solution-dependent contributions.
Definition ActiveStress.cpp:52
void update_constant(SparseSystem &system, const std::vector< int > &global_eqn_ids, const std::vector< int > &global_var_ids) override
Constant (time- and solution-independent) contributions.
Definition ActiveStress.cpp:31
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