Nektar++
Public Member Functions | Private Attributes | List of all members
Nektar::LibUtilities::Equation Class Reference

#include <Equation.h>

Public Member Functions

 Equation (const Equation &)=default
 
 Equation (InterpreterSharedPtr evaluator, const std::string &expr="", const std::string &vlist="")
 
Equationoperator= (const Equation &src)
 
NekDouble Evaluate () const
 
NekDouble Evaluate (NekDouble x, NekDouble y=0, NekDouble z=0, NekDouble t=0) const
 
void Evaluate (const Array< OneD, const NekDouble > &x, const Array< OneD, const NekDouble > &y, const Array< OneD, const NekDouble > &z, Array< OneD, NekDouble > &result) const
 
void Evaluate (const Array< OneD, const NekDouble > &x, const Array< OneD, const NekDouble > &y, const Array< OneD, const NekDouble > &z, const NekDouble t, Array< OneD, NekDouble > &result) const
 
void Evaluate (const Array< OneD, const NekDouble > &x, const Array< OneD, const NekDouble > &y, const Array< OneD, const NekDouble > &z, const Array< OneD, const NekDouble > &t, Array< OneD, NekDouble > &result) const
 
void Evaluate (const std::vector< Array< OneD, const NekDouble > > points, Array< OneD, NekDouble > &result) const
 
void SetParameter (const std::string &name, NekDouble value)
 
void SetConstants (const std::map< std::string, NekDouble > &constants)
 
std::string GetExpression (void) const
 
std::string GetVlist (void) const
 
NekDouble GetTime () const
 Returns time spend on expression evaluation at points (it does not include parse/pre-processing time). More...
 

Private Attributes

std::string m_vlist
 
std::string m_expr
 
int m_expr_id
 
InterpreterSharedPtr m_evaluator
 

Detailed Description

This class stores a string form of a symbolic expression to be evaluated e.g. for the boundary conditions, the unique numeric ID of that expression and a reference to the unique static instance of the Interpreter.

The scenario is that for multiple copies of Equation class holding their symbolic expressions in the std::string form, there is a unique instance of Interpreter, which holds a set of pre-processed symbolic expressions in the form of sequential containers of execution functors, ready for fast evaluation.

The interpreter also keeps all constants and parameters specified in an XML file. There should be only one copy of Equation class per each symbolic expression specified in XML file, modulo possible bugs. Classes Equation and Interpreter are complementary in a sense that the expression ID stored in the Equation class is generated by the Interpreter which holds ordered container of pre-processed expressions.

Definition at line 67 of file Equation.h.

Constructor & Destructor Documentation

◆ Equation() [1/2]

Nektar::LibUtilities::Equation::Equation ( const Equation )
default

◆ Equation() [2/2]

Nektar::LibUtilities::Equation::Equation ( InterpreterSharedPtr  evaluator,
const std::string &  expr = "",
const std::string &  vlist = "" 
)

Definition at line 43 of file BasicUtils/Equation.cpp.

45 : m_vlist(vlist), m_expr(expr), m_expr_id(-1), m_evaluator(evaluator)
46{
47 boost::algorithm::trim(m_expr);
48 boost::algorithm::trim(m_vlist);
49
50 if (m_vlist.empty())
51 {
52 m_vlist = "x y z t";
53 }
54
55 try
56 {
57 if (!m_expr.empty())
58 {
59 m_expr_id = m_evaluator->DefineFunction(m_vlist, m_expr);
60 }
61 }
62 catch (const std::runtime_error &e)
63 {
64 m_expr_id = -1;
65 std::string msg(
66 std::string("Equation::Equation() fails on expression [") + m_expr +
67 std::string("]\n"));
69 throw e;
70 return;
71 }
72 catch (const std::string &e)
73 {
74 m_expr_id = -1;
75 std::string msg(
76 std::string("Equation::Equation() fails on expression [") + m_expr +
77 std::string("]\n"));
79 throw e;
80 return;
81 }
82}
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
InterpreterSharedPtr m_evaluator
Definition: Equation.h:122

References Nektar::ErrorUtil::efatal, m_evaluator, m_expr, m_expr_id, m_vlist, CellMLToNektar.pycml::msg, and NEKERROR.

Member Function Documentation

◆ Evaluate() [1/6]

NekDouble Nektar::LibUtilities::Equation::Evaluate ( ) const

Definition at line 93 of file BasicUtils/Equation.cpp.

94{
95 try
96 {
97 if (m_expr_id != -1)
98 {
99 return m_evaluator->Evaluate(m_expr_id);
100 }
101 }
102 catch (const std::runtime_error &e)
103 {
104 std::string msg(
105 std::string("Equation::Evaluate fails on expression [") + m_expr +
106 std::string("]\n"));
107 NEKERROR(ErrorUtil::efatal, msg + std::string("ERROR: ") + e.what());
108 }
109 catch (const std::string &e)
110 {
111 std::string msg(
112 std::string("Equation::Evaluate fails on expression [") + m_expr +
113 std::string("]\n"));
114 NEKERROR(ErrorUtil::efatal, msg + std::string("ERROR: ") + e);
115 }
116 return 0;
117}

