From e2d3c1731d6b19f3ecec3ef2fb162daa337aeac7 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 3 Apr 1998 16:18:52 +0000 Subject: [PATCH] Add constant function. git-svn-id: https://svn.dealii.org/trunk@132 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/function.h | 57 ++++++++++++++++++++++++++++ deal.II/base/source/function.cc | 42 ++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/deal.II/base/include/base/function.h b/deal.II/base/include/base/function.h index ef4f87b458..37f9c941a8 100644 --- a/deal.II/base/include/base/function.h +++ b/deal.II/base/include/base/function.h @@ -35,6 +35,12 @@ template class Function { public: + /** + * Virtual destructor; absolutely + * necessary in this case. + */ + virtual ~Function (); + /** * Return the value of the function * at the given point. @@ -89,6 +95,11 @@ class Function { template class ZeroFunction : public Function { public: + /** + * Virtual destructor; absolutely + * necessary in this case. + */ + virtual ~ZeroFunction (); /** * Return the value of the function * at the given point. @@ -123,6 +134,52 @@ class ZeroFunction : public Function { + +/** + 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 +class ConstantFunction : public ZeroFunction { + 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 &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 > &points, + vector &values) const; + + protected: + /** + * Store the constant function value. + */ + const double function_value; +}; + + + + /*---------------------------- function.h ---------------------------*/ /* end of #ifndef __function_H */ #endif diff --git a/deal.II/base/source/function.cc b/deal.II/base/source/function.cc index 20f52784f0..8d728ba68f 100644 --- a/deal.II/base/source/function.cc +++ b/deal.II/base/source/function.cc @@ -5,6 +5,11 @@ #include + +template +Function::~Function () {}; + + template double Function::operator () (const Point &) const { Assert (false, ExcPureFunctionCalled()); @@ -52,6 +57,11 @@ void Function::gradient_list (const vector > &points, +template +ZeroFunction::~ZeroFunction () {}; + + + template double ZeroFunction::operator () (const Point &) const { return 0.; @@ -91,9 +101,41 @@ void ZeroFunction::gradient_list (const vector > &points, +template +ConstantFunction::ConstantFunction (const double value) : + function_value(value) {}; + + +template +ConstantFunction::~ConstantFunction () {}; + + + +template +double ConstantFunction::operator () (const Point &) const { + return function_value; +}; + + + +template +void ConstantFunction::value_list (const vector > &points, + vector &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>; -- 2.39.5