Nektar++
MappingXofXZ.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: MappingXofXZ.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(x,z)
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
36 #include <MultiRegions/ExpList.h>
37 
38 namespace Nektar
39 {
40 namespace GlobalMapping
41 {
42 
43 std::string MappingXofXZ::className =
45  "X = X(x,z)");
46 
47 /**
48  * @class MappingXofXZ
49  * This class implements a mapping defined by a transformation of the type
50  * \f[ \bar{x} = \bar{x}(x,z) \f]
51  * \f[ \bar{y} = y \f]
52  * \f[ \bar{z} = z \f]
53  * where \f$(\bar{x},\bar{y},\bar{z})\f$ are the Cartesian (physical)
54  * coordinates and \f$(x,y,z)\f$ are the transformed (computational)
55  * coordinates.
56  */
60  : Mapping(pSession, pFields)
61 {
62 }
63 
64 /**
65  *
66  */
69  const TiXmlElement *pMapping)
70 {
71  Mapping::v_InitObject(pFields, pMapping);
72 
73  m_constantJacobian = false;
74 
76  "Mapping X = X(x,z) needs 3 velocity components.");
77 }
78 
80  const Array<OneD, Array<OneD, NekDouble>> &inarray,
81  Array<OneD, Array<OneD, NekDouble>> &outarray)
82 {
83  int physTot = m_fields[0]->GetTotPoints();
84 
85  // U1 = fx*u1 + fz*u3
86  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, outarray[0], 1);
87  Vmath::Vvtvp(physTot, m_GeometricInfo[1], 1, inarray[2], 1, outarray[0], 1,
88  outarray[0], 1);
89 
90  // U2 = u2
91  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
92 
93  // U3 = u3
94  Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
95 }
96 
98  const Array<OneD, Array<OneD, NekDouble>> &inarray,
99  Array<OneD, Array<OneD, NekDouble>> &outarray)
100 {
101  int physTot = m_fields[0]->GetTotPoints();
102  Array<OneD, NekDouble> wk(physTot, 0.0);
103 
104  // U1 = u1/fx
105  Vmath::Vdiv(physTot, inarray[0], 1, m_GeometricInfo[0], 1, outarray[0], 1);
106 
107  // U2 = u2
108  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
109 
110  // U3 = u3 - fz/fx*u1
111  Vmath::Vdiv(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[0], 1, wk, 1);
112  Vmath::Vmul(physTot, wk, 1, inarray[0], 1, wk, 1);
113  Vmath::Vsub(physTot, inarray[2], 1, wk, 1, outarray[2], 1);
114 }
115 
117  const Array<OneD, Array<OneD, NekDouble>> &inarray,
118  Array<OneD, Array<OneD, NekDouble>> &outarray)
119 {
120  int physTot = m_fields[0]->GetTotPoints();
121  Array<OneD, NekDouble> wk(physTot, 0.0);
122 
123  // U1 = u1/fx - fz/fx * u3
124  Vmath::Vdiv(physTot, inarray[0], 1, m_GeometricInfo[0], 1, outarray[0], 1);
125  Vmath::Vdiv(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[0], 1, wk, 1);
126  Vmath::Vmul(physTot, wk, 1, inarray[2], 1, wk, 1);
127  Vmath::Vsub(physTot, outarray[0], 1, wk, 1, outarray[0], 1);
128 
129  // U2 = u2
130  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
131 
132  // U3 = u3
133  Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
134 }
135 
137  const Array<OneD, Array<OneD, NekDouble>> &inarray,
138  Array<OneD, Array<OneD, NekDouble>> &outarray)
139 {
140  int physTot = m_fields[0]->GetTotPoints();
141 
142  // U1 = u1*fx
143  Vmath::Vmul(physTot, inarray[0], 1, m_GeometricInfo[0], 1, outarray[0], 1);
144 
145  // U2 = u2
146  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
147 
148  // U3 = u3 + fz*u1
149  Vmath::Vmul(physTot, m_GeometricInfo[1], 1, inarray[0], 1, outarray[2], 1);
150  Vmath::Vadd(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
151 }
152 
154 {
155  int physTot = m_fields[0]->GetTotPoints();
156  Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray, 1);
157 }
158 
160  const Array<OneD, Array<OneD, NekDouble>> &inarray,
161  Array<OneD, NekDouble> &outarray)
162 {
163  int physTot = m_fields[0]->GetTotPoints();
164 
165  Vmath::Vmul(physTot, m_GeometricInfo[2], 1, inarray[0], 1, outarray, 1);
166  Vmath::Vvtvp(physTot, m_GeometricInfo[3], 1, inarray[2], 1, outarray, 1,
167  outarray, 1);
168 }
169 
171  Array<OneD, Array<OneD, NekDouble>> &outarray)
172 {
173  int physTot = m_fields[0]->GetTotPoints();
174  int nvel = m_nConvectiveFields;
175  Array<OneD, NekDouble> wk(physTot, 0.0);
176 
177  for (int i = 0; i < nvel * nvel; i++)
178  {
179  outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
180  }
181  // Fill G^{22} and G^{33} with 1.0
182  for (int i = 1; i < nvel; i++)
183  {
184  Vmath::Sadd(physTot, 1.0, outarray[i + nvel * i], 1,
185  outarray[i + nvel * i], 1);
186  }
187 
188  // G_{13} and G_{31} = fz*fx
189  Vmath::Vmul(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[0], 1, wk,
190  1); // fz*fx
191  Vmath::Vcopy(physTot, wk, 1, outarray[0 * nvel + 2], 1);
192  Vmath::Vcopy(physTot, wk, 1, outarray[2 * nvel + 0], 1);
193 
194  // G^{11} = (fx^2)
195  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1,
196  outarray[0 * nvel + 0], 1);
197 
198  // G^{33} = (1+fz^2)
199  Vmath::Vmul(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[1], 1, wk,
200  1); // fz^2
201  Vmath::Vadd(physTot, wk, 1, outarray[2 * nvel + 2], 1,
202  outarray[2 * nvel + 2], 1);
203 }
204 
206  Array<OneD, Array<OneD, NekDouble>> &outarray)
207 {
208  int physTot = m_fields[0]->GetTotPoints();
209  int nvel = m_nConvectiveFields;
210  Array<OneD, NekDouble> wk(physTot, 0.0);
211 
212  for (int i = 0; i < nvel * nvel; i++)
213  {
214  outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
215  }
216  // Fill diagonal with 1.0
217  for (int i = 0; i < nvel; i++)
218  {
219  Vmath::Sadd(physTot, 1.0, outarray[i + nvel * i], 1,
220  outarray[i + nvel * i], 1);
221  }
222 
223  // G^{13} and G^{31} = -fz/fx
224  Vmath::Vdiv(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[0], 1, wk,
225  1); // fz/fx
226  Vmath::Neg(physTot, wk, 1);
227  Vmath::Vcopy(physTot, wk, 1, outarray[0 * nvel + 2], 1);
228  Vmath::Vcopy(physTot, wk, 1, outarray[2 * nvel + 0], 1);
229 
230  // G^{11} = (1+fz^2)/(fx^2)
231  Vmath::Vmul(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[1], 1, wk,
232  1); // fz^2
233  Vmath::Vadd(physTot, wk, 1, outarray[0 * nvel + 0], 1,
234  outarray[0 * nvel + 0], 1);
235 
236  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1, wk,
237  1); // fx^2
238  Vmath::Vdiv(physTot, outarray[0 * nvel + 0], 1, wk, 1,
239  outarray[0 * nvel + 0], 1);
240 }
241 
243  const Array<OneD, Array<OneD, NekDouble>> &inarray,
244  Array<OneD, Array<OneD, NekDouble>> &outarray)
245 {
246  int physTot = m_fields[0]->GetTotPoints();
247  Array<OneD, NekDouble> wk(physTot, 0.0);
248 
249  // out[0] = in[0]*fx^2 + in[2] * fz*fx
250  Vmath::Vmul(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[0], 1, wk,
251  1); // fz*fx
252  Vmath::Vmul(physTot, wk, 1, inarray[2], 1, outarray[0], 1); // in[2]*fz*fx
253  Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[2], 1); // in[0]*fz*fx
254 
255  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1, wk,
256  1); // fx^2
257  Vmath::Vmul(physTot, wk, 1, inarray[0], 1, wk, 1); // in[0]*fx^2
258 
259  Vmath::Vadd(physTot, outarray[0], 1, wk, 1, outarray[0], 1);
260 
261  // out[1] = in[1]
262  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
263 
264  // out[2] = fx*fz*in[0] + (1+fz^2)*in[2]
265  Vmath::Vmul(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[1], 1, wk,
266  1); // fz^2
267  Vmath::Sadd(physTot, 1.0, wk, 1, wk, 1); // 1+fz^2
268  Vmath::Vmul(physTot, wk, 1, inarray[2], 1, wk, 1); // (1+fz^2)*in[2]
269 
270  Vmath::Vadd(physTot, wk, 1, outarray[2], 1, outarray[2], 1);
271 }
272 
274  const Array<OneD, Array<OneD, NekDouble>> &inarray,
275  Array<OneD, Array<OneD, NekDouble>> &outarray)
276 {
277  int physTot = m_fields[0]->GetTotPoints();
278  Array<OneD, NekDouble> wk(physTot, 0.0);
279  Array<OneD, NekDouble> wk_2(physTot, 0.0);
280 
281  // out[2] = in[2] - in[0] * fz/fx
282  Vmath::Vdiv(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[0], 1, wk, 1);
283  Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[2], 1);
284  Vmath::Vsub(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
285 
286  // out[0] = in[0]*(1+fz^2)/(fx^2) - in[2] * fz/fx
287  Vmath::Vmul(physTot, wk, 1, inarray[2], 1, outarray[0], 1);
288  Vmath::Vmul(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[1], 1, wk, 1);
289  Vmath::Sadd(physTot, 1.0, wk, 1, wk, 1);
290  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1, wk_2, 1);
291  Vmath::Vdiv(physTot, wk, 1, wk_2, 1, wk, 1);
292  Vmath::Vmul(physTot, wk, 1, inarray[0], 1, wk, 1);
293  Vmath::Vsub(physTot, wk, 1, outarray[0], 1, outarray[0], 1);
294 
295  // out[1] = in[1]
296  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
297 }
298 
300  const Array<OneD, Array<OneD, NekDouble>> &inarray,
301  Array<OneD, Array<OneD, NekDouble>> &outarray)
302 {
303  int physTot = m_fields[0]->GetTotPoints();
304  int nvel = m_nConvectiveFields;
305  Array<OneD, NekDouble> wk(physTot, 0.0);
306 
307  for (int i = 0; i < nvel; i++)
308  {
309  for (int j = 0; j < nvel; j++)
310  {
311  outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
312  }
313  }
314 
315  // Calculate non-zero terms
316 
317  // outarray(0,0) = U1 * fxx/fx + U3 * fxz/fx
318  Vmath::Vdiv(physTot, m_GeometricInfo[2], 1, m_GeometricInfo[0], 1, wk, 1);
319  Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[0 * nvel + 0], 1);
320  Vmath::Vdiv(physTot, m_GeometricInfo[3], 1, m_GeometricInfo[0], 1, wk, 1);
321  Vmath::Vvtvp(physTot, wk, 1, inarray[2], 1, outarray[0 * nvel + 0], 1,
322  outarray[0 * nvel + 0], 1);
323 
324  // outarray(0,2) = U1 * fxz/fx + U3 * fzz/fx
325  Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[0 * nvel + 2], 1);
326  Vmath::Vdiv(physTot, m_GeometricInfo[4], 1, m_GeometricInfo[0], 1, wk, 1);
327  Vmath::Vvtvp(physTot, wk, 1, inarray[2], 1, outarray[0 * nvel + 2], 1,
328  outarray[0 * nvel + 2], 1);
329 }
330 
332  const Array<OneD, Array<OneD, NekDouble>> &inarray,
333  Array<OneD, Array<OneD, NekDouble>> &outarray)
334 {
335  int physTot = m_fields[0]->GetTotPoints();
336  int nvel = m_nConvectiveFields;
337  Array<OneD, NekDouble> wk(physTot, 0.0);
338 
339  for (int i = 0; i < nvel; i++)
340  {
341  for (int j = 0; j < nvel; j++)
342  {
343  outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
344  }
345  }
346 
347  // Calculate non-zero terms
348 
349  // outarray(0,0) = U1 * fxx/fx
350  Vmath::Vdiv(physTot, m_GeometricInfo[2], 1, m_GeometricInfo[0], 1, wk, 1);
351  Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[0 * nvel + 0], 1);
352 
353  // outarray(0,2) = outarray(2,0) = U1 * fxz/fx
354  Vmath::Vdiv(physTot, m_GeometricInfo[3], 1, m_GeometricInfo[0], 1, wk, 1);
355  Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[0 * nvel + 2], 1);
356  Vmath::Vcopy(physTot, outarray[0 * nvel + 2], 1, outarray[2 * nvel + 0], 1);
357 
358  // outarray(2,2) = U1 * fzz/fx
359  Vmath::Vdiv(physTot, m_GeometricInfo[4], 1, m_GeometricInfo[0], 1, wk, 1);
360  Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[2 * nvel + 2], 1);
361 }
362 
364 {
365  int phystot = m_fields[0]->GetTotPoints();
366  // Allocation of geometry memory
368  for (int i = 0; i < m_GeometricInfo.size(); i++)
369  {
370  m_GeometricInfo[i] = Array<OneD, NekDouble>(phystot, 0.0);
371  }
372 
373  bool waveSpace = m_fields[0]->GetWaveSpace();
374  m_fields[0]->SetWaveSpace(false);
375 
376  // Calculate derivatives of transformation
377  m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[0], m_coords[0],
378  m_GeometricInfo[0]); // f_x
379  m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2], m_coords[0],
380  m_GeometricInfo[1]); // f_z
381 
383  m_GeometricInfo[2]); // f_xx
385  m_GeometricInfo[3]); // f_xz
387  m_GeometricInfo[4]); // f_zz
388 
389  m_fields[0]->SetWaveSpace(waveSpace);
390 }
391 
392 } // namespace GlobalMapping
393 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
Base class for mapping to be applied to the coordinate system.
Definition: Mapping.h:69
int m_nConvectiveFields
Number of velocity components.
Definition: Mapping.h:414
Array< OneD, Array< OneD, NekDouble > > m_GeometricInfo
Array with metric terms of the mapping.
Definition: Mapping.h:412
Array< OneD, Array< OneD, NekDouble > > m_coords
Array with the Cartesian coordinates.
Definition: Mapping.h:408
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Definition: Mapping.h:406
virtual GLOBAL_MAPPING_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping)
Definition: Mapping.cpp:101
bool m_constantJacobian
Flag defining if the Jacobian is constant.
Definition: Mapping.h:423
virtual GLOBAL_MAPPING_EXPORT void v_UpdateGeomInfo() override
virtual GLOBAL_MAPPING_EXPORT void v_ContravarFromCartesian(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_GetJacobian(Array< OneD, NekDouble > &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_LowerIndex(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_ApplyChristoffelContravar(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_CovarFromCartesian(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_CovarToCartesian(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_GetMetricTensor(Array< OneD, Array< OneD, NekDouble >> &outarray) override
static std::string className
Name of the class.
Definition: MappingXofXZ.h:70
virtual GLOBAL_MAPPING_EXPORT void v_DotGradJacobian(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, NekDouble > &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_RaiseIndex(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_ContravarToCartesian(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_GetInvMetricTensor(Array< OneD, Array< OneD, NekDouble >> &outarray) override
MappingXofXZ(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
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: MappingXofXZ.h:58
virtual GLOBAL_MAPPING_EXPORT void v_ApplyChristoffelCovar(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping) override
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
MappingFactory & GetMappingFactory()
Declaration of the mapping factory singleton.
Definition: Mapping.cpp:53
std::shared_ptr< SessionReader > SessionReaderSharedPtr
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:91
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
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
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:359
void Vdiv(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:284
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add scalar y = alpha + x.
Definition: Vmath.cpp:384
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255
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:419