Nektar++
AlternateSkewAdvection.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File AlternateSkewAdvection.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 
42 string AlternateSkewAdvection::className =
44  "AlternateSkew", AlternateSkewAdvection::create);
45 
46 /**
47  * Constructor. Creates ...
48  *
49  * \param
50  * \param
51  */
52 AlternateSkewAdvection::AlternateSkewAdvection()
53  : Advection()
54 {
55 }
56 
58 {
59 }
60 
64 {
65  pSession->MatchSolverInfo("ModeType","SingleMode",m_SingleMode,false);
66  pSession->MatchSolverInfo("ModeType","HalfMode",m_HalfMode,false);
67 }
68 
70  const int nConvectiveFields,
72  const Array<OneD, Array<OneD, NekDouble> > &advVel,
73  const Array<OneD, Array<OneD, NekDouble> > &inarray,
74  Array<OneD, Array<OneD, NekDouble> > &outarray,
75  const NekDouble &time,
76  const Array<OneD, Array<OneD, NekDouble> > &pFwd,
77  const Array<OneD, Array<OneD, NekDouble> > &pBwd)
78 {
79  // use dimension of Velocity vector to dictate dimension of operation
80  int ndim = advVel.size();
81  int nPointsTot = fields[0]->GetNpoints();
82  Array<OneD, Array<OneD, NekDouble> > velocity(ndim);
83  for(int i = 0; i < ndim; ++i)
84  {
85  if(fields[i]->GetWaveSpace() && !m_SingleMode && !m_HalfMode)
86  {
87  velocity[i] = Array<OneD, NekDouble>(nPointsTot,0.0);
88  fields[i]->HomogeneousBwdTrans(advVel[i],velocity[i]);
89  }
90  else
91  {
92  velocity[i] = advVel[i];
93  }
94  }
95  for(int n = 0; n < nConvectiveFields; ++n)
96  {
97  // ToDo: here we should add a check that V has right dimension
98  Array<OneD, NekDouble> gradV0,gradV1,gradV2, tmp, Up;
99 
100  gradV0 = Array<OneD, NekDouble> (nPointsTot);
101  tmp = Array<OneD, NekDouble> (nPointsTot);
102 
103  // Evaluate V\cdot Grad(u)
104  switch(ndim)
105  {
106  case 1:
107  if(m_advectioncalls % 2 == 0)
108  {
109  fields[0]->PhysDeriv(inarray[n],gradV0);
110  Vmath::Vmul(nPointsTot,gradV0,1,velocity[0],1,outarray[n],1);
111  }
112  else
113  {
114  Vmath::Vmul(nPointsTot,inarray[n],1,velocity[0],1,gradV0,1);
115  fields[0]->PhysDeriv(gradV0,outarray[n]);
116  }
117  Vmath::Smul(nPointsTot,0.5,outarray[n],1,outarray[n],1); //must be mult by 0.5????
118  break;
119  case 2:
120  gradV1 = Array<OneD, NekDouble> (nPointsTot);
121  if(m_advectioncalls % 2 == 0)
122  {
123  fields[0]->PhysDeriv(inarray[n],gradV0,gradV1);
124  Vmath::Vmul (nPointsTot,gradV0,1,velocity[0],1,outarray[n],1);
125  Vmath::Vvtvp(nPointsTot,gradV1,1,velocity[1],1,outarray[n],1,outarray[n],1);
126  }
127  else
128  {
129  Vmath::Vmul(nPointsTot,inarray[n],1,velocity[0],1,gradV0,1);
130  Vmath::Vmul(nPointsTot,inarray[n],1,velocity[1],1,gradV1,1);
131  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],gradV0,outarray[n]);
132  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],gradV1,tmp);
133  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
134  }
135  Vmath::Smul(nPointsTot,1.0,outarray[n],1,outarray[n],1); //must be mult by 0.5????
136  break;
137  case 3:
138  gradV1 = Array<OneD, NekDouble> (nPointsTot);
139  gradV2 = Array<OneD, NekDouble> (nPointsTot);
140 
141  //outarray[n] = 1/2(u*du/dx + v*du/dy + w*du/dz + duu/dx + duv/dy + duw/dz)
142 
143  if(fields[0]->GetWaveSpace() == true)
144  {
145  if(m_advectioncalls % 2 == 0)
146  {
147  //vector reused to avoid even more memory requirements
148  //names may be misleading
149  fields[0]->PhysDeriv(inarray[n],gradV0,gradV1,gradV2);
150  fields[0]->HomogeneousBwdTrans(gradV0,tmp);
151  Vmath::Vmul(nPointsTot,tmp,1,velocity[0],1,outarray[n],1); // + u*du/dx
152  fields[0]->HomogeneousBwdTrans(gradV1,tmp);
153  Vmath::Vvtvp(nPointsTot,tmp,1,velocity[1],1,outarray[n],1,outarray[n],1);// + v*du/dy
154  fields[0]->HomogeneousBwdTrans(gradV2,tmp);
155  Vmath::Vvtvp(nPointsTot,tmp,1,velocity[2],1,outarray[n],1,outarray[n],1);// + w*du/dz
156  }
157  else
158  {
159  Up = Array<OneD, NekDouble> (nPointsTot);
160  fields[0]->HomogeneousBwdTrans(inarray[n],Up);
161  Vmath::Vmul(nPointsTot,Up,1,velocity[0],1,gradV0,1);
162  Vmath::Vmul(nPointsTot,Up,1,velocity[1],1,gradV1,1);
163  Vmath::Vmul(nPointsTot,Up,1,velocity[2],1,gradV2,1);
164 
165  fields[0]->SetWaveSpace(false);
166  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],gradV0,outarray[n]);//duu/dx
167  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],gradV1,tmp);//duv/dy
168  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
169  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],gradV2,tmp);//duw/dz
170  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
171  fields[0]->SetWaveSpace(true);
172  }
173 
174  Vmath::Smul(nPointsTot,1.0,outarray[n],1,tmp,1); //must be mult by 0.5????
175  fields[0]->HomogeneousFwdTrans(tmp,outarray[n]);
176  }
177  else
178  {
179  if(m_advectioncalls % 2 == 0)
180  {
181  fields[0]->PhysDeriv(inarray[n],gradV0,gradV1,gradV2);
182  Vmath::Vmul(nPointsTot,gradV0,1,velocity[0],1,outarray[n],1);
183  Vmath::Vvtvp(nPointsTot,gradV1,1,velocity[1],1,outarray[n],1,outarray[n],1);
184  Vmath::Vvtvp(nPointsTot,gradV2,1,velocity[2],1,outarray[n],1,outarray[n],1);
185  }
186  else
187  {
188  Vmath::Vmul(nPointsTot,inarray[n],1,velocity[0],1,gradV0,1);
189  Vmath::Vmul(nPointsTot,inarray[n],1,velocity[1],1,gradV1,1);
190  Vmath::Vmul(nPointsTot,inarray[n],1,velocity[2],1,gradV2,1);
191  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0],gradV0,outarray[n]);
192  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[1],gradV1,tmp);
193  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
194  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],gradV2,tmp);
195  Vmath::Vadd(nPointsTot,tmp,1,outarray[n],1,outarray[n],1);
196  }
197  Vmath::Smul(nPointsTot,1.0,outarray[n],1,outarray[n],1); //must be mult by 0.5????
198  }
199  break;
200  default:
201  ASSERTL0(false,"dimension unknown");
202  }
203  }
204 }
205 
206 } //end of namespace
207 
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
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.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
An abstract base class encapsulating the concept of advection of a vector field.
Definition: Advection.h:73
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 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