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 * ### Internal variables
106 *
107 * This block has no internal variables.
108 *
109 */
110class ValveTanh : public Block {
111 public:
112 /**
113 * @brief Local IDs of the parameters
114 *
115 */
116 enum ParamId {
117 RMAX = 0,
118 RMIN = 1,
119 STEEPNESS = 2,
120 };
121
122 /**
123 * @brief Construct a new ValveTanh object
124 *
125 * @param id Global ID of the block
126 * @param model The model to which the block belongs
127 */
129 : Block(id, model, BlockType::valve_tanh, BlockClass::valve,
130 {{"Rmax", InputParameter()},
131 {"Rmin", InputParameter()},
132 {"Steepness", InputParameter()},
133 {"upstream_block", InputParameter(false, false, false)},
134 {"downstream_block", InputParameter(false, false, false)}}) {}
135
136 /**
137 * @brief Set up the degrees of freedom (DOF) of the block
138 *
139 * Set global_var_ids and global_eqn_ids of the element based on the
140 * number of equations and the number of internal variables of the
141 * element.
142 *
143 * @param dofhandler Degree-of-freedom handler to register variables and
144 * equations at
145 */
146 void setup_dofs(DOFHandler &dofhandler);
147
148 /**
149 * @brief Update the constant contributions of the element in a sparse
150 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 void update_solution(SparseSystem &system, std::vector<double> &parameters,
167 const Eigen::Matrix<double, Eigen::Dynamic, 1> &y,
168 const Eigen::Matrix<double, Eigen::Dynamic, 1> &dy);
169
170 /**
171 * @brief Number of triplets of element
172 *
173 * Number of triplets that the element contributes to the global system
174 * (relevant for sparse memory reservation)
175 */
177};
178
179#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:37
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:48
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:176
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:128
ParamId
Local IDs of the parameters.
Definition ValveTanh.h:116
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