Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Mapping of the type X = x + f(z)
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 #include <MultiRegions/ExpList.h>
38 
39 namespace Nektar
40 {
41 namespace GlobalMapping
42 {
43 
44 std::string MappingXofZ::className =
46  MappingXofZ::create, "X = x + f(z)");
47 
48 /**
49  * @class MappingXofZ
50  * This class implements a constant-Jacobian mapping defined by
51  * a transformation of the type
52  * \f[ \bar{x} = \bar{x}(x,z) = x + f(z) \f]
53  * \f[ \bar{y} = y \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  *
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 }
82 
84  const Array<OneD, Array<OneD, NekDouble> > &inarray,
85  Array<OneD, Array<OneD, NekDouble> > &outarray)
86 {
87  int physTot = m_fields[0]->GetTotPoints();
88  Array<OneD, NekDouble> wk(physTot, 0.0);
89 
90  // U1 = u1 + fz*u3
91  Vmath::Vmul(physTot, inarray[2], 1, m_GeometricInfo[0], 1, wk, 1);
92  Vmath::Vadd(physTot, wk, 1, inarray[0], 1, outarray[0],1);
93 
94  // U2 = u2
95  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
96 
97  // U3 = u3
98  Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
99 }
100 
102  const Array<OneD, Array<OneD, NekDouble> > &inarray,
103  Array<OneD, Array<OneD, NekDouble> > &outarray)
104 {
105  int physTot = m_fields[0]->GetTotPoints();
106  Array<OneD, NekDouble> wk(physTot, 0.0);
107 
108  // U1 = u1
109  Vmath::Vcopy(physTot, inarray[0], 1, outarray[0], 1);
110 
111  // U2 = u2
112  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
113 
114  // U3 = u3 - fz*u1
115  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 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
131  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
132 
133  // U3 = u3
134  Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
135 }
136 
138  const Array<OneD, Array<OneD, NekDouble> > &inarray,
139  Array<OneD, Array<OneD, NekDouble> > &outarray)
140 {
141  int physTot = m_fields[0]->GetTotPoints();
142 
143  // U1 = u1
144  Vmath::Vcopy(physTot, inarray[0], 1, outarray[0], 1);
145 
146  // U2 = u2
147  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
148 
149  // U3 = u3 + fz*u1
150  Vmath::Vmul(physTot, m_GeometricInfo[0], 1,
151  inarray[0], 1, outarray[2], 1);
152  Vmath::Vadd(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
153 }
154 
156  Array<OneD, NekDouble> &outarray)
157 {
158  int physTot = m_fields[0]->GetTotPoints();
159  Vmath::Fill(physTot, 1.0, outarray, 1);
160 }
161 
163  const Array<OneD, Array<OneD, NekDouble> > &inarray,
164  Array<OneD, NekDouble> &outarray)
165 {
166  int physTot = m_fields[0]->GetTotPoints();
167 
168  Vmath::Zero(physTot, outarray, 1);
169 }
170 
172  Array<OneD, Array<OneD, NekDouble> > &outarray)
173 {
174  int physTot = m_fields[0]->GetTotPoints();
175  int nvel = m_nConvectiveFields;
176 
177  for (int i=0; i<nvel*nvel; i++)
178  {
179  outarray[i] = Array<OneD, NekDouble> (physTot, 0.0);
180  }
181  // Fill diagonal with 1.0
182  for (int i=0; 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
189  Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[0*nvel+2], 1);
190  Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[2*nvel+0], 1);
191 
192  // G^{33} = (1+fz^2)
193  Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[2*nvel+2], 1,
194  outarray[2*nvel+2], 1);
195 }
196 
198  Array<OneD, Array<OneD, NekDouble> > &outarray)
199 {
200  int physTot = m_fields[0]->GetTotPoints();
201  int nvel = m_nConvectiveFields;
202  Array<OneD, NekDouble> wk(physTot, 0.0);
203 
204  for (int i=0; i<nvel*nvel; i++)
205  {
206  outarray[i] = Array<OneD, NekDouble> (physTot, 0.0);
207  }
208  // Fill diagonal with 1.0
209  for (int i=0; i<nvel; i++)
210  {
211  Vmath::Sadd(physTot, 1.0, outarray[i+nvel*i], 1,
212  outarray[i+nvel*i], 1);
213  }
214 
215  // G^{13} and G^{31} = -fz
216  Vmath::Vcopy(physTot, m_GeometricInfo[0],1,wk,1); // fz
217  Vmath::Neg(physTot, wk, 1);
218  Vmath::Vcopy(physTot, wk, 1, outarray[0*nvel+2], 1);
219  Vmath::Vcopy(physTot, wk, 1, outarray[2*nvel+0], 1);
220 
221  // G^{11} = (1+fz^2)
222  Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[0*nvel+0], 1,
223  outarray[0*nvel+0], 1);
224 }
225 
227  const Array<OneD, Array<OneD, NekDouble> > &inarray,
228  Array<OneD, Array<OneD, NekDouble> > &outarray)
229 {
230  int physTot = m_fields[0]->GetTotPoints();
231  Array<OneD, NekDouble> wk(physTot, 0.0);
232 
233  // out[0] = in[0] + in[2] * fz
234  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1,
235  outarray[0], 1); //in[2]*fz
236  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1,
237  outarray[2], 1); //in[0]*fz
238 
239  Vmath::Vadd(physTot, outarray[0], 1, inarray[0], 1,
240  outarray[0], 1);
241 
242  // out[1] = in[1]
243  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
244 
245  // out[2] = fz*in[0] + (1+fz^2)*in[2]
246  Vmath::Sadd(physTot, 1.0, m_GeometricInfo[2], 1, wk, 1); // 1+fz^2
247  Vmath::Vmul(physTot, wk, 1, inarray[2],1, wk, 1); // (1+fz^2)*in[2]
248  Vmath::Vadd(physTot, wk, 1, outarray[2],1, outarray[2], 1);
249 }
250 
252  const Array<OneD, Array<OneD, NekDouble> > &inarray,
253  Array<OneD, Array<OneD, NekDouble> > &outarray)
254 {
255  int physTot = m_fields[0]->GetTotPoints();
256  Array<OneD, NekDouble> wk(physTot, 0.0);
257 
258  // out[2] = in[2] - in[0] * fz
259  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1,
260  outarray[0], 1); // in[2]*fz
261  Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1,
262  outarray[2], 1); //in[0]*fz
263  Vmath::Vsub(physTot, inarray[2], 1, outarray[2], 1,
264  outarray[2], 1);
265 
266  // out[1] = in[1]]
267  Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
268 
269  // out[0] = in[0]*(1+fz^2)- in[2] * fz
270  Vmath::Sadd(physTot, 1.0, m_GeometricInfo[2], 1, wk, 1); // 1+fz^2
271  Vmath::Vmul(physTot, wk, 1, inarray[0],1, wk, 1); // in[0]*(1+fz^2)
272  Vmath::Vsub(physTot, wk, 1, outarray[0], 1, outarray[0], 1);
273 }
274 
276  const Array<OneD, Array<OneD, NekDouble> > &inarray,
277  Array<OneD, Array<OneD, NekDouble> > &outarray)
278 {
279  int physTot = m_fields[0]->GetTotPoints();
280  int nvel = m_nConvectiveFields;
281 
282  for (int i = 0; i< nvel; i++)
283  {
284  for (int j = 0; j< nvel; j++)
285  {
286  outarray[i*nvel+j] = Array<OneD, NekDouble>(physTot,0.0);
287  }
288  }
289 
290  // Calculate non-zero terms
291 
292  // outarray(0,2) = U3 * fzz
293  Vmath::Vmul(physTot,m_GeometricInfo[1],1,inarray[2],1,
294  outarray[0*nvel+2],1); // U1 * fzz
295 
296 }
297 
299  const Array<OneD, Array<OneD, NekDouble> > &inarray,
300  Array<OneD, Array<OneD, NekDouble> > &outarray)
301 {
302  int physTot = m_fields[0]->GetTotPoints();
303  int nvel = m_nConvectiveFields;
304 
305  for (int i = 0; i< nvel; i++)
306  {
307  for (int j = 0; j< nvel; j++)
308  {
309  outarray[i*nvel+j] = Array<OneD, NekDouble>(physTot,0.0);
310  }
311  }
312 
313  // Calculate non-zero terms
314 
315  // outarray(2,2) = U1 * fzz
316  Vmath::Vmul(physTot,m_GeometricInfo[1],1,inarray[0],1,
317  outarray[2*nvel+2],1); // U1 * fzz
318 }
319 
321 {
322  int phystot = m_fields[0]->GetTotPoints();
323  // Allocation of geometry memory
325  for (int i = 0; i < m_GeometricInfo.num_elements(); i++)
326  {
327  m_GeometricInfo[i] = Array<OneD, NekDouble>(phystot, 0.0);
328  }
329 
330  bool waveSpace = m_fields[0]->GetWaveSpace();
331  m_fields[0]->SetWaveSpace(false);
332  // Calculate derivatives of transformation
333  m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
334  m_coords[0],m_GeometricInfo[0]);
335  m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[2],
337  // m_GeometricInfo[2] = fz^2
338  Vmath::Vmul(phystot,m_GeometricInfo[0],1,
339  m_GeometricInfo[0],1,m_GeometricInfo[2],1);
340 
341  m_fields[0]->SetWaveSpace(waveSpace);
342 }
343 
344 }
345 }
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:60
Array< OneD, Array< OneD, NekDouble > > m_GeometricInfo
Array with metric terms of the mapping.
Definition: Mapping.h:415
Array< OneD, Array< OneD, NekDouble > > m_coords
Array with the Cartesian coordinates.
Definition: Mapping.h:411
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
MappingFactory & GetMappingFactory()
Declaration of the mapping factory singleton.
Definition: Mapping.cpp:49
virtual GLOBAL_MAPPING_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping)
Definition: MappingXofZ.cpp:70
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:46
static std::string className
Name of the class.
Definition: MappingXofZ.h:73
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
int m_nConvectiveFields
Number of velocity components.
Definition: Mapping.h:417
virtual GLOBAL_MAPPING_EXPORT void v_GetInvMetricTensor(Array< OneD, Array< OneD, NekDouble > > &outarray)
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Definition: Mapping.h:409
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:59
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:427
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:382
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:301
Base class for mapping to be applied to the coordinate system.
Definition: Mapping.h:69
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:329
virtual GLOBAL_MAPPING_EXPORT void v_GetJacobian(Array< OneD, NekDouble > &outarray)
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:86
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:83
virtual GLOBAL_MAPPING_EXPORT void v_ApplyChristoffelCovar(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
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:359
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1047
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:285
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:169
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215