Nektar++
Operator.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: Operator.h
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: Operator top class definition
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_LIBRARY_COLLECTIONS_OPERATOR_H
36#define NEKTAR_LIBRARY_COLLECTIONS_OPERATOR_H
37
42
43#define OPERATOR_CREATE(cname) \
44 static OperatorKey m_type; \
45 static OperatorKey m_typeArr[]; \
46 friend class MemoryManager<cname>; \
47 static OperatorSharedPtr create( \
48 std::vector<StdRegions::StdExpansionSharedPtr> pCollExp, \
49 std::shared_ptr<CoalescedGeomData> GeomData, \
50 StdRegions::FactorMap factors) \
51 { \
52 return MemoryManager<cname>::AllocateSharedPtr(pCollExp, GeomData, \
53 factors); \
54 }
55
56namespace Nektar::Collections
57{
58
59class CoalescedGeomData;
60typedef std::shared_ptr<CoalescedGeomData> CoalescedGeomDataSharedPtr;
61
63{
71};
72
73const char *const OperatorTypeMap[] = {
74 "BwdTrans", "Helmholtz", "IProductWRTBase", "IProductWRTDerivBase",
75 "PhysDeriv", "PhysInterp1DScaled"};
76
77const char *const OperatorTypeMap1[] = {"BwdTrans", "Helmholtz",
78 "IPWrtBase", "IPWrtDBase",
79 "PhysDeriv", "PhysInterp1DScaled"};
80
82{
90};
91
92const char *const ImplementationTypeMap[] = {"NoImplementationType",
93 "NoCollection",
94 "IterPerExp",
95 "StdMat",
96 "SumFac",
97 "MatrixFree"};
98
99const char *const ImplementationTypeMap1[] = {
100 "NoImplementationType",
101 "IterLocExp", // formerly "NoCollection"
102 "IterStdExp", // formerly "IterPerExp"
103 "StdMat ",
104 "SumFac ",
105 "MatFree " // formerly "MatrixFree"
106};
107
108typedef bool ExpansionIsNodal;
109
110class Operator;
111
112/// Key for describing an Operator
116
117/// Operator factory definition
119 OperatorKey, Operator, std::vector<StdRegions::StdExpansionSharedPtr>,
122
123/// Returns the singleton Operator factory object
125
126typedef std::map<OperatorType, ImplementationType> OperatorImpMap;
127
128/// simple Operator Implementation Map generator
130
131/// Base class for operators on a collection of elements
133{
134public:
135 /// Constructor
136 Operator(std::vector<StdRegions::StdExpansionSharedPtr> pCollExp,
137 std::shared_ptr<CoalescedGeomData> GeomData,
139
140 virtual ~Operator() = default;
141
142 /// Perform operation
144 const Array<OneD, const NekDouble> &input,
146 Array<OneD, NekDouble> &output2,
148
150 int dir, const Array<OneD, const NekDouble> &input,
153
154 /// Check the validity of the supplied factor map
156 int coll_phys_offset) = 0;
157
158 /// Get the size of the required workspace
159 unsigned int GetWspSize()
160 {
161 return m_wspSize;
162 }
163
164 /// Get number of elements
165 unsigned int GetNumElmt()
166 {
167 return m_numElmt;
168 }
169
170 /// Get expansion pointer
172 {
173 return m_stdExp;
174 }
175
176 inline unsigned int GetInputSize()
177 {
178 return m_inputSize;
179 }
180
181 inline unsigned int GetOutputSize()
182 {
183 return m_outputSize;
184 }
185
186protected:
189 /// number of elements that the operator is applied on
190 unsigned int m_numElmt;
191 unsigned int m_nqe;
192 unsigned int m_wspSize;
193 /// number of modes or quadrature points that are passed as input to an
194 /// operator
195 unsigned int m_inputSize;
196 /// number of modes or quadrature points that are taken as output from an
197 /// operator
198 unsigned int m_outputSize;
199
200 /// @brief This purely virtual function needs to be set-up for every
201 /// operator inside Collections. It is responsible for returning the size of
202 /// input collection, that the operator is applied on either in physical or
203 /// coefficient space.
204 /// @return Returns 0. The actual implementation is inside the specific
205 /// operator class.
206 virtual int v_GetInputSize()
207 {
209 "This method is not defined or valid for this class type");
210 return 0;
211 }
212 /// @brief This purely virtual function needs to be set-up for every
213 /// operator inside Collections. It is responsible for returning the output
214 /// size either in physical or coefficient space of an operator inside
215 /// Collections.
216 /// @return Returns 0. The actual implementation is inside the specific
217 /// operator class.
218 virtual int v_GetOutputSize()
219 {
221 "This method is not defined or valid for this class type");
222 return 0;
223 }
224};
225
226/// Shared pointer to an Operator object
227typedef std::shared_ptr<Operator> OperatorSharedPtr;
228
229/// Less-than comparison operator for OperatorKey objects
230bool operator<(OperatorKey const &p1, OperatorKey const &p2);
231
232/// Stream output operator for OperatorKey objects
233std::ostream &operator<<(std::ostream &os, OperatorKey const &p);
234
235} // namespace Nektar::Collections
236
237#endif
#define COLLECTIONS_EXPORT
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
Base class for operators on a collection of elements.
Definition: Operator.h:133
unsigned int GetNumElmt()
Get number of elements.
Definition: Operator.h:165
virtual ~Operator()=default
virtual COLLECTIONS_EXPORT void operator()(int dir, const Array< OneD, const NekDouble > &input, Array< OneD, NekDouble > &output, Array< OneD, NekDouble > &wsp=NullNekDouble1DArray)=0
virtual COLLECTIONS_EXPORT void operator()(const Array< OneD, const NekDouble > &input, Array< OneD, NekDouble > &output0, Array< OneD, NekDouble > &output1, Array< OneD, NekDouble > &output2, Array< OneD, NekDouble > &wsp=NullNekDouble1DArray)=0
Perform operation.
virtual COLLECTIONS_EXPORT void CheckFactors(StdRegions::FactorMap factors, int coll_phys_offset)=0
Check the validity of the supplied factor map.
StdRegions::StdExpansionSharedPtr m_stdExp
Definition: Operator.h:188
unsigned int m_numElmt
number of elements that the operator is applied on
Definition: Operator.h:190
unsigned int GetInputSize()
Definition: Operator.h:176
unsigned int m_outputSize
number of modes or quadrature points that are taken as output from an operator
Definition: Operator.h:198
unsigned int GetWspSize()
Get the size of the required workspace.
Definition: Operator.h:159
unsigned int m_inputSize
number of modes or quadrature points that are passed as input to an operator
Definition: Operator.h:195
StdRegions::StdExpansionSharedPtr GetExpSharedPtr()
Get expansion pointer.
Definition: Operator.h:171
virtual int v_GetOutputSize()
This purely virtual function needs to be set-up for every operator inside Collections....
Definition: Operator.h:218
virtual int v_GetInputSize()
This purely virtual function needs to be set-up for every operator inside Collections....
Definition: Operator.h:206
Operator(std::vector< StdRegions::StdExpansionSharedPtr > pCollExp, std::shared_ptr< CoalescedGeomData > GeomData, StdRegions::FactorMap factors)
Constructor.
Definition: Operator.cpp:66
unsigned int GetOutputSize()
Definition: Operator.h:181
Provides a generic Factory class.
Definition: NekFactory.hpp:104
bool operator<(OperatorKey const &p1, OperatorKey const &p2)
Less-than comparison operator for OperatorKey objects.
Definition: Operator.cpp:78
std::map< OperatorType, ImplementationType > OperatorImpMap
Definition: Operator.h:126
const char *const ImplementationTypeMap[]
Definition: Operator.h:92
std::shared_ptr< Operator > OperatorSharedPtr
Shared pointer to an Operator object.
Definition: Operator.h:227
const char *const ImplementationTypeMap1[]
Definition: Operator.h:99
std::ostream & operator<<(std::ostream &os, OperatorKey const &p)
Stream output operator for OperatorKey objects.
Definition: Operator.cpp:120
const char *const OperatorTypeMap[]
Definition: Operator.h:73
std::tuple< LibUtilities::ShapeType, OperatorType, ImplementationType, ExpansionIsNodal > OperatorKey
Key for describing an Operator.
Definition: Operator.h:115
std::shared_ptr< CoalescedGeomData > CoalescedGeomDataSharedPtr
OperatorFactory & GetOperatorFactory()
Returns the singleton Operator factory object.
Definition: Operator.cpp:44
OperatorImpMap SetFixedImpType(ImplementationType defaultType)
simple Operator Implementation Map generator
Definition: Operator.cpp:51
Nektar::LibUtilities::NekFactory< OperatorKey, Operator, std::vector< StdRegions::StdExpansionSharedPtr >, CoalescedGeomDataSharedPtr, StdRegions::FactorMap > OperatorFactory
Operator factory definition.
Definition: Operator.h:121
const char *const OperatorTypeMap1[]
Definition: Operator.h:77
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
ConstFactorMap FactorMap
Definition: StdRegions.hpp:406
StdRegions::ConstFactorMap factors
static Array< OneD, NekDouble > NullNekDouble1DArray