28 #ifdef DEAL_II_WITH_MUPARSER
29 # include <muParser.h>
36 const std::vector<std::string> &
46 const double initial_time,
56 const std::string &constants,
57 const std::string &variable_names,
90 #ifdef DEAL_II_WITH_MUPARSER
95 const std::vector<std::string> &expressions,
96 const std::map<std::string, double> &constants,
97 const bool time_dependent)
101 this->constants = constants;
103 this->expressions = expressions;
104 AssertThrow(((time_dependent) ? dim + 1 : dim) == var_names.size(),
110 ExcInvalidExpressionSize(this->
n_components, expressions.size()));
147 vars.get().resize(var_names.size());
148 for (
unsigned int component = 0; component < this->
n_components; ++component)
150 fp.get().emplace_back(
new mu::Parser());
152 for (
const auto &constant : constants)
154 fp.get()[component]->DefineConst(constant.first, constant.second);
157 for (
unsigned int iv = 0; iv < var_names.size(); ++iv)
158 fp.get()[component]->DefineVar(var_names[iv], &vars.get()[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)
287 vars.get()[i] = p(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)
324 vars.get()[i] = p(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> &,