Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Nektar::MultiRegions::Operator< TData > Class Template Reference

Common base class of the operator family interfaces: holds the expansion list, component names and data warehouse an operator was built with, and provides the family-agnostic Create() and GetOpExecSpace(). More...

#include <Operator.hpp>

Inheritance diagram for Nektar::MultiRegions::Operator< TData >:
[legend]

Public Member Functions

virtual ~Operator ()=default
 
 Operator (const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > components)
 Construct the interface part of a concrete operator; called by the factory-registered creator functions.
 

Static Public Member Functions

template<template< typename > typename TOperator>
static std::shared_ptr< TOperator< TData > > Create (const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > components, const std::string &execStr)
 Create a concrete operator instance through the operator factory.
 
static std::string GetOpExecSpace (std::shared_ptr< LibUtilities::SessionReader > session, const bool warn=true)
 Return the execution space name ("opExecSpace") for an operator.
 
static const DefaultOpImplRule * GetDefaultOpImplRule (const StdRegions::StdExpansionSharedPtr &exp, const std::string &execSpace)
 Return the row of the default implementation table (DefaultOpImplTable.hpp) that a block of elements takes, or null if none does.
 
static std::string GetDefaultOpImpl (const StdRegions::StdExpansionSharedPtr &exp, const std::string &execSpace)
 Return the implementation a block of elements takes when neither the command line nor the session names one for its operator.
 
static std::vector< unsigned int > GetDefaultInterleaveWidths (const MultiRegions::ExpListSharedPtr &expansionList)
 Return the default interleave widths, one per block of expansionList, that persistent Fields (e.g. solution storage, time-integration and linear-solver workspace) built on it should be constructed with.
 
static bool IsDiscontinuousProjection (std::shared_ptr< LibUtilities::SessionReader > session)
 Return true if the session uses a Discontinuous (DG) projection.
 

Protected Attributes

MultiRegions::ExpListSharedPtr m_expansionList
 Expansion list the operator acts on.
 
std::vector< std::string > m_components
 Names of the field components the operator was built for.
 
LibUtilities::NekDataWarehouseSharedPtr m_dataWarehouse
 Data warehouse shared with the other operators on the expansion list, used to build and cache shared tables (basis matrices, mode indices, geometric factors) once.
 

Detailed Description

template<typename TData>
class Nektar::MultiRegions::Operator< TData >

Common base class of the operator family interfaces: holds the expansion list, component names and data warehouse an operator was built with, and provides the family-agnostic Create() and GetOpExecSpace().

Template Parameters
TDataFloating-point type of the field data.
See also
ElmtOp for the element-by-element specialisation that adds the per-block factory stage.

Definition at line 99 of file Operator.hpp.

Constructor & Destructor Documentation

◆ ~Operator()

template<typename TData >
virtual Nektar::MultiRegions::Operator< TData >::~Operator ( )
virtualdefault

◆ Operator()

template<typename TData >
Nektar::MultiRegions::Operator< TData >::Operator ( const MultiRegions::ExpListSharedPtr &  expansionList,
const std::vector< std::string >  components 
)
inline

Construct the interface part of a concrete operator; called by the factory-registered creator functions.

Parameters
expansionListExpansion list the operator acts on.
componentsNames of the field components the operator is set up for.

Definition at line 112 of file Operator.hpp.

114 : m_expansionList(expansionList), m_components(components),
115 m_dataWarehouse(expansionList->GetDataWarehouseSharedPtr())
116 {
117 }
std::vector< std::string > m_components
Names of the field components the operator was built for.
Definition Operator.hpp:351
MultiRegions::ExpListSharedPtr m_expansionList
Expansion list the operator acts on.
Definition Operator.hpp:349
LibUtilities::NekDataWarehouseSharedPtr m_dataWarehouse
Data warehouse shared with the other operators on the expansion list, used to build and cache shared ...
Definition Operator.hpp:355

Member Function Documentation

◆ Create()

template<typename TData >
template<template< typename > typename TOperator>
static std::shared_ptr< TOperator< TData > > Nektar::MultiRegions::Operator< TData >::Create ( const MultiRegions::ExpListSharedPtr &  expansionList,
const std::vector< std::string >  components,
const std::string &  execStr 
)
inlinestatic

Create a concrete operator instance through the operator factory.

The factory key is TOperator::name + execStr, where an empty execStr is resolved by GetOpExecSpace(). The product is handed back through a static_pointer_cast to TOperator, so the creator registered under the key must construct that class or one derived from it.

Template Parameters
TOperatorFamily interface class supplying the static name string.
Parameters
expansionListExpansion list the operator acts on.
componentsNames of the field components the operator is set up for.
execStrExecution space ("Serial", "AVX" or "Device"); if empty, GetOpExecSpace() supplies it from the session's "opExecSpace" command-line argument or, failing that, the build's default, with a warning.
Returns
The newly created operator. Creation raises a fatal error (throws ErrorUtil::NekError) if no implementation is registered under the requested key.

