Nektar++
SkewSymmetricAdvection.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File SkewSymmetricAdvection.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: Evaluation of the Navier Stokes advective term
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
36 
37 using namespace std;
38 
39 namespace Nektar
40 {
41 string SkewSymmetricAdvection::className =
43  "SkewSymmetric", SkewSymmetricAdvection::create, "Skew Symmetric");
44 
45 /**
46  *
47  */
48 SkewSymmetricAdvection::SkewSymmetricAdvection() : Advection()
49 
50 {
51 }
52 
53 /**
54  *
55  */
57 {
58 }
59 
60 /**
61  *
62  */
66 {
67  Advection::v_InitObject(pSession, pFields);
68 
69  m_homogen_dealiasing = pSession->DefinesSolverInfo("dealiasing");
70  pSession->MatchSolverInfo("ModeType", "SingleMode", m_SingleMode, false);
71  pSession->MatchSolverInfo("ModeType", "HalfMode", m_HalfMode, false);
72 }
73 
74 /**
75  *
76  */
78  const int nConvectiveFields,
80  const Array<OneD, Array<OneD, NekDouble>> &advVel,
81  const Array<OneD, Array<OneD, NekDouble>> &inarray,
82  Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble &time,
83  const Array<OneD, Array<OneD, NekDouble>> &pFwd,
84  const Array<OneD, Array<OneD, NekDouble>> &pBwd)
85 {
86  // use dimension of Velocity vector to dictate dimension of operation
87  int ndim = advVel.size();
88  int nqtot = fields[0]->GetTotPoints();
89  ASSERTL1(nConvectiveFields == inarray.size(),
90  "Number of convective fields and Inarray are not compatible");
91 
92  Array<OneD, Array<OneD, NekDouble>> velocity(ndim);
93  for (int i = 0; i < ndim; ++i)
94  {
95  if (fields[i]->GetWaveSpace() && !m_SingleMode && !m_HalfMode)
96  {
97  velocity[i] = Array<OneD, NekDouble>(nqtot, 0.0);
98  fields[i]->HomogeneousBwdTrans(advVel[i], velocity[i]);
99  }
100  else
101  {
102  velocity[i] = advVel[i];
103  }
104  }
105 
106  for (int n = 0; n < nConvectiveFields; ++n)
107  {
108  // ToDo: here we should add a check that V has right dimension
109 
110  int nPointsTot = fields[0]->GetNpoints();
111  Array<OneD, NekDouble> gradV0, gradV1, gradV2, tmp, Up;
112 
113  gradV0 = Array<OneD, NekDouble>(nPointsTot);
114  tmp = Array<OneD, NekDouble>(nPointsTot);
115 
116  // Evaluate V\cdot Grad(u)
117  switch (ndim)
118  {
119  case 1:
120  fields[0]->PhysDeriv(inarray[n], gradV0);
121  Vmath::Vmul(nPointsTot, gradV0, 1, velocity[0], 1, outarray[n],
122  1);
123  Vmath::Vmul(nPointsTot, inarray[n], 1, velocity[0], 1, gradV0,
124  1);
125  fields[0]->PhysDeriv(gradV0, tmp);
126  Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n], 1);
127  Vmath::Smul(nPointsTot, 0.5, outarray[n], 1, outarray[n], 1);
128  break;
129  case 2:
130  gradV1 = Array<OneD, NekDouble>(nPointsTot);
131  fields[0]->PhysDeriv(inarray[n], gradV0, gradV1);
132  Vmath::Vmul(nPointsTot, gradV0, 1, velocity[0], 1, outarray[n],
133  1);
134  Vmath::Vvtvp(nPointsTot, gradV1, 1, velocity[1], 1, outarray[n],
135  1, outarray[n], 1);
136  Vmath::Vmul(nPointsTot, inarray[n], 1, velocity[0], 1, gradV0,
137  1);
138  Vmath::Vmul(nPointsTot, inarray[n], 1, velocity[1], 1, gradV1,
139  1);
140  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0], gradV0,
141  tmp);
142  Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n], 1);
143  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1], gradV1,
144  tmp);
145  Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n], 1);
146  Vmath::Smul(nPointsTot, 0.5, outarray[n], 1, outarray[n], 1);
147  break;
148  case 3:
149  gradV1 = Array<OneD, NekDouble>(nPointsTot);
150  gradV2 = Array<OneD, NekDouble>(nPointsTot);
151 
152  fields[0]->PhysDeriv(inarray[n], gradV0, gradV1, gradV2);
153 
154  // outarray[n] = 1/2(u*du/dx + v*du/dy + w*du/dz + duu/dx +
155  // duv/dy + duw/dz)
156 
157  if (m_homogen_dealiasing == true &&
158  fields[0]->GetWaveSpace() == false)
159  {
160  fields[0]->DealiasedProd(velocity[0], gradV0, gradV0);
161  fields[0]->DealiasedProd(velocity[1], gradV1, gradV1);
162  fields[0]->DealiasedProd(velocity[2], gradV2, gradV2);
163  Vmath::Vadd(nPointsTot, gradV0, 1, gradV1, 1, outarray[n],
164  1);
165  Vmath::Vadd(nPointsTot, gradV2, 1, outarray[n], 1,
166  outarray[n], 1);
167  fields[0]->DealiasedProd(inarray[n], velocity[0], gradV0);
168  fields[0]->DealiasedProd(inarray[n], velocity[1], gradV1);
169  fields[0]->DealiasedProd(inarray[n], velocity[2], gradV2);
170  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],
171  gradV0, tmp);
172  Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
173  1);
174  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],
175  gradV1, tmp);
176  Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
177  1);
178  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
179  gradV2, tmp);
180  Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
181  1);
182  Vmath::Smul(nPointsTot, 0.5, outarray[n], 1, outarray[n],
183  1);
184  }
185  else if (fields[0]->GetWaveSpace() == true &&
186  m_homogen_dealiasing == false)
187  {
188  Up = Array<OneD, NekDouble>(nPointsTot);
189  // vector reused to avoid even more memory requirements
190  // names may be misleading
191  fields[0]->HomogeneousBwdTrans(gradV0, tmp);
192  Vmath::Vmul(nPointsTot, tmp, 1, velocity[0], 1, outarray[n],
193  1); // + u*du/dx
194  fields[0]->HomogeneousBwdTrans(gradV1, tmp);
195  Vmath::Vvtvp(nPointsTot, tmp, 1, velocity[1], 1,
196  outarray[n], 1, outarray[n], 1); // + v*du/dy
197  fields[0]->HomogeneousBwdTrans(gradV2, tmp);
198  Vmath::Vvtvp(nPointsTot, tmp, 1, velocity[2], 1,
199  outarray[n], 1, outarray[n], 1); // + w*du/dz
200 
201  fields[0]->HomogeneousBwdTrans(inarray[n], Up);
202  Vmath::Vmul(nPointsTot, Up, 1, velocity[0], 1, gradV0, 1);
203  Vmath::Vmul(nPointsTot, Up, 1, velocity[1], 1, gradV1, 1);
204  Vmath::Vmul(nPointsTot, Up, 1, velocity[2], 1, gradV2, 1);
205 
206  fields[0]->SetWaveSpace(false);
207  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],
208  gradV0, tmp); // duu/dx
209  Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
210  1);
211  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],
212  gradV1, tmp); // duv/dy
213  Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
214  1);
215  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
216  gradV2, tmp); // duw/dz
217  Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
218  1);
219  fields[0]->SetWaveSpace(true);
220 
221  Vmath::Smul(nPointsTot, 0.5, outarray[n], 1, tmp, 1);
222  fields[0]->HomogeneousFwdTrans(tmp, outarray[n]);
223  }
224  else if (fields[0]->GetWaveSpace() == false &&
225  m_homogen_dealiasing == false)
226  {
227  Vmath::Vmul(nPointsTot, gradV0, 1, velocity[0], 1,
228  outarray[n], 1);
229  Vmath::Vvtvp(nPointsTot, gradV1, 1, velocity[1], 1,
230  outarray[n], 1, outarray[n], 1);
231  Vmath::Vvtvp(nPointsTot, gradV2, 1, velocity[2], 1,
232  outarray[n], 1, outarray[n], 1);
233  Vmath::Vmul(nPointsTot, inarray[n], 1, velocity[0], 1,
234  gradV0, 1);
235  Vmath::Vmul(nPointsTot, inarray[n], 1, velocity[1], 1,
236  gradV1, 1);
237  Vmath::Vmul(nPointsTot, inarray[n], 1, velocity[2], 1,
238  gradV2, 1);
239  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],
240  gradV0, tmp);
241  Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
242  1);
243  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],
244  gradV1, tmp);
245  Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
246  1);
247  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
248  gradV2, tmp);
249  Vmath::Vadd(nPointsTot, tmp, 1, outarray[n], 1, outarray[n],
250  1);
251  Vmath::Smul(nPointsTot, 0.5, outarray[n], 1, outarray[n],
252  1);
253  }
254  else
255  {
256  ASSERTL0(false,
257  "Dealiasing is not allowed in combination "
258  "with the Skew-Symmetric advection form for "
259  "efficiency reasons.");
260  }
261  break;
262  default:
263  ASSERTL0(false, "dimension unknown");
264  }
265 
266  Vmath::Neg(nqtot, outarray[n], 1);
267  }
268 }
269 
270 } // 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_Advect(const int nConvectiveFields, const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble >> &advVel, const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray, const NekDouble &time, const Array< OneD, Array< OneD, NekDouble >> &pFwd=NullNekDoubleArrayOfArray, const Array< OneD, Array< OneD, NekDouble >> &pBwd=NullNekDoubleArrayOfArray)
Advects a vector field.
virtual void v_InitObject(LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields)
Initialises the advection object.
An abstract base class encapsulating the concept of advection of a vector field.
Definition: Advection.h:72
virtual SOLVER_UTILS_EXPORT void v_InitObject(LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields)
Initialises the advection object.
Definition: Advection.cpp:353
std::shared_ptr< SessionReader > SessionReaderSharedPtr
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:89
AdvectionFactory & GetAdvectionFactory()
Gets the factory for initialising advection objects.
Definition: Advection.cpp:47
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition: Vmath.cpp:209
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:518
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.cpp:574
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.cpp:359
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.cpp:248