Nektar++
RoeSolverSIMD.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: RoeSolverSIMD.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 using simd types.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
37 
39 
40 namespace Nektar
41 {
42 std::string RoeSolverSIMD::solverName =
44  "RoeOpt", RoeSolverSIMD::create, "Roe Riemann solver opt");
45 
48  : CompressibleSolver(pSession)
49 {
50  m_requiresRotation = false;
51 }
52 
53 /// programmatic ctor
55 {
56  m_requiresRotation = false;
57 }
58 
60  const int nDim, const Array<OneD, const Array<OneD, NekDouble>> &fwd,
61  const Array<OneD, const Array<OneD, NekDouble>> &bwd,
63 {
64  boost::ignore_unused(nDim);
65 
66  static auto gamma = m_params["gamma"]();
67  static size_t nVars = fwd.size();
68  static size_t spaceDim = nVars - 2;
69 
70  // 3D case only so far
71  ASSERTL0(spaceDim == 3, "SIMD Roe implemented only for 3D case...");
72 
73  using namespace tinysimd;
74  using vec_t = simd<NekDouble>;
75  // using vec_t = typename tinysimd::abi::scalar<NekDouble>::type;
76 
77  // get limit of vectorizable chunk
78  size_t sizeScalar = fwd[0].size();
79  size_t sizeVec = (sizeScalar / vec_t::width) * vec_t::width;
80 
81  // get normal, vellocs
82  ASSERTL1(CheckVectors("N"), "N not defined.");
83  // ASSERTL1(CheckAuxVec("vecLocs"), "vecLocs not defined.");
85  // const Array<OneD, const Array<OneD, NekDouble> > vecLocs =
86  // m_auxVec["vecLocs"]();
87 
88  // const unsigned int vx = (int)vecLocs[0][0];
89  // const unsigned int vy = (int)vecLocs[0][1];
90  // const unsigned int vz = (int)vecLocs[0][2];
91 
92  // Generate matrices if they don't already exist.
93  if (m_rotMat.size() == 0)
94  {
95  GenerateRotationMatrices(normals);
96  }
97 
98  // SIMD loop
99  size_t i = 0;
100  for (; i < sizeVec; i += vec_t::width)
101  {
102  // load scalars
103  vec_t rhoL, rhoR, ER, EL;
104  rhoL.load(&(fwd[0][i]), is_not_aligned);
105  rhoR.load(&(bwd[0][i]), is_not_aligned);
106  ER.load(&(bwd[spaceDim + 1][i]), is_not_aligned);
107  EL.load(&(fwd[spaceDim + 1][i]), is_not_aligned);
108 
109  // load vectors left
110  vec_t tmpIn[3], tmpOut[3];
111  tmpIn[0].load(&(fwd[1][i]), is_not_aligned);
112  tmpIn[1].load(&(fwd[2][i]), is_not_aligned);
113  tmpIn[2].load(&(fwd[3][i]), is_not_aligned);
114 
115  // load rotation matrix
116  vec_t rotMat[9];
117  for (size_t j = 0; j < 9; ++j)
118  {
119  rotMat[j].load(&(m_rotMat[j][i]), is_not_aligned);
120  }
121 
122  // rotateTo kernel Fwd
123  rotateToNormalKernel(tmpIn, rotMat, tmpOut);
124 
125  vec_t rhouL = tmpOut[0];
126  vec_t rhovL = tmpOut[1];
127  vec_t rhowL = tmpOut[2];
128 
129  // load vectors right
130  tmpIn[0].load(&(bwd[1][i]), is_not_aligned);
131  tmpIn[1].load(&(bwd[2][i]), is_not_aligned);
132  tmpIn[2].load(&(bwd[3][i]), is_not_aligned);
133 
134  // rotateTo kernel Bwd
135  rotateToNormalKernel(tmpIn, rotMat, tmpOut);
136 
137  vec_t rhouR = tmpOut[0];
138  vec_t rhovR = tmpOut[1];
139  vec_t rhowR = tmpOut[2];
140 
141  // Roe kernel
142  vec_t rhof{}, Ef{};
143  RoeKernel(rhoL, rhouL, rhovL, rhowL, EL, rhoR, rhouR, rhovR, rhowR, ER,
144  rhof, tmpIn[0], tmpIn[1], tmpIn[2], Ef, gamma);
145 
146  // rotateFrom kernel
147  rotateFromNormalKernel(tmpIn, rotMat, tmpOut);
148 
149  // store scalar
150  rhof.store(&(flux[0][i]), is_not_aligned);
151  Ef.store(&(flux[nVars - 1][i]), is_not_aligned);
152 
153  // store vector 3D only
154  tmpOut[0].store(&(flux[1][i]), is_not_aligned);
155  tmpOut[1].store(&(flux[2][i]), is_not_aligned);
156  tmpOut[2].store(&(flux[3][i]), is_not_aligned);
157  }
158 
159  // spillover loop
160  for (; i < sizeScalar; ++i)
161  {
162  // load scalars
163  NekDouble rhoL = fwd[0][i];
164  NekDouble rhoR = bwd[0][i];
165  NekDouble EL = fwd[spaceDim + 1][i];
166  NekDouble ER = bwd[spaceDim + 1][i];
167 
168  // 3D case only
169  // load vectors left
170  NekDouble tmpIn[3], tmpOut[3];
171  tmpIn[0] = fwd[1][i];
172  tmpIn[1] = fwd[2][i];
173  tmpIn[2] = fwd[3][i];
174 
175  // load rotation matrix
176  NekDouble rotMat[9];
177  for (size_t j = 0; j < 9; ++j)
178  {
179  rotMat[j] = m_rotMat[j][i];
180  }
181 
182  // rotateTo kernel Fwd
183  rotateToNormalKernel(tmpIn, rotMat, tmpOut);
184 
185  NekDouble rhouL = tmpOut[0];
186  NekDouble rhovL = tmpOut[1];
187  NekDouble rhowL = tmpOut[2];
188 
189  // load vectors right
190  tmpIn[0] = bwd[1][i];
191  tmpIn[1] = bwd[2][i];
192  tmpIn[2] = bwd[3][i];
193 
194  // rotateTo kernel Bwd
195  rotateToNormalKernel(tmpIn, rotMat, tmpOut);
196 
197  NekDouble rhouR = tmpOut[0];
198  NekDouble rhovR = tmpOut[1];
199  NekDouble rhowR = tmpOut[2];
200 
201  // Roe kernel
202  NekDouble rhof{}, Ef{};
203  RoeKernel(rhoL, rhouL, rhovL, rhowL, EL, rhoR, rhouR, rhovR, rhowR, ER,
204  rhof, tmpIn[0], tmpIn[1], tmpIn[2], Ef, gamma);
205 
206  // rotateFrom kernel
207  rotateFromNormalKernel(tmpIn, rotMat, tmpOut);
208 
209  // store scalar
210  flux[0][i] = rhof;
211  flux[nVars - 1][i] = Ef;
212 
213  // store vector 3D only
214  flux[1][i] = tmpOut[0];
215  flux[2][i] = tmpOut[1];
216  flux[3][i] = tmpOut[2];
217  }
218 }
219 
220 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
virtual void v_Solve(const int nDim, const Array< OneD, const Array< OneD, ND >> &Fwd, const Array< OneD, const Array< OneD, ND >> &Bwd, Array< OneD, Array< OneD, ND >> &flux) override final
static RiemannSolverSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession)
Definition: RoeSolverSIMD.h:46
static std::string solverName
Definition: RoeSolverSIMD.h:52
RoeSolverSIMD()
programmatic ctor
bool m_requiresRotation
Indicates whether the Riemann solver requires a rotation to be applied to the velocity fields.
SOLVER_UTILS_EXPORT void GenerateRotationMatrices(const Array< OneD, const Array< OneD, NekDouble >> &normals)
Generate rotation matrices for 3D expansions.
Array< OneD, Array< OneD, NekDouble > > m_rotMat
Rotation matrices for each trace quadrature point.
std::map< std::string, RSVecFuncType > m_vectors
Map of vector function types.
SOLVER_UTILS_EXPORT bool CheckVectors(std::string name)
Determine whether a vector has been defined in m_vectors.
std::map< std::string, RSParamFuncType > m_params
Map of parameter function types.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
void rotateFromNormalKernel(T *in, T *rotMat, T *out)
void rotateToNormalKernel(T *in, T *rotMat, T *out)
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