16 #include <deal.II/base/parsed_function.h> 17 #include <deal.II/base/utilities.h> 21 DEAL_II_NAMESPACE_OPEN
29 , function_object(n_components)
37 const unsigned int n_components)
61 "The names of the variables as they will be used in the " 62 "function, separated by commas. By default, the names of variables " 63 "at which the function will be evaluated are `x' (in 1d), `x,y' (in 2d) or " 64 "`x,y,z' (in 3d) for spatial coordinates and `t' for time. You can then " 65 "use these variable names in your function expression and they will be " 66 "replaced by the values of these variables at which the function is " 67 "currently evaluated. However, you can also choose a different set " 68 "of names for the independent variables at which to evaluate your function " 69 "expression. For example, if you work in spherical coordinates, you may " 70 "wish to set this input parameter to `r,phi,theta,t' and then use these " 71 "variable names in your function expression.");
74 std::string expr =
"0";
75 for (
unsigned int i = 1; i < n_components; ++i)
79 "Function expression",
82 "The formula that denotes the function you want to evaluate for " 83 "particular values of the independent variables. This expression " 84 "may contain any of the usual operations such as addition or " 85 "multiplication, as well as all of the common functions such as " 86 "`sin' or `cos'. In addition, it may contain expressions like " 87 "`if(x>0, 1, -1)' where the expression evaluates to the second " 88 "argument if the first argument is true, and to the third argument " 89 "otherwise. For a full overview of possible expressions accepted " 90 "see the documentation of the muparser library at http://muparser.beltoforion.de/." 92 "If the function you are describing represents a vector-valued " 93 "function with multiple components, then separate the expressions " 94 "for individual components by a semicolon.");
99 "Sometimes it is convenient to use symbolic constants in the " 100 "expression that describes the function, rather than having to " 101 "use its numeric value everywhere the constant appears. These " 102 "values can be defined using this parameter, in the form " 103 "`var1=value1, var2=value2, ...'." 105 "A typical example would be to set this runtime parameter to " 106 "`pi=3.1415926536' and then use `pi' in the expression of the " 107 "actual formula. (That said, for convenience this class actually " 108 "defines both `pi' and `Pi' by default, but you get the idea.)");
117 std::string vnames = prm.
get(
"Variable names");
118 std::string expression = prm.
get(
"Function expression");
119 std::string constants_list = prm.
get(
"Function constants");
121 std::vector<std::string> const_list =
123 std::map<std::string, double> constants;
124 for (
const auto &constant : const_list)
126 std::vector<std::string> this_c =
130 AssertThrow(std::sscanf(this_c[1].c_str(),
"%lf", &tmp),
132 constants[this_c[0]] = tmp;
145 function_object.initialize(vnames, expression, constants);
149 function_object.initialize(vnames, expression, constants,
true);
154 "The list of variables specified is <" + vnames +
155 "> which is a list of length " +
157 " but it has to be a list of length equal to" +
158 " either dim (for a time-independent function)" +
159 " or dim+1 (for a time-dependent function)."));
170 function_object.vector_value(p, values);
179 return function_object.value(p, comp);
188 function_object.set_time(newtime);
198 DEAL_II_NAMESPACE_CLOSE
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation="")
virtual void vector_value(const Point< dim > &p, Vector< double > &values) const override
std::string get(const std::string &entry_string) const
#define AssertThrow(cond, exc)
virtual void set_time(const double newtime) override
static void declare_parameters(ParameterHandler &prm, const unsigned int n_components=1)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
void parse_parameters(ParameterHandler &prm)
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
virtual void set_time(const Number new_time)
ParsedFunction(const unsigned int n_components=1, const double h=1e-8)
static constexpr double PI
static ::ExceptionBase & ExcNotImplemented()
virtual double value(const Point< dim > &p, const unsigned int component=0) const override
static ::ExceptionBase & ExcZero()