Object-oriented Scientific Computing Library: Version 0.910
ode_funct.h
00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006-2012, 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 
00026 #include <string>
00027 #include <o2scl/ovector_tlate.h>
00028 
00029 #ifndef DOXYGENP
00030 namespace o2scl {
00031 #endif
00032 
00033   /** \brief Ordinary differential equation function [abstract base]
00034 
00035       This base class provides the basic format for specifying
00036       ordinary differential equations to integrate with the \o2 ODE
00037       solvers. Select the appropriate child of this class according
00038       to the kind of functions which are to be given to the solver.
00039   */
00040   template <class vec_t=ovector_base> class ode_funct {
00041 
00042   public:
00043 
00044   ode_funct() {}
00045 
00046   virtual ~ode_funct() {}
00047 
00048   /** \brief Compute the \c nv derivatives as a function of the \c nv 
00049       functions specified in \c y at the point \c x.
00050   */
00051   virtual int operator()(double x, size_t nv, const vec_t &y, 
00052                          vec_t &dydx)=0;
00053   
00054 #ifndef DOXYGEN_INTERNAL
00055 
00056   private:
00057 
00058   ode_funct(const ode_funct &);
00059   ode_funct& operator=(const ode_funct&);
00060 
00061 #endif
00062 
00063   };
00064 
00065   /** \brief Provide ODE functions in the form of function pointers
00066   */
00067   template <class vec_t=ovector_base>
00068     class ode_funct_fptr : public ode_funct<vec_t> {
00069   public:
00070 
00071   /** \brief Create an object given a function pointer
00072    */
00073   ode_funct_fptr(int (*fp)(double, size_t, const vec_t &, 
00074                            vec_t &)) {
00075     fptr=fp;
00076   }
00077 
00078   virtual ~ode_funct_fptr() {}
00079 
00080   /** \brief Compute the \c nv derivatives as a function of the \c nv 
00081       functions specified in \c y at the point \c x.
00082   */
00083   virtual int operator()(double x, size_t nv, const vec_t &y, 
00084                          vec_t &dydx) {
00085     return fptr(x,nv,y,dydx);
00086   }
00087   
00088 #ifndef DOXYGEN_INTERNAL
00089 
00090   protected:
00091 
00092   ode_funct_fptr() {};
00093   
00094   /// The function pointer
00095   int (*fptr)(double x, size_t nv, const vec_t &y, 
00096               vec_t &dydx);
00097   
00098   private:
00099   
00100   ode_funct_fptr(const ode_funct_fptr &);
00101   ode_funct_fptr& operator=(const ode_funct_fptr&);
00102 
00103 #endif
00104 
00105   };
00106 
00107   /** \brief Provide ODE functions in the form of function pointers
00108   */
00109   template <class param_t, class vec_t=ovector_base>
00110     class ode_funct_fptr_param : public ode_funct<vec_t> {
00111   public:
00112 
00113   /** \brief Create an object given a function pointer
00114    */
00115   ode_funct_fptr_param(int (*fp)(double, size_t, const vec_t &, 
00116                            vec_t &, param_t &), param_t &pa) {
00117     fptr=fp;
00118     pp=&pa;
00119   }
00120 
00121   virtual ~ode_funct_fptr_param() {}
00122 
00123   /** \brief Compute the \c nv derivatives as a function of the \c nv 
00124       functions specified in \c y at the point \c x.
00125   */
00126   virtual int operator()(double x, size_t nv, const vec_t &y, 
00127                          vec_t &dydx) {
00128     return fptr(x,nv,y,dydx,*pp);
00129   }
00130   
00131 #ifndef DOXYGEN_INTERNAL
00132 
00133   protected:
00134 
00135   ode_funct_fptr_param() {};
00136 
00137   /// The function pointer
00138   int (*fptr)(double x, size_t nv, const vec_t &y, 
00139               vec_t &dydx, param_t &);
00140 
00141   /// The parameter
00142   param_t *pp;
00143   
00144   private:
00145   
00146   ode_funct_fptr_param(const ode_funct_fptr_param &);
00147   ode_funct_fptr_param& operator=(const ode_funct_fptr_param&);
00148 
00149 #endif
00150 
00151   };
00152 
00153   /** \brief Provide ODE functions in the form of member 
00154       function pointers
00155   */
00156   template <class tclass, class vec_t=ovector_base> 
00157     class ode_funct_mfptr : public ode_funct<vec_t> {
00158 
00159   public:
00160     
00161   /** \brief Create an object given a class and member function pointer
00162    */
00163   ode_funct_mfptr
00164   (tclass *tp, int (tclass::*fp)(double x, size_t nv, 
00165                                  const vec_t &y, vec_t &dydx)) {
00166     tptr=tp;
00167     fptr=fp;
00168   }
00169   
00170   virtual ~ode_funct_mfptr() {};
00171   
00172   /** \brief Compute the \c nv derivatives as a function of the \c nv 
00173       functions specified in \c y at the point \c x.
00174   */
00175   virtual int operator()(double x, size_t nv, const vec_t &y, 
00176                          vec_t &dydx) {
00177     return (*tptr.*fptr)(x,nv,y,dydx);
00178   }
00179   
00180 #ifndef DOXYGEN_INTERNAL
00181 
00182   protected:
00183 
00184   /// The pointer to the member function
00185   int (tclass::*fptr)(double x, size_t nv, const vec_t &y, 
00186                       vec_t &dydx);
00187 
00188   /// The pointer to the class
00189   tclass *tptr;
00190 
00191   private:
00192 
00193   ode_funct_mfptr(const ode_funct_mfptr &);
00194   ode_funct_mfptr& operator=(const ode_funct_mfptr&);
00195 
00196 #endif
00197 
00198   };
00199 
00200   /** \brief Provide ODE functions in the form of member 
00201       function pointers
00202   */
00203   template <class tclass, class param_t, class vec_t=ovector_base> 
00204     class ode_funct_mfptr_param : public ode_funct<vec_t> {
00205 
00206   public:
00207     
00208   /** \brief Create an object given a class and member function pointer
00209    */
00210   ode_funct_mfptr_param
00211   (tclass *tp, 
00212    int (tclass::*fp)(double x, size_t nv, 
00213                      const vec_t &y, vec_t &dydx, param_t &), param_t &pa) {
00214     tptr=tp;
00215     fptr=fp;
00216     pp=&pa;
00217   }
00218   
00219   virtual ~ode_funct_mfptr_param() {};
00220   
00221   /** \brief Compute the \c nv derivatives as a function of the \c nv 
00222       functions specified in \c y at the point \c x.
00223   */
00224   virtual int operator()(double x, size_t nv, const vec_t &y, 
00225                          vec_t &dydx) {
00226     return (*tptr.*fptr)(x,nv,y,dydx,*pp);
00227   }
00228   
00229 #ifndef DOXYGEN_INTERNAL
00230 
00231   protected:
00232 
00233   /// The pointer to the member function
00234   int (tclass::*fptr)(double x, size_t nv, const vec_t &y, 
00235                       vec_t &dydx, param_t &);
00236 
00237   /// The pointer to the class
00238   tclass *tptr;
00239 
00240   /// The parameter
00241   param_t *pp;
00242 
00243   private:
00244 
00245   ode_funct_mfptr_param(const ode_funct_mfptr_param &);
00246   ode_funct_mfptr_param& operator=(const ode_funct_mfptr_param&);
00247 
00248 #endif
00249 
00250   };
00251 
00252   /** \brief Provide ODE functions in the form of const member 
00253       function pointers
00254   */
00255   template <class tclass, class vec_t=ovector_base> 
00256     class ode_funct_cmfptr : public ode_funct<vec_t> {
00257 
00258   public:
00259     
00260   /** \brief Create an object given a class and member function pointer
00261    */
00262   ode_funct_cmfptr
00263   (tclass *tp, int (tclass::*fp)(double x, size_t nv, 
00264                                  const vec_t &y, 
00265                                  vec_t &dydx) const) {
00266     tptr=tp;
00267     fptr=fp;
00268   }
00269   
00270   virtual ~ode_funct_cmfptr() {};
00271   
00272   /** \brief Compute the \c nv derivatives as a function of the \c nv 
00273       functions specified in \c y at the point \c x.
00274   */
00275   virtual int operator()(double x, size_t nv, const vec_t &y, 
00276                          vec_t &dydx) {
00277     return (*tptr.*fptr)(x,nv,y,dydx);
00278   }
00279   
00280 #ifndef DOXYGEN_INTERNAL
00281 
00282   protected:
00283 
00284   /// The pointer to the member function
00285   int (tclass::*fptr)(double x, size_t nv, const vec_t &y, 
00286                       vec_t &dydx) const;
00287 
00288   /// The pointer to the class
00289   tclass *tptr;
00290 
00291   private:
00292 
00293   ode_funct_cmfptr(const ode_funct_cmfptr &);
00294   ode_funct_cmfptr& operator=(const ode_funct_cmfptr&);
00295 
00296 #endif
00297 
00298   };
00299 
00300 #ifndef DOXYGENP
00301 }
00302 #endif
00303 
00304 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.