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