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