Skip to content

Commit 74dcbec

Browse files
Valve status output (#203)
1 parent 54ecc45 commit 74dcbec

File tree

5 files changed

+17425
-13504
lines changed

5 files changed

+17425
-13504
lines changed

src/model/ValveTanh.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
void ValveTanh::setup_dofs(DOFHandler& dofhandler) {
66
// set_up_dofs args: dofhandler (passed in), num equations, list of internal
7-
// variable names (strings) 2 eqns, one for Pressure, one for Flow
8-
Block::setup_dofs_(dofhandler, 2, {});
7+
// variable names (strings) 3 eqns, one for Pressure, one for Flow, one for
8+
// the valve status output
9+
Block::setup_dofs_(dofhandler, 3, {"valve_status"});
910
}
1011

1112
// update_constant updates matrices E and F from E(y,t)*y_dot + F(y,t)*y +
@@ -25,6 +26,7 @@ void ValveTanh::update_constant(SparseSystem& system,
2526
-0.5 * (Rmax + Rmin);
2627
system.F.coeffRef(global_eqn_ids[1], global_var_ids[1]) = 1.0;
2728
system.F.coeffRef(global_eqn_ids[1], global_var_ids[3]) = -1.0;
29+
system.F.coeffRef(global_eqn_ids[2], global_var_ids[4]) = 1.0;
2830
}
2931

3032
// update_solution updates matrices E and F from E(y,t)*y_dot + F(y,t)*y +
@@ -43,17 +45,21 @@ void ValveTanh::update_solution(
4345
double Rmax = parameters[global_param_ids[ParamId::RMAX]];
4446
double steep = parameters[global_param_ids[ParamId::STEEPNESS]];
4547

46-
// Nonlinear term
47-
system.C(global_eqn_ids[0]) =
48-
-0.5 * q_in * (Rmax - Rmin) * tanh(steep * (p_out - p_in));
48+
// Helper functions
49+
double fun_tanh = tanh(steep * (p_out - p_in));
50+
double fun_cosh = 0.5 * steep / pow(cosh(steep * (p_in - p_out)), 2);
4951

50-
// Derivatives of non-linear term
52+
// Nonlinear terms
53+
system.C(global_eqn_ids[0]) = -0.5 * q_in * (Rmax - Rmin) * fun_tanh;
54+
system.C(global_eqn_ids[2]) = -0.5 * (1 + fun_tanh);
55+
56+
// Derivatives of non-linear terms
5157
system.dC_dy.coeffRef(global_eqn_ids[0], global_var_ids[0]) =
52-
0.5 * q_in * (Rmax - Rmin) * steep *
53-
(1.0 - tanh(steep * (p_out - p_in)) * tanh(steep * (p_out - p_in)));
58+
0.5 * q_in * (Rmax - Rmin) * steep * (1.0 - pow(fun_tanh, 2));
5459
system.dC_dy.coeffRef(global_eqn_ids[0], global_var_ids[1]) =
55-
-0.5 * (Rmax - Rmin) * tanh(steep * (p_out - p_in));
60+
-0.5 * (Rmax - Rmin) * fun_tanh;
5661
system.dC_dy.coeffRef(global_eqn_ids[0], global_var_ids[2]) =
57-
-0.5 * q_in * (Rmax - Rmin) * steep *
58-
(1.0 - tanh(steep * (p_out - p_in)) * tanh(steep * (p_out - p_in)));
62+
-0.5 * q_in * (Rmax - Rmin) * steep * (1.0 - pow(fun_tanh, 2));
63+
system.dC_dy.coeffRef(global_eqn_ids[2], global_var_ids[0]) = fun_cosh;
64+
system.dC_dy.coeffRef(global_eqn_ids[2], global_var_ids[2]) = -fun_cosh;
5965
}

src/model/ValveTanh.h

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,43 @@
4040
* Q_{in}-Q_{out}=0
4141
* \f]
4242
*
43+
* \f[
44+
* \text{valve\_status} = \frac{1}{2}\left(1+tanh\{k(P_{out}-P{in})\}\right)
45+
* \f]
46+
*
4347
* ### Local contributions
4448
*
4549
* \f[
46-
* \mathbf{y}^{e}=\left[\begin{array}{llll}P_{in} & Q_{in} &
47-
* P_{out} & Q_{out}\end{array}\right]^{T} \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]
4852
*
4953
* \f[
50-
* \mathbf{E}^{e}=\left[\begin{array}{cccc}
51-
* 0 & 0 & 0 & 0 \\
52-
* 0 & 0 & 0 & 0
53-
* \end{array}\right]
54+
* \mathbf{E}^{e}=\mathbf{0}
5455
* \f]
5556
*
5657
* \f[
57-
* \mathbf{F}^{e}=\left[\begin{array}{cccc}
58-
* 1 & -(R_{max}+R_{min})/2.0 & -1 & 0 \\
59-
* 0 & 1 & 0 & -1
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
6062
* \end{array}\right]
6163
* \f]
6264
*
6365
* \f[
6466
* \mathbf{c}^{e}=\left[\begin{array}{c}
6567
* -\frac{1}{2}Q_{in}(R_{max}-R_{min})tanh\{k(P_{out}-P_{in})\} \\
66-
* 0
68+
* 0 \\
69+
* -\frac{1}{2}\left[1+tanh\{k(P_{out}-P_{in})\}\right]
6770
* \end{array}\right]
6871
* \f]
6972
*
7073
* \f[
7174
* \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+
* \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]
7580
* where,
7681
* \f[
7782
* A = \frac{1}{2} k Q_{in}
@@ -82,14 +87,15 @@
8287
* \f]
8388
* \f[
8489
* C = -\frac{1}{2} k Q_{in}
85-
* (R_{max}-R_{min})\left[1-tanh^2\{k(P_{out}-P_{in})\}\right] \f]
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]
8695
*
8796
* \f[
8897
* \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]
98+
* \mathbf{E}^{e}=\mathbf{0}
9399
* \f]
94100
*
95101
* ### Parameters

0 commit comments

Comments
 (0)