27 , function_object(n_components)
35 const unsigned int n_components,
36 const std::string &input_expr)
60 "The names of the variables as they will be used in the "
61 "function, separated by commas. By default, the names of variables "
62 "at which the function will be evaluated are `x' (in 1d), `x,y' (in 2d) or "
63 "`x,y,z' (in 3d) for spatial coordinates and `t' for time. You can then "
64 "use these variable names in your function expression and they will be "
65 "replaced by the values of these variables at which the function is "
66 "currently evaluated. However, you can also choose a different set "
67 "of names for the independent variables at which to evaluate your function "
68 "expression. For example, if you work in spherical coordinates, you may "
69 "wish to set this input parameter to `r,phi,theta,t' and then use these "
70 "variable names in your function expression.");
74 std::string expr = input_expr;
78 for (
unsigned int i = 1; i < n_components; ++i)
91 "Function expression",
94 "The formula that denotes the function you want to evaluate for "
95 "particular values of the independent variables. This expression "
96 "may contain any of the usual operations such as addition or "
97 "multiplication, as well as all of the common functions such as "
98 "`sin' or `cos'. In addition, it may contain expressions like "
99 "`if(x>0, 1, -1)' where the expression evaluates to the second "
100 "argument if the first argument is true, and to the third argument "
101 "otherwise. For a full overview of possible expressions accepted "
102 "see the documentation of the muparser library at http://muparser.beltoforion.de/."
104 "If the function you are describing represents a vector-valued "
105 "function with multiple components, then separate the expressions "
106 "for individual components by a semicolon.");
108 "Function constants",
111 "Sometimes it is convenient to use symbolic constants in the "
112 "expression that describes the function, rather than having to "
113 "use its numeric value everywhere the constant appears. These "
114 "values can be defined using this parameter, in the form "
115 "`var1=value1, var2=value2, ...'."
117 "A typical example would be to set this runtime parameter to "
118 "`pi=3.1415926536' and then use `pi' in the expression of the "
119 "actual formula. (That said, for convenience this class actually "
120 "defines both `pi' and `Pi' by default, but you get the idea.)");
129 std::string vnames = prm.
get(
"Variable names");
130 std::string expression = prm.
get(
"Function expression");
131 std::string constants_list = prm.
get(
"Function constants");
133 std::vector<std::string> const_list =
135 std::map<std::string, double> constants;
136 for (
const auto &constant : const_list)
138 std::vector<std::string> this_c =
141 ExcMessage(
"The list of constants, <" + constants_list +
142 ">, is not a comma-separated list of "
143 "entries of the form 'name=value'."));
157 function_object.initialize(vnames, expression, constants);
161 function_object.initialize(vnames, expression, constants,
true);
166 "The list of variables specified is <" + vnames +
167 "> which is a list of length " +
169 " but it has to be a list of length equal to" +
170 " either dim (for a time-independent function)" +
171 " or dim+1 (for a time-dependent function)."));
182 function_object.vector_value(p, values);
191 return function_object.value(p, comp);
200 function_object.set_time(newtime);
virtual void set_time(const Number new_time)
virtual void vector_value(const Point< dim > &p, Vector< double > &values) const override
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
static void declare_parameters(ParameterHandler &prm, const unsigned int n_components=1, const std::string &input_expr="")
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)
#define AssertDimension(dim1, dim2)
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)