]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add constant function.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 3 Apr 1998 16:18:52 +0000 (16:18 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 3 Apr 1998 16:18:52 +0000 (16:18 +0000)
git-svn-id: https://svn.dealii.org/trunk@132 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/function.h
deal.II/base/source/function.cc

index ef4f87b458e2f3a581c70e3ef30d33618c001330..37f9c941a8b2668c999a95b5587e9df3977bbe0a 100644 (file)
 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.
@@ -89,6 +95,11 @@ class Function {
 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.
@@ -123,6 +134,52 @@ class ZeroFunction : public Function<dim> {
 
 
 
+
+/**
+   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
index 20f52784f0217230b86c7a51d6f532d40ad979b7..8d728ba68f8f6b4ceed771e63b3e9871a51e7fee 100644 (file)
@@ -5,6 +5,11 @@
 #include <vector.h>
 
 
+
+template <int dim>
+Function<dim>::~Function () {};
+
+
 template <int dim>
 double Function<dim>::operator () (const Point<dim> &) const {
   Assert (false, ExcPureFunctionCalled());
@@ -52,6 +57,11 @@ void Function<dim>::gradient_list (const vector<Point<dim> > &points,
 
 
 
+template <int dim>
+ZeroFunction<dim>::~ZeroFunction () {};
+
+
+
 template <int dim>
 double ZeroFunction<dim>::operator () (const Point<dim> &) const {
   return 0.;
@@ -91,9 +101,41 @@ void ZeroFunction<dim>::gradient_list (const vector<Point<dim> > &points,
 
 
 
+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>;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.