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