Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AdjointAdvection.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File AdjointAdvection.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 adjoint advective term
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 
38 using namespace std;
39 
40 namespace Nektar
41 {
42 
43 string AdjointAdvection::className = SolverUtils
45  AdjointAdvection::create);
46 
47 /**
48  *
49  */
50 AdjointAdvection::AdjointAdvection():
52 {
53 }
54 
56 {
57 }
58 
60  const int nConvectiveFields,
62  const Array<OneD, Array<OneD, NekDouble> > &advVel,
63  const Array<OneD, Array<OneD, NekDouble> > &inarray,
64  Array<OneD, Array<OneD, NekDouble> > &outarray,
65  const NekDouble &time,
66  const Array<OneD, Array<OneD, NekDouble> > &pFwd,
67  const Array<OneD, Array<OneD, NekDouble> > &pBwd)
68 {
69  ASSERTL1(nConvectiveFields == inarray.num_elements(),
70  "Number of convective fields and Inarray are not compatible");
71 
72  int nPointsTot = fields[0]->GetNpoints();
73  int ndim = advVel.num_elements();
74  int nBaseDerivs = (m_halfMode || m_singleMode) ? 2 : m_spacedim;
75  int nDerivs = (m_halfMode) ? 2 : m_spacedim;
76 
77  Array<OneD, Array<OneD, NekDouble> > velocity(ndim);
78  for(int i = 0; i < ndim; ++i)
79  {
80  if(fields[i]->GetWaveSpace() && !m_singleMode && !m_halfMode)
81  {
82  velocity[i] = Array<OneD, NekDouble>(nPointsTot,0.0);
83  fields[i]->HomogeneousBwdTrans(advVel[i],velocity[i]);
84  }
85  else
86  {
87  velocity[i] = advVel[i];
88  }
89  }
90 
91  Array<OneD, Array<OneD, NekDouble> > grad (nDerivs);
92  for( int i = 0; i < nDerivs; ++i)
93  {
94  grad[i] = Array<OneD, NekDouble> (nPointsTot);
95  }
96 
97  // Evaluation of the base flow for periodic cases
98  if (m_slices > 1)
99  {
100  for (int i = 0; i < ndim; ++i)
101  {
103  time, m_period);
104  UpdateGradBase(i, fields[i]);
105  }
106  }
107 
108  //Evaluate the linearised advection term
109  for( int i = 0; i < ndim; ++i)
110  {
111  // Calculate gradient
112  switch(nDerivs)
113  {
114  case 1:
115  {
116  fields[i]->PhysDeriv(inarray[i], grad[0]);
117  }
118  break;
119  case 2:
120  {
121  fields[i]->PhysDeriv(inarray[i], grad[0], grad[1]);
122  }
123  break;
124  case 3:
125  {
126  fields[i]->PhysDeriv(inarray[i], grad[0], grad[1], grad[2]);
127  if(m_multipleModes)
128  {
129  // transform gradients into physical Fourier space
130  fields[i]->HomogeneousBwdTrans(grad[0], grad[0]);
131  fields[i]->HomogeneousBwdTrans(grad[1], grad[1]);
132  fields[i]->HomogeneousBwdTrans(grad[2], grad[2]);
133  }
134  }
135  break;
136  }
137 
138  // Calculate -U_j du'_i/dx_j
139  Vmath::Vmul(nPointsTot,grad[0], 1, m_baseflow[0], 1, outarray[i], 1);
140  for( int j = 1; j < nDerivs; ++j)
141  {
142  Vmath::Vvtvp(nPointsTot,grad[j], 1,
143  m_baseflow[j], 1,
144  outarray[i], 1,
145  outarray[i], 1);
146  }
147  Vmath::Neg(nPointsTot,outarray[i],1);
148 
149  // Add u'_j U_j/ dx_i
150  int lim = (m_halfMode) ? 2 : ndim;
151  if ( (m_halfMode || m_singleMode) && i==2)
152  {
153  lim = 0;
154  }
155  for( int j = 0; j < lim; ++j)
156  {
157  Vmath::Vvtvp(nPointsTot,m_gradBase[j*nBaseDerivs + i], 1,
158  velocity[j], 1,
159  outarray[i], 1,
160  outarray[i], 1);
161  }
162 
163  if(m_multipleModes)
164  {
165  fields[i]->HomogeneousFwdTrans(outarray[i],outarray[i]);
166  }
167  Vmath::Neg(nPointsTot,outarray[i],1);
168  }
169 }
170 
171 } //end of namespace
172 
bool m_singleMode
flag to determine if use single mode or not
Array< OneD, Array< OneD, NekDouble > > m_baseflow
Storage for base flow.
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:442
STL namespace.
int m_slices
number of slices
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.
Array< OneD, Array< OneD, NekDouble > > m_interp
interpolation vector
void UpdateBase(const NekDouble m_slices, const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const NekDouble m_time, const NekDouble m_period)
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:396
double NekDouble
NekDouble m_period
period length
bool m_multipleModes
flag to determine if use multiple mode or not
bool m_halfMode
flag to determine if use half mode or not
void UpdateGradBase(const int var, const MultiRegions::ExpListSharedPtr &field)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:228
Array< OneD, Array< OneD, NekDouble > > m_gradBase
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:183
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215