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