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