28 , function_object(n_components)
36 const unsigned int n_components)
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.");
73 std::string expr =
"0";
74 for (
unsigned int i = 1; i < n_components; ++i)
78 "Function expression",
81 "The formula that denotes the function you want to evaluate for "
82 "particular values of the independent variables. This expression "
83 "may contain any of the usual operations such as addition or "
84 "multiplication, as well as all of the common functions such as "
85 "`sin' or `cos'. In addition, it may contain expressions like "
86 "`if(x>0, 1, -1)' where the expression evaluates to the second "
87 "argument if the first argument is true, and to the third argument "
88 "otherwise. For a full overview of possible expressions accepted "
89 "see the documentation of the muparser library at http://muparser.beltoforion.de/."
91 "If the function you are describing represents a vector-valued "
92 "function with multiple components, then separate the expressions "
93 "for individual components by a semicolon.");
98 "Sometimes it is convenient to use symbolic constants in the "
99 "expression that describes the function, rather than having to "
100 "use its numeric value everywhere the constant appears. These "
101 "values can be defined using this parameter, in the form "
102 "`var1=value1, var2=value2, ...'."
104 "A typical example would be to set this runtime parameter to "
105 "`pi=3.1415926536' and then use `pi' in the expression of the "
106 "actual formula. (That said, for convenience this class actually "
107 "defines both `pi' and `Pi' by default, but you get the idea.)");
116 std::string vnames = prm.
get(
"Variable names");
117 std::string expression = prm.
get(
"Function expression");
118 std::string constants_list = prm.
get(
"Function constants");
120 std::vector<std::string> const_list =
122 std::map<std::string, double> constants;
123 for (
const auto &constant : const_list)
125 std::vector<std::string> this_c =
129 AssertThrow(std::sscanf(this_c[1].c_str(),
"%lf", &tmp),
131 constants[this_c[0]] = tmp;
144 function_object.initialize(vnames, expression, constants);
148 function_object.initialize(vnames, expression, constants,
true);
153 "The list of variables specified is <" + vnames +
154 "> which is a list of length " +
156 " but it has to be a list of length equal to" +
157 " either dim (for a time-independent function)" +
158 " or dim+1 (for a time-dependent function)."));
169 function_object.vector_value(p, values);
178 return function_object.value(p, comp);
187 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
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)
static constexpr double PI