References Nektar::ErrorUtil::efatal, m_evaluator, m_expr, m_expr_id, CellMLToNektar.pycml::msg, and NEKERROR.

Referenced by Evaluate(), Nektar::SolverUtils::ForcingMovingReferenceFrame::EvaluateExpression(), Nektar::SolverUtils::FilterAeroForces::FilterAeroForces(), Nektar::FilterAeroForcesSPM::FilterAeroForcesSPM(), Nektar::SolverUtils::FilterAverageFields::FilterAverageFields(), Nektar::FilterBenchmark::FilterBenchmark(), Nektar::SolverUtils::FilterBodyFittedVelocity::FilterBodyFittedVelocity(), Nektar::SolverUtils::FilterCheckpoint::FilterCheckpoint(), Nektar::FilterCheckpointCellModel::FilterCheckpointCellModel(), Nektar::FilterElectrogram::FilterElectrogram(), Nektar::SolverUtils::FilterEnergy::FilterEnergy(), Nektar::SolverUtils::FilterEnergy1D::FilterEnergy1D(), Nektar::SolverUtils::FilterError::FilterError(), Nektar::SolverUtils::FilterFieldConvert::FilterFieldConvert(), Nektar::FilterHilbertFFTPhase::FilterHilbertFFTPhase(), Nektar::SolverUtils::FilterHistoryPoints::FilterHistoryPoints(), Nektar::SolverUtils::FilterIntegral::FilterIntegral(), Nektar::SolverUtils::FilterMaxMinFields::FilterMaxMinFields(), Nektar::SolverUtils::FilterMean::FilterMean(), Nektar::SolverUtils::FilterModalEnergy::FilterModalEnergy(), Nektar::SolverUtils::FilterMovingAverage::FilterMovingAverage(), Nektar::FilterMovingBody::FilterMovingBody(), Nektar::FilterOffsetPhase::FilterOffsetPhase(), Nektar::SolverUtils::FilterReynoldsStresses::FilterReynoldsStresses(), Nektar::SolverUtils::FilterThresholdMax::FilterThresholdMax(), Nektar::SolverUtils::FilterThresholdMin::FilterThresholdMin(), Nektar::Extrapolate::GenerateHOPBCMap(), Nektar::SpatialDomains::MeshGraph::ReadExpansionInfo(), Nektar::LibUtilities::SessionReader::ReadParameters(), Nektar::SpatialDomains::MeshGraph::ReadRefinementInfo(), Nektar::MultiRegions::DisContField::v_EvaluateBoundaryConditions(), Nektar::MultiRegions::DisContField3DHomogeneous1D::v_EvaluateBoundaryConditions(), Nektar::MultiRegions::DisContField::v_GetRobinBCInfo(), Nektar::SolverUtils::FilterLagrangianPoints::v_Initialise(), Nektar::IncNavierStokes::v_InitObject(), Nektar::TransMovingWall::v_Update(), Nektar::GlobalMapping::Mapping::v_UpdateBCs(), and Nektar::AcousticSystem::WhiteNoiseBC().

◆ Evaluate() [2/6]

void Nektar::LibUtilities::Equation::Evaluate ( const Array< OneD, const NekDouble > &  x,
const Array< OneD, const NekDouble > &  y,
const Array< OneD, const NekDouble > &  z,
Array< OneD, NekDouble > &  result 
) const

Definition at line 145 of file BasicUtils/Equation.cpp.

149{
150 Array<OneD, NekDouble> zero(x.size(), 0.0);
151 Evaluate(x, y, z, zero, result);
152}
std::vector< double > z(NPUPPER)

References Evaluate(), and Nektar::UnitTests::z().

◆ Evaluate() [3/6]

void Nektar::LibUtilities::Equation::Evaluate ( const Array< OneD, const NekDouble > &  x,
const Array< OneD, const NekDouble > &  y,
const Array< OneD, const NekDouble > &  z,
const Array< OneD, const NekDouble > &  t,
Array< OneD, NekDouble > &  result 
) const

Definition at line 163 of file BasicUtils/Equation.cpp.

168{
169 std::vector<Array<OneD, const NekDouble>> points;
170 points.push_back(x);
171 points.push_back(y);
172 points.push_back(z);
173 points.push_back(t);
174 Evaluate(points, result);
175}

References Evaluate(), and Nektar::UnitTests::z().

◆ Evaluate() [4/6]

void Nektar::LibUtilities::Equation::Evaluate ( const Array< OneD, const NekDouble > &  x,
const Array< OneD, const NekDouble > &  y,
const Array< OneD, const NekDouble > &  z,
const NekDouble  t,
Array< OneD, NekDouble > &  result 
) const

Definition at line 154 of file BasicUtils/Equation.cpp.

158{
159 Array<OneD, NekDouble> time(x.size(), t);
160 Evaluate(x, y, z, time, result);
161}

References Evaluate(), and Nektar::UnitTests::z().

◆ Evaluate() [5/6]

