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",
44  SkewSymmetricAdvection::create);
45 
46 /**
47  *
48  */
49 SkewSymmetricAdvection::SkewSymmetricAdvection():
50  Advection()
51 
52 {
53 }
54 
55 
56 /**
57  *
58  */
60 {
61 }
62 
63 
64 /**
65  *
66  */
70 {
71  Advection::v_InitObject(pSession, pFields);
72 
73  m_homogen_dealiasing = pSession->DefinesSolverInfo("dealiasing");
74  pSession->MatchSolverInfo("ModeType","SingleMode",m_SingleMode,false);
75  pSession->MatchSolverInfo("ModeType","HalfMode",m_HalfMode,false);
76 }
77 
78 
79 /**
80  *
81  */
83  const int nConvectiveFields,
85  const Array<OneD, Array<OneD, NekDouble> > &advVel,
86  const Array<OneD, Array<OneD, NekDouble> > &inarray,
87  Array<OneD, Array<OneD, NekDouble> > &outarray,
88  const NekDouble &time,
89  const Array<OneD, Array<OneD, NekDouble> > &pFwd,
90  const Array<OneD, Array<OneD, NekDouble> > &pBwd)
91 {
92  // use dimension of Velocity vector to dictate dimension of operation
93  int ndim = advVel.size();
94  int nqtot = fields[0]->GetTotPoints();
95  ASSERTL1(nConvectiveFields == inarray.size(),"Number of convective fields and Inarray are not compatible");
96 
97  Array<OneD, Array<OneD, NekDouble> > velocity(ndim);
98  for(int i = 0; i < ndim; ++i)
99  {
100  if(fields[i]->GetWaveSpace() && !m_SingleMode && !m_HalfMode)
101  {
102  velocity[i] = Array<OneD, NekDouble>(nqtot,0.0);
103  fields[i]->HomogeneousBwdTrans(advVel[i],velocity[i]);
104  }
105  else
106  {
107  velocity[i] = advVel[i];
108  }
109  }
110 
111  for(int n = 0; n < nConvectiveFields; ++n)
112  {
113  // ToDo: here we should add a check that V has right dimension
114 
115  int nPointsTot = fields[0]->GetNpoints();
116  Array<OneD, NekDouble> gradV0,gradV1,gradV2, tmp, Up;
117 
118  gradV0 = Array<OneD, NekDouble> (nPointsTot);
119  tmp = Array<OneD, NekDouble> (nPointsTot);
120 
121  // Evaluate V\cdot Grad(u)
122  switch(ndim)
123  {
124  case 1:
125  fields[0]->PhysDeriv(inarray[n],gradV0);
126  Vmath::Vmul(nPointsTot,gradV0,1,velocity[0],1,outarray[n],1);
127  Vmath::Vmul(nPointsTot,inarray[n],1,velocity[0],1,gradV0,1);
128  fields[0]->PhysDeriv(gradV0,tmp);
129  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
130  Vmath::Smul(nPointsTot,0.5,outarray[n],1,outarray[n],1);
131  break;
132  case 2:
133  gradV1 = Array<OneD, NekDouble> (nPointsTot);
134  fields[0]->PhysDeriv(inarray[n],gradV0,gradV1);
135  Vmath::Vmul (nPointsTot,gradV0,1,velocity[0],1,outarray[n],1);
136  Vmath::Vvtvp(nPointsTot,gradV1,1,velocity[1],1,outarray[n],1,outarray[n],1);
137  Vmath::Vmul(nPointsTot,inarray[n],1,velocity[0],1,gradV0,1);
138  Vmath::Vmul(nPointsTot,inarray[n],1,velocity[1],1,gradV1,1);
139  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],gradV0,tmp);
140  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
141  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],gradV1,tmp);
142  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
143  Vmath::Smul(nPointsTot,0.5,outarray[n],1,outarray[n],1);
144  break;
145  case 3:
146  gradV1 = Array<OneD, NekDouble> (nPointsTot);
147  gradV2 = Array<OneD, NekDouble> (nPointsTot);
148 
149  fields[0]->PhysDeriv(inarray[n],gradV0,gradV1,gradV2);
150 
151  //outarray[n] = 1/2(u*du/dx + v*du/dy + w*du/dz + duu/dx + duv/dy + duw/dz)
152 
153  if(m_homogen_dealiasing == true && fields[0]->GetWaveSpace() == false)
154  {
155  fields[0]->DealiasedProd(velocity[0],gradV0,gradV0);
156  fields[0]->DealiasedProd(velocity[1],gradV1,gradV1);
157  fields[0]->DealiasedProd(velocity[2],gradV2,gradV2);
158  Vmath::Vadd(nPointsTot,gradV0,1,gradV1,1,outarray[n],1);
159  Vmath::Vadd(nPointsTot,gradV2,1,outarray[n],1,outarray[n],1);
160  fields[0]->DealiasedProd(inarray[n],velocity[0],gradV0);
161  fields[0]->DealiasedProd(inarray[n],velocity[1],gradV1);
162  fields[0]->DealiasedProd(inarray[n],velocity[2],gradV2);
163  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],gradV0,tmp);
164  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
165  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],gradV1,tmp);
166  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
167  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],gradV2,tmp);
168  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
169  Vmath::Smul(nPointsTot,0.5,outarray[n],1,outarray[n],1);
170  }
171  else if(fields[0]->GetWaveSpace() == true && m_homogen_dealiasing == false)
172  {
173  Up = Array<OneD, NekDouble> (nPointsTot);
174  //vector reused to avoid even more memory requirements
175  //names may be misleading
176  fields[0]->HomogeneousBwdTrans(gradV0,tmp);
177  Vmath::Vmul(nPointsTot,tmp,1,velocity[0],1,outarray[n],1); // + u*du/dx
178  fields[0]->HomogeneousBwdTrans(gradV1,tmp);
179  Vmath::Vvtvp(nPointsTot,tmp,1,velocity[1],1,outarray[n],1,outarray[n],1);// + v*du/dy
180  fields[0]->HomogeneousBwdTrans(gradV2,tmp);
181  Vmath::Vvtvp(nPointsTot,tmp,1,velocity[2],1,outarray[n],1,outarray[n],1);// + w*du/dz
182 
183  fields[0]->HomogeneousBwdTrans(inarray[n],Up);
184  Vmath::Vmul(nPointsTot,Up,1,velocity[0],1,gradV0,1);
185  Vmath::Vmul(nPointsTot,Up,1,velocity[1],1,gradV1,1);
186  Vmath::Vmul(nPointsTot,Up,1,velocity[2],1,gradV2,1);
187 
188  fields[0]->SetWaveSpace(false);
189  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],gradV0,tmp);//duu/dx
190  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
191  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],gradV1,tmp);//duv/dy
192  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
193  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],gradV2,tmp);//duw/dz
194  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
195  fields[0]->SetWaveSpace(true);
196 
197  Vmath::Smul(nPointsTot,0.5,outarray[n],1,tmp,1);
198  fields[0]->HomogeneousFwdTrans(tmp,outarray[n]);
199  }
200  else if(fields[0]->GetWaveSpace() == false && m_homogen_dealiasing == false)
201  {
202  Vmath::Vmul(nPointsTot,gradV0,1,velocity[0],1,outarray[n],1);
203  Vmath::Vvtvp(nPointsTot,gradV1,1,velocity[1],1,outarray[n],1,outarray[n],1);
204  Vmath::Vvtvp(nPointsTot,gradV2,1,velocity[2],1,outarray[n],1,outarray[n],1);
205  Vmath::Vmul(nPointsTot,inarray[n],1,velocity[0],1,gradV0,1);
206  Vmath::Vmul(nPointsTot,inarray[n],1,velocity[1],1,gradV1,1);
207  Vmath::Vmul(nPointsTot,inarray[n],1,velocity[2],1,gradV2,1);
208  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],gradV0,tmp);
209  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
210  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],gradV1,tmp);
211  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
212  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],gradV2,tmp);
213  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
214  Vmath::Smul(nPointsTot,0.5,outarray[n],1,outarray[n],1);
215  }
216  else
217  {
218  ASSERTL0(false, "Dealiasing is not allowed in combination "
219  "with the Skew-Symmetric advection form for "
220  "efficiency reasons.");
221  }
222  break;
223  default:
224  ASSERTL0(false,"dimension unknown");
225  }
226 
227  Vmath::Neg(nqtot,outarray[n],1);
228  }
229 
230 }
231 
232 } //end of namespace
233 
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:250
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
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:73
virtual SOLVER_UTILS_EXPORT void v_InitObject(LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields)
Initialises the advection object.
Definition: Advection.cpp:366
std::shared_ptr< SessionReader > SessionReaderSharedPtr
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:90
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:192
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:461
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:513
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:322
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:225