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,
50  {
51  ASSERTL0(fbasis0.GetNumModes() == tbasis0.GetNumModes(),
52  "Number of modes must be the same for "
53  "interpolating coefficients");
54 
55  // Check to see if the same basis
56  if (fbasis0.GetBasisType() == tbasis0.GetBasisType())
57  {
58  Vmath::Vcopy(fbasis0.GetNumModes(), from, 1, to, 1);
59  }
60  else
61  {
62  // interpolate
63  DNekMatSharedPtr ftB = BasisManager()[fbasis0]->GetI(tbasis0);
64 
65  NekVector<NekDouble> in (fbasis0.GetNumModes(), from, eWrapper);
66  NekVector<NekDouble> out(tbasis0.GetNumModes(), to, eWrapper);
67 
68  out = (*ftB)*in;
69  }
70  }
71 
72  void InterpCoeff2D(const BasisKey &fbasis0,
73  const BasisKey &fbasis1,
74  const Array<OneD, const NekDouble>& from,
75  const BasisKey &tbasis0,
76  const BasisKey &tbasis1,
78  {
79  InterpCoeff2D(fbasis0, fbasis1, from.data(),
80  tbasis0, tbasis1, to. data());
81  }
82 
83  void InterpCoeff2D(const BasisKey &fbasis0,
84  const BasisKey &fbasis1,
85  const NekDouble *from,
86  const BasisKey &tbasis0,
87  const BasisKey &tbasis1,
88  NekDouble *to)
89  {
90  const int fnm0 = fbasis0.GetNumModes();
91  const int fnm1 = fbasis1.GetNumModes();
92  const int tnm0 = tbasis0.GetNumModes();
93  const int tnm1 = tbasis1.GetNumModes();
94 
95  Array<OneD, NekDouble> wsp(tnm1 * fnm0);
96 
97  if (fbasis1.GetBasisType() == tbasis1.GetBasisType())
98  {
99  Vmath::Vcopy(fnm0*tnm1, from, 1, wsp.get(), 1);
100  }
101  else
102  {
103  // interpolate
104  DNekMatSharedPtr ft1 = BasisManager()[fbasis1]->GetI(tbasis1);
105 
106  Blas::Dgemm('N', 'T', fnm0, tnm1, fnm1, 1.0, from, fnm0,
107  ft1->GetPtr().get(), tnm1, 0.0, wsp.get(), fnm0);
108  }
109 
110  if (fbasis0.GetBasisType() == tbasis0.GetBasisType())
111  {
112  Vmath::Vcopy(tnm0*tnm1, wsp.get(), 1, to, 1);
113  }
114  else
115  {
116  // interpolate
117  DNekMatSharedPtr ft0 = BasisManager()[fbasis0]->GetI(tbasis0);
118 
119  Blas::Dgemm('N', 'N', tnm0, tnm1, fnm0, 1.0, ft0->GetPtr().get(),
120  tnm0, wsp.get(), fnm0, 0.0, to, tnm0);
121  }
122  }
123 
124  void InterpCoeff3D(const BasisKey &fbasis0,
125  const BasisKey &fbasis1,
126  const BasisKey &fbasis2,
127  const Array<OneD, const NekDouble>& from,
128  const BasisKey &tbasis0,
129  const BasisKey &tbasis1,
130  const BasisKey &tbasis2,
132  {
133  InterpCoeff3D(fbasis0, fbasis1, fbasis2, from.data(),
134  tbasis0, tbasis1, tbasis2, to. data());
135  }
136 
137  void InterpCoeff3D(const BasisKey &fbasis0,
138  const BasisKey &fbasis1,
139  const BasisKey &fbasis2,
140  const NekDouble *from,
141  const BasisKey &tbasis0,
142  const BasisKey &tbasis1,
143  const BasisKey &tbasis2,
144  NekDouble *to)
145  {
146  const int fnm0 = fbasis0.GetNumModes();
147  const int fnm1 = fbasis1.GetNumModes();
148  const int fnm2 = fbasis2.GetNumModes();
149  const int tnm0 = tbasis0.GetNumModes();
150  const int tnm1 = tbasis1.GetNumModes();
151  const int tnm2 = tbasis2.GetNumModes();
152 
153  Array<OneD, NekDouble> wsp1(tnm0 * tnm1 * fnm2);
154  Array<OneD, NekDouble> wsp2(tnm0 * fnm1 * fnm2);
155 
156  DNekMatSharedPtr ft0 = BasisManager()[fbasis0]->GetI(tbasis0);
157  DNekMatSharedPtr ft1 = BasisManager()[fbasis1]->GetI(tbasis1);
158  DNekMatSharedPtr ft2 = BasisManager()[fbasis2]->GetI(tbasis2);
159 
160  Blas::Dgemm('N', 'N', tnm0, fnm1*fnm2, fnm0, 1.0,
161  ft0->GetPtr().get(), tnm0, from, fnm0, 0.0,
162  wsp2.get(), tnm0);
163 
164  for (int i = 0; i < fnm2; i++)
165  {
166  Blas::Dgemm('N', 'T', tnm0, tnm1, fnm1, 1.0,
167  wsp2.get()+i*tnm0*fnm1, tnm0, ft1->GetPtr().get(),
168  tnm1, 0.0, wsp1.get()+i*tnm0*tnm1, tnm0);
169  }
170 
171  Blas::Dgemm('N', 'T', tnm0*tnm1, tnm2, fnm2, 1.0, wsp1.get(),
172  tnm0*tnm1, ft2->GetPtr().get(), tnm2,
173  0.0, to, tnm0*tnm1);
174  }
175  }
176 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
Describes the specification for a Basis.
Definition: Basis.h:50
BasisType GetBasisType() const
Return type of expansion basis.
Definition: Basis.h:144
int GetNumModes() const
Returns the order of the basis.
Definition: Basis.h:86
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:394
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:72
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:1
std::shared_ptr< DNekMat > DNekMatSharedPtr
Definition: NekTypeDefs.hpp:69
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1199