Skip to content

Commit 436384d

Browse files
committed
Requested changes as specified in code review
1 parent 3a02a9b commit 436384d

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

src/model/ValveTanh.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,29 @@ void ValveTanh::update_solution(
4040
double p_in = y[global_var_ids[0]];
4141
double p_out = y[global_var_ids[2]];
4242
double q_in = y[global_var_ids[1]];
43-
double valve_status = y[global_var_ids[4]];
4443
// Get parameters
4544
double Rmin = parameters[global_param_ids[ParamId::RMIN]];
4645
double Rmax = parameters[global_param_ids[ParamId::RMAX]];
4746
double steep = parameters[global_param_ids[ParamId::STEEPNESS]];
4847

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);
51+
4952
// Nonlinear terms
5053
system.C(global_eqn_ids[0]) =
51-
-0.5 * q_in * (Rmax - Rmin) * tanh(steep * (p_out - p_in));
52-
system.C(global_eqn_ids[2]) = -0.5 * (1 + tanh(steep * (p_out - p_in)));
54+
-0.5 * q_in * (Rmax - Rmin) * fun_tanh;
55+
system.C(global_eqn_ids[2]) = -0.5 * (1 + fun_tanh);
5356

5457
// Derivatives of non-linear terms
5558
system.dC_dy.coeffRef(global_eqn_ids[0], global_var_ids[0]) =
56-
0.5 * q_in * (Rmax - Rmin) * steep *
57-
(1.0 - tanh(steep * (p_out - p_in)) * tanh(steep * (p_out - p_in)));
59+
0.5 * q_in * (Rmax - Rmin) * steep * (1.0 - pow(fun_tanh,2));
5860
system.dC_dy.coeffRef(global_eqn_ids[0], global_var_ids[1]) =
59-
-0.5 * (Rmax - Rmin) * tanh(steep * (p_out - p_in));
61+
-0.5 * (Rmax - Rmin) * fun_tanh;
6062
system.dC_dy.coeffRef(global_eqn_ids[0], global_var_ids[2]) =
61-
-0.5 * q_in * (Rmax - Rmin) * steep *
62-
(1.0 - tanh(steep * (p_out - p_in)) * tanh(steep * (p_out - p_in)));
63+
-0.5 * q_in * (Rmax - Rmin) * steep * (1.0 - pow(fun_tanh,2));
6364
system.dC_dy.coeffRef(global_eqn_ids[2], global_var_ids[0]) =
64-
0.5 * steep / pow(cosh(steep * (p_in - p_out)), 2);
65+
fun_cosh;
6566
system.dC_dy.coeffRef(global_eqn_ids[2], global_var_ids[2]) =
66-
-0.5 * steep / pow(cosh(steep * (p_in - p_out)), 2);
67+
-fun_cosh;
6768
}

src/model/ValveTanh.h

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,39 +39,47 @@
3939
* \f[
4040
* Q_{in}-Q_{out}=0
4141
* \f]
42+
*
43+
* \f[
44+
* \text{valve\_status} = \frac{1}{2}\left(1+tanh\{k(P_{out}-P{in})\}\right)
45+
* \f]
4246
*
4347
* ### Local contributions
4448
*
4549
* \f[
4650
* \mathbf{y}^{e}=\left[\begin{array}{llll}P_{in} & Q_{in} &
47-
* P_{out} & Q_{out}\end{array}\right]^{T} \f]
51+
* P_{out} & Q_{out}\end{array}\right]^{T} & \text{valve\_status}\f]
4852
*
4953
* \f[
5054
* \mathbf{E}^{e}=\left[\begin{array}{cccc}
51-
* 0 & 0 & 0 & 0 \\
52-
* 0 & 0 & 0 & 0
55+
* 0 & 0 & 0 & 0 & 0 \\
56+
* 0 & 0 & 0 & 0 & 0 \\
5357
* \end{array}\right]
5458
* \f]
5559
*
5660
* \f[
5761
* \mathbf{F}^{e}=\left[\begin{array}{cccc}
58-
* 1 & -(R_{max}+R_{min})/2.0 & -1 & 0 \\
59-
* 0 & 1 & 0 & -1
62+
* 1 & -(R_{max}+R_{min})/2.0 & -1 & 0 & 0\\
63+
* 0 & 1 & 0 & -1 & 0\\
64+
* 0 & 0 & 0 & 7 & 1
6065
* \end{array}\right]
6166
* \f]
6267
*
6368
* \f[
6469
* \mathbf{c}^{e}=\left[\begin{array}{c}
6570
* -\frac{1}{2}Q_{in}(R_{max}-R_{min})tanh\{k(P_{out}-P_{in})\} \\
66-
* 0
71+
* 0 \\
72+
* -\frac{1}{2}\left[1+tanh\{k(P_{out}-P_{in})\}\right]
6773
* \end{array}\right]
6874
* \f]
6975
*
7076
* \f[
7177
* \left(\frac{\partial\mathbf{c}}{\partial\mathbf{y}}\right)^{e} =
7278
* \left[\begin{array}{cccc}
73-
* A & B & C & 0 \\
74-
* 0 & 0 & 0 & 0 \end{array}\right] \f]
79+
* A & B & C & 0 & 0\\
80+
* 0 & 0 & 0 & 0 & 0\\
81+
* D & 0 & -D & 0 & 0
82+
* \end{array}\right] \f]
7583
* where,
7684
* \f[
7785
* A = \frac{1}{2} k Q_{in}
@@ -83,12 +91,15 @@
8391
* \f[
8492
* C = -\frac{1}{2} k Q_{in}
8593
* (R_{max}-R_{min})\left[1-tanh^2\{k(P_{out}-P_{in})\}\right] \f]
94+
* \f[
95+
* D = \frac{1}{2} \frac{k}{cosh^2\{k(P_{in}-P_{out})\}} \f]
8696
*
8797
* \f[
8898
* \left(\frac{\partial\mathbf{c}}{\partial\dot{\mathbf{y}}}\right)^{e} =
8999
* \left[\begin{array}{cccc}
90-
* 0 & 0 & 0 & 0 \\
91-
* 0 & 0 & 0 & 0
100+
* 0 & 0 & 0 & 0 & 0\\
101+
* 0 & 0 & 0 & 0 & 0\\
102+
* 0 & 0 & 0 & 0 & 0
92103
* \end{array}\right]
93104
* \f]
94105
*
@@ -190,9 +201,6 @@ class ValveTanh : public Block {
190201
* (relevant for sparse memory reservation)
191202
*/
192203
TripletsContributions num_triplets{5, 0, 3};
193-
194-
private:
195-
double valve_status = -1.0; // 0=closed, 1=open
196204
};
197205

198206
#endif // SVZERODSOLVER_MODEL_VALVETANH_HPP_

0 commit comments

Comments
 (0)