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