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
37
39{
40
41std::string MappingXYofZ::className =
43 "X = x + f(z), Y = y +g(z)");
44
45/**
46 * @class MappingXYofZ
47 * This class implements a constant-Jacobian mapping defined by
48 * \f[ \bar{x} = \bar{x}(x,z) = x + f(z) \f]
49 * \f[ \bar{y} = \bar{y}(y,z) = y + g(z) \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 = true;
72
74 "Mapping X = x + f(z), Y = y+g(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 = u1 + fz*u3
84 Vmath::Vvtvp(physTot, m_GeometricInfo[0], 1, inarray[2], 1, inarray[0], 1,
85 outarray[0], 1);
86
87 // U2 = u2 + gz*u3
88 Vmath::Vvtvp(physTot, m_GeometricInfo[3], 1, inarray[2], 1, inarray[1], 1,
89 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
103 Vmath::Vcopy(physTot, inarray[0], 1, outarray[0], 1);
104
105 // U2 = u2
106 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
107
108 // U3 = u3 - fz*u1 - gz*u2
109 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, wk, 1);
110 Vmath::Vsub(physTot, inarray[2], 1, wk, 1, outarray[2], 1);
111 Vmath::Vmul(physTot, m_GeometricInfo[3], 1, inarray[1], 1, wk, 1);
112 Vmath::Vsub(physTot, inarray[2], 1, wk, 1, outarray[2], 1);
113}
114
116 const Array<OneD, Array<OneD, NekDouble>> &inarray,
118{
119 int physTot = m_fields[0]->GetTotPoints();
120 Array<OneD, NekDouble> wk(physTot, 0.0);
121
122 // U1 = u1 - fz * u3
123 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, wk, 1);
124 Vmath::Vsub(physTot, inarray[0], 1, wk, 1, outarray[0], 1);
125
126 // U2 = u2 - gz*u3
127 Vmath::Vmul(physTot, m_GeometricInfo[3], 1, inarray[2], 1, wk, 1);
128 Vmath::Vsub(physTot, inarray[1], 1, wk, 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
141 Vmath::Vcopy(physTot, inarray[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 + gz*u2
147 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, outarray[2], 1);
148 Vmath::Vvtvp(physTot, m_GeometricInfo[3], 1, inarray[1], 1, outarray[2], 1,
149 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 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &inarray,
161 Array<OneD, NekDouble> &outarray)
162{
163 int physTot = m_fields[0]->GetTotPoints();
164 Vmath::Zero(physTot, outarray, 1);
165}
166
169{
170 int physTot = m_fields[0]->GetTotPoints();
171 int nvel = m_nConvectiveFields;
172
173 for (int i = 0; i < nvel * nvel; i++)
174 {
175 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
176 }
177 // Fill diagonal with 1.0
178 for (int i = 0; i < nvel; i++)
179 {
180 Vmath::Sadd(physTot, 1.0, outarray[i * nvel + i], 1,
181 outarray[i * nvel + i], 1);
182 }
183
184 // G_{13} and G_{31} = fz
185 Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[0 * nvel + 2], 1);
186 Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[2 * nvel + 0], 1);
187
188 // G_{23} and G_{32} = gz
189 Vmath::Vcopy(physTot, m_GeometricInfo[3], 1, outarray[1 * nvel + 2], 1);
190 Vmath::Vcopy(physTot, m_GeometricInfo[3], 1, outarray[2 * nvel + 1], 1);
191
192 // G^{33} = (1+fz^2 + gz^2)
193 Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[2 * nvel + 2], 1,
194 outarray[2 * nvel + 2], 1);
195 Vmath::Vadd(physTot, m_GeometricInfo[5], 1, outarray[2 * nvel + 2], 1,
196 outarray[2 * nvel + 2], 1);
197}
198
201{
202 int physTot = m_fields[0]->GetTotPoints();
203 int nvel = m_nConvectiveFields;
204 Array<OneD, NekDouble> wk(physTot, 0.0);
205
206 for (int i = 0; i < nvel * nvel; i++)
207 {
208 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
209 }
210 // Fill diagonal with 1.0
211 for (int i = 0; i < nvel; i++)
212 {
213 Vmath::Sadd(physTot, 1.0, outarray[i * nvel + i], 1,
214 outarray[i * nvel + i], 1);
215 }
216
217 // G^{11} = 1+fz^2
218 Vmath::Vadd(physTot, outarray[0 * nvel + 0], 1, m_GeometricInfo[2], 1,
219 outarray[0 * nvel + 0], 1);
220
221 // G^{22} = 1+gz^2
222 Vmath::Vadd(physTot, outarray[1 * nvel + 1], 1, m_GeometricInfo[5], 1,
223 outarray[1 * nvel + 1], 1);
224
225 // G^{12} and G^{21} = fz*gz
226 Vmath::Vcopy(physTot, m_GeometricInfo[6], 1, outarray[0 * nvel + 1], 1);
227 Vmath::Vcopy(physTot, outarray[0 * nvel + 1], 1, outarray[1 * nvel + 0], 1);
228
229 // G^{13} and G^{31} = -fz
230 Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, wk, 1); // fz
231 Vmath::Neg(physTot, wk, 1);
232 Vmath::Vcopy(physTot, wk, 1, outarray[0 * nvel + 2], 1);
233 Vmath::Vcopy(physTot, wk, 1, outarray[2 * nvel + 0], 1);
234
235 // G^{23} and G^{32} = -gz
236 Vmath::Vcopy(physTot, m_GeometricInfo[3], 1, wk, 1); // fz
237 Vmath::Neg(physTot, wk, 1);
238 Vmath::Vcopy(physTot, wk, 1, outarray[1 * nvel + 2], 1);
239 Vmath::Vcopy(physTot, wk, 1, outarray[2 * nvel + 1], 1);
240}
241
243 const Array<OneD, Array<OneD, NekDouble>> &inarray,
245{
246 int physTot = m_fields[0]->GetTotPoints();
247 int nvel = m_nConvectiveFields;
248
249 for (int i = 0; i < nvel; i++)
250 {
251 for (int j = 0; j < nvel; j++)
252 {
253 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
254 }
255 }
256
257 // Calculate non-zero terms
258
259 // outarray(0,2) = U3 * fzz
260 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, inarray[2], 1,
261 outarray[0 * nvel + 2], 1);
262
263 // outarray(1,2) = U3 * gzz
264 Vmath::Vmul(physTot, m_GeometricInfo[4], 1, inarray[2], 1,
265 outarray[1 * nvel + 2], 1);
266}
267
269 const Array<OneD, Array<OneD, NekDouble>> &inarray,
271{
272 int physTot = m_fields[0]->GetTotPoints();
273 int nvel = m_nConvectiveFields;
274
275 for (int i = 0; i < nvel; i++)
276 {
277 for (int j = 0; j < nvel; j++)
278 {
279 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
280 }
281 }
282
283 // Calculate non-zero terms
284
285 // outarray(2,2) = U1 * fzz + U^2 * gzz
286 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, inarray[0], 1,
287 outarray[2 * nvel + 2], 1);
288 Vmath::Vvtvp(physTot, m_GeometricInfo[4], 1, inarray[1], 1,
289 outarray[2 * nvel + 2], 1, outarray[2 * nvel + 2], 1);
290}
291
293{
294 int phystot = m_fields[0]->GetTotPoints();
295 // Allocation of geometry memory
297 for (int i = 0; i < m_GeometricInfo.size(); i++)
298 {
299 m_GeometricInfo[i] = Array<OneD, NekDouble>(phystot, 0.0);
300 }
301
302 bool waveSpace = m_fields[0]->GetWaveSpace();
303 m_fields[0]->SetWaveSpace(false);
304
305 // Calculate derivatives of x transformation --> m_GeometricInfo 0-1
307 m_GeometricInfo[0]);
309 m_GeometricInfo[1]);
310 // m_GeometricInfo[2] = fz^2
311 Vmath::Vmul(phystot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1,
312 m_GeometricInfo[2], 1);
313
314 // Calculate derivatives of transformation -> m_GeometricInfo 3-4
316 m_GeometricInfo[3]);
318 m_GeometricInfo[4]);
319 // m_GeometricInfo[5] = gz^2
320 Vmath::Vmul(phystot, m_GeometricInfo[3], 1, m_GeometricInfo[3], 1,
321 m_GeometricInfo[5], 1);
322
323 // m_GeometricInfo[6] = gz*fz
324 Vmath::Vmul(phystot, m_GeometricInfo[0], 1, m_GeometricInfo[3], 1,
325 m_GeometricInfo[6], 1);
326
327 m_fields[0]->SetWaveSpace(waveSpace);
328}
329
330} // 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_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping) override
GLOBAL_MAPPING_EXPORT void v_CovarFromCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray) override
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_ContravarFromCartesian(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_GetMetricTensor(Array< OneD, Array< OneD, NekDouble > > &outarray) override
GLOBAL_MAPPING_EXPORT void v_DotGradJacobian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, NekDouble > &outarray) override
GLOBAL_MAPPING_EXPORT void v_UpdateGeomInfo() override
GLOBAL_MAPPING_EXPORT void v_ContravarToCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray) override
static std::string className
Name of the class.
Definition: MappingXYofZ.h:67
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:55
MappingXYofZ(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
GLOBAL_MAPPING_EXPORT void v_GetInvMetricTensor(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_GetJacobian(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:49
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 Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.hpp:273
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.hpp:54
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