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
62/**
63 *
64 */
67 const TiXmlElement *pMapping)
68{
69 Mapping::v_InitObject(pFields, pMapping);
70
71 m_constantJacobian = false;
72
74 "Mapping X = X(x,z) needs 3 velocity components.");
75}
76
78 const Array<OneD, Array<OneD, NekDouble>> &inarray,
80{
81 int physTot = m_fields[0]->GetTotPoints();
82
83 // U1 = fx*u1 + fz*u3
84 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, outarray[0], 1);
85 Vmath::Vvtvp(physTot, m_GeometricInfo[1], 1, inarray[2], 1, outarray[0], 1,
86 outarray[0], 1);
87
88 // U2 = u2
89 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
90
91 // U3 = u3
92 Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
93}
94
96 const Array<OneD, Array<OneD, NekDouble>> &inarray,
98{
99 int physTot = m_fields[0]->GetTotPoints();
100 Array<OneD, NekDouble> wk(physTot, 0.0);
101
102 // U1 = u1/fx
103 Vmath::Vdiv(physTot, inarray[0], 1, m_GeometricInfo[0], 1, outarray[0], 1);
104
105 // U2 = u2
106 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
107
108 // U3 = u3 - fz/fx*u1
109 Vmath::Vdiv(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[0], 1, wk, 1);
110 Vmath::Vmul(physTot, wk, 1, inarray[0], 1, wk, 1);
111 Vmath::Vsub(physTot, inarray[2], 1, wk, 1, outarray[2], 1);
112}
113
115 const Array<OneD, Array<OneD, NekDouble>> &inarray,
117{
118 int physTot = m_fields[0]->GetTotPoints();
119 Array<OneD, NekDouble> wk(physTot, 0.0);
120
121 // U1 = u1/fx - fz/fx * u3
122 Vmath::Vdiv(physTot, inarray[0], 1, m_GeometricInfo[0], 1, outarray[0], 1);
123 Vmath::Vdiv(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[0], 1, wk, 1);
124 Vmath::Vmul(physTot, wk, 1, inarray[2], 1, wk, 1);
125 Vmath::Vsub(physTot, outarray[0], 1, wk, 1, outarray[0], 1);
126
127 // U2 = u2
128 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
129
130 // U3 = u3
131 Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
132}
133
135 const Array<OneD, Array<OneD, NekDouble>> &inarray,
137{
138 int physTot = m_fields[0]->GetTotPoints();
139
140 // U1 = u1*fx
141 Vmath::Vmul(physTot, inarray[0], 1, m_GeometricInfo[0], 1, outarray[0], 1);
142
143 // U2 = u2
144 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
145
146 // U3 = u3 + fz*u1
147 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, inarray[0], 1, outarray[2], 1);
148 Vmath::Vadd(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
149}
150
152{
153 int physTot = m_fields[0]->GetTotPoints();
154 Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray, 1);
155}
156
158 const Array<OneD, Array<OneD, NekDouble>> &inarray,
159 Array<OneD, NekDouble> &outarray)
160{
161 int physTot = m_fields[0]->GetTotPoints();
162
163 Vmath::Vmul(physTot, m_GeometricInfo[2], 1, inarray[0], 1, outarray, 1);
164 Vmath::Vvtvp(physTot, m_GeometricInfo[3], 1, inarray[2], 1, outarray, 1,
165 outarray, 1);
166}
167
170{
171 int physTot = m_fields[0]->GetTotPoints();
172 int nvel = m_nConvectiveFields;
173 Array<OneD, NekDouble> wk(physTot, 0.0);
174
175 for (int i = 0; i < nvel * nvel; i++)
176 {
177 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
178 }
179 // Fill G^{22} and G^{33} with 1.0
180 for (int i = 1; i < nvel; i++)
181 {
182 Vmath::Sadd(physTot, 1.0, outarray[i + nvel * i], 1,
183 outarray[i + nvel * i], 1);
184 }
185
186 // G_{13} and G_{31} = fz*fx
187 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[0], 1, wk,
188 1); // fz*fx
189 Vmath::Vcopy(physTot, wk, 1, outarray[0 * nvel + 2], 1);
190 Vmath::Vcopy(physTot, wk, 1, outarray[2 * nvel + 0], 1);
191
192 // G^{11} = (fx^2)
193 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1,
194 outarray[0 * nvel + 0], 1);
195
196 // G^{33} = (1+fz^2)
197 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[1], 1, wk,
198 1); // fz^2
199 Vmath::Vadd(physTot, wk, 1, outarray[2 * nvel + 2], 1,
200 outarray[2 * nvel + 2], 1);
201}
202
205{
206 int physTot = m_fields[0]->GetTotPoints();
207 int nvel = m_nConvectiveFields;
208 Array<OneD, NekDouble> wk(physTot, 0.0);
209
210 for (int i = 0; i < nvel * nvel; i++)
211 {
212 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
213 }
214 // Fill diagonal with 1.0
215 for (int i = 0; i < nvel; i++)
216 {
217 Vmath::Sadd(physTot, 1.0, outarray[i + nvel * i], 1,
218 outarray[i + nvel * i], 1);
219 }
220
221 // G^{13} and G^{31} = -fz/fx
222 Vmath::Vdiv(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[0], 1, wk,
223 1); // fz/fx
224 Vmath::Neg(physTot, wk, 1);
225 Vmath::Vcopy(physTot, wk, 1, outarray[0 * nvel + 2], 1);
226 Vmath::Vcopy(physTot, wk, 1, outarray[2 * nvel + 0], 1);
227
228 // G^{11} = (1+fz^2)/(fx^2)
229 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[1], 1, wk,
230 1); // fz^2
231 Vmath::Vadd(physTot, wk, 1, outarray[0 * nvel + 0], 1,
232 outarray[0 * nvel + 0], 1);
233
234 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1, wk,
235 1); // fx^2
236 Vmath::Vdiv(physTot, outarray[0 * nvel + 0], 1, wk, 1,
237 outarray[0 * nvel + 0], 1);
238}
239
241 const Array<OneD, Array<OneD, NekDouble>> &inarray,
243{
244 int physTot = m_fields[0]->GetTotPoints();
245 Array<OneD, NekDouble> wk(physTot, 0.0);
246
247 // out[0] = in[0]*fx^2 + in[2] * fz*fx
248 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[0], 1, wk,
249 1); // fz*fx
250 Vmath::Vmul(physTot, wk, 1, inarray[2], 1, outarray[0], 1); // in[2]*fz*fx
251 Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[2], 1); // in[0]*fz*fx
252
253 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1, wk,
254 1); // fx^2
255 Vmath::Vmul(physTot, wk, 1, inarray[0], 1, wk, 1); // in[0]*fx^2
256
257 Vmath::Vadd(physTot, outarray[0], 1, wk, 1, outarray[0], 1);
258
259 // out[1] = in[1]
260 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
261
262 // out[2] = fx*fz*in[0] + (1+fz^2)*in[2]
263 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[1], 1, wk,
264 1); // fz^2
265 Vmath::Sadd(physTot, 1.0, wk, 1, wk, 1); // 1+fz^2
266 Vmath::Vmul(physTot, wk, 1, inarray[2], 1, wk, 1); // (1+fz^2)*in[2]
267
268 Vmath::Vadd(physTot, wk, 1, outarray[2], 1, outarray[2], 1);
269}
270
272 const Array<OneD, Array<OneD, NekDouble>> &inarray,
274{
275 int physTot = m_fields[0]->GetTotPoints();
276 Array<OneD, NekDouble> wk(physTot, 0.0);
277 Array<OneD, NekDouble> wk_2(physTot, 0.0);
278
279 // out[2] = in[2] - in[0] * fz/fx
280 Vmath::Vdiv(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[0], 1, wk, 1);
281 Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[2], 1);
282 Vmath::Vsub(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
283
284 // out[0] = in[0]*(1+fz^2)/(fx^2) - in[2] * fz/fx
285 Vmath::Vmul(physTot, wk, 1, inarray[2], 1, outarray[0], 1);
286 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, m_GeometricInfo[1], 1, wk, 1);
287 Vmath::Sadd(physTot, 1.0, wk, 1, wk, 1);
288 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1, wk_2, 1);
289 Vmath::Vdiv(physTot, wk, 1, wk_2, 1, wk, 1);
290 Vmath::Vmul(physTot, wk, 1, inarray[0], 1, wk, 1);
291 Vmath::Vsub(physTot, wk, 1, outarray[0], 1, outarray[0], 1);
292
293 // out[1] = in[1]
294 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
295}
296
298 const Array<OneD, Array<OneD, NekDouble>> &inarray,
300{
301 int physTot = m_fields[0]->GetTotPoints();
302 int nvel = m_nConvectiveFields;
303 Array<OneD, NekDouble> wk(physTot, 0.0);
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(0,0) = U1 * fxx/fx + U3 * fxz/fx
316 Vmath::Vdiv(physTot, m_GeometricInfo[2], 1, m_GeometricInfo[0], 1, wk, 1);
317 Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[0 * nvel + 0], 1);
318 Vmath::Vdiv(physTot, m_GeometricInfo[3], 1, m_GeometricInfo[0], 1, wk, 1);
319 Vmath::Vvtvp(physTot, wk, 1, inarray[2], 1, outarray[0 * nvel + 0], 1,
320 outarray[0 * nvel + 0], 1);
321
322 // outarray(0,2) = U1 * fxz/fx + U3 * fzz/fx
323 Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[0 * nvel + 2], 1);
324 Vmath::Vdiv(physTot, m_GeometricInfo[4], 1, m_GeometricInfo[0], 1, wk, 1);
325 Vmath::Vvtvp(physTot, wk, 1, inarray[2], 1, outarray[0 * nvel + 2], 1,
326 outarray[0 * nvel + 2], 1);
327}
328
330 const Array<OneD, Array<OneD, NekDouble>> &inarray,
332{
333 int physTot = m_fields[0]->GetTotPoints();
334 int nvel = m_nConvectiveFields;
335 Array<OneD, NekDouble> wk(physTot, 0.0);
336
337 for (int i = 0; i < nvel; i++)
338 {
339 for (int j = 0; j < nvel; j++)
340 {
341 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
342 }
343 }
344
345 // Calculate non-zero terms
346
347 // outarray(0,0) = U1 * fxx/fx
348 Vmath::Vdiv(physTot, m_GeometricInfo[2], 1, m_GeometricInfo[0], 1, wk, 1);
349 Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[0 * nvel + 0], 1);
350
351 // outarray(0,2) = outarray(2,0) = U1 * fxz/fx
352 Vmath::Vdiv(physTot, m_GeometricInfo[3], 1, m_GeometricInfo[0], 1, wk, 1);
353 Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[0 * nvel + 2], 1);
354 Vmath::Vcopy(physTot, outarray[0 * nvel + 2], 1, outarray[2 * nvel + 0], 1);
355
356 // outarray(2,2) = U1 * fzz/fx
357 Vmath::Vdiv(physTot, m_GeometricInfo[4], 1, m_GeometricInfo[0], 1, wk, 1);
358 Vmath::Vmul(physTot, wk, 1, inarray[0], 1, outarray[2 * nvel + 2], 1);
359}
360
362{
363 int phystot = m_fields[0]->GetTotPoints();
364 // Allocation of geometry memory
366 for (int i = 0; i < m_GeometricInfo.size(); i++)
367 {
368 m_GeometricInfo[i] = Array<OneD, NekDouble>(phystot, 0.0);
369 }
370
371 bool waveSpace = m_fields[0]->GetWaveSpace();
372 m_fields[0]->SetWaveSpace(false);
373
374 // Calculate derivatives of transformation
376 m_GeometricInfo[0]); // f_x
378 m_GeometricInfo[1]); // f_z
379
381 m_GeometricInfo[2]); // f_xx
383 m_GeometricInfo[3]); // f_xz
385 m_GeometricInfo[4]); // f_zz
386
387 m_fields[0]->SetWaveSpace(waveSpace);
388}
389
390} // 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:67
int m_nConvectiveFields
Number of velocity components.
Definition: Mapping.h:412
Array< OneD, Array< OneD, NekDouble > > m_GeometricInfo
Array with metric terms of the mapping.
Definition: Mapping.h:410
Array< OneD, Array< OneD, NekDouble > > m_coords
Array with the Cartesian coordinates.
Definition: Mapping.h:406
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Definition: Mapping.h:404
virtual GLOBAL_MAPPING_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping)
Definition: Mapping.cpp:97
bool m_constantJacobian
Flag defining if the Jacobian is constant.
Definition: Mapping.h:421
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:68
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:56
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.
Definition: NekFactory.hpp:197
MappingFactory & GetMappingFactory()
Declaration of the mapping factory singleton.
Definition: Mapping.cpp:49
std::shared_ptr< SessionReader > SessionReaderSharedPtr
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:86
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