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