44
55void 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}
0 commit comments