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

Block-level interface of the Expression operator: evaluates the configured expressions at every quadrature point of one element block. More...

#include <ExpressionBlockOp.hpp>

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

Public Member Functions

void SetExpressions (const std::vector< LibUtilities::EquationSharedPtr > &exprs)
 Set the expressions to evaluate (one per component) via the back-end hook v_SetExpressions().
 
bool IsAvailable (const std::vector< LibUtilities::EquationSharedPtr > &exprs) const
 Whether this back-end can evaluate exprs under the current component mask.
 
void SetTime (const TData &time)
 Set the value substituted for the built-in variable t.
 
void SetScale (const TData &scale)
 Set the factor every evaluated value is multiplied by.
 
void SetAppend (const bool &append)
 Choose between accumulating onto the output and overwriting it.
 
void SetNumEvars (const std::vector< unsigned int > &numEvars)
 Set the variable count of each expression, as computed by ExpressionOp::GetNumberEvars().
 
void SetComponentMask (const std::vector< bool > &cmask)
 Set the per-component enable flags (see the mask notes in ExpressionOp::SetComponentMask, including the requirement that the mask be final before SetExpressions()).
 
- Public Member Functions inherited from Nektar::MultiRegions::ElmtBlockOp< FieldState::Phys, FieldState::Phys, TData >
void Apply (LibUtilities::BlockAccessor< TData, TFieldIn > &inblock, LibUtilities::BlockAccessor< TData, TFieldOut > &outblock)
 Apply the element operation to every element of the block.
 
void operator() (LibUtilities::BlockAccessor< TData, TFieldIn > &inblock, LibUtilities::BlockAccessor< TData, TFieldOut > &outblock)
 Call operator; equivalent to Apply().
 
- Public Member Functions inherited from Nektar::MultiRegions::BlockOperator< TData >
virtual ~BlockOperator ()=default
 

Static Public Member Functions

static std::shared_ptr< ExpressionBlockOp< TData > > Create (const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse, const std::string &execStr, const std::string &implStr)
 Create one block operator through the block-operator factory.
 
static std::vector< std::string > GetEvarsNames (const LibUtilities::EquationSharedPtr &expression)
 Split an expression's variable list into the individual variable names.
 
static std::set< std::string > GetExpressionVariables (const std::string &expr)
 The variables an expression uses: every name in expr that is not called as a function, so also its parameters and constants.
 
static std::set< std::string > GetExpressionFunctions (const std::string &expr)
 The functions an expression calls: every name in expr followed by an opening parenthesis.
 
- Static Public Member Functions inherited from Nektar::MultiRegions::ElmtBlockOp< FieldState::Phys, FieldState::Phys, TData >
static std::shared_ptr< TOperator< TData > > Create (const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse, const std::string &execStr, const std::string &implStr)
 Create one block operator through the block-operator factory.
 
- Static Public Member Functions inherited from Nektar::MultiRegions::BlockOperator< TData >
template<template< typename > typename TOperator>
static std::shared_ptr< TOperator< TData > > Create (const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse, const std::string &execStr)
 Create a concrete block-operator instance through the block-operator factory.
 

Static Public Attributes

static const std::string name = "BlockExpression"
 Block-operator base name; Create() appends the execution space and implementation to it to form the factory key.
 

Protected Member Functions

 ExpressionBlockOp (const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse)
 Construct the interface part of a concrete block operator; called by the factory-registered creator functions.
 
 ~ExpressionBlockOp () override=default
 
virtual void v_SetExpressions (const std::vector< LibUtilities::EquationSharedPtr > &exprs)=0
 Implementation hook for SetExpressions().
 
virtual bool v_IsAvailable (const std::vector< LibUtilities::EquationSharedPtr > &exprs) const =0
 Implementation hook for IsAvailable().
 
- Protected Member Functions inherited from Nektar::MultiRegions::ElmtBlockOp< FieldState::Phys, FieldState::Phys, TData >
 ElmtBlockOp (const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse)
 Construct the interface part of a concrete block operator; called by the factory-registered creator functions.
 
 ~ElmtBlockOp () override=default
 
