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{
72};
73
74const char *const OperatorTypeMap[] = {"BwdTrans",
75 "Helmholtz",
76 "LinearAdvectionDiffusionReaction",
77 "IProductWRTBase",
78 "IProductWRTDerivBase",
79 "PhysDeriv",
80 "PhysInterp1DScaled"};
81
82const char *const OperatorTypeMap1[] = {
83 "BwdTrans", "Helmholtz", "LinearADR", "IPWrtBase",
84 "IPWrtDBase", "PhysDeriv", "PhysInterp1DScaled"};
85
87{
95};
96
97const char *const ImplementationTypeMap[] = {"NoImplementationType",
98 "NoCollection",
99 "IterPerExp",
100 "StdMat",
101 "SumFac",
102 "MatrixFree"};
103
104const char *const ImplementationTypeMap1[] = {
105 "NoImplementationType",
106 "IterLocExp", // formerly "NoCollection"
107 "IterStdExp", // formerly "IterPerExp"
108 "StdMat ",
109 "SumFac ",
110 "MatFree " // formerly "MatrixFree"
111};
112
113typedef bool ExpansionIsNodal;
114
115class Operator;
116
117/// Key for describing an Operator
121
122/// Operator factory definition
124 OperatorKey, Operator, std::vector<StdRegions::StdExpansionSharedPtr>,
127
128/// Returns the singleton Operator factory object
130
131typedef std::map<OperatorType, ImplementationType> OperatorImpMap;
132
133/// simple Operator Implementation Map generator
135
136/// Base class for operators on a collection of elements
138{
139public:
140 /// Constructor
141 Operator(std::vector<StdRegions::StdExpansionSharedPtr> pCollExp,
142 std::shared_ptr<CoalescedGeomData> GeomData,
144
145 virtual ~Operator() = default;
146
147 /// Perform operation
149 const Array<OneD, const NekDouble> &input,
151 Array<OneD, NekDouble> &output2,
153
155 int dir, const Array<OneD, const NekDouble> &input,
158
159 /// Update the supplied factor map
161 [[maybe_unused]] StdRegions::FactorMap factors)
162 {
163 ASSERTL0(false, "This method needs to be re-implemented in derived "
164 "operator class.");
165 }
166
167 /// Update the supplied variable coefficients
169 [[maybe_unused]] StdRegions::VarCoeffMap &varcoeffs)
170 {
171 ASSERTL0(false,
172 "This method needs to be re-implemented in derived "
173 "operator class. Make sure it is implemented for the operator"
174 " in the .opt file");
175 }
176
177 /// Get the size of the required workspace
178 unsigned int GetWspSize()
179 {
180 return m_wspSize;
181 }
182
183 /// Get number of elements
184 unsigned int GetNumElmt()
185 {
186 return m_numElmt;
187 }
188
189 /// Get expansion pointer
191 {
192 return m_stdExp;
193 }
194
195 /*
196 * Return the input size for this collection.
197 * Optionally return the size for the opposite (Phys or Coeff) space.
198 */
199 inline unsigned int GetInputSize(bool defaultIn = true)
200 {
201 return (m_inputSizeOther && !defaultIn) ? m_inputSizeOther
202 : m_inputSize;
203 }
204
205 /*
206 * Return the output size for this collection.
207 * Optionally return the size for the opposite (Phys or Coeff) space.
208 */
209 inline unsigned int GetOutputSize(bool defaultOut = true)
210 {
211 return (m_outputSizeOther && !defaultOut) ? m_outputSizeOther
212 : m_outputSize;
213 }
214
215protected:
218 /// number of elements that the operator is applied on
219 unsigned int m_numElmt;
220 unsigned int m_nqe;
221 unsigned int m_wspSize;
222 /// number of modes or quadrature points that are passed as input to an
223 /// operator
224 unsigned int m_inputSize;
225 /// number of modes or quadrature points that are taken as output from an
226 /// operator
227 unsigned int m_outputSize;
228 /// Number of modes or quadrature points, opposite to m_inputSize
229 unsigned int m_inputSizeOther;
230 /// Number of modes or quadrature points, opposite to m_outputSize
231 unsigned int m_outputSizeOther;
232};
233
234/// Shared pointer to an Operator object
235typedef std::shared_ptr<Operator> OperatorSharedPtr;
236
237/// Less-than comparison operator for OperatorKey objects
238bool operator<(OperatorKey const &p1, OperatorKey const &p2);
239
240/// Stream output operator for OperatorKey objects
241std::ostream &operator<<(std::ostream &os, OperatorKey const &p);
242
243} // namespace Nektar::Collections
244
245#endif
#define COLLECTIONS_EXPORT
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
Base class for operators on a collection of elements.
Definition: Operator.h:138
unsigned int GetNumElmt()
Get number of elements.
Definition: Operator.h:184
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 UpdateFactors(StdRegions::FactorMap factors)
Update the supplied factor map.
Definition: Operator.h:160
StdRegions::StdExpansionSharedPtr m_stdExp
Definition: Operator.h:217
unsigned int m_outputSizeOther
Number of modes or quadrature points, opposite to m_outputSize.
Definition: Operator.h:231
unsigned int m_numElmt
number of elements that the operator is applied on
Definition: Operator.h:219
unsigned int m_inputSizeOther
Number of modes or quadrature points, opposite to m_inputSize.
Definition: Operator.h:229
unsigned int m_outputSize
number of modes or quadrature points that are taken as output from an operator
Definition: Operator.h:227
unsigned int GetWspSize()
Get the size of the required workspace.
Definition: Operator.h:178
unsigned int GetOutputSize(bool defaultOut=true)
Definition: Operator.h:209
unsigned int m_inputSize
number of modes or quadrature points that are passed as input to an operator
Definition: Operator.h:224
StdRegions::StdExpansionSharedPtr GetExpSharedPtr()
Get expansion pointer.
Definition: Operator.h:190
Operator(std::vector< StdRegions::StdExpansionSharedPtr > pCollExp, std::shared_ptr< CoalescedGeomData > GeomData, StdRegions::FactorMap factors)
Constructor.
Definition: Operator.cpp:66
virtual COLLECTIONS_EXPORT void UpdateVarcoeffs(StdRegions::VarCoeffMap &varcoeffs)
Update the supplied variable coefficients.
Definition: Operator.h:168
unsigned int GetInputSize(bool defaultIn=true)
Definition: Operator.h:199
Provides a generic Factory class.
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:131
const char *const ImplementationTypeMap[]
Definition: Operator.h:97
std::shared_ptr< Operator > OperatorSharedPtr
Shared pointer to an Operator object.
Definition: Operator.h:235
const char *const ImplementationTypeMap1[]
Definition: Operator.h:104
@ eLinearAdvectionDiffusionReaction
Definition: Operator.h:66
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:74
std::tuple< LibUtilities::ShapeType, OperatorType, ImplementationType, ExpansionIsNodal > OperatorKey
Key for describing an Operator.
Definition: Operator.h:120
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:126
const char *const OperatorTypeMap1[]
Definition: Operator.h:82
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
ConstFactorMap FactorMap
Definition: StdRegions.hpp:434
std::map< StdRegions::VarCoeffType, VarCoeffEntry > VarCoeffMap
Definition: StdRegions.hpp:375
StdRegions::ConstFactorMap factors
static Array< OneD, NekDouble > NullNekDouble1DArray