Nektar++
RoeSolver.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: RoeSolver.cpp
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 
36 
38 
39 namespace Nektar
40 {
41 std::string RoeSolver::solverName =
43  "Roe", RoeSolver::create, "Roe Riemann solver");
44 
46  : CompressibleSolver(pSession)
47 {
48  // m_pointSolve = false;
49 }
50 
51 /// programmatic ctor
53 {
54  // m_pointSolve = false;
55 }
56 
57 /**
58  * @brief Roe Riemann solver.
59  *
60  * Stated equations numbers are from:
61  *
62  * "Riemann Solvers and Numerical Methods for Fluid Dynamics: A Practical
63  * Introduction", E. F. Toro (3rd edition, 2009).
64  *
65  * We follow the algorithm prescribed following equation 11.70.
66  *
67  * @param rhoL Density left state.
68  * @param rhoR Density right state.
69  * @param rhouL x-momentum component left state.
70  * @param rhouR x-momentum component right state.
71  * @param rhovL y-momentum component left state.
72  * @param rhovR y-momentum component right state.
73  * @param rhowL z-momentum component left state.
74  * @param rhowR z-momentum component right state.
75  * @param EL Energy left state.
76  * @param ER Energy right state.
77  * @param rhof Computed Riemann flux for density.
78  * @param rhouf Computed Riemann flux for x-momentum component
79  * @param rhovf Computed Riemann flux for y-momentum component
80  * @param rhowf Computed Riemann flux for z-momentum component
81  * @param Ef Computed Riemann flux for energy.
82  */
83 void RoeSolver::v_PointSolve(double rhoL, double rhouL, double rhovL,
84  double rhowL, double EL, double rhoR, double rhouR,
85  double rhovR, double rhowR, double ER,
86  double &rhof, double &rhouf, double &rhovf,
87  double &rhowf, double &Ef)
88 {
89  static NekDouble gamma = m_params["gamma"]();
90 
91  RoeKernel(rhoL, rhouL, rhovL, rhowL, EL, rhoR, rhouR, rhovR, rhowR, ER,
92  rhof, rhouf, rhovf, rhowf, Ef, gamma);
93 }
94 
96  const Array<OneD, const Array<OneD, NekDouble>> &fwd,
97  const Array<OneD, const Array<OneD, NekDouble>> &bwd,
99 {
100  static auto gamma = m_params["gamma"]();
101  static size_t nVars = fwd.size();
102  static size_t spaceDim = nVars - 2;
103 
104  using namespace tinysimd;
105  using vec_t = simd<NekDouble>;
106 
107  // get limit of vectorizable chunk
108  size_t sizeScalar = fwd[0].size();
109  size_t sizeVec = (sizeScalar / vec_t::width) * vec_t::width;
110 
111  // SIMD loop
112  size_t i = 0;
113  for (; i < sizeVec; i += vec_t::width)
114  {
115  vec_t rhoL{}, rhouL{}, rhovL{}, rhowL{}, EL{};
116  vec_t rhoR{}, rhouR{}, rhovR{}, rhowR{}, ER{};
117 
118  // load
119  rhoL.load(&(fwd[0][i]), is_not_aligned);
120  rhouL.load(&(fwd[1][i]), is_not_aligned);
121  EL.load(&(fwd[spaceDim + 1][i]), is_not_aligned);
122  rhoR.load(&(bwd[0][i]), is_not_aligned);
123  rhouR.load(&(bwd[1][i]), is_not_aligned);
124  ER.load(&(bwd[spaceDim + 1][i]), is_not_aligned);
125 
126  if (spaceDim == 2)
127  {
128  rhovL.load(&(fwd[2][i]), is_not_aligned);
129  rhovR.load(&(bwd[2][i]), is_not_aligned);
130  }
131  else if (spaceDim == 3)
132  {
133  rhovL.load(&(fwd[2][i]), is_not_aligned);
134  rhowL.load(&(fwd[3][i]), is_not_aligned);
135  rhovR.load(&(bwd[2][i]), is_not_aligned);
136  rhowR.load(&(bwd[3][i]), is_not_aligned);
137  }
138 
139  vec_t rhof{}, rhouf{}, rhovf{}, rhowf{}, Ef{};
140 
141  RoeKernel(rhoL, rhouL, rhovL, rhowL, EL, rhoR, rhouR, rhovR, rhowR, ER,
142  rhof, rhouf, rhovf, rhowf, Ef, gamma);
143 
144  // store
145  rhof.store(&(flux[0][i]), is_not_aligned);
146  rhouf.store(&(flux[1][i]), is_not_aligned);
147  Ef.store(&(flux[nVars - 1][i]), is_not_aligned);
148  if (spaceDim == 2)
149  {
150  rhovf.store(&(flux[2][i]), is_not_aligned);
151  }
152  else if (spaceDim == 3)
153  {
154  rhovf.store(&(flux[2][i]), is_not_aligned);
155  rhowf.store(&(flux[3][i]), is_not_aligned);
156  }
157 
158  } // avx loop
159 
160  // spillover loop
161  for (; i < sizeScalar; ++i)
162  {
163  NekDouble rhoL{}, rhouL{}, rhovL{}, rhowL{}, EL{};
164  NekDouble rhoR{}, rhouR{}, rhovR{}, rhowR{}, ER{};
165 
166  // load
167  rhoL = fwd[0][i];
168  rhouL = fwd[1][i];
169  EL = fwd[spaceDim + 1][i];
170  rhoR = bwd[0][i];
171  rhouR = bwd[1][i];
172  ER = bwd[spaceDim + 1][i];
173 
174  if (spaceDim == 2)
175  {
176  rhovL = fwd[2][i];
177  rhovR = bwd[2][i];
178  }
179  else if (spaceDim == 3)
180  {
181  rhovL = fwd[2][i];
182  rhowL = fwd[3][i];
183  rhovR = bwd[2][i];
184  rhowR = bwd[3][i];
185  }
186 
187  NekDouble rhof{}, rhouf{}, rhovf{}, rhowf{}, Ef{};
188 
189  RoeKernel(rhoL, rhouL, rhovL, rhowL, EL, rhoR, rhouR, rhovR, rhowR, ER,
190  rhof, rhouf, rhovf, rhowf, Ef, gamma);
191 
192  // store
193  flux[0][i] = rhof;
194  flux[1][i] = rhouf;
195  flux[nVars - 1][i] = Ef;
196  if (spaceDim == 2)
197  {
198  flux[2][i] = rhovf;
199  }
200  else if (spaceDim == 3)
201  {
202  flux[2][i] = rhovf;
203  flux[3][i] = rhowf;
204  }
205 
206  } // loop
207 }
208 
209 } // namespace Nektar
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
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::map< std::string, RSParamFuncType > m_params
Map of parameter function types.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
RiemannSolverFactory & GetRiemannSolverFactory()
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
tinysimd::simd< NekDouble > vec_t
double NekDouble
static constexpr struct tinysimd::is_not_aligned_t is_not_aligned
typename abi< ScalarType, width >::type simd
Definition: tinysimd.hpp:80