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 * \f[
44 * \text{valve\_status} = \frac{1}{2}\left(1+tanh\{k(P_{out}-P{in})\}\right)
45 * \f]
46 *
47 * ### Local contributions
48 *
49 * \f[
50 * \mathbf{y}^{e}=\left[\begin{array}{lllll}P_{in} & Q_{in} &
51 * P_{out} & Q_{out} & \text{valve\_status} \end{array}\right]^{T} \f]
52 *
53 * \f[
54 * \mathbf{E}^{e}=\mathbf{0}
55 * \f]
56 *
57 * \f[
58 * \mathbf{F}^{e}=\left[\begin{array}{ccccc}
59 * 1 & -(R_{max}+R_{min})/2.0 & -1 & 0 & 0\\
60 * 0 & 1 & 0 & -1 & 0\\
61 * 0 & 0 & 0 & 0 & 1
62 * \end{array}\right]
63 * \f]
64 *
65 * \f[
66 * \mathbf{c}^{e}=\left[\begin{array}{c}
67 * -\frac{1}{2}Q_{in}(R_{max}-R_{min})tanh\{k(P_{out}-P_{in})\} \\
68 * 0 \\
69 * -\frac{1}{2}\left[1+tanh\{k(P_{out}-P_{in})\}\right]
70 * \end{array}\right]
71 * \f]
72 *
73 * \f[
74 * \left(\frac{\partial\mathbf{c}}{\partial\mathbf{y}}\right)^{e} =
75 * \left[\begin{array}{ccccc}
76 * A & B & C & 0 & 0\\
77 * 0 & 0 & 0 & 0 & 0\\
78 * D & 0 & -D & 0 & 0
79 * \end{array}\right] \f]
80 * where,
81 * \f[
82 * A = \frac{1}{2} k Q_{in}
83 * (R_{max}-R_{min})\left[1-tanh^2\{k(P_{out}-P_{in})\}\right] \\
84 * \f]
85 * \f[
86 * B = -\frac{1}{2}(R_{max}-R_{min})tanh\{k(P_{out}-P_{in})\} \\
87 * \f]
88 * \f[
89 * C = -\frac{1}{2} k Q_{in}
90 * (R_{max}-R_{min})\left[1-tanh^2\{k(P_{out}-P_{in})\}\right]
91 * \f]
92 * \f[
93 * D = \frac{1}{2} \frac{k}{cosh^2\{k(P_{in}-P_{out})\} }
94 * \f]
95 *
96 * \f[
97 * \left(\frac{\partial\mathbf{c}}{\partial\dot{\mathbf{y}}}\right)^{e} =
98 * \mathbf{E}^{e}=\mathbf{0}
99 * \f]
100 *
101 * ### Parameters
102 *
103 * Parameter sequence for constructing this block
104 *
105 * * `0` Rmax: Maximum (closed) valve resistance
106 * * `1` Rmin: Minimum (open) valve resistance
107 * * `2` Steepness: Steepness of sigmoid function
108 * * `3` upstream_block: Name of block connected upstream
109 * * `4` downstream_block: Name of block connected downstream
110 *
111 * ### Usage in json configuration file
112 *
113 * "valves": [
114 * {
115 * "type": "ValveTanh",
116 * "name": "valve",
117 * "params": {
118 * "Rmax": 100000.0,
119 * "Rmin": 100.0,
120 * "Steepness": 100.0,
121 * "upstream_block": "upstream_vessel",
122 * "downstream_block": "downstream_vessel"
123 * }
124 * }
125 * ]
126 *
127 * ### Internal variables
128 *
129 * This block has no internal variables.
130 *
131 */
132class ValveTanh : public Block {
133 public:
134 /**
135 * @brief Local IDs of the parameters
136 *
137 */
138 enum ParamId {
139 RMAX = 0,
140 RMIN = 1,
141 STEEPNESS = 2,
142 };
143
144 /**
145 * @brief Construct a new ValveTanh object
146 *
147 * @param id Global ID of the block
148 * @param model The model to which the block belongs
149 */
151 : Block(id, model, BlockType::valve_tanh, BlockClass::valve,
152 {{"Rmax", InputParameter()},
153 {"Rmin", InputParameter()},
154 {"Steepness", InputParameter()},
155 {"upstream_block", InputParameter(false, false, false)},
156 {"downstream_block", InputParameter(false, false, false)}}) {}
157
158 /**
159 * @brief Set up the degrees of freedom (DOF) of the block
160 *
161 * Set global_var_ids and global_eqn_ids of the element based on the
162 * number of equations and the number of internal variables of the
163 * element.
164 *
165 * @param dofhandler Degree-of-freedom handler to register variables and
166 * equations at
167 */
168 void setup_dofs(DOFHandler& dofhandler);
169
170 /**
171 * @brief Update the constant contributions of the element in a sparse
172 system
173 *
174 * @param system System to update contributions at
175 * @param parameters Parameters of the model
176 */
177 void update_constant(SparseSystem& system, std::vector<double>& parameters);
178
179 /**
180 * @brief Update the solution-dependent contributions of the element in a
181 * sparse system
182 *
183 * @param system System to update contributions at
184 * @param parameters Parameters of the model
185 * @param y Current solution
186 * @param dy Current derivate of the solution
187 */
188 void update_solution(SparseSystem& system, std::vector<double>& parameters,
189 const Eigen::Matrix<double, Eigen::Dynamic, 1>& y,
190 const Eigen::Matrix<double, Eigen::Dynamic, 1>& dy);
191
192 /**
193 * @brief Number of triplets of element
194 *
195 * Number of triplets that the element contributes to the global system
196 * (relevant for sparse memory reservation)
197 */
199};
200
201#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:14
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:198
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:35
ValveTanh(int id, Model *model)
Construct a new ValveTanh object.
Definition ValveTanh.h:150
ParamId
Local IDs of the parameters.
Definition ValveTanh.h:138
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