Nektar++
RoeSolver.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: RoeSolver.h
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Roe Riemann solver.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef NEKTAR_SOLVERS_COMPRESSIBLEFLOWSOLVER_RIEMANNSOLVER_ROESOLVER
36 #define NEKTAR_SOLVERS_COMPRESSIBLEFLOWSOLVER_RIEMANNSOLVER_ROESOLVER
37 
39 
40 namespace Nektar
41 {
43 {
44 public:
47  {
48  return RiemannSolverSharedPtr(new RoeSolver(pSession));
49  }
50 
51  static std::string solverName;
52 
53  /// programmatic ctor
54  RoeSolver();
55 
56 protected:
58 
59  using ND = NekDouble;
60 
61  virtual void v_PointSolve(ND rhoL, ND rhouL, ND rhovL, ND rhowL, ND EL,
62  ND rhoR, ND rhouR, ND rhovR, ND rhowR, ND ER,
63  ND &rhof, ND &rhouf, ND &rhovf, ND &rhowf,
64  ND &Ef) override final;
65 
66  virtual void v_ArraySolve(
67  const Array<OneD, const Array<OneD, ND>> &Fwd,
68  const Array<OneD, const Array<OneD, ND>> &Bwd,
69  Array<OneD, Array<OneD, ND>> &flux) override final;
70 };
71 
72 template <class T, typename = typename std::enable_if<
73  std::is_floating_point<T>::value ||
75 inline void RoeKernel(T &rhoL, T &rhouL, T &rhovL, T &rhowL, T &EL, T &rhoR,
76  T &rhouR, T &rhovR, T &rhowR, T &ER, T &rhof, T &rhouf,
77  T &rhovf, T &rhowf, T &Ef, NekDouble gamma)
78 {
79  // Left and right velocities
80  T uL = rhouL / rhoL;
81  T vL = rhovL / rhoL;
82  T wL = rhowL / rhoL;
83  T uR = rhouR / rhoR;
84  T vR = rhovR / rhoR;
85  T wR = rhowR / rhoR;
86 
87  // Left and right pressures
88  T pL = (gamma - 1.0) * (EL - 0.5 * (rhouL * uL + rhovL * vL + rhowL * wL));
89  T pR = (gamma - 1.0) * (ER - 0.5 * (rhouR * uR + rhovR * vR + rhowR * wR));
90 
91  // Left and right enthalpy
92  T hL = (EL + pL) / rhoL;
93  T hR = (ER + pR) / rhoR;
94 
95  // Square root of rhoL and rhoR.
96  T srL = sqrt(rhoL);
97  T srR = sqrt(rhoR);
98  T srLR = srL + srR;
99 
100  // Velocity, enthalpy and sound speed Roe averages (equation 11.60).
101  T uRoe = (srL * uL + srR * uR) / srLR;
102  T vRoe = (srL * vL + srR * vR) / srLR;
103  T wRoe = (srL * wL + srR * wR) / srLR;
104  T hRoe = (srL * hL + srR * hR) / srLR;
105  T URoe = (uRoe * uRoe + vRoe * vRoe + wRoe * wRoe);
106  T cRoe = sqrt((gamma - 1.0) * (hRoe - 0.5 * URoe));
107 
108  // Compute eigenvectors (equation 11.59).
109  T k[5][5] = {{1., uRoe - cRoe, vRoe, wRoe, hRoe - uRoe * cRoe},
110  {1., uRoe, vRoe, wRoe, 0.5 * URoe},
111  {0., 0., 1., 0., vRoe},
112  {0., 0., 0., 1., wRoe},
113  {1., uRoe + cRoe, vRoe, wRoe, hRoe + uRoe * cRoe}};
114 
115  // Calculate jumps \Delta u_i (defined preceding equation 11.67).
116  T jump[5] = {rhoR - rhoL, rhouR - rhouL, rhovR - rhovL, rhowR - rhowL,
117  ER - EL};
118 
119  // Define \Delta u_5 (equation 11.70).
120  T jumpbar = jump[4] - (jump[2] - vRoe * jump[0]) * vRoe -
121  (jump[3] - wRoe * jump[0]) * wRoe;
122 
123  // Compute wave amplitudes (equations 11.68, 11.69).
124  T alpha[5];
125  alpha[1] = (gamma - 1.0) *
126  (jump[0] * (hRoe - uRoe * uRoe) + uRoe * jump[1] - jumpbar) /
127  (cRoe * cRoe);
128  alpha[0] =
129  (jump[0] * (uRoe + cRoe) - jump[1] - cRoe * alpha[1]) / (2.0 * cRoe);
130  alpha[4] = jump[0] - (alpha[0] + alpha[1]);
131  alpha[2] = jump[2] - vRoe * jump[0];
132  alpha[3] = jump[3] - wRoe * jump[0];
133 
134  // Compute average of left and right fluxes needed for equation 11.29.
135  rhof = 0.5 * (rhoL * uL + rhoR * uR);
136  rhouf = 0.5 * (pL + rhoL * uL * uL + pR + rhoR * uR * uR);
137  rhovf = 0.5 * (rhoL * uL * vL + rhoR * uR * vR);
138  rhowf = 0.5 * (rhoL * uL * wL + rhoR * uR * wR);
139  Ef = 0.5 * (uL * (EL + pL) + uR * (ER + pR));
140 
141  // Needed to get right overload resolution for std::abs
142  using std::abs;
143 
144  // Compute eigenvalues \lambda_i (equation 11.58).
145  T uRoeAbs = abs(uRoe);
146  T lambda[5] = {abs(uRoe - cRoe), uRoeAbs, uRoeAbs, uRoeAbs,
147  abs(uRoe + cRoe)};
148 
149  // Finally perform summation (11.29).
150  for (size_t i = 0; i < 5; ++i)
151  {
152  uRoeAbs = 0.5 * alpha[i] * lambda[i];
153 
154  rhof -= uRoeAbs * k[i][0];
155  rhouf -= uRoeAbs * k[i][1];
156  rhovf -= uRoeAbs * k[i][2];
157  rhowf -= uRoeAbs * k[i][3];
158  Ef -= uRoeAbs * k[i][4];
159  }
160 }
161 
162 } // namespace Nektar
163 
164 #endif
virtual void v_PointSolve(ND rhoL, ND rhouL, ND rhovL, ND rhowL, ND EL, ND rhoR, ND rhouR, ND rhovR, ND rhowR, ND ER, ND &rhof, ND &rhouf, ND &rhovf, ND &rhowf, ND &Ef) override final
Roe Riemann solver.
Definition: RoeSolver.cpp:83
RoeSolver()
programmatic ctor
Definition: RoeSolver.cpp:52
virtual void v_ArraySolve(const Array< OneD, const Array< OneD, ND >> &Fwd, const Array< OneD, const Array< OneD, ND >> &Bwd, Array< OneD, Array< OneD, ND >> &flux) override final
Definition: RoeSolver.cpp:95
static RiemannSolverSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession)
Definition: RoeSolver.h:45
static std::string solverName
Definition: RoeSolver.h:51
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< RiemannSolver > RiemannSolverSharedPtr
A shared pointer to an EquationSystem object.
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
void RoeKernel(T &rhoL, T &rhouL, T &rhovL, T &rhowL, T &EL, T &rhoR, T &rhouR, T &rhovR, T &rhowR, T &ER, T &rhof, T &rhouf, T &rhovf, T &rhowf, T &Ef, NekDouble gamma)
Definition: RoeSolver.h:75
double NekDouble
scalarT< T > abs(scalarT< T > in)
Definition: scalar.hpp:298
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:294