Nektar++
MappingGeneral.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: MappingGeneral.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,y), Y = Y(x,y)
32//
33///////////////////////////////////////////////////////////////////////////////
34
37#include <iomanip>
38
40{
41
42std::string MappingGeneral::className =
44 "General", MappingGeneral::create,
45 "X = X(x,y,z), Y = Y(x,y,z), Z=Z(x,y,z)");
46
47/**
48 * @class MappingGeneral
49 * This class implements the most general mapping, defined by the transformation
50 * \f[ \bar{x} = \bar{x}(x,y,z) \f]
51 * \f[ \bar{y} = \bar{y}(x,y,z) \f]
52 * \f[ \bar{z} = \bar{z}(x,y,z) \f]
53 * where \f$(\bar{x},\bar{y},\bar{z})\f$ are the Cartesian (physical)
54 * coordinates and \f$(x,y,z)\f$ are the transformed (computational)
55 * coordinates.
56 */
60 : Mapping(pSession, pFields)
61{
62}
63
64/**
65 *
66 */
69 const TiXmlElement *pMapping)
70{
71 Mapping::v_InitObject(pFields, pMapping);
72
73 m_constantJacobian = false;
74
76 "General Mapping needs at least 2 velocity components.");
77}
78
80 const Array<OneD, Array<OneD, NekDouble>> &inarray,
82{
83 int physTot = m_fields[0]->GetTotPoints();
84 int nvel = m_nConvectiveFields;
85
86 for (int i = 0; i < nvel; i++)
87 {
88 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
89 for (int j = 0; j < nvel; j++)
90 {
91 Vmath::Vvtvp(physTot, inarray[j], 1, m_deriv[i * nvel + j], 1,
92 outarray[i], 1, outarray[i], 1);
93 }
94 }
95}
96
98 const Array<OneD, Array<OneD, NekDouble>> &inarray,
100{
101 int physTot = m_fields[0]->GetTotPoints();
102 int nvel = m_nConvectiveFields;
103
104 for (int i = 0; i < nvel; i++)
105 {
106 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
107 for (int j = 0; j < nvel; j++)
108 {
109 Vmath::Vvtvp(physTot, inarray[j], 1, m_invDeriv[i * nvel + j], 1,
110 outarray[i], 1, outarray[i], 1);
111 }
112 }
113}
114
116 const Array<OneD, Array<OneD, NekDouble>> &inarray,
118{
119 int physTot = m_fields[0]->GetTotPoints();
120 int nvel = m_nConvectiveFields;
121
122 for (int i = 0; i < nvel; i++)
123 {
124 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
125 for (int j = 0; j < nvel; j++)
126 {
127 Vmath::Vvtvp(physTot, inarray[j], 1, m_invDeriv[j * nvel + i], 1,
128 outarray[i], 1, outarray[i], 1);
129 }
130 }
131}
132
134 const Array<OneD, Array<OneD, NekDouble>> &inarray,
136{
137 int physTot = m_fields[0]->GetTotPoints();
138 int nvel = m_nConvectiveFields;
139
140 for (int i = 0; i < nvel; i++)
141 {
142 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
143 for (int j = 0; j < nvel; j++)
144 {
145 Vmath::Vvtvp(physTot, inarray[j], 1, m_deriv[j * nvel + i], 1,
146 outarray[i], 1, outarray[i], 1);
147 }
148 }
149}
150
152{
153 int physTot = m_fields[0]->GetTotPoints();
154 Vmath::Vcopy(physTot, m_jac, 1, outarray, 1);
155}
156
159{
160 int physTot = m_fields[0]->GetTotPoints();
161 int nvel = m_nConvectiveFields;
162
163 for (int i = 0; i < nvel; i++)
164 {
165 for (int j = 0; j < nvel; j++)
166 {
167 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
168 Vmath::Vcopy(physTot, m_metricTensor[i * nvel + j], 1,
169 outarray[i * nvel + j], 1);
170 }
171 }
172}
173
176{
177 int physTot = m_fields[0]->GetTotPoints();
178 int nvel = m_nConvectiveFields;
179
180 for (int i = 0; i < nvel; i++)
181 {
182 for (int j = 0; j < nvel; j++)
183 {
184 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
185 Vmath::Vcopy(physTot, m_invMetricTensor[i * nvel + j], 1,
186 outarray[i * nvel + j], 1);
187 }
188 }
189}
190
192 const Array<OneD, Array<OneD, NekDouble>> &inarray,
194{
195 int physTot = m_fields[0]->GetTotPoints();
196 int nvel = m_nConvectiveFields;
197
198 // Calculate {i,jk} u^j
199 for (int i = 0; i < nvel; i++)
200 {
201 for (int k = 0; k < nvel; k++)
202 {
203 outarray[i * nvel + k] = Array<OneD, NekDouble>(physTot, 0.0);
204 for (int j = 0; j < nvel; j++)
205 {
206 Vmath::Vvtvp(physTot, inarray[j], 1,
207 m_Christoffel[i * nvel * nvel + j * nvel + k], 1,
208 outarray[i * nvel + k], 1, outarray[i * nvel + k],
209 1);
210 }
211 }
212 }
213}
214
216 const Array<OneD, Array<OneD, NekDouble>> &inarray,
218{
219 int physTot = m_fields[0]->GetTotPoints();
220 int nvel = m_nConvectiveFields;
221
222 // Calculate {i,jk} u_i
223 for (int j = 0; j < nvel; j++)
224 {
225 for (int k = 0; k < nvel; k++)
226 {
227 outarray[j * nvel + k] = Array<OneD, NekDouble>(physTot, 0.0);
228 for (int i = 0; i < nvel; i++)
229 {
230 Vmath::Vvtvp(physTot, inarray[i], 1,
231 m_Christoffel[i * nvel * nvel + j * nvel + k], 1,
232 outarray[j * nvel + k], 1, outarray[j * nvel + k],
233 1);
234 }
235 }
236 }
237}
238
240{
243}
244
246{
247 int physTot = m_fields[0]->GetTotPoints();
248 int nvel = m_nConvectiveFields;
249
250 // Set wavespace to false and store current value
251 bool wavespace = m_fields[0]->GetWaveSpace();
252 m_fields[0]->SetWaveSpace(false);
253
254 // Allocate memory
259 for (int i = 0; i < m_metricTensor.size(); i++)
260 {
261 m_metricTensor[i] = Array<OneD, NekDouble>(physTot, 0.0);
262 m_invMetricTensor[i] = Array<OneD, NekDouble>(physTot, 0.0);
263 m_deriv[i] = Array<OneD, NekDouble>(physTot, 0.0);
264 m_invDeriv[i] = Array<OneD, NekDouble>(physTot, 0.0);
265 }
266 m_jac = Array<OneD, NekDouble>(physTot, 0.0);
267
268 // First, calculate derivatives of the mapping -> dX^i/dx^j = c^i_j
269 for (int i = 0; i < nvel; i++)
270 {
271 for (int j = 0; j < nvel; j++)
272 {
274 m_coords[i], m_deriv[i * nvel + j]);
275 }
276 }
277 // In Homogeneous case, m_deriv(2,2) needs to be set to 1
278 // because differentiation in wavespace is not valid for non-periodic field
279 if (m_fields[0]->GetExpType() == MultiRegions::e3DH1D)
280 {
281 Vmath::Fill(physTot, 1.0, m_deriv[2 * nvel + 2], 1);
282 }
283
284 // Now calculate the metric tensor --> g_ij = sum_k { c^k_i c^k_j }
285 for (int i = 0; i < nvel; i++)
286 {
287 for (int j = 0; j < nvel; j++)
288 {
289 for (int k = 0; k < nvel; k++)
290 {
291 Vmath::Vvtvp(physTot, m_deriv[k * nvel + i], 1,
292 m_deriv[k * nvel + j], 1,
293 m_metricTensor[i * nvel + j], 1,
294 m_metricTensor[i * nvel + j], 1);
295 }
296 }
297 }
298
299 // Put the adjoint of g in m_invMetricTensor
300 switch (nvel)
301 {
302 case 1:
303 Vmath::Fill(physTot, 1.0, m_invMetricTensor[0], 1);
304 break;
305 case 2:
306 Vmath::Vcopy(physTot, m_metricTensor[1 * nvel + 1], 1,
307 m_invMetricTensor[0 * nvel + 0], 1);
308 Vmath::Smul(physTot, -1.0, m_metricTensor[0 * nvel + 1], 1,
309 m_invMetricTensor[1 * nvel + 0], 1);
310 Vmath::Smul(physTot, -1.0, m_metricTensor[1 * nvel + 0], 1,
311 m_invMetricTensor[0 * nvel + 1], 1);
312 Vmath::Vcopy(physTot, m_metricTensor[0 * nvel + 0], 1,
313 m_invMetricTensor[1 * nvel + 1], 1);
314 break;
315 case 3:
316 {
317 int a, b, c, d, e, i, j;
318
319 // Compute g^{ij} by computing Cofactors(g_ij)^T
320 for (i = 0; i < nvel; ++i)
321 {
322 for (j = 0; j < nvel; ++j)
323 {
324 a = ((i + 1) % nvel) * nvel + ((j + 1) % nvel);
325 b = ((i + 1) % nvel) * nvel + ((j + 2) % nvel);
326 c = ((i + 2) % nvel) * nvel + ((j + 1) % nvel);
327 d = ((i + 2) % nvel) * nvel + ((j + 2) % nvel);
328 e = i * nvel + j;
329 // a*d - b*c
330 Vmath::Vmul(physTot, m_metricTensor[b], 1,
331 m_metricTensor[c], 1, m_invMetricTensor[e], 1);
332 Vmath::Vvtvm(physTot, m_metricTensor[a], 1,
334 m_invMetricTensor[e], 1);
335 }
336 }
337 break;
338 }
339 }
340
341 // Compute g = det(g_{ij}) (= Jacobian squared) and store
342 // temporarily in m_jac.
343 for (int i = 0; i < nvel; ++i)
344 {
345 Vmath::Vvtvp(physTot, m_metricTensor[i], 1, m_invMetricTensor[i * nvel],
346 1, m_jac, 1, m_jac, 1);
347 }
348
349 // Calculate g^ij (the inverse of g_ij) by dividing by jac
350 for (int i = 0; i < nvel * nvel; ++i)
351 {
352 Vmath::Vdiv(physTot, m_invMetricTensor[i], 1, m_jac, 1,
353 m_invMetricTensor[i], 1);
354 }
355
356 // Compute the Jacobian = sqrt(g)
357 Vmath::Vsqrt(physTot, m_jac, 1, m_jac, 1);
358
359 // Calculate the derivatives of the inverse transformation
360 // c'^j_i = dx^j/dX^i = sum_k {g^jk c^i_k}
361 for (int i = 0; i < nvel; ++i)
362 {
363 for (int j = 0; j < nvel; ++j)
364 {
365 for (int k = 0; k < nvel; ++k)
366 {
367 Vmath::Vvtvp(physTot, m_deriv[i * nvel + k], 1,
368 m_invMetricTensor[j * nvel + k], 1,
369 m_invDeriv[i * nvel + j], 1,
370 m_invDeriv[i * nvel + j], 1);
371 }
372 }
373 }
374
375 // Restore value of wavespace
376 m_fields[0]->SetWaveSpace(wavespace);
377}
378
380{
381 int physTot = m_fields[0]->GetTotPoints();
382 int nvel = m_nConvectiveFields;
383
384 Array<OneD, Array<OneD, NekDouble>> gradG(nvel * nvel * nvel);
385 Array<OneD, Array<OneD, NekDouble>> tmp(nvel * nvel * nvel);
387 // Allocate memory
388 for (int i = 0; i < gradG.size(); i++)
389 {
390 gradG[i] = Array<OneD, NekDouble>(physTot, 0.0);
391 tmp[i] = Array<OneD, NekDouble>(physTot, 0.0);
392 m_Christoffel[i] = Array<OneD, NekDouble>(physTot, 0.0);
393 }
394
395 // Set wavespace to false and store current value
396 bool waveSpace = m_fields[0]->GetWaveSpace();
397 m_fields[0]->SetWaveSpace(false);
398
399 // Calculate gradients of g_ij
400 for (int i = 0; i < nvel; i++)
401 {
402 for (int j = 0; j < nvel; j++)
403 {
404 for (int k = 0; k < nvel; k++)
405 {
407 m_metricTensor[i * nvel + j],
408 gradG[i * nvel * nvel + j * nvel + k]);
409 }
410 }
411 }
412
413 // Calculate tmp[p,j,k] = 1/2( gradG[pj,k]+ gradG[pk,j]-gradG[jk,p])
414 for (int p = 0; p < nvel; p++)
415 {
416 for (int j = 0; j < nvel; j++)
417 {
418 for (int k = 0; k < nvel; k++)
419 {
420 Vmath::Vadd(physTot, gradG[p * nvel * nvel + j * nvel + k], 1,
421 gradG[p * nvel * nvel + k * nvel + j], 1,
422 tmp[p * nvel * nvel + j * nvel + k], 1);
423 Vmath::Vsub(physTot, tmp[p * nvel * nvel + j * nvel + k], 1,
424 gradG[j * nvel * nvel + k * nvel + p], 1,
425 tmp[p * nvel * nvel + j * nvel + k], 1);
426 Vmath::Smul(physTot, 0.5, tmp[p * nvel * nvel + j * nvel + k],
427 1, tmp[p * nvel * nvel + j * nvel + k], 1);
428 }
429 }
430 }
431
432 // Calculate Christoffel symbols = g^ip tmp[p,j,k]
433 for (int i = 0; i < nvel; i++)
434 {
435 for (int j = 0; j < nvel; j++)
436 {
437 for (int k = 0; k < nvel; k++)
438 {
439 for (int p = 0; p < nvel; p++)
440 {
442 physTot, m_invMetricTensor[i * nvel + p], 1,
443 tmp[p * nvel * nvel + j * nvel + k], 1,
444 m_Christoffel[i * nvel * nvel + j * nvel + k], 1,
445 m_Christoffel[i * nvel * nvel + j * nvel + k], 1);
446 }
447 }
448 }
449 }
450 // Restore wavespace
451 m_fields[0]->SetWaveSpace(waveSpace);
452}
453
454} // namespace Nektar::GlobalMapping
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
static std::string className
Name of the class.
GLOBAL_MAPPING_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping) 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_CovarToCartesian(const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray) override
Array< OneD, Array< OneD, NekDouble > > m_invDeriv
Array< OneD, Array< OneD, NekDouble > > m_metricTensor
GLOBAL_MAPPING_EXPORT void v_GetJacobian(Array< OneD, NekDouble > &outarray) override
Array< OneD, Array< OneD, NekDouble > > m_deriv
GLOBAL_MAPPING_EXPORT void v_GetMetricTensor(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
Array< OneD, NekDouble > m_jac
Array< OneD, Array< OneD, NekDouble > > m_invMetricTensor
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_CovarFromCartesian(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
Array< OneD, Array< OneD, NekDouble > > m_Christoffel
MappingGeneral(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.
GLOBAL_MAPPING_EXPORT void v_UpdateGeomInfo() override
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_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
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
std::vector< double > d(NPUPPER *NPUPPER)
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
Definition: Vmath.hpp:340
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 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 Vvtvm(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)
vvtvm (vector times vector minus vector): z = w*x - y
Definition: Vmath.hpp:381
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.hpp:100
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 Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.hpp:54
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