ode_funct.h

00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006, 2007, Andrew W. Steiner
00005   
00006   This file is part of O2scl.
00007   
00008   O2scl is free software; you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation; either version 3 of the License, or
00011   (at your option) any later version.
00012   
00013   O2scl is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017   
00018   You should have received a copy of the GNU General Public License
00019   along with O2scl. If not, see <http://www.gnu.org/licenses/>.
00020 
00021   -------------------------------------------------------------------
00022 */
00023 #ifndef O2SCL_ODE_FUNCT_H
00024 #define O2SCL_ODE_FUNCT_H
00025 #include <string>
00026 #include <o2scl/collection.h>
00027 
00028 #ifndef DOXYGENP
00029 namespace o2scl {
00030 #endif
00031 
00032   /** 
00033       \brief Ordinary differential equation function base
00034 
00035   */
00036   template <class param_t, class vec_t=ovector_view>
00037     class ode_funct {
00038     public:
00039 
00040     ode_funct() {}
00041 
00042     virtual ~ode_funct() {}
00043 
00044     /** \brief The overloaded operator()
00045      */
00046     virtual int operator()(double x, size_t nv, const vec_t &y, 
00047                            vec_t &dydx, param_t &pa) {
00048       set_err_ret("Empty ode_funct::operator().",gsl_nobase);
00049     }
00050   
00051 #ifndef DOXYGEN_INTERNAL
00052     private:
00053     ode_funct(const ode_funct &);
00054     ode_funct& operator=(const ode_funct&);
00055 #endif
00056   };
00057 
00058   /** 
00059       \brief Function pointer to a function
00060   */
00061   template <class param_t, class vec_t=ovector_view>
00062     class ode_funct_fptr : public ode_funct<param_t,vec_t> {
00063     public:
00064 
00065     /** \brief Specify the function pointer
00066      */
00067     ode_funct_fptr(int (*fp)(double, size_t, const vec_t &, 
00068                              vec_t &, param_t &)) {
00069       fptr=fp;
00070     }
00071 
00072     virtual ~ode_funct_fptr() {}
00073 
00074     virtual int operator()(double x, size_t nv, const vec_t &y, 
00075                            vec_t &dydx, param_t &pa) 
00076     {
00077       return fptr(x,nv,y,dydx,pa);
00078     }
00079 
00080 #ifndef DOXYGEN_INTERNAL
00081 
00082     protected:
00083 
00084     ode_funct_fptr() {};
00085 
00086     /// The function pointer
00087     int (*fptr)(double x, size_t nv, const vec_t &y, 
00088                 vec_t &dydx, param_t &);
00089 
00090     private:
00091 
00092     ode_funct_fptr(const ode_funct_fptr &);
00093     ode_funct_fptr& operator=(const ode_funct_fptr&);
00094 
00095 #endif
00096 
00097   };
00098 
00099   /** 
00100       \brief Member function pointer to a one-dimensional function
00101   */
00102   template <class tclass, class param_t, class vec_t=ovector_view> 
00103     class ode_funct_mfptr : public ode_funct<param_t,vec_t> {
00104     public:
00105     
00106     /** \brief Specify the member function pointer
00107      */
00108     ode_funct_mfptr
00109       (tclass *tp, int (tclass::*fp)(double x, size_t nv, 
00110                                      const vec_t &y, 
00111                                      vec_t &dydx, param_t &)) {
00112       tptr=tp;
00113       fptr=fp;
00114     }
00115   
00116     virtual ~ode_funct_mfptr() {};
00117   
00118     virtual int operator()(double x, size_t nv, const vec_t &y, 
00119                            vec_t &dydx, param_t &pa) {
00120       return (*tptr.*fptr)(x,nv,y,dydx,pa);
00121     }
00122   
00123 #ifndef DOXYGEN_INTERNAL
00124 
00125     protected:
00126 
00127     /// The pointer to the member function
00128     int (tclass::*fptr)(double x, size_t nv, const vec_t &y, 
00129                         vec_t &dydx, param_t &);
00130 
00131     /// The pointer to the class
00132     tclass *tptr;
00133 
00134     private:
00135 
00136     ode_funct_mfptr(const ode_funct_mfptr &);
00137     ode_funct_mfptr& operator=(const ode_funct_mfptr&);
00138 
00139 #endif
00140 
00141   };
00142 
00143   // ---------------------------------------------------------------------
00144 
00145   /** 
00146       \brief Ordinary differential equation function base
00147       
00148   */
00149   template <class param_t, size_t nv>
00150     class ode_vfunct {
00151     public:
00152 
00153     ode_vfunct() {}
00154 
00155     virtual ~ode_vfunct() {}
00156 
00157     /** \brief The overloaded operator()
00158      */
00159     virtual int operator()(double x, size_t nvar, const double y[nv], 
00160                            double dydx[nv], param_t &pa) {
00161       set_err_ret("Empty ode_vfunct::operator().",gsl_nobase);
00162     }
00163   
00164 #ifndef DOXYGEN_INTERNAL
00165     private:
00166     ode_vfunct(const ode_vfunct &);
00167     ode_vfunct& operator=(const ode_vfunct&);
00168 #endif
00169   };
00170 
00171   /** 
00172       \brief Function pointer to a function
00173   */
00174   template <class param_t, size_t nv>
00175     class ode_vfunct_fptr : public ode_vfunct<param_t,nv> {
00176     public:
00177     
00178     /** \brief Specify the function pointer
00179      */
00180     ode_vfunct_fptr(int (*fp)(double, size_t, const double y[nv], 
00181                               double dydx[nv], param_t &)) {
00182       fptr=fp;
00183     }
00184 
00185     virtual ~ode_vfunct_fptr() {}
00186 
00187     virtual int operator()(double x, size_t nvar, const double y[nv], 
00188                            double dydx[nv], param_t &pa) 
00189     {
00190       return fptr(x,nv,y,dydx,pa);
00191     }
00192 
00193 #ifndef DOXYGEN_INTERNAL
00194 
00195     protected:
00196 
00197     ode_vfunct_fptr() {};
00198 
00199     /// The function pointer
00200     int (*fptr)(double x, size_t nvar, const double y[nv], 
00201                 double dydx[nv], param_t &);
00202 
00203     private:
00204 
00205     ode_vfunct_fptr(const ode_vfunct_fptr &);
00206     ode_vfunct_fptr& operator=(const ode_vfunct_fptr&);
00207 
00208 #endif
00209 
00210   };
00211 
00212   /** 
00213       \brief Member function pointer to a one-dimensional function
00214   */
00215   template <class tclass, class param_t, size_t nv> 
00216     class ode_vfunct_mfptr : public ode_vfunct<param_t,nv> {
00217     public:
00218     
00219     /** \brief Specify the member function pointer
00220      */
00221     ode_vfunct_mfptr
00222       (tclass *tp, int (tclass::*fp)(double x, size_t nvar, 
00223                                      const double y[nv], 
00224                                      double dydx[nv], param_t &)) {
00225       tptr=tp;
00226       fptr=fp;
00227     }
00228   
00229     virtual ~ode_vfunct_mfptr() {};
00230   
00231     virtual int operator()(double x, size_t nvar, const double y[nv], 
00232                            double dydx[nv], param_t &pa) {
00233       return (*tptr.*fptr)(x,nv,y,dydx,pa);
00234     }
00235   
00236 #ifndef DOXYGEN_INTERNAL
00237 
00238     protected:
00239   
00240     /// Pointer to the member function
00241     int (tclass::*fptr)(double x, size_t nvar, const double y[nv], 
00242                         double dydx[nv], param_t &);
00243 
00244     /// Pointer to the class
00245     tclass *tptr;
00246 
00247     private:
00248 
00249     ode_vfunct_mfptr(const ode_vfunct_mfptr &);
00250     ode_vfunct_mfptr& operator=(const ode_vfunct_mfptr&);
00251 
00252 #endif
00253 
00254   };
00255 
00256 #ifndef DOXYGENP
00257 }
00258 #endif
00259 
00260 #endif

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.