Definition at line 147 of file Operator.hpp.

150 {
151 auto session = expansionList->GetSession();
152
153 std::string execStr0 = (execStr == "")
155 : execStr;
156
157 std::string requestedKey = TOperator<TData>::name + execStr0;
158
159 OperatorFactory<TData> &factory = GetOperatorFactory<TData>();
160
161 // No suitable operator was found.
162 if (!factory.ModuleExists(requestedKey))
163 {
164 std::stringstream msg;
165 msg << "No such operator: " << requestedKey << std::endl;
166 factory.PrintAvailableClasses(msg);
167 NEKERROR(ErrorUtil::efatal, msg.str());
168 }
169
170 return std::static_pointer_cast<TOperator<TData>>(
171 factory.CreateInstance(requestedKey, expansionList, components));
172 }
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
LibUtilities::SessionReaderSharedPtr session
static std::string GetOpExecSpace(std::shared_ptr< LibUtilities::SessionReader > session, const bool warn=true)
Return the execution space name ("opExecSpace") for an operator.
Definition Operator.hpp:190

References Nektar::LibUtilities::NekFactoryBase< tKey, tBase, tBasePtr, tParam >::CreateInstance(), Nektar::ErrorUtil::efatal, Nektar::LibUtilities::NekFactoryBase< tKey, tBase, tBasePtr, tParam >::ModuleExists(), NEKERROR, Nektar::LibUtilities::NekFactoryBase< tKey, tBase, tBasePtr, tParam >::PrintAvailableClasses(), and session.

◆ GetDefaultInterleaveWidths()

template<typename TData >
static std::vector< unsigned int > Nektar::MultiRegions::Operator< TData >::GetDefaultInterleaveWidths ( const MultiRegions::ExpListSharedPtr &  expansionList)
inlinestatic

Return the default interleave widths, one per block of expansionList, that persistent Fields (e.g. solution storage, time-integration and linear-solver workspace) built on it should be constructed with.

A block takes the vector width of the session's execution space when its implementation is SumFac or the execution space is AVX, so that Fields are created at that width rather than reshaped on every Apply; 1 otherwise. The implementation is the command line's "opImpl" or, without it, the block's default of GetDefaultOpImpl(), so that each block matches the operators' default for it; a session that names implementations per operator (a backend section) leaves that default out, since one width cannot follow a mix. A DG projection takes the same interleave widths as a continuous one: the trace operators read a field at whatever width each of its blocks carries.

Parameters
expansionListExpansion list the fields are built on; its session supplies the command-line arguments and the backend sections.
Returns
std::vector<unsigned int> of interleave widths, one per block, for GetBlockAttributes().

Definition at line 288 of file Operator.hpp.

290 {
291 const auto session = expansionList->GetSession();
292 std::vector<unsigned int> interleave_widths;
293 if (!session)
294 {
295 // Without a session there is no execution space to follow.
296 interleave_widths.assign(GetCollections(expansionList).size(), 1u);
297 }
298 else
299 {
300 const std::string execName = GetOpExecSpace(session, false);
301
302 const LibUtilities::BackendMap &backend =
303 session->GetBackendMap(execName);
304 const bool cmdLineImpl = session->DefinesCmdLineArgument("opImpl");
305 const std::string cmdLineImplName =
306 cmdLineImpl ? session->GetCmdLineArgument<std::string>("opImpl")
307 : "";
308
309 for (auto &coll : GetCollections(expansionList))
310 {
311 const std::string implName =
312 cmdLineImpl ? cmdLineImplName
313 : backend.empty()
314 ? GetDefaultOpImpl(coll.GetExpVector()[0], execName)
315 : ""; // "" for now as different block operators might
316 // use different implementations
317 interleave_widths.push_back(
318 (implName == "SumFac" || execName == "AVX")
319 ? NektarSpaces::GetVectorWidth<TData>(execName)
320 : 1u);
321 }
322 }
323 return interleave_widths;
324 }
static std::string GetDefaultOpImpl(const StdRegions::StdExpansionSharedPtr &exp, const std::string &execSpace)
Return the implementation a block of elements takes when neither the command line nor the session nam...
Definition Operator.hpp:255
std::map< std::string, std::string > BackendMap
Collections::CollectionVector GetCollections(MultiRegions::ExpListSharedPtr expansionList)

References Nektar::MultiRegions::GetCollections(), Nektar::MultiRegions::Operator< TData >::GetDefaultOpImpl(), Nektar::MultiRegions::Operator< TData >::GetOpExecSpace(), and session.

