svZeroDSolver
Loading...
Searching...
No Matches
ValveTanh.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 ValveTanh.h
32 * @brief model::ValveTanh source file
33 */
34#ifndef SVZERODSOLVER_MODEL_VALVETANH_HPP_
35#define SVZERODSOLVER_MODEL_VALVETANH_HPP_
36
37#include <math.h>
38
39#include "Block.h"
40#include "SparseSystem.h"
41#include "debug.h"
42
43/**
44 * @brief Valve (tanh) block.
45 *
46 * Models the pressure drop across a diode-like valve, which is implemented as a
47 * non-linear hyperbolic-tangent resistor. See \cite pfaller2019importance
48 * (equations 16 and 22).
49 *
50 * \f[
51 * \begin{circuitikz} \draw
52 * node[left] {$Q_{in}$} [-latex] (0,0) -- (0.8,0);
53 * \draw (1,0) node[anchor=south]{$P_{in}$}
54 * to [D, l=$R_v$, *-*] (3,0)
55 * node[anchor=south]{$P_{out}$};
56 * \end{circuitikz}
57 * \f]
58 *
59 * ### Governing equations
60 *
61 * \f[
62 * P_{in}-P_{out}-Q_{in}\left[R_{min} +
63 * (R_{max}-R_{min})\frac{1}{2}\left[1+tanh\{k(P_{out}-P{in})\}\right]\right]=0
64 * \f]
65 *
66 * \f[
67 * Q_{in}-Q_{out}=0
68 * \f]
69 *
70 * ### Local contributions
71 *
72 * \f[
73 * \mathbf{y}^{e}=\left[\begin{array}{llll}P_{in} & Q_{in} &
74 * P_{out} & Q_{out}\end{array}\right]^{T} \f]
75 *
76 * \f[
77 * \mathbf{E}^{e}=\left[\begin{array}{cccc}
78 * 0 & 0 & 0 & 0 \\
79 * 0 & 0 & 0 & 0
80 * \end{array}\right]
81 * \f]
82 *
83 * \f[
84 * \mathbf{F}^{e}=\left[\begin{array}{cccc}
85 * 1 & -(R_{max}+R_{min})/2.0 & -1 & 0 \\
86 * 0 & 1 & 0 & -1
87 * \end{array}\right]
88 * \f]
89 *
90 * \f[
91 * \mathbf{c}^{e}=\left[\begin{array}{c}
92 * -\frac{1}{2}Q_{in}(R_{max}-R_{min})tanh\{k(P_{out}-P_{in})\} \\
93 * 0
94 * \end{array}\right]
95 * \f]
96 *
97 * \f[
98 * \left(\frac{\partial\mathbf{c}}{\partial\mathbf{y}}\right)^{e} =
99 * \left[\begin{array}{cccc}
100 * A & B & C & 0 \\
101 * 0 & 0 & 0 & 0 \end{array}\right] \f]
102 * where,
103 * \f[
104 * A = \frac{1}{2} k Q_{in}
105 * (R_{max}-R_{min})\left[1-tanh^2\{k(P_{out}-P_{in})\}\right] \\
106 * \f]
107 * \f[
108 * B = -\frac{1}{2}(R_{max}-R_{min})tanh\{k(P_{out}-P_{in})\} \\
109 * \f]
110 * \f[
111 * C = -\frac{1}{2} k Q_{in}
112 * (R_{max}-R_{min})\left[1-tanh^2\{k(P_{out}-P_{in})\}\right] \f]
113 *
114 * \f[
115 * \left(\frac{\partial\mathbf{c}}{\partial\dot{\mathbf{y}}}\right)^{e} =
116 * \left[\begin{array}{cccc}
117 * 0 & 0 & 0 & 0 \\
118 * 0 & 0 & 0 & 0
119 * \end{array}\right]
120 * \f]
121 *
122 * ### Parameters
123 *
124 * Parameter sequence for constructing this block
125 *
126 * * `0` Rmax: Maximum (closed) valve resistance
127 * * `1` Rmin: Minimum (open) valve resistance
128 * * `2` Steepness: Steepness of sigmoid function
129 * * `3` upstream_block: Name of block connected upstream
130 * * `4` downstream_block: Name of block connected downstream
131 *
132 * ### Internal variables
133 *
134 * This block has no internal variables.
135 *
136 */
137class ValveTanh : public Block {
138 public:
139 /**
140 * @brief Local IDs of the parameters
141 *
142 */
143 enum ParamId {
144 RMAX = 0,
145 RMIN = 1,
146 STEEPNESS = 2,
147 };
148
149 /**
150 * @brief Construct a new ValveTanh object
151 *
152 * @param id Global ID of the block
153 * @param model The model to which the block belongs
154 */
156 : Block(id, model, BlockType::valve_tanh, BlockClass::valve,
157 {{"Rmax", InputParameter()},
158 {"Rmin", InputParameter()},
159 {"Steepness", InputParameter()},
160 {"upstream_block", InputParameter(false, false, false)},
161 {"downstream_block", InputParameter(false, false, false)}}) {}
162
163 /**
164 * @brief Set up the degrees of freedom (DOF) of the block
165 *
166 * Set global_var_ids and global_eqn_ids of the element based on the
167 * number of equations and the number of internal variables of the
168 * element.
169 *
170 * @param dofhandler Degree-of-freedom handler to register variables and
171 * equations at
172 */
173 void setup_dofs(DOFHandler &dofhandler);
174
175 /**
176 * @brief Update the constant contributions of the element in a sparse
177 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 void update_solution(SparseSystem &system, std::vector<double> &parameters,
194 const Eigen::Matrix<double, Eigen::Dynamic, 1> &y,
195 const Eigen::Matrix<double, Eigen::Dynamic, 1> &dy);
196
197 /**
198 * @brief Number of triplets of element
199 *
200 * Number of triplets that the element contributes to the global system
201 * (relevant for sparse memory reservation)
202 */
204};
205
206#endif // SVZERODSOLVER_MODEL_VALVETANH_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
Degree-of-freedom handler.
Definition DOFHandler.h:48
Model of 0D elements.
Definition Model.h:75
Sparse system.
Definition SparseSystem.h:57
Valve (tanh) block.
Definition ValveTanh.h:137
void update_constant(SparseSystem &system, std::vector< double > &parameters)
Update the constant contributions of the element in a sparse system.
Definition ValveTanh.cpp:41
void setup_dofs(DOFHandler &dofhandler)
Set up the degrees of freedom (DOF) of the block.
Definition ValveTanh.cpp:33
TripletsContributions num_triplets
Number of triplets of element.
Definition ValveTanh.h:203
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 ValveTanh.cpp:61
ValveTanh(int id, Model *model)
Construct a new ValveTanh object.
Definition ValveTanh.h:155
ParamId
Local IDs of the parameters.
Definition ValveTanh.h:143
DEBUG_MSG source file.
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