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
63/**
64 *
65 */
68 const TiXmlElement *pMapping)
69{
70 Mapping::v_InitObject(pFields, pMapping);
71
72 m_constantJacobian = true;
73
75 "Mapping X = x + f(z) needs 3 velocity components.");
76}
77
79 const Array<OneD, Array<OneD, NekDouble>> &inarray,
81{
82 int physTot = m_fields[0]->GetTotPoints();
83 Array<OneD, NekDouble> wk(physTot, 0.0);
84
85 // U1 = u1 + fz*u3
86 Vmath::Vmul(physTot, inarray[2], 1, m_GeometricInfo[0], 1, wk, 1);
87 Vmath::Vadd(physTot, wk, 1, inarray[0], 1, outarray[0], 1);
88
89 // U2 = u2
90 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
91
92 // U3 = u3
93 Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
94}
95
97 const Array<OneD, Array<OneD, NekDouble>> &inarray,
99{
100 int physTot = m_fields[0]->GetTotPoints();
101 Array<OneD, NekDouble> wk(physTot, 0.0);
102
103 // U1 = u1
104 Vmath::Vcopy(physTot, inarray[0], 1, outarray[0], 1);
105
106 // U2 = u2
107 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
108
109 // U3 = u3 - fz*u1
110 Vmath::Vmul(physTot, m_GeometricInfo[0], 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 - fz * u3
122 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, wk, 1);
123 Vmath::Vsub(physTot, inarray[0], 1, wk, 1, outarray[0], 1);
124
125 // U2 = u2
126 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
127
128 // U3 = u3
129 Vmath::Vcopy(physTot, inarray[2], 1, outarray[2], 1);
130}
131
133 const Array<OneD, Array<OneD, NekDouble>> &inarray,
135{
136 int physTot = m_fields[0]->GetTotPoints();
137
138 // U1 = u1
139 Vmath::Vcopy(physTot, inarray[0], 1, outarray[0], 1);
140
141 // U2 = u2
142 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
143
144 // U3 = u3 + fz*u1
145 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, outarray[2], 1);
146 Vmath::Vadd(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
147}
148
150{
151 int physTot = m_fields[0]->GetTotPoints();
152 Vmath::Fill(physTot, 1.0, outarray, 1);
153}
154
156 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &inarray,
157 Array<OneD, NekDouble> &outarray)
158{
159 int physTot = m_fields[0]->GetTotPoints();
160
161 Vmath::Zero(physTot, outarray, 1);
162}
163
166{
167 int physTot = m_fields[0]->GetTotPoints();
168 int nvel = m_nConvectiveFields;
169
170 for (int i = 0; i < nvel * nvel; i++)
171 {
172 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
173 }
174 // Fill diagonal with 1.0
175 for (int i = 0; i < nvel; i++)
176 {
177 Vmath::Sadd(physTot, 1.0, outarray[i + nvel * i], 1,
178 outarray[i + nvel * i], 1);
179 }
180
181 // G_{13} and G_{31} = fz
182 Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[0 * nvel + 2], 1);
183 Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, outarray[2 * nvel + 0], 1);
184
185 // G^{33} = (1+fz^2)
186 Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[2 * nvel + 2], 1,
187 outarray[2 * nvel + 2], 1);
188}
189
192{
193 int physTot = m_fields[0]->GetTotPoints();
194 int nvel = m_nConvectiveFields;
195 Array<OneD, NekDouble> wk(physTot, 0.0);
196
197 for (int i = 0; i < nvel * nvel; i++)
198 {
199 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
200 }
201 // Fill diagonal with 1.0
202 for (int i = 0; i < nvel; i++)
203 {
204 Vmath::Sadd(physTot, 1.0, outarray[i + nvel * i], 1,
205 outarray[i + nvel * i], 1);
206 }
207
208 // G^{13} and G^{31} = -fz
209 Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, wk, 1); // fz
210 Vmath::Neg(physTot, wk, 1);
211 Vmath::Vcopy(physTot, wk, 1, outarray[0 * nvel + 2], 1);
212 Vmath::Vcopy(physTot, wk, 1, outarray[2 * nvel + 0], 1);
213
214 // G^{11} = (1+fz^2)
215 Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[0 * nvel + 0], 1,
216 outarray[0 * nvel + 0], 1);
217}
218
220 const Array<OneD, Array<OneD, NekDouble>> &inarray,
222{
223 int physTot = m_fields[0]->GetTotPoints();
224 Array<OneD, NekDouble> wk(physTot, 0.0);
225
226 // out[0] = in[0] + in[2] * fz
227 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, outarray[0],
228 1); // in[2]*fz
229 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, outarray[2],
230 1); // in[0]*fz
231
232 Vmath::Vadd(physTot, outarray[0], 1, inarray[0], 1, outarray[0], 1);
233
234 // out[1] = in[1]
235 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
236
237 // out[2] = fz*in[0] + (1+fz^2)*in[2]
238 Vmath::Sadd(physTot, 1.0, m_GeometricInfo[2], 1, wk, 1); // 1+fz^2
239 Vmath::Vmul(physTot, wk, 1, inarray[2], 1, wk, 1); // (1+fz^2)*in[2]
240 Vmath::Vadd(physTot, wk, 1, outarray[2], 1, outarray[2], 1);
241}
242
244 const Array<OneD, Array<OneD, NekDouble>> &inarray,
246{
247 int physTot = m_fields[0]->GetTotPoints();
248 Array<OneD, NekDouble> wk(physTot, 0.0);
249
250 // out[2] = in[2] - in[0] * fz
251 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, outarray[0],
252 1); // in[2]*fz
253 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, outarray[2],
254 1); // in[0]*fz
255 Vmath::Vsub(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
256
257 // out[1] = in[1]]
258 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
259
260 // out[0] = in[0]*(1+fz^2)- in[2] * fz
261 Vmath::Sadd(physTot, 1.0, m_GeometricInfo[2], 1, wk, 1); // 1+fz^2
262 Vmath::Vmul(physTot, wk, 1, inarray[0], 1, wk, 1); // in[0]*(1+fz^2)
263 Vmath::Vsub(physTot, wk, 1, outarray[0], 1, outarray[0], 1);
264}
265
267 const Array<OneD, Array<OneD, NekDouble>> &inarray,
269{
270 int physTot = m_fields[0]->GetTotPoints();
271 int nvel = m_nConvectiveFields;
272
273 for (int i = 0; i < nvel; i++)
274 {
275 for (int j = 0; j < nvel; j++)
276 {
277 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
278 }
279 }
280
281 // Calculate non-zero terms
282
283 // outarray(0,2) = U3 * fzz
284 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, inarray[2], 1,
285 outarray[0 * nvel + 2], 1); // U1 * fzz
286}
287
289 const Array<OneD, Array<OneD, NekDouble>> &inarray,
291{
292 int physTot = m_fields[0]->GetTotPoints();
293 int nvel = m_nConvectiveFields;
294
295 for (int i = 0; i < nvel; i++)
296 {
297 for (int j = 0; j < nvel; j++)
298 {
299 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
300 }
301 }
302
303 // Calculate non-zero terms
304
305 // outarray(2,2) = U1 * fzz
306 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, inarray[0], 1,
307 outarray[2 * nvel + 2], 1); // U1 * fzz
308}
309
311{
312 int phystot = m_fields[0]->GetTotPoints();
313 // Allocation of geometry memory
315 for (int i = 0; i < m_GeometricInfo.size(); i++)
316 {
317 m_GeometricInfo[i] = Array<OneD, NekDouble>(phystot, 0.0);
318 }
319
320 bool waveSpace = m_fields[0]->GetWaveSpace();
321 m_fields[0]->SetWaveSpace(false);
322 // Calculate derivatives of transformation
324 m_GeometricInfo[0]);
326 m_GeometricInfo[1]);
327 // m_GeometricInfo[2] = fz^2
328 Vmath::Vmul(phystot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1,
329 m_GeometricInfo[2], 1);
330
331 m_fields[0]->SetWaveSpace(waveSpace);
332}
333
334} // 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_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:96
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:56
static std::string className
Name of the class.
Definition: MappingXofZ.h:68
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:66
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:78
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: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 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