virtual void v_Apply (LibUtilities::BlockAccessor< TData, TFieldIn > &inblock, LibUtilities::BlockAccessor< TData, TFieldOut > &outblock)=0
 Implementation hook for Apply().
 
- Protected Member Functions inherited from Nektar::MultiRegions::BlockOperator< TData >
 BlockOperator (const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse)
 Construct the interface part of a concrete block operator; called by the factory-registered creator functions.
 

Protected Attributes

std::vector< LibUtilities::EquationSharedPtr > m_expressions
 Parsed expressions, one per field component.
 
std::vector< unsigned int > m_numEvars
 Variable-list length of each expression: the built-in x, y, z and t plus any field-valued EVARS. The implementations read entry 0 only, assuming all expressions share one variable list.
 
std::vector< bool > m_cmask
 Per-component enable flags.
 
TData m_time = 0.0
 Value of the built-in time variable t.
 
TData m_scale = 1.0
 Factor applied to every evaluated expression value.
 
bool m_append = false
 Accumulate onto the output (true) or overwrite it (false).
 
- Protected Attributes inherited from Nektar::MultiRegions::ElmtBlockOp< FieldState::Phys, FieldState::Phys, TData >
bool m_warnOnceTemplate
 Set once the generated ShapeBlock switch code has warned that an element size outside the templated switch range fell back to the runtime-sized OperatorND call, so that the warning is issued only once per block operator (see the BlockOpSwitch templates in LibUtilities/BasicUtils/Switch).
 
- Protected Attributes inherited from Nektar::MultiRegions::BlockOperator< TData >
unsigned int m_block_idx
 Index of the block within the expansion list's Collections.
 
LocalRegions::ExpansionSharedPtr m_exp
 Representative expansion of the block (its first element).
 
LibUtilities::NekDataWarehouseSharedPtr m_dataWarehouse
 Data warehouse shared with the other operators on the expansion list.
 

Private Types

enum class  NameKind { Variable , Function }
 Kind of name GetExpressionNames() collects. More...
 

Static Private Member Functions

static std::set< std::string > GetExpressionNames (const std::string &expr, const NameKind kind)
 The names of kind kind in expr.
 

Additional Inherited Members

- Public Types inherited from Nektar::MultiRegions::ElmtBlockOp< FieldState::Phys, FieldState::Phys, TData >
using InBlock = LibUtilities::BlockAccessor< TData, TFieldIn >
 Accessor type of this operator's input block.
 
using OutBlock = LibUtilities::BlockAccessor< TData, TFieldOut >
 Accessor type of this operator's output block; see InBlock.
 
- Static Protected Member Functions inherited from Nektar::MultiRegions::ElmtBlockOp< FieldState::Phys, FieldState::Phys, TData >
static void ShapeSwitch (const LibUtilities::ShapeType shape, TFunc &&func)
 Call func with the runtime shape as a compile-time constant, std::integral_constant<LibUtilities::ShapeType, ...>.
 
static void DispatchAppendFlag (const bool append, TFunc &&func)
 Call func with std::true_type if append and std::false_type otherwise.
 
static void DispatchScaleFlag (const TData scale, TFunc &&func)
 Call func with std::false_type if scale is one and std::true_type otherwise.
 
static void DispatchDeformedFlag (const bool deformed, TFunc &&func)
 Call func with std::true_type if deformed and std::false_type otherwise.
 
- Static Protected Member Functions inherited from Nektar::MultiRegions::BlockOperator< TData >
template<typename MemSpace >
static TData * GetStaticWorkSpace (const size_t size, const unsigned int streamID=0)
 Return a per-stream scratch buffer in MemSpace, sized to hold at least size elements of TData, growing and reallocating it as needed.
 

Detailed Description

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

Block-level interface of the Expression operator: evaluates the configured expressions at every quadrature point of one element block.

