8#include <kernel/analytic/function.hpp>
12#if defined(FEAT_HAVE_FPARSER) || defined(DOXYGEN)
107 static_assert((dim_ >= 1) && (dim_ <= 3),
"unsupported function dimension");
143 _parser.AddConstant(
"pi", Math::pi<double>());
144 _parser.AddConstant(
"eps", Math::eps<double>());
195 XASSERTM(name.
compare_no_case(
"x") != 0,
"variable name 'x' is reserved and cannot be used as extra variable");
196 XASSERTM(name.
compare_no_case(
"y") != 0,
"variable name 'y' is reserved and cannot be used as extra variable");
197 XASSERTM(name.
compare_no_case(
"z") != 0,
"variable name 'z' is reserved and cannot be used as extra variable");
233 if(dim_ > 1) vars +=
",y";
234 if(dim_ > 2) vars +=
",z";
238 (vars +=
",") += v.first;
241 const int ret =
_parser.Parse(function.c_str(), vars.c_str());
245 msg.append(
"\n>>> '");
246 msg.append(function);
248 if(ret <
int(function.size()))
253 msg.append(
String(std::size_t(ret+2),
'-'));
263 template<
typename Traits_>
287 _vars(std::size_t(dim_), 0.0)
293 _vars.push_back(v.second);
299 for(
int i(0); i < dim_; ++i)
300 _vars[std::size_t(i)] = double(point[i]);
354 template<
int dom_dim_,
int img_dim_ = dom_dim_>
360 static_assert((dom_dim_ >= 1) && (dom_dim_ <= 3),
"unsupported domain dimension");
361 static_assert(img_dim_ >= 1,
"unsupported image dimension");
433 p.AddConstant(name.c_str(),
value);
450 XASSERTM(name.
compare_no_case(
"x") != 0,
"variable name 'x' is reserved and cannot be used as extra variable");
451 XASSERTM(name.
compare_no_case(
"y") != 0,
"variable name 'y' is reserved and cannot be used as extra variable");
452 XASSERTM(name.
compare_no_case(
"z") != 0,
"variable name 'z' is reserved and cannot be used as extra variable");
489 if(dom_dim_ > 1) vars +=
",y";
490 if(dom_dim_ > 2) vars +=
",z";
494 (vars +=
",") += v.first;
497 if(sfunc.starts_with(
'['))
499 if(sfunc.ends_with(
']'))
504 std::deque<String> sfuncs = sfunc.split_by_charset(
"'");
505 if(sfuncs.size() !=
_parsers.size())
507 String msg(
"Invalid number of formulae: expected ");
509 msg.append(
" but got ");
515 for(std::size_t i(0); i <
_parsers.size(); ++i)
518 const int ret =
_parsers.at(i).Parse(sfuncs.at(i).c_str(), vars.c_str());
522 msg.append(
"\n>>> '");
523 msg.append(sfuncs.at(i));
525 if(ret <
int(sfuncs.at(i).size()))
530 msg.append(
String(std::size_t(ret+2),
'-'));
541 template<
typename Traits_>
562 _vars(std::size_t(dom_dim_), 0.0)
570 _vars.push_back(v.second);
576 for(
int i(0); i < dom_dim_; ++i)
577 _vars[std::size_t(i)] = double(point[i]);
581 for(std::size_t i(0); i <
_parsers.size(); ++i)
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Analytic Function Evaluator base-class template.
Analytic Function interface.
Parsed Function evaluation error.
ParsedFunctionEvalError(const String &msg)
constructor
Parsed Function parse error.
ParsedFunctionParseError(const String &msg)
constructor
::FunctionParser _parser
our own private copy of the function parser
Traits_::ValueType ValueType
value type
Traits_::PointType PointType
evaluation point type
Traits_::DataType DataType
coefficient data type
std::vector< double > _vars
a vector for the variable values
Parsed scalar function implementation.
void set_variable(const String &name, double value)
Sets the value of an extra variable.
static constexpr int domain_dim
validate our dimension
::FunctionParser _parser
the actual function parser object
Analytic::Image::Scalar ImageType
This function is always scalar.
static constexpr bool can_grad
we cannot compute gradients
static constexpr bool can_value
we can compute function values
void parse(const String &function)
Parses a function.
ParsedScalarFunction(const String &function)
Constructor.
std::map< String, double > _extra_vars
our extra variable names
void add_constant(const String &name, double value)
Adds a constant to the parser.
ParsedScalarFunction()
Standard constructor.
void add_variable(const String &name, double value=0.0)
Adds an extra variable to the parser.
static constexpr bool can_hess
we cannot compute hessians
Traits_::PointType PointType
evaluation point type
Traits_::ValueType ValueType
value type
Traits_::DataType DataType
coefficient data type
std::vector< double > _vars
a vector for the variable values
std::array< ::FunctionParser, img_dim_ > _parsers
our own private copy of the function parsers
Parsed vector function implementation.
void set_variable(const String &name, double value)
Sets the value of an extra variable.
static constexpr bool can_grad
we cannot compute gradients
std::map< String, double > _extra_vars
our extra variable names
ParsedVectorFunction(const String &function)
Constructor.
static constexpr int domain_dim
validate our dimensions
static constexpr bool can_value
we can compute function values
void add_variable(const String &name, double value=0.0)
Adds an extra variable to the parser.
static constexpr bool can_hess
we cannot compute hessians
void parse(const String &function)
Parses a function.
void add_constant(const String &name, double value)
Adds a constant to the parser.
Analytic::Image::Vector< img_dim_ > ImageType
This function is always a vector field.
std::array<::FunctionParser, img_dim_ > _parsers
the actual function parser objects
ParsedVectorFunction()
Standard constructor.
Class for parser related errors.
String class implementation.
void pop_front()
Removes the first character from the string.
int compare_no_case(const String &other) const
Compares two strings without regard to case.
String stringify(const T_ &item)
Converts an item into a String.
@ value
specifies whether the space should supply basis function values
Scalar Function Image tag class.
Vector Field Image tag class.