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
39{
40
41std::string MappingGeneral::className =
43 "General", MappingGeneral::create,
44 "X = X(x,y,z), Y = Y(x,y,z), Z=Z(x,y,z)");
45
46/**
47 * @class MappingGeneral
48 * This class implements the most general mapping, defined by the transformation
49 * \f[ \bar{x} = \bar{x}(x,y,z) \f]
50 * \f[ \bar{y} = \bar{y}(x,y,z) \f]
51 * \f[ \bar{z} = \bar{z}(x,y,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 = false;
70
72 "General Mapping needs at least 2 velocity components.");
73}
74
76 const Array<OneD, Array<OneD, NekDouble>> &inarray,
78{
79 int physTot = m_fields[0]->GetTotPoints();
80 int nvel = m_nConvectiveFields;
81
82 for (int i = 0; i < nvel; i++)
83 {
84 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
85 for (int j = 0; j < nvel; j++)
86 {
87 Vmath::Vvtvp(physTot, inarray[j], 1, m_deriv[i * nvel + j], 1,
88 outarray[i], 1, outarray[i], 1);
89 }
90 }
91}
92
94 const Array<OneD, Array<OneD, NekDouble>> &inarray,
96{
97 int physTot = m_fields[0]->GetTotPoints();
98 int nvel = m_nConvectiveFields;
99
100 for (int i = 0; i < nvel; i++)
101 {
102 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
103 for (int j = 0; j < nvel; j++)
104 {
105 Vmath::Vvtvp(physTot, inarray[j], 1, m_invDeriv[i * nvel + j], 1,
106 outarray[i], 1, outarray[i], 1);
107 }
108 }
109}
110
112 const Array<OneD, Array<OneD, NekDouble>> &inarray,
114{
115 int physTot = m_fields[0]->GetTotPoints();
116 int nvel = m_nConvectiveFields;
117
118 for (int i = 0; i < nvel; i++)
119 {
120 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
121 for (int j = 0; j < nvel; j++)
122 {
123 Vmath::Vvtvp(physTot, inarray[j], 1, m_invDeriv[j * nvel + i], 1,
124 outarray[i], 1, outarray[i], 1);
125 }
126 }
127}
128
130 const Array<OneD, Array<OneD, NekDouble>> &inarray,
132{
133 int physTot = m_fields[0]->GetTotPoints();
134 int nvel = m_nConvectiveFields;
135
136 for (int i = 0; i < nvel; i++)
137 {
138 outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
139 for (int j = 0; j < nvel; j++)
140 {
141 Vmath::Vvtvp(physTot, inarray[j], 1, m_deriv[j * nvel + i], 1,
142 outarray[i], 1, outarray[i], 1);
143 }
144 }
145}
146
148{
149 int physTot = m_fields[0]->GetTotPoints();
150 Vmath::Vcopy(physTot, m_jac, 1, outarray, 1);
151}
152
155{
156 int physTot = m_fields[0]->GetTotPoints();
157 int nvel = m_nConvectiveFields;
158
159 for (int i = 0; i < nvel; i++)
160 {
161 for (int j = 0; j < nvel; j++)
162 {
163 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
164 Vmath::Vcopy(physTot, m_metricTensor[i * nvel + j], 1,
165 outarray[i * nvel + j], 1);
166 }
167 }
168}
169
172{
173 int physTot = m_fields[0]->GetTotPoints();
174 int nvel = m_nConvectiveFields;
175
176 for (int i = 0; i < nvel; i++)
177 {
178 for (int j = 0; j < nvel; j++)
179 {
180 outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
181 Vmath::Vcopy(physTot, m_invMetricTensor[i * nvel + j], 1,
182 outarray[i * nvel + j], 1);
183 }
184 }
185}
186
188 const Array<OneD, Array<OneD, NekDouble>> &inarray,
190{
191 int physTot = m_fields[0]->GetTotPoints();
192 int nvel = m_nConvectiveFields;
193
194 // Calculate {i,jk} u^j
195 for (int i = 0; i < nvel; i++)
196 {
197 for (int k = 0; k < nvel; k++)
198 {
199 outarray[i * nvel + k] = Array<OneD, NekDouble>(physTot, 0.0);
200 for (int j = 0; j < nvel; j++)
201 {
202 Vmath::Vvtvp(physTot, inarray[j], 1,
203 m_Christoffel[i * nvel * nvel + j * nvel + k], 1,
204 outarray[i * nvel + k], 1, outarray[i * nvel + k],
205 1);
206 }
207 }
208 }
209}
210
212 const Array<OneD, Array<OneD, NekDouble>> &inarray,
214{
215 int physTot = m_fields[0]->GetTotPoints();
216 int nvel = m_nConvectiveFields;
217
218 // Calculate {i,jk} u_i
219 for (int j = 0; j < nvel; j++)
220 {
221 for (int k = 0; k < nvel; k++)
222 {
223 outarray[j * nvel + k] = Array<OneD, NekDouble>(physTot, 0.0);
224 for (int i = 0; i < nvel; i++)
225 {
226 Vmath::Vvtvp(physTot, inarray[i], 1,
227 m_Christoffel[i * nvel * nvel + j * nvel + k], 1,
228 outarray[j * nvel + k], 1, outarray[j * nvel + k],
229 1);
230 }
231 }
232 }
233}
234
236{
239}
240
242{
243 int physTot = m_fields[0]->GetTotPoints();
244 int nvel = m_nConvectiveFields;
245
246 // Set wavespace to false and store current value
247 bool wavespace = m_fields[0]->GetWaveSpace();
248 m_fields[0]->SetWaveSpace(false);
249
250 // Allocate memory
255 for (int i = 0; i < m_metricTensor.size(); i++)
256 {
257 m_metricTensor[i] = Array<OneD, NekDouble>(physTot, 0.0);
258 m_invMetricTensor[i] = Array<OneD, NekDouble>(physTot, 0.0);
259 m_deriv[i] = Array<OneD, NekDouble>(physTot, 0.0);
260 m_invDeriv[i] = Array<OneD, NekDouble>(physTot, 0.0);
261 }
262 m_jac = Array<OneD, NekDouble>(physTot, 0.0);
263
264 // First, calculate derivatives of the mapping -> dX^i/dx^j = c^i_j
265 for (int i = 0; i < nvel; i++)
266 {
267 for (int j = 0; j < nvel; j++)
268 {
270 m_coords[i], m_deriv[i * nvel + j]);
271 }
272 }
273 // In Homogeneous case, m_deriv(2,2) needs to be set to 1
274 // because differentiation in wavespace is not valid for non-periodic field
275 if (m_fields[0]->GetExpType() == MultiRegions::e3DH1D)
276 {
277 Vmath::Fill(physTot, 1.0, m_deriv[2 * nvel + 2], 1);
278 }
279
280 // Now calculate the metric tensor --> g_ij = sum_k { c^k_i c^k_j }
281 for (int i = 0; i < nvel; i++)
282 {
283 for (int j = 0; j < nvel; j++)
284 {
285 for (int k = 0; k < nvel; k++)
286 {
287 Vmath::Vvtvp(physTot, m_deriv[k * nvel + i], 1,
288 m_deriv[k * nvel + j], 1,
289 m_metricTensor[i * nvel + j], 1,
290 m_metricTensor[i * nvel + j], 1);
291 }
292 }
293 }
294
295 // Put the adjoint of g in m_invMetricTensor
296 switch (nvel)
297 {
298 case 1:
299 Vmath::Fill(physTot, 1.0, m_invMetricTensor[0], 1);
300 break;
301 case 2:
302 Vmath::Vcopy(physTot, m_metricTensor[1 * nvel + 1], 1,
303 m_invMetricTensor[0 * nvel + 0], 1);
304 Vmath::Smul(physTot, -1.0, m_metricTensor[0 * nvel + 1], 1,
305 m_invMetricTensor[1 * nvel + 0], 1);
306 Vmath::Smul(physTot, -1.0, m_metricTensor[1 * nvel + 0], 1,
307 m_invMetricTensor[0 * nvel + 1], 1);
308 Vmath::Vcopy(physTot, m_metricTensor[0 * nvel + 0], 1,
309 m_invMetricTensor[1 * nvel + 1], 1);
310 break;
311 case 3:
312 {
313 int a, b, c, d, e, i, j;
314
315 // Compute g^{ij} by computing Cofactors(g_ij)^T
316 for (i = 0; i < nvel; ++i)
317 {
318 for (j = 0; j < nvel; ++j)
319 {
320 a = ((i + 1) % nvel) * nvel + ((j + 1) % nvel);
321 b = ((i + 1) % nvel) * nvel + ((j + 2) % nvel);
322 c = ((i + 2) % nvel) * nvel + ((j + 1) % nvel);
323 d = ((i + 2) % nvel) * nvel + ((j + 2) % nvel);
324 e = i * nvel + j;
325 // a*d - b*c
326 Vmath::Vmul(physTot, m_metricTensor[b], 1,
327 m_metricTensor[c], 1, m_invMetricTensor[e], 1);
328 Vmath::Vvtvm(physTot, m_metricTensor[a], 1,
330 m_invMetricTensor[e], 1);
331 }
332 }
333 break;
334 }
335 }
336
337 // Compute g = det(g_{ij}) (= Jacobian squared) and store
338 // temporarily in m_jac.
339 for (int i = 0; i < nvel; ++i)
340 {
341 Vmath::Vvtvp(physTot, m_metricTensor[i], 1, m_invMetricTensor[i * nvel],
342 1, m_jac, 1, m_jac, 1);
343 }
344
345 // Calculate g^ij (the inverse of g_ij) by dividing by jac
346 for (int i = 0; i < nvel * nvel; ++i)
347 {
348 Vmath::Vdiv(physTot, m_invMetricTensor[i], 1, m_jac, 1,
349 m_invMetricTensor[i], 1);
350 }
351
352 // Compute the Jacobian = sqrt(g)
353 Vmath::Vsqrt(physTot, m_jac, 1, m_jac, 1);
354
355 // Calculate the derivatives of the inverse transformation
356 // c'^j_i = dx^j/dX^i = sum_k {g^jk c^i_k}
357 for (int i = 0; i < nvel; ++i)
358 {
359 for (int j = 0; j < nvel; ++j)
360 {
361 for (int k = 0; k < nvel; ++k)
362 {
363 Vmath::Vvtvp(physTot, m_deriv[i * nvel + k], 1,
364 m_invMetricTensor[j * nvel + k], 1,
365 m_invDeriv[i * nvel + j], 1,
366 m_invDeriv[i * nvel + j], 1);
367 }
368 }
369 }
370
371 // Restore value of wavespace
372 m_fields[0]->SetWaveSpace(wavespace);
373}
374
376{
377 int physTot = m_fields[0]->GetTotPoints();
378 int nvel = m_nConvectiveFields;
379
380 Array<OneD, Array<OneD, NekDouble>> gradG(nvel * nvel * nvel);
381 Array<OneD, Array<OneD, NekDouble>> tmp(nvel * nvel * nvel);
383 // Allocate memory
384 for (int i = 0; i < gradG.size(); i++)
385 {
386 gradG[i] = Array<OneD, NekDouble>(physTot, 0.0);
387 tmp[i] = Array<OneD, NekDouble>(physTot, 0.0);
388 m_Christoffel[i] = Array<OneD, NekDouble>(physTot, 0.0);
389 }
390
391 // Set wavespace to false and store current value
392 bool waveSpace = m_fields[0]->GetWaveSpace();
393 m_fields[0]->SetWaveSpace(false);
394
395 // Calculate gradients of g_ij
396 for (int i = 0; i < nvel; i++)
397 {
398 for (int j = 0; j < nvel; j++)
399 {
400 for (int k = 0; k < nvel; k++)
401 {
403 m_metricTensor[i * nvel + j],
404 gradG[i * nvel * nvel + j * nvel + k]);
405 }
406 }
407 }
408
409 // Calculate tmp[p,j,k] = 1/2( gradG[pj,k]+ gradG[pk,j]-gradG[jk,p])
410 for (int p = 0; p < nvel; p++)
411 {
412 for (int j = 0; j < nvel; j++)
413 {
414 for (int k = 0; k < nvel; k++)
415 {
416 Vmath::Vadd(physTot, gradG[p * nvel * nvel + j * nvel + k], 1,
417 gradG[p * nvel * nvel + k * nvel + j], 1,
418 tmp[p * nvel * nvel + j * nvel + k], 1);
419 Vmath::Vsub(physTot, tmp[p * nvel * nvel + j * nvel + k], 1,
420 gradG[j * nvel * nvel + k * nvel + p], 1,
421 tmp[p * nvel * nvel + j * nvel + k], 1);
422 Vmath::Smul(physTot, 0.5, tmp[p * nvel * nvel + j * nvel + k],
423 1, tmp[p * nvel * nvel + j * nvel + k], 1);
424 }
425 }
426 }
427
428 // Calculate Christoffel symbols = g^ip tmp[p,j,k]
429 for (int i = 0; i < nvel; i++)
430 {
431 for (int j = 0; j < nvel; j++)
432 {
433 for (int k = 0; k < nvel; k++)
434 {
435 for (int p = 0; p < nvel; p++)
436 {
438 physTot, m_invMetricTensor[i * nvel + p], 1,
439 tmp[p * nvel * nvel + j * nvel + k], 1,
440 m_Christoffel[i * nvel * nvel + j * nvel + k], 1,
441 m_Christoffel[i * nvel * nvel + j * nvel + k], 1);
442 }
443 }
444 }
445 }
446 // Restore wavespace
447 m_fields[0]->SetWaveSpace(waveSpace);
448}
449
450} // 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:73
int m_nConvectiveFields
Number of velocity components.
Definition: Mapping.h:418
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
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
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