Nektar++
Functions
Python/Interpreter/Interpreter.cpp File Reference
#include <LibUtilities/Interpreter/Interpreter.h>
#include <LibUtilities/BasicConst/NektarUnivTypeDefs.hpp>
#include <LibUtilities/Python/NekPyConfig.hpp>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <boost/python/raw_function.hpp>

Go to the source code of this file.

Functions

py::object Interpreter_AddConstants (py::tuple args, py::dict kwargs)
 Wrapper for Interpreter::AddConstants. More...
 
py::object Interpreter_SetParameters (py::tuple args, py::dict kwargs)
 Wrapper for Interpreter::SetParameters. More...
 
NekDouble Interpreter_GetParameter (std::shared_ptr< Interpreter > interpreter, std::string paramName)
 Wrapper for Interpreter::GetParameter. More...
 
NekDouble Interpreter_GetConstant (std::shared_ptr< Interpreter > interpreter, std::string constantName)
 Wrapper for Interpreter::GetConstant. More...
 
NekDouble Interpreter_Evaluate (std::shared_ptr< Interpreter > interpreter, const int id)
 Wrapper for Interpreter::Evaluate (only constant or parameter). More...
 
NekDouble Interpreter_Evaluate2 (std::shared_ptr< Interpreter > interpreter, const int id, const NekDouble x, const NekDouble y, const NekDouble z, const NekDouble t)
 Wrapper for Interpreter::Evaluate (only constant parameters). More...
 
Array< OneD, NekDoubleInterpreter_Evaluate3 (std::shared_ptr< Interpreter > interpreter, const int id, const Array< OneD, const NekDouble > &x, const Array< OneD, const NekDouble > &y, const Array< OneD, const NekDouble > &z, const Array< OneD, const NekDouble > &t)
 Wrapper for Interpreter::Evaluate (vectorised version of the evaluation method that will allow the same function to be evaluated many times). More...
 
Array< OneD, NekDoubleInterpreter_Evaluate4 (std::shared_ptr< Interpreter > interpreter, const int expression_id, const std::vector< Array< OneD, const NekDouble >> &points)
 Wrapper for Interpreter::Evaluate (zero or more arrays). More...
 
void export_Interpreter ()
 

Function Documentation

◆ export_Interpreter()

void export_Interpreter ( )

Definition at line 226 of file Python/Interpreter/Interpreter.cpp.

