113template <
typename TData>
146 static std::shared_ptr<ExpressionOp<TData>>
Create(
147 const MultiRegions::ExpListSharedPtr &expansionList,
148 const std::vector<std::string> &components,
149 const std::string &execStr = "", const std::string &implStr = "")
158 op->m_blockHostOp.resize(op->m_blockOp.size(),
nullptr);
159 op->m_useHostOp.resize(op->m_blockOp.size(),
false);
168 static inline const std::string
name =
"Expression";
184 const std::vector<LibUtilities::EquationSharedPtr> &exprs)
187 std::vector<unsigned int> numEvars;
188 for (
unsigned int ne = 0; ne < exprs.size(); ++ne)
198 for (
unsigned int blk = 0; blk <
m_blockOp.size(); ++blk)
210 "Serial",
"Generic");
221 this->
m_blockOp[blk]->SetExpressions(exprs);
222 this->
m_blockOp[blk]->SetNumEvars(numEvars);
238 for (
unsigned int blk = 0; blk <
m_blockOp.size(); ++blk)
257 for (
unsigned int blk = 0; blk <
m_blockOp.size(); ++blk)
277 for (
unsigned int blk = 0; blk <
m_blockOp.size(); ++blk)
306 for (
unsigned int blk = 0; blk <
m_blockOp.size(); ++blk)
308 this->
m_blockOp[blk]->SetComponentMask(cmask);
336 std::vector<std::string> vars;
337 auto variableList = expression->GetVlist();
346 std::vector<std::shared_ptr<ExpressionBlockOp<TData>>>
m_blockOp;
373 const std::vector<std::string> &components)
396 ASSERTL1(in.GetNumComponents() == out.GetNumComponents(),
397 "Number of input and output components differ");
399 ASSERTL1(in.GetNumHomoModes() == out.GetNumHomoModes(),
400 "Number of input and output homogeneous modes differ");
402 ASSERTL1(this->m_isExpressionsDefined,
403 "No expressions defined for this Operator. Define with "
407 for (
unsigned int blk = 0; blk < this->m_blockOp.size(); ++blk)
410 auto &inblock = in.GetBlocks()[blk];
411 auto &outblock = out.GetBlocks()[blk];
416 "Expression evaluated on the host: the execution "
417 "space cannot evaluate it.");
419 this->m_blockHostOp[blk]->Apply(inblock, outblock);
423 this->m_blockOp[blk]->Apply(inblock, outblock);
Whole-field base class and factory machinery shared by every element-operator family in the MultiRegi...
#define WARNINGL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Per-block interface of the Expression operator, holding the evaluation settings shared by all back-en...
A Field represents expansion data to be operated on.
Common base class of the element-operator interfaces: an operator applied independently to every elem...
static std::shared_ptr< TOperator< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Build a complete element operator: the whole-field interface object plus one block operator per eleme...
Block-level interface of the Expression operator: evaluates the configured expressions at every quadr...
void SetComponentMask(const std::vector< bool > &cmask)
Set the per-component enable flags (see the mask notes in ExpressionOp::SetComponentMask,...
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.
Whole-field interface of the Expression operator: evaluates one analytical expression per field compo...
bool m_isExpressionsDefined
Whether SetExpressions() has been called; Apply() asserts this.
static const std::string name
Operator base name; Create() appends the execution space to it to form the factory key.
~ExpressionOp() override=default
std::vector< std::shared_ptr< ExpressionBlockOp< TData > > > m_blockOp
One block operator per element block, filled by ElmtOp::Create.
std::vector< bool > m_useHostOp
Whether each block evaluates the current expressions with its host block operator.
static std::shared_ptr< ExpressionOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create an Expression operator through the two-stage element-operator factory and initialise its defau...
bool m_warnOnceHostOp
Set once the use of a host block operator has been warned about, for the current expressions.
void v_Apply(LibUtilities::Field< TData, FieldState::Phys > &in, LibUtilities::Field< TData, FieldState::Phys > &out) override
Evaluate the expressions block by block: checks that the fields conform and that expressions have bee...
static unsigned int GetNumberEvars(const LibUtilities::EquationSharedPtr &expression)
Count the variables of an expression, i.e. the length of its variable list.
void SetComponentMask(const std::vector< bool > &cmask)
Select which output components the expressions are evaluated for (default: all enabled).
std::vector< std::shared_ptr< ExpressionBlockOp< TData > > > m_blockHostOp
Host block operator of each block whose own could not evaluate some expressions set,...
void SetScale(const TData &scale)
Set the factor every evaluated expression value is multiplied by before it is written or appended (de...
void SetTime(const TData &time)
Set the value substituted for the built-in time variable t in every expression (default 0).
void SetExpressions(const std::vector< LibUtilities::EquationSharedPtr > &exprs)
Set the expressions to evaluate, one per field component in component order.
std::vector< bool > m_cmask
Settings forwarded to the block operators, kept for those of m_blockHostOp, created after them.
void SetAppend(const bool &append)
Choose between accumulating onto the output (out += scale * f) and overwriting it (out = scale * f,...
ExpressionOp(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components)
Construct the interface part of a concrete implementation; called by the factory-registered creator f...
MultiRegions::ExpListSharedPtr m_expansionList
Expansion list the operator acts on.
Predicate matching any of a set of characters.
std::shared_ptr< Equation > EquationSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
Collections::Collection GetCollection(MultiRegions::ExpListSharedPtr expansionList, unsigned int block_idx)
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 ...
FieldState
Possible states for Field data.