DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
EulerP_ARS.hpp
Go to the documentation of this file.
1/**
2 * @file EulerP_ARS.hpp
3 * @brief Approximate Riemann Solver (Roe scheme) for the EulerP 5-equation Navier-Stokes system.
4 *
5 * Provides device-callable functions for:
6 * - Entropy-corrected eigenvalue fixing (delegating to @c IdealGas::EntropyFix_HCorrHY)
7 * - Roe-averaged state computation (velocity, enthalpy, density, speed of sound)
8 * - Complete Roe numerical flux for the 5-equation flow system
9 *
10 * The Roe flux formula is F = 0.5 * (F_L + F_R - |A_Roe| * (U_R - U_L)),
11 * where |A_Roe| is the Roe-averaged absolute flux Jacobian.
12 */
13#include "EulerP_Physics.hpp"
14
15namespace DNDS::EulerP
16{
17 /**
18 * @brief Applies entropy fix to Roe eigenvalues to prevent expansion shocks.
19 *
20 * Thin wrapper delegating to @c IdealGas::EntropyFix_HCorrHY, which is shared
21 * with the Euler module. Modifies the three characteristic eigenvalues (lam0, lam123, lam4)
22 * in-place.
23 *
24 * @param aL Speed of sound on the left state.
25 * @param aR Speed of sound on the right state.
26 * @param vnL Normal velocity on the left state.
27 * @param vnR Normal velocity on the right state.
28 * @param dLambda Entropy fix threshold parameter.
29 * @param fixScale Scaling factor for the entropy fix.
30 * @param[in,out] lam0 Eigenvalue for the u-a characteristic wave.
31 * @param[in,out] lam123 Eigenvalue for the u (contact/shear) waves.
32 * @param[in,out] lam4 Eigenvalue for the u+a characteristic wave.
33 */
35 real aL, real aR, real vnL, real vnR,
36 real dLambda, real fixScale,
37 real &lam0, real &lam123, real &lam4)
38 {
39 DNDS::IdealGas::EntropyFix_HCorrHY(aL, aR, vnL, vnR, dLambda, fixScale,
40 lam0, lam123, lam4);
41 }
42
43 /**
44 * @brief Computes Roe-averaged quantities from left and right states.
45 *
46 * Calculates the Roe-averaged velocity, specific total enthalpy, density, and speed of
47 * sound squared using the density-weighted averaging formula:
48 * - phi_Roe = (sqrt(rho_L) * phi_L + sqrt(rho_R) * phi_R) / (sqrt(rho_L) + sqrt(rho_R))
49 * - rho_Roe = sqrt(rho_L * rho_R)
50 *
51 * @note Speed of sound squared uses @c IdealGas::RoeSpeedOfSoundSqr, which assumes a perfect gas.
52 *
53 * @tparam B Device backend (Host or CUDA).
54 * @tparam TUL Left conservative state type (deduced).
55 * @tparam TUR Right conservative state type (deduced).
56 * @tparam TULPrim Left primitive state type (deduced).
57 * @tparam TURPrim Right primitive state type (deduced).
58 * @param UL Left conservative state vector.
59 * @param UR Right conservative state vector.
60 * @param ULPrim Left primitive state vector.
61 * @param URPrim Right primitive state vector.
62 * @param nVars Total number of variables.
63 * @param pL Left pressure.
64 * @param pR Right pressure.
65 * @param phy Physics device view for thermodynamic computations.
66 * @param[out] veloRoe Roe-averaged velocity vector (3 components).
67 * @param[out] vsqrRoe Roe-averaged velocity magnitude squared.
68 * @param[out] HRoe Roe-averaged specific total enthalpy.
69 * @param[out] rhoRoe Roe-averaged density.
70 * @param[out] aSqrRoe Roe-averaged speed of sound squared.
71 */
72 template <DeviceBackend B, class TUL, class TUR, class TULPrim, class TURPrim>
73 DNDS_DEVICE_CALLABLE void RoeAverageNS(TUL &&UL, TUR &&UR,
74 TULPrim &&ULPrim, TURPrim &&URPrim,
75 int nVars,
76 real pL, real pR,
78 Geom::tPoint &veloRoe,
79 real &vsqrRoe,
80 real &HRoe,
81 real &rhoRoe,
82 real &aSqrRoe)
83 {
84 real sqrtRhoLm = std::sqrt(UL(0));
85 real sqrtRhoRm = std::sqrt(UR(0));
86 real HLm = phy.Pressure2Enthalpy(UL, nVars, pL);
87 real HRm = phy.Pressure2Enthalpy(UR, nVars, pR);
88
89 for (int d = 0; d < 3; d++)
90 veloRoe(d) = (sqrtRhoLm * ULPrim(d + 1) + sqrtRhoRm * URPrim(d + 1)) / (sqrtRhoLm + sqrtRhoRm);
91 vsqrRoe = veloRoe.squaredNorm();
92 HRoe = (sqrtRhoLm * HLm + sqrtRhoRm * HRm) / (sqrtRhoLm + sqrtRhoRm);
93 // TODO: be more generic here!!! (phy.gamma - 1) is for perfect gas
94 aSqrRoe = DNDS::IdealGas::RoeSpeedOfSoundSqr(phy.params.gamma, HRoe, vsqrRoe);
95 rhoRoe = sqrtRhoLm * sqrtRhoRm;
96 }
97
98 /**
99 * @brief Computes the complete Roe numerical flux for the 5-equation flow system.
100 *
101 * Implements the Roe approximate Riemann solver:
102 * F = 0.5 * (F_L + F_R - |A_Roe| * dU)
103 *
104 * The procedure:
105 * 1. Decomposes the state jump dU = U_R - U_L into Roe characteristic variables (alpha decomposition)
106 * via @c IdealGas::RoeAlphaDecomposition.
107 * 2. Scales each alpha by the corresponding entropy-fixed eigenvalue (lam0, lam123, lam4).
108 * 3. Accumulates left and right inviscid fluxes via @c GasInviscidFlux_XY.
109 * 4. Subtracts the upwind dissipation from the averaged flux.
110 * 5. Multiplies the result by 0.5 for the final Roe flux.
111 *
112 * @tparam B Device backend (Host or CUDA).
113 * @param UL Left conservative state.
114 * @param UR Right conservative state.
115 * @param pL Left pressure.
116 * @param pR Right pressure.
117 * @param veloRoe Roe-averaged velocity vector (from RoeAverageNS).
118 * @param vsqrRoe Roe-averaged velocity magnitude squared.
119 * @param vgn Grid normal velocity (for ALE; 0 for static mesh).
120 * @param n Outward unit face normal vector.
121 * @param asqrRoe Roe-averaged speed of sound squared.
122 * @param aRoe Roe-averaged speed of sound.
123 * @param HRoe Roe-averaged specific total enthalpy.
124 * @param phy Physics device view.
125 * @param lam0 Entropy-fixed eigenvalue for the u-a wave.
126 * @param lam123 Entropy-fixed eigenvalue for the contact/shear waves.
127 * @param lam4 Entropy-fixed eigenvalue for the u+a wave.
128 * @param[out] F Output Roe flux vector (must be zero-initialized by caller).
129 */
130 template <DeviceBackend B>
131 DNDS_DEVICE_CALLABLE void RoeFluxFlow(const TU &UL, const TU &UR,
132 real pL, real pR,
133 const Geom::tPoint &veloRoe,
134 real vsqrRoe,
135 real vgn, const Geom::tPoint &n,
136 real asqrRoe, real aRoe, real HRoe,
138 real lam0, real lam123, real lam4,
139 TU &F)
140 {
141 using TVec = Geom::tPoint;
142 TU incU = UR - UL;
143 real vnL = U123(UL).dot(n) / UL(0);
144 real vnR = U123(UR).dot(n) / UR(0);
145 real incU123N = U123(incU).dot(n);
146 real veloRoeN = veloRoe.dot(n);
147
148 TVec alpha23V = U123(incU) - incU(0) * veloRoe;
149 TVec alpha23VT = alpha23V - n * alpha23V.dot(n);
150 real incU4b = incU(I4) - alpha23VT.dot(veloRoe);
151 real alpha0, alpha1, alpha4;
152 DNDS::IdealGas::RoeAlphaDecomposition(incU(0), incU123N, incU4b,
153 veloRoeN, HRoe, asqrRoe, aRoe,
154 phy.params.gamma,
155 alpha0, alpha1, alpha4);
156
157 alpha0 *= lam0;
158 alpha1 *= lam123;
159 alpha23VT *= lam123;
160 alpha4 *= lam4; // here becomes alpha_i * lam_i
161
162 GasInviscidFlux_XY(UL, nVarsFlow, vnL, vgn, n, pL, F);
163 GasInviscidFlux_XY(UR, nVarsFlow, vnR, vgn, n, pR, F);
164
165 F(0) -= alpha0 + alpha1 + alpha4;
166 F(I4) -= (HRoe - veloRoeN * aRoe) * alpha0 + 0.5 * vsqrRoe * alpha1 +
167 (HRoe + veloRoeN * aRoe) * alpha4 + alpha23VT.dot(veloRoe);
168 for (int d = 0; d < 3; d++)
169 F(d + 1) -=
170 (veloRoe(d) - aRoe * n(d)) * alpha0 + (veloRoe(d) + aRoe * n(d)) * alpha4 +
171 veloRoe(d) * alpha1 + alpha23VT(d);
172
173 for (int i = 0; i < nVarsFlow; i++)
174 F(i) *= 0.5;
175 }
176}
#define DNDS_DEVICE_CALLABLE
Definition Defines.hpp:76
Physics model definitions for the EulerP module: gas properties, state conversions,...
Namespace for the EulerP alternative evaluator module with GPU support.
Definition EulerP.hpp:29
DNDS_DEVICE_CALLABLE void RoeAverageNS(TUL &&UL, TUR &&UR, TULPrim &&ULPrim, TURPrim &&URPrim, int nVars, real pL, real pR, PhysicsDeviceView< B > &phy, Geom::tPoint &veloRoe, real &vsqrRoe, real &HRoe, real &rhoRoe, real &aSqrRoe)
Computes Roe-averaged quantities from left and right states.
DNDS_DEVICE_CALLABLE void GasInviscidFlux_XY(TU &&U, int nVars, real vn, real vgn, TVecN &&n, real p, TF &F)
Computes the inviscid (Euler) flux projected onto a face normal direction.
DNDS_DEVICE_CALLABLE void RoeFluxFlow(const TU &UL, const TU &UR, real pL, real pR, const Geom::tPoint &veloRoe, real vsqrRoe, real vgn, const Geom::tPoint &n, real asqrRoe, real aRoe, real HRoe, PhysicsDeviceView< B > &phy, real lam0, real lam123, real lam4, TU &F)
Computes the complete Roe numerical flux for the 5-equation flow system.
DNDS_DEVICE_CALLABLE DNDS_FORCEINLINE auto U123(TU &&v)
Extracts the momentum components (indices 1,2,3) from a state vector as a 3x1 block.
Definition EulerP.hpp:60
Eigen::Vector< real, nVarsFlow > TU
Fixed-size 5-component conservative state vector (rho, rhoU, rhoV, rhoW, E).
Definition EulerP.hpp:33
DNDS_DEVICE_CALLABLE void RoeEigenValueFixer(real aL, real aR, real vnL, real vnR, real dLambda, real fixScale, real &lam0, real &lam123, real &lam4)
Applies entropy fix to Roe eigenvalues to prevent expansion shocks.
Eigen::Vector3d tPoint
Definition Geometric.hpp:9
DNDS_DEVICE_CALLABLE real RoeSpeedOfSoundSqr(real gamma, real HRoe, real vsqrRoe)
Roe-averaged speed of sound squared: a^2 = (gamma-1)(H - 0.5*v^2).
DNDS_DEVICE_CALLABLE void EntropyFix_HCorrHY(real aL, real aR, real vnL, real vnR, real dLambda, real fixScale, real &lam0, real &lam123, real &lam4)
H-correction + Harten-Yee entropy fix (scheme 8 in Euler module).
DNDS_DEVICE_CALLABLE void RoeAlphaDecomposition(real incU0, real incU123N, real incU4b, real veloRoeN, real HRoe, real asqrRoe, real aRoe, real gamma, real &alpha0, real &alpha1, real &alpha4)
Roe alpha-decomposition coefficients for the 1D wave structure.
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
Definition Defines.hpp:105
Device-callable view of physics parameters providing thermodynamic operations.
DNDS_DEVICE_CALLABLE real Pressure2Enthalpy(tU &&U, int nVars, real p) const
Computes specific total enthalpy from conservative state and pressure.
PhysicsParams params
Gas physical parameters (copied to device).
real gamma
only simple data here allowed
Eigen::Vector3d n(1.0, 0.0, 0.0)