svZeroDSolver
Loading...
Searching...
No Matches
Junction.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 Junction.h
5 * @brief model::Junction source file
6 */
7#ifndef SVZERODSOLVER_MODEL_JUNCTION_HPP_
8#define SVZERODSOLVER_MODEL_JUNCTION_HPP_
9
10#include "Block.h"
11#include "SparseSystem.h"
12
13/**
14 * @brief Junction
15 *
16 * Models a junction with arbitrary inlets and outlets. Across all inlets and
17 * outlets of the junction, mass is conserved and pressure is continuous.
18 *
19 * Inlets and outlets can be specified in two ways. Either using `inlet_vessels`
20 * and `outlet_vessels` keys in the JSON file, with the corresponding lists
21 * specifying vessel IDs, or using `inlet_blocks` and `outlet_blocks` keys, with
22 * the corresponding lists specifying the names of blocks as strings.
23 *
24 *
25 * \f[
26 * \begin{circuitikz}
27 * \draw node[left] {$Q_{in}$} [-latex] (0,0) -- (0.8,0);
28 * \draw (1,0) node[anchor=south]{$P_{in}$} to [short, *-*] (3.0,0);
29 * \draw (3,0) node[anchor=south]{} to [short, -*] (4.5,1.0);
30 * \draw (4.3,1.1) node[anchor=south] {$P_{out,1}$};
31 * \draw (3,0) node[anchor=south]{} to [short, -*] (4.5,-1.0);
32 * \draw (4.3,-1.1) node[anchor=north] {$P_{out,2}$};
33 * \draw [-latex] (4.65,1.1) -- (5.25,1.5) node[right] {$Q_{out,1}$};
34 * \draw [-latex] (4.65,-1.1) -- (5.25,-1.5) node[right] {$Q_{out,2}$};
35 * \end{circuitikz}
36 * \f]
37 *
38 * ### Governing equations
39 *
40 * \f[
41 * \sum_{i}^{n_{inlets}} Q_{in, i}=\sum_{j}^{n_{outlets}} Q_{out, j}
42 * \f]
43 *
44 * \f[
45 * P_{i}=P_{j} \quad \mathrm{with} \quad i \neq j
46 * \f]
47 *
48 * ### Local contributions
49 *
50 * \f[
51 * \mathbf{y}^{e}=\left[\begin{array}{llllllllll}P_{in, 1}^{e} & Q_{in, 1}^{e} &
52 * \dots & P_{in, i}^{e} & Q_{in, i}^{e} & P_{out, 1}^{e} & Q_{out, 1}^{e} &
53 * \dots & P_{out, i}^{e} & Q_{out, i}^{e}\end{array}\right] \f]
54 *
55 * Mass conservation
56 *
57 * \f[
58 * \mathbf{F}^{e}_1 = \left[\begin{array}{llllllllll}0 & 1 & 0 & 1 & \dots & 0 &
59 * -1 & 0 & -1 & \dots\end{array}\right] \f]
60 *
61 * Due to the pressure continuity, we can write for all independent pressure
62 * pairs: \f[ \mathbf{F}^{e}_{2,...,n} = \left[\begin{array}{lllll}\dots &
63 * \underbrace{1}_{P_i} & \dots & \underbrace{1}_{P_j} & \dots\end{array}\right]
64 * \quad \mathrm{with} \quad i \neq j \f]
65 *
66 * ### Internal variables
67 *
68 * This block has no internal variables.
69 *
70 */
71class Junction : public Block {
72 public:
73 static const BlockType block_type; ///< Type of this block
74 static const BlockClass block_class; ///< Class of this block
75 static const std::vector<InputParameter>
76 input_params; ///< List of input parameter names
77
78 /**
79 * @brief Construct a new Junction object
80 *
81 * @param id Global ID of the block
82 * @param model The model to which the block belongs
83 */
85 : Block(id, model, BlockType::junction, BlockClass::junction, {}) {}
86 /**
87 * @brief Set up the degrees of freedom (DOF) of the block
88 *
89 * Set \ref global_var_ids and \ref global_eqn_ids of the element based on the
90 * number of equations and the number of internal variables of the
91 * element.
92 *
93 * @param dofhandler Degree-of-freedom handler to register variables and
94 * equations at
95 */
96 void setup_dofs(DOFHandler &dofhandler);
97
98 /**
99 * @brief Update the constant contributions of the element in a sparse system
100 *
101 * @param system System to update contributions at
102 * @param parameters Parameters of the model
103 */
104 void update_constant(SparseSystem &system, std::vector<double> &parameters);
105
106 /**
107 * @brief Set the gradient of the block contributions with respect to the
108 * parameters
109 *
110 * @param jacobian Jacobian with respect to the parameters
111 * @param alpha Current parameter vector
112 * @param residual Residual with respect to the parameters
113 * @param y Current solution
114 * @param dy Time-derivative of the current solution
115 */
116 void update_gradient(Eigen::SparseMatrix<double> &jacobian,
117 Eigen::Matrix<double, Eigen::Dynamic, 1> &residual,
118 Eigen::Matrix<double, Eigen::Dynamic, 1> &alpha,
119 std::vector<double> &y, std::vector<double> &dy);
120
121 /**
122 * @brief Number of triplets of element
123 *
124 * Number of triplets that the element contributes to the global system
125 * (relevant for sparse memory reservation)
126 */
128
129 /**
130 * @brief Number of inlets to the block.
131 *
132 */
134 /**
135 * @brief Number of outlets from the block.
136 *
137 */
139};
140
141#endif
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
void update_gradient(Eigen::SparseMatrix< double > &jacobian, Eigen::Matrix< double, Eigen::Dynamic, 1 > &residual, Eigen::Matrix< double, Eigen::Dynamic, 1 > &alpha, std::vector< double > &y, std::vector< double > &dy)
Set the gradient of the block contributions with respect to the parameters.
Definition Junction.cpp:35
void update_constant(SparseSystem &system, std::vector< double > &parameters)
Update the constant contributions of the element in a sparse system.
Definition Junction.cpp:15
void setup_dofs(DOFHandler &dofhandler)
Set up the degrees of freedom (DOF) of the block.
Definition Junction.cpp:5
static const BlockClass block_class
Class of this block.
Definition Junction.h:74
static const std::vector< InputParameter > input_params
List of input parameter names.
Definition Junction.h:76
int num_inlets
Number of inlets to the block.
Definition Junction.h:133
TripletsContributions num_triplets
Number of triplets of element.
Definition Junction.h:127
static const BlockType block_type
Type of this block.
Definition Junction.h:73
Junction(int id, Model *model)
Construct a new Junction object.
Definition Junction.h:84
int num_outlets
Number of outlets from the block.
Definition Junction.h:138
Model of 0D elements.
Definition Model.h:48
The number of triplets that the element contributes to the global system.
Definition Block.h:26