Besides setting the BlockAccessor states accepted by Apply() to physical space on both sides, this class holds the evaluation settings – expressions, per-expression variable counts, component mask, time, scale and append flag. One instance per block is created by ElmtOp::Create via ExpressionOp::Create, and the settings are written through the whole-field ExpressionOp setters, which forward to every block.

All setters are plain stores except SetExpressions(), which goes through the virtual v_SetExpressions() so a back-end can prepare for evaluation.

Template Parameters
TDataFloating-point type of the field data.
See also
detail::ExpressionBlockOpImpl (ExpressionBlockOpSerialAVXGeneric.hpp / ExpressionBlockOpDeviceGeneric.hpp) for the v_Apply() implementations.

Definition at line 84 of file ExpressionBlockOp.hpp.

Member Enumeration Documentation

◆ NameKind

template<typename TData >
enum class Nektar::MultiRegions::ExpressionBlockOp::NameKind
strongprivate

Kind of name GetExpressionNames() collects.

Enumerator
Variable 

A name not called as a function.

Function 

A name followed by an opening parenthesis.

Definition at line 287 of file ExpressionBlockOp.hpp.

288 {
289 Variable, ///< A name not called as a function.
290 Function ///< A name followed by an opening parenthesis.
291 };
@ Variable
A name not called as a function.
@ Function
A name followed by an opening parenthesis.

Constructor & Destructor Documentation

◆ ExpressionBlockOp()

template<typename TData >
Nektar::MultiRegions::ExpressionBlockOp< TData >::ExpressionBlockOp ( const unsigned int  block_idx,
const LocalRegions::ExpansionSharedPtr &  exp,
LibUtilities::NekDataWarehouseSharedPtr  dataWarehouse 
)
inlineprotected

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

Parameters
block_idxIndex of the block within the expansion list's Collections.
expRepresentative expansion of the block.
dataWarehouseData warehouse shared with the other operators on the expansion list.

Definition at line 254 of file ExpressionBlockOp.hpp.

257 : ElmtBlockOp<FieldState::Phys, FieldState::Phys, TData>(block_idx, exp,
258 dataWarehouse)
259 {
260 }

◆ ~ExpressionBlockOp()

template<typename TData >
Nektar::MultiRegions::ExpressionBlockOp< TData >::~ExpressionBlockOp ( )
overrideprotecteddefault

Member Function Documentation

◆ Create()

template<typename TData >
static std::shared_ptr< ExpressionBlockOp< TData > > Nektar::MultiRegions::ExpressionBlockOp< TData >::Create ( const unsigned int  block_idx,
const LocalRegions::ExpansionSharedPtr &  exp,
LibUtilities::NekDataWarehouseSharedPtr  dataWarehouse,
const std::string &  execStr,
const std::string &  implStr 
)
inlinestatic

Create one block operator through the block-operator factory.

The factory key is name + execStr + implStr; since the family registers only "Generic" implementations, any other implStr falls back to the Generic key of the same execution space (see ElmtBlockOp::Create).

Parameters
block_idxIndex of the block within the expansion list's Collections.
expRepresentative expansion of the block.
dataWarehouseData warehouse shared with the other operators on the expansion list.
execStrExecution-space part of the factory key.
implStrImplementation part of the factory key.

Definition at line 106 of file ExpressionBlockOp.hpp.

111 {
112 return ElmtBlockOp<FieldState::Phys, FieldState::Phys, TData>::
113 template Create<ExpressionBlockOp>(block_idx, exp, dataWarehouse,
114 execStr, implStr);
115 }

Referenced by Nektar::MultiRegions::ExpressionOp< TData >::SetExpressions().

◆ GetEvarsNames()

template<typename TData >
static std::vector< std::string > Nektar::MultiRegions::ExpressionBlockOp< TData >::GetEvarsNames ( const LibUtilities::EquationSharedPtr &  expression)
inlinestatic

