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