svZeroDSolver
Loading...
Searching...
No Matches
BloodVesselJunction.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 BloodVesselJunction.h
32 * @brief model::BloodVesselJunction source file
33 */
34#ifndef SVZERODSOLVER_MODEL_BLOODVESSELJUNCTION_HPP_
35#define SVZERODSOLVER_MODEL_BLOODVESSELJUNCTION_HPP_
36
37#include "Block.h"
38#include "BloodVessel.h"
39#include "SparseSystem.h"
40
41/**
42 * @brief Junction between blood vessels
43 *
44 * Models a junction with one inlet and arbitrary outlets using
45 * modified blood vessel elements between each inlet and outlet pair.
46 *
47 * \f[
48 * \begin{circuitikz}
49 * \draw node[left] {$Q_\text{in}$} [-latex] (0,0) -- (0.8,0);
50 * \draw (1,0.1) node[anchor=south]{$P_\text{in}$};
51 * \draw (1,0) to [short, *-] (2.5,0.75);
52 * \draw (1,0) to [short, *-] (2.5,-0.75);
53 * \draw (2.5,0.75) node[anchor=south]{} to [generic, l_=$BV_{1}$, -*]
54 * (4.5,0.75); \draw (2.4,0.75) node[anchor=south]{}; \draw (4.6,0.75)
55 * node[anchor=south] {$P_{out,1}$}; \draw (2.5,-0.75) node[anchor=south]{}
56 to
57 * [generic, l^=$BV_{2}$, -*] (4.5,-0.75); \draw (2.4,-0.75)
58 * node[anchor=north]{}; \draw (4.6,-0.75) node[anchor=north]
59 * {$P_{out,2}$}; \draw [-latex] (4.7,0.75) -- (5.5,0.75) node[right]
60 * {$Q_{out,1}$}; \draw [-latex] (4.7,-0.75) -- (5.5,-0.75) node[right]
61 * {$Q_{out,2}$}; \end{circuitikz}
62 * \f]
63 *
64 * Each blood vessel is modelled as:
65 *
66 * \f[
67 * \begin{circuitikz} \draw
68 * node[left] {$Q_\text{in}$} [-latex] (0,0) -- (0.8,0);
69 * \draw (1,0) node[anchor=south]{$P_\text{in}$}
70 * to [R, l=$R$, *-] (3,0)
71 * to [R, l=$S$, -] (5,0)
72 * (5,0) to [L, l=$L$, -*] (7,0)
73 * node[anchor=south]{$P_\text{out}$};
74 * \draw [-latex] (7.2,0) -- (8,0) node[right] {$Q_\text{out}$};
75 * \end{circuitikz}
76 * \f]
77 *
78 * ### Governing equations
79 *
80 * \f[
81 * Q_\text{in}-\sum_{i}^{n_{outlets}} Q_{out, i} = 0
82 * \f]
83 *
84 * \f[
85 * P_\text{in}-P_{\text{out},i} - (R+S|Q_{\text{out},i}|) \cdot Q_{\text{out},i}
86 * - L \dot{Q}_{\text{out},i} = 0 \quad \forall i \in n_{outlets} \f]
87 *
88 * ### Local contributions
89 *
90 * \f[
91 * \mathbf{y}^{e}=\left[\begin{array}{lllllll}P_\text{in} & Q_\text{in}
92 * & P_{out, 1} & Q_{out, 1} &
93 * \dots & P_{out, i} & Q_{out, i}\end{array}\right] \f]
94 *
95 * \f[
96 * \mathbf{F}^{e} = \left[\begin{array}{ccccccc}
97 * 0 & 1 & 0 & -1 & 0 & -1 & \dots \\
98 * 1 & 0 & -1 & -R_1 & 0 & 0 & \\
99 * 1 & 0 & 0 & 0 & -1 & -R_2 & \\
100 * \vdots & & & & & & \ddots
101 * \end{array}\right]
102 * \f]
103 *
104 * \f[
105 * \mathbf{E}^{e} = \left[\begin{array}{ccccccc}
106 * 0 & 0 & 0 & 0 & 0 & 0 & \dots \\
107 * 0 & 0 & 0 & -L_1 & 0 & 0 & \\
108 * 0 & 0 & 0 & 0 & 0 & -L_2 & \\
109 * \vdots & & & & & & \ddots
110 * \end{array}\right]
111 * \f]
112 *
113 * \f[
114 * \mathbf{c}^{e} = \left[\begin{array}{c}
115 * 0 \\
116 * - S_1 |Q_{\text{in},1}| Q_{\text{in},1} \\
117 * - S_2 |Q_{\text{in},2}| Q_{\text{in},2} \\
118 * \vdots
119 * \end{array}\right] \f]
120 *
121 * ### Gradient
122 *
123 * Gradient of the equations with respect to the parameters:
124 *
125 * \f[
126 * \mathbf{J}^{e} = \left[\begin{array}{lllllllll}
127 * 0 & 0 & \dots & 0 & 0 & \dots & 0 & 0 &
128 * \dots \\
129 * - y_4 & 0 & \dots & - \dot y_4 & 0 & \dots & |y_4| y_4 & 0 & \dots \\
130 * 0 & - y_6 & \dots & 0 & - \dot y_6 & \dots & 0 & |y_6| y_6 & \dots \\
131 * 0 & 0 & \ddots & 0 & 0 & \ddots & 0 & 0 & \ddots \\
132 * \end{array}\right]
133 * \f]
134 *
135 * ### Parameters
136 *
137 * Parameter sequence for constructing this block
138 *
139 * * `i` Poiseuille resistance for inner blood vessel `i`
140 * * `i+num_outlets` Inductance for inner blood vessel `i`
141 * * `i+2*num_outlets` Stenosis coefficient for inner blood vessel `i`
142 *
143 * ### Internal variables
144 *
145 * This block has no internal variables.
146 *
147 */
149 public:
150 /**
151 * @brief Construct a new BloodVesselJunction object
152 *
153 * @param id Global ID of the block
154 * @param model The model to which the block belongs
155 */
157 : Block(id, model, BlockType::blood_vessel_junction, BlockClass::junction,
158 {{"R_poiseuille", InputParameter()},
159 {"L", InputParameter()},
160 {"stenosis_coefficient", InputParameter()}}) {
161 input_params_list = true;
162 }
163
164 /**
165 * @brief Set up the degrees of freedom (DOF) of the block
166 *
167 * Set \ref global_var_ids and \ref global_eqn_ids of the element based on the
168 * number of equations and the number of internal variables of the
169 * element.
170 *
171 * @param dofhandler Degree-of-freedom handler to register variables and
172 * equations at
173 */
174 void setup_dofs(DOFHandler &dofhandler);
175
176 /**
177 * @brief Update the constant contributions of the element in a sparse system
178 *
179 * @param system System to update contributions at
180 * @param parameters Parameters of the model
181 */
182 void update_constant(SparseSystem &system, std::vector<double> &parameters);
183
184 /**
185 * @brief Update the solution-dependent contributions of the element in a
186 * sparse system
187 *
188 * @param system System to update contributions at
189 * @param parameters Parameters of the model
190 * @param y Current solution
191 * @param dy Current derivate of the solution
192 */
193 virtual void update_solution(
194 SparseSystem &system, std::vector<double> &parameters,
195 const Eigen::Matrix<double, Eigen::Dynamic, 1> &y,
196 const Eigen::Matrix<double, Eigen::Dynamic, 1> &dy);
197
198 /**
199 * @brief Set the gradient of the block contributions with respect to the
200 * parameters
201 *
202 * @param jacobian Jacobian with respect to the parameters
203 * @param alpha Current parameter vector
204 * @param residual Residual with respect to the parameters
205 * @param y Current solution
206 * @param dy Time-derivative of the current solution
207 */
208 void update_gradient(Eigen::SparseMatrix<double> &jacobian,
209 Eigen::Matrix<double, Eigen::Dynamic, 1> &residual,
210 Eigen::Matrix<double, Eigen::Dynamic, 1> &alpha,
211 std::vector<double> &y, std::vector<double> &dy);
212
213 /**
214 * @brief Number of triplets of element
215 *
216 * Number of triplets that the element contributes to the global system
217 * (relevant for sparse memory reservation)
218 */
220
221 private:
222 int num_outlets;
223};
224
225#endif // SVZERODSOLVER_MODEL_BLOODVESSELJUNCTION_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
model::BloodVessel source file
SparseSystem source file.
Base class for 0D model components.
Definition Block.h:101
bool input_params_list
Are input parameters given as a list?
Definition Block.h:115
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
Junction between blood vessels.
Definition BloodVesselJunction.h:148
void setup_dofs(DOFHandler &dofhandler)
Set up the degrees of freedom (DOF) of the block.
Definition BloodVesselJunction.cpp:33
void update_constant(SparseSystem &system, std::vector< double > &parameters)
Update the constant contributions of the element in a sparse system.
Definition BloodVesselJunction.cpp:46
TripletsContributions num_triplets
Number of triplets of element.
Definition BloodVesselJunction.h:219
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 BloodVesselJunction.cpp:82
BloodVesselJunction(int id, Model *model)
Construct a new BloodVesselJunction object.
Definition BloodVesselJunction.h:156
virtual 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 BloodVesselJunction.cpp:65
Degree-of-freedom handler.
Definition DOFHandler.h:48
Model of 0D elements.
Definition Model.h:75
Sparse system.
Definition SparseSystem.h:88
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