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")),
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);
128 const std::vector<ADReal> & Ui,
131 using std::abs, std::max, std::min;
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);
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,
207 bool is_primary_connection)
const 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;
297 std::vector<const MooseVariableBase *>
308 std::vector<const MooseVariableBase *>
const ADVariableValue & _rhoA
rho*A of the connected flow channels
std::vector< std::vector< ADReal > > _flux
Cached flux vector for each connection.
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
std::vector< ADReal > computeResidual(const std::vector< ADReal > &flux_3d, const std::vector< ADReal > &Ui, const RealVectorValue &ni, bool is_primary_connection) const
static InputParameters validParams()
std::vector< ADReal > _cached_junction_var_values
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.
std::vector< std::string > _scalar_variable_names
Vector of coupled variable names for each scalar variable.
static InputParameters validParams()
const SinglePhaseFluidProperties & _fp
Single-phase fluid properties user object.
virtual std::vector< const MooseVariableBase * > getFlowChannelVariables() const override
Gets the flow channel variables.
const Parallel::Communicator & comm() const
virtual void finalize() override
virtual void computeFluxesAndResiduals(const unsigned int &c) override
Computes and stores the fluxes, the scalar residuals, and their Jacobians.
unsigned int _n_scalar_eq
Number of scalar residual components.
MooseVariable * getVar(const std::string &var_name, unsigned int comp)
const unsigned int _n_connections
Number of connected flow channels.
const std::vector< UserObjectName > & _numerical_flux_names
Names of numerical flux user objects for each connected flow channel.
auto max(const L &left, const R &right)
std::vector< ADReal > _residual
Cached scalar residual vector.
const Real & _volume
Volume of the junction.
std::vector< const ADNumericalFlux3EqnBase * > _numerical_flux_uo
Vector of numerical flux user objects for each connected flow channel.
std::vector< const ADVariableValue * > _junction_var_values
ADVolumeJunction1PhaseUserObject(const InputParameters ¶ms)
std::vector< std::string > _flow_variable_names
Vector of coupled variable names for each flow variable.
const MaterialProperty< RealVectorValue > & _dir
Direction of the element connected to the junction.
static const unsigned int N_EQ
Number of equations for the junction.
const Real & _A_ref
Reference area.
const ADVariableValue & _rhoEA
rho*E*A of the connected flow channels
Common class for single phase fluid properties.
std::vector< ADReal > compute3DFlux(const ADNumericalFlux3EqnBase &numerical_flux, const std::vector< ADReal > &Ui, const RealVectorValue &ni) const
Base class for computing numerical fluxes for FlowModelSinglePhase.
Base class for computing and caching flux and residual vectors for a volume junction.
Computes and caches flux and residual vectors for a 1-phase volume junction.
const Real & _K
Form loss coefficient.
virtual void finalize() override
static const unsigned int N_FLUX_OUTPUTS
Number of numerical flux function outputs for 1D.
void computeOrthogonalDirections(const RealVectorValue &n_unnormalized, RealVectorValue &t1, RealVectorValue &t2)
Computes two unit vectors orthogonal to the given vector.
const ADVariableValue & _A
Cross-sectional area of connected flow channels.
virtual std::vector< const MooseVariableBase * > getJunctionVariables() const override
Gets the junction variables.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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.
const std::vector< Real > & _normal
Flow channel outward normals or junction inward normals.
registerMooseObject("ThermalHydraulicsApp", ADVolumeJunction1PhaseUserObject)
const bool _apply_velocity_scaling
Apply velocity scaling?
auto min(const L &left, const R &right)
const ADVariableValue & _rhouA
rho*u*A of the connected flow channels
const ADVariableValue & coupledJunctionValue(const std::string &var_name, unsigned int i=0) const
Gets an AD junction variable value.
auto index_range(const T &sizable)
const MooseVariableBase * getJunctionVar(const std::string &var_name, unsigned int i=0) const
Gets a junction variable.
static const unsigned int N_FLUX_INPUTS
Number of numerical flux function inputs for 3D.