Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Attributes | List of all members
Nektar::LibUtilities::Equation Class Reference

#include <Equation.h>

Collaboration diagram for Nektar::LibUtilities::Equation:
Collaboration graph
[legend]

Public Member Functions

 Equation (const Equation &src)
 
 Equation (const SessionReaderSharedPtr &session, const std::string &expr="")
 
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)
 
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 SetParameter (const std::string &name, NekDouble value)
 
void SetConstants (const std::map< std::string, NekDouble > &constants)
 
std::string GetExpression (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_expr
 
int m_expr_id
 
AnalyticExpressionEvaluatorm_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 AnalyticExpressionEvaluator.

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 AnalyticExpressionEvaluator which holds a set of pre-processed symbolic expressions in the form of sequential containers of execution functors, ready for fast evaluation.

AnalyticExpressionEvaluator 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 AnalyticExpressionEvaluator live symbiotic in a sense that the expression id stored in Equation class is generated by AnalyticExpressionEvaluator which holds ordered container of pre-processed expressions.

Definition at line 54 of file Equation.h.

Constructor & Destructor Documentation

Nektar::LibUtilities::Equation::Equation ( const Equation src)
inline

Definition at line 58 of file Equation.h.

58  :
59  m_expr (src.m_expr),
60  m_expr_id (src.m_expr_id),
61  m_evaluator (src.m_evaluator)
62  {
63  }
AnalyticExpressionEvaluator & m_evaluator
Definition: Equation.h:221
Nektar::LibUtilities::Equation::Equation ( const SessionReaderSharedPtr session,
const std::string &  expr = "" 
)
inline

Definition at line 65 of file Equation.h.

References ASSERTL1, Nektar::LibUtilities::AnalyticExpressionEvaluator::DefineFunction(), m_evaluator, m_expr, and m_expr_id.

65  :
66  m_expr (expr),
67  m_expr_id (-1),
68  m_evaluator (session->GetExpressionEvaluator())
69  {
70  boost::algorithm::trim(m_expr);
71 
72  try
73  {
74  if (!m_expr.empty())
75  {
77  }
78  }
79  catch (const std::runtime_error& e)
80  {
81  m_expr_id = -1;
82  std::string msg(std::string("Equation::Equation() fails on expression [") + m_expr + std::string("]\n"));
83  ASSERTL1(false, msg);
84  throw e;
85  return;
86  }
87  catch (const std::string& e)
88  {
89  m_expr_id = -1;
90  std::string msg(std::string("Equation::Equation() fails on expression [") + m_expr + std::string("]\n"));
91  ASSERTL1(false, msg);
92  throw e;
93  return;
94  }
95  }
int DefineFunction(const std::string &vlist, const std::string &function)
This function allows one to define a function to evaluate. The first argument (vlist) is a list of va...
AnalyticExpressionEvaluator & m_evaluator
Definition: Equation.h:221
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:191

Member Function Documentation

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

Definition at line 102 of file Equation.h.

References ASSERTL0, Nektar::LibUtilities::AnalyticExpressionEvaluator::Evaluate(), m_evaluator, m_expr, and m_expr_id.

Referenced by Evaluate(), Nektar::SolverUtils::FilterAeroForces::FilterAeroForces(), Nektar::FilterBenchmark::FilterBenchmark(), Nektar::FilterElectrogram::FilterElectrogram(), Nektar::SolverUtils::FilterEnergy1D::FilterEnergy1D(), Nektar::SolverUtils::FilterHistoryPoints::FilterHistoryPoints(), Nektar::SolverUtils::FilterModalEnergy::FilterModalEnergy(), Nektar::SolverUtils::FilterMovingAverage::FilterMovingAverage(), Nektar::FilterMovingBody::FilterMovingBody(), Nektar::SolverUtils::FilterReynoldsStresses::FilterReynoldsStresses(), Nektar::SolverUtils::FilterSampler::FilterSampler(), Nektar::SolverUtils::FilterThresholdMax::FilterThresholdMax(), Nektar::SolverUtils::FilterThresholdMin::FilterThresholdMin(), Nektar::SpatialDomains::MeshGraph::ReadExpansions(), Nektar::LibUtilities::SessionReader::ReadParameters(), Nektar::MultiRegions::DisContField3D::v_EvaluateBoundaryConditions(), Nektar::MultiRegions::DisContField2D::v_EvaluateBoundaryConditions(), Nektar::IncNavierStokes::v_InitObject(), and Nektar::GlobalMapping::Mapping::v_UpdateBCs().

103  {
104  try
105  {
106  if (m_expr_id != -1)
107  {
109  }
110  }
111  catch (const std::runtime_error& e)
112  {
113  std::string msg(std::string("Equation::Evaluate fails on expression [") + m_expr + std::string("]\n"));
114  ASSERTL0(false, msg + std::string("ERROR: ") + e.what());
115  }
116  catch (const std::string& e)
117  {
118  std::string msg(std::string("Equation::Evaluate fails on expression [") + m_expr + std::string("]\n"));
119  ASSERTL0(false, msg + std::string("ERROR: ") + e);
120  }
121  return 0;
122  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
NekDouble Evaluate(const int AnalyticExpression_id)
Evaluation method for expressions depending on parameters only.
AnalyticExpressionEvaluator & m_evaluator
Definition: Equation.h:221
NekDouble Nektar::LibUtilities::Equation::Evaluate ( NekDouble  x,
NekDouble  y = 0,
NekDouble  z = 0,
NekDouble  t = 0 
) const
inline

Definition at line 124 of file Equation.h.

References ASSERTL0, Nektar::LibUtilities::AnalyticExpressionEvaluator::Evaluate(), m_evaluator, m_expr, and m_expr_id.

125  {
126  try
127  {
128  if (m_expr_id != -1)
129  {
130  return m_evaluator.Evaluate(m_expr_id, x,y,z,t);
131  }
132  }
133  catch (const std::runtime_error& e)
134  {
135  std::string msg(std::string("Equation::Evaluate fails on expression [") + m_expr + std::string("]\n"));
136  ASSERTL0(false, msg + std::string("ERROR: ") + e.what());
137  }
138  catch (const std::string& e)
139  {
140  std::string msg(std::string("Equation::Evaluate fails on expression [") + m_expr + std::string("]\n"));
141  ASSERTL0(false, msg + std::string("ERROR: ") + e);
142  }
143  return 0;
144  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
NekDouble Evaluate(const int AnalyticExpression_id)
Evaluation method for expressions depending on parameters only.
AnalyticExpressionEvaluator & m_evaluator
Definition: Equation.h:221
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 
)
inline

Definition at line 146 of file Equation.h.

References Evaluate().

151  {
152  Array<OneD, NekDouble> zero(x.num_elements(), 0.0);
153  Evaluate(x,y,z,zero, result);
154  }
NekDouble Evaluate() const
Definition: Equation.h:102
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
inline

Definition at line 156 of file Equation.h.

References Evaluate().

162  {
163  Array<OneD, NekDouble> time(x.num_elements(), t);
164  Evaluate(x,y,z,time, result);
165  }
NekDouble Evaluate() const
Definition: Equation.h:102
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
inline

Definition at line 168 of file Equation.h.

References ASSERTL0, Nektar::LibUtilities::AnalyticExpressionEvaluator::Evaluate(), m_evaluator, m_expr, and m_expr_id.

174  {
175  try
176  {
177  if (m_expr_id != -1)
178  {
179  m_evaluator.Evaluate(m_expr_id, x,y,z,t, result);
180  }
181  }
182  catch (const std::runtime_error& e)
183  {
184  std::string msg(std::string("Equation::Evaluate fails on expression [") + m_expr + std::string("]\n"));
185  ASSERTL0(false, msg + std::string("ERROR: ") + e.what());
186  return;
187  }
188  catch (const std::string& e)
189  {
190  std::string msg(std::string("Equation::Evaluate fails on expression [") + m_expr + std::string("]\n"));
191  ASSERTL0(false, msg + std::string("ERROR: ") + e);
192  return;
193  }
194  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
NekDouble Evaluate(const int AnalyticExpression_id)
Evaluation method for expressions depending on parameters only.
AnalyticExpressionEvaluator & m_evaluator
Definition: Equation.h:221
std::string Nektar::LibUtilities::Equation::GetExpression ( void  ) const
inline

Definition at line 206 of file Equation.h.

References m_expr.

207  {
208  return m_expr;
209  }
NekDouble Nektar::LibUtilities::Equation::GetTime ( ) const
inline

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

Definition at line 213 of file Equation.h.

References Nektar::LibUtilities::AnalyticExpressionEvaluator::GetTime(), and m_evaluator.

214  {
215  return m_evaluator.GetTime();
216  }
NekDouble GetTime() const
Returns the total time spent in evaluation procedures, seconds.
AnalyticExpressionEvaluator & m_evaluator
Definition: Equation.h:221
Equation& Nektar::LibUtilities::Equation::operator= ( const Equation src)
inline

Definition at line 97 of file Equation.h.

98  {
99  return *this;
100  }
void Nektar::LibUtilities::Equation::SetConstants ( const std::map< std::string, NekDouble > &  constants)
inline

Definition at line 201 of file Equation.h.

References Nektar::LibUtilities::AnalyticExpressionEvaluator::AddConstants(), and m_evaluator.

202  {
203  m_evaluator.AddConstants(constants);
204  }
void AddConstants(std::map< std::string, NekDouble > const &constants)
Constants are evaluated and inserted into the function at the time it is parsed when calling the Defi...
AnalyticExpressionEvaluator & m_evaluator
Definition: Equation.h:221
void Nektar::LibUtilities::Equation::SetParameter ( const std::string &  name,
NekDouble  value 
)
inline

Definition at line 196 of file Equation.h.

References m_evaluator, and Nektar::LibUtilities::AnalyticExpressionEvaluator::SetParameter().

197  {
198  m_evaluator.SetParameter(name, value);
199  }
void SetParameter(std::string const &name, NekDouble value)
This function behaves in the same way as SetParameters, but it only adds one parameter and it does no...
AnalyticExpressionEvaluator & m_evaluator
Definition: Equation.h:221

Member Data Documentation

AnalyticExpressionEvaluator& Nektar::LibUtilities::Equation::m_evaluator
private

Definition at line 221 of file Equation.h.

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

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

Definition at line 219 of file Equation.h.

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

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

Definition at line 220 of file Equation.h.

Referenced by Equation(), and Evaluate().