Nektar++
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// 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)
32//
33///////////////////////////////////////////////////////////////////////////////
34
37
39{
40
41std::string MappingXofZ::className =
43 "X = x + f(z)");
44
45/**
46 * @class MappingXofZ
47 * This class implements a constant-Jacobian mapping defined by
48 * a transformation of the type
49 * \f[ \bar{x} = \bar{x}(x,z) = x + f(z) \f]
50 * \f[ \bar{y} = y \f]
51 * \f[ \bar{z} = z \f]
52 * where \f$(\bar{x},\bar{y},\bar{z})\f$ are the Cartesian (physical)
53 * coordinates and \f$(x,y,z)\f$ are the transformed (computational)
54 * coordinates.
55 */
59 : Mapping(pSession, pFields)
60{
61}
62
65 const TiXmlElement *pMapping)
66{
67 Mapping::v_InitObject(pFields, pMapping);
68
69 m_constantJacobian = true;
70
72 "Mapping X = x + f(z) needs 3 velocity components.");
73}
74
76 const Array<OneD, Array<OneD, NekDouble>> &inarray,
78{
79 int physTot = m_fields[0]->GetTotPoints();
80 Array<OneD, NekDouble> wk(physTot, 0.0);
81
82 // U1 = u1 + fz*u3
83 Vmath::Vmul(physTot, inarray[2], 1, m_GeometricInfo[0], 1, wk, 1);
84 Vmath::Vadd(physTot, wk, 1, inarray[0], 1, outarray[0], 1);
85
86 // U2 = u2
87 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
88
89 // U3 = u3
90 Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
91}
92
94 const Array<OneD, Array<OneD, NekDouble>> &inarray,
96{
97 int physTot = m_fields[0]->GetTotPoints();
98 Array<OneD, NekDouble> wk(physTot, 0.0);
99
100 // U1 = u1
101 Vmath::Vcopy(physTot, inarray[0], 1, outarray[0], 1);
102
103 // U2 = u2
104 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
105
106 // U3 = u3 - fz*u1
107 Vmath::Vmul(physTot, m_GeometricInfo[0], 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 - fz * u3
119 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, wk, 1);
120 Vmath::Vsub(physTot, inarray[0], 1, wk, 1, outarray[0], 1);
121
122 // U2 = u2
123 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
124
125 // U3 = u3
126 Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
127}
128
130 const Array<OneD, Array<OneD, NekDouble>> &inarray,
132{
133 int physTot = m_fields[0]->GetTotPoints();
134
135 // U1 = u1
136 Vmath::Vcopy(physTot, inarray[0], 1, outarray[0], 1);
137
138 // U2 = u2
139 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
140
141 // U3 = u3 + fz*u1
142 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, outarray[2], 1);
143 Vmath::Vadd(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
144}
145
147{
148 int physTot = m_fields[0]->GetTotPoints();
149 Vmath::Fill(physTot, 1.0, outarray, 1);
150}
151
153 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &inarray,
154 Array<OneD, NekDouble> &outarray)
155{
156 int physTot = m_fields[0]->GetTotPoints();
157
158 Vmath::Zero(physTot, outarray, 1);
159}
160
163{
164 int physTot = m_fields[0]->GetTotPoints();
165 int nvel = m_nConvectiveFields;
166
167 for (int i = 0; i < nvel * nvel; i++)
168 {
169 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
170 }
171 // Fill diagonal with 1.0
172 for (int i = 0; i < nvel; i++)
173 {
174 Vmath::Sadd(physTot, 1.0, outarray[i + nvel * i], 1,
175 outarray[i + nvel * i], 1);
176 }
177
178 // G_{13} and G_{31} = fz
179 Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[0 * nvel + 2], 1);
180 Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[2 * nvel + 0], 1);
181
182 // G^{33} = (1+fz^2)
183 Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[2 * nvel + 2], 1,
184 outarray[2 * nvel + 2], 1);
185}
186
189{
190 int physTot = m_fields[0]->GetTotPoints();
191 int nvel = m_nConvectiveFields;
192 Array<OneD, NekDouble> wk(physTot, 0.0);
193
194 for (int i = 0; i < nvel * nvel; i++)
195 {
196 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
197 }
198 // Fill diagonal with 1.0
199 for (int i = 0; i < nvel; i++)
200 {
201 Vmath::Sadd(physTot, 1.0, outarray[i + nvel * i], 1,
202 outarray[i + nvel * i], 1);
203 }
204
205 // G^{13} and G^{31} = -fz
206 Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, wk, 1); // fz
207 Vmath::Neg(physTot, wk, 1);
208 Vmath::Vcopy(physTot, wk, 1, outarray[0 * nvel + 2], 1);
209 Vmath::Vcopy(physTot, wk, 1, outarray[2 * nvel + 0], 1);
210
211 // G^{11} = (1+fz^2)
212 Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[0 * nvel + 0], 1,
213 outarray[0 * nvel + 0], 1);
214}
215
217 const Array<OneD, Array<OneD, NekDouble>> &inarray,
219{
220 int physTot = m_fields[0]->GetTotPoints();
221 Array<OneD, NekDouble> wk(physTot, 0.0);
222
223 // out[0] = in[0] + in[2] * fz
224 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, outarray[0],
225 1); // in[2]*fz
226 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, outarray[2],
227 1); // in[0]*fz
228
229 Vmath::Vadd(physTot, outarray[0], 1, inarray[0], 1, outarray[0], 1);
230
231 // out[1] = in[1]
232 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
233
234 // out[2] = fz*in[0] + (1+fz^2)*in[2]
235 Vmath::Sadd(physTot, 1.0, m_GeometricInfo[2], 1, wk, 1); // 1+fz^2
236 Vmath::Vmul(physTot, wk, 1, inarray[2], 1, wk, 1); // (1+fz^2)*in[2]
237 Vmath::Vadd(physTot, wk, 1, outarray[2], 1, outarray[2], 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[2] = in[2] - in[0] * fz
248 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, outarray[0],
249 1); // in[2]*fz
250 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, outarray[2],
251 1); // in[0]*fz
252 Vmath::Vsub(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
253
254 // out[1] = in[1]]
255 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
256
257 // out[0] = in[0]*(1+fz^2)- in[2] * fz
258 Vmath::Sadd(physTot, 1.0, m_GeometricInfo[2], 1, wk, 1); // 1+fz^2
259 Vmath::Vmul(physTot, wk, 1, inarray[0], 1, wk, 1); // in[0]*(1+fz^2)
260 Vmath::Vsub(physTot, wk, 1, outarray[0], 1, outarray[0], 1);
261}
262
264 const Array<OneD, Array<OneD, NekDouble>> &inarray,
266{
267 int physTot = m_fields[0]->GetTotPoints();
268 int nvel = m_nConvectiveFields;
269
270 for (int i = 0; i < nvel; i++)
271 {
272 for (int j = 0; j < nvel; j++)
273 {
274 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
275 }
276 }
277
278 // Calculate non-zero terms
279
280 // outarray(0,2) = U3 * fzz
281 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, inarray[2], 1,
282 outarray[0 * nvel + 2], 1); // U1 * fzz
283}
284
286 const Array<OneD, Array<OneD, NekDouble>> &inarray,
288{
289 int physTot = m_fields[0]->GetTotPoints();
290 int nvel = m_nConvectiveFields;
291
292 for (int i = 0; i < nvel; i++)
293 {
294 for (int j = 0; j < nvel; j++)
295 {
296 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
297 }
298 }
299
300 // Calculate non-zero terms
301
302 // outarray(2,2) = U1 * fzz
303 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, inarray[0], 1,
304 outarray[2 * nvel + 2], 1); // U1 * fzz
305}
306
308{
309 int phystot = m_fields[0]->GetTotPoints();
310 // Allocation of geometry memory
312 for (int i = 0; i < m_GeometricInfo.size(); i++)
313 {
314 m_GeometricInfo[i] = Array<OneD, NekDouble>(phystot, 0.0);
315 }
316
317 bool waveSpace = m_fields[0]->GetWaveSpace();
318 m_fields[0]->SetWaveSpace(false);
319 // Calculate derivatives of transformation
321 m_GeometricInfo[0]);
323 m_GeometricInfo[1]);
324 // m_GeometricInfo[2] = fz^2
325 Vmath::Vmul(phystot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1,
326 m_GeometricInfo[2], 1);
327
328 m_fields[0]->SetWaveSpace(waveSpace);
329}
330
331} // 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_GetMetricTensor(Array< OneD, Array< OneD, NekDouble > > &outarray) override
MappingXofZ(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
Definition: MappingXofZ.cpp:56
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_CovarToCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray) override
Definition: MappingXofZ.cpp:93
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:50
static std::string className
Name of the class.
Definition: MappingXofZ.h:62
GLOBAL_MAPPING_EXPORT void v_UpdateGeomInfo() 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_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_ContravarFromCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray) override
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
Definition: MappingXofZ.cpp:63
GLOBAL_MAPPING_EXPORT void v_DotGradJacobian(const Array< OneD, Array< OneD, NekDouble > > &inarray, 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
Definition: MappingXofZ.cpp:75
GLOBAL_MAPPING_EXPORT void v_CovarFromCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, 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 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