Nektar++
Interp.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File Interp.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 Interpolation methods
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
38 
43 
44 namespace Nektar
45 {
46  namespace LibUtilities
47  {
48 
49  // Physical Space Interpolation methods
50 
51 
52  // 1D Interpolation
53  void Interp1D(const BasisKey &fbasis0,
54  const Array<OneD, const NekDouble>& from,
55  const BasisKey &tbasis0,
57  {
58  Interp1D(fbasis0.GetPointsKey(),from,tbasis0.GetPointsKey(),to);
59  }
60 
61  void Interp1D(const PointsKey &fpoints0,
62  const Array<OneD, const NekDouble>& from,
63  const PointsKey &tpoints0,
65  {
66  if(fpoints0 == tpoints0) //check to see if the same
67  {
68  Vmath::Vcopy(fpoints0.GetNumPoints(),from,1,to,1);
69  }
70  else // interpolate
71  {
73 
74  I0 = PointsManager()[fpoints0]->GetI(tpoints0);
75 
76  NekVector<NekDouble> in(fpoints0.GetNumPoints(),from,eWrapper);
77  NekVector<NekDouble> out(tpoints0.GetNumPoints(),to,eWrapper);
78 
79  out = (*I0)*in;
80  }
81  }
82 
83  void Interp1D(const BasisKey &fbasis0,
84  const NekDouble *from,
85  const BasisKey &tbasis0,
86  NekDouble *to)
87  {
88  Interp1D(fbasis0.GetPointsKey(),from,tbasis0.GetPointsKey(),to);
89  }
90 
91  void Interp1D(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 I0;
104 
105  I0 = PointsManager()[fpoints0]
106  ->GetI(tpoints0);
107 
108  Blas::Dgemv('N', tpoints0.GetNumPoints(), fpoints0.GetNumPoints(),
109  1.0, I0->GetPtr().get(), tpoints0.GetNumPoints(),
110  from, 1, 0.0, to, 1);
111  }
112  }
113 
114  // 2D Interpolation
115  void Interp2D(const BasisKey &fbasis0,
116  const BasisKey &fbasis1,
117  const Array<OneD, const NekDouble>& from,
118  const BasisKey &tbasis0,
119  const BasisKey &tbasis1,
121  {
122  Interp2D(fbasis0.GetPointsKey(),fbasis1.GetPointsKey(),from.data(),
123  tbasis0.GetPointsKey(),tbasis1.GetPointsKey(),to.data());
124  }
125 
126  void Interp2D(const PointsKey &fpoints0,
127  const PointsKey &fpoints1,
128  const Array<OneD, const NekDouble>& from,
129  const PointsKey &tpoints0,
130  const PointsKey &tpoints1,
132  {
133  Interp2D(fpoints0,fpoints1,from.data(),tpoints0,tpoints1,to.data());
134  }
135 
136  void Interp2D(const PointsKey &fpoints0,
137  const PointsKey &fpoints1,
138  const NekDouble *from,
139  const PointsKey &tpoints0,
140  const PointsKey &tpoints1,
141  NekDouble *to)
142  {
143  // default interpolation
144  if((fpoints0 == tpoints0)&&(fpoints1 == tpoints1))
145  {
146  Vmath::Vcopy(tpoints0.GetNumPoints()*tpoints1.GetNumPoints(),
147  from,1,to,1);
148  return;
149  }
150 
151  DNekMatSharedPtr I0,I1;
152  Array<OneD, NekDouble> wsp(tpoints1.GetNumPoints()*fpoints0.GetNumPoints()); // fnp0*tnp1
153 
154  int fnp0 = fpoints0.GetNumPoints();
155  int fnp1 = fpoints1.GetNumPoints();
156  int tnp0 = tpoints0.GetNumPoints();
157  int tnp1 = tpoints1.GetNumPoints();
158 
159  if(fpoints1 == tpoints1)
160  {
161  Vmath::Vcopy(fnp0*tnp1,from,1,wsp.get(),1);
162  }
163  else
164  {
165  I1 = PointsManager()[fpoints1]->GetI(tpoints1);
166  Blas::Dgemm('N', 'T', fnp0, tnp1, fnp1, 1.0, from, fnp0,
167  I1->GetPtr().get(), tnp1, 0.0, wsp.get(), fnp0);
168  }
169 
170  if(fpoints0 == tpoints0)
171  {
172  Vmath::Vcopy(tnp0*tnp1,wsp.get(),1,to,1);
173  }
174  else
175  {
176  I0 = PointsManager()[fpoints0]->GetI(tpoints0);
177  Blas::Dgemm('N', 'N', tnp0, tnp1, fnp0, 1.0, I0->GetPtr().get(),
178  tnp0, wsp.get(), fnp0, 0.0, to, tnp0);
179  }
180  }
181 
182 
183 
184  // 3D interpolation
185  void Interp3D(const BasisKey &fbasis0,
186  const BasisKey &fbasis1,
187  const BasisKey &fbasis2,
188  const Array<OneD, const NekDouble>& from,
189  const BasisKey &tbasis0,
190  const BasisKey &tbasis1,
191  const BasisKey &tbasis2,
193  {
194  Interp3D(fbasis0.GetPointsKey(),fbasis1.GetPointsKey(),
195  fbasis2.GetPointsKey(),from.data(),
196  tbasis0.GetPointsKey(),tbasis1.GetPointsKey(),
197  tbasis2.GetPointsKey(),to.data());
198  }
199 
200 
201  void Interp3D(const PointsKey &fpoints0,
202  const PointsKey &fpoints1,
203  const PointsKey &fpoints2,
204  const Array<OneD, const NekDouble>& from,
205  const PointsKey &tpoints0,
206  const PointsKey &tpoints1,
207  const PointsKey &tpoints2,
209  {
210  Interp3D(fpoints0,fpoints1,fpoints2,from.data(),
211  tpoints0,tpoints1,tpoints2,to.data());
212  }
213 
214  void Interp3D(const PointsKey &fpoints0,
215  const PointsKey &fpoints1,
216  const PointsKey &fpoints2,
217  const NekDouble *from,
218  const PointsKey &tpoints0,
219  const PointsKey &tpoints1,
220  const PointsKey &tpoints2,
221  NekDouble *to)
222  {
223  int i;
224  DNekMatSharedPtr I0, I1, I2;
225 
226  int fnp0 = fpoints0.GetNumPoints();
227  int fnp1 = fpoints1.GetNumPoints();
228  int fnp2 = fpoints2.GetNumPoints();
229  int tnp0 = tpoints0.GetNumPoints();
230  int tnp1 = tpoints1.GetNumPoints();
231  int tnp2 = tpoints2.GetNumPoints();
232 
233  Array<OneD, NekDouble> wsp1(tnp0*tnp1*fnp2);
234  Array<OneD, NekDouble> wsp2(tnp0*fnp1*fnp2);
235 
236  I0 = PointsManager()[fpoints0]->GetI(tpoints0);
237  I1 = PointsManager()[fpoints1]->GetI(tpoints1);
238  I2 = PointsManager()[fpoints2]->GetI(tpoints2);
239 
240  Blas::Dgemm('N', 'N', tnp0, fnp1*fnp2, fnp0, 1.0, I0->GetPtr().get(),
241  tnp0, from, fnp0, 0.0, wsp2.get(), tnp0);
242 
243  for(i = 0; i < fnp2; i++)
244  {
245  Blas::Dgemm('N', 'T', tnp0, tnp1, fnp1, 1.0, wsp2.get()+i*tnp0*fnp1,
246  tnp0, I1->GetPtr().get(), tnp1, 0.0, wsp1.get()+i*tnp0*tnp1, tnp0);
247  }
248 
249  Blas::Dgemm('N', 'T', tnp0*tnp1, tnp2, fnp2, 1.0, wsp1.get(),
250  tnp0*tnp1, I2->GetPtr().get(), tnp2, 0.0, to, tnp0*tnp1);
251  }
252 
253 
254 
255  } // end of namespace
256 } // end of namespace
257 
Describes the specification for a Basis.
Definition: Basis.h:50
PointsKey GetPointsKey() const
Return distribution of points.
Definition: Basis.h:150
Defines a specification for a set of points.
Definition: Points.h:60
unsigned int GetNumPoints() const
Definition: Points.h:107
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:265
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 op(A)[m x k], op(B)[k x n], C[m x n] DGEMM perfo...
Definition: Blas.hpp:394
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
PointsManagerT & PointsManager(void)
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 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
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
std::shared_ptr< DNekMat > DNekMatSharedPtr
Definition: NekTypeDefs.hpp:69
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1199