Nektar++
NavierStokesAdvection.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File NavierStokesAdvection.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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Evaluation of the Navier Stokes advective term
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 
38 namespace Nektar
39 {
42 
43  /**
44  * Constructor. Creates ...
45  *
46  * \param
47  * \param
48  */
49 
51  Advection()
52 
53  {
54 
55  }
56 
58  {
59  }
60 
61 
65  {
67  m_homogen_dealiasing = pSession->DefinesSolverInfo("dealiasing");
68 
69  pSession->MatchSolverInfo("SPECTRALHPDEALIASING","True",m_specHP_dealiasing,false);
70  if(m_specHP_dealiasing == false)
71  {
72  pSession->MatchSolverInfo("SPECTRALHPDEALIASING","On",m_specHP_dealiasing,false);
73  }
74  pSession->MatchSolverInfo("ModeType","SingleMode",m_SingleMode,false);
75  pSession->MatchSolverInfo("ModeType","HalfMode",m_HalfMode,false);
76 
77  Advection::v_InitObject(pSession, pFields);
78  }
79 
80 
82  const int nConvectiveFields,
84  const Array<OneD, Array<OneD, NekDouble> > &advVel,
85  const Array<OneD, Array<OneD, NekDouble> > &inarray,
86  Array<OneD, Array<OneD, NekDouble> > &outarray,
87  const NekDouble &time)
88  {
89  int nqtot = fields[0]->GetTotPoints();
90  ASSERTL1(nConvectiveFields == inarray.num_elements(),"Number of convective fields and Inarray are not compatible");
91 
92  Array<OneD, NekDouble > Deriv(nqtot*nConvectiveFields);
93 
94  for(int n = 0; n < nConvectiveFields; ++n)
95  {
96  // use dimension of Velocity vector to dictate dimension of operation
97  int ndim = advVel.num_elements();
98  Array<OneD, Array<OneD, NekDouble> > AdvVel (advVel.num_elements());
99  Array<OneD, NekDouble> Outarray;
100 
101 
102  int nPointsTot = fields[0]->GetNpoints();
103  Array<OneD, NekDouble> grad0,grad1,grad2,wkSp;
104 
105  NekDouble OneDptscale = 1.5; // factor to rescale 1d points in dealiasing
106 
108  {
109  // Get number of points to dealias a quadratic non-linearity
110  nPointsTot = fields[0]->Get1DScaledTotPoints(OneDptscale);
111  }
112 
113  grad0 = Array<OneD, NekDouble> (nPointsTot);
114 
115  // interpolate Advection velocity
116  int nadv = advVel.num_elements();
117  if(m_specHP_dealiasing) // interpolate advection field to higher space.
118  {
119  AdvVel[0] = Array<OneD, NekDouble> (nPointsTot*(nadv+1));
120  for(int i = 0; i < nadv; ++i)
121  {
122  if(i)
123  {
124  AdvVel[i] = AdvVel[i-1]+nPointsTot;
125  }
126  // interpolate infield to 3/2 dimension
127  fields[0]->PhysInterp1DScaled(OneDptscale,advVel[i],AdvVel[i]);
128  }
129 
130  Outarray = AdvVel[nadv-1] + nPointsTot;
131  }
132  else
133  {
134  for(int i = 0; i < nadv; ++i)
135  {
136  AdvVel[i] = advVel[i];
137  }
138 
139  Outarray = outarray[n];
140  }
141 
142  wkSp = Array<OneD, NekDouble> (nPointsTot);
143 
144 
145  // Evaluate V\cdot Grad(u)
146  switch(ndim)
147  {
148  case 1:
149  fields[0]->PhysDeriv(inarray[n],grad0);
150  Vmath::Vmul(nPointsTot,grad0,1,advVel[0],1,outarray[n],1);
151  break;
152  case 2:
153  {
154  grad1 = Array<OneD, NekDouble> (nPointsTot);
155  fields[0]->PhysDeriv(inarray[n],grad0,grad1);
156 
157  if(m_specHP_dealiasing) // interpolate gradient field
158  {
159  fields[0]->PhysInterp1DScaled(OneDptscale,grad0,wkSp);
160  Vmath::Vcopy(nPointsTot,wkSp,1,grad0,1);
161  fields[0]->PhysInterp1DScaled(OneDptscale,grad1,wkSp);
162  Vmath::Vcopy(nPointsTot,wkSp,1,grad1,1);
163  }
164 
165  Vmath::Vmul (nPointsTot,grad0,1,AdvVel[0],1,Outarray,1);
166  Vmath::Vvtvp(nPointsTot,grad1,1,AdvVel[1],1,Outarray,1,Outarray,1);
167 
168  if(m_specHP_dealiasing) // Galerkin project solution back to origianl space
169  {
170  fields[0]->PhysGalerkinProjection1DScaled(OneDptscale,Outarray,outarray[n]);
171  }
172 
173  }
174  break;
175  case 3:
176  grad1 = Array<OneD, NekDouble> (fields[0]->GetNpoints());
177  grad2 = Array<OneD, NekDouble> (fields[0]->GetNpoints());
178 
179  if(fields[0]->GetWaveSpace() == false && m_homogen_dealiasing == true )
180  {
181  ASSERTL0(m_specHP_dealiasing == false,"Spectral/hp element dealaising is not set up for this option");
182 
183  fields[0]->PhysDeriv(inarray[n],grad0,grad1,grad2);
184 
185  fields[0]->DealiasedProd(advVel[0],grad0,grad0,m_CoeffState);
186  fields[0]->DealiasedProd(advVel[1],grad1,grad1,m_CoeffState);
187  fields[0]->DealiasedProd(advVel[2],grad2,grad2,m_CoeffState);
188  Vmath::Vadd(nPointsTot,grad0,1,grad1,1,outarray[n],1);
189  Vmath::Vadd(nPointsTot,grad2,1,outarray[n],1,outarray[n],1);
190  }
191  else if(fields[0]->GetWaveSpace() == true && m_homogen_dealiasing == false)
192  {
193  // take d/dx, d/dy gradients in physical Fourier space
194  fields[0]->PhysDeriv(advVel[n],grad0,grad1);
195 
196  // Take d/dz derivative using wave space field
197  fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],inarray[n],
198  outarray[n]);
199  fields[0]->HomogeneousBwdTrans(outarray[n],grad2);
200 
201  if(m_specHP_dealiasing) //interpolate spectral/hp gradient field
202  {
203  fields[0]->PhysInterp1DScaled(OneDptscale,grad0,wkSp);
204  Vmath::Vmul(nPointsTot,wkSp,1,AdvVel[0],1,Outarray,1);
205  }
206  else
207  {
208  Vmath::Vmul(nPointsTot,grad0,1,AdvVel[0],1,Outarray,1);
209  }
210 
211  if(m_specHP_dealiasing) //interpolate spectral/hp gradient field
212  {
213  fields[0]->PhysInterp1DScaled(OneDptscale,grad1,wkSp);
214  Vmath::Vvtvp(nPointsTot,wkSp,1,AdvVel[1],1,Outarray,1,
215  Outarray,1);
216  }
217  else
218  {
219  Vmath::Vvtvp(nPointsTot,grad1,1,AdvVel[1],1,Outarray,1,
220  Outarray,1);
221  }
222 
223  if(m_specHP_dealiasing) //interpolate spectral/hp gradient field
224  {
225  fields[0]->PhysInterp1DScaled(OneDptscale,grad2,wkSp);
226  Vmath::Vvtvp(nPointsTot,wkSp,1,AdvVel[2],1,Outarray,1,Outarray,1);
227  fields[0]->PhysGalerkinProjection1DScaled(OneDptscale,Outarray,grad2);
228  fields[0]->HomogeneousFwdTrans(grad2,outarray[n]);
229  }
230  else
231  {
232  Vmath::Vvtvp(nPointsTot,grad2,1,AdvVel[2],1,Outarray,1,grad0,1);
233  fields[0]->HomogeneousFwdTrans(grad0,outarray[n]);
234  }
235  }
236  else if(fields[0]->GetWaveSpace() == false && m_homogen_dealiasing == false)
237  {
238 
239  fields[0]->PhysDeriv(inarray[n],grad0,grad1,grad2);
240 
241  if(m_specHP_dealiasing) //interpolate spectral/hp gradient field
242  {
243  fields[0]->PhysInterp1DScaled(OneDptscale,grad0,wkSp);
244  Vmath::Vmul(nPointsTot,wkSp,1,AdvVel[0],1,Outarray,1);
245  }
246  else
247  {
248  Vmath::Vmul(nPointsTot,grad0,1,AdvVel[0],1,Outarray,1);
249  }
250 
251 
252  if(m_specHP_dealiasing) //interpolate spectral/hp gradient field
253  {
254  fields[0]->PhysInterp1DScaled(OneDptscale,grad1,wkSp);
255  Vmath::Vvtvp(nPointsTot,wkSp,1,AdvVel[1],1,Outarray,1,
256  Outarray,1);
257  }
258  else
259  {
260  Vmath::Vvtvp(nPointsTot,grad1,1,AdvVel[1],1,Outarray,1,
261  Outarray,1);
262  }
263 
264  if(m_specHP_dealiasing) //interpolate spectral/hp gradient field
265  {
266  fields[0]->PhysInterp1DScaled(OneDptscale,grad2,wkSp);
267  Vmath::Vvtvp(nPointsTot,wkSp,1,AdvVel[2],1,Outarray,1,Outarray,1);
268  fields[0]->PhysGalerkinProjection1DScaled(OneDptscale,Outarray,outarray[n]);
269  }
270  else
271  {
272  Vmath::Vvtvp(nPointsTot,grad2,1,AdvVel[2],1,Outarray,1,outarray[n],1);
273  }
274  }
275  else if(fields[0]->GetWaveSpace() == true && m_homogen_dealiasing == true)
276  {
277  ASSERTL0(m_specHP_dealiasing == false,"Spectral/hp element dealaising is not set up for this option");
278 
279  fields[0]->PhysDeriv(inarray[n],grad0,grad1,grad2);
280 
281  fields[0]->HomogeneousBwdTrans(grad0, outarray[n]);
282  fields[0]->DealiasedProd(advVel[0], outarray[n], grad0,
283  m_CoeffState);
284 
285  fields[0]->HomogeneousBwdTrans(grad1,outarray[n]);
286  fields[0]->DealiasedProd(advVel[1], outarray[n], grad1,
287  m_CoeffState);
288 
289  fields[0]->HomogeneousBwdTrans(grad2,outarray[n]);
290  fields[0]->DealiasedProd(advVel[2], outarray[n], grad2,
291  m_CoeffState);
292 
293  Vmath::Vadd(nPointsTot, grad0, 1, grad1, 1, grad0, 1);
294  Vmath::Vadd(nPointsTot, grad0, 1, grad2, 1, grad0, 1);
295 
296  fields[0]->HomogeneousFwdTrans(grad0,outarray[n]);
297  }
298  else
299  {
300  ASSERTL0(false, "Advection term calculation not implented or "
301  "possible with the current problem set up");
302  }
303  break;
304  default:
305  ASSERTL0(false,"dimension unknown");
306  }
307 
308  Vmath::Neg(nqtot,outarray[n],1);
309  }
310 
311  }
312 
313 } //end of namespace
314 
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
Local coefficients.
static SolverUtils::AdvectionSharedPtr create(std::string)
Creates an instance of this class.
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)
Advects a vector field.
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:428
static std::string className
Name of class.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:50
AdvectionFactory & GetAdvectionFactory()
Gets the factory for initialising advection objects.
Definition: Advection.cpp:46
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:382
double NekDouble
MultiRegions::CoeffState m_CoeffState
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:86
virtual void v_InitObject(LibUtilities::SessionReaderSharedPtr pSession, Array< OneD, MultiRegions::ExpListSharedPtr > pFields)
Initialises the advection object.
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:191
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1038
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:285
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:169
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215