27 , function_object(n_components)
35 const unsigned int n_components)
59 "The names of the variables as they will be used in the "
60 "function, separated by commas. By default, the names of variables "
61 "at which the function will be evaluated are `x' (in 1d), `x,y' (in 2d) or "
62 "`x,y,z' (in 3d) for spatial coordinates and `t' for time. You can then "
63 "use these variable names in your function expression and they will be "
64 "replaced by the values of these variables at which the function is "
65 "currently evaluated. However, you can also choose a different set "
66 "of names for the independent variables at which to evaluate your function "
67 "expression. For example, if you work in spherical coordinates, you may "
68 "wish to set this input parameter to `r,phi,theta,t' and then use these "
69 "variable names in your function expression.");
72 std::string expr =
"0";
73 for (
unsigned int i = 1; i < n_components; ++i)
77 "Function expression",
80 "The formula that denotes the function you want to evaluate for "
81 "particular values of the independent variables. This expression "
82 "may contain any of the usual operations such as addition or "
83 "multiplication, as well as all of the common functions such as "
84 "`sin' or `cos'. In addition, it may contain expressions like "
85 "`if(x>0, 1, -1)' where the expression evaluates to the second "
86 "argument if the first argument is true, and to the third argument "
87 "otherwise. For a full overview of possible expressions accepted "
88 "see the documentation of the muparser library at http://muparser.beltoforion.de/."
90 "If the function you are describing represents a vector-valued "
91 "function with multiple components, then separate the expressions "
92 "for individual components by a semicolon.");
97 "Sometimes it is convenient to use symbolic constants in the "
98 "expression that describes the function, rather than having to "
99 "use its numeric value everywhere the constant appears. These "
100 "values can be defined using this parameter, in the form "
101 "`var1=value1, var2=value2, ...'."
103 "A typical example would be to set this runtime parameter to "
104 "`pi=3.1415926536' and then use `pi' in the expression of the "
105 "actual formula. (That said, for convenience this class actually "
106 "defines both `pi' and `Pi' by default, but you get the idea.)");
115 std::string vnames = prm.
get(
"Variable names");
116 std::string expression = prm.
get(
"Function expression");
117 std::string constants_list = prm.
get(
"Function constants");
119 std::vector<std::string> const_list =
121 std::map<std::string, double> constants;
122 for (
const auto &constant : const_list)
124 std::vector<std::string> this_c =
127 ExcMessage(
"The list of constants, <" + constants_list +
128 ">, is not a comma-separated list of "
129 "entries of the form 'name=value'."));
143 function_object.initialize(vnames, expression, constants);
147 function_object.initialize(vnames, expression, constants,
true);
152 "The list of variables specified is <" + vnames +
153 "> which is a list of length " +
155 " but it has to be a list of length equal to" +
156 " either dim (for a time-independent function)" +
157 " or dim+1 (for a time-dependent function)."));
168 function_object.vector_value(p, values);
177 return function_object.value(p, comp);
186 function_object.set_time(newtime);
virtual void set_time(const numbers::NumberTraits< double >::real_type new_time)
virtual void vector_value(const Point< dim > &p, Vector< double > &values) const override
static void declare_parameters(ParameterHandler &prm, const unsigned int n_components=1)
ParsedFunction(const unsigned int n_components=1, const double h=1e-8)
virtual double value(const Point< dim > &p, const unsigned int component=0) const override
virtual void set_time(const double newtime) override
void parse_parameters(ParameterHandler &prm)
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation="", const bool has_to_be_set=false)
std::string get(const std::string &entry_string) const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcZero()
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
double string_to_double(const std::string &s)
static constexpr double PI