Referenced by Nektar::MultiRegions::GetBlockAttributes().

◆ GetDefaultOpImpl()

template<typename TData >
static std::string Nektar::MultiRegions::Operator< TData >::GetDefaultOpImpl ( const StdRegions::StdExpansionSharedPtr &  exp,
const std::string &  execSpace 
)
inlinestatic

Return the implementation a block of elements takes when neither the command line nor the session names one for its operator.

This is the implementation of the block's row of the default implementation table (DefaultOpImplTable.hpp), by execution space, device architecture, element shape and expansion order, and SumFac where no row applies or without an expansion. On Device the table currently gives SumFacTOP from order three in 3D and order six in 1D and 2D. The default is taken per block, so the blocks of a mesh of mixed order or shape can take different implementations.

Parameters
expThe block's representative element, or null.
execSpaceExecution space ("Serial", "AVX" or "Device").
Returns
std::string containing the implementation name.

Definition at line 255 of file Operator.hpp.

258 {
259 const DefaultOpImplRule *rule = GetDefaultOpImplRule(exp, execSpace);
260 return rule ? std::string(rule->opImpl) : "SumFac";
261 }
static const DefaultOpImplRule * GetDefaultOpImplRule(const StdRegions::StdExpansionSharedPtr &exp, const std::string &execSpace)
Return the row of the default implementation table (DefaultOpImplTable.hpp) that a block of elements ...
Definition Operator.hpp:224

References Nektar::MultiRegions::Operator< TData >::GetDefaultOpImplRule(), and Nektar::MultiRegions::DefaultOpImplRule::opImpl.

Referenced by TestFusedElmt< Policy, VISCOUS >::DefaultImplementation(), and Nektar::MultiRegions::Operator< TData >::GetDefaultInterleaveWidths().

◆ GetDefaultOpImplRule()

template<typename TData >
static const DefaultOpImplRule * Nektar::MultiRegions::Operator< TData >::GetDefaultOpImplRule ( const StdRegions::StdExpansionSharedPtr &  exp,
const std::string &  execSpace 
)
inlinestatic

Return the row of the default implementation table (DefaultOpImplTable.hpp) that a block of elements takes, or null if none does.

Parameters
expThe block's representative element, whose shape and highest order over its directions are used, or null.
execSpaceExecution space ("Serial", "AVX" or "Device").

Definition at line 224 of file Operator.hpp.

227 {
228 const DefaultOpImplRule *rule = nullptr;
229 if (exp)
230 {
232 execSpace, execSpace == "Device" ? GetDeviceArchitecture() : "",
233 exp->DetShapeType(), exp->EvalBasisNumModesMax() - 1);
234 }
235 return rule;
236 }
const DefaultOpImplRule * FindDefaultOpImplRule(const std::string_view execSpace, const std::string_view arch, const LibUtilities::ShapeType shape, const int order, const DefaultOpImplRule *first=std::begin(defaultOpImplTable), const DefaultOpImplRule *last=std::end(defaultOpImplTable))
Return the row of a default implementation table that a block takes, or null if none does (the block ...
static std::string GetDeviceArchitecture()
Return the architecture id of the device the calling rank uses, as the default implementation table (...

References Nektar::MultiRegions::FindDefaultOpImplRule(), and Nektar::GetDeviceArchitecture().

Referenced by Nektar::MultiRegions::Operator< TData >::GetDefaultOpImpl(), and Nektar::MultiRegions::ElmtOp< TFieldIn, TFieldOut, TData >::GetOpImpl().

◆ GetOpExecSpace()

template<typename TData >
static std::string Nektar::MultiRegions::Operator< TData >::GetOpExecSpace ( std::shared_ptr< LibUtilities::SessionReader >  session,
const bool  warn = true 
)
inlinestatic

Return the execution space name ("opExecSpace") for an operator.

The space comes from the command-line argument "opExecSpace". Without it the operator takes the space the build provides, "Device" when a device is present and otherwise "AVX" or "Serial", and, if warn, warns that it has done so.

Parameters
sessionSession reader to recover the relevant command-line argument.
warnWhether to warn when the space is defaulted.
Returns
std::string containing the implementation name (e.g. "Serial", "Device").

Definition at line 190 of file Operator.hpp.

193 {
194 std::string OpExec = (nekGetNumDevice()) ? "Device" :
195#if defined(NEKTAR_ENABLE_SIMD)
196 "AVX";
197#else
198 "Serial";
199#endif
200
201 if (session->DefinesCmdLineArgument("opExecSpace"))
202 {
203 OpExec = session->GetCmdLineArgument<std::string>("opExecSpace");
204 }
205 else if (warn)
206 {
208 "No execution space specified for operator. Defaulting "
209 "to " +
210 OpExec);
211 }
212 return OpExec;
213 }
static unsigned int nekGetNumDevice()
Definition Backends.hpp:397

References Nektar::ErrorUtil::ewarning, NEKERROR, Nektar::nekGetNumDevice(), and session.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), Nektar::FilterAeroForces::FilterAeroForces(), Nektar::FilterEnergy::FilterEnergy(), Nektar::MultiRegions::Operator< TData >::GetDefaultInterleaveWidths(), LaunchProfiler(), TestAvgAssmbScatr< TData >::ReshapeInput(), TestAssmbScatr< TData >::RunTestCase(), TestExpression< TData >::RunTestCase(), TestRobin< TData >::RunTestCase(), TestMaxStdVelocity< TData >::RunTestCase(), TestNormOps< TData >::RunTestCase(), TestDirichlet< TData >::RunTestCase(), TestNeumann< TData >::RunTestCase(), TestPreconOps< TData >::RunTestCase(), TestAssmbScatr< TData >::RunTestCaseAtWidth(), TestAssmbScatr< TData >::RunTestCaseZeroDir(), and TestTimeOps< TData >::SetTestCase().

