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  "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  */
72  const TiXmlElement *pMapping)
73 {
74  Mapping::v_InitObject(pFields, pMapping);
75 
76  m_constantJacobian = true;
77 
79  "Mapping X = x + f(z) needs 3 velocity components.");
80 }
81 
83  const Array<OneD, Array<OneD, NekDouble>> &inarray,
84  Array<OneD, Array<OneD, NekDouble>> &outarray)
85 {
86  int physTot = m_fields[0]->GetTotPoints();
87  Array<OneD, NekDouble> wk(physTot, 0.0);
88 
89  // U1 = u1 + fz*u3
90  Vmath::Vmul(physTot, inarray[2], 1, m_GeometricInfo[0], 1, wk, 1);
91  Vmath::Vadd(physTot, wk, 1, inarray[0], 1, outarray[0], 1);
92 
93  // U2 = u2
94  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
95 
96  // U3 = u3
97  Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
98 }
99 
101  const Array<OneD, Array<OneD, NekDouble>> &inarray,
102  Array<OneD, Array<OneD, NekDouble>> &outarray)
103 {
104  int physTot = m_fields[0]->GetTotPoints();
105  Array<OneD, NekDouble> wk(physTot, 0.0);
106 
107  // U1 = u1
108  Vmath::Vcopy(physTot, inarray[0], 1, outarray[0], 1);
109 
110  // U2 = u2
111  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
112 
113  // U3 = u3 - fz*u1
114  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, wk, 1);
115  Vmath::Vsub(physTot, inarray[2], 1, wk, 1, outarray[2], 1);
116 }
117 
119  const Array<OneD, Array<OneD, NekDouble>> &inarray,
120  Array<OneD, Array<OneD, NekDouble>> &outarray)
121 {
122  int physTot = m_fields[0]->GetTotPoints();
123  Array<OneD, NekDouble> wk(physTot, 0.0);
124 
125  // U1 = u1 - fz * u3
126  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, wk, 1);
127  Vmath::Vsub(physTot, inarray[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
143  Vmath::Vcopy(physTot, inarray[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[0], 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::Fill(physTot, 1.0, outarray, 1);
157 }
158 
160  const Array<OneD, Array<OneD, NekDouble>> &inarray,
161  Array<OneD, NekDouble> &outarray)
162 {
163  boost::ignore_unused(inarray);
164 
165  int physTot = m_fields[0]->GetTotPoints();
166 
167  Vmath::Zero(physTot, 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 
176  for (int i = 0; i < nvel * nvel; i++)
177  {
178  outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
179  }
180  // Fill diagonal with 1.0
181  for (int i = 0; i < nvel; i++)
182  {
183  Vmath::Sadd(physTot, 1.0, outarray[i + nvel * i], 1,
184  outarray[i + nvel * i], 1);
185  }
186 
187  // G_{13} and G_{31} = fz
188  Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[0 * nvel + 2], 1);
189  Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[2 * nvel + 0], 1);
190 
191  // G^{33} = (1+fz^2)
192  Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[2 * nvel + 2], 1,
193  outarray[2 * nvel + 2], 1);
194 }
195 
197  Array<OneD, Array<OneD, NekDouble>> &outarray)
198 {
199  int physTot = m_fields[0]->GetTotPoints();
200  int nvel = m_nConvectiveFields;
201  Array<OneD, NekDouble> wk(physTot, 0.0);
202 
203  for (int i = 0; i < nvel * nvel; i++)
204  {
205  outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
206  }
207  // Fill diagonal with 1.0
208  for (int i = 0; i < nvel; i++)
209  {
210  Vmath::Sadd(physTot, 1.0, outarray[i + nvel * i], 1,
211  outarray[i + nvel * i], 1);
212  }
213 
214  // G^{13} and G^{31} = -fz
215  Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, wk, 1); // fz
216  Vmath::Neg(physTot, wk, 1);
217  Vmath::Vcopy(physTot, wk, 1, outarray[0 * nvel + 2], 1);
218  Vmath::Vcopy(physTot, wk, 1, outarray[2 * nvel + 0], 1);
219 
220  // G^{11} = (1+fz^2)
221  Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[0 * nvel + 0], 1,
222  outarray[0 * nvel + 0], 1);
223 }
224 
226  const Array<OneD, Array<OneD, NekDouble>> &inarray,
227  Array<OneD, Array<OneD, NekDouble>> &outarray)
228 {
229  int physTot = m_fields[0]->GetTotPoints();
230  Array<OneD, NekDouble> wk(physTot, 0.0);
231 
232  // out[0] = in[0] + in[2] * fz
233  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, outarray[0],
234  1); // in[2]*fz
235  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, outarray[2],
236  1); // in[0]*fz
237 
238  Vmath::Vadd(physTot, outarray[0], 1, inarray[0], 1, outarray[0], 1);
239 
240  // out[1] = in[1]
241  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
242 
243  // out[2] = fz*in[0] + (1+fz^2)*in[2]
244  Vmath::Sadd(physTot, 1.0, m_GeometricInfo[2], 1, wk, 1); // 1+fz^2
245  Vmath::Vmul(physTot, wk, 1, inarray[2], 1, wk, 1); // (1+fz^2)*in[2]
246  Vmath::Vadd(physTot, wk, 1, outarray[2], 1, outarray[2], 1);
247 }
248 
250  const Array<OneD, Array<OneD, NekDouble>> &inarray,
251  Array<OneD, Array<OneD, NekDouble>> &outarray)
252 {
253  int physTot = m_fields[0]->GetTotPoints();
254  Array<OneD, NekDouble> wk(physTot, 0.0);
255 
256  // out[2] = in[2] - in[0] * fz
257  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, outarray[0],
258  1); // in[2]*fz
259  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, outarray[2],
260  1); // in[0]*fz
261  Vmath::Vsub(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
262 
263  // out[1] = in[1]]
264  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
265 
266  // out[0] = in[0]*(1+fz^2)- in[2] * fz
267  Vmath::Sadd(physTot, 1.0, m_GeometricInfo[2], 1, wk, 1); // 1+fz^2
268  Vmath::Vmul(physTot, wk, 1, inarray[0], 1, wk, 1); // in[0]*(1+fz^2)
269  Vmath::Vsub(physTot, wk, 1, outarray[0], 1, outarray[0], 1);
270 }
271 
273  const Array<OneD, Array<OneD, NekDouble>> &inarray,
274  Array<OneD, Array<OneD, NekDouble>> &outarray)
275 {
276  int physTot = m_fields[0]->GetTotPoints();
277  int nvel = m_nConvectiveFields;
278 
279  for (int i = 0; i < nvel; i++)
280  {
281  for (int j = 0; j < nvel; j++)
282  {
283  outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
284  }
285  }
286 
287  // Calculate non-zero terms
288 
289  // outarray(0,2) = U3 * fzz
290  Vmath::Vmul(physTot, m_GeometricInfo[1], 1, inarray[2], 1,
291  outarray[0 * nvel + 2], 1); // U1 * fzz
292 }
293 
295  const Array<OneD, Array<OneD, NekDouble>> &inarray,
296  Array<OneD, Array<OneD, NekDouble>> &outarray)
297 {
298  int physTot = m_fields[0]->GetTotPoints();
299  int nvel = m_nConvectiveFields;
300 
301  for (int i = 0; i < nvel; i++)
302  {
303  for (int j = 0; j < nvel; j++)
304  {
305  outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
306  }
307  }
308 
309  // Calculate non-zero terms
310 
311  // outarray(2,2) = U1 * fzz
312  Vmath::Vmul(physTot, m_GeometricInfo[1], 1, inarray[0], 1,
313  outarray[2 * nvel + 2], 1); // U1 * fzz
314 }
315 
317 {
318  int phystot = m_fields[0]->GetTotPoints();
319  // Allocation of geometry memory
321  for (int i = 0; i < m_GeometricInfo.size(); i++)
322  {
323  m_GeometricInfo[i] = Array<OneD, NekDouble>(phystot, 0.0);
324  }
325 
326  bool waveSpace = m_fields[0]->GetWaveSpace();
327  m_fields[0]->SetWaveSpace(false);
328  // Calculate derivatives of transformation
329  m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2], m_coords[0],
330  m_GeometricInfo[0]);
332  m_GeometricInfo[1]);
333  // m_GeometricInfo[2] = fz^2
334  Vmath::Vmul(phystot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1,
335  m_GeometricInfo[2], 1);
336 
337  m_fields[0]->SetWaveSpace(waveSpace);
338 }
339 
340 } // namespace GlobalMapping
341 } // 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
MappingXofZ(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
Definition: MappingXofZ.cpp:60
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_ApplyChristoffelCovar(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
Definition: MappingXofZ.cpp:82
virtual GLOBAL_MAPPING_EXPORT void v_GetInvMetricTensor(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
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:58
virtual GLOBAL_MAPPING_EXPORT void v_DotGradJacobian(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, NekDouble > &outarray) override
static std::string className
Name of the class.
Definition: MappingXofZ.h:70
virtual GLOBAL_MAPPING_EXPORT void v_UpdateGeomInfo() 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_GetMetricTensor(Array< OneD, 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_CovarToCartesian(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, 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_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping) override
Definition: MappingXofZ.cpp:70
virtual GLOBAL_MAPPING_EXPORT void v_GetJacobian(Array< OneD, NekDouble > &outarray) 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 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 Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:492
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:45
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