Nektar++
PhysGalerkinProject.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File PhysGalerkinProject.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: Definition of Physical Space Galerkin Projection methods
32 //
33 ///////////////////////////////////////////////////////////////////////////////
37 
42 
43 namespace Nektar
44 {
45  namespace LibUtilities
46  {
47 
48  // Physical Space Interpolation methods
49 
50 
51  // 1D Interpolation
52  void PhysGalerkinProject1D(const BasisKey &fbasis0,
53  const Array<OneD, const NekDouble>& from,
54  const BasisKey &tbasis0,
56  {
57  PhysGalerkinProject1D(fbasis0.GetPointsKey(),from,tbasis0.GetPointsKey(),to);
58  }
59 
60  void PhysGalerkinProject1D(const PointsKey &fpoints0,
61  const Array<OneD, const NekDouble>& from,
62  const PointsKey &tpoints0,
64  {
65  if(fpoints0 == tpoints0) //check to see if the same
66  {
67  Vmath::Vcopy(fpoints0.GetNumPoints(),from,1,to,1);
68  }
69  else // interpolate
70  {
71  DNekMatSharedPtr GP0;
72 
73  GP0 = PointsManager()[tpoints0]->GetGalerkinProjection(fpoints0);
74 
75  NekVector<NekDouble> in(fpoints0.GetNumPoints(),from,eWrapper);
76  NekVector<NekDouble> out(tpoints0.GetNumPoints(),to,eWrapper);
77 
78  GP0->Transpose();
79  out = (*GP0)*in;
80  }
81  }
82 
83  void PhysGalerkinProject1D(const BasisKey &fbasis0,
84  const NekDouble *from,
85  const BasisKey &tbasis0,
86  NekDouble *to)
87  {
88  PhysGalerkinProject1D(fbasis0.GetPointsKey(),from,tbasis0.GetPointsKey(),to);
89  }
90 
91  void PhysGalerkinProject1D(const PointsKey &fpoints0,
92  const NekDouble *from,
93  const PointsKey &tpoints0,
94  NekDouble *to)
95  {
96  if(fpoints0 == tpoints0) //check to see if the same
97  {
98  Vmath::Vcopy(fpoints0.GetNumPoints(),from,1,to,1);
99  }
100  else // interpolate
101  {
102 
103  DNekMatSharedPtr GP0;
104 
105  GP0 = PointsManager()[tpoints0]
106  ->GetGalerkinProjection(fpoints0);
107 
108  Blas::Dgemv('T', tpoints0.GetNumPoints(), fpoints0.GetNumPoints(),
109  1.0, GP0->GetPtr().get(), tpoints0.GetNumPoints(),
110  from, 1, 0.0, to, 1);
111  }
112  }
113 
114  // 2D Galerkin Projection
115  void PhysGalerkinProject2D(const BasisKey &fbasis0,
116  const BasisKey &fbasis1,
117  const Array<OneD, const NekDouble>& from,
118  const BasisKey &tbasis0,
119  const BasisKey &tbasis1,
121  {
122  PhysGalerkinProject2D(fbasis0.GetPointsKey(),fbasis1.GetPointsKey(),from.data(),
123  tbasis0.GetPointsKey(),tbasis1.GetPointsKey(),to.data());
124  }
125 
126  void PhysGalerkinProject2D(const PointsKey &fpoints0,
127  const PointsKey &fpoints1,
128  const Array<OneD, const NekDouble>& from,
129  const PointsKey &tpoints0,
130  const PointsKey &tpoints1,
132  {
133  PhysGalerkinProject2D(fpoints0,fpoints1,from.data(),tpoints0,tpoints1,to.data());
134  }
135 
136  void PhysGalerkinProject2D(const PointsKey &fpoints0,
137  const PointsKey &fpoints1,
138  const NekDouble *from,
139  const PointsKey &tpoints0,
140  const PointsKey &tpoints1,
141  NekDouble *to)
142  {
143  DNekMatSharedPtr GP0,GP1;
144  Array<OneD, NekDouble> wsp(tpoints1.GetNumPoints()*fpoints0.GetNumPoints()); // fnp0*tnp1
145 
146  int fnp0 = fpoints0.GetNumPoints();
147  int fnp1 = fpoints1.GetNumPoints();
148  int tnp0 = tpoints0.GetNumPoints();
149  int tnp1 = tpoints1.GetNumPoints();
150 
151  if(fpoints1 == tpoints1)
152  {
153  Vmath::Vcopy(fnp0*tnp1,from,1,wsp.get(),1);
154  }
155  else
156  {
157  GP1 = PointsManager()[tpoints1]->GetGalerkinProjection(fpoints1);
158  Blas::Dgemm('N', 'T', fnp0, tnp1, fnp1, 1.0, from, fnp0,
159  GP1->GetPtr().get(), tnp1, 0.0, wsp.get(), fnp0);
160  }
161 
162  if(fpoints0 == tpoints0)
163  {
164  Vmath::Vcopy(tnp0*tnp1,wsp.get(),1,to,1);
165  }
166  else
167  {
168  GP0 = PointsManager()[tpoints0]->GetGalerkinProjection(fpoints0);
169  Blas::Dgemm('N', 'N', tnp0, tnp1, fnp0, 1.0,
170  GP0->GetPtr().get(),
171  tnp0, wsp.get(), fnp0, 0.0, to, tnp0);
172  }
173  }
174 
175 
176  // 3D Galerkin Projection
177  void PhysGalerkinProject3D(const BasisKey &fbasis0,
178  const BasisKey &fbasis1,
179  const BasisKey &fbasis2,
180  const Array<OneD, const NekDouble>& from,
181  const BasisKey &tbasis0,
182  const BasisKey &tbasis1,
183  const BasisKey &tbasis2,
185  {
187  fbasis1.GetPointsKey(),
188  fbasis2.GetPointsKey(),
189  from.data(),
190  tbasis0.GetPointsKey(),
191  tbasis1.GetPointsKey(),
192  tbasis2.GetPointsKey(),
193  to.data());
194  }
195 
196  void PhysGalerkinProject3D(const PointsKey &fpoints0,
197  const PointsKey &fpoints1,
198  const PointsKey &fpoints2,
199  const Array<OneD, const NekDouble>& from,
200  const PointsKey &tpoints0,
201  const PointsKey &tpoints1,
202  const PointsKey &tpoints2,
204  {
205  PhysGalerkinProject3D(fpoints0,fpoints1,fpoints2,from.data(),
206  tpoints0,tpoints1,tpoints2,to.data());
207  }
208 
209  void PhysGalerkinProject3D(const PointsKey &fpoints0,
210  const PointsKey &fpoints1,
211  const PointsKey &fpoints2,
212  const NekDouble *from,
213  const PointsKey &tpoints0,
214  const PointsKey &tpoints1,
215  const PointsKey &tpoints2,
216  NekDouble *to)
217  {
218  DNekMatSharedPtr GP0,GP1,GP2;
219 
220  int fnp0 = fpoints0.GetNumPoints();
221  int fnp1 = fpoints1.GetNumPoints();
222  int fnp2 = fpoints2.GetNumPoints();
223  int tnp0 = tpoints0.GetNumPoints();
224  int tnp1 = tpoints1.GetNumPoints();
225  int tnp2 = tpoints2.GetNumPoints();
226 
227  Array<OneD, NekDouble> wsp1(fnp0*tnp1*tnp2);
228  Array<OneD, NekDouble> wsp2(fnp0*fnp1*tnp2);
229 
230  GP2 = PointsManager()[tpoints2]->GetGalerkinProjection(fpoints2);
231  Blas::Dgemm('N', 'T', fnp0*fnp1, tnp2, fnp2, 1.0, from, fnp0*fnp1,
232  GP2->GetPtr().get(), tnp2, 0.0, wsp2.get(), fnp0*fnp1);
233 
234  GP1 = PointsManager()[tpoints1]->GetGalerkinProjection(fpoints1);
235  for(int i = 0; i < tnp2; i++)
236  {
237  Blas::Dgemm('N', 'T', fnp0, tnp1, fnp1, 1.0,
238  wsp2.get()+i*fnp0*fnp1,
239  fnp0, GP1->GetPtr().get(),tnp1, 0.0,
240  wsp1.get()+i*fnp0*tnp1,
241  fnp0);
242  }
243 
244  GP0 = PointsManager()[tpoints0]->GetGalerkinProjection(fpoints0);
245  Blas::Dgemm('N', 'N', tnp0, tnp1*tnp2, fnp0, 1.0,
246  GP0->GetPtr().get(), tnp0, wsp1.get(), fnp0, 0.0,
247  to, tnp0);
248  }
249 
250  } // end of namespace
251 } // end of namespace
252 
void PhysGalerkinProject1D(const BasisKey &fbasis0, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, Array< OneD, NekDouble > &to)
std::shared_ptr< DNekMat > DNekMatSharedPtr
Definition: NekTypeDefs.hpp:69
static void Dgemm(const char &transa, const char &transb, const int &m, const int &n, const int &k, const double &alpha, const double *a, const int &lda, const double *b, const int &ldb, const double &beta, double *c, const int &ldc)
BLAS level 3: Matrix-matrix multiply C = A x B where A[m x n], B[n x k], C[m x k].
Definition: Blas.hpp:213
PointsKey GetPointsKey() const
Return distribution of points.
Definition: Basis.h:150
PointsManagerT & PointsManager(void)
void PhysGalerkinProject3D(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)
Defines a specification for a set of points.
Definition: Points.h:59
double NekDouble
static void Dgemv(const char &trans, const int &m, const int &n, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
BLAS level 2: Matrix vector multiply y = A x where A[m x n].
Definition: Blas.hpp:168
unsigned int GetNumPoints() const
Definition: Points.h:107
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
Describes the specification for a Basis.
Definition: Basis.h:49
void PhysGalerkinProject2D(const BasisKey &fbasis0, const BasisKey &fbasis1, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, Array< OneD, NekDouble > &to)