Nektar++
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 // 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 adjoint advective term
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
36 
37 using namespace std;
38 
39 namespace Nektar
40 {
41 
42 string AdjointAdvection::className =
44  "Adjoint", AdjointAdvection::create);
45 
46 /**
47  *
48  */
49 AdjointAdvection::AdjointAdvection() : LinearisedAdvection()
50 {
51 }
52 
54 {
55 }
56 
58  const int nConvectiveFields,
60  const Array<OneD, Array<OneD, NekDouble>> &advVel,
61  const Array<OneD, Array<OneD, NekDouble>> &inarray,
62  Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble &time,
63  const Array<OneD, Array<OneD, NekDouble>> &pFwd,
64  const Array<OneD, Array<OneD, NekDouble>> &pBwd)
65 {
66  boost::ignore_unused(pFwd, pBwd);
67  ASSERTL1(nConvectiveFields == inarray.size(),
68  "Number of convective fields and Inarray are not compatible");
69 
70  int nPointsTot = fields[0]->GetNpoints();
71  int ndim = advVel.size();
72  int nBaseDerivs = (m_halfMode || m_singleMode) ? 2 : m_spacedim;
73  int nDerivs = (m_halfMode) ? 2 : m_spacedim;
74 
75  Array<OneD, Array<OneD, NekDouble>> velocity(ndim);
76  int nScalar = nConvectiveFields - ndim;
77  Array<OneD, Array<OneD, NekDouble>> scalar(nScalar);
78 
79  for (int i = 0; i < ndim; ++i)
80  {
81  if (fields[i]->GetWaveSpace() && !m_singleMode && !m_halfMode)
82  {
83  velocity[i] = Array<OneD, NekDouble>(nPointsTot, 0.0);
84  fields[i]->HomogeneousBwdTrans(nPointsTot, advVel[i], velocity[i]);
85  }
86  else
87  {
88  velocity[i] = advVel[i];
89  }
90  }
91  if (nScalar > 0) // add for temperature field
92  {
93  for (int jj = ndim; jj < nConvectiveFields; ++jj)
94  {
95  scalar[jj - ndim] = inarray[jj];
96  }
97  }
98 
100  for (int i = 0; i < nDerivs; ++i)
101  {
102  grad[i] = Array<OneD, NekDouble>(nPointsTot);
103  }
104 
105  // Evaluation of the base flow for periodic cases
106  if (m_slices > 1)
107  {
108  for (int i = 0; i < ndim; ++i)
109  {
110  UpdateBase(m_interp[i], m_baseflow[i], m_period - time);
111  UpdateGradBase(i, fields[i]);
112  }
113  }
114 
115  // Evaluate the linearised advection term
116  for (int i = 0; i < nConvectiveFields; ++i)
117  {
118  // Calculate gradient
119  switch (nDerivs)
120  {
121  case 1:
122  {
123  fields[i]->PhysDeriv(inarray[i], grad[0]);
124  }
125  break;
126  case 2:
127  {
128  fields[i]->PhysDeriv(inarray[i], grad[0], grad[1]);
129  }
130  break;
131  case 3:
132  {
133  fields[i]->PhysDeriv(inarray[i], grad[0], grad[1], grad[2]);
134  if (m_multipleModes)
135  {
136  // transform gradients into physical Fourier space
137  fields[i]->HomogeneousBwdTrans(nPointsTot, grad[0],
138  grad[0]);
139  fields[i]->HomogeneousBwdTrans(nPointsTot, grad[1],
140  grad[1]);
141  fields[i]->HomogeneousBwdTrans(nPointsTot, grad[2],
142  grad[2]);
143  }
144  }
145  break;
146  }
147 
148  // Momentum field advection
149  if (i < ndim)
150  {
151  // Calculate -U_j du'_i/dx_j
152  Vmath::Vmul(nPointsTot, grad[0], 1, m_baseflow[0], 1, outarray[i],
153  1);
154  for (int j = 1; j < nDerivs; ++j)
155  {
156  Vmath::Vvtvp(nPointsTot, grad[j], 1, m_baseflow[j], 1,
157  outarray[i], 1, outarray[i], 1);
158  }
159  Vmath::Neg(nPointsTot, outarray[i], 1);
160 
161  // Add u'_j U_j/ dx_i
162  int lim = (m_halfMode) ? 2 : ndim;
163  if ((m_halfMode || m_singleMode) && i == 2)
164  {
165  lim = 0;
166  }
167  for (int j = 0; j < lim; ++j)
168  {
169  Vmath::Vvtvp(nPointsTot, m_gradBase[j * nBaseDerivs + i], 1,
170  velocity[j], 1, outarray[i], 1, outarray[i], 1);
171  }
172  // Add Tprime*Grad_Tbase in u, v equations
173  if (nScalar > 0 && i < ndim)
174  {
175  for (int s = 0; s < nScalar; ++s)
176  {
177  Vmath::Vvtvp(nPointsTot,
178  m_gradBase[(ndim + s) * nBaseDerivs + i], 1,
179  scalar[s], 1, outarray[i], 1, outarray[i], 1);
180  }
181  }
182  }
183  // Scalar Field Advection
184  else
185  {
186  // Calculate -U_j du'_i/dx_j
187  Vmath::Vmul(nPointsTot, grad[0], 1, m_baseflow[0], 1, outarray[i],
188  1);
189  for (int j = 1; j < nDerivs; ++j)
190  {
191  Vmath::Vvtvp(nPointsTot, grad[j], 1, m_baseflow[j], 1,
192  outarray[i], 1, outarray[i], 1);
193  }
194  Vmath::Neg(nPointsTot, outarray[i], 1);
195  }
196 
197  if (m_multipleModes)
198  {
199  fields[i]->HomogeneousFwdTrans(nPointsTot, outarray[i],
200  outarray[i]);
201  }
202  Vmath::Neg(nPointsTot, outarray[i], 1);
203  }
204 }
205 
206 } // namespace Nektar
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
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) override
Advects a vector field.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
void UpdateBase(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const NekDouble time)
NekDouble m_period
period length
void UpdateGradBase(const int var, const MultiRegions::ExpListSharedPtr &field)
bool m_singleMode
flag to determine if use single mode or not
Array< OneD, Array< OneD, NekDouble > > m_baseflow
Storage for base flow.
Array< OneD, Array< OneD, NekDouble > > m_gradBase
bool m_multipleModes
flag to determine if use multiple mode or not
bool m_halfMode
flag to determine if use half mode or not
Array< OneD, Array< OneD, NekDouble > > m_interp
interpolation vector
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:2
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