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).

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.

:
m_expr (src.m_expr),
m_expr_id (src.m_expr_id),
m_evaluator (src.m_evaluator)
{
}
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.

:
m_expr (expr),
m_expr_id (-1),
m_evaluator (session->GetExpressionEvaluator())
{
boost::algorithm::trim(m_expr);
try
{
if (!m_expr.empty())
{
}
}
catch (const std::runtime_error& e)
{
m_expr_id = -1;
std::string msg(std::string("Equation::Equation() fails on expression [") + m_expr + std::string("]\n"));
ASSERTL1(false, msg);
throw e;
return;
}
catch (const std::string& e)
{
m_expr_id = -1;
std::string msg(std::string("Equation::Equation() fails on expression [") + m_expr + std::string("]\n"));
ASSERTL1(false, msg);
throw e;
return;
}
}

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::SpatialDomains::MeshGraph::ReadExpansions(), Nektar::LibUtilities::SessionReader::ReadParameters(), Nektar::MultiRegions::DisContField3D::v_EvaluateBoundaryConditions(), Nektar::MultiRegions::DisContField2D::v_EvaluateBoundaryConditions(), and Nektar::IncNavierStokes::v_InitObject().

{
try
{
if (m_expr_id != -1)
{
}
}
catch (const std::runtime_error& e)
{
std::string msg(std::string("Equation::Evaluate fails on expression [") + m_expr + std::string("]\n"));
ASSERTL0(false, msg + std::string("ERROR: ") + e.what());
}
catch (const std::string& e)
{
std::string msg(std::string("Equation::Evaluate fails on expression [") + m_expr + std::string("]\n"));
ASSERTL0(false, msg + std::string("ERROR: ") + e);
}
return 0;
}
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.

{
try
{
if (m_expr_id != -1)
{
return m_evaluator.Evaluate(m_expr_id, x,y,z,t);
}
}
catch (const std::runtime_error& e)
{
std::string msg(std::string("Equation::Evaluate fails on expression [") + m_expr + std::string("]\n"));
ASSERTL0(false, msg + std::string("ERROR: ") + e.what());
}
catch (const std::string& e)
{
std::string msg(std::string("Equation::Evaluate fails on expression [") + m_expr + std::string("]\n"));
ASSERTL0(false, msg + std::string("ERROR: ") + e);
}
return 0;
}
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().

{
Array<OneD, NekDouble> zero(x.num_elements(), 0.0);
Evaluate(x,y,z,zero, result);
}
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().

{
Array<OneD, NekDouble> time(x.num_elements(), t);
Evaluate(x,y,z,time, result);
}
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.

{
try
{
if (m_expr_id != -1)
{
m_evaluator.Evaluate(m_expr_id, x,y,z,t, result);
}
}
catch (const std::runtime_error& e)
{
std::string msg(std::string("Equation::Evaluate fails on expression [") + m_expr + std::string("]\n"));
ASSERTL0(false, msg + std::string("ERROR: ") + e.what());
return;
}
catch (const std::string& e)
{
std::string msg(std::string("Equation::Evaluate fails on expression [") + m_expr + std::string("]\n"));
ASSERTL0(false, msg + std::string("ERROR: ") + e);
return;
}
}
std::string Nektar::LibUtilities::Equation::GetExpression ( void  ) const
inline

Definition at line 206 of file Equation.h.

References m_expr.

{
return m_expr;
}
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.

{
return m_evaluator.GetTime();
}
Equation& Nektar::LibUtilities::Equation::operator= ( const Equation src)
inline

Definition at line 97 of file Equation.h.

{
return *this;
}
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.

{
}
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().

{
m_evaluator.SetParameter(name, value);
}

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().