◆ IsDiscontinuousProjection()

template<typename TData >
static bool Nektar::MultiRegions::Operator< TData >::IsDiscontinuousProjection ( std::shared_ptr< LibUtilities::SessionReader >  session)
inlinestatic

Return true if the session uses a Discontinuous (DG) projection.

Parameters
sessionSession reader to recover the relevant SolverInfo.
Returns
bool true if the "Projection" SolverInfo is "DG" or "Discontinuous".

Definition at line 334 of file Operator.hpp.

336 {
337 if (!session->DefinesSolverInfo("Projection"))
338 {
339 return false;
340 }
341
342 std::string projection =
343 StringUtils::ToUpperCopy(session->GetSolverInfo("Projection"));
344 return projection == "DG" || projection == "DISCONTINUOUS";
345 }
std::string ToUpperCopy(std::string str)

References session, and Nektar::StringUtils::ToUpperCopy().

Member Data Documentation

◆ m_components

template<typename TData >
std::vector<std::string> Nektar::MultiRegions::Operator< TData >::m_components
protected

◆ m_dataWarehouse

template<typename TData >
LibUtilities::NekDataWarehouseSharedPtr Nektar::MultiRegions::Operator< TData >::m_dataWarehouse
protected

◆ m_expansionList

template<typename TData >
MultiRegions::ExpListSharedPtr Nektar::MultiRegions::Operator< TData >::m_expansionList
protected

Expansion list the operator acts on.

Definition at line 349 of file Operator.hpp.

Referenced by Nektar::MultiRegions::PhysTraceExtractOp< TData >::ApplyNormalComponent(), Nektar::MultiRegions::IProductWRTPhysNormalDerivTraceOp< TData >::ApplyVector(), Nektar::MultiRegions::IProductWRTPhysNormalDerivTraceOp< TData >::ApplyVector(), Nektar::MultiRegions::detail::BndCondPhysOpImpl< ExecSpace, TData >::BndCondPhysOpImpl(), Nektar::detail::HOPressureBndCondOpImpl< ExecSpace, TData >::BuildBoundaryData(), Nektar::detail::HOutflowBndCondOpImpl< ExecSpace, TData >::BuildBoundaryElementData(), Nektar::detail::HOPressureBndCondOpImpl< ExecSpace, TData >::BuildBoundaryVelocityData(), Nektar::detail::HOutflowBndCondOpImpl< ExecSpace, TData >::BuildPressureBoundaryData(), Nektar::MultiRegions::detail::NeuBndCondOpImpl< ExecSpace, TData >::BuildRegions(), Nektar::MultiRegions::detail::DirBndCondOpImpl< ExecSpace, TData >::DirBndCondOpImpl(), Nektar::EnergyOp< TData >::GetResult(), Nektar::AeroForcesOp< TData >::GetResultVector(), Nektar::MultiRegions::detail::RobBndCondOpImpl< ExecSpace, TData >::RobBndCondOpImpl(), Nektar::MultiRegions::ExpressionOp< TData >::SetExpressions(), Nektar::MultiRegions::detail::AssmbScatrOpImpl< ExecSpace, TData, ZERODIR, SIGNCHANGE >::SetUpMaps(), Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::v_Apply(), Nektar::detail::EnergyOpImpl< ExecSpace, TData >::v_Apply(), Nektar::detail::AeroForcesOpImpl< ExecSpace, TData >::v_Configure(), Nektar::MultiRegions::detail::NeuBndCondOpImpl< ExecSpace, TData >::v_ExcludeUserDefinedType(), and Nektar::detail::HOutflowBndCondOpImpl< ExecSpace, TData >::ValidateAndBuildVelocityBoundaryData().