Split an expression's variable list into the individual variable names.

Entries 0-3 are the built-in x, y, z and t; entries from 4 onwards name the extra field variables (EVARS).

Parameters
expressionExpression whose variable list is split.
Returns
The comma/space-separated names, in list order.

Definition at line 132 of file ExpressionBlockOp.hpp.

134 {
135 std::vector<std::string> vnames;
136 StringUtils::Split(vnames, expression->GetVlist(),
137 StringUtils::IsAnyOf(", "));
138 return vnames;
139 }
Container & Split(Container &result, std::string_view input, Pred pred, TokenCompressMode mode=eTokenCompressOff)
Splits input at characters matching pred into result, which is cleared first. An empty input gives a ...

References Nektar::StringUtils::Split().

Referenced by Nektar::MultiRegions::detail::GetExpressionKernelSource().

◆ GetExpressionFunctions()

template<typename TData >
static std::set< std::string > Nektar::MultiRegions::ExpressionBlockOp< TData >::GetExpressionFunctions ( const std::string &  expr)
inlinestatic

The functions an expression calls: every name in expr followed by an opening parenthesis.

Parameters
exprExpression to scan.
Returns
The distinct function names in expr.

Definition at line 162 of file ExpressionBlockOp.hpp.

163 {
165 }
static std::set< std::string > GetExpressionNames(const std::string &expr, const NameKind kind)
The names of kind kind in expr.

References Nektar::MultiRegions::ExpressionBlockOp< TData >::Function, and Nektar::MultiRegions::ExpressionBlockOp< TData >::GetExpressionNames().

Referenced by Nektar::MultiRegions::detail::ExpressionBlockOpImpl< ExecSpace, Implementation, TData >::v_IsAvailable().

◆ GetExpressionNames()

template<typename TData >
static std::set< std::string > Nektar::MultiRegions::ExpressionBlockOp< TData >::GetExpressionNames ( const std::string &  expr,
const NameKind  kind 
)
inlinestaticprivate

The names of kind kind in expr.

Numbers are skipped, so that an exponent is not read as a name.

Definition at line 298 of file ExpressionBlockOp.hpp.

300 {
301 const auto isName = [](const char c) {
302 return std::isalnum(static_cast<unsigned char>(c)) || c == '_';
303 };
304
305 std::set<std::string> names;
306 for (size_t i = 0; i < expr.size();)
307 {
308 const char c = expr[i];
309 if (std::isdigit(static_cast<unsigned char>(c)) || c == '.')
310 {
311 for (++i; i < expr.size(); ++i)
312 {
313 const bool sign =
314 (expr[i] == '+' || expr[i] == '-') &&
315 (expr[i - 1] == 'e' || expr[i - 1] == 'E');
316 if (!isName(expr[i]) && expr[i] != '.' && !sign)
317 {
318 break;
319 }
320 }
321 }
322 else if (std::isalpha(static_cast<unsigned char>(c)) || c == '_')
323 {
324 size_t j = i + 1;
325 while (j < expr.size() && isName(expr[j]))
326 {
327 ++j;
328 }
329 size_t k = j;
330 while (k < expr.size() &&
331 std::isspace(static_cast<unsigned char>(expr[k])))
332 {
333 ++k;
334 }
335 const NameKind found = k < expr.size() && expr[k] == '('
338 if (found == kind)
339 {
340 names.insert(expr.substr(i, j - i));
341 }
342 i = j;
343 }
344 else
345 {
346 ++i;
347 }
348 }
349 return names;
350 }
#define sign(a, b)
return the sign(b)*a
Definition Polylib.cpp:47
NameKind
Kind of name GetExpressionNames() collects.

References Nektar::MultiRegions::ExpressionBlockOp< TData >::Function, sign, and Nektar::MultiRegions::ExpressionBlockOp< TData >::Variable.

Referenced by Nektar::MultiRegions::ExpressionBlockOp< TData >::GetExpressionFunctions(), and Nektar::MultiRegions::ExpressionBlockOp< TData >::GetExpressionVariables().

