Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GaussPoints.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File GaussPoints.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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: GaussPoints Definitions
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
38 
45 
46 
47 namespace Nektar
48 {
49  namespace LibUtilities
50  {
52  {
53  // Allocate the storage for points and weights
56 
57  int numpoints = m_pointsKey.GetNumPoints();
58 
59  switch(m_pointsKey.GetPointsType())
60  {
62  Polylib::zwgj(m_points[0].data(),m_weights.data(),numpoints,0.0,0.0);
63  break;
64 
66  Polylib::zwgrjm(m_points[0].data(),m_weights.data(),numpoints,0.0,0.0);
67  break;
68 
70  Polylib::zwgrjp(m_points[0].data(),m_weights.data(),numpoints,0.0,0.0);
71  break;
72 
74  Polylib::zwglj(m_points[0].data(),m_weights.data(),numpoints,0.0,0.0);
75  break;
76 
78  Polylib::zwgj(m_points[0].data(),m_weights.data(),numpoints,-0.5,-0.5);
79  break;
80 
82  Polylib::zwgrjm(m_points[0].data(),m_weights.data(),numpoints,-0.5,-0.5);
83  break;
84 
86  Polylib::zwgrjp(m_points[0].data(),m_weights.data(),numpoints,-0.5,-0.5);
87  break;
88 
90  Polylib::zwglj(m_points[0].data(),m_weights.data(),numpoints,-0.5,-0.5);
91  break;
92 
94  Polylib::zwgrjm(m_points[0].data(),m_weights.data(),numpoints,0.0,1.0);
95  break;
96 
98  Polylib::zwgrjm(m_points[0].data(),m_weights.data(),numpoints,0.0,2.0);
99  break;
100 
102  Polylib::zwgrjm(m_points[0].data(),m_weights.data(),numpoints,1.0,0.0);
103  break;
104 
106  Polylib::zwgrjm(m_points[0].data(),m_weights.data(),numpoints,2.0,0.0);
107  break;
108 
110  Polylib::zwgk(m_points[0].data(),m_weights.data(),numpoints,0.0,0.0);
111  break;
112 
114  Polylib::zwrk(m_points[0].data(),m_weights.data(),numpoints,0.0,0.0);
115  break;
116 
118  Polylib::zwrk(m_points[0].data(),m_weights.data(),numpoints,1.0,0.0);
119  break;
120 
122  Polylib::zwlk(m_points[0].data(),m_weights.data(),numpoints,0.0,0.0);
123  break;
124 
125  default:
126  ASSERTL0(false, "Unknown Gauss quadrature point distribution requested");
127  }
128  }
129 
131  {
132  // For Gauss Quadrature, this is done as part of the points computation
133  }
134 
136  {
137  // Allocate the derivative matrix
139 
140  int numpoints = m_pointsKey.GetNumPoints();
141  int totpoints = m_pointsKey.GetTotNumPoints();
142  Array<OneD, NekDouble> dmtempSharedArray = Array<OneD, NekDouble>(totpoints*totpoints);
143  NekDouble *dmtemp = dmtempSharedArray.data();
144 
145  switch(m_pointsKey.GetPointsType())
146  {
147  case eGaussGaussLegendre:
148  Polylib::Dgj(dmtemp,m_points[0].data(),numpoints,0.0,0.0);
149  break;
150 
152  Polylib::Dgrjm(dmtemp,m_points[0].data(),numpoints,0.0,0.0);
153  break;
154 
156  Polylib::Dgrjp(dmtemp,m_points[0].data(),numpoints,0.0,0.0);
157  break;
158 
160  Polylib::Dglj(dmtemp,m_points[0].data(),numpoints,0.0,0.0);
161  break;
162 
164  Polylib::Dgj(dmtemp,m_points[0].data(),numpoints,-0.5,-0.5);
165  break;
166 
168  Polylib::Dgrjm(dmtemp,m_points[0].data(),numpoints,-0.5,-0.5);
169  break;
170 
172  Polylib::Dgrjp(dmtemp,m_points[0].data(),numpoints,-0.5,-0.5);
173  break;
174 
176  Polylib::Dglj(dmtemp,m_points[0].data(),numpoints,-0.5,-0.5);
177  break;
178 
180  Polylib::Dgrjm(dmtemp,m_points[0].data(),numpoints,0.0,1.0);
181  break;
182 
184  Polylib::Dgrjm(dmtemp,m_points[0].data(),numpoints,0.0,2.0);
185  break;
186 
188  Polylib::Dgrjm(dmtemp,m_points[0].data(),numpoints,1.0,0.0);
189  break;
190 
192  Polylib::Dgrjm(dmtemp,m_points[0].data(),numpoints,2.0,0.0);
193  break;
194 
199  {
200  for(unsigned int i=0;i<m_pointsKey.GetNumPoints();++i)
201  {
202  for(unsigned int j=0;j<m_pointsKey.GetNumPoints();++j)
203  {
205  }
206  }
207  return;
208  }
209  break;
210 
211  default:
212  ASSERTL0(false, "Unknown Gauss quadrature point distribution requested");
213  }
214 
215  std::copy(dmtemp,dmtemp+totpoints*totpoints,m_derivmatrix[0]->begin());
216  }
217 
219  {
220  switch(m_pointsKey.GetPointsType())
221  {
222  case eGaussGaussLegendre:
223  Polylib::Imgj(interp.data(),m_points[0].data(),xpoints.data(),GetNumPoints(),npts,0.0,0.0);
224  break;
225 
227  Polylib::Imgrjm(interp.data(),m_points[0].data(),xpoints.data(),GetNumPoints(),npts,0.0,0.0);
228  break;
229 
231  Polylib::Imgrjp(interp.data(),m_points[0].data(),xpoints.data(),GetNumPoints(),npts,0.0,0.0);
232  break;
233 
235  Polylib::Imglj(interp.data(),m_points[0].data(),xpoints.data(),GetNumPoints(),npts,0.0,0.0);
236  break;
237 
239  Polylib::Imgj(interp.data(),m_points[0].data(),xpoints.data(),GetNumPoints(),npts,-0.5,-0.5);
240  break;
241 
243  Polylib::Imgrjm(interp.data(),m_points[0].data(),xpoints.data(),GetNumPoints(),npts,-0.5,-0.5);
244  break;
245 
247  Polylib::Imgrjp(interp.data(),m_points[0].data(),xpoints.data(),GetNumPoints(),npts,-0.5,-0.5);
248  break;
249 
251  Polylib::Imglj(interp.data(),m_points[0].data(),xpoints.data(),GetNumPoints(),npts,-0.5,-0.5);
252  break;
253 
255  Polylib::Imgrjm(interp.data(),m_points[0].data(),xpoints.data(),GetNumPoints(),npts,0.0,1.0);
256  break;
257 
259  Polylib::Imgrjm(interp.data(),m_points[0].data(),xpoints.data(),GetNumPoints(),npts,0.0,2.0);
260  break;
261 
263  Polylib::Imgrjm(interp.data(),m_points[0].data(),xpoints.data(),GetNumPoints(),npts,1.0,0.0);
264  break;
265 
267  Polylib::Imgrjm(interp.data(),m_points[0].data(),xpoints.data(),GetNumPoints(),npts,2.0,0.0);
268  break;
269 
274  {
275  for(unsigned int i=0;i<npts;++i)
276  {
277  for(unsigned int j=0;j<m_pointsKey.GetNumPoints();++j)
278  {
279  interp[i + j*npts] = LagrangePoly(xpoints[i],j,m_pointsKey.GetNumPoints(),m_points[0]);
280  }
281  }
282  }
283  break;
284 
285  default:
286  ASSERTL0(false, "Unknown Gauss quadrature point distribution requested");
287  }
288  }
289 
290  boost::shared_ptr<Points<NekDouble> > GaussPoints::Create(const PointsKey &pkey)
291  {
292  boost::shared_ptr< Points<NekDouble> > returnval(MemoryManager< GaussPoints >::AllocateSharedPtr(pkey));
293 
294  returnval->Initialize();
295 
296  return returnval;
297  }
298 
299  boost::shared_ptr< NekMatrix<NekDouble> > GaussPoints::CreateMatrix(const PointsKey &pkey)
300  {
301  int numpoints = pkey.GetNumPoints();
303 
304  PointsManager()[pkey]->GetPoints(xpoints);
305 
306  // Delegate to function below
307  return GetI(numpoints, xpoints);
308  }
309 
310 
311  const boost::shared_ptr<NekMatrix<NekDouble> > GaussPoints::GetI(const PointsKey &pkey)
312  {
313  ASSERTL0(pkey.GetPointsDim()==1, "Gauss Points can only interp to other 1d point distributions");
314 
315  return m_InterpManager[pkey];
316  }
317 
318  const boost::shared_ptr<NekMatrix<NekDouble> > GaussPoints::GetI(const Array<OneD, const NekDouble>& x)
319  {
320  int numpoints = 1;
321 
322  // Delegate to function below
323  return GetI(numpoints, x);
324  }
325 
326  const boost::shared_ptr<NekMatrix<NekDouble> > GaussPoints::GetI(unsigned int numpoints, const Array<OneD, const NekDouble>& x)
327  {
328  Array<OneD, NekDouble> interp(GetNumPoints()*numpoints);
329 
330  CalculateInterpMatrix(numpoints, x, interp);
331 
332  NekDouble* t = interp.data();
333  unsigned int np = GetNumPoints();
334  boost::shared_ptr< NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr(numpoints,np,t));
335 
336  return returnval;
337  }
338 
340  const Array<OneD, const NekDouble>& funcvals)
341  {
342  NekDouble sum = 0.0;
343 
344  for(int i=0;i<npts;++i)
345  {
346  sum += funcvals[i]*LagrangePoly(x,i,npts,xpts);
347  }
348  return sum;
349  }
350 
351 
353  {
354  NekDouble h=1.0;
355 
356  for(int i=0;i<pt; ++i)
357  {
358  h = h * (x - xpts[i])/(xpts[pt]-xpts[i]);
359  }
360 
361  for(int i=pt+1;i<npts;++i)
362  {
363  h = h * (x - xpts[i])/(xpts[pt]-xpts[i]);
364  }
365 
366  return h;
367  }
368 
370  {
371  NekDouble h;
372  NekDouble y=0.0;
373 
374  for(int j=0;j<npts;++j)
375  {
376  if(j!=pt)
377  {
378  h=1.0;
379  for(int i=0;i<npts;++i)
380  {
381  if(i!=pt)
382  {
383  if(i!=j)
384  {
385  h = h*(x-xpts[i]);
386  }
387  h = h/(xpts[pt]-xpts[i]);
388  }
389  }
390  y = y + h;
391  }
392  }
393  return y;
394  }
395 
396  const boost::shared_ptr<NekMatrix<NekDouble> > GaussPoints::GetGalerkinProjection(const PointsKey &pkey)
397  {
398  return m_GalerkinProjectionManager[pkey];
399  }
400 
401  boost::shared_ptr< NekMatrix<NekDouble> > GaussPoints::CreateGPMatrix(const PointsKey &pkey)
402  {
403  boost::shared_ptr< NekMatrix<NekDouble> > returnval = CalculateGalerkinProjectionMatrix(pkey);
404 
405  // Delegate to function below
406  return returnval;
407  }
408 
409  boost::shared_ptr<NekMatrix<NekDouble> > GaussPoints::CalculateGalerkinProjectionMatrix(const PointsKey &pkey)
410  {
411  int numpointsfrom = pkey.GetNumPoints();
412  int numpointsto = GetNumPoints();
413 
414  Array<OneD, const NekDouble> weightsfrom;
415 
416  weightsfrom = PointsManager()[pkey]->GetW();
417 
418  boost::shared_ptr< NekMatrix<NekDouble> > Interp = GetI(pkey);
419 
420  Array<OneD, NekDouble> GalProj(numpointsfrom*numpointsto);
421 
422  // set up inner product matrix and multiply by inverse of
423  // diagaonal mass matrix
424  for(int i = 0; i < numpointsto; ++i)
425  {
426  Vmath::Vmul(numpointsfrom,Interp->GetPtr().get() +i*numpointsfrom,1,
427  &weightsfrom[0],1,&GalProj[0] +i,numpointsto);
428  Vmath::Smul(numpointsfrom,1.0/m_weights[i],&GalProj[0]+i,numpointsto,
429  &GalProj[0]+i,numpointsto);
430  }
431 
432 
433  NekDouble* t = GalProj.data();
434  boost::shared_ptr< NekMatrix<NekDouble> > returnval(MemoryManager<NekMatrix<NekDouble> >::AllocateSharedPtr(numpointsto,numpointsfrom,t));
435 
436  return returnval;
437  }
438 
439  } // end of namespace LibUtilities
440 } // end of namespace Nektar
441 
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_GalerkinProjectionManager
Definition: Points.h:353
void Dgj(double *D, const double *z, const int np, const double alpha, const double beta)
Compute the Derivative Matrix and its transpose associated.
Definition: Polylib.cpp:932
1D Gauss-Radau-Kronrod-Legendre quadrature points, pinned at x=-1
Definition: PointsType.h:60
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
NekDouble LagrangePolyDeriv(NekDouble x, int pt, int npts, const Array< OneD, const NekDouble > &xpts)
1D Gauss-Radau-Chebyshev quadrature points, pinned at x=-1
Definition: PointsType.h:52
NekDouble LagrangePoly(NekDouble x, int pt, int npts, const Array< OneD, const NekDouble > &xpts)
void zwgrjp(double *z, double *w, const int np, const double alpha, const double beta)
Gauss-Radau-Jacobi zeros and weights with end point at z=1.
Definition: Polylib.cpp:234
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
1D Gauss-Radau-Legendre quadrature points, pinned at x=1
Definition: PointsType.h:49
void Imgrjp(double *im, const double *zgrj, const double *zm, const int nz, const int mz, const double alpha, const double beta)
Interpolation Operator from Gauss-Radau-Jacobi points.
Definition: Polylib.cpp:1770
MatrixSharedPtrType m_derivmatrix[3]
Definition: Points.h:351
void zwglj(double *z, double *w, const int np, const double alpha, const double beta)
Gauss-Lobatto-Jacobi zeros and weights with end point at z=-1,1.
Definition: Polylib.cpp:306
Array< OneD, DataType > m_points[3]
Definition: Points.h:349
const boost::shared_ptr< NekMatrix< NekDouble > > GetI(const PointsKey &pkey)
1D Gauss-Kronrod-Legendre quadrature points
Definition: PointsType.h:59
void zwlk(double *z, double *w, const int npt, const double alpha, const double beta)
Gauss-Lobatto-Kronrod-Jacobi zeros and weights.
Definition: Polylib.cpp:706
1D Gauss-Gauss-Legendre quadrature points
Definition: PointsType.h:47
Gauss Radau pinned at x=-1, .
Definition: PointsType.h:57
1D Gauss-Radau-Kronrod-Legendre pinned at x=-1,
Definition: PointsType.h:61
1D Lobatto Kronrod quadrature points
Definition: PointsType.h:62
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
Definition: Vmath.cpp:199
const boost::shared_ptr< NekMatrix< NekDouble > > GetGalerkinProjection(const PointsKey &pkey)
void Imglj(double *im, const double *zglj, const double *zm, const int nz, const int mz, const double alpha, const double beta)
Interpolation Operator from Gauss-Lobatto-Jacobi points.
Definition: Polylib.cpp:1832
unsigned int GetNumPoints() const
Definition: Points.h:246
void Dgrjm(double *D, const double *z, const int np, const double alpha, const double beta)
Compute the Derivative Matrix and its transpose associated.
Definition: Polylib.cpp:1018
void zwgk(double *z, double *w, const int npt, const double alpha, const double beta)
Gauss-Kronrod-Jacobi zeros and weights.
Definition: Polylib.cpp:380
void Imgrjm(double *im, const double *zgrj, const double *zm, const int nz, const int mz, const double alpha, const double beta)
Interpolation Operator from Gauss-Radau-Jacobi points.
Definition: Polylib.cpp:1710
unsigned int GetTotNumPoints() const
Definition: Points.h:175
1D Gauss-Radau-Chebyshev quadrature points, pinned at x=1
Definition: PointsType.h:53
static std::string npts
Definition: InputFld.cpp:43
unsigned int GetPointsDim() const
Definition: Points.h:149
PointsManagerT & PointsManager(void)
static boost::shared_ptr< Points< NekDouble > > Create(const PointsKey &pkey)
1D Gauss-Gauss-Chebyshev quadrature points
Definition: PointsType.h:51
Array< OneD, DataType > m_weights
Definition: Points.h:350
Defines a specification for a set of points.
Definition: Points.h:58
void Dgrjp(double *D, const double *z, const int np, const double alpha, const double beta)
Compute the Derivative Matrix associated with the.
Definition: Polylib.cpp:1116
double NekDouble
void zwgrjm(double *z, double *w, const int np, const double alpha, const double beta)
Gauss-Radau-Jacobi zeros and weights with end point at z=-1.
Definition: Polylib.cpp:158
void CalculateInterpMatrix(unsigned int npts, const Array< OneD, const NekDouble > &xpoints, Array< OneD, NekDouble > &interp)
boost::shared_ptr< NekMatrix< NekDouble > > CalculateGalerkinProjectionMatrix(const PointsKey &pkey)
unsigned int GetNumPoints() const
Definition: Points.h:106
void zwrk(double *z, double *w, const int npt, const double alpha, const double beta)
Gauss-Radau-Kronrod-Jacobi zeros and weights.
Definition: Polylib.cpp:514
Gauss Radau pinned at x=-1, .
Definition: PointsType.h:58
NekDouble LagrangeInterpolant(NekDouble x, int npts, const Array< OneD, const NekDouble > &xpts, const Array< OneD, const NekDouble > &funcvals)
functions used by the Kronrod points
boost::shared_ptr< NekMatrix< NekDouble > > CreateMatrix(const PointsKey &pkey)
boost::shared_ptr< NekMatrix< NekDouble > > CreateGPMatrix(const PointsKey &pkey)
Gauss Radau pinned at x=-1, .
Definition: PointsType.h:56
NekManager< PointsKey, NekMatrix< DataType >, PointsKey::opLess > m_InterpManager
Definition: Points.h:352
Gauss Radau pinned at x=-1, .
Definition: PointsType.h:55
void Dglj(double *D, const double *z, const int np, const double alpha, const double beta)
Compute the Derivative Matrix associated with the.
Definition: Polylib.cpp:1216
void Imgj(double *im, const double *zgj, const double *zm, const int nz, const int mz, const double alpha, const double beta)
Interpolation Operator from Gauss-Jacobi points to an.
Definition: Polylib.cpp:1652
1D Gauss-Lobatto-Legendre quadrature points
Definition: PointsType.h:50
PointsType GetPointsType() const
Definition: Points.h:111
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:169
1D Gauss-Radau-Legendre quadrature points, pinned at x=-1
Definition: PointsType.h:48
1D Gauss-Lobatto-Legendre quadrature points
Definition: PointsType.h:54
void zwgj(double *z, double *w, const int np, const double alpha, const double beta)
Gauss-Jacobi zeros and weights.
Definition: Polylib.cpp:102