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 
38 #include <boost/core/ignore_unused.hpp>
39 
44 
45 #define OPERATOR_CREATE(cname) \
46  static OperatorKey m_type; \
47  static OperatorKey m_typeArr[]; \
48  friend class MemoryManager<cname>; \
49  static OperatorSharedPtr create( \
50  std::vector<StdRegions::StdExpansionSharedPtr> pCollExp,\
51  std::shared_ptr<CoalescedGeomData> GeomData) \
52  { \
53  return MemoryManager<cname> \
54  ::AllocateSharedPtr(pCollExp, GeomData); \
55  }
56 
57 namespace Nektar
58 {
59 namespace Collections
60 {
61 
62 class CoalescedGeomData;
63 typedef std::shared_ptr<CoalescedGeomData> CoalescedGeomDataSharedPtr;
64 
66 {
72 };
73 
74 const char* const OperatorTypeMap[] =
75 {
76  "BwdTrans",
77  "IProductWRTBase",
78  "IProductWRTDerivBase",
79  "PhysDeriv"
80 };
81 
83 {
90 };
91 
92 const char* const ImplementationTypeMap[] =
93 {
94  "NoImplementationType",
95  "NoCollection",
96  "IterPerExp",
97  "StdMat",
98  "SumFac"
99 };
100 
101 typedef bool ExpansionIsNodal;
102 
103 typedef std::map<OperatorType, ImplementationType> OperatorImpMap;
104 
105 /// simple Operator Implementation Map generator
106 OperatorImpMap SetFixedImpType(ImplementationType defaultType);
107 
108 /// Base class for operators on a collection of elements
109 class Operator
110 {
111  public:
112  /// Constructor
114  std::vector<StdRegions::StdExpansionSharedPtr> pCollExp,
115  std::shared_ptr<CoalescedGeomData> GeomData)
116  : m_stdExp(pCollExp[0]->GetStdExp()),
117  m_numElmt(pCollExp.size()),
118  m_wspSize(0)
119  {
120  boost::ignore_unused(GeomData);
121  }
122 
123  /// Perform operation
124  COLLECTIONS_EXPORT virtual void operator()(
125  const Array<OneD, const NekDouble> &input,
126  Array<OneD, NekDouble> &output0,
127  Array<OneD, NekDouble> &output1,
128  Array<OneD, NekDouble> &output2,
130  = NullNekDouble1DArray) = 0;
131 
132  COLLECTIONS_EXPORT virtual void operator()(
133  int dir,
134  const Array<OneD, const NekDouble> &input,
135  Array<OneD, NekDouble> &output,
137  = NullNekDouble1DArray) = 0;
138 
139  COLLECTIONS_EXPORT virtual ~Operator();
140 
141  /// Get the size of the required workspace
143  {
144  return m_wspSize;
145  }
146 
147  protected:
149  unsigned int m_numElmt;
150  unsigned int m_wspSize;
151 };
152 
153 /// Shared pointer to an Operator object
154 typedef std::shared_ptr<Operator> OperatorSharedPtr;
155 
156 /// Key for describing an Operator
157 typedef std::tuple<
159  OperatorType,
161  ExpansionIsNodal> OperatorKey;
162 
163 /// Less-than comparison operator for OperatorKey objects
164 bool operator< (OperatorKey const &p1, OperatorKey const &p2);
165 
166 /// Stream output operator for OperatorKey objects
167 std::ostream &operator<<(std::ostream &os, OperatorKey const &p);
168 
169 /// Operator factory definition
171  OperatorKey,
172  Operator,
173  std::vector<StdRegions::StdExpansionSharedPtr>,
174  CoalescedGeomDataSharedPtr> OperatorFactory;
175 
176 /// Returns the singleton Operator factory object
177 OperatorFactory& GetOperatorFactory();
178 
179 }
180 }
181 #endif
std::shared_ptr< CoalescedGeomData > CoalescedGeomDataSharedPtr
static Array< OneD, NekDouble > NullNekDouble1DArray
const char *const ImplementationTypeMap[]
Definition: Operator.h:92
std::tuple< LibUtilities::ShapeType, OperatorType, ImplementationType, ExpansionIsNodal > OperatorKey
Key for describing an Operator.
Definition: Operator.h:161
bool operator<(OperatorKey const &p1, OperatorKey const &p2)
Less-than comparison operator for OperatorKey objects.
Definition: Operator.cpp:44
Base class for operators on a collection of elements.
Definition: Operator.h:109
const char *const OperatorTypeMap[]
Definition: Operator.h:74
int GetWspSize()
Get the size of the required workspace.
Definition: Operator.h:142
std::ostream & operator<<(std::ostream &os, OperatorKey const &p)
Stream output operator for OperatorKey objects.
Definition: Operator.cpp:87
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
std::map< OperatorType, ImplementationType > OperatorImpMap
Definition: Operator.h:103
std::shared_ptr< Operator > OperatorSharedPtr
Shared pointer to an Operator object.
Definition: Operator.h:154
Operator(std::vector< StdRegions::StdExpansionSharedPtr > pCollExp, std::shared_ptr< CoalescedGeomData > GeomData)
Constructor.
Definition: Operator.h:113
OperatorFactory & GetOperatorFactory()
Returns the singleton Operator factory object.
Definition: Operator.cpp:108
StdRegions::StdExpansionSharedPtr m_stdExp
Definition: Operator.h:148
#define COLLECTIONS_EXPORT
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.
Nektar::LibUtilities::NekFactory< OperatorKey, Operator, std::vector< StdRegions::StdExpansionSharedPtr >, CoalescedGeomDataSharedPtr > OperatorFactory
Operator factory definition.
Definition: Operator.h:174
virtual COLLECTIONS_EXPORT ~Operator()
Definition: Operator.cpp:100
OperatorImpMap SetFixedImpType(ImplementationType defaultType)
simple Operator Implementation Map generator
Definition: Operator.cpp:117
Provides a generic Factory class.
Definition: NekFactory.hpp:103