MathTL
utils/function.h
00001 // -*- c++ -*-
00002 
00003 // +--------------------------------------------------------------------+
00004 // | This file is part of MathTL - the Mathematical Template Library    |
00005 // |                                                                    |
00006 // | Copyright (c) 2002-2009                                            |
00007 // | Thorsten Raasch, Manuel Werner                                     |
00008 // +--------------------------------------------------------------------+
00009 
00010 #ifndef _MATHTL_FUNCTION_H
00011 #define _MATHTL_FUNCTION_H
00012 
00013 #include <algebra/vector.h>
00014 #include <utils/function_time.h>
00015 #include <geometry/point.h>
00016 
00017 namespace MathTL
00018 {
00019   template <unsigned int DIM, class VALUE> class Point;
00020   template <unsigned int RANK, unsigned int DIM, class VALUE> class Tensor;
00021   template <unsigned int DIM, class VALUE> class Tensor<1, DIM, VALUE>;
00022 
00029   template <unsigned int DIM, class VALUE = double>
00030   class Function : public FunctionTime
00031   {
00032   public:
00036     static const unsigned int dimension = DIM;
00037 
00041     typedef size_t size_type;
00042 
00046     const unsigned int n_components;
00047 
00053     Function(const unsigned int n_components = 1,
00054              const double initial_time = 0.0);
00055 
00059     virtual ~Function() = 0;
00060 
00064     virtual VALUE value (const Point<DIM,VALUE>& p,
00065                          const unsigned int component = 0) const = 0;
00066 
00071     virtual void vector_value(const Point<DIM,VALUE> &p,
00072                               Vector<VALUE>& values) const = 0;
00073 
00077     const size_type memory_consumption() const;
00078   };
00079 
00080 
00081   //
00082   //
00083   // some example functions
00084 
00088   template <unsigned int DIM, class VALUE = double>
00089   class ZeroFunction
00090     : public Function<DIM, VALUE>
00091   {
00092   public:
00093     ZeroFunction(const unsigned int n_components = 1);
00094     virtual ~ZeroFunction();
00095     VALUE value(const Point<DIM,VALUE>& p,
00096                 const unsigned int component = 0) const;
00097     void vector_value(const Point<DIM,VALUE> &p,
00098                       Vector<VALUE>& values) const;
00099   };
00100 
00104   template <unsigned int DIM, class VALUE = double>
00105   class ConstantFunction
00106     : public Function<DIM, VALUE>
00107   {
00108   public:
00109     ConstantFunction(const Vector<VALUE>& value);
00110     virtual ~ConstantFunction();
00111     VALUE value(const Point<DIM,VALUE>& p,
00112                 const unsigned int component = 0) const;
00113     void vector_value(const Point<DIM,VALUE> &p,
00114                       Vector<VALUE>& values) const;
00115   protected:
00117     Vector<VALUE> c;
00118   };
00119 
00123   template <unsigned int DIM, class VALUE = double>
00124   class ProductFunction
00125     : public Function<DIM, VALUE>
00126   {
00127   public:
00128     ProductFunction(const Function<DIM,VALUE>* f1,
00129                     const Function<DIM,VALUE>* f2);
00130     virtual ~ProductFunction();
00131     VALUE value(const Point<DIM,VALUE>& p,
00132                 const unsigned int component = 0) const;
00133     void vector_value(const Point<DIM,VALUE> &p,
00134                       Vector<VALUE>& values) const;
00135     
00136   protected:
00137     const Function<DIM,VALUE>* f1_;
00138     const Function<DIM,VALUE>* f2_;
00139   };
00140 }
00141 
00142 // implementations of inline functions
00143 #include "utils/function.cpp"
00144 
00145 #endif
 All Classes Functions Variables Typedefs Enumerations