void Nektar::LibUtilities::Equation::Evaluate ( const std::vector< Array< OneD, const NekDouble > >  points,
Array< OneD, NekDouble > &  result 
) const

Definition at line 177 of file BasicUtils/Equation.cpp.

179{
180 try
181 {
182 if (m_expr_id != -1)
183 {
184 m_evaluator->Evaluate(m_expr_id, points, result);
185 }
186 }
187 catch (const std::runtime_error &e)
188 {
189 std::string msg =
190 "Equation::Evaluate fails on expression [" + m_expr + "]\n";
191 NEKERROR(ErrorUtil::efatal, msg + std::string("ERROR: ") + e.what());
192 return;
193 }
194 catch (const std::string &e)
195 {
196 std::string msg =
197 "Equation::Evaluate fails on expression [" + m_expr + "]\n";
198 NEKERROR(ErrorUtil::efatal, msg + std::string("ERROR: ") + e);
199 return;
200 }
201}

References Nektar::ErrorUtil::efatal, m_evaluator, m_expr, m_expr_id, CellMLToNektar.pycml::msg, and NEKERROR.

◆ Evaluate() [6/6]

NekDouble Nektar::LibUtilities::Equation::Evaluate ( NekDouble  x,
NekDouble  y = 0,
NekDouble  z = 0,
NekDouble  t = 0 
) const

Definition at line 119 of file BasicUtils/Equation.cpp.

121{
122 try
123 {
124 if (m_expr_id != -1)
125 {
126 return m_evaluator->Evaluate(m_expr_id, x, y, z, t);
127 }
128 }
129 catch (const std::runtime_error &e)
130 {
131 std::string msg =
132 "Equation::Evaluate fails on expression [" + m_expr + "]\n";
133 NEKERROR(ErrorUtil::efatal, msg + std::string("ERROR: ") + e.what());
134 }
135 catch (const std::string &e)
136 {
137 std::string msg =
138 "Equation::Evaluate fails on expression [" + m_expr + "]\n";
139 NEKERROR(ErrorUtil::efatal, msg + std::string("ERROR: ") + e);
140 }
141
142 return 0;
143}

References Nektar::ErrorUtil::efatal, m_evaluator, m_expr, m_expr_id, CellMLToNektar.pycml::msg, NEKERROR, and Nektar::UnitTests::z().

◆ GetExpression()

std::string Nektar::LibUtilities::Equation::GetExpression ( void  ) const

Definition at line 213 of file BasicUtils/Equation.cpp.

214{
215 return m_expr;
216}

References m_expr.

Referenced by Nektar::Extrapolate::GenerateHOPBCMap().

◆ GetTime()

NekDouble Nektar::LibUtilities::Equation::GetTime ( ) const

Returns time spend on expression evaluation at points (it does not include parse/pre-processing time).

Definition at line 225 of file BasicUtils/Equation.cpp.

226{
227 return m_evaluator->GetTime();
228}

References m_evaluator.

◆ GetVlist()

std::string Nektar::LibUtilities::Equation::GetVlist ( void  ) const

Definition at line 218 of file BasicUtils/Equation.cpp.

219{
220 return m_vlist;
221}

References m_vlist.

◆ operator=()

Equation & Nektar::LibUtilities::Equation::operator= ( const Equation src)

Definition at line 84 of file BasicUtils/Equation.cpp.

85{
86 m_vlist = src.m_vlist;
87 m_expr = src.m_expr;
88 m_expr_id = src.m_expr_id;
89 m_evaluator = src.m_evaluator;
90 return *this;
91}

References m_evaluator, m_expr, m_expr_id, and m_vlist.

◆ SetConstants()

void Nektar::LibUtilities::Equation::SetConstants ( const std::map< std::string, NekDouble > &  constants)

Definition at line 208 of file BasicUtils/Equation.cpp.

209{
210 m_evaluator->AddConstants(constants);
211}

References m_evaluator.

Referenced by Equation_SetConstants().

◆ SetParameter()

void Nektar::LibUtilities::Equation::SetParameter ( const std::string &  name,
NekDouble  value 
)

Definition at line 203 of file BasicUtils/Equation.cpp.

204{
205 m_evaluator->SetParameter(name, value);
206}

References m_evaluator, and CellMLToNektar.pycml::name.

Member Data Documentation

◆ m_evaluator

InterpreterSharedPtr Nektar::LibUtilities::Equation::m_evaluator
private

Definition at line 122 of file Equation.h.

Referenced by Equation(), Evaluate(), GetTime(), operator=(), SetConstants(), and SetParameter().

◆ m_expr

std::string Nektar::LibUtilities::Equation::m_expr
private

Definition at line 120 of file Equation.h.

Referenced by Equation(), Evaluate(), GetExpression(), and operator=().

◆ m_expr_id

int Nektar::LibUtilities::Equation::m_expr_id
private

Definition at line 121 of file Equation.h.

Referenced by Equation(), Evaluate(), and operator=().

◆ m_vlist

std::string Nektar::LibUtilities::Equation::m_vlist
private

Definition at line 119 of file Equation.h.

Referenced by Equation(), GetVlist(), and operator=().