Commit d842b433 authored by Kilian Lackhove's avatar Kilian Lackhove

Added possiblility to define additional variables in the FUNCTION tags

parent 86c71f01
...@@ -56,24 +56,34 @@ namespace Nektar ...@@ -56,24 +56,34 @@ namespace Nektar
public: public:
LIB_UTILITIES_EXPORT Equation(const Equation &src): LIB_UTILITIES_EXPORT Equation(const Equation &src):
m_vlist (src.m_vlist),
m_expr (src.m_expr), m_expr (src.m_expr),
m_expr_id (src.m_expr_id), m_expr_id (src.m_expr_id),
m_evaluator (src.m_evaluator) m_evaluator (src.m_evaluator)
{ {
} }
LIB_UTILITIES_EXPORT Equation(const SessionReaderSharedPtr& session, const std::string& expr = ""): LIB_UTILITIES_EXPORT Equation(const SessionReaderSharedPtr& session,
const std::string& expr = "",
const std::string& vlist = ""):
m_vlist (vlist),
m_expr (expr), m_expr (expr),
m_expr_id (-1), m_expr_id (-1),
m_evaluator (session->GetExpressionEvaluator()) m_evaluator (session->GetExpressionEvaluator())
{ {
boost::algorithm::trim(m_expr); boost::algorithm::trim(m_expr);
boost::algorithm::trim(m_vlist);
if (m_vlist.empty())
{
m_vlist = "x y z t";
}
try try
{ {
if (!m_expr.empty()) if (!m_expr.empty())
{ {
m_expr_id = m_evaluator.DefineFunction("x y z t", m_expr); m_expr_id = m_evaluator.DefineFunction(m_vlist, m_expr);
} }
} }
catch (const std::runtime_error& e) catch (const std::runtime_error& e)
...@@ -171,12 +181,24 @@ namespace Nektar ...@@ -171,12 +181,24 @@ namespace Nektar
const Array<OneD, const NekDouble>& z, const Array<OneD, const NekDouble>& z,
const Array<OneD, const NekDouble>& t, const Array<OneD, const NekDouble>& t,
Array<OneD, NekDouble>& result) const Array<OneD, NekDouble>& result) const
{
std::vector<Array<OneD, const NekDouble> > points;
points.push_back(x);
points.push_back(y);
points.push_back(z);
points.push_back(t);
Evaluate(points, result);
}
LIB_UTILITIES_EXPORT void Evaluate(
const std::vector<Array<OneD, const NekDouble> > points,
Array<OneD, NekDouble>& result) const
{ {
try try
{ {
if (m_expr_id != -1) if (m_expr_id != -1)
{ {
m_evaluator.Evaluate(m_expr_id, x,y,z,t, result); m_evaluator.Evaluate(m_expr_id, points, result);
} }
} }
catch (const std::runtime_error& e) catch (const std::runtime_error& e)
...@@ -208,6 +230,11 @@ namespace Nektar ...@@ -208,6 +230,11 @@ namespace Nektar
return m_expr; return m_expr;
} }
LIB_UTILITIES_EXPORT std::string GetVlist(void) const
{
return m_vlist;
}
/// Returns time spend on expression evaluation at /// Returns time spend on expression evaluation at
/// points (it does not include parse/pre-processing time). /// points (it does not include parse/pre-processing time).
LIB_UTILITIES_EXPORT NekDouble GetTime() const LIB_UTILITIES_EXPORT NekDouble GetTime() const
...@@ -216,6 +243,7 @@ namespace Nektar ...@@ -216,6 +243,7 @@ namespace Nektar
} }
private: private:
std::string m_vlist;
std::string m_expr; std::string m_expr;
int m_expr_id; int m_expr_id;
AnalyticExpressionEvaluator& m_evaluator; AnalyticExpressionEvaluator& m_evaluator;
......
...@@ -2416,6 +2416,13 @@ namespace Nektar ...@@ -2416,6 +2416,13 @@ namespace Nektar
domainStr = variable->Attribute("DOMAIN"); domainStr = variable->Attribute("DOMAIN");
} }
// If no domain string put to 0
std::string evarsStr = "x y z t";
if (variable->Attribute("EVARS"))
{
evarsStr = evarsStr + std::string(" ") + variable->Attribute("EVARS");
}
// Parse list of variables // Parse list of variables
std::vector<std::string> varSplit; std::vector<std::string> varSplit;
std::vector<unsigned int> domainList; std::vector<unsigned int> domainList;
...@@ -2441,7 +2448,7 @@ namespace Nektar ...@@ -2441,7 +2448,7 @@ namespace Nektar
// set expression // set expression
funcDef.m_expression = MemoryManager<Equation> funcDef.m_expression = MemoryManager<Equation>
::AllocateSharedPtr(GetSharedThisPtr(),fcnStr); ::AllocateSharedPtr(GetSharedThisPtr(), fcnStr, evarsStr);
} }
// Files are denoted by F // Files are denoted by F
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment