&values,
const double initial_time = 0.0);
+ /**
+ * Constructor for functions of which you only know the values.
+ *
+ * The resulting function will have a number of components equal @p n_components.
+ * A call to the FunctionFromFunctionObject::gradient()
+ * method will trigger an exception, unless you first call the
+ * set_function_gradients() method.
+ */
+ explicit FunctionFromFunctionObjects(
+ const std::function<RangeNumberType(const Point<dim> &, const unsigned int)>
+ &values,
+ const unsigned int n_components,
+ const double initial_time = 0.0);
+
/**
* Constructor for functions of which you know both the values and the
* gradients.
/**
* The actual function values.
*/
- std::vector<std::function<RangeNumberType(const Point<dim> &)>>
+ std::function<RangeNumberType(const Point<dim> &, const unsigned int)>
function_values;
/**
* The actual function gradients.
*/
- std::vector<
- std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &)>>
+ std::function<Tensor<1, dim, RangeNumberType>(const Point<dim> &,
+ const unsigned int)>
function_gradients;
};
const unsigned int n_components,
const double initial_time)
: Function<dim, RangeNumberType>(n_components, initial_time)
- , function_values(n_components)
- , function_gradients(n_components)
{}
const std::vector<std::function<RangeNumberType(const Point<dim> &)>> &values,
const double initial_time)
: Function<dim, RangeNumberType>(values.size(), initial_time)
+{
+ this->set_function_values(values);
+}
+
+
+
+template <int dim, typename RangeNumberType>
+FunctionFromFunctionObjects<dim, RangeNumberType>::FunctionFromFunctionObjects(
+ const std::function<RangeNumberType(const Point<dim> &, const unsigned int)>
+ &values,
+ const unsigned int n_components,
+ const double initial_time)
+ : Function<dim, RangeNumberType>(n_components, initial_time)
, function_values(values)
- , function_gradients(values.size())
{}
&gradients,
const double initial_time)
: Function<dim, RangeNumberType>(values.size(), initial_time)
- , function_values(values)
- , function_gradients(gradients)
-{}
+{
+ this->set_function_values(values);
+ this->set_function_gradients(gradients);
+}
const unsigned int component) const
{
AssertIndexRange(component, this->n_components);
- Assert(function_values[component],
+ Assert(function_values,
ExcMessage("Accessing value() in FunctionFromFunctionObjects requires "
"setting the std::function objects for the value"));
- return function_values[component](p);
+ return function_values(p, component);
}
const unsigned int component) const
{
AssertIndexRange(component, this->n_components);
- Assert(function_gradients[component],
+ Assert(function_gradients,
ExcMessage(
"Accessing gradient() in FunctionFromFunctionObjects "
"requires setting the std::function objects for the gradient"));
- return function_gradients[component](p);
+ return function_gradients(p, component);
}
const std::vector<std::function<RangeNumberType(const Point<dim> &)>> &values)
{
AssertDimension(this->n_components, values.size());
- function_values = values;
+ function_values = [values](const auto &p, const auto c) {
+ AssertIndexRange(c, values.size());
+ return values[c](p);
+ };
}
&gradients)
{
AssertDimension(this->n_components, gradients.size());
- function_gradients = gradients;
+ function_gradients = [gradients](const auto &p, const auto c) {
+ AssertIndexRange(c, gradients.size());
+ return gradients[c](p);
+ };
}
DEAL_II_NAMESPACE_CLOSE