Nektar++
MappingXofZ.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: MappingXofZ.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: Mapping of the type X = x + f(z)
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <boost/core/ignore_unused.hpp>
36 
38 #include <MultiRegions/ExpList.h>
39 
40 namespace Nektar
41 {
42 namespace GlobalMapping
43 {
44 
45 std::string MappingXofZ::className =
47  MappingXofZ::create, "X = x + f(z)");
48 
49 /**
50  * @class MappingXofZ
51  * This class implements a constant-Jacobian mapping defined by
52  * a transformation of the type
53  * \f[ \bar{x} = \bar{x}(x,z) = x + f(z) \f]
54  * \f[ \bar{y} = y \f]
55  * \f[ \bar{z} = z \f]
56  * where \f$(\bar{x},\bar{y},\bar{z})\f$ are the Cartesian (physical)
57  * coordinates and \f$(x,y,z)\f$ are the transformed (computational)
58  * coordinates.
59  */
63  : Mapping(pSession, pFields)
64 {
65 }
66 
67 
68 /**
69  *
70  */
73  const TiXmlElement *pMapping)
74 {
75  Mapping::v_InitObject(pFields, pMapping);
76 
77  m_constantJacobian = true;
78 
80  "Mapping X = x + f(z) needs 3 velocity components.");
81 
82 }
83 
85  const Array<OneD, Array<OneD, NekDouble> > &inarray,
86  Array<OneD, Array<OneD, NekDouble> > &outarray)
87 {
88  int physTot = m_fields[0]->GetTotPoints();
89  Array<OneD, NekDouble> wk(physTot, 0.0);
90 
91  // U1 = u1 + fz*u3
92  Vmath::Vmul(physTot, inarray[2], 1, m_GeometricInfo[0], 1, wk, 1);
93  Vmath::Vadd(physTot, wk, 1, inarray[0], 1, outarray[0],1);
94 
95  // U2 = u2
96  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
97 
98  // U3 = u3
99  Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
100 }
101 
103  const Array<OneD, Array<OneD, NekDouble> > &inarray,
104  Array<OneD, Array<OneD, NekDouble> > &outarray)
105 {
106  int physTot = m_fields[0]->GetTotPoints();
107  Array<OneD, NekDouble> wk(physTot, 0.0);
108 
109  // U1 = u1
110  Vmath::Vcopy(physTot, inarray[0], 1, outarray[0], 1);
111 
112  // U2 = u2
113  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
114 
115  // U3 = u3 - fz*u1
116  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, wk, 1);
117  Vmath::Vsub(physTot, inarray[2], 1, wk, 1, outarray[2], 1);
118 }
119 
121  const Array<OneD, Array<OneD, NekDouble> > &inarray,
122  Array<OneD, Array<OneD, NekDouble> > &outarray)
123 {
124  int physTot = m_fields[0]->GetTotPoints();
125  Array<OneD, NekDouble> wk(physTot, 0.0);
126 
127  // U1 = u1 - fz * u3
128  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, wk, 1);
129  Vmath::Vsub(physTot, inarray[0], 1, wk, 1, outarray[0], 1);
130 
131  // U2 = u2
132  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
133 
134  // U3 = u3
135  Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
136 }
137 
139  const Array<OneD, Array<OneD, NekDouble> > &inarray,
140  Array<OneD, Array<OneD, NekDouble> > &outarray)
141 {
142  int physTot = m_fields[0]->GetTotPoints();
143 
144  // U1 = u1
145  Vmath::Vcopy(physTot, inarray[0], 1, outarray[0], 1);
146 
147  // U2 = u2
148  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
149 
150  // U3 = u3 + fz*u1
151  Vmath::Vmul(physTot, m_GeometricInfo[0], 1,
152  inarray[0], 1, outarray[2], 1);
153  Vmath::Vadd(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
154 }
155 
157  Array<OneD, NekDouble> &outarray)
158 {
159  int physTot = m_fields[0]->GetTotPoints();
160  Vmath::Fill(physTot, 1.0, outarray, 1);
161 }
162 
164  const Array<OneD, Array<OneD, NekDouble> > &inarray,
165  Array<OneD, NekDouble> &outarray)
166 {
167  boost::ignore_unused(inarray);
168 
169  int physTot = m_fields[0]->GetTotPoints();
170 
171  Vmath::Zero(physTot, outarray, 1);
172 }
173 
175  Array<OneD, Array<OneD, NekDouble> > &outarray)
176 {
177  int physTot = m_fields[0]->GetTotPoints();
178  int nvel = m_nConvectiveFields;
179 
180  for (int i=0; i<nvel*nvel; i++)
181  {
182  outarray[i] = Array<OneD, NekDouble> (physTot, 0.0);
183  }
184  // Fill diagonal with 1.0
185  for (int i=0; i<nvel; i++)
186  {
187  Vmath::Sadd(physTot, 1.0, outarray[i+nvel*i], 1,
188  outarray[i+nvel*i], 1);
189  }
190 
191  // G_{13} and G_{31} = fz
192  Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[0*nvel+2], 1);
193  Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[2*nvel+0], 1);
194 
195  // G^{33} = (1+fz^2)
196  Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[2*nvel+2], 1,
197  outarray[2*nvel+2], 1);
198 }
199 
201  Array<OneD, Array<OneD, NekDouble> > &outarray)
202 {
203  int physTot = m_fields[0]->GetTotPoints();
204  int nvel = m_nConvectiveFields;
205  Array<OneD, NekDouble> wk(physTot, 0.0);
206 
207  for (int i=0; i<nvel*nvel; i++)
208  {
209  outarray[i] = Array<OneD, NekDouble> (physTot, 0.0);
210  }
211  // Fill diagonal with 1.0
212  for (int i=0; i<nvel; i++)
213  {
214  Vmath::Sadd(physTot, 1.0, outarray[i+nvel*i], 1,
215  outarray[i+nvel*i], 1);
216  }
217 
218  // G^{13} and G^{31} = -fz
219  Vmath::Vcopy(physTot, m_GeometricInfo[0],1,wk,1); // fz
220  Vmath::Neg(physTot, wk, 1);
221  Vmath::Vcopy(physTot, wk, 1, outarray[0*nvel+2], 1);
222  Vmath::Vcopy(physTot, wk, 1, outarray[2*nvel+0], 1);
223 
224  // G^{11} = (1+fz^2)
225  Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[0*nvel+0], 1,
226  outarray[0*nvel+0], 1);
227 }
228 
230  const Array<OneD, Array<OneD, NekDouble> > &inarray,
231  Array<OneD, Array<OneD, NekDouble> > &outarray)
232 {
233  int physTot = m_fields[0]->GetTotPoints();
234  Array<OneD, NekDouble> wk(physTot, 0.0);
235 
236  // out[0] = in[0] + in[2] * fz
237  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1,
238  outarray[0], 1); //in[2]*fz
239  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1,
240  outarray[2], 1); //in[0]*fz
241 
242  Vmath::Vadd(physTot, outarray[0], 1, inarray[0], 1,
243  outarray[0], 1);
244 
245  // out[1] = in[1]
246  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
247 
248  // out[2] = fz*in[0] + (1+fz^2)*in[2]
249  Vmath::Sadd(physTot, 1.0, m_GeometricInfo[2], 1, wk, 1); // 1+fz^2
250  Vmath::Vmul(physTot, wk, 1, inarray[2],1, wk, 1); // (1+fz^2)*in[2]
251  Vmath::Vadd(physTot, wk, 1, outarray[2],1, outarray[2], 1);
252 }
253 
255  const Array<OneD, Array<OneD, NekDouble> > &inarray,
256  Array<OneD, Array<OneD, NekDouble> > &outarray)
257 {
258  int physTot = m_fields[0]->GetTotPoints();
259  Array<OneD, NekDouble> wk(physTot, 0.0);
260 
261  // out[2] = in[2] - in[0] * fz
262  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1,
263  outarray[0], 1); // in[2]*fz
264  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1,
265  outarray[2], 1); //in[0]*fz
266  Vmath::Vsub(physTot, inarray[2], 1, outarray[2], 1,
267  outarray[2], 1);
268 
269  // out[1] = in[1]]
270  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
271 
272  // out[0] = in[0]*(1+fz^2)- in[2] * fz
273  Vmath::Sadd(physTot, 1.0, m_GeometricInfo[2], 1, wk, 1); // 1+fz^2
274  Vmath::Vmul(physTot, wk, 1, inarray[0],1, wk, 1); // in[0]*(1+fz^2)
275  Vmath::Vsub(physTot, wk, 1, outarray[0], 1, outarray[0], 1);
276 }
277 
279  const Array<OneD, Array<OneD, NekDouble> > &inarray,
280  Array<OneD, Array<OneD, NekDouble> > &outarray)
281 {
282  int physTot = m_fields[0]->GetTotPoints();
283  int nvel = m_nConvectiveFields;
284 
285  for (int i = 0; i< nvel; i++)
286  {
287  for (int j = 0; j< nvel; j++)
288  {
289  outarray[i*nvel+j] = Array<OneD, NekDouble>(physTot,0.0);
290  }
291  }
292 
293  // Calculate non-zero terms
294 
295  // outarray(0,2) = U3 * fzz
296  Vmath::Vmul(physTot,m_GeometricInfo[1],1,inarray[2],1,
297  outarray[0*nvel+2],1); // U1 * fzz
298 
299 }
300 
302  const Array<OneD, Array<OneD, NekDouble> > &inarray,
303  Array<OneD, Array<OneD, NekDouble> > &outarray)
304 {
305  int physTot = m_fields[0]->GetTotPoints();
306  int nvel = m_nConvectiveFields;
307 
308  for (int i = 0; i< nvel; i++)
309  {
310  for (int j = 0; j< nvel; j++)
311  {
312  outarray[i*nvel+j] = Array<OneD, NekDouble>(physTot,0.0);
313  }
314  }
315 
316  // Calculate non-zero terms
317 
318  // outarray(2,2) = U1 * fzz
319  Vmath::Vmul(physTot,m_GeometricInfo[1],1,inarray[0],1,
320  outarray[2*nvel+2],1); // U1 * fzz
321 }
322 
324 {
325  int phystot = m_fields[0]->GetTotPoints();
326  // Allocation of geometry memory
328  for (int i = 0; i < m_GeometricInfo.num_elements(); i++)
329  {
330  m_GeometricInfo[i] = Array<OneD, NekDouble>(phystot, 0.0);
331  }
332 
333  bool waveSpace = m_fields[0]->GetWaveSpace();
334  m_fields[0]->SetWaveSpace(false);
335  // Calculate derivatives of transformation
336  m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
337  m_coords[0],m_GeometricInfo[0]);
338  m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
340  // m_GeometricInfo[2] = fz^2
341  Vmath::Vmul(phystot,m_GeometricInfo[0],1,
342  m_GeometricInfo[0],1,m_GeometricInfo[2],1);
343 
344  m_fields[0]->SetWaveSpace(waveSpace);
345 }
346 
347 }
348 }
virtual GLOBAL_MAPPING_EXPORT void v_CovarFromCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
static GLOBAL_MAPPING_EXPORT MappingSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping)
Creates an instance of this class.
Definition: MappingXofZ.h:59
Array< OneD, Array< OneD, NekDouble > > m_GeometricInfo
Array with metric terms of the mapping.
Definition: Mapping.h:414
Array< OneD, Array< OneD, NekDouble > > m_coords
Array with the Cartesian coordinates.
Definition: Mapping.h:410
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
MappingFactory & GetMappingFactory()
Declaration of the mapping factory singleton.
Definition: Mapping.cpp:52
virtual GLOBAL_MAPPING_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping)
Definition: MappingXofZ.cpp:71
virtual GLOBAL_MAPPING_EXPORT void v_DotGradJacobian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, NekDouble > &outarray)
virtual GLOBAL_MAPPING_EXPORT void v_CovarToCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:45
static std::string className
Name of the class.
Definition: MappingXofZ.h:72
int m_nConvectiveFields
Number of velocity components.
Definition: Mapping.h:416
virtual GLOBAL_MAPPING_EXPORT void v_GetInvMetricTensor(Array< OneD, Array< OneD, NekDouble > > &outarray)
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Definition: Mapping.h:408
virtual GLOBAL_MAPPING_EXPORT void v_RaiseIndex(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
MappingXofZ(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
Definition: MappingXofZ.cpp:60
virtual GLOBAL_MAPPING_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping)
Definition: Mapping.cpp:100
bool m_constantJacobian
Flag defining if the Jacobian is constant.
Definition: Mapping.h:426
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:399
virtual GLOBAL_MAPPING_EXPORT void v_LowerIndex(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha + x.
Definition: Vmath.cpp:318
Base class for mapping to be applied to the coordinate system.
Definition: Mapping.h:68
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition: Vmath.cpp:346
virtual GLOBAL_MAPPING_EXPORT void v_GetJacobian(Array< OneD, NekDouble > &outarray)
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:88
virtual GLOBAL_MAPPING_EXPORT void v_ContravarFromCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
virtual GLOBAL_MAPPING_EXPORT void v_ContravarToCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
Definition: MappingXofZ.cpp:84
virtual GLOBAL_MAPPING_EXPORT void v_ApplyChristoffelCovar(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
virtual GLOBAL_MAPPING_EXPORT void v_GetMetricTensor(Array< OneD, Array< OneD, NekDouble > > &outarray)
virtual GLOBAL_MAPPING_EXPORT void v_ApplyChristoffelContravar(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
virtual GLOBAL_MAPPING_EXPORT void v_UpdateGeomInfo()
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:376
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
std::shared_ptr< SessionReader > SessionReaderSharedPtr
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:302
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:186