227 {
228  py::class_<Interpreter, std::shared_ptr<Interpreter>, boost::noncopyable>(
229  "Interpreter", py::init<>())
230 
231  .def("SetRandomSeed", &Interpreter::SetRandomSeed)
232 
233  .def("AddConstants", py::raw_function(Interpreter_AddConstants))
234  .def("AddConstant", &Interpreter::AddConstant)
235  .def("GetConstant", Interpreter_GetConstant)
236 
237  .def("SetParameters", py::raw_function(Interpreter_SetParameters))
238  .def("SetParameter", &Interpreter::SetParameter)
239  .def("GetParameter", Interpreter_GetParameter)
240 
241  .def("GetTime", &Interpreter::GetTime)
242  .def("DefineFunction", &Interpreter::DefineFunction)
243 
244  .def("Evaluate", Interpreter_Evaluate)
245  .def("Evaluate", Interpreter_Evaluate2)
246  .def("Evaluate", Interpreter_Evaluate3)
247  .def("Evaluate", Interpreter_Evaluate4)
248 
249  ;
250 }
NekDouble Interpreter_Evaluate2(std::shared_ptr< Interpreter > interpreter, const int id, const NekDouble x, const NekDouble y, const NekDouble z, const NekDouble t)
Wrapper for Interpreter::Evaluate (only constant parameters).
Array< OneD, NekDouble > Interpreter_Evaluate3(std::shared_ptr< Interpreter > interpreter, const int id, const Array< OneD, const NekDouble > &x, const Array< OneD, const NekDouble > &y, const Array< OneD, const NekDouble > &z, const Array< OneD, const NekDouble > &t)
Wrapper for Interpreter::Evaluate (vectorised version of the evaluation method that will allow the sa...
NekDouble Interpreter_Evaluate(std::shared_ptr< Interpreter > interpreter, const int id)
Wrapper for Interpreter::Evaluate (only constant or parameter).
NekDouble Interpreter_GetParameter(std::shared_ptr< Interpreter > interpreter, std::string paramName)
Wrapper for Interpreter::GetParameter.
py::object Interpreter_SetParameters(py::tuple args, py::dict kwargs)
Wrapper for Interpreter::SetParameters.
Array< OneD, NekDouble > Interpreter_Evaluate4(std::shared_ptr< Interpreter > interpreter, const int expression_id, const std::vector< Array< OneD, const NekDouble >> &points)
Wrapper for Interpreter::Evaluate (zero or more arrays).
NekDouble Interpreter_GetConstant(std::shared_ptr< Interpreter > interpreter, std::string constantName)
Wrapper for Interpreter::GetConstant.
py::object Interpreter_AddConstants(py::tuple args, py::dict kwargs)
Wrapper for Interpreter::AddConstants.

References Nektar::LibUtilities::Interpreter::AddConstant(), Nektar::LibUtilities::Interpreter::DefineFunction(), Nektar::LibUtilities::Interpreter::GetTime(), Interpreter_AddConstants(), Interpreter_Evaluate(), Interpreter_Evaluate2(), Interpreter_Evaluate3(), Interpreter_Evaluate4(), Interpreter_GetConstant(), Interpreter_GetParameter(), Interpreter_SetParameters(), Nektar::LibUtilities::Interpreter::SetParameter(), and Nektar::LibUtilities::Interpreter::SetRandomSeed().

Referenced by BOOST_PYTHON_MODULE().

◆ Interpreter_AddConstants()

py::object Interpreter_AddConstants ( py::tuple  args,
py::dict  kwargs 
)

Wrapper for Interpreter::AddConstants.

boost.python does not know how (by default) to convert from any Python datatype to a C++ map, so we add a pythonic way to set parameters through keyword arguments.

Parameters
argsPython function positional arguments.
kwargsPython function keyword arguments.
Returns
None (null py::object).

Definition at line 58 of file Python/Interpreter/Interpreter.cpp.

59 {
60  // To extract the 'self' object
61  Interpreter &interpreter = py::extract<Interpreter &>(args[0]);
62 
63  // Map that will be passed to C++
64  std::map<std::string, NekDouble> constants;
65 
66  // Loop over the keys inside the kwargs dictionary
67  py::list keys = kwargs.keys();
68  for (int i = 0; i < py::len(keys); ++i)
69  {
70  py::object arg = kwargs[keys[i]];
71  if (arg)
72  {
73  constants[py::extract<std::string>(keys[i])] =
74  py::extract<NekDouble>(arg);
75  }
76  }
77 
78  interpreter.AddConstants(constants);
79  return py::object();
80 }
Interpreter class for the evaluation of mathematical expressions.
Definition: Interpreter.h:78
void AddConstants(std::map< std::string, NekDouble > const &constants)
Set constants to be evaluated.

References Nektar::LibUtilities::Interpreter::AddConstants().

Referenced by export_Interpreter().

◆ Interpreter_Evaluate()

NekDouble Interpreter_Evaluate ( std::shared_ptr< Interpreter interpreter,
const int  id 
)

Wrapper for Interpreter::Evaluate (only constant or parameter).

Parameters
interpreterInterpreter object
idid of the expression
Returns
Value corresponding to id

Definition at line 156 of file Python/Interpreter/Interpreter.cpp.

158 {
159  return interpreter->Evaluate(id);
160 }

Referenced by export_Interpreter().

◆ Interpreter_Evaluate2()

NekDouble Interpreter_Evaluate2 ( std::shared_ptr< Interpreter interpreter,
const int  id,
const NekDouble  x,
const NekDouble  y,
const NekDouble  z,
const NekDouble  t 
)

Wrapper for Interpreter::Evaluate (only constant parameters).

Parameters
interpreterInterpreter object
idid of the expression
xx-coordinate within the expression
yy-coordinate within the expression
zz-coordinate within the expression
tvalue of time within the expression
Returns
Value of evaluated expression.

Definition at line 174 of file Python/Interpreter/Interpreter.cpp.

178 {
179  return interpreter->Evaluate(id, x, y, z, t);
180 }

Referenced by export_Interpreter().

◆ Interpreter_Evaluate3()

Array<OneD, NekDouble> Interpreter_Evaluate3 ( std::shared_ptr< Interpreter interpreter,
const int  id,
const Array< OneD, const NekDouble > &  x,
const Array< OneD, const NekDouble > &  y,
const Array< OneD, const NekDouble > &  z,
const Array< OneD, const NekDouble > &  t 
)

Wrapper for Interpreter::Evaluate (vectorised version of the evaluation method that will allow the same function to be evaluated many times).

Parameters
interpreterInterpreter object
idid of the expression
xx-coordinates within the expression
yy-coordinates within the expression
zz-coordinates within the expression
tvalues of time within the expression
Returns
Values of evaluated expression.

Definition at line 196 of file Python/Interpreter/Interpreter.cpp.

202 {
203  Array<OneD, NekDouble> tmp(x.size());
204  interpreter->Evaluate(id, x, y, z, t, tmp);
205  return tmp;
206 }

Referenced by export_Interpreter().

◆ Interpreter_Evaluate4()

Array<OneD, NekDouble> Interpreter_Evaluate4 ( std::shared_ptr< Interpreter interpreter,
const int  expression_id,
const std::vector< Array< OneD, const NekDouble >> &  points 
)

Wrapper for Interpreter::Evaluate (zero or more arrays).

Parameters
expression_idid of the expression
pointsvector containing arrays of values required for the expression.
Returns
Values of evaluated expression.

Definition at line 217 of file Python/Interpreter/Interpreter.cpp.

220 {
221  Array<OneD, NekDouble> tmp(points.size());
222  interpreter->Evaluate(expression_id, points, tmp);
223  return tmp;
224 }

Referenced by export_Interpreter().

◆ Interpreter_GetConstant()

NekDouble Interpreter_GetConstant ( std::shared_ptr< Interpreter interpreter,
std::string  constantName 
)

Wrapper for Interpreter::GetConstant.

Parameters
interpreterInterpreter object
constantNameName of constant
Returns
Constant defined by constantName.

Definition at line 141 of file Python/Interpreter/Interpreter.cpp.

143 {
144 
145  return interpreter->GetConstant(constantName);
146 }

Referenced by export_Interpreter().

◆ Interpreter_GetParameter()

NekDouble Interpreter_GetParameter ( std::shared_ptr< Interpreter interpreter,
std::string  paramName 
)

Wrapper for Interpreter::GetParameter.

Parameters
interpreterInterpreter object
paramNameName of parameter
Returns
Parameter defined by paramName.

Definition at line 126 of file Python/Interpreter/Interpreter.cpp.

128 {
129 
130  return interpreter->GetParameter(paramName);
131 }

Referenced by export_Interpreter().

◆ Interpreter_SetParameters()

py::object Interpreter_SetParameters ( py::tuple  args,
py::dict  kwargs 
)

Wrapper for Interpreter::SetParameters.

boost.python does not know how (by default) to convert from any Python datatype to a C++ map, so we add a pythonic way to set parameters through keyword arguments.

Parameters
argsPython function positional arguments.
kwargsPython function keyword arguments.
Returns
None (null py::object).

Definition at line 94 of file Python/Interpreter/Interpreter.cpp.

95 {
96 
97  // To extract the 'self' object
98  Interpreter &interpreter = py::extract<Interpreter &>(args[0]);
99 
100  // Map that will be passed to C++
101  std::map<std::string, NekDouble> parameters;
102 
103  // Loop over the keys inside the kwargs dictionary
104  py::list keys = kwargs.keys();
105  for (int i = 0; i < py::len(keys); ++i)
106  {
107  py::object arg = kwargs[keys[i]];
108  if (arg)
109  {
110  parameters[py::extract<std::string>(keys[i])] =
111  py::extract<NekDouble>(arg);
112  }
113  }
114  interpreter.SetParameters(parameters);
115  return py::object();
116 }
void SetParameters(std::map< std::string, NekDouble > const &params)
Set parameter values.

References Nektar::LibUtilities::Interpreter::SetParameters().

Referenced by export_Interpreter().