svMultiPhysics
Loading...
Searching...
No Matches
ActiveStress.h
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#ifndef ACTIVE_STRESS_H
5#define ACTIVE_STRESS_H
6
7#include "Array.h"
8#include "Parameters.h"
9#include "Vector.h"
10#include "consts.h"
11#include "factory.h"
12#include "mat_fun.h"
13
14#include "CmMod.h"
15
16#include <memory>
17
18/**
19 * @brief Return whether a certain equation type can be solved with active
20 * stress.
21 */
22bool supports_active_stress(const consts::EquationType eq_type);
23
24/**
25 * @brief Abstract active stress class.
26 *
27 * ## Table of contents
28 *
29 * - @ref activestress-overview
30 * - @ref activestress-inputs
31 * - @ref activestress-directions
32 * - @ref activestress-implementing
33 * - @ref activestress-coupling
34 *
35 * ## Overview {#activestress-overview}
36 *
37 * This class provides an interface for defining active stress models, i.e.
38 * models that, in the context of structural mechanics of muscular tissue,
39 * compute an active tension representing the contribution of muscular
40 * contraction to the constitiutive law.
41 *
42 * The class assumes that the active tension can be expressed as
43 * @f[
44 * \Tact = \Tact(t, \calcium, \fiberstretch, \fiberstretchrate,
45 * \astressstate),
46 * @f]
47 * where @f$\calcium@f$ is the intracellular calcium concentration,
48 * @f$\fiberstretch@f$ is the fiber stretch, @f$\fiberstretchrate@f$ is the
49 * fiber stretch rate, and @f$\astressstate@f$ is a vector of internal state
50 * variables, representing the state of contraction.
51 *
52 * The expression assumed above implies that the active tension is a local
53 * function of the variables it depends on, that is the active tension at a
54 * given point only depends on the value of other variables at that same point.
55 * Accordingly, this class works nodally, storing the state of contraction at
56 * every mesh node and evaluating the active tension from it, on demand,
57 * through @ref ActiveStress::compute_tension.
58 *
59 * ## Preprocessing of model inputs {#activestress-inputs}
60 *
61 * Two parameters, set at the top level of the @c <Active_stress> XML element
62 * and shared by all models, modify the inputs before they reach the model:
63 *
64 * - @c Calcium_scaling_factor (default @c 1.0): calcium is multiplied by this
65 * factor, e.g. to convert between the units of the electrophysiology model
66 * and those expected by the active stress model.
67 * - @c Disable_force_strain_rate_feedback (default @c false): if @c true, the
68 * fiber stretch rate is set to zero, and its computation is skipped.
69 *
70 * Both are applied once, in @ref update, so that @ref advance_time_step_local
71 * receives already scaled calcium and an already zeroed stretch rate. Models
72 * that do not use calcium or the stretch rate ignore them.
73 *
74 * ## Directional distribution of active stress {#activestress-directions}
75 *
76 * In muscular mechanics models, active stress normally acts only along the
77 * direction of fibers @f$\fiberdirection@f$, reflecting the fact that
78 * contractile units are aligned with fibers. However, one might want to account
79 * for fiber dispersion, i.e. the fact that fibers are not perfectly and
80 * regularly aligned, but rather have a certain distribution of orientations
81 * centered around the principal direction @f$\fiberdirection@f$.
82 *
83 * This can be surrogated by defining the active stress tensor as
84 * @f[
85 * S_\text{act} = \Tact \left(
86 * \eta_f \fiberdirection \otimes \fiberdirection +
87 * \eta_s \sheetdirection \otimes \sheetdirection +
88 * \eta_n \sheetnormaldirection \otimes \sheetnormaldirection
89 * \right),
90 * @f]
91 * where @f$\sheetdirection@f$ and @f$\sheetnormaldirection@f$ are the sheet and
92 * sheet-normal directions, respectively, and @f$\eta_f@f$, @f$\eta_s@f$, and
93 * @f$\eta_n@f$ are coefficients that define the distribution the active tension
94 * along the three principal directions. The coefficients must be such that
95 * @f$\eta_f + \eta_s + \eta_n = 1@f$.
96 *
97 * This class stores the values of @f$\eta_f@f$, @f$\eta_s@f$ and @f$\eta_n@f$,
98 * and applies them in @ref ActiveStress::compute_tension, which returns
99 * @f$\eta_f \Tact@f$, @f$\eta_s \Tact@f$ and @f$\eta_n \Tact@f$, bundled in an
100 * @ref ActiveTension.
101 *
102 * ## Implementing concrete active stress models {#activestress-implementing}
103 *
104 * To implement a new active stress model, the following steps need to be taken:
105 *
106 * 1. Create a new class derived from @ref ActiveStress.
107 * 2. Override the methods @ref init_local, @ref advance_time_step_local,
108 * @ref compute_active_tension_local and
109 * @ref compute_active_tension_derivative_local, defining the initial
110 * condition, time evolution, active tension and its partial derivative with
111 * respect to the fiber stretch, respectively, for a single node.
112 * 3. Create a new class derived from @ref ActiveStressModelParameters to store
113 * the parameters specific to the new active stress model.
114 * 4. Override the methods @ref get_parameters,
115 * @ref read_model_specific_parameters and
116 * @ref distribute_model_specific_parameters to manage the parameters of the
117 * new active stress model.
118 * 5. Register the new class into the active stress model factory by using the
119 * macro @ref REGISTER_ACTIVE_STRESS_MODEL. The macro should be called in a
120 * `.cpp` file, not in a header file.
121 *
122 * Notice that if the model is expressed in terms of a system of ODEs, it can
123 * be implemented by deriving from @ref ActiveStressODE, which already addresses
124 * some of the points above.
125 *
126 * Models need no code of their own for calcium scaling or for disabling the
127 * force-strain-rate feedback, as these are applied by this class (see
128 * @ref activestress-inputs).
129 *
130 * ## Coupling with the structural mechanics problem {#activestress-coupling}
131 *
132 * The active tension depends on the fiber stretch @f$\fiberstretch@f$ both
133 * directly, through the expression of @f$\Tact@f$, and indirectly, through the
134 * state @f$\astressstate@f$, which is itself driven by the fiber stretch. The
135 * mechanics problem, in turn, depends on @f$\Tact@f$.
136 *
137 * Explicit time discretization for the direct dependence was observed to lead
138 * to instabilities. Accordingly, the direct dependence is discretized
139 * implicitly, that is the active tension is recomputed within the nonlinear
140 * iterations for the structure problem that uses ActiveStress. To facilitate
141 * the convergence of nonlinear iterations, this class also allows to compute
142 * the derivative @f$\frac{\partial\Tact}{\partial\fiberstretch}@f$, which is
143 * used to assemble tangent terms associated to this in the structural system.
144 *
145 * Indirect dependence was not observed to give rise to instabilities.
146 * Accordingly, it is discretized explicitly by default, meaning that the state
147 * is updated once per time step evaluating the fiber stretch
148 * @f$\fiberstretch@f$ using the displacement from the previous time step. The
149 * user can change this behavior by setting the parameter @c
150 * Implicit_state_coupling to @c true in the XML file. This will make the state
151 * update every nonlinear iteration. No tangent terms are computed for this
152 * contribution, so nonlinear iterations can be expected to converge more slowly
153 * when this is enabled.
154 */
156public:
157 /**
158 * @brief Active tension information at a point.
159 *
160 * This struct bundles the active tension along the three principal
161 * directions (fibers @f$\fiberdirection@f$, sheets @f$\sheetdirection@f$ and
162 * sheet normals @f$\sheetnormaldirection@f$) and their partial derivatives
163 * with respect to the fiber stretch.
164 *
165 * It is a convenience data structure used to pass this information to
166 * functions that consume active tension information (e.g. the structural
167 * mechanics assembly functions).
168 */
170 /// Tension along the fiber direction, @f$\eta_f \Tact@f$.
171 double fibers = 0.0;
172
173 /// Tension along the sheet direction, @f$\eta_s \Tact@f$.
174 double sheets = 0.0;
175
176 /// Tension along the sheet-normal direction, @f$\eta_n \Tact@f$.
177 double sheet_normals = 0.0;
178
179 /// Derivative of @ref fibers with respect to the fiber stretch, at fixed
180 /// state, @f$\eta_f \pdv*{\Tact}{\fiberstretch}@f$.
181 double d_fibers = 0.0;
182
183 /// Derivative of @ref sheets with respect to the fiber stretch, at fixed
184 /// state, @f$\eta_s \pdv*{\Tact}{\fiberstretch}@f$.
185 double d_sheets = 0.0;
186
187 /// Derivative of @ref sheet_normals with respect to the fiber stretch, at
188 /// fixed state, @f$\eta_n \pdv*{\Tact}{\fiberstretch}@f$.
189 double d_sheet_normals = 0.0;
190 };
191
192 /**
193 * @brief Helper to evaluate active tension at quadrature points.
194 *
195 * The active stress model stores the state at the degrees of freedom, but the
196 * active tension needs to be evaluated at quadrature points. This class
197 * allows to do that by interpolating the state to quadrature points and then
198 * evaluating the active tension there.
199 */
200 class Evaluator {
201 public:
202 /**
203 * @brief Update the evaluator for a given element.
204 *
205 * @param[in] active_stress Active stress model of the domain the element
206 * belongs to.
207 * @param[in] nodes Indices of the mesh nodes of the element.
208 */
209 void update(const ActiveStress &active_stress, const Vector<int> &nodes);
210
211 /**
212 * @brief Reset this evaluator so that @ref evaluate returns zero tension,
213 * until the next call to @ref update.
214 *
215 * Used for elements whose domain has no active stress model.
216 */
217 void clear() { active_stress_ = nullptr; }
218
219 /**
220 * @brief Compute the active tension at a quadrature point.
221 *
222 * @param[in] N Shape functions at the quadrature point, of the same nodes
223 * the state was gathered at by @ref update.
224 * @param[in] F Deformation gradient at the quadrature point.
225 * @param[in] fibers Fiber directions of the element, one per column, the first
226 * column being the fiber direction itself.
227 *
228 * @return Active tension along fibers, sheets and sheet normals, and their
229 * derivatives with respect to the fiber stretch, bundled in an object of
230 * type @ref ActiveTension.
231 *
232 * @tparam nsd Number of spatial dimensions.
233 */
234 template <int nsd>
236 evaluate(const Eigen::Ref<const Eigen::VectorXd> &N,
237 const mat_fun::Matrix<nsd> &F,
238 const Eigen::Ref<const Eigen::Matrix<double, nsd, Eigen::Dynamic>>
239 &fibers) const;
240
241 private:
242 /// Active stress model of the domain the element belongs to, or null if
243 /// @ref clear was called last, or if this evaluator was never updated.
244 const ActiveStress *active_stress_ = nullptr;
245
246 /// State variables at the element nodes, of size (n_states, element
247 /// nodes).
248 Eigen::MatrixXd state_;
249
250 /// State variables interpolated at the quadrature point, of size
251 /// n_states. Scratch storage for @ref evaluate, mutable so that it can
252 /// stay const.
253 mutable Vector<double> interpolated_state;
254 };
255
256 /// Grants @ref Evaluator direct access to @ref states.
257 friend class Evaluator;
258
259 /**
260 * @brief Constructor.
261 *
262 * @param n_states_ Number of state variables for this model.
263 * @param needs_fiber_stretch Whether this model uses the fiber stretch
264 * passed to @ref update. This flag can be used to determine whether fiber
265 * stretch computation can be skipped for efficiency.
266 * @param needs_fiber_stretch_rate Whether this model uses the fiber stretch
267 * rate passed to @ref update. This flag can be used to determine whether
268 * fiber stretch rate computation can be skipped for efficiency.
269 */
274
275 /**
276 * @brief Virtual destructor.
277 */
278 virtual ~ActiveStress() = default;
279
280 /**
281 * @brief Construct an instance of model parameters for this model.
282 */
283 virtual std::unique_ptr<ActiveStressModelParameters>
284 get_parameters() const = 0;
285
286 /**
287 * @brief Read model parameters from a parameter object.
288 */
289 void read_parameters(const ActiveStressParameters &params);
290
291 /**
292 * @brief Distribute model parameters to all parallel processes.
293 */
294 void distribute_parameters(const CmMod &cm_mod, const cmType &cm);
295
296 /**
297 * @brief Get the state vector at a given mesh node.
298 *
299 * @param[in] Ac Index of the mesh node.
300 */
301 Vector<double> get_state(const unsigned int Ac) const {
302 return states.col(Ac);
303 }
304
305 /**
306 * @brief Compute the active tension given the state vector and fiber stretch.
307 *
308 * @param[in] state State vector at the point.
309 * @param[in] fiber_stretch Fiber stretch at the point.
310 *
311 * @return Active tension along fibers, sheets and sheet normals, and their
312 * derivatives with respect to the fiber stretch, bundled in an object of
313 * type @ref ActiveTension.
314 */
316 const double fiber_stretch) const {
317 const double tension = compute_active_tension_local(state, fiber_stretch);
318 const double derivative =
319 compute_active_tension_derivative_local(state, fiber_stretch);
320
321 return {eta_f * tension, eta_s * tension, eta_n * tension,
322 eta_f * derivative, eta_s * derivative, eta_n * derivative};
323 }
324
325 /**
326 * @brief Initialize the model.
327 *
328 * Allocates the internal state vector and initializes it with the model's
329 * initial conditions.
330 *
331 * @param[in] tnNo Total number of mesh nodes for the current rank.
332 */
333 virtual void init(const unsigned int tnNo);
334
335 /**
336 * @brief Begin a new time step.
337 *
338 * Stores the current state as the initial condition of the time step. Must be
339 * called once per time step, before any call to @ref update.
340 */
341 virtual void time_advance();
342
343 /**
344 * @brief Update the state over the current time step.
345 *
346 * Advances the state stored by @ref time_advance over one time step, using
347 * the given calcium, fiber stretch and fiber stretch rate.
348 *
349 * This function may be called more than once per time step: every call
350 * restarts from the state stored by @ref time_advance, so the resulting state
351 * depends only on the arguments of the last call.
352 *
353 * @param[in] t Current time (i.e. the time instant being advanced to).
354 * @param[in] dt Time step size.
355 * @param[in] calcium Calcium concentration at every node.
356 * @param[in] fiber_stretch Fiber stretch at every node. This is usually
357 * computed with post::fib_stretch.
358 * @param[in] fiber_stretch_rate Fiber stretch rate at every node. This is
359 * usually computed with post::fib_stretch_rate.
360 */
361 virtual void update(const double t, const double dt,
362 const Vector<double> &calcium,
363 const Vector<double> &fiber_stretch,
364 const Vector<double> &fiber_stretch_rate);
365
366 /**
367 * @brief Whether this model uses the fiber stretch passed to @ref update.
368 * This flag can be used to determine whether fiber stretch computation can be
369 * skipped for efficiency.
370 */
372
373 /**
374 * @brief Whether this model uses the fiber stretch rate passed to
375 * @ref update. This flag can be used to determine whether fiber stretch rate
376 * computation can be skipped for efficiency.
377 */
379
380 /**
381 * @brief Whether the state of this model is updated within the nonlinear
382 * iterations of the mechanics problem, i.e. whether the indirect dependence
383 * of the active tension on the fiber stretch is treated implicitly.
384 */
386
387 /// Number of state variables for this model.
388 const unsigned int n_states;
389
390protected:
391 /**
392 * @brief Read model parameters from a parameter object.
393 *
394 * This method needs to be overridden by derived classes to read the
395 * parameters specific to the concrete model they implement.
396 */
397 virtual void
399
400 /**
401 * @brief Distribute model parameters to all parallel processes.
402 *
403 * This method needs to be overridden by derived classes to distribute the
404 * parameters specific to the concrete model they implement to all parallel
405 * processes.
406 */
407 virtual void distribute_model_specific_parameters(const CmMod &cm_mod,
408 const cmType &cm) = 0;
409
410 /**
411 * @brief Initialize the state vector for a single node.
412 *
413 * @param[out] state State vector for a single node, to be initialized by
414 * this function.
415 */
416 virtual void init_local(Vector<double> &state) const = 0;
417
418 /**
419 * @brief Advance in time for a single node.
420 *
421 * @param[in] t Current time (i.e. the time instant being advanced to).
422 * @param[in] dt Time step size.
423 * @param[in] calcium Calcium concentration at the current node, already
424 * multiplied by @ref calcium_scaling_factor_.
425 * @param[in] fiber_stretch Fiber stretch at the current node.
426 * @param[in] fiber_stretch_rate Fiber stretch rate at the current node, or
427 * zero if @ref disable_force_strain_rate_feedback_ is set.
428 * @param[in,out] state State vector for a single node, to be updated by
429 * this function.
430 */
431 virtual void advance_time_step_local(const double t, const double dt,
432 const double calcium,
433 const double fiber_stretch,
434 const double fiber_stretch_rate,
435 Vector<double> &state) const = 0;
436
437 /**
438 * @brief Compute the active tension for a single node.
439 *
440 * @param[in] state State vector for a single node.
441 * @param[in] fiber_stretch Fiber stretch at the current node.
442 */
443 virtual double
445 const double fiber_stretch) const = 0;
446
447 /**
448 * @brief Compute the partial derivative of the active tension with respect to
449 * the fiber stretch, at fixed state, for a single node.
450 *
451 * @param[in] state State vector for a single node.
452 * @param[in] fiber_stretch Fiber stretch at the current node.
453 */
454 virtual double
456 const double fiber_stretch) const = 0;
457
458 /**
459 * @brief Backing store for @ref needs_fiber_stretch.
460 */
462
463 /**
464 * @brief Backing store for @ref needs_fiber_stretch_rate.
465 */
467
468 /// Time instant being advanced to. Set by @ref update.
469 double time = 0.0;
470
471 /// State variables for the model.
472 Array<double> states;
473
474 /**
475 * @brief State variables at the beginning of the current time step.
476 *
477 * Set by @ref time_advance and used by @ref update as the initial condition
478 * of every call within the time step.
479 */
481
482 /**
483 * @brief Whether the state of this model is updated within the nonlinear
484 * iterations of the mechanics problem.
485 */
487
488 /// Factor applied to calcium in @ref update before it is passed to
489 /// @ref advance_time_step_local.
491
492 /// If true, the fiber stretch rate passed to @ref advance_time_step_local is
493 /// set to zero, disabling the force-strain-rate feedback.
495
496 /// Active tension coefficient along the fiber direction.
497 double eta_f;
498
499 /// Active tension coefficient along the sheet direction.
500 double eta_s;
501
502 /// Active tension coefficient along the sheet-normal direction.
503 double eta_n;
504};
505
506/**
507 * @brief Alias for the active stress model factory.
508 *
509 * See the documentation for @ref Factory for more details on how this works.
510 */
511using ActiveStressFactory = Factory<ActiveStress>;
512
513/**
514 * @brief Macro to register an active stress model in the factory.
515 */
516#define REGISTER_ACTIVE_STRESS_MODEL(name, type) \
517 REGISTER_IN_FACTORY(ActiveStress, type, name)
518
519#endif
Helper to evaluate active tension at quadrature points.
Definition ActiveStress.h:200
ActiveTension evaluate(const Eigen::Ref< const Eigen::VectorXd > &N, const mat_fun::Matrix< nsd > &F, const Eigen::Ref< const Eigen::Matrix< double, nsd, Eigen::Dynamic > > &fibers) const
Compute the active tension at a quadrature point.
void clear()
Reset this evaluator so that evaluate returns zero tension, until the next call to update.
Definition ActiveStress.h:217
void update(const ActiveStress &active_stress, const Vector< int > &nodes)
Update the evaluator for a given element.
Definition ActiveStress.cpp:14
virtual void init_local(Vector< double > &state) const =0
Initialize the state vector for a single node.
double eta_n
Active tension coefficient along the sheet-normal direction.
Definition ActiveStress.h:503
double calcium_scaling_factor_
Definition ActiveStress.h:490
bool implicit_state_coupling() const
Whether the state of this model is updated within the nonlinear iterations of the mechanics problem,...
Definition ActiveStress.h:385
double time
Time instant being advanced to. Set by update.
Definition ActiveStress.h:469
virtual void advance_time_step_local(const double t, const double dt, const double calcium, const double fiber_stretch, const double fiber_stretch_rate, Vector< double > &state) const =0
Advance in time for a single node.
bool needs_fiber_stretch_
Backing store for needs_fiber_stretch.
Definition ActiveStress.h:461
virtual double compute_active_tension_local(const Vector< double > &state, const double fiber_stretch) const =0
Compute the active tension for a single node.
bool disable_force_strain_rate_feedback_
Definition ActiveStress.h:494
virtual double compute_active_tension_derivative_local(const Vector< double > &state, const double fiber_stretch) const =0
Compute the partial derivative of the active tension with respect to the fiber stretch,...
virtual void read_model_specific_parameters(const ActiveStressModelParameters &params)=0
Read model parameters from a parameter object.
virtual void time_advance()
Begin a new time step.
Definition ActiveStress.cpp:114
double eta_f
Active tension coefficient along the fiber direction.
Definition ActiveStress.h:497
bool needs_fiber_stretch_rate_
Backing store for needs_fiber_stretch_rate.
Definition ActiveStress.h:466
void read_parameters(const ActiveStressParameters &params)
Read model parameters from a parameter object.
Definition ActiveStress.cpp:64
bool implicit_state_coupling_
Whether the state of this model is updated within the nonlinear iterations of the mechanics problem.
Definition ActiveStress.h:486
Array< double > states
State variables for the model.
Definition ActiveStress.h:472
double eta_s
Active tension coefficient along the sheet direction.
Definition ActiveStress.h:500
Array< double > states_at_time_step_start
State variables at the beginning of the current time step.
Definition ActiveStress.h:480
const unsigned int n_states
Number of state variables for this model.
Definition ActiveStress.h:388
ActiveTension compute_tension(const Vector< double > &state, const double fiber_stretch) const
Compute the active tension given the state vector and fiber stretch.
Definition ActiveStress.h:315
void distribute_parameters(const CmMod &cm_mod, const cmType &cm)
Distribute model parameters to all parallel processes.
Definition ActiveStress.cpp:83
bool needs_fiber_stretch_rate() const
Whether this model uses the fiber stretch rate passed to update. This flag can be used to determine w...
Definition ActiveStress.h:378
virtual ~ActiveStress()=default
Virtual destructor.
virtual std::unique_ptr< ActiveStressModelParameters > get_parameters() const =0
Construct an instance of model parameters for this model.
bool needs_fiber_stretch() const
Whether this model uses the fiber stretch passed to update. This flag can be used to determine whethe...
Definition ActiveStress.h:371
virtual void distribute_model_specific_parameters(const CmMod &cm_mod, const cmType &cm)=0
Distribute model parameters to all parallel processes.
virtual void init(const unsigned int tnNo)
Initialize the model.
Definition ActiveStress.cpp:98
virtual void update(const double t, const double dt, const Vector< double > &calcium, const Vector< double > &fiber_stretch, const Vector< double > &fiber_stretch_rate)
Update the state over the current time step.
Definition ActiveStress.cpp:116
Vector< double > get_state(const unsigned int Ac) const
Get the state vector at a given mesh node.
Definition ActiveStress.h:301
ActiveStress(const unsigned int n_states_, const bool needs_fiber_stretch, const bool needs_fiber_stretch_rate)
Constructor.
Definition ActiveStress.h:270
Parameters for a generic active stress model.
Definition Parameters.h:1450
Parameters for active stress models.
Definition Parameters.h:1540
The CmMod class duplicates the data structures in the Fortran CMMOD module defined in COMU....
Definition CmMod.h:37
Abstract self-registering factory.
Definition factory.h:30
The Vector template class is used for storing int and double data.
Definition Vector.h:26
The cmType class stores data and defines methods used for mpi communication.
Definition CmMod.h:57
Eigen::Matrix< double, nsd, nsd > Matrix
A 2nd order tensor, nsd x nsd, fixed size and stack allocated. Used for the deformation gradient,...
Definition mat_fun.h:29
Active tension information at a point.
Definition ActiveStress.h:169
double sheet_normals
Tension along the sheet-normal direction, .
Definition ActiveStress.h:177
double d_sheet_normals
Definition ActiveStress.h:189
double d_sheets
Definition ActiveStress.h:185
double fibers
Tension along the fiber direction, .
Definition ActiveStress.h:171
double sheets
Tension along the sheet direction, .
Definition ActiveStress.h:174
double d_fibers
Definition ActiveStress.h:181