https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ADNumericalFlux3EqnHLLC.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
11#include "THMIndicesVACE.h"
12#include "Numerics.h"
13
15
18{
20 params += NaNInterface::validParams();
21
22 MooseEnum wave_speed_formulation("einfeldt davis", "einfeldt");
23 params.addParam<MooseEnum>(
24 "wave_speed_formulation", wave_speed_formulation, "Method for computing wave speeds");
25
26 params.addRequiredParam<UserObjectName>("fluid_properties",
27 "Name for fluid properties user object");
28
29 params.addClassDescription("Computes internal side flux for the 1-D, 1-phase, variable-area "
30 "Euler equations using the HLLC approximate Riemann solver.");
31
32 return params;
33}
34
36 : ADNumericalFlux3EqnBase(parameters),
37 NaNInterface(this),
38 _fp(getUserObject<SinglePhaseFluidProperties>("fluid_properties")),
39 _wave_speed_formulation(
40 getParam<MooseEnum>("wave_speed_formulation").getEnum<WaveSpeedFormulation>())
41{
42}
43
44void
45ADNumericalFlux3EqnHLLC::calcFlux(const std::vector<ADReal> & UL,
46 const std::vector<ADReal> & UR,
47 const RealVectorValue & nLR,
48 const RealVectorValue & t1,
49 const RealVectorValue & t2,
50 std::vector<ADReal> & FL,
51 std::vector<ADReal> & FR) const
52{
53 // extract the conserved variables and area
54 using std::sqrt, std::min, std::max;
55
56 const ADReal rhoAL = UL[THMVACE3D::RHOA];
57 const ADReal rhouAL = UL[THMVACE3D::RHOUA];
58 const ADReal rhovAL = UL[THMVACE3D::RHOVA];
59 const ADReal rhowAL = UL[THMVACE3D::RHOWA];
60 const ADReal rhoEAL = UL[THMVACE3D::RHOEA];
61 const ADReal AL = UL[THMVACE3D::AREA];
62
63 const ADReal rhoAR = UR[THMVACE3D::RHOA];
64 const ADReal rhouAR = UR[THMVACE3D::RHOUA];
65 const ADReal rhovAR = UR[THMVACE3D::RHOVA];
66 const ADReal rhowAR = UR[THMVACE3D::RHOWA];
67 const ADReal rhoEAR = UR[THMVACE3D::RHOEA];
68 const ADReal AR = UR[THMVACE3D::AREA];
69
70 const auto n_passives = UL.size() - THMVACE3D::N_FLUX_INPUTS;
71 std::vector<ADReal> passivesL(n_passives, 0.0), passivesR(n_passives, 0.0);
72 for (const auto i : make_range(n_passives))
73 {
74 passivesL[i] = UL[THMVACE3D::N_FLUX_INPUTS + i] / AL;
75 passivesR[i] = UR[THMVACE3D::N_FLUX_INPUTS + i] / AR;
76 }
77
78 // compute the primitive variables
79
80 const ADReal rhoL = rhoAL / AL;
81 const ADRealVectorValue uvecL(rhouAL / rhoAL, rhovAL / rhoAL, rhowAL / rhoAL);
82 const ADReal unL = uvecL * nLR;
83 const ADReal ut1L = uvecL * t1;
84 const ADReal ut2L = uvecL * t2;
85 const ADReal rhoEL = rhoEAL / AL;
86 const ADReal vL = 1.0 / rhoL;
87 const ADReal EL = rhoEAL / rhoAL;
88 const ADReal eL = EL - 0.5 * uvecL * uvecL;
89 const ADReal pL = _fp.p_from_v_e(vL, eL);
90 const ADReal cL = _fp.c_from_v_e(vL, eL);
91
92 const ADReal rhoR = rhoAR / AR;
93 const ADRealVectorValue uvecR(rhouAR / rhoAR, rhovAR / rhoAR, rhowAR / rhoAR);
94 const ADReal unR = uvecR * nLR;
95 const ADReal ut1R = uvecR * t1;
96 const ADReal ut2R = uvecR * t2;
97 const ADReal rhoER = rhoEAR / AR;
98 const ADReal vR = 1.0 / rhoR;
99 const ADReal ER = rhoEAR / rhoAR;
100 const ADReal eR = ER - 0.5 * uvecR * uvecR;
101 const ADReal pR = _fp.p_from_v_e(vR, eR);
102 const ADReal cR = _fp.c_from_v_e(vR, eR);
103
104 // compute left and right wave speeds
105 ADReal sL, sR;
107 {
108 // compute Roe-averaged variables
109 const ADReal sqrt_rhoL = sqrt(rhoL);
110 const ADReal sqrt_rhoR = sqrt(rhoR);
111 const ADReal un_roe = (sqrt_rhoL * unL + sqrt_rhoR * unR) / (sqrt_rhoL + sqrt_rhoR);
112 const ADReal ut1_roe = (sqrt_rhoL * ut1L + sqrt_rhoR * ut1R) / (sqrt_rhoL + sqrt_rhoR);
113 const ADReal ut2_roe = (sqrt_rhoL * ut2L + sqrt_rhoR * ut2R) / (sqrt_rhoL + sqrt_rhoR);
114 const ADReal HL = EL + pL / rhoL;
115 const ADReal HR = ER + pR / rhoR;
116 const ADReal H_roe = (sqrt_rhoL * HL + sqrt_rhoR * HR) / (sqrt_rhoL + sqrt_rhoR);
117 const ADRealVectorValue uvec_roe(un_roe, ut1_roe, ut2_roe);
118 const ADReal h_roe = H_roe - 0.5 * uvec_roe * uvec_roe;
119 const ADReal rho_roe = sqrt(rhoL * rhoR);
120 const ADReal v_roe = 1.0 / rho_roe;
121 const ADReal e_roe = _fp.e_from_v_h(v_roe, h_roe);
122 const ADReal c_roe = _fp.c_from_v_e(v_roe, e_roe);
123
124 sL = min(unL - cL, un_roe - c_roe);
125 sR = max(unR + cR, un_roe + c_roe);
126 }
128 {
129 sL = min(unL - cL, unR - cR);
130 sR = max(unL + cL, unR + cR);
131 }
132 else
133 {
134 mooseAssert(false, "Invalid 'wave_speed_formulation'.");
135 }
136
137 // compute middle wave speed
138 const ADReal sm = (rhoR * unR * (sR - unR) - rhoL * unL * (sL - unL) + pL - pR) /
139 (rhoR * (sR - unR) - rhoL * (sL - unL));
140
141 // compute Omega_L, Omega_R
142 const ADReal omegL = 1.0 / (sL - sm);
143 const ADReal omegR = 1.0 / (sR - sm);
144
145 // compute p^*
146 const ADReal ps = rhoL * (sL - unL) * (sm - unL) + pL;
147
148 // compute U_L^*, U_R^*
149
150 const ADReal rhoLs = omegL * (sL - unL) * rhoL;
151 const ADReal rhounLs = omegL * ((sL - unL) * rhoL * unL + ps - pL);
152 const ADReal rhoELs = omegL * ((sL - unL) * rhoEL - pL * unL + ps * sm);
153
154 const ADReal rhoRs = omegR * (sR - unR) * rhoR;
155 const ADReal rhounRs = omegR * ((sR - unR) * rhoR * unR + ps - pR);
156 const ADReal rhoERs = omegR * ((sR - unR) * rhoER - pR * unR + ps * sm);
157
158 std::vector<ADReal> UL_1d(THMVACE1D::N_FLUX_INPUTS);
159 UL_1d[THMVACE1D::RHOA] = UL[THMVACE3D::RHOA];
162 UL_1d[THMVACE1D::AREA] = UL[THMVACE3D::AREA];
163
164 std::vector<ADReal> UR_1d(THMVACE1D::N_FLUX_INPUTS);
165 UR_1d[THMVACE1D::RHOA] = UR[THMVACE3D::RHOA];
168 UR_1d[THMVACE1D::AREA] = UR[THMVACE3D::AREA];
169
170 const ADReal A_flow = computeFlowArea(UL_1d, UR_1d);
171
172 // compute the fluxes
173 FL.resize(THMVACE3D::N_FLUX_OUTPUTS + n_passives);
174 if (sL > 0.0)
175 {
176 FL[THMVACE3D::MASS] = unL * rhoL * A_flow;
177 FL[THMVACE3D::MOM_NORM] = (unL * rhoL * unL + pL) * A_flow;
178 FL[THMVACE3D::MOM_TAN1] = rhoL * unL * ut1L * A_flow;
179 FL[THMVACE3D::MOM_TAN2] = rhoL * unL * ut2L * A_flow;
180 FL[THMVACE3D::ENERGY] = unL * (rhoEL + pL) * A_flow;
181 for (const auto i : make_range(n_passives))
182 FL[THMVACE3D::N_FLUX_OUTPUTS + i] = passivesL[i] * unL * A_flow;
183
185 }
186 else if (sL <= 0.0 && sm > 0.0)
187 {
188 FL[THMVACE3D::MASS] = sm * rhoLs * A_flow;
189 FL[THMVACE3D::MOM_NORM] = (sm * rhounLs + ps) * A_flow;
190 FL[THMVACE3D::MOM_TAN1] = rhounLs * ut1L * A_flow;
191 FL[THMVACE3D::MOM_TAN2] = rhounLs * ut2L * A_flow;
192 FL[THMVACE3D::ENERGY] = sm * (rhoELs + ps) * A_flow;
193 for (const auto i : make_range(n_passives))
194 {
195 const auto passiveLs = omegL * (sL - unL) * passivesL[i];
196 FL[THMVACE3D::N_FLUX_OUTPUTS + i] = passiveLs * sm * A_flow;
197 }
198
200 }
201 else if (sm <= 0.0 && sR >= 0.0)
202 {
203 FL[THMVACE3D::MASS] = sm * rhoRs * A_flow;
204 FL[THMVACE3D::MOM_NORM] = (sm * rhounRs + ps) * A_flow;
205 FL[THMVACE3D::MOM_TAN1] = rhounRs * ut1R * A_flow;
206 FL[THMVACE3D::MOM_TAN2] = rhounRs * ut2R * A_flow;
207 FL[THMVACE3D::ENERGY] = sm * (rhoERs + ps) * A_flow;
208 for (const auto i : make_range(n_passives))
209 {
210 const auto passiveRs = omegR * (sR - unR) * passivesR[i];
211 FL[THMVACE3D::N_FLUX_OUTPUTS + i] = passiveRs * sm * A_flow;
212 }
213
215 }
216 else if (sR < 0.0)
217 {
218 FL[THMVACE3D::MASS] = unR * rhoR * A_flow;
219 FL[THMVACE3D::MOM_NORM] = (unR * rhoR * unR + pR) * A_flow;
220 FL[THMVACE3D::MOM_TAN1] = rhoR * unR * ut1R * A_flow;
221 FL[THMVACE3D::MOM_TAN2] = rhoR * unR * ut2R * A_flow;
222 FL[THMVACE3D::ENERGY] = unR * (rhoER + pR) * A_flow;
223 for (const auto i : make_range(n_passives))
224 FL[THMVACE3D::N_FLUX_OUTPUTS + i] = passivesR[i] * unR * A_flow;
225
227 }
228 else
229 std::fill(FL.begin(), FL.end(), getNaN());
230
231 FR = FL;
232
233 const ADReal A_wall_L = AL - A_flow;
234 FL[THMVACE3D::MOM_NORM] += pL * A_wall_L;
235
236 const ADReal A_wall_R = AR - A_flow;
237 FR[THMVACE3D::MOM_NORM] += pR * A_wall_R;
238}
239
240ADReal
241ADNumericalFlux3EqnHLLC::computeFlowArea(const std::vector<ADReal> & UL,
242 const std::vector<ADReal> & UR) const
243{
244 return std::min(UL[THMVACE1D::AREA], UR[THMVACE1D::AREA]);
245}
registerMooseObject("ThermalHydraulicsApp", ADNumericalFlux3EqnHLLC)
DualNumber< Real, DNDerivativeType, true > ADReal
Base class for computing numerical fluxes for FlowModelSinglePhase.
static InputParameters validParams()
Computes internal side flux for the 1-D, 1-phase, variable-area Euler equations using the HLLC approx...
static InputParameters validParams()
virtual void calcFlux(const std::vector< ADReal > &UL, const std::vector< ADReal > &UR, const RealVectorValue &nLR, const RealVectorValue &t1, const RealVectorValue &t2, std::vector< ADReal > &FL, std::vector< ADReal > &FR) const override
Calculates the 3D flux vectors given "left" and "right" states.
const SinglePhaseFluidProperties & _fp
fluid properties user object
const WaveSpeedFormulation _wave_speed_formulation
How to compute left and right wave speeds.
ADNumericalFlux3EqnHLLC(const InputParameters &parameters)
WaveSpeedFormulation
Type for how to compute left and right wave speeds.
virtual ADReal computeFlowArea(const std::vector< ADReal > &UL, const std::vector< ADReal > &UR) const
Computes the flow area that is used in the numerical flux.
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
Interface class for producing errors, warnings, or just quiet NaNs.
Real getNaN() const
Throws an error or returns a NaN with or without a warning, with a default message.
static InputParameters validParams()
unsigned int _last_region_index
Index describing the region last entered, which is useful for testing and debugging.
Common class for single phase fluid properties.
static const unsigned int N_FLUX_INPUTS
Number of numerical flux function inputs for 1D.
static const unsigned int N_FLUX_INPUTS
Number of numerical flux function inputs for 3D.
static const unsigned int N_FLUX_OUTPUTS
Number of numerical flux function outputs for 3D.