◆ GetExpressionVariables()

template<typename TData >
static std::set< std::string > Nektar::MultiRegions::ExpressionBlockOp< TData >::GetExpressionVariables ( const std::string &  expr)
inlinestatic

The variables an expression uses: every name in expr that is not called as a function, so also its parameters and constants.

Parameters
exprExpression to scan.
Returns
The distinct variable names in expr.

Definition at line 149 of file ExpressionBlockOp.hpp.

150 {
152 }

References Nektar::MultiRegions::ExpressionBlockOp< TData >::GetExpressionNames(), and Nektar::MultiRegions::ExpressionBlockOp< TData >::Variable.

Referenced by Nektar::MultiRegions::detail::ExpressionBlockOpImpl< ExecSpace, Implementation, TData >::v_IsAvailable(), and Nektar::detail::HOutflowBndCondOpImpl< ExecSpace, TData >::ValidateAndBuildVelocityBoundaryData().

◆ IsAvailable()

template<typename TData >
bool Nektar::MultiRegions::ExpressionBlockOp< TData >::IsAvailable ( const std::vector< LibUtilities::EquationSharedPtr > &  exprs) const
inline

Whether this back-end can evaluate exprs under the current component mask.

Definition at line 181 of file ExpressionBlockOp.hpp.

183 {
184 return v_IsAvailable(exprs);
185 }
virtual bool v_IsAvailable(const std::vector< LibUtilities::EquationSharedPtr > &exprs) const =0
Implementation hook for IsAvailable().

References Nektar::MultiRegions::ExpressionBlockOp< TData >::v_IsAvailable().

◆ SetAppend()

template<typename TData >
void Nektar::MultiRegions::ExpressionBlockOp< TData >::SetAppend ( const bool &  append)
inline

Choose between accumulating onto the output and overwriting it.

Definition at line 203 of file ExpressionBlockOp.hpp.

204 {
205 this->m_append = append;
206 }
bool m_append
Accumulate onto the output (true) or overwrite it (false).
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT const bool append

References Nektar::MultiRegions::ExpressionBlockOp< TData >::m_append.

◆ SetComponentMask()

template<typename TData >
void Nektar::MultiRegions::ExpressionBlockOp< TData >::SetComponentMask ( const std::vector< bool > &  cmask)
inline

Set the per-component enable flags (see the mask notes in ExpressionOp::SetComponentMask, including the requirement that the mask be final before SetExpressions()).

Definition at line 222 of file ExpressionBlockOp.hpp.

223 {
224 this->m_cmask = cmask;
225 }
std::vector< bool > m_cmask
Per-component enable flags.

References Nektar::MultiRegions::ExpressionBlockOp< TData >::m_cmask.

Referenced by Nektar::MultiRegions::ExpressionOp< TData >::Create().

◆ SetExpressions()

template<typename TData >
void Nektar::MultiRegions::ExpressionBlockOp< TData >::SetExpressions ( const std::vector< LibUtilities::EquationSharedPtr > &  exprs)
inline

Set the expressions to evaluate (one per component) via the back-end hook v_SetExpressions().

Definition at line 171 of file ExpressionBlockOp.hpp.

173 {
174 v_SetExpressions(exprs);
175 }
virtual void v_SetExpressions(const std::vector< LibUtilities::EquationSharedPtr > &exprs)=0
Implementation hook for SetExpressions().

References Nektar::MultiRegions::ExpressionBlockOp< TData >::v_SetExpressions().

◆ SetNumEvars()

template<typename TData >
void Nektar::MultiRegions::ExpressionBlockOp< TData >::SetNumEvars ( const std::vector< unsigned int > &  numEvars)
inline

Set the variable count of each expression, as computed by ExpressionOp::GetNumberEvars().

Definition at line 212 of file ExpressionBlockOp.hpp.

