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 This base class provides the basic format for specifying 00036 ordinary differential equations to integrate with the O2scl 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 param_t, class vec_t=ovector_view> 00041 class ode_funct { 00042 public: 00043 00044 ode_funct() {} 00045 00046 virtual ~ode_funct() {} 00047 00048 /** \brief The overloaded operator() 00049 */ 00050 virtual int operator()(double x, size_t nv, const vec_t &y, 00051 vec_t &dydx, param_t &pa) { 00052 set_err_ret("Empty ode_funct::operator().",gsl_nobase); 00053 } 00054 00055 #ifndef DOXYGEN_INTERNAL 00056 private: 00057 ode_funct(const ode_funct &); 00058 ode_funct& operator=(const ode_funct&); 00059 #endif 00060 }; 00061 00062 /** 00063 \brief Provide ODE functions in the form of function pointers 00064 */ 00065 template <class param_t, class vec_t=ovector_view> 00066 class ode_funct_fptr : public ode_funct<param_t,vec_t> { 00067 public: 00068 00069 /** \brief Create an object given a function pointer 00070 */ 00071 ode_funct_fptr(int (*fp)(double, size_t, const vec_t &, 00072 vec_t &, param_t &)) { 00073 fptr=fp; 00074 } 00075 00076 virtual ~ode_funct_fptr() {} 00077 00078 /** \brief Compute the \c nv derivatives as a function of the \c nv 00079 functions specified in \c y at the point \c x. 00080 */ 00081 virtual int operator()(double x, size_t nv, const vec_t &y, 00082 vec_t &dydx, param_t &pa) 00083 { 00084 return fptr(x,nv,y,dydx,pa); 00085 } 00086 00087 #ifndef DOXYGEN_INTERNAL 00088 00089 protected: 00090 00091 ode_funct_fptr() {}; 00092 00093 /// The function pointer 00094 int (*fptr)(double x, size_t nv, const vec_t &y, 00095 vec_t &dydx, param_t &); 00096 00097 private: 00098 00099 ode_funct_fptr(const ode_funct_fptr &); 00100 ode_funct_fptr& operator=(const ode_funct_fptr&); 00101 00102 #endif 00103 00104 }; 00105 00106 /** 00107 \brief Provide ODE functions in the form of member 00108 function pointers 00109 */ 00110 template <class tclass, class param_t, class vec_t=ovector_view> 00111 class ode_funct_mfptr : public ode_funct<param_t,vec_t> { 00112 00113 public: 00114 00115 /** \brief Create an object given a class and member function pointer 00116 */ 00117 ode_funct_mfptr 00118 (tclass *tp, int (tclass::*fp)(double x, size_t nv, 00119 const vec_t &y, 00120 vec_t &dydx, param_t &)) { 00121 tptr=tp; 00122 fptr=fp; 00123 } 00124 00125 virtual ~ode_funct_mfptr() {}; 00126 00127 /** \brief Compute the \c nv derivatives as a function of the \c nv 00128 functions specified in \c y at the point \c x. 00129 */ 00130 virtual int operator()(double x, size_t nv, const vec_t &y, 00131 vec_t &dydx, param_t &pa) { 00132 return (*tptr.*fptr)(x,nv,y,dydx,pa); 00133 } 00134 00135 #ifndef DOXYGEN_INTERNAL 00136 00137 protected: 00138 00139 /// The pointer to the member function 00140 int (tclass::*fptr)(double x, size_t nv, const vec_t &y, 00141 vec_t &dydx, param_t &); 00142 00143 /// The pointer to the class 00144 tclass *tptr; 00145 00146 private: 00147 00148 ode_funct_mfptr(const ode_funct_mfptr &); 00149 ode_funct_mfptr& operator=(const ode_funct_mfptr&); 00150 00151 #endif 00152 00153 }; 00154 00155 // --------------------------------------------------------------------- 00156 00157 /** 00158 \brief Ordinary differential equation function base for arrays 00159 00160 This base class provides the basic format for specifying 00161 ordinary differential equations to integrate with the O2scl ODE 00162 solvers. Select the appropriate child of this class according 00163 to the kind of functions which are to be given to the solver. 00164 */ 00165 template <class param_t, size_t nv> class ode_vfunct { 00166 00167 public: 00168 00169 ode_vfunct() {} 00170 00171 virtual ~ode_vfunct() {} 00172 00173 /** \brief Compute the \c nv derivatives as a function of the \c nv 00174 functions specified in \c y at the point \c x. 00175 */ 00176 virtual int operator()(double x, size_t nvar, const double y[nv], 00177 double dydx[nv], param_t &pa) { 00178 set_err_ret("Empty ode_vfunct::operator().",gsl_nobase); 00179 } 00180 00181 #ifndef DOXYGEN_INTERNAL 00182 private: 00183 ode_vfunct(const ode_vfunct &); 00184 ode_vfunct& operator=(const ode_vfunct&); 00185 #endif 00186 }; 00187 00188 /** 00189 \brief Function pointer to a function 00190 */ 00191 template <class param_t, size_t nv> 00192 class ode_vfunct_fptr : public ode_vfunct<param_t,nv> { 00193 public: 00194 00195 /** \brief Specify the function pointer 00196 */ 00197 ode_vfunct_fptr(int (*fp)(double, size_t, const double y[nv], 00198 double dydx[nv], param_t &)) { 00199 fptr=fp; 00200 } 00201 00202 virtual ~ode_vfunct_fptr() {} 00203 00204 /** \brief The overloaded operator() 00205 */ 00206 virtual int operator()(double x, size_t nvar, const double y[nv], 00207 double dydx[nv], param_t &pa) 00208 { 00209 return fptr(x,nv,y,dydx,pa); 00210 } 00211 00212 #ifndef DOXYGEN_INTERNAL 00213 00214 protected: 00215 00216 ode_vfunct_fptr() {}; 00217 00218 /// The function pointer 00219 int (*fptr)(double x, size_t nvar, const double y[nv], 00220 double dydx[nv], param_t &); 00221 00222 private: 00223 00224 ode_vfunct_fptr(const ode_vfunct_fptr &); 00225 ode_vfunct_fptr& operator=(const ode_vfunct_fptr&); 00226 00227 #endif 00228 00229 }; 00230 00231 /** 00232 \brief Provide ODE functions in the form of member 00233 function pointers 00234 */ 00235 template <class tclass, class param_t, size_t nv> 00236 class ode_vfunct_mfptr : public ode_vfunct<param_t,nv> { 00237 public: 00238 00239 /** \brief Specify the member function pointer 00240 */ 00241 ode_vfunct_mfptr 00242 (tclass *tp, int (tclass::*fp)(double x, size_t nvar, 00243 const double y[nv], 00244 double dydx[nv], param_t &)) { 00245 tptr=tp; 00246 fptr=fp; 00247 } 00248 00249 virtual ~ode_vfunct_mfptr() {}; 00250 00251 /** \brief The overloaded operator() 00252 */ 00253 virtual int operator()(double x, size_t nvar, const double y[nv], 00254 double dydx[nv], param_t &pa) { 00255 return (*tptr.*fptr)(x,nv,y,dydx,pa); 00256 } 00257 00258 #ifndef DOXYGEN_INTERNAL 00259 00260 protected: 00261 00262 /// Pointer to the member function 00263 int (tclass::*fptr)(double x, size_t nvar, const double y[nv], 00264 double dydx[nv], param_t &); 00265 00266 /// Pointer to the class 00267 tclass *tptr; 00268 00269 private: 00270 00271 ode_vfunct_mfptr(const ode_vfunct_mfptr &); 00272 ode_vfunct_mfptr& operator=(const ode_vfunct_mfptr&); 00273 00274 #endif 00275 00276 }; 00277 00278 #ifndef DOXYGENP 00279 } 00280 #endif 00281 00282 #endif
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page