svZeroDSolver
Loading...
Searching...
No Matches
ChamberElastanceInductor.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 ChamberElastanceInductor.h
5 * @brief model::ChamberElastanceInductor source file
6 */
7#ifndef SVZERODSOLVER_MODEL_CHAMBERELASTANCEINDUCTOR_HPP_
8#define SVZERODSOLVER_MODEL_CHAMBERELASTANCEINDUCTOR_HPP_
9
10#include <math.h>
11
12#include <memory>
13
14#include "ActivationFunction.h"
15#include "Block.h"
16#include "SparseSystem.h"
17#include "debug.h"
18
19/**
20 * @brief Cardiac chamber with linear elastance and inductor.
21 *
22 * Models a cardiac chamber as a time-varying capacitor (elastance with
23 * specified resting volumes) and an inductor. See \cite kerckhoffs2007coupling
24 * (equations 1 and 2). The addition of the inductor is similar to the models in
25 * \cite sankaran2012patient and \cite menon2023predictors.
26 *
27 * This chamber block can be connected to other blocks using junctions.
28 *
29 * \f[
30 * \begin{circuitikz} \draw
31 * node[left] {$Q_{in}$} [-latex] (0,0) -- (0.8,0);
32 * \draw (1,0) node[anchor=south]{$P_{in}$}
33 * to (1,0)
34 * node[anchor=south]{}
35 * to [L, l=$L$, *-*] (3,0)
36 * node[anchor=south]{$P_{out}$}
37 * (1,0) to [vC, l=$E$, *-] (1,-1.5)
38 * node[ground]{};
39 * \draw [-latex] (3.2,0) -- (4.0,0) node[right] {$Q_{out}$} ;
40 * \end{circuitikz}
41 * \f]
42 *
43 * ### Governing equations
44 *
45 * \f[
46 * P_{in}-E(t)(V_c-V_{rest})=0
47 * \f]
48 *
49 * \f[
50 * P_{in}-P_{out}-L\dot{Q}_{out}=0
51 * \f]
52 *
53 * \f[
54 * Q_{in}-Q_{out}-\dot{V}_c=0
55 * \f]
56 *
57 * ### Local contributions
58 *
59 * \f[
60 * \mathbf{y}^{e}=\left[\begin{array}{lllll}P_{in} & Q_{in} &
61 * P_{out} & Q_{out} & V_c\end{array}\right]^{T} \f]
62 *
63 * \f[
64 * \mathbf{E}^{e}=\left[\begin{array}{ccccc}
65 * 0 & 0 & 0 & 0 & 0\\
66 * 0 & 0 & 0 & -L & 0\\
67 * 0 & 0 & 0 & 0 & -1
68 * \end{array}\right]
69 * \f]
70 *
71 * \f[
72 * \mathbf{F}^{e}=\left[\begin{array}{ccccc}
73 * 1 & 0 & 0 & 0 & -E(t) \\
74 * 1 & 0 & -1 & 0 & 0 \\
75 * 0 & 1 & 0 & -1 & 0
76 * \end{array}\right]
77 * \f]
78 *
79 * \f[
80 * \mathbf{c}^{e}=\left[\begin{array}{c}
81 * E(t) V_{rest} \\
82 * 0 \\
83 * 0
84 * \end{array}\right]
85 * \f]
86 *
87 * where
88 *
89 * \f[
90 * V_{rest}(t)= \{1-A(t)\}(V_{rd}-V_{rs})+V_{rs}
91 * \f]
92 *
93 * \f[
94 * E(t)=(E_{max}-E_{min})A(t) + E_{min}
95 * \f]
96 *
97 * The activation function \f$A(t)\f$ is provided as a separate object
98 * (e.g. half_cosine, fourier, wrapping_cosine).
99 *
100 * ### Parameters
101 *
102 * * `0` Impedance: Outflow inductance \f$L\f$
103 * * `1` Emax: Maximum elastance
104 * * `2` Emin: Minimum elastance
105 * * `3` Vrd: Rest diastolic volume
106 * * `4` Vrs: Rest systolic volume
107 *
108 * ### Internal variables
109 *
110 * * `Vc`: Chamber volume
111 *
112 */
114 public:
115 /**
116 * @brief Construct a new ChamberElastanceInductor object
117 *
118 * @param id Global ID of the block
119 * @param model The model to which the block belongs
120 */
122 : Block(id, model, BlockType::chamber_elastance_inductor,
123 BlockClass::chamber,
124 {{"Impedance", InputParameter()},
125 {"Emax", InputParameter()},
126 {"Emin", InputParameter()},
127 {"Vrd", InputParameter()},
128 {"Vrs", InputParameter()}}) {}
129
130 /**
131 * @brief Local IDs of the parameters (shared indices first)
132 */
133 enum ParamId {
134 IMPEDANCE = 0,
135 EMAX = 1,
136 EMIN = 2,
137 VRD = 3,
138 VRS = 4,
139 };
140
141 /**
142 * @brief Set up the degrees of freedom (DOF) of the block
143 *
144 * Set global_var_ids and global_eqn_ids of the element based on the
145 * number of equations and the number of internal variables of the
146 * element.
147 *
148 * @param dofhandler Degree-of-freedom handler to register variables and
149 * equations at
150 */
151 void setup_dofs(DOFHandler& dofhandler) override;
152
153 /**
154 * @brief Update the constant contributions of the element in a sparse
155 system
156 *
157 * @param system System to update contributions at
158 * @param parameters Parameters of the model
159 */
160 void update_constant(SparseSystem& system,
161 std::vector<double>& parameters) override;
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,
171 std::vector<double>& parameters) override;
172
173 /// @brief Number of triplets of element
175
176 void set_activation_function(std::unique_ptr<ActivationFunction> af) override;
177
178 protected:
179 /**
180 * @brief Construct a ChamberElastanceInductor with custom block type and
181 * parameters. Used by derived classes.
182 *
183 * @param id Global ID of the block
184 * @param model The model to which the block belongs
185 * @param block_type The specific block type for the derived class
186 * @param params Parameter list for the derived class
187 */
190 std::vector<std::pair<std::string, InputParameter>> params)
191 : Block(id, model, block_type, BlockClass::chamber, params) {}
192
193 double Elas = 0.0; ///< Current chamber elastance
194 double Vrest = 0.0; ///< Current rest volume
195 double act_ = 0.0; ///< Last computed activation
196 /// @brief Activation function
197 std::unique_ptr<ActivationFunction> activation_func_;
198
199 /**
200 * @brief Compute elastance and rest volume from activation and parameters.
201 *
202 * @param parameters Parameters of the model
203 */
204 virtual void get_elastance_values(std::vector<double>& parameters);
205};
206
207#endif // SVZERODSOLVER_MODEL_CHAMBERELASTANCEINDUCTOR_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.
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
const BlockType block_type
Type of this block.
Definition Block.h:80
TripletsContributions num_triplets
Number of triplets of element.
Definition ChamberElastanceInductor.h:174
void update_constant(SparseSystem &system, std::vector< double > &parameters) override
Update the constant contributions of the element in a sparse system.
Definition ChamberElastanceInductor.cpp:12
std::unique_ptr< ActivationFunction > activation_func_
Activation function.
Definition ChamberElastanceInductor.h:197
void update_time(SparseSystem &system, std::vector< double > &parameters) override
Update the time-dependent contributions of the element in a sparse system.
Definition ChamberElastanceInductor.cpp:32
ChamberElastanceInductor(int id, Model *model)
Construct a new ChamberElastanceInductor object.
Definition ChamberElastanceInductor.h:121
void setup_dofs(DOFHandler &dofhandler) override
Set up the degrees of freedom (DOF) of the block.
Definition ChamberElastanceInductor.cpp:7
ChamberElastanceInductor(int id, Model *model, BlockType block_type, std::vector< std::pair< std::string, InputParameter > > params)
Construct a ChamberElastanceInductor with custom block type and parameters. Used by derived classes.
Definition ChamberElastanceInductor.h:188
double Elas
Current chamber elastance.
Definition ChamberElastanceInductor.h:193
virtual void get_elastance_values(std::vector< double > &parameters)
Compute elastance and rest volume from activation and parameters.
Definition ChamberElastanceInductor.cpp:43
ParamId
Local IDs of the parameters (shared indices first).
Definition ChamberElastanceInductor.h:133
double Vrest
Current rest volume.
Definition ChamberElastanceInductor.h:194
void set_activation_function(std::unique_ptr< ActivationFunction > af) override
Set activation function (for chamber blocks that use one).
Definition ChamberElastanceInductor.cpp:55
double act_
Definition ChamberElastanceInductor.h:195
Degree-of-freedom handler.
Definition DOFHandler.h:21
Model of 0D elements.
Definition Model.h:55
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