Nektar++
PhysGalerkinProject.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: PhysGalerkinProject.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 Physical Space Galerkin Projection methods
32//
33///////////////////////////////////////////////////////////////////////////////
34
42
44{
45
46// Physical Space Interpolation methods
47
48// 1D Interpolation
49void PhysGalerkinProject1D(const BasisKey &fbasis0,
51 const BasisKey &tbasis0, Array<OneD, NekDouble> &to)
52{
53 PhysGalerkinProject1D(fbasis0.GetPointsKey(), from, tbasis0.GetPointsKey(),
54 to);
55}
56
57void PhysGalerkinProject1D(const PointsKey &fpoints0,
59 const PointsKey &tpoints0,
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 GP0 = PointsManager()[tpoints0]->GetGalerkinProjection(fpoints0);
71
72 NekVector<NekDouble> in(fpoints0.GetNumPoints(), from, eWrapper);
73 NekVector<NekDouble> out(tpoints0.GetNumPoints(), to, eWrapper);
74
75 GP0->Transpose();
76 out = (*GP0) * in;
77 }
78}
79
80void PhysGalerkinProject1D(const BasisKey &fbasis0, const NekDouble *from,
81 const BasisKey &tbasis0, NekDouble *to)
82{
83 PhysGalerkinProject1D(fbasis0.GetPointsKey(), from, tbasis0.GetPointsKey(),
84 to);
85}
86
87void PhysGalerkinProject1D(const PointsKey &fpoints0, const NekDouble *from,
88 const PointsKey &tpoints0, NekDouble *to)
89{
90 if (fpoints0 == tpoints0) // check to see if the same
91 {
92 Vmath::Vcopy(fpoints0.GetNumPoints(), from, 1, to, 1);
93 }
94 else // interpolate
95 {
96
98
99 GP0 = PointsManager()[tpoints0]->GetGalerkinProjection(fpoints0);
100
101 Blas::Dgemv('T', tpoints0.GetNumPoints(), fpoints0.GetNumPoints(), 1.0,
102 GP0->GetPtr().get(), tpoints0.GetNumPoints(), from, 1, 0.0,
103 to, 1);
104 }
105}
106
107// 2D Galerkin Projection
108void PhysGalerkinProject2D(const BasisKey &fbasis0, const BasisKey &fbasis1,
110 const BasisKey &tbasis0, const BasisKey &tbasis1,
112{
114 from.data(), tbasis0.GetPointsKey(),
115 tbasis1.GetPointsKey(), to.data());
116}
117
118void PhysGalerkinProject2D(const PointsKey &fpoints0, const PointsKey &fpoints1,
120 const PointsKey &tpoints0, const PointsKey &tpoints1,
122{
123 PhysGalerkinProject2D(fpoints0, fpoints1, from.data(), tpoints0, tpoints1,
124 to.data());
125}
126
127void PhysGalerkinProject2D(const PointsKey &fpoints0, const PointsKey &fpoints1,
128 const NekDouble *from, const PointsKey &tpoints0,
129 const PointsKey &tpoints1, NekDouble *to)
130{
131 DNekMatSharedPtr GP0, GP1;
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 GP1 = PointsManager()[tpoints1]->GetGalerkinProjection(fpoints1);
147 Blas::Dgemm('N', 'T', fnp0, tnp1, fnp1, 1.0, from, fnp0,
148 GP1->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 GP0 = PointsManager()[tpoints0]->GetGalerkinProjection(fpoints0);
158 Blas::Dgemm('N', 'N', tnp0, tnp1, fnp0, 1.0, GP0->GetPtr().get(), tnp0,
159 wsp.get(), fnp0, 0.0, to, tnp0);
160 }
161}
162
163// 3D Galerkin Projection
164void PhysGalerkinProject3D(const BasisKey &fbasis0, const BasisKey &fbasis1,
165 const BasisKey &fbasis2,
167 const BasisKey &tbasis0, const BasisKey &tbasis1,
168 const BasisKey &tbasis2, Array<OneD, NekDouble> &to)
169{
171 fbasis2.GetPointsKey(), from.data(),
172 tbasis0.GetPointsKey(), tbasis1.GetPointsKey(),
173 tbasis2.GetPointsKey(), to.data());
174}
175
176void PhysGalerkinProject3D(const PointsKey &fpoints0, const PointsKey &fpoints1,
177 const PointsKey &fpoints2,
179 const PointsKey &tpoints0, const PointsKey &tpoints1,
180 const PointsKey &tpoints2,
182{
183 PhysGalerkinProject3D(fpoints0, fpoints1, fpoints2, from.data(), tpoints0,
184 tpoints1, tpoints2, to.data());
185}
186
187void PhysGalerkinProject3D(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 DNekMatSharedPtr GP0, GP1, GP2;
193
194 size_t fnp0 = fpoints0.GetNumPoints();
195 size_t fnp1 = fpoints1.GetNumPoints();
196 size_t fnp2 = fpoints2.GetNumPoints();
197 size_t tnp0 = tpoints0.GetNumPoints();
198 size_t tnp1 = tpoints1.GetNumPoints();
199 size_t tnp2 = tpoints2.GetNumPoints();
200
201 Array<OneD, NekDouble> wsp1(fnp0 * tnp1 * tnp2);
202 Array<OneD, NekDouble> wsp2(fnp0 * fnp1 * tnp2);
203
204 GP2 = PointsManager()[tpoints2]->GetGalerkinProjection(fpoints2);
205 Blas::Dgemm('N', 'T', fnp0 * fnp1, tnp2, fnp2, 1.0, from, fnp0 * fnp1,
206 GP2->GetPtr().get(), tnp2, 0.0, wsp2.get(), fnp0 * fnp1);
207
208 GP1 = PointsManager()[tpoints1]->GetGalerkinProjection(fpoints1);
209 for (size_t i = 0; i < tnp2; i++)
210 {
211 Blas::Dgemm('N', 'T', fnp0, tnp1, fnp1, 1.0,
212 wsp2.get() + i * fnp0 * fnp1, fnp0, GP1->GetPtr().get(),
213 tnp1, 0.0, wsp1.get() + i * fnp0 * tnp1, fnp0);
214 }
215
216 GP0 = PointsManager()[tpoints0]->GetGalerkinProjection(fpoints0);
217 Blas::Dgemm('N', 'N', tnp0, tnp1 * tnp2, fnp0, 1.0, GP0->GetPtr().get(),
218 tnp0, wsp1.get(), fnp0, 0.0, to, tnp0);
219}
220
221} // 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 PhysGalerkinProject3D(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)
void PhysGalerkinProject1D(const BasisKey &fbasis0, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, Array< OneD, NekDouble > &to)
PointsManagerT & PointsManager(void)
void PhysGalerkinProject2D(const BasisKey &fbasis0, const BasisKey &fbasis1, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, Array< OneD, NekDouble > &to)
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