Nektar++
InterpCoeff.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: InterpCoeff.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 for Coefficients
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
37 
41 
42 namespace Nektar
43 {
44 namespace LibUtilities
45 {
46 void InterpCoeff1D(const BasisKey &fbasis0,
47  const Array<OneD, const NekDouble> &from,
48  const BasisKey &tbasis0, Array<OneD, NekDouble> &to)
49 {
50  ASSERTL0(fbasis0.GetNumModes() == tbasis0.GetNumModes(),
51  "Number of modes must be the same for "
52  "interpolating coefficients");
53 
54  // Check to see if the same basis
55  if (fbasis0.GetBasisType() == tbasis0.GetBasisType())
56  {
57  Vmath::Vcopy(fbasis0.GetNumModes(), from, 1, to, 1);
58  }
59  else
60  {
61  // interpolate
62  DNekMatSharedPtr ftB = BasisManager()[fbasis0]->GetI(tbasis0);
63 
64  NekVector<NekDouble> in(fbasis0.GetNumModes(), from, eWrapper);
65  NekVector<NekDouble> out(tbasis0.GetNumModes(), to, eWrapper);
66 
67  out = (*ftB) * in;
68  }
69 }
70 
71 void InterpCoeff2D(const BasisKey &fbasis0, const BasisKey &fbasis1,
72  const Array<OneD, const NekDouble> &from,
73  const BasisKey &tbasis0, const BasisKey &tbasis1,
75 {
76  InterpCoeff2D(fbasis0, fbasis1, from.data(), tbasis0, tbasis1, to.data());
77 }
78 
79 void InterpCoeff2D(const BasisKey &fbasis0, const BasisKey &fbasis1,
80  const NekDouble *from, const BasisKey &tbasis0,
81  const BasisKey &tbasis1, NekDouble *to)
82 {
83  const int fnm0 = fbasis0.GetNumModes();
84  const int fnm1 = fbasis1.GetNumModes();
85  const int tnm0 = tbasis0.GetNumModes();
86  const int tnm1 = tbasis1.GetNumModes();
87 
88  Array<OneD, NekDouble> wsp(tnm1 * fnm0);
89 
90  if (fbasis1.GetBasisType() == tbasis1.GetBasisType())
91  {
92  Vmath::Vcopy(fnm0 * tnm1, from, 1, wsp.get(), 1);
93  }
94  else
95  {
96  // interpolate
97  DNekMatSharedPtr ft1 = BasisManager()[fbasis1]->GetI(tbasis1);
98 
99  Blas::Dgemm('N', 'T', fnm0, tnm1, fnm1, 1.0, from, fnm0,
100  ft1->GetPtr().get(), tnm1, 0.0, wsp.get(), fnm0);
101  }
102 
103  if (fbasis0.GetBasisType() == tbasis0.GetBasisType())
104  {
105  Vmath::Vcopy(tnm0 * tnm1, wsp.get(), 1, to, 1);
106  }
107  else
108  {
109  // interpolate
110  DNekMatSharedPtr ft0 = BasisManager()[fbasis0]->GetI(tbasis0);
111 
112  Blas::Dgemm('N', 'N', tnm0, tnm1, fnm0, 1.0, ft0->GetPtr().get(), tnm0,
113  wsp.get(), fnm0, 0.0, to, tnm0);
114  }
115 }
116 
117 void InterpCoeff3D(const BasisKey &fbasis0, const BasisKey &fbasis1,
118  const BasisKey &fbasis2,
119  const Array<OneD, const NekDouble> &from,
120  const BasisKey &tbasis0, const BasisKey &tbasis1,
121  const BasisKey &tbasis2, Array<OneD, NekDouble> &to)
122 {
123  InterpCoeff3D(fbasis0, fbasis1, fbasis2, from.data(), tbasis0, tbasis1,
124  tbasis2, to.data());
125 }
126 
127 void InterpCoeff3D(const BasisKey &fbasis0, const BasisKey &fbasis1,
128  const BasisKey &fbasis2, const NekDouble *from,
129  const BasisKey &tbasis0, const BasisKey &tbasis1,
130  const BasisKey &tbasis2, NekDouble *to)
131 {
132  const int fnm0 = fbasis0.GetNumModes();
133  const int fnm1 = fbasis1.GetNumModes();
134  const int fnm2 = fbasis2.GetNumModes();
135  const int tnm0 = tbasis0.GetNumModes();
136  const int tnm1 = tbasis1.GetNumModes();
137  const int tnm2 = tbasis2.GetNumModes();
138 
139  Array<OneD, NekDouble> wsp1(tnm0 * tnm1 * fnm2);
140  Array<OneD, NekDouble> wsp2(tnm0 * fnm1 * fnm2);
141 
142  DNekMatSharedPtr ft0 = BasisManager()[fbasis0]->GetI(tbasis0);
143  DNekMatSharedPtr ft1 = BasisManager()[fbasis1]->GetI(tbasis1);
144  DNekMatSharedPtr ft2 = BasisManager()[fbasis2]->GetI(tbasis2);
145 
146  Blas::Dgemm('N', 'N', tnm0, fnm1 * fnm2, fnm0, 1.0, ft0->GetPtr().get(),
147  tnm0, from, fnm0, 0.0, wsp2.get(), tnm0);
148 
149  for (int i = 0; i < fnm2; i++)
150  {
151  Blas::Dgemm('N', 'T', tnm0, tnm1, fnm1, 1.0,
152  wsp2.get() + i * tnm0 * fnm1, tnm0, ft1->GetPtr().get(),
153  tnm1, 0.0, wsp1.get() + i * tnm0 * tnm1, tnm0);
154  }
155 
156  Blas::Dgemm('N', 'T', tnm0 * tnm1, tnm2, fnm2, 1.0, wsp1.get(), tnm0 * tnm1,
157  ft2->GetPtr().get(), tnm2, 0.0, to, tnm0 * tnm1);
158 }
159 } // namespace LibUtilities
160 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
Describes the specification for a Basis.
Definition: Basis.h:50
BasisType GetBasisType() const
Return type of expansion basis.
Definition: Basis.h:141
int GetNumModes() const
Returns the order of the basis.
Definition: Basis.h:83
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
BasisManagerT & BasisManager(void)
void InterpCoeff2D(const BasisKey &fbasis0, const BasisKey &fbasis1, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, Array< OneD, NekDouble > &to)
Definition: InterpCoeff.cpp:71
void InterpCoeff3D(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 InterpCoeff1D(const BasisKey &fbasis0, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, Array< OneD, NekDouble > &to)
Definition: InterpCoeff.cpp:46
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