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
64 const TiXmlElement *pMapping)
65{
66 Mapping::v_InitObject(pFields, pMapping);
67
68 m_constantJacobian = true;
69
71 "Mapping X = x + f(z), Y = y+g(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 = u1 + fz*u3
81 Vmath::Vvtvp(physTot, m_GeometricInfo[0], 1, inarray[2], 1, inarray[0], 1,
82 outarray[0], 1);
83
84 // U2 = u2 + gz*u3
85 Vmath::Vvtvp(physTot, m_GeometricInfo[3], 1, inarray[2], 1, inarray[1], 1,
86 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
100 Vmath::Vcopy(physTot, inarray[0], 1, outarray[0], 1);
101
102 // U2 = u2
103 Vmath::Vcopy(physTot, inarray[1], 1, outarray[1], 1);
104
105 // U3 = u3 - fz*u1 - gz*u2
106 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, wk, 1);
107 Vmath::Vsub(physTot, inarray[2], 1, wk, 1, outarray[2], 1);
108 Vmath::Vmul(physTot, m_GeometricInfo[3], 1, inarray[1], 1, wk, 1);
109 Vmath::Vsub(physTot, inarray[2], 1, wk, 1, outarray[2], 1);
110}
111
113 const Array<OneD, Array<OneD, NekDouble>> &inarray,
115{
116 int physTot = m_fields[0]->GetTotPoints();
117 Array<OneD, NekDouble> wk(physTot, 0.0);
118
119 // U1 = u1 - fz * u3
120 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[2], 1, wk, 1);
121 Vmath::Vsub(physTot, inarray[0], 1, wk, 1, outarray[0], 1);
122
123 // U2 = u2 - gz*u3
124 Vmath::Vmul(physTot, m_GeometricInfo[3], 1, inarray[2], 1, wk, 1);
125 Vmath::Vsub(physTot, inarray[1], 1, wk, 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
138 Vmath::Vcopy(physTot, inarray[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 + gz*u2
144 Vmath::Vmul(physTot, m_GeometricInfo[0], 1, inarray[0], 1, outarray[2], 1);
145 Vmath::Vvtvp(physTot, m_GeometricInfo[3], 1, inarray[1], 1, outarray[2], 1,
146 outarray[2], 1);
147 Vmath::Vadd(physTot, inarray[2], 1, outarray[2], 1, outarray[2], 1);
148}
149
151{
152 int physTot = m_fields[0]->GetTotPoints();
153 Vmath::Fill(physTot, 1.0, outarray, 1);
154}
155
157 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &inarray,
158 Array<OneD, NekDouble> &outarray)
159{
160 int physTot = m_fields[0]->GetTotPoints();
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_{23} and G_{32} = gz
186 Vmath::Vcopy(physTot, m_GeometricInfo[3], 1, outarray[1 * nvel + 2], 1);
187 Vmath::Vcopy(physTot, m_GeometricInfo[3], 1, outarray[2 * nvel + 1], 1);
188
189 // G^{33} = (1+fz^2 + gz^2)
190 Vmath::Vadd(physTot, m_GeometricInfo[2], 1, outarray[2 * nvel + 2], 1,
191 outarray[2 * nvel + 2], 1);
192 Vmath::Vadd(physTot, m_GeometricInfo[5], 1, outarray[2 * nvel + 2], 1,
193 outarray[2 * nvel + 2], 1);
194}
195
198{
199 int physTot = m_fields[0]->GetTotPoints();
200 int nvel = m_nConvectiveFields;
201 Array<OneD, NekDouble> wk(physTot, 0.0);
202
203 for (int i = 0; i < nvel * nvel; i++)
204 {
205 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
206 }
207 // Fill diagonal with 1.0
208 for (int i = 0; i < nvel; i++)
209 {
210 Vmath::Sadd(physTot, 1.0, outarray[i * nvel + i], 1,
211 outarray[i * nvel + i], 1);
212 }
213
214 // G^{11} = 1+fz^2
215 Vmath::Vadd(physTot, outarray[0 * nvel + 0], 1, m_GeometricInfo[2], 1,
216 outarray[0 * nvel + 0], 1);
217
218 // G^{22} = 1+gz^2
219 Vmath::Vadd(physTot, outarray[1 * nvel + 1], 1, m_GeometricInfo[5], 1,
220 outarray[1 * nvel + 1], 1);
221
222 // G^{12} and G^{21} = fz*gz
223 Vmath::Vcopy(physTot, m_GeometricInfo[6], 1, outarray[0 * nvel + 1], 1);
224 Vmath::Vcopy(physTot, outarray[0 * nvel + 1], 1, outarray[1 * nvel + 0], 1);
225
226 // G^{13} and G^{31} = -fz
227 Vmath::Vcopy(physTot, m_GeometricInfo[0], 1, wk, 1); // fz
228 Vmath::Neg(physTot, wk, 1);
229 Vmath::Vcopy(physTot, wk, 1, outarray[0 * nvel + 2], 1);
230 Vmath::Vcopy(physTot, wk, 1, outarray[2 * nvel + 0], 1);
231
232 // G^{23} and G^{32} = -gz
233 Vmath::Vcopy(physTot, m_GeometricInfo[3], 1, wk, 1); // fz
234 Vmath::Neg(physTot, wk, 1);
235 Vmath::Vcopy(physTot, wk, 1, outarray[1 * nvel + 2], 1);
236 Vmath::Vcopy(physTot, wk, 1, outarray[2 * nvel + 1], 1);
237}
238
240 const Array<OneD, Array<OneD, NekDouble>> &inarray,
242{
243 int physTot = m_fields[0]->GetTotPoints();
244 int nvel = m_nConvectiveFields;
245
246 for (int i = 0; i < nvel; i++)
247 {
248 for (int j = 0; j < nvel; j++)
249 {
250 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
251 }
252 }
253
254 // Calculate non-zero terms
255
256 // outarray(0,2) = U3 * fzz
257 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, inarray[2], 1,
258 outarray[0 * nvel + 2], 1);
259
260 // outarray(1,2) = U3 * gzz
261 Vmath::Vmul(physTot, m_GeometricInfo[4], 1, inarray[2], 1,
262 outarray[1 * nvel + 2], 1);
263}
264
266 const Array<OneD, Array<OneD, NekDouble>> &inarray,
268{
269 int physTot = m_fields[0]->GetTotPoints();
270 int nvel = m_nConvectiveFields;
271
272 for (int i = 0; i < nvel; i++)
273 {
274 for (int j = 0; j < nvel; j++)
275 {
276 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
277 }
278 }
279
280 // Calculate non-zero terms
281
282 // outarray(2,2) = U1 * fzz + U^2 * gzz
283 Vmath::Vmul(physTot, m_GeometricInfo[1], 1, inarray[0], 1,
284 outarray[2 * nvel + 2], 1);
285 Vmath::Vvtvp(physTot, m_GeometricInfo[4], 1, inarray[1], 1,
286 outarray[2 * nvel + 2], 1, outarray[2 * nvel + 2], 1);
287}
288
290{
291 int phystot = m_fields[0]->GetTotPoints();
292 // Allocation of geometry memory
294 for (int i = 0; i < m_GeometricInfo.size(); i++)
295 {
296 m_GeometricInfo[i] = Array<OneD, NekDouble>(phystot, 0.0);
297 }
298
299 bool waveSpace = m_fields[0]->GetWaveSpace();
300 m_fields[0]->SetWaveSpace(false);
301
302 // Calculate derivatives of x transformation --> m_GeometricInfo 0-1
304 m_GeometricInfo[0]);
306 m_GeometricInfo[1]);
307 // m_GeometricInfo[2] = fz^2
308 Vmath::Vmul(phystot, m_GeometricInfo[0], 1, m_GeometricInfo[0], 1,
309 m_GeometricInfo[2], 1);
310
311 // Calculate derivatives of transformation -> m_GeometricInfo 3-4
313 m_GeometricInfo[3]);
315 m_GeometricInfo[4]);
316 // m_GeometricInfo[5] = gz^2
317 Vmath::Vmul(phystot, m_GeometricInfo[3], 1, m_GeometricInfo[3], 1,
318 m_GeometricInfo[5], 1);
319
320 // m_GeometricInfo[6] = gz*fz
321 Vmath::Vmul(phystot, m_GeometricInfo[0], 1, m_GeometricInfo[3], 1,
322 m_GeometricInfo[6], 1);
323
324 m_fields[0]->SetWaveSpace(waveSpace);
325}
326
327} // 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_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:62
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:50
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: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 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