]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
FunctionTime base object for Function<dim>
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 5 Feb 1999 13:08:02 +0000 (13:08 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 5 Feb 1999 13:08:02 +0000 (13:08 +0000)
git-svn-id: https://svn.dealii.org/trunk@756 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/function.h
deal.II/base/include/base/function_time.h [new file with mode: 0644]
deal.II/base/include/base/tensor.h
deal.II/base/source/function.cc
deal.II/base/source/function_time.cc [new file with mode: 0644]

index f992406d9c0f7cc7d3ae5f980517a9f2c0f04cc1..e3a6acde4baddfb69f3d7e2f19bfb97eef487a2b 100644 (file)
@@ -9,7 +9,7 @@
 #include <base/exceptions.h>
 #include <vector>
 #include <base/point.h>
-
+#include <base/functiontime.h>
 
 
 
  *  less than the virtual function call itself.
  *
  *
- *  \subsection{Support for time dependant functions}
- *
- *  The library was also designed for time dependant problems. For this
- *  purpose, the function objects also contain a field which stores the
- *  time, as well as functions manipulating them. Time independant problems
- *  should not access or even abuse them for other purposes, but since one
- *  normally does not create thousands of function objects, the gain in
- *  generality weighs out the fact that we need not store the time value
- *  for not time dependant problems. The second advantage is that the derived
- *  standard classes like #ZeroFunction#, #ConstantFunction# etc also work
- *  for time dependant problems.
- *
- *  Access to the time goes through the following functions:
- *  \begin{verbatim}
- *  \item #get_time#: return the present value of the time variable.
- *  \item #set_time#: set the time value to a specific value.
- *  \item #advance_time#: increase the time by a certain time step.
- *  \end{verbatim}
- *  The latter two functions are virtual, so that derived classes can
- *  perform computations which need only be done once for every new time.
- *  For example, if a time dependant function had a factor #sin(t)#, then
- *  it may be a reasonable choice to calculate this factor in a derived
- *  version of #set_time#, store it in a member variable and use that one
- *  rather than computing it every time #operator()#, #value_list# or one
- *  of the other functions is called.
- *
- *  By default, the #advance_time# function calls the #set_time# function
- *  with the new time, so it is sufficient in most cases to overload only
- *  #set_time# for computations as sketched out above.
- *
- *  Derived classes should access the time variable directly, which is
- *  available under the obvious name #time#, rather than calling
- *  #get_time#.
- *
- *  The constructor of this class takes an initial value for the time
- *  variable, which defaults to zero. Because a default value is given,
- *  none of the derived classes needs to take an initial value for the
- *  time variable if not needed.
- *
- *  Once again the warning: do not use the #time# variable for any other
- *  purpose than the intended one! This will inevitably lead to confusion.
- *
- *
- *  @author Wolfgang Bangerth, 1998
+ *  Support for time dependant functions can be found in the base
+ *  class #FunctionTime#.
+
+ *  @author Wolfgang Bangerth, 1998, 1999
  */
 template <int dim>
-class Function {
+class Function :
+  public FunctionTime
+{
   public:
                                     /**
                                      * Constructor. May take an initial vakue
@@ -127,23 +89,6 @@ class Function {
                                      */
     virtual void gradient_list (const vector<Point<dim> > &points,
                                vector<Tensor<1,dim> >    &gradients) const;
-
-                                    /**
-                                     * Return the value of the time variable/
-                                     */
-    double get_time () const;
-
-                                    /**
-                                     * Set the time to #new_time#, overwriting
-                                     * the old value.
-                                     */
-    virtual void set_time (const double new_time);
-
-                                    /**
-                                     * Advance the time by the given
-                                     * time step #delta_t#.
-                                     */
-    virtual void advance_time (const double delta_t);
     
                                     /**
                                      * Exception
diff --git a/deal.II/base/include/base/function_time.h b/deal.II/base/include/base/function_time.h
new file mode 100644 (file)
index 0000000..d29dc46
--- /dev/null
@@ -0,0 +1,100 @@
+/*---------------------------- functiontime.h ---------------------------*/
+/*      $Id$ */
+/*      Copyright W. Bangerth, Guido Kanschat
+ * University of Heidelberg, 1998, 1999 */
+#ifndef __functiontime_H
+#define __functiontime_H
+/*---------------------------- functiontime.h ---------------------------*/
+
+
+#include <base/exceptions.h>
+
+/**
+ *  Support for time dependent functions.
+ *  The library was also designed for time dependent problems. For this
+ *  purpose, the function objects also contain a field which stores the
+ *  time, as well as functions manipulating them. Time independent problems
+ *  should not access or even abuse them for other purposes, but since one
+ *  normally does not create thousands of function objects, the gain in
+ *  generality weighs out the fact that we need not store the time value
+ *  for not time dependent problems. The second advantage is that the derived
+ *  standard classes like #ZeroFunction#, #ConstantFunction# etc also work
+ *  for time dependent problems.
+ *
+ *  Access to the time goes through the following functions:
+ *  \begin{verbatim}
+ *  \item #get_time#: return the present value of the time variable.
+ *  \item #set_time#: set the time value to a specific value.
+ *  \item #advance_time#: increase the time by a certain time step.
+ *  \end{verbatim}
+ *  The latter two functions are virtual, so that derived classes can
+ *  perform computations which need only be done once for every new time.
+ *  For example, if a time dependent function had a factor #sin(t)#, then
+ *  it may be a reasonable choice to calculate this factor in a derived
+ *  version of #set_time#, store it in a member variable and use that one
+ *  rather than computing it every time #operator()#, #value_list# or one
+ *  of the other functions is called.
+ *
+ *  By default, the #advance_time# function calls the #set_time# function
+ *  with the new time, so it is sufficient in most cases to overload only
+ *  #set_time# for computations as sketched out above.
+ *
+ *  The constructor of this class takes an initial value for the time
+ *  variable, which defaults to zero. Because a default value is given,
+ *  none of the derived classes needs to take an initial value for the
+ *  time variable if not needed.
+ *
+ *  Once again the warning: do not use the #time# variable for any other
+ *  purpose than the intended one! This will inevitably lead to confusion.
+ *
+ *
+ *  @author Wolfgang Bangerth, Guido Kanschat, 1998, 1999
+ */
+class FunctionTime {
+  public:
+                                    /**
+                                     * Constructor. May take an initial vakue
+                                     * for the time variable, which defaults
+                                     * to zero.
+                                     */
+    FunctionTime (const double initial_time = 0.0);
+
+                                  /**
+                                   * Virtual destructor.
+                                   */
+  virtual ~FunctionTime();
+  
+                                    /**
+                                     * Return the value of the time variable/
+                                     */
+    double get_time () const;
+
+                                    /**
+                                     * Set the time to #new_time#, overwriting
+                                     * the old value.
+                                     */
+    virtual void set_time (const double new_time);
+
+                                    /**
+                                     * Advance the time by the given
+                                     * time step #delta_t#.
+                                     */
+    virtual void advance_time (const double delta_t);
+
+private:
+                                    /**
+                                     * Store the present time.
+                                     */
+    double time;
+};
+
+inline double
+FunctionTime::get_time () const
+{
+  return time;
+};
+
+/*---------------------------- functiontime.h ---------------------------*/
+/* end of #ifndef __functiontime_H */
+#endif
+/*---------------------------- functiontime.h ---------------------------*/
index fa679b2cc136e89b336f0c6007dc47a4a2d7b828..3806731eb504294cd3a01c776d2b71d23f2d6ae9 100644 (file)
  * functionality is recursively handed down to tensors of rank 1 or
  * put into external templated functions, e.g. the #contract# family.
  *
- * Using this tensor class for objects of rank to has advantages over
+ * Using this tensor class for objects of rank 2 has advantages over
  * matrices in many cases since the dimension is known to the compiler
  * as well as the location of the data. It is therefore possible to
  * produce far more efficient code than for matrices with
- * runtime-dependant dimension.
+ * runtime-dependent dimension.
  */
 template <int rank_, int dim>
 class Tensor {
@@ -106,7 +106,7 @@ class Tensor {
     Tensor<rank_,dim> & operator -= (const Tensor<rank_,dim> &);
 
                                     /**
-                                     *  Scale the vector by #factor#, i.e. multiply
+                                     *  Scale the tensor by #factor#, i.e. multiply
                                      *  all coordinates by #factor#.
                                      */
     Tensor<rank_,dim> & operator *= (const double &factor);
index 3b7a77494be7080c8d1fc1c97e4f326e67897a11..d2905c2a5b5504dbef3af5d53569bb15be0075fe 100644 (file)
@@ -7,12 +7,14 @@
 
 template <int dim>
 Function<dim>::Function (const double initial_time) :
-               time(initial_time) {};
+               FunctionTime(initial_time)
+{};
 
 
 
 template <int dim>
-Function<dim>::~Function () {};
+Function<dim>::~Function ()
+{};
 
 
 
@@ -57,27 +59,6 @@ void Function<dim>::gradient_list (const vector<Point<dim> > &points,
 
 
 
-template <int dim>
-double Function<dim>::get_time () const {
-  return time;
-};
-
-
-
-template <int dim>
-void Function<dim>::set_time (const double new_time) {
-  time = new_time;
-};
-
-
-
-template <int dim>
-void Function<dim>::advance_time (const double delta_t) {
-  set_time (time+delta_t);
-};
-
-
-
 
 
 template <int dim>
diff --git a/deal.II/base/source/function_time.cc b/deal.II/base/source/function_time.cc
new file mode 100644 (file)
index 0000000..0fa1f82
--- /dev/null
@@ -0,0 +1,27 @@
+// $Id$
+
+#include <base/functiontime.h>
+
+
+FunctionTime::FunctionTime(double initial_time)
+               :
+               time(initial_time)
+{}
+
+FunctionTime::~FunctionTime()
+{}
+
+void
+FunctionTime::set_time (const double new_time)
+{
+  time = new_time;
+};
+
+void
+FunctionTime::advance_time (const double delta_t)
+{
+  set_time (time+delta_t);
+};
+
+
+

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.