template <int dim>
class Function {
public:
+ /**
+ * Virtual destructor; absolutely
+ * necessary in this case.
+ */
+ virtual ~Function ();
+
/**
* Return the value of the function
* at the given point.
template <int dim>
class ZeroFunction : public Function<dim> {
public:
+ /**
+ * Virtual destructor; absolutely
+ * necessary in this case.
+ */
+ virtual ~ZeroFunction ();
/**
* Return the value of the function
* at the given point.
+
+/**
+ Provide a function which always returns a constant value, which is delivered
+ upon construction. Obviously, the derivates of this function are zerom which
+ is why we derive this class from #ZeroFunction#: we then only have to
+ overload th value functions, not all the derivatives.
+*/
+template <int dim>
+class ConstantFunction : public ZeroFunction<dim> {
+ public:
+ /**
+ * Constructor; takes the constant function
+ * value as an argument.
+ */
+ ConstantFunction (const double value);
+
+ /**
+ * Virtual destructor; absolutely
+ * necessary in this case.
+ */
+ virtual ~ConstantFunction ();
+ /**
+ * Return the value of the function
+ * at the given point.
+ */
+ virtual double operator () (const Point<dim> &p) const;
+
+ /**
+ * Set #values# to the point values
+ * of the function at the #points#.
+ * It is assumed that #values# be
+ * empty.
+ */
+ virtual void value_list (const vector<Point<dim> > &points,
+ vector<double> &values) const;
+
+ protected:
+ /**
+ * Store the constant function value.
+ */
+ const double function_value;
+};
+
+
+
+
/*---------------------------- function.h ---------------------------*/
/* end of #ifndef __function_H */
#endif
#include <vector.h>
+
+template <int dim>
+Function<dim>::~Function () {};
+
+
template <int dim>
double Function<dim>::operator () (const Point<dim> &) const {
Assert (false, ExcPureFunctionCalled());
+template <int dim>
+ZeroFunction<dim>::~ZeroFunction () {};
+
+
+
template <int dim>
double ZeroFunction<dim>::operator () (const Point<dim> &) const {
return 0.;
+template <int dim>
+ConstantFunction<dim>::ConstantFunction (const double value) :
+ function_value(value) {};
+
+
+template <int dim>
+ConstantFunction<dim>::~ConstantFunction () {};
+
+
+
+template <int dim>
+double ConstantFunction<dim>::operator () (const Point<dim> &) const {
+ return function_value;
+};
+
+
+
+template <int dim>
+void ConstantFunction<dim>::value_list (const vector<Point<dim> > &points,
+ vector<double> &values) const {
+ Assert (values.size() == 0,
+ ExcVectorNotEmpty());
+
+ values.reserve (points.size());
+ values.insert (values.begin(), points.size(), function_value);
+};
+
+
+
// explicit instantiations
template class Function<1>;
template class Function<2>;
template class ZeroFunction<1>;
template class ZeroFunction<2>;
+
+template class ConstantFunction<1>;
+template class ConstantFunction<2>;