Nektar++
MappingXYofZ.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: MappingXYofZ.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), Y = y + g(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 MappingXYofZ::className =
47  MappingXYofZ::create, "X = x + f(z), Y = y +g(z)");
48 
49 /**
50  * @class MappingXYofZ
51  * This class implements a constant-Jacobian mapping defined by
52  * \f[ \bar{x} = \bar{x}(x,z) = x + f(z) \f]
53  * \f[ \bar{y} = \bar{y}(y,z) = y + g(z) \f]
54  * \f[ \bar{z} = z \f]
55  * where \f$(\bar{x},\bar{y},\bar{z})\f$ are the Cartesian (physical)
56  * coordinates and \f$(x,y,z)\f$ are the transformed (computational)
57  * coordinates.
58  */
62  : Mapping(pSession, pFields)
63 {
64 }
65 
66 /**
67  *
68  */
71  const TiXmlElement *pMapping)
72 {
73  Mapping::v_InitObject(pFields, pMapping);
74 
75  m_constantJacobian = true;
76 
78  "Mapping X = x + f(z), Y = y+g(z) needs 3 velocity components.");
79 }
80 
82  const Array<OneD, Array<OneD, NekDouble> > &inarray,
83  Array<OneD, Array<OneD, NekDouble> > &outarray)
84 {
85  int physTot = m_fields[0]->GetTotPoints();
86 
87  // U1 = u1 + fz*u3
88  Vmath::Vvtvp(physTot, m_GeometricInfo[0], 1, inarray[2], 1,
89  inarray[0], 1, outarray[0],1);
90 
91  // U2 = u2 + gz*u3
92  Vmath::Vvtvp(physTot, m_GeometricInfo[3], 1, inarray[2], 1,
93  inarray[1], 1, outarray[1],1);
94 
95  // U3 = u3
96  Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
97 }
98 
100  const Array<OneD, Array<OneD, NekDouble> > &inarray,
101  Array<OneD, Array<OneD, NekDouble> > &outarray)
102 {
103  int physTot = m_fields[0]->GetTotPoints();
104  Array<OneD, NekDouble> wk(physTot, 0.0);
105 
106  // U1 = u1
107  Vmath::Vcopy(physTot, inarray[0], 1, outarray[0], 1);
108 
109  // U2 = u2
110  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
111 
112  // U3 = u3 - fz*u1 - gz*u2
113  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, wk, 1);
114  Vmath::Vsub(physTot, inarray[2], 1, wk, 1, outarray[2], 1);
115  Vmath::Vmul(physTot, m_GeometricInfo[3], 1, inarray[1], 1, wk, 1);
116  Vmath::Vsub(physTot, inarray[2], 1, wk, 1, outarray[2], 1);
117 }
118 
120  const Array<OneD, Array<OneD, NekDouble> > &inarray,
121  Array<OneD, Array<OneD, NekDouble> > &outarray)
122 {
123  int physTot = m_fields[0]->GetTotPoints();
124  Array<OneD, NekDouble> wk(physTot, 0.0);
125 
126  // U1 = u1 - fz * u3
127  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, wk, 1);
128  Vmath::Vsub(physTot, inarray[0], 1, wk, 1, outarray[0], 1);
129 
130  // U2 = u2 - gz*u3
131  Vmath::Vmul(physTot, m_GeometricInfo[3], 1, inarray[2], 1, wk, 1);
132  Vmath::Vsub(physTot, inarray[1], 1, wk, 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 + gz*u2
151  Vmath::Vmul(physTot, m_GeometricInfo[0], 1,
152  inarray[0], 1, outarray[2], 1);
153  Vmath::Vvtvp(physTot, m_GeometricInfo[3], 1, inarray[1], 1,
154  outarray[2], 1, outarray[2], 1);
155  Vmath::Vadd(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
156 }
157 
159  Array<OneD, NekDouble> &outarray)
160 {
161  int physTot = m_fields[0]->GetTotPoints();
162  Vmath::Fill(physTot, 1.0, outarray, 1);
163 }
164 
166  const Array<OneD, Array<OneD, NekDouble> > &inarray,
167  Array<OneD, NekDouble> &outarray)
168 {
169  boost::ignore_unused(inarray);
170 
171  int physTot = m_fields[0]->GetTotPoints();
172  Vmath::Zero(physTot, outarray, 1);
173 }
174 
176  Array<OneD, Array<OneD, NekDouble> > &outarray)
177 {
178  int physTot = m_fields[0]->GetTotPoints();
179  int nvel = m_nConvectiveFields;
180 
181  for (int i=0; i<nvel*nvel; i++)
182  {
183  outarray[i] = Array<OneD, NekDouble> (physTot, 0.0);
184  }
185  // Fill diagonal with 1.0
186  for (int i=0; i<nvel; i++)
187  {
188  Vmath::Sadd(physTot, 1.0, outarray[i*nvel+i], 1,
189  outarray[i*nvel+i], 1);
190  }
191 
192  // G_{13} and G_{31} = fz
193  Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[0*nvel+2], 1);
194  Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[2*nvel+0], 1);
195 
196  // G_{23} and G_{32} = gz
197  Vmath::Vcopy(physTot, m_GeometricInfo[3], 1, outarray[1*nvel+2], 1);
198  Vmath::Vcopy(physTot, m_GeometricInfo[3], 1, outarray[2*nvel+1], 1);
199 
200  // G^{33} = (1+fz^2 + gz^2)
201  Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[2*nvel+2], 1,
202  outarray[2*nvel+2], 1);
203  Vmath::Vadd(physTot, m_GeometricInfo[5], 1, outarray[2*nvel+2], 1,
204  outarray[2*nvel+2], 1);
205 }
206 
208  Array<OneD, Array<OneD, NekDouble> > &outarray)
209 {
210  int physTot = m_fields[0]->GetTotPoints();
211  int nvel = m_nConvectiveFields;
212  Array<OneD, NekDouble> wk(physTot, 0.0);
213 
214  for (int i=0; i<nvel*nvel; i++)
215  {
216  outarray[i] = Array<OneD, NekDouble> (physTot, 0.0);
217  }
218  // Fill diagonal with 1.0
219  for (int i=0; i<nvel; i++)
220  {
221  Vmath::Sadd(physTot, 1.0, outarray[i*nvel+i], 1,
222  outarray[i*nvel+i], 1);
223  }
224 
225  // G^{11} = 1+fz^2
226  Vmath::Vadd(physTot, outarray[0*nvel+0], 1, m_GeometricInfo[2], 1,
227  outarray[0*nvel+0], 1);
228 
229  // G^{22} = 1+gz^2
230  Vmath::Vadd(physTot, outarray[1*nvel+1], 1, m_GeometricInfo[5], 1,
231  outarray[1*nvel+1], 1);
232 
233  // G^{12} and G^{21} = fz*gz
234  Vmath::Vcopy(physTot, m_GeometricInfo[6],1, outarray[0*nvel+1], 1);
235  Vmath::Vcopy(physTot, outarray[0*nvel+1], 1, outarray[1*nvel+0], 1);
236 
237  // G^{13} and G^{31} = -fz
238  Vmath::Vcopy(physTot, m_GeometricInfo[0],1,wk,1); // fz
239  Vmath::Neg(physTot, wk, 1);
240  Vmath::Vcopy(physTot, wk, 1, outarray[0*nvel+2], 1);
241  Vmath::Vcopy(physTot, wk, 1, outarray[2*nvel+0], 1);
242 
243  // G^{23} and G^{32} = -gz
244  Vmath::Vcopy(physTot, m_GeometricInfo[3],1,wk,1); // fz
245  Vmath::Neg(physTot, wk, 1);
246  Vmath::Vcopy(physTot, wk, 1, outarray[1*nvel+2], 1);
247  Vmath::Vcopy(physTot, wk, 1, outarray[2*nvel+1], 1);
248 }
249 
251  const Array<OneD, Array<OneD, NekDouble> > &inarray,
252  Array<OneD, Array<OneD, NekDouble> > &outarray)
253 {
254  int physTot = m_fields[0]->GetTotPoints();
255  int nvel = m_nConvectiveFields;
256 
257  for (int i = 0; i< nvel; i++)
258  {
259  for (int j = 0; j< nvel; j++)
260  {
261  outarray[i*nvel+j] = Array<OneD, NekDouble>(physTot,0.0);
262  }
263  }
264 
265  // Calculate non-zero terms
266 
267  // outarray(0,2) = U3 * fzz
268  Vmath::Vmul(physTot,m_GeometricInfo[1],1,inarray[2],1,
269  outarray[0*nvel+2],1);
270 
271  // outarray(1,2) = U3 * gzz
272  Vmath::Vmul(physTot,m_GeometricInfo[4],1,inarray[2],1,
273  outarray[1*nvel+2],1);
274 
275 }
276 
278  const Array<OneD, Array<OneD, NekDouble> > &inarray,
279  Array<OneD, Array<OneD, NekDouble> > &outarray)
280 {
281  int physTot = m_fields[0]->GetTotPoints();
282  int nvel = m_nConvectiveFields;
283 
284  for (int i = 0; i< nvel; i++)
285  {
286  for (int j = 0; j< nvel; j++)
287  {
288  outarray[i*nvel+j] = Array<OneD, NekDouble>(physTot,0.0);
289  }
290  }
291 
292  // Calculate non-zero terms
293 
294  // outarray(2,2) = U1 * fzz + U^2 * gzz
295  Vmath::Vmul(physTot,m_GeometricInfo[1],1,inarray[0],1,outarray[2*nvel+2],1);
296  Vmath::Vvtvp(physTot, m_GeometricInfo[4], 1, inarray[1], 1,
297  outarray[2*nvel+2], 1, outarray[2*nvel+2],1);
298 }
299 
301 {
302  int phystot = m_fields[0]->GetTotPoints();
303  // Allocation of geometry memory
305  for (int i = 0; i < m_GeometricInfo.num_elements(); i++)
306  {
307  m_GeometricInfo[i] = Array<OneD, NekDouble>(phystot, 0.0);
308  }
309 
310  bool waveSpace = m_fields[0]->GetWaveSpace();
311  m_fields[0]->SetWaveSpace(false);
312 
313  // Calculate derivatives of x transformation --> m_GeometricInfo 0-1
314  m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
315  m_coords[0],m_GeometricInfo[0]);
316  m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
318  // m_GeometricInfo[2] = fz^2
319  Vmath::Vmul(phystot,m_GeometricInfo[0],1,m_GeometricInfo[0],1,
320  m_GeometricInfo[2],1);
321 
322  // Calculate derivatives of transformation -> m_GeometricInfo 3-4
323  m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
324  m_coords[1],m_GeometricInfo[3]);
325  m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
327  // m_GeometricInfo[5] = gz^2
328  Vmath::Vmul(phystot,m_GeometricInfo[3],1,m_GeometricInfo[3],1,
329  m_GeometricInfo[5],1);
330 
331  // m_GeometricInfo[6] = gz*fz
332  Vmath::Vmul(phystot,m_GeometricInfo[0],1,m_GeometricInfo[3],1,
333  m_GeometricInfo[6],1);
334 
335  m_fields[0]->SetWaveSpace(waveSpace);
336 }
337 
338 }
339 }
Array< OneD, Array< OneD, NekDouble > > m_GeometricInfo
Array with metric terms of the mapping.
Definition: Mapping.h:414
virtual GLOBAL_MAPPING_EXPORT void v_ApplyChristoffelContravar(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
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_DotGradJacobian(const Array< OneD, Array< OneD, NekDouble > > &inarray, 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
virtual GLOBAL_MAPPING_EXPORT void v_ContravarFromCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
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:445
virtual GLOBAL_MAPPING_EXPORT void v_GetJacobian(Array< OneD, NekDouble > &outarray)
int m_nConvectiveFields
Number of velocity components.
Definition: Mapping.h:416
virtual GLOBAL_MAPPING_EXPORT void v_ApplyChristoffelCovar(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Definition: Mapping.h:408
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: MappingXYofZ.h:58
virtual GLOBAL_MAPPING_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping)
virtual GLOBAL_MAPPING_EXPORT void v_CovarToCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
virtual GLOBAL_MAPPING_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping)
Definition: Mapping.cpp:100
virtual GLOBAL_MAPPING_EXPORT void v_GetMetricTensor(Array< OneD, Array< OneD, NekDouble > > &outarray)
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_CovarFromCartesian(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
static std::string className
Name of the class.
Definition: MappingXYofZ.h:71
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
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:88
virtual GLOBAL_MAPPING_EXPORT void v_UpdateGeomInfo()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:376
MappingXYofZ(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
virtual GLOBAL_MAPPING_EXPORT void v_ContravarToCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
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
virtual GLOBAL_MAPPING_EXPORT void v_GetInvMetricTensor(Array< OneD, Array< OneD, NekDouble > > &outarray)