Nektar++
MappingTranslation.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: MappingTranslation.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: Trivial mapping for translation transformation
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <boost/core/ignore_unused.hpp>
36 
38 #include <MultiRegions/ExpList.h>
39 
40 namespace Nektar
41 {
42 namespace GlobalMapping
43 {
44 
47  "Translation", MappingTranslation::create,
48  "Translation mapping (X_i = x_i + constant)");
49 
50 /**
51  * @class MappingTranslation
52  * This class implements a trivial mapping defined by
53  * \f[ \bar{x} = x + c_1 \f]
54  * \f[ \bar{y} = y + c_2 \f]
55  * \f[ \bar{z} = z + c_3 \f]
56  * where \f$c_i\f$ are constants, \f$(\bar{x},\bar{y},\bar{z})\f$ are the
57  * Cartesian (physical) coordinates and \f$(x,y,z)\f$ are the transformed
58  * (computational) coordinates.
59  */
63  : Mapping(pSession, pFields)
64 {
65 }
66 
67 /**
68  *
69  */
72  const TiXmlElement *pMapping)
73 {
74  m_constantJacobian = true;
75  // When there is no Mapping object defined, use the identity
76  // transformation as a default
77  if (m_session->DefinesElement("Nektar/Mapping"))
78  {
79  Mapping::v_InitObject(pFields, pMapping);
80  }
81  else
82  {
83  int phystot = pFields[0]->GetTotPoints();
84 
85  m_timeDependent = false;
86 
89  for (int i = 0; i < 3; i++)
90  {
91  m_coords[i] = Array<OneD, NekDouble>(phystot);
92  m_coordsVel[i] = Array<OneD, NekDouble>(phystot, 0.0);
93  }
94 
95  m_fields[0]->GetCoords(m_coords[0], m_coords[1], m_coords[2]);
96 
97  // Initialise workspace variables
99  for (int i = 0; i < m_nConvectiveFields; i++)
100  {
101  m_tmp[i] = Array<OneD, NekDouble>(phystot, 0.0);
102  }
103  }
104 }
105 
107  const Array<OneD, Array<OneD, NekDouble>> &inarray,
108  Array<OneD, Array<OneD, NekDouble>> &outarray)
109 {
110  int physTot = m_fields[0]->GetTotPoints();
111 
112  for (int i = 0; i < m_nConvectiveFields; ++i)
113  {
114  Vmath::Vcopy(physTot, inarray[i], 1, outarray[i], 1);
115  }
116 }
117 
119  const Array<OneD, Array<OneD, NekDouble>> &inarray,
120  Array<OneD, Array<OneD, NekDouble>> &outarray)
121 {
122  int physTot = m_fields[0]->GetTotPoints();
123 
124  for (int i = 0; i < m_nConvectiveFields; ++i)
125  {
126  Vmath::Vcopy(physTot, inarray[i], 1, outarray[i], 1);
127  }
128 }
129 
131  const Array<OneD, Array<OneD, NekDouble>> &inarray,
132  Array<OneD, Array<OneD, NekDouble>> &outarray)
133 {
134  int physTot = m_fields[0]->GetTotPoints();
135 
136  for (int i = 0; i < m_nConvectiveFields; ++i)
137  {
138  Vmath::Vcopy(physTot, inarray[i], 1, outarray[i], 1);
139  }
140 }
141 
143  const Array<OneD, Array<OneD, NekDouble>> &inarray,
144  Array<OneD, Array<OneD, NekDouble>> &outarray)
145 {
146  int physTot = m_fields[0]->GetTotPoints();
147 
148  for (int i = 0; i < m_nConvectiveFields; ++i)
149  {
150  Vmath::Vcopy(physTot, inarray[i], 1, outarray[i], 1);
151  }
152 }
153 
155 {
156  int physTot = m_fields[0]->GetTotPoints();
157  Vmath::Fill(physTot, 1.0, outarray, 1);
158 }
159 
161  const Array<OneD, Array<OneD, NekDouble>> &inarray,
162  Array<OneD, NekDouble> &outarray)
163 {
164  boost::ignore_unused(inarray);
165 
166  int physTot = m_fields[0]->GetTotPoints();
167 
168  Vmath::Zero(physTot, outarray, 1);
169 }
170 
172  Array<OneD, Array<OneD, NekDouble>> &outarray)
173 {
174  int physTot = m_fields[0]->GetTotPoints();
175  int nvel = m_nConvectiveFields;
176 
177  for (int i = 0; i < nvel * nvel; i++)
178  {
179  outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
180  }
181  // Fill diagonal with 1.0
182  for (int i = 0; i < nvel; i++)
183  {
184  Vmath::Sadd(physTot, 1.0, outarray[i + nvel * i], 1,
185  outarray[i + nvel * i], 1);
186  }
187 }
188 
190  Array<OneD, Array<OneD, NekDouble>> &outarray)
191 {
192  int physTot = m_fields[0]->GetTotPoints();
193  int nvel = m_nConvectiveFields;
194 
195  for (int i = 0; i < nvel * nvel; i++)
196  {
197  outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
198  }
199  // Fill diagonal with 1.0
200  for (int i = 0; i < nvel; i++)
201  {
202  Vmath::Sadd(physTot, 1.0, outarray[i + nvel * i], 1,
203  outarray[i + nvel * i], 1);
204  }
205 }
206 
208  const Array<OneD, Array<OneD, NekDouble>> &inarray,
209  Array<OneD, Array<OneD, NekDouble>> &outarray)
210 {
211  int physTot = m_fields[0]->GetTotPoints();
212  int nvel = m_nConvectiveFields;
213 
214  for (int i = 0; i < nvel; i++)
215  {
216  outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
217  }
218  // Copy
219  for (int i = 0; i < nvel; i++)
220  {
221  Vmath::Vcopy(physTot, inarray[i], 1, outarray[i], 1);
222  }
223 }
224 
226  const Array<OneD, Array<OneD, NekDouble>> &inarray,
227  Array<OneD, Array<OneD, NekDouble>> &outarray)
228 {
229  int physTot = m_fields[0]->GetTotPoints();
230  int nvel = m_nConvectiveFields;
231 
232  for (int i = 0; i < nvel; i++)
233  {
234  outarray[i] = Array<OneD, NekDouble>(physTot, 0.0);
235  }
236  // Copy
237  for (int i = 0; i < nvel; i++)
238  {
239  Vmath::Vcopy(physTot, inarray[i], 1, outarray[i], 1);
240  }
241 }
242 
244  const Array<OneD, Array<OneD, NekDouble>> &inarray,
245  Array<OneD, Array<OneD, NekDouble>> &outarray)
246 {
247  boost::ignore_unused(inarray);
248 
249  int physTot = m_fields[0]->GetTotPoints();
250  int nvel = m_nConvectiveFields;
251 
252  for (int i = 0; i < nvel; i++)
253  {
254  for (int j = 0; j < nvel; j++)
255  {
256  outarray[i * nvel + j] = Array<OneD, NekDouble>(physTot, 0.0);
257  }
258  }
259 }
260 
262  const Array<OneD, Array<OneD, NekDouble>> &inarray,
263  Array<OneD, Array<OneD, NekDouble>> &outarray)
264 {
265  boost::ignore_unused(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 
280 {
281 }
282 
283 } // namespace GlobalMapping
284 } // namespace Nektar
Base class for mapping to be applied to the coordinate system.
Definition: Mapping.h:69
int m_nConvectiveFields
Number of velocity components.
Definition: Mapping.h:414
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Mapping.h:402
Array< OneD, Array< OneD, NekDouble > > m_coords
Array with the Cartesian coordinates.
Definition: Mapping.h:408
Array< OneD, Array< OneD, NekDouble > > m_coordsVel
Array with the velocity of the coordinates.
Definition: Mapping.h:410
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Definition: Mapping.h:406
virtual GLOBAL_MAPPING_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping)
Definition: Mapping.cpp:101
Array< OneD, Array< OneD, NekDouble > > m_tmp
Definition: Mapping.h:437
bool m_constantJacobian
Flag defining if the Jacobian is constant.
Definition: Mapping.h:423
bool m_timeDependent
Flag defining if the Mapping is time-dependent.
Definition: Mapping.h:425
virtual GLOBAL_MAPPING_EXPORT void v_DotGradJacobian(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, NekDouble > &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_ContravarFromCartesian(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_UpdateGeomInfo() override
virtual GLOBAL_MAPPING_EXPORT void v_CovarToCartesian(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_CovarFromCartesian(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_GetMetricTensor(Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pMapping) override
virtual GLOBAL_MAPPING_EXPORT void v_ApplyChristoffelCovar(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_RaiseIndex(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_GetJacobian(Array< OneD, NekDouble > &outarray) override
MappingTranslation(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
virtual GLOBAL_MAPPING_EXPORT void v_ContravarToCartesian(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_ApplyChristoffelContravar(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_GetInvMetricTensor(Array< OneD, Array< OneD, NekDouble >> &outarray) override
virtual GLOBAL_MAPPING_EXPORT void v_LowerIndex(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray) override
static std::string className
Name of the class.
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.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
MappingFactory & GetMappingFactory()
Declaration of the mapping factory singleton.
Definition: Mapping.cpp:53
std::shared_ptr< SessionReader > SessionReaderSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:492
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:45
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add scalar y = alpha + x.
Definition: Vmath.cpp:384
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255