Object-oriented Scientific Computing Library: Version 0.910
ode_jac_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_JAC_FUNCT_H
00024 #define O2SCL_ODE_JAC_FUNCT_H
00025 
00026 #include <string>
00027 #include <o2scl/ovector_tlate.h>
00028 #include <o2scl/omatrix_tlate.h>
00029 
00030 #ifndef DOXYGENP
00031 namespace o2scl {
00032 #endif
00033 
00034   /** \brief Ordinary differential equation Jacobian [abstract base]
00035       
00036       This base class provides the basic format for specifying the
00037       Jacobian for ordinary differential equations to integrate with
00038       the \o2 ODE solvers. Select the appropriate child of this class
00039       according to the kind of functions which are to be given to the
00040       solver.
00041   */
00042   template <class vec_t=ovector_base, 
00043     class mat_t=omatrix_base> class ode_jac_funct {
00044 
00045     public:
00046 
00047     ode_jac_funct() {}
00048 
00049     virtual ~ode_jac_funct() {}
00050 
00051     /** \brief Compute the derivatives \c dfdx and the Jacobian matrix
00052         \c dfdy given \c y at the point \c x.
00053     */
00054     virtual int operator()(double x, size_t nv, const vec_t &y, 
00055                            mat_t &dfdy, vec_t &dfdx)=0;
00056   
00057 #ifndef DOXYGEN_INTERNAL
00058 
00059     private:
00060 
00061     ode_jac_funct(const ode_jac_funct &);
00062     ode_jac_funct& operator=(const ode_jac_funct&);
00063 
00064 #endif
00065 
00066   };
00067 
00068   /** \brief Provide ODE Jacobian in the form of function pointers
00069   */
00070 #ifdef DOXYGENP
00071   template <class vec_t=ovector_base, class mat_t=omatrix_base>
00072     class ode_jac_funct_fptr : public ode_jac_funct
00073 #else
00074   template <class vec_t=ovector_base, class mat_t=omatrix_base>
00075     class ode_jac_funct_fptr : public ode_jac_funct<vec_t> 
00076 #endif
00077     {
00078 
00079     public:
00080     
00081     /** \brief Create an object given a function pointer
00082      */
00083     ode_jac_funct_fptr(int (*fp)(double, size_t, const vec_t &, 
00084                                  mat_t &, vec_t &)) {
00085       fptr=fp;
00086     }
00087     
00088     virtual ~ode_jac_funct_fptr() {}
00089     
00090     /** \brief Compute the derivatives \c dfdx and the Jacobian matrix
00091         \c dfdy given \c y at the point \c x.
00092     */
00093     virtual int operator()(double x, size_t nv, const vec_t &y, 
00094                            mat_t &dfdy, vec_t &dfdx) {
00095       return fptr(x,nv,y,dfdy,dfdx);
00096     }
00097     
00098 #ifndef DOXYGEN_INTERNAL
00099     
00100     protected:
00101 
00102     ode_jac_funct_fptr() {};
00103 
00104     /// The function pointer
00105     int (*fptr)(double x, size_t nv, const vec_t &y, 
00106                 mat_t &dfdy, vec_t &dfdx);
00107 
00108     private:
00109 
00110     ode_jac_funct_fptr(const ode_jac_funct_fptr &);
00111     ode_jac_funct_fptr& operator=(const ode_jac_funct_fptr&);
00112 
00113 #endif
00114 
00115   };
00116 
00117   /** \brief Provide ODE Jacobian in the form of member 
00118       function pointers
00119   */
00120 #ifdef DOXYGENP
00121   template <class tclass, class vec_t=ovector_base, 
00122     class mat_t=omatrix_base> class ode_jac_funct_mfptr : 
00123   public ode_jac_funct
00124 #else
00125   template <class tclass, class vec_t=ovector_base, 
00126     class mat_t=omatrix_base> class ode_jac_funct_mfptr : 
00127   public ode_jac_funct<vec_t>
00128 #endif
00129  {
00130     
00131     public:
00132     
00133     /** \brief Create an object given a class and member function pointer
00134      */
00135     ode_jac_funct_mfptr
00136     (tclass *tp, int (tclass::*fp)(double x, size_t nv, const vec_t &y, 
00137                                    mat_t &dfdy, vec_t &dfdx)) {
00138       tptr=tp;
00139       fptr=fp;
00140     }
00141     
00142     virtual ~ode_jac_funct_mfptr() {};
00143     
00144     /** \brief Compute the derivatives \c dfdx and the Jacobian matrix
00145         \c dfdy given \c y at the point \c x.
00146     */
00147     virtual int operator()(double x, size_t nv, const vec_t &y, 
00148                            mat_t &dfdy, vec_t &dfdx) {
00149       return (*tptr.*fptr)(x,nv,y,dfdy,dfdx);
00150     }
00151   
00152 #ifndef DOXYGEN_INTERNAL
00153 
00154     protected:
00155 
00156     /// The pointer to the member function
00157     int (tclass::*fptr)(double x, size_t nv, const vec_t &y, 
00158                         mat_t &dfdy, vec_t &dfdx);
00159 
00160     /// The pointer to the class
00161     tclass *tptr;
00162 
00163     private:
00164 
00165     ode_jac_funct_mfptr(const ode_jac_funct_mfptr &);
00166     ode_jac_funct_mfptr& operator=(const ode_jac_funct_mfptr&);
00167 
00168 #endif
00169 
00170   };
00171 
00172   /** \brief Provide ODE Jacobian in the form of const member 
00173       function pointers
00174   */
00175 #ifdef DOXYGENP
00176   template <class tclass, class vec_t=ovector_base, 
00177     class mat_t=omatrix_base> class ode_jac_funct_cmfptr : 
00178   public ode_jac_funct
00179 #else
00180   template <class tclass, class vec_t=ovector_base, 
00181     class mat_t=omatrix_base> class ode_jac_funct_cmfptr : 
00182   public ode_jac_funct<vec_t>
00183 #endif
00184  {
00185 
00186     public:
00187     
00188     /** \brief Create an object given a class and member function pointer
00189      */
00190     ode_jac_funct_cmfptr
00191     (tclass *tp, int (tclass::*fp)(double x, size_t nv, const vec_t &y, 
00192                                    mat_t &dfdy, vec_t &dfdx) const) {
00193       tptr=tp;
00194       fptr=fp;
00195     }
00196   
00197     virtual ~ode_jac_funct_cmfptr() {};
00198   
00199     /** \brief Compute the derivatives \c dfdx and the Jacobian matrix
00200         \c dfdy given \c y at the point \c x.
00201     */
00202     virtual int operator()(double x, size_t nv, const vec_t &y, 
00203                            mat_t &dfdy, vec_t &dfdx) {
00204       return (*tptr.*fptr)(x,nv,y,dfdy,dfdx);
00205     }
00206   
00207 #ifndef DOXYGEN_INTERNAL
00208 
00209     protected:
00210 
00211     /// The pointer to the member function
00212     int (tclass::*fptr)(double x, size_t nv, const vec_t &y, 
00213                         mat_t &dfdy, vec_t &dfdx) const;
00214 
00215     /// The pointer to the class
00216     tclass *tptr;
00217 
00218     private:
00219 
00220     ode_jac_funct_cmfptr(const ode_jac_funct_cmfptr &);
00221     ode_jac_funct_cmfptr& operator=(const ode_jac_funct_cmfptr&);
00222 
00223 #endif
00224 
00225   };
00226 
00227 #ifndef DOXYGENP
00228 }
00229 #endif
00230 
00231 #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.