https://mooseframework.inl.gov
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 
14 registerMooseObject("ThermalHydraulicsApp", ADNumericalFlux3EqnHLLC);
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 
44 void
45 ADNumericalFlux3EqnHLLC::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 
55  const ADReal rhoAL = UL[THMVACE3D::RHOA];
56  const ADReal rhouAL = UL[THMVACE3D::RHOUA];
57  const ADReal rhovAL = UL[THMVACE3D::RHOVA];
58  const ADReal rhowAL = UL[THMVACE3D::RHOWA];
59  const ADReal rhoEAL = UL[THMVACE3D::RHOEA];
60  const ADReal AL = UL[THMVACE3D::AREA];
61 
62  const ADReal rhoAR = UR[THMVACE3D::RHOA];
63  const ADReal rhouAR = UR[THMVACE3D::RHOUA];
64  const ADReal rhovAR = UR[THMVACE3D::RHOVA];
65  const ADReal rhowAR = UR[THMVACE3D::RHOWA];
66  const ADReal rhoEAR = UR[THMVACE3D::RHOEA];
67  const ADReal AR = UR[THMVACE3D::AREA];
68 
69  // compute the primitive variables
70 
71  const ADReal rhoL = rhoAL / AL;
72  const ADRealVectorValue uvecL(rhouAL / rhoAL, rhovAL / rhoAL, rhowAL / rhoAL);
73  const ADReal unL = uvecL * nLR;
74  const ADReal ut1L = uvecL * t1;
75  const ADReal ut2L = uvecL * t2;
76  const ADReal rhoEL = rhoEAL / AL;
77  const ADReal vL = 1.0 / rhoL;
78  const ADReal EL = rhoEAL / rhoAL;
79  const ADReal eL = EL - 0.5 * uvecL * uvecL;
80  const ADReal pL = _fp.p_from_v_e(vL, eL);
81  const ADReal cL = _fp.c_from_v_e(vL, eL);
82 
83  const ADReal rhoR = rhoAR / AR;
84  const ADRealVectorValue uvecR(rhouAR / rhoAR, rhovAR / rhoAR, rhowAR / rhoAR);
85  const ADReal unR = uvecR * nLR;
86  const ADReal ut1R = uvecR * t1;
87  const ADReal ut2R = uvecR * t2;
88  const ADReal rhoER = rhoEAR / AR;
89  const ADReal vR = 1.0 / rhoR;
90  const ADReal ER = rhoEAR / rhoAR;
91  const ADReal eR = ER - 0.5 * uvecR * uvecR;
92  const ADReal pR = _fp.p_from_v_e(vR, eR);
93  const ADReal cR = _fp.c_from_v_e(vR, eR);
94 
95  // compute left and right wave speeds
96  ADReal sL, sR;
98  {
99  // compute Roe-averaged variables
100  const ADReal sqrt_rhoL = std::sqrt(rhoL);
101  const ADReal sqrt_rhoR = std::sqrt(rhoR);
102  const ADReal un_roe = (sqrt_rhoL * unL + sqrt_rhoR * unR) / (sqrt_rhoL + sqrt_rhoR);
103  const ADReal ut1_roe = (sqrt_rhoL * ut1L + sqrt_rhoR * ut1R) / (sqrt_rhoL + sqrt_rhoR);
104  const ADReal ut2_roe = (sqrt_rhoL * ut2L + sqrt_rhoR * ut2R) / (sqrt_rhoL + sqrt_rhoR);
105  const ADReal HL = EL + pL / rhoL;
106  const ADReal HR = ER + pR / rhoR;
107  const ADReal H_roe = (sqrt_rhoL * HL + sqrt_rhoR * HR) / (sqrt_rhoL + sqrt_rhoR);
108  const ADRealVectorValue uvec_roe(un_roe, ut1_roe, ut2_roe);
109  const ADReal h_roe = H_roe - 0.5 * uvec_roe * uvec_roe;
110  const ADReal rho_roe = std::sqrt(rhoL * rhoR);
111  const ADReal v_roe = 1.0 / rho_roe;
112  const ADReal e_roe = _fp.e_from_v_h(v_roe, h_roe);
113  const ADReal c_roe = _fp.c_from_v_e(v_roe, e_roe);
114 
115  sL = std::min(unL - cL, un_roe - c_roe);
116  sR = std::max(unR + cR, un_roe + c_roe);
117  }
119  {
120  sL = std::min(unL - cL, unR - cR);
121  sR = std::max(unL + cL, unR + cR);
122  }
123  else
124  {
125  mooseAssert(false, "Invalid 'wave_speed_formulation'.");
126  }
127 
128  // compute middle wave speed
129  const ADReal sm = (rhoR * unR * (sR - unR) - rhoL * unL * (sL - unL) + pL - pR) /
130  (rhoR * (sR - unR) - rhoL * (sL - unL));
131 
132  // compute Omega_L, Omega_R
133  const ADReal omegL = 1.0 / (sL - sm);
134  const ADReal omegR = 1.0 / (sR - sm);
135 
136  // compute p^*
137  const ADReal ps = rhoL * (sL - unL) * (sm - unL) + pL;
138 
139  // compute U_L^*, U_R^*
140 
141  const ADReal rhoLs = omegL * (sL - unL) * rhoL;
142  const ADReal rhounLs = omegL * ((sL - unL) * rhoL * unL + ps - pL);
143  const ADReal rhoELs = omegL * ((sL - unL) * rhoEL - pL * unL + ps * sm);
144 
145  const ADReal rhoRs = omegR * (sR - unR) * rhoR;
146  const ADReal rhounRs = omegR * ((sR - unR) * rhoR * unR + ps - pR);
147  const ADReal rhoERs = omegR * ((sR - unR) * rhoER - pR * unR + ps * sm);
148 
149  std::vector<ADReal> UL_1d(THMVACE1D::N_FLUX_INPUTS);
150  UL_1d[THMVACE1D::RHOA] = UL[THMVACE3D::RHOA];
151  UL_1d[THMVACE1D::RHOUA] = UL[THMVACE3D::RHOUA];
152  UL_1d[THMVACE1D::RHOEA] = UL[THMVACE3D::RHOEA];
153  UL_1d[THMVACE1D::AREA] = UL[THMVACE3D::AREA];
154 
155  std::vector<ADReal> UR_1d(THMVACE1D::N_FLUX_INPUTS);
156  UR_1d[THMVACE1D::RHOA] = UR[THMVACE3D::RHOA];
157  UR_1d[THMVACE1D::RHOUA] = UR[THMVACE3D::RHOUA];
158  UR_1d[THMVACE1D::RHOEA] = UR[THMVACE3D::RHOEA];
159  UR_1d[THMVACE1D::AREA] = UR[THMVACE3D::AREA];
160 
161  const ADReal A_flow = computeFlowArea(UL_1d, UR_1d);
162 
163  // compute the fluxes
164  FL.resize(THMVACE3D::N_FLUX_OUTPUTS);
165  if (sL > 0.0)
166  {
167  FL[THMVACE3D::MASS] = unL * rhoL * A_flow;
168  FL[THMVACE3D::MOM_NORM] = (unL * rhoL * unL + pL) * A_flow;
169  FL[THMVACE3D::MOM_TAN1] = rhoL * unL * ut1L * A_flow;
170  FL[THMVACE3D::MOM_TAN2] = rhoL * unL * ut2L * A_flow;
171  FL[THMVACE3D::ENERGY] = unL * (rhoEL + pL) * A_flow;
172 
173  _last_region_index = 0;
174  }
175  else if (sL <= 0.0 && sm > 0.0)
176  {
177  FL[THMVACE3D::MASS] = sm * rhoLs * A_flow;
178  FL[THMVACE3D::MOM_NORM] = (sm * rhounLs + ps) * A_flow;
179  FL[THMVACE3D::MOM_TAN1] = rhounLs * ut1L * A_flow;
180  FL[THMVACE3D::MOM_TAN2] = rhounLs * ut2L * A_flow;
181  FL[THMVACE3D::ENERGY] = sm * (rhoELs + ps) * A_flow;
182 
183  _last_region_index = 1;
184  }
185  else if (sm <= 0.0 && sR >= 0.0)
186  {
187  FL[THMVACE3D::MASS] = sm * rhoRs * A_flow;
188  FL[THMVACE3D::MOM_NORM] = (sm * rhounRs + ps) * A_flow;
189  FL[THMVACE3D::MOM_TAN1] = rhounRs * ut1R * A_flow;
190  FL[THMVACE3D::MOM_TAN2] = rhounRs * ut2R * A_flow;
191  FL[THMVACE3D::ENERGY] = sm * (rhoERs + ps) * A_flow;
192 
193  _last_region_index = 2;
194  }
195  else if (sR < 0.0)
196  {
197  FL[THMVACE3D::MASS] = unR * rhoR * A_flow;
198  FL[THMVACE3D::MOM_NORM] = (unR * rhoR * unR + pR) * A_flow;
199  FL[THMVACE3D::MOM_TAN1] = rhoR * unR * ut1R * A_flow;
200  FL[THMVACE3D::MOM_TAN2] = rhoR * unR * ut2R * A_flow;
201  FL[THMVACE3D::ENERGY] = unR * (rhoER + pR) * A_flow;
202 
203  _last_region_index = 3;
204  }
205  else
206  std::fill(FL.begin(), FL.end(), getNaN());
207 
208  FR = FL;
209 
210  const ADReal A_wall_L = AL - A_flow;
211  FL[THMVACE3D::MOM_NORM] += pL * A_wall_L;
212 
213  const ADReal A_wall_R = AR - A_flow;
214  FR[THMVACE3D::MOM_NORM] += pR * A_wall_R;
215 }
216 
217 ADReal
218 ADNumericalFlux3EqnHLLC::computeFlowArea(const std::vector<ADReal> & UL,
219  const std::vector<ADReal> & UR) const
220 {
221  return std::min(UL[THMVACE1D::AREA], UR[THMVACE1D::AREA]);
222 }
static const unsigned int N_FLUX_OUTPUTS
Number of numerical flux function outputs for 3D.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
Real getNaN() const
Throws an error or returns a NaN with or without a warning, with a default message.
Definition: NaNInterface.h:46
static InputParameters validParams()
WaveSpeedFormulation
Type for how to compute left and right wave speeds.
DualNumber< Real, DNDerivativeType, true > ADReal
unsigned int _last_region_index
Index describing the region last entered, which is useful for testing and debugging.
void addRequiredParam(const std::string &name, const std::string &doc_string)
const SinglePhaseFluidProperties & _fp
fluid properties user object
Computes internal side flux for the 1-D, 1-phase, variable-area Euler equations using the HLLC approx...
static InputParameters validParams()
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.
const WaveSpeedFormulation _wave_speed_formulation
How to compute left and right wave speeds.
Common class for single phase fluid properties.
Base class for computing numerical fluxes for FlowModelSinglePhase.
static const unsigned int N_FLUX_INPUTS
Number of numerical flux function inputs for 1D.
ADNumericalFlux3EqnHLLC(const InputParameters &parameters)
registerMooseObject("ThermalHydraulicsApp", ADNumericalFlux3EqnHLLC)
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.
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
Definition: NaNInterface.C:15
Interface class for producing errors, warnings, or just quiet NaNs.
Definition: NaNInterface.h:22
static const std::string cL
Definition: NS.h:111