213 {
214 this->m_numEvars = numEvars;
215 }
std::vector< unsigned int > m_numEvars
Variable-list length of each expression: the built-in x, y, z and t plus any field-valued EVARS....

References Nektar::MultiRegions::ExpressionBlockOp< TData >::m_numEvars.

◆ SetScale()

template<typename TData >
void Nektar::MultiRegions::ExpressionBlockOp< TData >::SetScale ( const TData &  scale)
inline

Set the factor every evaluated value is multiplied by.

Definition at line 194 of file ExpressionBlockOp.hpp.

195 {
196 this->m_scale = scale;
197 }
TData m_scale
Factor applied to every evaluated expression value.

References Nektar::MultiRegions::ExpressionBlockOp< TData >::m_scale.

◆ SetTime()

template<typename TData >
void Nektar::MultiRegions::ExpressionBlockOp< TData >::SetTime ( const TData &  time)
inline

Set the value substituted for the built-in variable t.

Definition at line 188 of file ExpressionBlockOp.hpp.

189 {
190 this->m_time = time;
191 }
TData m_time
Value of the built-in time variable t.

References Nektar::MultiRegions::ExpressionBlockOp< TData >::m_time.

◆ v_IsAvailable()

template<typename TData >
virtual bool Nektar::MultiRegions::ExpressionBlockOp< TData >::v_IsAvailable ( const std::vector< LibUtilities::EquationSharedPtr > &  exprs) const
protectedpure virtual

◆ v_SetExpressions()

template<typename TData >
virtual void Nektar::MultiRegions::ExpressionBlockOp< TData >::v_SetExpressions ( const std::vector< LibUtilities::EquationSharedPtr > &  exprs)
protectedpure virtual

Implementation hook for SetExpressions().

Overrides must arrange that m_expressions, and whatever the back-end derives from them, are in place before the work queued by the next Apply() runs; that work need not have finished by the time this call returns.

Parameters
exprsParsed expressions, one per component.

Implemented in Nektar::MultiRegions::detail::ExpressionBlockOpImpl< ExecSpace, Implementation, TData >, and Nektar::MultiRegions::detail::ExpressionBlockOpImpl< ExecSpace, Implementation, TData >.

Referenced by Nektar::MultiRegions::ExpressionBlockOp< TData >::SetExpressions().

Member Data Documentation

◆ m_append

template<typename TData >
bool Nektar::MultiRegions::ExpressionBlockOp< TData >::m_append = false
protected

◆ m_cmask

template<typename TData >
std::vector<bool> Nektar::MultiRegions::ExpressionBlockOp< TData >::m_cmask
protected

◆ m_expressions

template<typename TData >
std::vector<LibUtilities::EquationSharedPtr> Nektar::MultiRegions::ExpressionBlockOp< TData >::m_expressions
protected

◆ m_numEvars

template<typename TData >
std::vector<unsigned int> Nektar::MultiRegions::ExpressionBlockOp< TData >::m_numEvars
protected

Variable-list length of each expression: the built-in x, y, z and t plus any field-valued EVARS. The implementations read entry 0 only, assuming all expressions share one variable list.

Definition at line 233 of file ExpressionBlockOp.hpp.

Referenced by Nektar::MultiRegions::ExpressionBlockOp< TData >::SetNumEvars(), and Nektar::MultiRegions::detail::ExpressionBlockOpImpl< ExecSpace, Implementation, TData >::v_Apply().

◆ m_scale

template<typename TData >
TData Nektar::MultiRegions::ExpressionBlockOp< TData >::m_scale = 1.0
protected

◆ m_time

template<typename TData >
TData Nektar::MultiRegions::ExpressionBlockOp< TData >::m_time = 0.0
protected

◆ name

template<typename TData >
const std::string Nektar::MultiRegions::ExpressionBlockOp< TData >::name = "BlockExpression"
inlinestatic

Block-operator base name; Create() appends the execution space and implementation to it to form the factory key.

Definition at line 119 of file ExpressionBlockOp.hpp.