17#include "metaphysicl/parallel_numberarray.h"
18#include "metaphysicl/parallel_dualnumber.h"
19#include "metaphysicl/parallel_semidynamicsparsenumberarray.h"
20#include "libmesh/parallel_algebra.h"
40 params.
addRequiredParam<UserObjectName>(
"fp",
"Fluid properties user object name");
45 params.
addParam<
bool>(
"apply_velocity_scaling",
47 "Set to true to apply the scaling to the normal velocity. See "
48 "documentation for more information.");
51 "Computes and caches flux and residual vectors for a 1-phase volume junction");
60 _A(adCoupledValue(
"A")),
61 _rhoA(adCoupledValue(
"rhoA")),
62 _rhouA(adCoupledValue(
"rhouA")),
63 _rhoEA(adCoupledValue(
"rhoEA")),
65 _K(getParam<Real>(
"K")),
66 _A_ref(getParam<Real>(
"A_ref")),
68 _apply_velocity_scaling(getParam<bool>(
"apply_velocity_scaling")),
100 const RealVectorValue di =
_dir[0];
101 const RealVectorValue ni = di * din;
102 const Real nJi_dot_di = -din;
119 const bool is_primary_connection = (
c == 0);
120 const auto residual =
computeResidual(flux_3d, Ui, ni, is_primary_connection);
122 for (
const auto i : index_range(
_residual))
128 const std::vector<ADReal> & Ui,
129 const RealVectorValue & ni)
const
131 using std::abs, std::max, std::min;
133 const RealVectorValue nJi = -ni;
135 RealVectorValue t1, t2;
157 const ADReal uni = uveci * nJi;
160 const ADReal vJ = 1.0 / rhoJ;
162 const ADReal eJ = rhoEV / rhoV - 0.5 * uvecJ * uvecJ;
164 const ADReal unJ = uvecJ * nJi;
165 const ADReal ut1J = uvecJ * t1;
166 const ADReal ut2J = uvecJ * t2;
168 const ADReal rhoi = rhoAi / Ai;
169 const ADReal vi = 1.0 / rhoi;
170 const ADReal ei = rhoEAi / rhoAi - 0.5 * uni * uni;
172 const ADReal ci =
_fp.c_from_v_e(vi, ei);
173 const ADReal cJ =
_fp.c_from_v_e(vJ, eJ);
174 const ADReal cmax = max(ci, cJ);
176 const ADReal uni_sign = (uni > 0) - (uni < 0);
177 const ADReal factor = 0.5 * (1.0 - uni_sign) * min(abs(uni - unJ) / cmax, 1.0);
179 const ADReal unJ_mod = uni - factor * (uni - unJ);
181 const ADReal EJ_mod = eJ + 0.5 * uvecJ_mod * uvecJ_mod;
197 std::vector<ADReal> FL, FR;
198 numerical_flux.
calcFlux(UJi, Ui, nJi, t1, t2, FL, FR);
205 const std::vector<ADReal> & Ui,
206 const RealVectorValue & ni,
207 bool is_primary_connection)
const
211 const RealVectorValue nJi = -ni;
213 RealVectorValue t1, t2;
225 const ADReal vJ = 1.0 / rhoJ;
227 const ADReal eJ = rhoEV / rhoV - 0.5 * uvecJ * uvecJ;
228 const ADReal pJ =
_fp.p_from_v_e(vJ, eJ);
232 if (is_primary_connection && std::abs(
_K) > 1e-10)
241 const ADReal uni = uveci * nJi;
244 const ADReal rhouA2 = rhouAi * rhouAi;
245 const ADReal e_in = rhoEAi / rhoAi - 0.5 * rhouA2 / (rhoAi * rhoAi);
246 const ADReal p_in =
_fp.p_from_v_e(v_in, e_in);
247 const ADReal s0_in =
_fp.s_from_v_e(v_in, e_in);
248 const ADReal T_in =
_fp.T_from_v_e(v_in, e_in);
249 const ADReal h_in =
_fp.h_from_p_T(p_in, T_in);
250 const ADReal velin2 = uni * uni;
251 const ADReal h0_in = h_in + 0.5 * velin2;
252 const ADReal p0_in =
_fp.p_from_h_s(h0_in, s0_in);
255 S_loss =
_K * (p0_in - p_in) * Ai;
257 S_loss =
_K * (p0_in - p_in) *
_A_ref;
276 const RealVectorValue ex(1, 0, 0);
277 const RealVectorValue ey(0, 1, 0);
278 const RealVectorValue ez(0, 0, 1);
297std::vector<const MooseVariableBase *>
308std::vector<const MooseVariableBase *>
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("ThermalHydraulicsApp", ADVolumeJunction1PhaseUserObject)
const unsigned int _n_connections
Number of connected flow channels.
const std::vector< Real > & _normal
Flow channel outward normals or junction inward normals.
const MaterialProperty< RealVectorValue > & _dir
Direction of the element connected to the junction.
Base class for computing numerical fluxes for FlowModelSinglePhase.
Computes and caches flux and residual vectors for a 1-phase volume junction.
virtual std::vector< const MooseVariableBase * > getFlowChannelVariables() const override
Gets the flow channel variables.
const SinglePhaseFluidProperties & _fp
Single-phase fluid properties user object.
const ADVariableValue & _rhoEA
rho*E*A of the connected flow channels
std::vector< const ADNumericalFlux3EqnBase * > _numerical_flux_uo
Vector of numerical flux user objects for each connected flow channel.
std::vector< ADReal > computeResidual(const std::vector< ADReal > &flux_3d, const std::vector< ADReal > &Ui, const RealVectorValue &ni, bool is_primary_connection) const
virtual void finalize() override
virtual void computeFluxesAndResiduals(const unsigned int &c) override
Computes and stores the fluxes, the scalar residuals, and their Jacobians.
const bool _apply_velocity_scaling
Apply velocity scaling?
const ADVariableValue & _rhouA
rho*u*A of the connected flow channels
virtual std::vector< const MooseVariableBase * > getJunctionVariables() const override
Gets the junction variables.
const ADVariableValue & _rhoA
rho*A of the connected flow channels
const Real & _A_ref
Reference area.
ADVolumeJunction1PhaseUserObject(const InputParameters ¶ms)
static InputParameters validParams()
std::vector< ADReal > compute3DFlux(const ADNumericalFlux3EqnBase &numerical_flux, const std::vector< ADReal > &Ui, const RealVectorValue &ni) const
const ADVariableValue & _A
Cross-sectional area of connected flow channels.
const Real & _K
Form loss coefficient.
Base class for computing and caching flux and residual vectors for a volume junction.
std::vector< const ADVariableValue * > _junction_var_values
const ADVariableValue & coupledJunctionValue(const std::string &var_name, unsigned int i=0) const
Gets an AD junction variable value.
std::vector< std::vector< ADReal > > _flux
Cached flux vector for each connection.
std::vector< std::string > _scalar_variable_names
Vector of coupled variable names for each scalar variable.
const MooseVariableBase * getJunctionVar(const std::string &var_name, unsigned int i=0) const
Gets a junction variable.
static InputParameters validParams()
std::vector< std::string > _flow_variable_names
Vector of coupled variable names for each flow variable.
unsigned int _n_scalar_eq
Number of scalar residual components.
const std::vector< UserObjectName > & _numerical_flux_names
Names of numerical flux user objects for each connected flow channel.
std::vector< ADReal > _residual
Cached scalar residual vector.
const Real & _volume
Volume of the junction.
std::vector< ADReal > _cached_junction_var_values
MooseVariable * getVar(const std::string &var_name, unsigned int comp)
virtual void calcFlux(const std::vector< ADReal > &UL_3d, const std::vector< ADReal > &UR_3d, const RealVectorValue &nLR, const RealVectorValue &t1, const RealVectorValue &t2, std::vector< ADReal > &FL, std::vector< ADReal > &FR) const =0
Calculates the 3D flux vectors given "left" and "right" states.
Common class for single phase fluid properties.
virtual void finalize()=0
static const unsigned int N_EQ
Number of equations for the junction.
const Parallel::Communicator & comm() const
static const unsigned int N_FLUX_OUTPUTS
Number of numerical flux function outputs for 1D.
static const unsigned int N_FLUX_INPUTS
Number of numerical flux function inputs for 3D.
void v_from_rhoA_A(Real rhoA, Real A, Real &v, Real &dv_drhoA)
Computes specific volume and its derivatives from rho*A, and area.
void computeOrthogonalDirections(const RealVectorValue &n_unnormalized, RealVectorValue &t1, RealVectorValue &t2)
Computes two unit vectors orthogonal to the given vector.