28 #ifdef DEAL_II_WITH_MUPARSER 29 # include <muParser.h> 36 const std::vector<std::string> &
46 const double initial_time,
57 const std::string &variable_names,
90 #ifdef DEAL_II_WITH_MUPARSER 96 const std::map<std::string, double> &
constants,
97 const bool time_dependent)
148 for (
unsigned int component = 0; component < this->
n_components; ++component)
150 fp.
get().emplace_back(
new mu::Parser());
154 fp.
get()[component]->DefineConst(constant.first, constant.second);
157 for (
unsigned int iv = 0; iv <
var_names.size(); ++iv)
161 fp.
get()[component]->DefineFun(
"if",
166 fp.
get()[component]->DefineFun(
"int",
169 fp.
get()[component]->DefineFun(
"ceil",
172 fp.
get()[component]->DefineFun(
"cot",
175 fp.
get()[component]->DefineFun(
"csc",
178 fp.
get()[component]->DefineFun(
"floor",
181 fp.
get()[component]->DefineFun(
"sec",
184 fp.
get()[component]->DefineFun(
"log",
187 fp.
get()[component]->DefineFun(
"pow",
190 fp.
get()[component]->DefineFun(
"erfc",
193 fp.
get()[component]->DefineFun(
"rand_seed",
196 fp.
get()[component]->DefineFun(
"rand",
209 std::string transformed_expression =
expressions[component];
211 for (
const auto ¤t_function_name :
214 const unsigned int function_name_length =
215 current_function_name.size();
221 pos = transformed_expression.find(current_function_name, pos);
222 if (pos == std::string::npos)
226 while ((pos + function_name_length <
227 transformed_expression.size()) &&
228 ((transformed_expression[pos + function_name_length] ==
230 (transformed_expression[pos + function_name_length] ==
232 transformed_expression.erase(
233 transformed_expression.begin() + pos +
234 function_name_length);
238 pos += function_name_length;
243 fp.
get()[component]->SetExpr(transformed_expression);
245 catch (mu::ParserError &
e)
247 std::cerr <<
"Message: <" << e.GetMsg() <<
">\n";
248 std::cerr <<
"Formula: <" << e.GetExpr() <<
">\n";
249 std::cerr <<
"Token: <" << e.GetToken() <<
">\n";
250 std::cerr <<
"Position: <" << e.GetPos() <<
">\n";
251 std::cerr <<
"Errc: <" << e.GetCode() <<
">" << std::endl;
262 const std::string & expression,
263 const std::map<std::string, double> &
constants,
264 const bool time_dependent)
277 const unsigned int component)
const 283 if (
fp.
get().size() == 0)
286 for (
unsigned int i = 0; i < dim; ++i)
293 return fp.
get()[component]->Eval();
295 catch (mu::ParserError &
e)
297 std::cerr <<
"Message: <" << e.GetMsg() <<
">\n";
298 std::cerr <<
"Formula: <" << e.GetExpr() <<
">\n";
299 std::cerr <<
"Token: <" << e.GetToken() <<
">\n";
300 std::cerr <<
"Position: <" << e.GetPos() <<
">\n";
301 std::cerr <<
"Errc: <" << e.GetCode() <<
">" << std::endl;
320 if (
fp.
get().size() == 0)
323 for (
unsigned int i = 0; i < dim; ++i)
328 for (
unsigned int component = 0; component < this->
n_components; ++component)
329 values(component) =
fp.
get()[component]->Eval();
338 const std::vector<std::string> &,
339 const std::map<std::string, double> &,
349 const std::map<std::string, double> &,
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
static ::ExceptionBase & ExcNeedsFunctionparser()
double mu_ceil(double value)
FunctionParser(const unsigned int n_components=1, const double initial_time=0.0, const double h=1e-8)
const unsigned int n_components
types::global_dof_index size_type
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
double mu_int(double value)
#define AssertIndexRange(index, range)
static const unsigned int max_int_value
static ::ExceptionBase & ExcParseError(int arg1, std::string arg2)
double mu_floor(double value)
static ::ExceptionBase & ExcNotInitialized()
#define AssertThrow(cond, exc)
double mu_rand_seed(double seed)
double mu_csc(double value)
static ::ExceptionBase & ExcMessage(std::string arg1)
virtual void vector_value(const Point< dim > &p, Vector< double > &values) const override
double mu_and(double left, double right)
Threads::ThreadLocalStorage< std::vector< std::unique_ptr< mu::Parser > > > fp
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
double mu_or(double left, double right)
Threads::ThreadLocalStorage< std::vector< double > > vars
#define DEAL_II_NAMESPACE_CLOSE
void init_muparser() const
static ::ExceptionBase & ExcInvalidExpressionSize(int arg1, int arg2)
double mu_if(double condition, double thenvalue, double elsevalue)
double mu_log(double value)
double mu_pow(double a, double b)
double mu_sec(double value)
double mu_erfc(double value)
std::vector< std::string > var_names
const std::vector< std::string > & get_expressions() const
void initialize(const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false)
#define DEAL_II_NAMESPACE_OPEN
std::vector< std::string > function_names
unsigned int n_components(const DoFHandler< dim, spacedim > &dh)
virtual double value(const Point< dim > &p, const unsigned int component=0) const override
double mu_cot(double value)
std::vector< std::string > expressions
virtual ~FunctionParser() override
std::map< std::string, double > constants
static ::ExceptionBase & ExcInternalError()