MathTL
numerics/quadrature.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_QUADRATURE_H
00011 #define _MATHTL_QUADRATURE_H
00012 
00013 #include <utils/array1d.h>
00014 #include <utils/function.h>
00015 #include <geometry/point.h>
00016 
00017 namespace MathTL
00018 {
00030   template <unsigned int DIM>
00031   class QuadratureRule
00032   {
00033   public:
00037     typedef QuadratureRule<DIM-1> SubQuadratureRule;
00038 
00042     QuadratureRule();
00043 
00047     QuadratureRule(const QuadratureRule<DIM>& Q);
00048 
00053     QuadratureRule(const SubQuadratureRule& Q,
00054                    const QuadratureRule<1>& Q1);
00055     
00059     virtual ~QuadratureRule();
00060 
00064     unsigned int get_N() const;
00065 
00069     void get_points(Array1D<Point<DIM> >& points) const;
00070 
00074     void get_weights(Array1D<double>& weights) const;
00075 
00080     double integrate(const Function<DIM, double>& f) const;
00081 
00087     double integrate(const Function<DIM, double>& f,
00088                      const Point<DIM>& a, const Point<DIM>& b) const;
00089 
00090   protected:
00094     Array1D<Point<DIM> > points_;
00095 
00099     Array1D<double> weights_;
00100   };
00101 
00105   class MidpointRule : public QuadratureRule<1>
00106   {
00107   public:
00111     MidpointRule();
00112   };
00113 
00117   class ClosedNewtonCotesRule : public QuadratureRule<1>
00118   {
00119   public:
00123     ClosedNewtonCotesRule(const unsigned int N);
00124   };
00125 
00130   class TrapezoidalRule: public QuadratureRule<1>
00131   {
00132   public:
00136     TrapezoidalRule();
00137   };
00138 
00143   class SimpsonRule: public QuadratureRule<1>
00144   {
00145   public:
00149     SimpsonRule();
00150   };
00151 
00155   template <unsigned int DIM>
00156   class CompositeRule
00157     : public QuadratureRule<DIM>
00158   {
00159   public:
00164     CompositeRule(const QuadratureRule<1>& Q,
00165                   const unsigned int N = 1);
00166     
00167   protected:
00171     const QuadratureRule<1> Q_;
00172 
00176     unsigned int N_;
00177 
00178   private:
00184     static bool uses_both_endpoints(const QuadratureRule<1>& Q);
00185   };
00186 }
00187 
00188 
00189 // include implementation of inline functions and specializations
00190 #include <numerics/quadrature.cpp>
00191 
00192 #endif
 All Classes Functions Variables Typedefs Enumerations