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