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