Nektar++
Expansion.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File Expansion.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: File for Expansion routines
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <boost/core/ignore_unused.hpp>
36 
38 #include <LocalRegions/Expansion.h>
39 #include <LocalRegions/MatrixKey.h>
40 
41 using namespace std;
42 
43 namespace Nektar
44 {
45  namespace LocalRegions
46  {
47  Expansion::Expansion(SpatialDomains::GeometrySharedPtr pGeom) :
48  m_geom(pGeom),
49  m_metricinfo(m_geom->GetGeomFactors())
50  {
51  if (!m_metricinfo)
52  {
53  return;
54  }
55 
56  if (!m_metricinfo->IsValid())
57  {
58  int nDim = m_base.num_elements();
59  string type = "regular";
60  if (m_metricinfo->GetGtype() == SpatialDomains::eDeformed)
61  {
62  type = "deformed";
63  }
64 
65  stringstream err;
66  err << nDim << "D " << type << " Jacobian not positive "
67  << "(element ID = " << m_geom->GetGlobalID() << ") "
68  << "(first vertex ID = " << m_geom->GetVid(0) << ")";
69  NEKERROR(ErrorUtil::ewarning, err.str());
70  }
71  }
72 
74  StdExpansion(pSrc),
75  m_geom(pSrc.m_geom),
77  {
78 
79  }
80 
82  {
83  }
84 
86  {
87  return v_GetLocMatrix(mkey);
88  }
89 
91  const DNekScalMatSharedPtr &r_bnd,
92  const StdRegions::MatrixType matrixType)
93  {
94  return v_BuildTransformationMatrix(r_bnd,matrixType);
95  }
96 
97 
99  const DNekScalMatSharedPtr &r_bnd)
100  {
101  return v_BuildVertexMatrix(r_bnd);
102  }
103 
104 
106  const NekDouble *data,
107  const std::vector<unsigned int > &nummodes,
108  const int nmodes_offset,
109  NekDouble *coeffs,
110  std::vector<LibUtilities::BasisType> &fromType)
111  {
112  v_ExtractDataToCoeffs(data,nummodes,nmodes_offset,coeffs,fromType);
113  }
114 
116  const int edge,
117  const std::shared_ptr<Expansion> &EdgeExp,
120  Array<OneD, NekDouble> &outarray)
121  {
122  v_AddEdgeNormBoundaryInt(edge, EdgeExp, Fx, Fy, outarray);
123  }
124 
126  const int edge,
127  const std::shared_ptr<Expansion> &EdgeExp,
129  Array<OneD, NekDouble> &outarray)
130  {
131  v_AddEdgeNormBoundaryInt(edge, EdgeExp, Fn, outarray);
132  }
133 
135  const int face,
136  const std::shared_ptr<Expansion> &FaceExp,
138  Array<OneD, NekDouble> &outarray)
139  {
140  v_AddFaceNormBoundaryInt(face, FaceExp, Fn, outarray);
141  }
142 
144  const int dir,
145  const Array<OneD, const NekDouble>& inarray,
147  Array<OneD, Array<OneD, NekDouble> > &coeffs,
148  Array<OneD, NekDouble> &outarray)
149  {
150  v_DGDeriv(dir, inarray, EdgeExp, coeffs, outarray);
151  }
152 
154  const Array<OneD, Array<OneD, NekDouble > > &vec)
155  {
156  return v_VectorFlux(vec);
157  }
158 
160  const StdRegions::ConstFactorMap &factors,
161  const StdRegions::VarCoeffMap &varcoeffs)
162  {
163  MatrixKey mkey(mtype, DetShapeType(), *this, factors, varcoeffs);
164  return GetLocMatrix(mkey);
165  }
166 
168  {
169  return m_geom;
170  }
171 
173  {
174  // Clear metrics
175  m_metrics.clear();
176 
177  // Regenerate geometry factors
178  m_metricinfo = m_geom->GetGeomFactors();
179  }
180 
182  {
183  return m_metricinfo;
184  }
185 
186 
188  {
189  boost::ignore_unused(mkey);
190  NEKERROR(ErrorUtil::efatal, "This function is only valid for LocalRegions");
192  }
193 
195  Array<OneD, NekDouble> &outarray)
196  {
197  const int nqtot = GetTotPoints();
198 
199  if (m_metrics.count(eMetricQuadrature) == 0)
200  {
202  }
203 
204  Vmath::Vmul(nqtot, m_metrics[eMetricQuadrature], 1, inarray, 1, outarray, 1);
205  }
206 
208  {
210  }
211 
213  {
214  unsigned int nqtot = GetTotPoints();
215  SpatialDomains::GeomType type = m_metricinfo->GetGtype();
217  if (type == SpatialDomains::eRegular ||
219  {
221  }
222  else
223  {
225  }
226 
228  m_metrics[eMetricQuadrature]);
229  }
230 
232  Array<OneD, NekDouble> &coords_0,
233  Array<OneD, NekDouble> &coords_1,
234  Array<OneD, NekDouble> &coords_2)
235  {
236  ASSERTL1(m_geom, "m_geom not defined");
237 
238  // get physical points defined in Geom
239  m_geom->FillGeom();
240 
241  const int expDim = m_base.num_elements();
242  int nqGeom = 1;
243  bool doCopy = true;
244 
247 
248  for (int i = 0; i < expDim; ++i)
249  {
250  CBasis[i] = m_geom->GetXmap()->GetBasis(i);
251  nqGeom *= CBasis[i]->GetNumPoints();
252  doCopy = doCopy && m_base[i]->GetBasisKey().SamePoints(
253  CBasis[i]->GetBasisKey());
254  }
255 
256  tmp[0] = coords_0;
257  tmp[1] = coords_1;
258  tmp[2] = coords_2;
259 
260  if (doCopy)
261  {
262  for (int i = 0; i < m_geom->GetCoordim(); ++i)
263  {
264  m_geom->GetXmap()->BwdTrans(m_geom->GetCoeffs(i), tmp[i]);
265  }
266  }
267  else
268  {
269  for (int i = 0; i < m_geom->GetCoordim(); ++i)
270  {
271  Array<OneD, NekDouble> tmpGeom(nqGeom);
272  m_geom->GetXmap()->BwdTrans(m_geom->GetCoeffs(i), tmpGeom);
273 
274  switch (expDim)
275  {
276  case 1:
277  {
279  CBasis[0]->GetPointsKey(), &tmpGeom[0],
280  m_base[0]->GetPointsKey(), &tmp[i][0]);
281  break;
282  }
283  case 2:
284  {
286  CBasis[0]->GetPointsKey(),
287  CBasis[1]->GetPointsKey(),
288  &tmpGeom[0],
289  m_base[0]->GetPointsKey(),
290  m_base[1]->GetPointsKey(),
291  &tmp[i][0]);
292  break;
293  }
294  case 3:
295  {
297  CBasis[0]->GetPointsKey(),
298  CBasis[1]->GetPointsKey(),
299  CBasis[2]->GetPointsKey(),
300  &tmpGeom[0],
301  m_base[0]->GetPointsKey(),
302  m_base[1]->GetPointsKey(),
303  m_base[2]->GetPointsKey(),
304  &tmp[i][0]);
305  break;
306  }
307  }
308  }
309  }
310  }
311 
314  const Array<OneD, const NekDouble> &direction,
316  {
317  int shapedim = dfdir.num_elements();
318  int coordim = GetCoordim();
319  int nqtot = direction.num_elements()/coordim;
320 
321  for(int j = 0; j < shapedim; j++)
322  {
323  dfdir[j] = Array<OneD, NekDouble>(nqtot,0.0);
324  for (int k = 0; k < coordim; k++)
325  {
326  if(m_metricinfo->GetGtype() == SpatialDomains::eDeformed)
327  {
328  Vmath::Vvtvp(nqtot,
329  &df[shapedim*k+j][0], 1,
330  &direction[k*nqtot], 1,
331  &dfdir[j][0], 1,
332  &dfdir[j][0], 1);
333  }
334  else
335  {
336  Vmath::Svtvp(nqtot,
337  df[shapedim*k+j][0],
338  &direction[k*nqtot], 1,
339  &dfdir[j][0], 1,
340  &dfdir[j][0], 1);
341  }
342  }
343  }
344  }
345 
346  // Get Moving frames
348  const int dir,
349  const int shapedim,
350  const StdRegions::VarCoeffMap &varcoeffs)
351  {
352  int coordim = GetCoordim();
353 
354  int nquad0, nquad1, nquad2;
355  int nqtot=1;
356  switch(shapedim)
357  {
358  case 2:
359  {
360  nquad0 = m_base[0]->GetNumPoints();
361  nquad1 = m_base[1]->GetNumPoints();
362  nqtot = nquad0*nquad1;
363  break;
364  }
365  case 3:
366  {
367  nquad0 = m_base[0]->GetNumPoints();
368  nquad1 = m_base[1]->GetNumPoints();
369  nquad2 = m_base[2]->GetNumPoints();
370  nqtot = nquad0 * nquad1 * nquad2;
371  break;
372  }
373  default:
374  break;
375  }
376 
377  StdRegions::VarCoeffType MMFCoeffs[15] =
378  {
394  };
395 
396  Array<OneD, NekDouble> MF(coordim*nqtot);
397  Array<OneD, NekDouble> tmp(nqtot);
398  for (int k = 0; k < coordim; k++)
399  {
400  StdRegions::VarCoeffMap::const_iterator MFdir =
401  varcoeffs.find(MMFCoeffs[5*dir+k]);
402  tmp = MFdir->second;
403 
404  Vmath::Vcopy(nqtot, &tmp[0], 1, &MF[k*nqtot], 1);
405  }
406 
407  return MF;
408  }
409 
410  // Get magnitude of MF
412  const int dir,
413  const StdRegions::VarCoeffMap &varcoeffs)
414  {
415  int indxDiv = 3;
416 
417  StdRegions::VarCoeffType MMFCoeffs[15] =
418  {
434  };
435 
436  StdRegions::VarCoeffMap::const_iterator MFdir =
437  varcoeffs.find(MMFCoeffs[5*dir+indxDiv]);
438  Array<OneD, NekDouble> MFDiv = MFdir->second;
439 
440  return MFDiv;
441  }
442 
443  // Get magnitude of MF
445  const int dir,
446  const StdRegions::VarCoeffMap &varcoeffs)
447  {
448  int indxMag = 4;
449 
450  StdRegions::VarCoeffType MMFCoeffs[15] =
451  {
467  };
468 
469  StdRegions::VarCoeffMap::const_iterator MFdir = varcoeffs.find(MMFCoeffs[5*dir+indxMag]);
470  Array<OneD, NekDouble> MFmag = MFdir->second;
471 
472  return MFmag;
473  }
474 
475 
477  const DNekScalMatSharedPtr &r_bnd,
478  const StdRegions::MatrixType matrixType)
479  {
480  boost::ignore_unused(r_bnd, matrixType);
481  NEKERROR(ErrorUtil::efatal, "This function is only valid for LocalRegions");
482  return NullDNekMatSharedPtr;
483  }
484 
486  const DNekScalMatSharedPtr &r_bnd)
487  {
488  boost::ignore_unused(r_bnd);
489  NEKERROR(ErrorUtil::efatal, "This function is only valid for LocalRegions");
490  return NullDNekMatSharedPtr;
491  }
492 
494  const NekDouble *data,
495  const std::vector<unsigned int > &nummodes,
496  const int nmodes_offset,
497  NekDouble *coeffs,
498  std::vector<LibUtilities::BasisType> &fromType)
499  {
500  boost::ignore_unused(data, nummodes, nmodes_offset,
501  coeffs, fromType);
502  NEKERROR(ErrorUtil::efatal, "This function is only valid for LocalRegions");
503  }
504 
506  const int edge,
507  const std::shared_ptr<Expansion> &EdgeExp,
510  Array<OneD, NekDouble> &outarray)
511  {
512  boost::ignore_unused(edge, EdgeExp, Fx, Fy, outarray);
513  NEKERROR(ErrorUtil::efatal, "This function is only valid for LocalRegions");
514  }
515 
517  const int edge,
518  const std::shared_ptr<Expansion> &EdgeExp,
520  Array<OneD, NekDouble> &outarray)
521  {
522  boost::ignore_unused(edge, EdgeExp, Fn, outarray);
523  NEKERROR(ErrorUtil::efatal, "This function is only valid for LocalRegions");
524  }
525 
527  const int face,
528  const std::shared_ptr<Expansion> &FaceExp,
530  Array<OneD, NekDouble> &outarray)
531  {
532  boost::ignore_unused(face, FaceExp, Fn, outarray);
533  NEKERROR(ErrorUtil::efatal, "This function is only valid for LocalRegions");
534  }
535 
537  const int dir,
538  const Array<OneD, const NekDouble>& inarray,
540  Array<OneD, Array<OneD, NekDouble> > &coeffs,
541  Array<OneD, NekDouble> &outarray)
542  {
543  boost::ignore_unused(dir, inarray, EdgeExp, coeffs, outarray);
544  NEKERROR(ErrorUtil::efatal, "This function is only valid for LocalRegions");
545  }
546 
548  const Array<OneD, Array<OneD, NekDouble > > &vec)
549  {
550  boost::ignore_unused(vec);
551  NEKERROR(ErrorUtil::efatal, "This function is only valid for LocalRegions");
552  return 0.0;
553  }
554  } //end of namespace
555 } //end of namespace
556 
virtual NekDouble v_VectorFlux(const Array< OneD, Array< OneD, NekDouble > > &vec)
Definition: Expansion.cpp:547
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:209
std::vector< PointsKey > PointsKeyVector
Definition: Points.h:246
NekDouble VectorFlux(const Array< OneD, Array< OneD, NekDouble > > &vec)
Definition: Expansion.cpp:153
DNekMatSharedPtr BuildTransformationMatrix(const DNekScalMatSharedPtr &r_bnd, const StdRegions::MatrixType matrixType)
Definition: Expansion.cpp:90
LibUtilities::ShapeType DetShapeType() const
This function returns the shape of the expansion domain.
Definition: StdExpansion.h:469
std::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
void ExtractDataToCoeffs(const NekDouble *data, const std::vector< unsigned int > &nummodes, const int nmodes_offset, NekDouble *coeffs, std::vector< LibUtilities::BasisType > &fromType)
Definition: Expansion.cpp:105
SpatialDomains::GeometrySharedPtr GetGeom() const
Definition: Expansion.cpp:167
std::shared_ptr< GeomFactors > GeomFactorsSharedPtr
Pointer to a GeomFactors object.
Definition: GeomFactors.h:62
void MultiplyByStdQuadratureMetric(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray)
Definition: StdExpansion.h:952
virtual void v_MultiplyByQuadratureMetric(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray)
Definition: Expansion.cpp:194
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
svtvp (scalar times vector plus vector): z = alpha*x + y
Definition: Vmath.cpp:488
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.cpp:445
SpatialDomains::GeomFactorsSharedPtr m_metricinfo
Definition: Expansion.h:128
STL namespace.
static DNekScalMatSharedPtr NullDNekScalMatSharedPtr
Definition: NekTypeDefs.hpp:79
DNekMatSharedPtr BuildVertexMatrix(const DNekScalMatSharedPtr &r_bnd)
Definition: Expansion.cpp:98
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:294
std::shared_ptr< DNekMat > DNekMatSharedPtr
Definition: NekTypeDefs.hpp:69
SpatialDomains::GeometrySharedPtr m_geom
Definition: Expansion.h:127
virtual DNekMatSharedPtr v_BuildTransformationMatrix(const DNekScalMatSharedPtr &r_bnd, const StdRegions::MatrixType matrixType)
Definition: Expansion.cpp:476
virtual DNekMatSharedPtr v_BuildVertexMatrix(const DNekScalMatSharedPtr &r_bnd)
Definition: Expansion.cpp:485
virtual void v_ExtractDataToCoeffs(const NekDouble *data, const std::vector< unsigned int > &nummodes, const int nmodes_offset, NekDouble *coeffs, std::vector< LibUtilities::BasisType > &fromType)
Definition: Expansion.cpp:493
static DNekMatSharedPtr NullDNekMatSharedPtr
Definition: NekTypeDefs.hpp:78
const LibUtilities::PointsKeyVector GetPointsKeys() const
void Interp2D(const BasisKey &fbasis0, const BasisKey &fbasis1, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, Array< OneD, NekDouble > &to)
this function interpolates a 2D function evaluated at the quadrature points of the 2D basis...
Definition: Interp.cpp:115
Expansion(SpatialDomains::GeometrySharedPtr pGeom)
Definition: Expansion.cpp:47
virtual void v_ComputeLaplacianMetric()
Definition: Expansion.h:142
std::map< StdRegions::VarCoeffType, Array< OneD, NekDouble > > VarCoeffMap
Definition: StdRegions.hpp:264
virtual void v_GetCoords(Array< OneD, NekDouble > &coords_1, Array< OneD, NekDouble > &coords_2, Array< OneD, NekDouble > &coords_3)
Definition: Expansion.cpp:231
Array< OneD, NekDouble > v_GetMFMag(const int dir, const StdRegions::VarCoeffMap &varcoeffs)
Definition: Expansion.cpp:444
std::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
Array< OneD, NekDouble > v_GetMF(const int dir, const int shapedim, const StdRegions::VarCoeffMap &varcoeffs)
Definition: Expansion.cpp:347
virtual DNekScalMatSharedPtr v_GetLocMatrix(const LocalRegions::MatrixKey &mkey)
Definition: Expansion.cpp:187
void DGDeriv(const int dir, const Array< OneD, const NekDouble > &inarray, Array< OneD, ExpansionSharedPtr > &EdgeExp, Array< OneD, Array< OneD, NekDouble > > &coeffs, Array< OneD, NekDouble > &outarray)
Definition: Expansion.cpp:143
double NekDouble
const SpatialDomains::GeomFactorsSharedPtr & GetMetricInfo() const
Definition: Expansion.cpp:181
virtual void v_AddFaceNormBoundaryInt(const int face, const std::shared_ptr< Expansion > &FaceExp, const Array< OneD, const NekDouble > &Fn, Array< OneD, NekDouble > &outarray)
Definition: Expansion.cpp:526
virtual void v_AddEdgeNormBoundaryInt(const int edge, const std::shared_ptr< Expansion > &EdgeExp, const Array< OneD, const NekDouble > &Fx, const Array< OneD, const NekDouble > &Fy, Array< OneD, NekDouble > &outarray)
Definition: Expansion.cpp:505
Array< OneD, NekDouble > v_GetMFDiv(const int dir, const StdRegions::VarCoeffMap &varcoeffs)
Definition: Expansion.cpp:411
DNekScalMatSharedPtr GetLocMatrix(const LocalRegions::MatrixKey &mkey)
Definition: Expansion.cpp:85
void AddFaceNormBoundaryInt(const int face, const std::shared_ptr< Expansion > &FaceExp, const Array< OneD, const NekDouble > &Fn, Array< OneD, NekDouble > &outarray)
Definition: Expansion.cpp:134
void AddEdgeNormBoundaryInt(const int edge, const std::shared_ptr< Expansion > &EdgeExp, const Array< OneD, const NekDouble > &Fx, const Array< OneD, const NekDouble > &Fy, Array< OneD, NekDouble > &outarray)
Definition: Expansion.cpp:115
void Interp3D(const BasisKey &fbasis0, const BasisKey &fbasis1, const BasisKey &fbasis2, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, const BasisKey &tbasis2, Array< OneD, NekDouble > &to)
this function interpolates a 3D function evaluated at the quadrature points of the 3D basis...
Definition: Interp.cpp:185
void ComputeGmatcdotMF(const Array< TwoD, const NekDouble > &df, const Array< OneD, const NekDouble > &direction, Array< OneD, Array< OneD, NekDouble > > &dfdir)
Definition: Expansion.cpp:312
virtual void v_DGDeriv(const int dir, const Array< OneD, const NekDouble > &inarray, Array< OneD, ExpansionSharedPtr > &EdgeExp, Array< OneD, Array< OneD, NekDouble > > &coeffs, Array< OneD, NekDouble > &outarray)
Definition: Expansion.cpp:536
Geometry is straight-sided with constant geometric factors.
void Interp1D(const BasisKey &fbasis0, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, Array< OneD, NekDouble > &to)
this function interpolates a 1D function evaluated at the quadrature points of the basis fbasis0 to ...
Definition: Interp.cpp:53
StdExpansion()
Default Constructor.
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
Definition: StdExpansion.h:140
GeomType
Indicates the type of element geometry.
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250
Array< OneD, LibUtilities::BasisSharedPtr > m_base
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
Geometry is curved or has non-constant factors.
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.cpp:186