svZeroDSolver
Loading...
Searching...
No Matches
Junction.h
Go to the documentation of this file.
1// Copyright (c) Stanford University, The Regents of the University of
2// California, and others.
3//
4// All Rights Reserved.
5//
6// See Copyright-SimVascular.txt for additional details.
7//
8// Permission is hereby granted, free of charge, to any person obtaining
9// a copy of this software and associated documentation files (the
10// "Software"), to deal in the Software without restriction, including
11// without limitation the rights to use, copy, modify, merge, publish,
12// distribute, sublicense, and/or sell copies of the Software, and to
13// permit persons to whom the Software is furnished to do so, subject
14// to the following conditions:
15//
16// The above copyright notice and this permission notice shall be included
17// in all copies or substantial portions of the Software.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30/**
31 * @file Junction.h
32 * @brief model::Junction source file
33 */
34#ifndef SVZERODSOLVER_MODEL_JUNCTION_HPP_
35#define SVZERODSOLVER_MODEL_JUNCTION_HPP_
36
37#include "Block.h"
38#include "SparseSystem.h"
39
40/**
41 * @brief Junction
42 *
43 * Models a junction with arbitrary inlets and outlets. Across all inlets and
44 * outlets of the junction, mass is conserved and pressure is continuous.
45 *
46 * Inlets and outlets can be specified in two ways. Either using `inlet_vessels`
47 * and `outlet_vessels` keys in the JSON file, with the corresponding lists
48 * specifying vessel IDs, or using `inlet_blocks` and `outlet_blocks` keys, with
49 * the corresponding lists specifying the names of blocks as strings.
50 *
51 *
52 * \f[
53 * \begin{circuitikz}
54 * \draw node[left] {$Q_{in}$} [-latex] (0,0) -- (0.8,0);
55 * \draw (1,0) node[anchor=south]{$P_{in}$} to [short, *-*] (3.0,0);
56 * \draw (3,0) node[anchor=south]{} to [short, -*] (4.5,1.0);
57 * \draw (4.3,1.1) node[anchor=south] {$P_{out,1}$};
58 * \draw (3,0) node[anchor=south]{} to [short, -*] (4.5,-1.0);
59 * \draw (4.3,-1.1) node[anchor=north] {$P_{out,2}$};
60 * \draw [-latex] (4.65,1.1) -- (5.25,1.5) node[right] {$Q_{out,1}$};
61 * \draw [-latex] (4.65,-1.1) -- (5.25,-1.5) node[right] {$Q_{out,2}$};
62 * \end{circuitikz}
63 * \f]
64 *
65 * ### Governing equations
66 *
67 * \f[
68 * \sum_{i}^{n_{inlets}} Q_{in, i}=\sum_{j}^{n_{outlets}} Q_{out, j}
69 * \f]
70 *
71 * \f[
72 * P_{i}=P_{j} \quad \mathrm{with} \quad i \neq j
73 * \f]
74 *
75 * ### Local contributions
76 *
77 * \f[
78 * \mathbf{y}^{e}=\left[\begin{array}{llllllllll}P_{in, 1}^{e} & Q_{in, 1}^{e} &
79 * \dots & P_{in, i}^{e} & Q_{in, i}^{e} & P_{out, 1}^{e} & Q_{out, 1}^{e} &
80 * \dots & P_{out, i}^{e} & Q_{out, i}^{e}\end{array}\right] \f]
81 *
82 * Mass conservation
83 *
84 * \f[
85 * \mathbf{F}^{e}_1 = \left[\begin{array}{llllllllll}0 & 1 & 0 & 1 & \dots & 0 &
86 * -1 & 0 & -1 & \dots\end{array}\right] \f]
87 *
88 * Due to the pressure continuity, we can write for all independent pressure
89 * pairs: \f[ \mathbf{F}^{e}_{2,...,n} = \left[\begin{array}{lllll}\dots &
90 * \underbrace{1}_{P_i} & \dots & \underbrace{1}_{P_j} & \dots\end{array}\right]
91 * \quad \mathrm{with} \quad i \neq j \f]
92 *
93 * ### Internal variables
94 *
95 * This block has no internal variables.
96 *
97 */
98class Junction : public Block {
99 public:
100 static const BlockType block_type; ///< Type of this block
101 static const BlockClass block_class; ///< Class of this block
102 static const std::vector<InputParameter>
103 input_params; ///< List of input parameter names
104
105 /**
106 * @brief Construct a new Junction object
107 *
108 * @param id Global ID of the block
109 * @param model The model to which the block belongs
110 */
112 : Block(id, model, BlockType::junction, BlockClass::junction, {}) {}
113 /**
114 * @brief Set up the degrees of freedom (DOF) of the block
115 *
116 * Set \ref global_var_ids and \ref 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 system
127 *
128 * @param system System to update contributions at
129 * @param parameters Parameters of the model
130 */
131 void update_constant(SparseSystem &system, std::vector<double> &parameters);
132
133 /**
134 * @brief Set the gradient of the block contributions with respect to the
135 * parameters
136 *
137 * @param jacobian Jacobian with respect to the parameters
138 * @param alpha Current parameter vector
139 * @param residual Residual with respect to the parameters
140 * @param y Current solution
141 * @param dy Time-derivative of the current solution
142 */
143 void update_gradient(Eigen::SparseMatrix<double> &jacobian,
144 Eigen::Matrix<double, Eigen::Dynamic, 1> &residual,
145 Eigen::Matrix<double, Eigen::Dynamic, 1> &alpha,
146 std::vector<double> &y, std::vector<double> &dy);
147
148 /**
149 * @brief Number of triplets of element
150 *
151 * Number of triplets that the element contributes to the global system
152 * (relevant for sparse memory reservation)
153 */
155
156 /**
157 * @brief Number of inlets to the block.
158 *
159 */
161 /**
162 * @brief Number of outlets from the block.
163 *
164 */
166};
167
168#endif
model::Block source file
BlockType
The types of blocks supported by the solver.
Definition BlockType.h:42
BlockClass
The classes/categories of blocks supported. Some classes require special handling (e....
Definition BlockType.h:64
SparseSystem source file.
Base class for 0D model components.
Definition Block.h:101
const int id
Global ID of the block.
Definition Block.h:103
const Model * model
The model to which the block belongs.
Definition Block.h:104
Degree-of-freedom handler.
Definition DOFHandler.h:48
Junction.
Definition Junction.h:98
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:63
void update_constant(SparseSystem &system, std::vector< double > &parameters)
Update the constant contributions of the element in a sparse system.
Definition Junction.cpp:43
void setup_dofs(DOFHandler &dofhandler)
Set up the degrees of freedom (DOF) of the block.
Definition Junction.cpp:33
static const BlockClass block_class
Class of this block.
Definition Junction.h:101
static const std::vector< InputParameter > input_params
List of input parameter names.
Definition Junction.h:103
int num_inlets
Number of inlets to the block.
Definition Junction.h:160
TripletsContributions num_triplets
Number of triplets of element.
Definition Junction.h:154
static const BlockType block_type
Type of this block.
Definition Junction.h:100
Junction(int id, Model *model)
Construct a new Junction object.
Definition Junction.h:111
int num_outlets
Number of outlets from the block.
Definition Junction.h:165
Model of 0D elements.
Definition Model.h:75
Sparse system.
Definition SparseSystem.h:88
The number of triplets that the element contributes to the global system.
Definition Block.h:52