Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Definition of Interpolation methods for Coefficients
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
38 
42 
43 namespace Nektar
44 {
45  namespace LibUtilities
46  {
47  void InterpCoeff1D(const BasisKey &fbasis0,
48  const Array<OneD, const NekDouble>& from,
49  const BasisKey &tbasis0,
51  {
52  ASSERTL0(fbasis0.GetNumModes() == tbasis0.GetNumModes(),
53  "Number of modes must be the same for "
54  "interpolating coefficients");
55 
56  // Check to see if the same basis
57  if (fbasis0.GetBasisType() == tbasis0.GetBasisType())
58  {
59  Vmath::Vcopy(fbasis0.GetNumModes(), from, 1, to, 1);
60  }
61  else
62  {
63  // interpolate
64  DNekMatSharedPtr ftB = BasisManager()[fbasis0]->GetI(tbasis0);
65 
66  NekVector<NekDouble> in (fbasis0.GetNumModes(), from, eWrapper);
67  NekVector<NekDouble> out(tbasis0.GetNumModes(), to, eWrapper);
68 
69  out = (*ftB)*in;
70  }
71  }
72 
73  void InterpCoeff2D(const BasisKey &fbasis0,
74  const BasisKey &fbasis1,
75  const Array<OneD, const NekDouble>& from,
76  const BasisKey &tbasis0,
77  const BasisKey &tbasis1,
79  {
80  InterpCoeff2D(fbasis0, fbasis1, from.data(),
81  tbasis0, tbasis1, to. data());
82  }
83 
84  void InterpCoeff2D(const BasisKey &fbasis0,
85  const BasisKey &fbasis1,
86  const NekDouble *from,
87  const BasisKey &tbasis0,
88  const BasisKey &tbasis1,
89  NekDouble *to)
90  {
91  const int fnm0 = fbasis0.GetNumModes();
92  const int fnm1 = fbasis1.GetNumModes();
93  const int tnm0 = tbasis0.GetNumModes();
94  const int tnm1 = tbasis1.GetNumModes();
95 
96  Array<OneD, NekDouble> wsp(tnm1 * fnm0);
97 
98  if (fbasis1.GetBasisType() == tbasis1.GetBasisType())
99  {
100  Vmath::Vcopy(fnm0*tnm1, from, 1, wsp.get(), 1);
101  }
102  else
103  {
104  // interpolate
105  DNekMatSharedPtr ft1 = BasisManager()[fbasis1]->GetI(tbasis1);
106 
107  Blas::Dgemm('N', 'T', fnm0, tnm1, fnm1, 1.0, from, fnm0,
108  ft1->GetPtr().get(), tnm1, 0.0, wsp.get(), fnm0);
109  }
110 
111  if (fbasis0.GetBasisType() == tbasis0.GetBasisType())
112  {
113  Vmath::Vcopy(tnm0*tnm1, wsp.get(), 1, to, 1);
114  }
115  else
116  {
117  // interpolate
118  DNekMatSharedPtr ft0 = BasisManager()[fbasis0]->GetI(tbasis0);
119 
120  Blas::Dgemm('N', 'N', tnm0, tnm1, fnm0, 1.0, ft0->GetPtr().get(),
121  tnm0, wsp.get(), fnm0, 0.0, to, tnm0);
122  }
123  }
124 
125  void InterpCoeff3D(const BasisKey &fbasis0,
126  const BasisKey &fbasis1,
127  const BasisKey &fbasis2,
128  const Array<OneD, const NekDouble>& from,
129  const BasisKey &tbasis0,
130  const BasisKey &tbasis1,
131  const BasisKey &tbasis2,
133  {
134  InterpCoeff3D(fbasis0, fbasis1, fbasis2, from.data(),
135  tbasis0, tbasis1, tbasis2, to. data());
136  }
137 
138  void InterpCoeff3D(const BasisKey &fbasis0,
139  const BasisKey &fbasis1,
140  const BasisKey &fbasis2,
141  const NekDouble *from,
142  const BasisKey &tbasis0,
143  const BasisKey &tbasis1,
144  const BasisKey &tbasis2,
145  NekDouble *to)
146  {
147  const int fnm0 = fbasis0.GetNumModes();
148  const int fnm1 = fbasis1.GetNumModes();
149  const int fnm2 = fbasis2.GetNumModes();
150  const int tnm0 = tbasis0.GetNumModes();
151  const int tnm1 = tbasis1.GetNumModes();
152  const int tnm2 = tbasis2.GetNumModes();
153 
154  Array<OneD, NekDouble> wsp1(tnm0 * tnm1 * fnm2);
155  Array<OneD, NekDouble> wsp2(tnm0 * fnm1 * fnm2);
156 
157  DNekMatSharedPtr ft0 = BasisManager()[fbasis0]->GetI(tbasis0);
158  DNekMatSharedPtr ft1 = BasisManager()[fbasis1]->GetI(tbasis1);
159  DNekMatSharedPtr ft2 = BasisManager()[fbasis2]->GetI(tbasis2);
160 
161  Blas::Dgemm('N', 'N', tnm0, fnm1*fnm2, fnm0, 1.0,
162  ft0->GetPtr().get(), tnm0, from, fnm0, 0.0,
163  wsp2.get(), tnm0);
164 
165  for (int i = 0; i < fnm2; i++)
166  {
167  Blas::Dgemm('N', 'T', tnm0, tnm1, fnm1, 1.0,
168  wsp2.get()+i*tnm0*fnm1, tnm0, ft1->GetPtr().get(),
169  tnm1, 0.0, wsp1.get()+i*tnm0*tnm1, tnm0);
170  }
171 
172  Blas::Dgemm('N', 'T', tnm0*tnm1, tnm2, fnm2, 1.0, wsp1.get(),
173  tnm0*tnm1, ft2->GetPtr().get(), tnm2,
174  0.0, to, tnm0*tnm1);
175  }
176  }
177 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
void InterpCoeff1D(const BasisKey &fbasis0, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, Array< OneD, NekDouble > &to)
Definition: InterpCoeff.cpp:47
BasisType GetBasisType() const
Return type of expansion basis.
Definition: Basis.h:139
boost::shared_ptr< DNekMat > DNekMatSharedPtr
Definition: NekTypeDefs.hpp:70
BasisManagerT & BasisManager(void)
double NekDouble
int GetNumModes() const
Returns the order of the basis.
Definition: Basis.h:84
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 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:73
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1047
Describes the specification for a Basis.
Definition: Basis.h:50