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  {
49  new RoeSolver(pSession));
50  }
51 
52  static std::string solverName;
53 
54  /// programmatic ctor
55  RoeSolver();
56 
57 protected:
59 
60  using ND = NekDouble;
61 
62  void v_PointSolve(
63  ND rhoL, ND rhouL, ND rhovL, ND rhowL, ND EL,
64  ND rhoR, ND rhouR, ND rhovR, ND rhowR, ND ER,
65  ND &rhof, ND &rhouf, ND &rhovf, ND &rhowf, ND &Ef) final;
66 
67  void v_ArraySolve(
68  const Array<OneD, const Array<OneD, ND> > &Fwd,
69  const Array<OneD, const Array<OneD, ND> > &Bwd,
70  Array<OneD, Array<OneD, ND> > &flux) final;
71 };
72 
73 template <class T, typename = typename std::enable_if
74  <
75  std::is_floating_point<T>::value ||
77  >::type
78 >
79 inline void RoeKernel(
80  T& rhoL, T& rhouL, T& rhovL, T& rhowL, T& EL,
81  T& rhoR, T& rhouR, T& rhovR, T& rhowR, T& ER,
82  T& rhof, T& rhouf, T& rhovf, T& rhowf, T& Ef,
83  NekDouble gamma)
84 {
85  // Left and right velocities
86  T uL = rhouL / rhoL;
87  T vL = rhovL / rhoL;
88  T wL = rhowL / rhoL;
89  T uR = rhouR / rhoR;
90  T vR = rhovR / rhoR;
91  T wR = rhowR / rhoR;
92 
93  // Left and right pressures
94  T pL = (gamma - 1.0) *
95  (EL - 0.5 * (rhouL * uL + rhovL * vL + rhowL * wL));
96  T pR = (gamma - 1.0) *
97  (ER - 0.5 * (rhouR * uR + rhovR * vR + rhowR * wR));
98 
99  // Left and right enthalpy
100  T hL = (EL + pL) / rhoL;
101  T hR = (ER + pR) / rhoR;
102 
103  // Square root of rhoL and rhoR.
104  T srL = sqrt(rhoL);
105  T srR = sqrt(rhoR);
106  T srLR = srL + srR;
107 
108  // Velocity, enthalpy and sound speed Roe averages (equation 11.60).
109  T uRoe = (srL * uL + srR * uR) / srLR;
110  T vRoe = (srL * vL + srR * vR) / srLR;
111  T wRoe = (srL * wL + srR * wR) / srLR;
112  T hRoe = (srL * hL + srR * hR) / srLR;
113  T URoe = (uRoe * uRoe + vRoe * vRoe + wRoe * wRoe);
114  T cRoe = sqrt((gamma - 1.0)*(hRoe - 0.5 * URoe));
115 
116  // Compute eigenvectors (equation 11.59).
117  T k[5][5] = {
118  {1., uRoe - cRoe, vRoe, wRoe, hRoe - uRoe * cRoe},
119  {1., uRoe, vRoe, wRoe, 0.5 * URoe},
120  {0., 0., 1., 0., vRoe},
121  {0., 0., 0., 1., wRoe},
122  {1., uRoe+cRoe, vRoe, wRoe, hRoe + uRoe*cRoe}
123  };
124 
125  // Calculate jumps \Delta u_i (defined preceding equation 11.67).
126  T jump[5] = {
127  rhoR - rhoL,
128  rhouR - rhouL,
129  rhovR - rhovL,
130  rhowR - rhowL,
131  ER - EL
132  };
133 
134  // Define \Delta u_5 (equation 11.70).
135  T jumpbar = jump[4] - (jump[2]-vRoe*jump[0])*vRoe -
136  (jump[3]-wRoe*jump[0])*wRoe;
137 
138  // Compute wave amplitudes (equations 11.68, 11.69).
139  T alpha[5];
140  alpha[1] = (gamma-1.0)*(jump[0]*(hRoe - uRoe*uRoe) + uRoe*jump[1] -
141  jumpbar)/(cRoe*cRoe);
142  alpha[0] = (jump[0]*(uRoe + cRoe) - jump[1] - cRoe*alpha[1])/(2.0*cRoe);
143  alpha[4] = jump[0] - (alpha[0] + alpha[1]);
144  alpha[2] = jump[2] - vRoe * jump[0];
145  alpha[3] = jump[3] - wRoe * jump[0];
146 
147  // Compute average of left and right fluxes needed for equation 11.29.
148  rhof = 0.5*(rhoL*uL + rhoR*uR);
149  rhouf = 0.5*(pL + rhoL*uL*uL + pR + rhoR*uR*uR);
150  rhovf = 0.5*(rhoL*uL*vL + rhoR*uR*vR);
151  rhowf = 0.5*(rhoL*uL*wL + rhoR*uR*wR);
152  Ef = 0.5*(uL*(EL + pL) + uR*(ER + pR));
153 
154  // Needed to get right overload resolution for std::abs
155  using std::abs;
156 
157  // Compute eigenvalues \lambda_i (equation 11.58).
158  T uRoeAbs = abs(uRoe);
159  T lambda[5] = {
160  abs(uRoe - cRoe),
161  uRoeAbs,
162  uRoeAbs,
163  uRoeAbs,
164  abs(uRoe + cRoe)
165  };
166 
167  // Finally perform summation (11.29).
168  for (size_t i = 0; i < 5; ++i)
169  {
170  uRoeAbs = 0.5*alpha[i]*lambda[i];
171 
172  rhof -= uRoeAbs*k[i][0];
173  rhouf -= uRoeAbs*k[i][1];
174  rhovf -= uRoeAbs*k[i][2];
175  rhowf -= uRoeAbs*k[i][3];
176  Ef -= uRoeAbs*k[i][4];
177  }
178 
179 }
180 
181 
182 } // namespace
183 
184 #endif
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) final
Roe Riemann solver.
Definition: RoeSolver.cpp:85
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) final
Definition: RoeSolver.cpp:100
RoeSolver()
programmatic ctor
Definition: RoeSolver.cpp:54
static RiemannSolverSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession)
Definition: RoeSolver.h:45
static std::string solverName
Definition: RoeSolver.h:52
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:1
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:79
double NekDouble
scalarT< T > abs(scalarT< T > in)
Definition: scalar.hpp:272
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:267