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 // 1D Interpolation
52 void Interp1D(const BasisKey &fbasis0, const Array<OneD, const NekDouble> &from,
53  const BasisKey &tbasis0, Array<OneD, NekDouble> &to)
54 {
55  Interp1D(fbasis0.GetPointsKey(), from, tbasis0.GetPointsKey(), to);
56 }
57 
58 void Interp1D(const PointsKey &fpoints0,
59  const Array<OneD, const NekDouble> &from,
60  const PointsKey &tpoints0, Array<OneD, NekDouble> &to)
61 {
62  if (fpoints0 == tpoints0) // check to see if the same
63  {
64  Vmath::Vcopy(fpoints0.GetNumPoints(), from, 1, to, 1);
65  }
66  else // interpolate
67  {
69 
70  I0 = PointsManager()[fpoints0]->GetI(tpoints0);
71 
72  NekVector<NekDouble> in(fpoints0.GetNumPoints(), from, eWrapper);
73  NekVector<NekDouble> out(tpoints0.GetNumPoints(), to, eWrapper);
74 
75  out = (*I0) * in;
76  }
77 }
78 
79 void Interp1D(const BasisKey &fbasis0, const NekDouble *from,
80  const BasisKey &tbasis0, NekDouble *to)
81 {
82  Interp1D(fbasis0.GetPointsKey(), from, tbasis0.GetPointsKey(), to);
83 }
84 
85 void Interp1D(const PointsKey &fpoints0, const NekDouble *from,
86  const PointsKey &tpoints0, NekDouble *to)
87 {
88  if (fpoints0 == tpoints0) // check to see if the same
89  {
90  Vmath::Vcopy(fpoints0.GetNumPoints(), from, 1, to, 1);
91  }
92  else // interpolate
93  {
94 
96 
97  I0 = PointsManager()[fpoints0]->GetI(tpoints0);
98 
99  Blas::Dgemv('N', tpoints0.GetNumPoints(), fpoints0.GetNumPoints(), 1.0,
100  I0->GetPtr().get(), tpoints0.GetNumPoints(), from, 1, 0.0,
101  to, 1);
102  }
103 }
104 
105 // 2D Interpolation
106 void Interp2D(const BasisKey &fbasis0, const BasisKey &fbasis1,
107  const Array<OneD, const NekDouble> &from, const BasisKey &tbasis0,
108  const BasisKey &tbasis1, Array<OneD, NekDouble> &to)
109 {
110  Interp2D(fbasis0.GetPointsKey(), fbasis1.GetPointsKey(), from.data(),
111  tbasis0.GetPointsKey(), tbasis1.GetPointsKey(), to.data());
112 }
113 
114 void Interp2D(const PointsKey &fpoints0, const PointsKey &fpoints1,
115  const Array<OneD, const NekDouble> &from,
116  const PointsKey &tpoints0, const PointsKey &tpoints1,
118 {
119  Interp2D(fpoints0, fpoints1, from.data(), tpoints0, tpoints1, to.data());
120 }
121 
122 void Interp2D(const PointsKey &fpoints0, const PointsKey &fpoints1,
123  const NekDouble *from, const PointsKey &tpoints0,
124  const PointsKey &tpoints1, NekDouble *to)
125 {
126  // default interpolation
127  if ((fpoints0 == tpoints0) && (fpoints1 == tpoints1))
128  {
129  Vmath::Vcopy(tpoints0.GetNumPoints() * tpoints1.GetNumPoints(), from, 1,
130  to, 1);
131  return;
132  }
133 
134  DNekMatSharedPtr I0, I1;
135  Array<OneD, NekDouble> wsp(tpoints1.GetNumPoints() *
136  fpoints0.GetNumPoints()); // fnp0*tnp1
137 
138  int fnp0 = fpoints0.GetNumPoints();
139  int fnp1 = fpoints1.GetNumPoints();
140  int tnp0 = tpoints0.GetNumPoints();
141  int tnp1 = tpoints1.GetNumPoints();
142 
143  if (fpoints1 == tpoints1)
144  {
145  Vmath::Vcopy(fnp0 * tnp1, from, 1, wsp.get(), 1);
146  }
147  else
148  {
149  I1 = PointsManager()[fpoints1]->GetI(tpoints1);
150  Blas::Dgemm('N', 'T', fnp0, tnp1, fnp1, 1.0, from, fnp0,
151  I1->GetPtr().get(), tnp1, 0.0, wsp.get(), fnp0);
152  }
153 
154  if (fpoints0 == tpoints0)
155  {
156  Vmath::Vcopy(tnp0 * tnp1, wsp.get(), 1, to, 1);
157  }
158  else
159  {
160  I0 = PointsManager()[fpoints0]->GetI(tpoints0);
161  Blas::Dgemm('N', 'N', tnp0, tnp1, fnp0, 1.0, I0->GetPtr().get(), tnp0,
162  wsp.get(), fnp0, 0.0, to, tnp0);
163  }
164 }
165 
166 // 3D interpolation
167 void Interp3D(const BasisKey &fbasis0, const BasisKey &fbasis1,
168  const BasisKey &fbasis2, const Array<OneD, const NekDouble> &from,
169  const BasisKey &tbasis0, const BasisKey &tbasis1,
170  const BasisKey &tbasis2, Array<OneD, NekDouble> &to)
171 {
172  Interp3D(fbasis0.GetPointsKey(), fbasis1.GetPointsKey(),
173  fbasis2.GetPointsKey(), from.data(), tbasis0.GetPointsKey(),
174  tbasis1.GetPointsKey(), tbasis2.GetPointsKey(), to.data());
175 }
176 
177 void Interp3D(const PointsKey &fpoints0, const PointsKey &fpoints1,
178  const PointsKey &fpoints2,
179  const Array<OneD, const NekDouble> &from,
180  const PointsKey &tpoints0, const PointsKey &tpoints1,
181  const PointsKey &tpoints2, Array<OneD, NekDouble> &to)
182 {
183  Interp3D(fpoints0, fpoints1, fpoints2, from.data(), tpoints0, tpoints1,
184  tpoints2, to.data());
185 }
186 
187 void Interp3D(const PointsKey &fpoints0, const PointsKey &fpoints1,
188  const PointsKey &fpoints2, const NekDouble *from,
189  const PointsKey &tpoints0, const PointsKey &tpoints1,
190  const PointsKey &tpoints2, NekDouble *to)
191 {
192  int i;
193  DNekMatSharedPtr I0, I1, I2;
194 
195  int fnp0 = fpoints0.GetNumPoints();
196  int fnp1 = fpoints1.GetNumPoints();
197  int fnp2 = fpoints2.GetNumPoints();
198  int tnp0 = tpoints0.GetNumPoints();
199  int tnp1 = tpoints1.GetNumPoints();
200  int tnp2 = tpoints2.GetNumPoints();
201 
202  Array<OneD, NekDouble> wsp1(tnp0 * tnp1 * fnp2);
203  Array<OneD, NekDouble> wsp2(tnp0 * fnp1 * fnp2);
204 
205  I0 = PointsManager()[fpoints0]->GetI(tpoints0);
206  I1 = PointsManager()[fpoints1]->GetI(tpoints1);
207  I2 = PointsManager()[fpoints2]->GetI(tpoints2);
208 
209  Blas::Dgemm('N', 'N', tnp0, fnp1 * fnp2, fnp0, 1.0, I0->GetPtr().get(),
210  tnp0, from, fnp0, 0.0, wsp2.get(), tnp0);
211 
212  for (i = 0; i < fnp2; i++)
213  {
214  Blas::Dgemm('N', 'T', tnp0, tnp1, fnp1, 1.0,
215  wsp2.get() + i * tnp0 * fnp1, tnp0, I1->GetPtr().get(),
216  tnp1, 0.0, wsp1.get() + i * tnp0 * tnp1, tnp0);
217  }
218 
219  Blas::Dgemm('N', 'T', tnp0 * tnp1, tnp2, fnp2, 1.0, wsp1.get(), tnp0 * tnp1,
220  I2->GetPtr().get(), tnp2, 0.0, to, tnp0 * tnp1);
221 }
222 
223 } // namespace LibUtilities
224 } // namespace Nektar
Describes the specification for a Basis.
Definition: Basis.h:50
PointsKey GetPointsKey() const
Return distribution of points.
Definition: Basis.h:147
Defines a specification for a set of points.
Definition: Points.h:59
unsigned int GetNumPoints() const
Definition: Points.h:104
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:246
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:368
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:52
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:167
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:106
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
std::shared_ptr< DNekMat > DNekMatSharedPtr
Definition: NekTypeDefs.hpp:75
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255