MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
fvcartesiansyseqneegas.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef FVSYSEQNEEGAS_H_
8#define FVSYSEQNEEGAS_H_
9
10#include <algorithm>
11#include <array>
12#include <iterator>
13#include <numeric>
15#include "INCLUDE/maiatypes.h"
16#include "MEMORY/alloc.h"
17#include "filter.h"
18#include "fvcartesiansyseqnns.h"
19
20
21template <MInt nDim>
22class FvSysEqnEEGas : public FvSysEqnNS<nDim> {
23 // Declare parent a friend so that CRTP can access private methods/members
24 // friend class FvSysEqn<nDim>;
25
26 public:
27 FvSysEqnEEGas(const MInt solverId, const MInt noSpecies);
28
29 template <MInt stencil = AUSM>
30 inline void Ausm(const MInt orientation, const MFloat upwindCoefficient, const MFloat A, const MFloat* const leftVars,
31 const MFloat* const rightVars, const MFloat* const NotUsed(srfcCoeff), MFloat* const flux);
32
33 inline void AusmBndryCorrection(const MInt orientation, const MFloat A, const MFloat* const leftVars,
34 const MFloat* const rightVars, MFloat* const flux);
35
36 // Dispatch function for classic five-point-style viscous flux schemes
37 template <MInt stencil>
38 inline void viscousFlux(const MInt orientation, const MFloat A, const MFloat* const vars0, const MFloat* const vars1,
39 const MFloat* const slope0, const MFloat* const slope1, const MFloat* const srfcCoeff,
40 const MFloat f0, const MFloat f1, MFloat* const flux) {
41 if(stencil == FIVE_POINT) {
42 viscousFluxFivePoint(orientation, A, vars0, vars1, slope0, slope1, srfcCoeff, f0, f1, flux);
43 } else {
44 TERMM(1, "Viscous Flux Scheme not implemented.");
45 }
46 }
47
48 // Dispatch function for compact viscous flux schemes
49 template <MInt stencil>
50 inline void viscousFlux(const MInt, const MFloat, const MBool, const MFloat* const, const MFloat* const,
51 const MFloat* const, const MFloat* const, const MFloat* const, const MFloat* const,
52 const MFloat* const, const MFloat* const, const MFloat* const, const MFloat, const MFloat,
53 MFloat* const) {
54 if(stencil == THREE_POINT) {
55 TERMM(1, "Three point viscous Flux Scheme not implemented for SysEqnEEGas.");
56 } else {
57 TERMM(1, "Viscous Flux Scheme not implemented.");
58 }
59 }
60
61 inline void viscousFluxFivePoint(const MInt orientation, const MFloat A, const MFloat* const vars0,
62 const MFloat* const vars1, const MFloat* const slope0, const MFloat* const slope1,
63 const MFloat* const srfcCoeff, const MFloat f0, const MFloat f1, MFloat* const flux);
64
65 inline void computePrimitiveVariables(const MFloat* const cvarsCell, MFloat* const pvarsCell,
66 const MFloat* const avarsCell);
67
68 inline void computeConservativeVariables(const MFloat* const pvarsCell, MFloat* const cvarsCell,
69 const MFloat* const NotUsed(avarsCell));
70
71 inline std::vector<std::vector<MFloat>> conservativeSlopes(const MFloat* const pvarsCell,
72 const MFloat* const cvarsCell,
73 const MFloat* const avarsCell,
74 const MFloat* const slopesCell);
75
76 private:
78 using Base::index0;
79 using Base::index1;
81 using Base::m_solverId;
82
83 // Equation specific values
85 using Base::m_gamma;
87 using Base::m_gFGMOrPr;
93
95
96 void readProperties();
98
99 public:
100 using Base::m_muInfinity;
101 using Base::m_Re0;
102
103 // Hold indices for primitive and conservative variables
105 struct FluxVariables;
106 struct PrimitiveVariables;
107 struct AdditionalVariables;
108 static constexpr MBool hasAV = true;
109 static constexpr MBool hasSC = false;
111 FluxVariables* FV = nullptr;
114};
115
116
119template <MInt nDim>
121 static const MInt Segfault = std::numeric_limits<MInt>::min();
122
123 static constexpr MUint m_noSpecies = 1;
124 static constexpr MInt noVariables = nDim + 1;
125
126 // these are the actual conservative variables. A is the void fraction alpha.
127 static constexpr MInt A_RHO_U = 0;
128 static constexpr MInt A_RHO_V = 1;
129 static constexpr MInt A_RHO_W = nDim == 3 ? 2 : Segfault;
130 static constexpr std::array<MInt, nDim> A_RHO_VV = getArray012();
131 static constexpr MInt A_RHO = nDim;
132
133 // the other ones are neccesary to compile the code.
134 static constexpr MInt RHO_U = 0;
135 static constexpr MInt RHO_V = 1;
136 static constexpr MInt RHO_W = nDim == 3 ? 2 : Segfault;
137 static constexpr std::array<MInt, nDim> RHO_VV = getArray012();
138 static constexpr MInt RHO_E = Segfault;
139 static constexpr MInt RHO = nDim;
140
141 static constexpr MInt RHO_Y[1] = {nDim};
142};
143
145template <MInt nDim>
147 // the Flux variables with P are used for the pressure fluxes in the gas-liquid E-E equations
148 static constexpr MInt P_RHO_U = ConservativeVariables::noVariables + 0;
149 static constexpr MInt P_RHO_V = ConservativeVariables::noVariables + 1;
150 static constexpr MInt P_RHO_W = nDim == 3 ? ConservativeVariables::noVariables + 2 : ConservativeVariables::Segfault;
151 static constexpr std::array<MInt, nDim> P_RHO_VV = [] {
152 IF_CONSTEXPR(nDim == 2) {
154 return a;
155 }
156 else {
159 return a;
160 }
161 }();
162 static constexpr MInt noVariables = ConservativeVariables::noVariables + 3;
163};
164
167template <MInt nDim>
169 static const MInt Segfault = std::numeric_limits<MInt>::min();
170 static constexpr MUint m_noSpecies = 1;
171 static constexpr MInt noVariables = nDim + 3;
172
173 static constexpr MInt U = 0;
174 static constexpr MInt V = 1;
175 static constexpr MInt W = nDim == 3 ? 2 : Segfault;
176 static constexpr std::array<MInt, nDim> VV = getArray012();
177 static constexpr MInt RHO = nDim;
178 static constexpr MInt P = nDim + 1;
179
180 // A is the void fraction alpha
181 static constexpr MInt A = nDim + 2;
182 static constexpr MInt Y[1] = {A};
183
184 const std::array<MString, nDim + 3> varNames = [] {
185 IF_CONSTEXPR(nDim == 2) {
186 std::array<MString, nDim + 3> a = {"u", "v", "rho", "p", "alpha"};
187 return a;
188 }
189 else {
190 std::array<MString, nDim + 3> a = {"u", "v", "w", "rho", "p", "alpha"};
191 return a;
192 }
193 }();
195 for(MInt i = 0; i < noVariables; i++) {
196 names[i] = varNames[i];
197 }
198 };
199};
200
202template <MInt nDim>
204 static constexpr MInt noVariables = 1;
205
206 static constexpr MInt DC = 0; // DepthCorrectionValues
207};
208
209template <MInt nDim>
210template <MInt stencil>
211inline void FvSysEqnEEGas<nDim>::Ausm(const MInt orientation, const MFloat upwindCoefficient, const MFloat A,
212 const MFloat* const leftVars, const MFloat* const rightVars,
213 const MFloat* const NotUsed(srfcCoeff), MFloat* const flux) {
214 // catch the primitive variables rho and p,
215 // compute speed of sound, and interface mach number
216 const MFloat RHOL = leftVars[PV->RHO];
217 const MFloat PL = leftVars[PV->P];
218 const MFloat AL = sqrt(m_gamma * mMax(MFloatEps, PL / mMax(MFloatEps, RHOL)));
219 const MFloat ML = leftVars[orientation] / AL;
220
221 const MFloat ALPHAL = mMax(mMin(leftVars[PV->Y[0]], F1), F0);
222
223 const MFloat RHOR = rightVars[PV->RHO];
224 const MFloat PR = rightVars[PV->P];
225 const MFloat AR = sqrt(m_gamma * mMax(MFloatEps, PR / mMax(MFloatEps, RHOR)));
226 const MFloat MR = rightVars[orientation] / AR;
227
228 const MFloat ALPHAR = mMax(mMin(rightVars[PV->Y[0]], F1), F0);
229
230 // calculation of the resulting pressure and mach number on the surface
231 const MFloat MLR = 0.5 * (ML + MR);
232 const MFloat PLR = PL * (0.5 + upwindCoefficient * ML) + PR * (0.5 - upwindCoefficient * MR);
233
234 const MFloat ALPHALR = 0.5 * (ALPHAL + ALPHAR);
235
236 // calculation of the left and right rho*a
237 const MFloat RHO_AL = RHOL * AL;
238 const MFloat RHO_AR = RHOR * AR;
239
240 // calculation of the resulting mass flux through the surface
241 const MFloat RHO_U2 = 0.25 * (MLR * (RHO_AL + RHO_AR) + fabs(MLR) * (RHO_AL - RHO_AR));
242 const MFloat AbsRHO_U2 = fabs(RHO_U2);
243
244 std::array<MFloat, nDim> pFactor{};
245 pFactor[orientation] = 1.0;
246
247 for(MUint n = 0; n < nDim; n++) {
248 flux[FV->A_RHO_VV[n]] = ALPHALR
249 * (RHO_U2 * (leftVars[PV->VV[n]] + rightVars[PV->VV[n]])
250 + AbsRHO_U2 * (leftVars[PV->VV[n]] - rightVars[PV->VV[n]]))
251 * A;
252 flux[FV->P_RHO_VV[n]] = PLR * pFactor[n] * A;
253 }
254
255 flux[FV->A_RHO] = ALPHALR * 2.0 * RHO_U2 * A;
256}
257
258template <MInt nDim>
259inline void FvSysEqnEEGas<nDim>::AusmBndryCorrection(const MInt /* orientation */, const MFloat /* A */,
260 const MFloat* const /* leftVars */,
261 const MFloat* const /* rightVars */, MFloat* const flux) {
262 for(MInt n = 0; n < nDim; n++) {
263 flux[FV->A_RHO_VV[n]] = F0;
264 }
265 flux[FV->A_RHO] = F0;
266}
267
268template <MInt nDim>
269inline void FvSysEqnEEGas<nDim>::viscousFluxFivePoint(const MInt orientation, const MFloat A, const MFloat* const vars0,
270 const MFloat* const vars1, const MFloat* const slope0,
271 const MFloat* const slope1,
272 const MFloat* const NotUsed(srfcCoeff), const MFloat f0,
273 const MFloat f1, MFloat* const flux) {
274 static const MFloat F1BRe0 = F1 / m_Re0;
275
276 const MFloat rho = F1B2 * (vars0[PV->RHO] + vars1[PV->RHO]);
277 const MFloat F1Brho = F1 / rho;
278 const MFloat p = F1B2 * (vars0[PV->P] + vars1[PV->P]);
279 const MFloat alpha = F1B2 * (vars0[PV->A] + vars1[PV->A]);
280
281 // Temperature on the surface T = gamma * p / rho
282 const MFloat T = m_gamma * p * F1Brho;
283
284 // Indices for the orientations
285 const MUint id0 = orientation;
286 const MUint id1 = index0[orientation];
287 const MUint id2 = index1[orientation];
288
289 // Compute A / Re
290 const MFloat dAOverRe = A * F1BRe0;
291
292 // calculate the viscosity with the sutherland law mue = T^3/2 * (1+S/T_0)(T + S/T_0)
293 const MFloat mue = (T * sqrt(T) * m_sutherlandPlusOne) / (T + m_sutherlandConstant);
294
295 // Compute the stress terms
296 const MUint s00 = id0 * nDim + id0;
297 const MUint s01 = id0 * nDim + id1;
298 const MUint s10 = id1 * nDim + id0;
299 const MUint s11 = id1 * nDim + id1;
300
301 std::array<MFloat, nDim> tau{};
302 if(nDim == 2) {
303 tau[id0] =
304 mue * alpha * (f0 * (F4B3 * slope0[s00] - F2B3 * slope0[s11]) + f1 * (F4B3 * slope1[s00] - F2B3 * slope1[s11]));
305 tau[id1] = mue * alpha * (f0 * (slope0[s01] + slope0[s10]) + f1 * (slope1[s01] + slope1[s10]));
306 } else if(nDim == 3) {
307 const MUint s22 = id2 * nDim + id2;
308 const MUint s02 = id0 * nDim + id2;
309 const MUint s20 = id2 * nDim + id0;
310 tau[id0] = mue * alpha
311 * (f0 * (F4B3 * slope0[s00] - F2B3 * (slope0[s11] + slope0[s22]))
312 + f1 * (F4B3 * slope1[s00] - F2B3 * (slope1[s11] + slope1[s22])));
313 tau[id1] = mue * alpha * (f0 * (slope0[s01] + slope0[s10]) + f1 * (slope1[s01] + slope1[s10]));
314 tau[id2] = mue * alpha * (f0 * (slope0[s02] + slope0[s20]) + f1 * (slope1[s02] + slope1[s20]));
315 }
316
317 // Compute the flux
318 for(MUint n = 0; n < nDim; n++) {
319 flux[FV->A_RHO_VV[n]] -= dAOverRe * tau[n];
320 }
321}
322
323template <MInt nDim>
324inline void FvSysEqnEEGas<nDim>::computePrimitiveVariables(const MFloat* const cvarsCell, MFloat* const pvarsCell,
325 const MFloat* const avarsCell) {
326 MFloat fRhoAlpha = F0;
327 if(cvarsCell[CV->A_RHO] > -m_EEGasEps) {
328 fRhoAlpha = F1 / mMax(cvarsCell[CV->A_RHO], m_EEGasEps);
329 } else {
330 fRhoAlpha = F1 / cvarsCell[CV->A_RHO];
331 }
332
333 for(MInt vel = 0; vel < nDim; ++vel) {
334 pvarsCell[PV->VV[vel]] = cvarsCell[CV->A_RHO_VV[vel]] * fRhoAlpha;
335 }
336 pvarsCell[PV->RHO] = pvarsCell[PV->P] * m_gamma + avarsCell[AV->DC]; // density
337
338 pvarsCell[PV->A] = cvarsCell[CV->A_RHO] / pvarsCell[PV->RHO]; // alpha
339}
340
341template <MInt nDim>
343 MFloat* const cvarsCell,
344 const MFloat* const NotUsed(avarsCell)) {
345 cvarsCell[CV->A_RHO] = pvarsCell[PV->RHO] * pvarsCell[PV->A];
346 for(MInt vel = 0; vel < nDim; vel++) {
347 cvarsCell[CV->A_RHO_VV[vel]] = cvarsCell[CV->A_RHO] * pvarsCell[PV->VV[vel]];
348 }
349}
350
351template <MInt nDim>
352inline std::vector<std::vector<MFloat>>
353FvSysEqnEEGas<nDim>::conservativeSlopes(const MFloat* const NotUsed(pvarsCell), const MFloat* const NotUsed(cvarsCell),
354 const MFloat* const NotUsed(avarsCell),
355 const MFloat* const NotUsed(slopesCell)) {
356 mTerm(1, AT_,
357 "SysEqnEEGas has not been tested with adaptation. The computation of the conservative variables should be "
358 "adjusted. Terminating.");
359 std::vector<std::vector<MFloat>> dQ(CV->noVariables, std::vector<MFloat>(nDim));
360 return dQ;
361}
362
363#endif // FVSYSEQNEEGAS_H_
static constexpr std::array< MInt, nDim > getArray012()
static constexpr MBool hasSC
void Ausm(const MInt orientation, const MFloat upwindCoefficient, const MFloat A, const MFloat *const leftVars, const MFloat *const rightVars, const MFloat *const NotUsed(srfcCoeff), MFloat *const flux)
AdditionalVariables * AV
void viscousFlux(const MInt orientation, const MFloat A, const MFloat *const vars0, const MFloat *const vars1, const MFloat *const slope0, const MFloat *const slope1, const MFloat *const srfcCoeff, const MFloat f0, const MFloat f1, MFloat *const flux)
PrimitiveVariables * PV
FluxVariables * FV
void AusmBndryCorrection(const MInt orientation, const MFloat A, const MFloat *const leftVars, const MFloat *const rightVars, MFloat *const flux)
ConservativeVariables * CV
void viscousFlux(const MInt, const MFloat, const MBool, const MFloat *const, const MFloat *const, const MFloat *const, const MFloat *const, const MFloat *const, const MFloat *const, const MFloat *const, const MFloat *const, const MFloat *const, const MFloat, const MFloat, MFloat *const)
std::vector< std::vector< MFloat > > conservativeSlopes(const MFloat *const pvarsCell, const MFloat *const cvarsCell, const MFloat *const avarsCell, const MFloat *const slopesCell)
void viscousFluxFivePoint(const MInt orientation, const MFloat A, const MFloat *const vars0, const MFloat *const vars1, const MFloat *const slope0, const MFloat *const slope1, const MFloat *const srfcCoeff, const MFloat f0, const MFloat f1, MFloat *const flux)
void computePrimitiveVariables(const MFloat *const cvarsCell, MFloat *const pvarsCell, const MFloat *const avarsCell)
static constexpr MBool hasAV
void computeConservativeVariables(const MFloat *const pvarsCell, MFloat *const cvarsCell, const MFloat *const NotUsed(avarsCell))
MFloat m_sutherlandConstant
static constexpr std::array< MInt, nDim > getArray012()
MFloat m_sutherlandPlusOneThermal
MFloat m_sutherlandPlusOne
MFloat m_referenceTemperature
MFloat m_F1BGammaMinusOne
static const MUint index1[nDim]
static const MUint index0[nDim]
MFloat m_sutherlandConstantThermal
@ FIVE_POINT
Definition: enums.h:184
@ THREE_POINT
Definition: enums.h:184
void mTerm(const MInt errorCode, const MString &location, const MString &message)
Definition: functions.cpp:29
constexpr T mMin(const T &x, const T &y)
Definition: functions.h:90
constexpr T mMax(const T &x, const T &y)
Definition: functions.h:94
int32_t MInt
Definition: maiatypes.h:62
uint32_t MUint
Definition: maiatypes.h:63
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
bool MBool
Definition: maiatypes.h:58
Static indices for accessing additional variables.
Static indices for accessing conservative variables in nDim spatial dimensions.
Static indices for accessing flux variables.
Static indices for accessing primitive variables in nDim spatial dimensions.
Definition: contexttypes.h:19