svZeroDSolver
Loading...
Searching...
No Matches
BloodVessel.h
Go to the documentation of this file.
1// Copyright (c) Stanford University, The Regents of the University of
2// California, and others.
3//
4// All Rights Reserved.
5//
6// See Copyright-SimVascular.txt for additional details.
7//
8// Permission is hereby granted, free of charge, to any person obtaining
9// a copy of this software and associated documentation files (the
10// "Software"), to deal in the Software without restriction, including
11// without limitation the rights to use, copy, modify, merge, publish,
12// distribute, sublicense, and/or sell copies of the Software, and to
13// permit persons to whom the Software is furnished to do so, subject
14// to the following conditions:
15//
16// The above copyright notice and this permission notice shall be included
17// in all copies or substantial portions of the Software.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30/**
31 * @file BloodVessel.h
32 * @brief model::BloodVessel source file
33 */
34#ifndef SVZERODSOLVER_MODEL_BLOODVESSEL_HPP_
35#define SVZERODSOLVER_MODEL_BLOODVESSEL_HPP_
36
37#include <math.h>
38
39#include "Block.h"
40#include "SparseSystem.h"
41
42/**
43 * @brief Resistor-capacitor-inductor blood vessel with optional stenosis
44 *
45 * Models the mechanical behavior of a bloodvessel with optional stenosis.
46 *
47 * \f[
48 * \begin{circuitikz} \draw
49 * node[left] {$Q_{in}$} [-latex] (0,0) -- (0.8,0);
50 * \draw (1,0) node[anchor=south]{$P_{in}$}
51 * to [R, l=$R$, *-] (3,0)
52 * to [R, l=$S$, -] (5,0)
53 * (5,0) to [L, l=$L$, -*] (7,0)
54 * node[anchor=south]{$P_{out}$}
55 * (5,0) to [C, l=$C$, -] (5,-1.5)
56 * node[ground]{};
57 * \draw [-latex] (7.2,0) -- (8,0) node[right] {$Q_{out}$};
58 * \end{circuitikz}
59 * \f]
60 *
61 * ### Governing equations
62 *
63 * \f[
64 * P_\text{in}-P_\text{out} - (R + S|Q_\text{in}|) Q_\text{in}-L
65 * \dot{Q}_\text{out}=0 \f]
66 *
67 * \f[
68 * Q_\text{in}-Q_\text{out} - C \dot{P}_\text{in}+C(R +
69 * 2S|Q_\text{in}|) \dot{Q}_{in}=0 \f]
70 *
71 * ### Local contributions
72 *
73 * \f[
74 * \mathbf{y}^{e}=\left[\begin{array}{llll}P_{i n} & Q_{in} &
75 * P_{out} & Q_{out}\end{array}\right]^\text{T} \f]
76 *
77 * \f[
78 * \mathbf{F}^{e}=\left[\begin{array}{cccc}
79 * 1 & -R & -1 & 0 \\
80 * 0 & 1 & 0 & -1
81 * \end{array}\right]
82 * \f]
83 *
84 * \f[
85 * \mathbf{E}^{e}=\left[\begin{array}{cccc}
86 * 0 & 0 & 0 & -L \\
87 * -C & CR & 0 & 0
88 * \end{array}\right]
89 * \f]
90 *
91 * \f[
92 * \mathbf{c}^{e} = S|Q_\text{in}|
93 * \left[\begin{array}{c}
94 * -Q_\text{in} \\
95 * 2C\dot{Q}_\text{in}
96 * \end{array}\right]
97 * \f]
98 *
99 * \f[
100 * \left(\frac{\partial\mathbf{c}}{\partial\mathbf{y}}\right)^{e} =
101 * S \text{sgn} (Q_\text{in})
102 * \left[\begin{array}{cccc}
103 * 0 & -2Q_\text{in} & 0 & 0 \\
104 * 0 & 2C\dot{Q}_\text{in} & 0 & 0
105 * \end{array}\right]
106 * \f]
107 *
108 * \f[
109 * \left(\frac{\partial\mathbf{c}}{\partial\dot{\mathbf{y}}}\right)^{e} =
110 * S|Q_\text{in}|
111 * \left[\begin{array}{cccc}
112 * 0 & 0 & 0 & 0 \\
113 * 0 & 2C & 0 & 0
114 * \end{array}\right]
115 * \f]
116 *
117 * with the stenosis resistance \f$ S=K_{t} \frac{\rho}{2
118 * A_{o}^{2}}\left(\frac{A_{o}}{A_{s}}-1\right)^{2} \f$.
119 * \f$R\f$, \f$C\f$, and \f$L\f$ refer to
120 * Poisieuille resistance, capacitance and inductance, respectively.
121 *
122 * ### Gradient
123 *
124 * Gradient of the equations with respect to the parameters:
125 *
126 * \f[
127 * \mathbf{J}^{e} = \left[\begin{array}{cccc}
128 * -y_2 & 0 & -\dot{y}_4 & -|y_2|y_2 \\
129 * C\dot{y}_2 & (-\dot{y}_1+(R+2S|Q_\text{in}|)\dot{y}_2) & 0 & 2C|y_2|\dot{y}_2
130 * \end{array}\right]
131 * \f]
132 *
133 * ### Parameters
134 *
135 * Parameter sequence for constructing this block
136 *
137 * * `0` Poiseuille resistance
138 * * `1` Capacitance
139 * * `2` Inductance
140 * * `3` Stenosis coefficient
141 *
142 * ### Internal variables
143 *
144 * This block has no internal variables.
145 *
146 */
147class BloodVessel : public Block {
148 public:
149 /**
150 * @brief Local IDs of the parameters
151 *
152 */
153 enum ParamId {
154 RESISTANCE = 0,
155 CAPACITANCE = 1,
156 INDUCTANCE = 2,
157 STENOSIS_COEFFICIENT = 3,
158 };
159
160 /**
161 * @brief Construct a new BloodVessel object
162 *
163 * @param id Global ID of the block
164 * @param model The model to which the block belongs
165 */
167 : Block(id, model, BlockType::blood_vessel, BlockClass::vessel,
168 {{"R_poiseuille", InputParameter()},
169 {"C", InputParameter(true)},
170 {"L", InputParameter(true)},
171 {"stenosis_coefficient", InputParameter(true)}}) {}
172
173 /**
174 * @brief Set up the degrees of freedom (DOF) of the block
175 *
176 * Set \ref global_var_ids and \ref global_eqn_ids of the element based on the
177 * number of equations and the number of internal variables of the
178 * element.
179 *
180 * @param dofhandler Degree-of-freedom handler to register variables and
181 * equations at
182 */
183 void setup_dofs(DOFHandler &dofhandler);
184
185 /**
186 * @brief Update the constant contributions of the element in a sparse
187 system
188 *
189 * @param system System to update contributions at
190 * @param parameters Parameters of the model
191 */
192 void update_constant(SparseSystem &system, std::vector<double> &parameters);
193
194 /**
195 * @brief Update the solution-dependent contributions of the element in a
196 * sparse system
197 *
198 * @param system System to update contributions at
199 * @param parameters Parameters of the model
200 * @param y Current solution
201 * @param dy Current derivate of the solution
202 */
203 void update_solution(SparseSystem &system, std::vector<double> &parameters,
204 const Eigen::Matrix<double, Eigen::Dynamic, 1> &y,
205 const Eigen::Matrix<double, Eigen::Dynamic, 1> &dy);
206
207 /**
208 * @brief Set the gradient of the block contributions with respect to the
209 * parameters
210 *
211 * @param jacobian Jacobian with respect to the parameters
212 * @param alpha Current parameter vector
213 * @param residual Residual with respect to the parameters
214 * @param y Current solution
215 * @param dy Time-derivative of the current solution
216 */
217 void update_gradient(Eigen::SparseMatrix<double> &jacobian,
218 Eigen::Matrix<double, Eigen::Dynamic, 1> &residual,
219 Eigen::Matrix<double, Eigen::Dynamic, 1> &alpha,
220 std::vector<double> &y, std::vector<double> &dy);
221
222 /**
223 * @brief Number of triplets of element
224 *
225 * Number of triplets that the element contributes to the global system
226 * (relevant for sparse memory reservation)
227 */
229};
230
231#endif // SVZERODSOLVER_MODEL_BLOODVESSEL_HPP_
model::Block source file
BlockType
The types of blocks supported by the solver.
Definition BlockType.h:42
BlockClass
The classes/categories of blocks supported. Some classes require special handling (e....
Definition BlockType.h:64
SparseSystem source file.
Base class for 0D model components.
Definition Block.h:101
const int id
Global ID of the block.
Definition Block.h:103
const Model * model
The model to which the block belongs.
Definition Block.h:104
Resistor-capacitor-inductor blood vessel with optional stenosis.
Definition BloodVessel.h:147
void update_constant(SparseSystem &system, std::vector< double > &parameters)
Update the constant contributions of the element in a sparse system.
Definition BloodVessel.cpp:37
ParamId
Local IDs of the parameters.
Definition BloodVessel.h:153
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)
Update the solution-dependent contributions of the element in a sparse system.
Definition BloodVessel.cpp:60
void update_gradient(Eigen::SparseMatrix< double > &jacobian, Eigen::Matrix< double, Eigen::Dynamic, 1 > &residual, Eigen::Matrix< double, Eigen::Dynamic, 1 > &alpha, std::vector< double > &y, std::vector< double > &dy)
Set the gradient of the block contributions with respect to the parameters.
Definition BloodVessel.cpp:86
BloodVessel(int id, Model *model)
Construct a new BloodVessel object.
Definition BloodVessel.h:166
TripletsContributions num_triplets
Number of triplets of element.
Definition BloodVessel.h:228
void setup_dofs(DOFHandler &dofhandler)
Set up the degrees of freedom (DOF) of the block.
Definition BloodVessel.cpp:33
Degree-of-freedom handler.
Definition DOFHandler.h:48
Model of 0D elements.
Definition Model.h:75
Sparse system.
Definition SparseSystem.h:57
Handles the properties of input parameters.
Definition Parameter.h:127
The number of triplets that the element contributes to the global system.
Definition Block.h:52