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  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  // compute the primitive variables
71 
72  const ADReal rhoL = rhoAL / AL;
73  const ADRealVectorValue uvecL(rhouAL / rhoAL, rhovAL / rhoAL, rhowAL / rhoAL);
74  const ADReal unL = uvecL * nLR;
75  const ADReal ut1L = uvecL * t1;
76  const ADReal ut2L = uvecL * t2;
77  const ADReal rhoEL = rhoEAL / AL;
78  const ADReal vL = 1.0 / rhoL;
79  const ADReal EL = rhoEAL / rhoAL;
80  const ADReal eL = EL - 0.5 * uvecL * uvecL;
81  const ADReal pL = _fp.p_from_v_e(vL, eL);
82  const ADReal cL = _fp.c_from_v_e(vL, eL);
83 
84  const ADReal rhoR = rhoAR / AR;
85  const ADRealVectorValue uvecR(rhouAR / rhoAR, rhovAR / rhoAR, rhowAR / rhoAR);
86  const ADReal unR = uvecR * nLR;
87  const ADReal ut1R = uvecR * t1;
88  const ADReal ut2R = uvecR * t2;
89  const ADReal rhoER = rhoEAR / AR;
90  const ADReal vR = 1.0 / rhoR;
91  const ADReal ER = rhoEAR / rhoAR;
92  const ADReal eR = ER - 0.5 * uvecR * uvecR;
93  const ADReal pR = _fp.p_from_v_e(vR, eR);
94  const ADReal cR = _fp.c_from_v_e(vR, eR);
95 
96  // compute left and right wave speeds
97  ADReal sL, sR;
99  {
100  // compute Roe-averaged variables
101  const ADReal sqrt_rhoL = sqrt(rhoL);
102  const ADReal sqrt_rhoR = sqrt(rhoR);
103  const ADReal un_roe = (sqrt_rhoL * unL + sqrt_rhoR * unR) / (sqrt_rhoL + sqrt_rhoR);
104  const ADReal ut1_roe = (sqrt_rhoL * ut1L + sqrt_rhoR * ut1R) / (sqrt_rhoL + sqrt_rhoR);
105  const ADReal ut2_roe = (sqrt_rhoL * ut2L + sqrt_rhoR * ut2R) / (sqrt_rhoL + sqrt_rhoR);
106  const ADReal HL = EL + pL / rhoL;
107  const ADReal HR = ER + pR / rhoR;
108  const ADReal H_roe = (sqrt_rhoL * HL + sqrt_rhoR * HR) / (sqrt_rhoL + sqrt_rhoR);
109  const ADRealVectorValue uvec_roe(un_roe, ut1_roe, ut2_roe);
110  const ADReal h_roe = H_roe - 0.5 * uvec_roe * uvec_roe;
111  const ADReal rho_roe = sqrt(rhoL * rhoR);
112  const ADReal v_roe = 1.0 / rho_roe;
113  const ADReal e_roe = _fp.e_from_v_h(v_roe, h_roe);
114  const ADReal c_roe = _fp.c_from_v_e(v_roe, e_roe);
115 
116  sL = min(unL - cL, un_roe - c_roe);
117  sR = max(unR + cR, un_roe + c_roe);
118  }
120  {
121  sL = min(unL - cL, unR - cR);
122  sR = max(unL + cL, unR + cR);
123  }
124  else
125  {
126  mooseAssert(false, "Invalid 'wave_speed_formulation'.");
127  }
128 
129  // compute middle wave speed
130  const ADReal sm = (rhoR * unR * (sR - unR) - rhoL * unL * (sL - unL) + pL - pR) /
131  (rhoR * (sR - unR) - rhoL * (sL - unL));
132 
133  // compute Omega_L, Omega_R
134  const ADReal omegL = 1.0 / (sL - sm);
135  const ADReal omegR = 1.0 / (sR - sm);
136 
137  // compute p^*
138  const ADReal ps = rhoL * (sL - unL) * (sm - unL) + pL;
139 
140  // compute U_L^*, U_R^*
141 
142  const ADReal rhoLs = omegL * (sL - unL) * rhoL;
143  const ADReal rhounLs = omegL * ((sL - unL) * rhoL * unL + ps - pL);
144  const ADReal rhoELs = omegL * ((sL - unL) * rhoEL - pL * unL + ps * sm);
145 
146  const ADReal rhoRs = omegR * (sR - unR) * rhoR;
147  const ADReal rhounRs = omegR * ((sR - unR) * rhoR * unR + ps - pR);
148  const ADReal rhoERs = omegR * ((sR - unR) * rhoER - pR * unR + ps * sm);
149 
150  std::vector<ADReal> UL_1d(THMVACE1D::N_FLUX_INPUTS);
151  UL_1d[THMVACE1D::RHOA] = UL[THMVACE3D::RHOA];
152  UL_1d[THMVACE1D::RHOUA] = UL[THMVACE3D::RHOUA];
153  UL_1d[THMVACE1D::RHOEA] = UL[THMVACE3D::RHOEA];
154  UL_1d[THMVACE1D::AREA] = UL[THMVACE3D::AREA];
155 
156  std::vector<ADReal> UR_1d(THMVACE1D::N_FLUX_INPUTS);
157  UR_1d[THMVACE1D::RHOA] = UR[THMVACE3D::RHOA];
158  UR_1d[THMVACE1D::RHOUA] = UR[THMVACE3D::RHOUA];
159  UR_1d[THMVACE1D::RHOEA] = UR[THMVACE3D::RHOEA];
160  UR_1d[THMVACE1D::AREA] = UR[THMVACE3D::AREA];
161 
162  const ADReal A_flow = computeFlowArea(UL_1d, UR_1d);
163 
164  // compute the fluxes
165  FL.resize(THMVACE3D::N_FLUX_OUTPUTS);
166  if (sL > 0.0)
167  {
168  FL[THMVACE3D::MASS] = unL * rhoL * A_flow;
169  FL[THMVACE3D::MOM_NORM] = (unL * rhoL * unL + pL) * A_flow;
170  FL[THMVACE3D::MOM_TAN1] = rhoL * unL * ut1L * A_flow;
171  FL[THMVACE3D::MOM_TAN2] = rhoL * unL * ut2L * A_flow;
172  FL[THMVACE3D::ENERGY] = unL * (rhoEL + pL) * A_flow;
173 
174  _last_region_index = 0;
175  }
176  else if (sL <= 0.0 && sm > 0.0)
177  {
178  FL[THMVACE3D::MASS] = sm * rhoLs * A_flow;
179  FL[THMVACE3D::MOM_NORM] = (sm * rhounLs + ps) * A_flow;
180  FL[THMVACE3D::MOM_TAN1] = rhounLs * ut1L * A_flow;
181  FL[THMVACE3D::MOM_TAN2] = rhounLs * ut2L * A_flow;
182  FL[THMVACE3D::ENERGY] = sm * (rhoELs + ps) * A_flow;
183 
184  _last_region_index = 1;
185  }
186  else if (sm <= 0.0 && sR >= 0.0)
187  {
188  FL[THMVACE3D::MASS] = sm * rhoRs * A_flow;
189  FL[THMVACE3D::MOM_NORM] = (sm * rhounRs + ps) * A_flow;
190  FL[THMVACE3D::MOM_TAN1] = rhounRs * ut1R * A_flow;
191  FL[THMVACE3D::MOM_TAN2] = rhounRs * ut2R * A_flow;
192  FL[THMVACE3D::ENERGY] = sm * (rhoERs + ps) * A_flow;
193 
194  _last_region_index = 2;
195  }
196  else if (sR < 0.0)
197  {
198  FL[THMVACE3D::MASS] = unR * rhoR * A_flow;
199  FL[THMVACE3D::MOM_NORM] = (unR * rhoR * unR + pR) * A_flow;
200  FL[THMVACE3D::MOM_TAN1] = rhoR * unR * ut1R * A_flow;
201  FL[THMVACE3D::MOM_TAN2] = rhoR * unR * ut2R * A_flow;
202  FL[THMVACE3D::ENERGY] = unR * (rhoER + pR) * A_flow;
203 
204  _last_region_index = 3;
205  }
206  else
207  std::fill(FL.begin(), FL.end(), getNaN());
208 
209  FR = FL;
210 
211  const ADReal A_wall_L = AL - A_flow;
212  FL[THMVACE3D::MOM_NORM] += pL * A_wall_L;
213 
214  const ADReal A_wall_R = AR - A_flow;
215  FR[THMVACE3D::MOM_NORM] += pR * A_wall_R;
216 }
217 
218 ADReal
219 ADNumericalFlux3EqnHLLC::computeFlowArea(const std::vector<ADReal> & UL,
220  const std::vector<ADReal> & UR) const
221 {
222  return std::min(UL[THMVACE1D::AREA], UR[THMVACE1D::AREA]);
223 }
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)
auto max(const L &left, const R &right)
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)
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
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
auto min(const L &left, const R &right)
static const std::string cL
Definition: NS.h:111