00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 2009, 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 [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 For functions with C-style arrays, use the corresponding 00041 children of \ref ode_vfunct . 00042 */ 00043 template <class param_t, class vec_t=ovector_base> 00044 class ode_funct { 00045 00046 public: 00047 00048 ode_funct() {} 00049 00050 virtual ~ode_funct() {} 00051 00052 /** \brief Compute the \c nv derivatives as a function of the \c nv 00053 functions specified in \c y at the point \c x. 00054 */ 00055 virtual int operator()(double x, size_t nv, const vec_t &y, 00056 vec_t &dydx, param_t &pa)=0; 00057 00058 #ifndef DOXYGEN_INTERNAL 00059 00060 private: 00061 00062 ode_funct(const ode_funct &); 00063 ode_funct& operator=(const ode_funct&); 00064 00065 #endif 00066 00067 }; 00068 00069 /** 00070 \brief Provide ODE functions in the form of function pointers 00071 */ 00072 template <class param_t, class vec_t=ovector_base> 00073 class ode_funct_fptr : public ode_funct<param_t,vec_t> { 00074 public: 00075 00076 /** \brief Create an object given a function pointer 00077 */ 00078 ode_funct_fptr(int (*fp)(double, size_t, const vec_t &, 00079 vec_t &, param_t &)) { 00080 fptr=fp; 00081 } 00082 00083 virtual ~ode_funct_fptr() {} 00084 00085 /** \brief Compute the \c nv derivatives as a function of the \c nv 00086 functions specified in \c y at the point \c x. 00087 */ 00088 virtual int operator()(double x, size_t nv, const vec_t &y, 00089 vec_t &dydx, param_t &pa) 00090 { 00091 return fptr(x,nv,y,dydx,pa); 00092 } 00093 00094 #ifndef DOXYGEN_INTERNAL 00095 00096 protected: 00097 00098 ode_funct_fptr() {}; 00099 00100 /// The function pointer 00101 int (*fptr)(double x, size_t nv, const vec_t &y, 00102 vec_t &dydx, param_t &); 00103 00104 private: 00105 00106 ode_funct_fptr(const ode_funct_fptr &); 00107 ode_funct_fptr& operator=(const ode_funct_fptr&); 00108 00109 #endif 00110 00111 }; 00112 00113 /** 00114 \brief Provide ODE functions in the form of member 00115 function pointers 00116 */ 00117 template <class tclass, class param_t, class vec_t=ovector_base> 00118 class ode_funct_mfptr : public ode_funct<param_t,vec_t> { 00119 00120 public: 00121 00122 /** \brief Create an object given a class and member function pointer 00123 */ 00124 ode_funct_mfptr 00125 (tclass *tp, int (tclass::*fp)(double x, size_t nv, 00126 const vec_t &y, 00127 vec_t &dydx, param_t &)) { 00128 tptr=tp; 00129 fptr=fp; 00130 } 00131 00132 virtual ~ode_funct_mfptr() {}; 00133 00134 /** \brief Compute the \c nv derivatives as a function of the \c nv 00135 functions specified in \c y at the point \c x. 00136 */ 00137 virtual int operator()(double x, size_t nv, const vec_t &y, 00138 vec_t &dydx, param_t &pa) { 00139 return (*tptr.*fptr)(x,nv,y,dydx,pa); 00140 } 00141 00142 #ifndef DOXYGEN_INTERNAL 00143 00144 protected: 00145 00146 /// The pointer to the member function 00147 int (tclass::*fptr)(double x, size_t nv, const vec_t &y, 00148 vec_t &dydx, param_t &); 00149 00150 /// The pointer to the class 00151 tclass *tptr; 00152 00153 private: 00154 00155 ode_funct_mfptr(const ode_funct_mfptr &); 00156 ode_funct_mfptr& operator=(const ode_funct_mfptr&); 00157 00158 #endif 00159 00160 }; 00161 00162 /** 00163 \brief Provide ODE functions in the form of const member 00164 function pointers 00165 */ 00166 template <class tclass, class param_t, class vec_t=ovector_base> 00167 class ode_funct_cmfptr : public ode_funct<param_t,vec_t> { 00168 00169 public: 00170 00171 /** \brief Create an object given a class and member function pointer 00172 */ 00173 ode_funct_cmfptr 00174 (tclass *tp, int (tclass::*fp)(double x, size_t nv, 00175 const vec_t &y, 00176 vec_t &dydx, param_t &) const) { 00177 tptr=tp; 00178 fptr=fp; 00179 } 00180 00181 virtual ~ode_funct_cmfptr() {}; 00182 00183 /** \brief Compute the \c nv derivatives as a function of the \c nv 00184 functions specified in \c y at the point \c x. 00185 */ 00186 virtual int operator()(double x, size_t nv, const vec_t &y, 00187 vec_t &dydx, param_t &pa) { 00188 return (*tptr.*fptr)(x,nv,y,dydx,pa); 00189 } 00190 00191 #ifndef DOXYGEN_INTERNAL 00192 00193 protected: 00194 00195 /// The pointer to the member function 00196 int (tclass::*fptr)(double x, size_t nv, const vec_t &y, 00197 vec_t &dydx, param_t &) const; 00198 00199 /// The pointer to the class 00200 tclass *tptr; 00201 00202 private: 00203 00204 ode_funct_cmfptr(const ode_funct_cmfptr &); 00205 ode_funct_cmfptr& operator=(const ode_funct_cmfptr&); 00206 00207 #endif 00208 00209 }; 00210 00211 // --------------------------------------------------------------------- 00212 00213 /** 00214 \brief Ordinary differential equation function with arrays 00215 [abstract base] 00216 00217 This base class provides the basic format for specifying 00218 ordinary differential equations to integrate with the O2scl ODE 00219 solvers. Select the appropriate child of this class according 00220 to the kind of functions which are to be given to the solver. 00221 */ 00222 template <class param_t, size_t nv> class ode_vfunct { 00223 00224 public: 00225 00226 ode_vfunct() {} 00227 00228 virtual ~ode_vfunct() {} 00229 00230 /** \brief Compute the \c nv derivatives as a function of the \c nv 00231 functions specified in \c y at the point \c x. 00232 */ 00233 virtual int operator()(double x, size_t nvar, const double y[nv], 00234 double dydx[nv], param_t &pa)=0; 00235 00236 #ifndef DOXYGEN_INTERNAL 00237 00238 private: 00239 00240 ode_vfunct(const ode_vfunct &); 00241 ode_vfunct& operator=(const ode_vfunct&); 00242 00243 #endif 00244 }; 00245 00246 /** 00247 \brief Function pointer to a function 00248 */ 00249 template <class param_t, size_t nv> 00250 class ode_vfunct_fptr : public ode_vfunct<param_t,nv> { 00251 00252 public: 00253 00254 /** \brief Specify the function pointer 00255 */ 00256 ode_vfunct_fptr(int (*fp)(double, size_t, const double y[nv], 00257 double dydx[nv], param_t &)) { 00258 fptr=fp; 00259 } 00260 00261 virtual ~ode_vfunct_fptr() {} 00262 00263 /** \brief Compute the \c nv derivatives as a function of the \c nv 00264 functions specified in \c y at the point \c x. 00265 */ 00266 virtual int operator()(double x, size_t nvar, const double y[nv], 00267 double dydx[nv], param_t &pa) 00268 { 00269 return fptr(x,nv,y,dydx,pa); 00270 } 00271 00272 #ifndef DOXYGEN_INTERNAL 00273 00274 protected: 00275 00276 ode_vfunct_fptr() {}; 00277 00278 /// The function pointer 00279 int (*fptr)(double x, size_t nvar, const double y[nv], 00280 double dydx[nv], param_t &); 00281 00282 private: 00283 00284 ode_vfunct_fptr(const ode_vfunct_fptr &); 00285 ode_vfunct_fptr& operator=(const ode_vfunct_fptr&); 00286 00287 #endif 00288 00289 }; 00290 00291 /** 00292 \brief Provide ODE functions in the form of member 00293 function pointers 00294 */ 00295 template <class tclass, class param_t, size_t nv> 00296 class ode_vfunct_mfptr : public ode_vfunct<param_t,nv> { 00297 00298 public: 00299 00300 /** \brief Specify the member function pointer 00301 */ 00302 ode_vfunct_mfptr 00303 (tclass *tp, int (tclass::*fp)(double x, size_t nvar, 00304 const double y[nv], 00305 double dydx[nv], param_t &)) { 00306 tptr=tp; 00307 fptr=fp; 00308 } 00309 00310 virtual ~ode_vfunct_mfptr() {}; 00311 00312 /** \brief Compute the \c nv derivatives as a function of the \c nv 00313 functions specified in \c y at the point \c x. 00314 */ 00315 virtual int operator()(double x, size_t nvar, const double y[nv], 00316 double dydx[nv], param_t &pa) { 00317 return (*tptr.*fptr)(x,nv,y,dydx,pa); 00318 } 00319 00320 #ifndef DOXYGEN_INTERNAL 00321 00322 protected: 00323 00324 /// Pointer to the member function 00325 int (tclass::*fptr)(double x, size_t nvar, const double y[nv], 00326 double dydx[nv], param_t &); 00327 00328 /// Pointer to the class 00329 tclass *tptr; 00330 00331 private: 00332 00333 ode_vfunct_mfptr(const ode_vfunct_mfptr &); 00334 ode_vfunct_mfptr& operator=(const ode_vfunct_mfptr&); 00335 00336 #endif 00337 00338 }; 00339 00340 /** 00341 \brief Provide ODE functions in the form of const member 00342 function pointers 00343 */ 00344 template <class tclass, class param_t, size_t nv> 00345 class ode_vfunct_cmfptr : public ode_vfunct<param_t,nv> { 00346 00347 public: 00348 00349 /** \brief Specify the member function pointer 00350 */ 00351 ode_vfunct_cmfptr 00352 (tclass *tp, int (tclass::*fp)(double x, size_t nvar, 00353 const double y[nv], 00354 double dydx[nv], param_t &) const) { 00355 tptr=tp; 00356 fptr=fp; 00357 } 00358 00359 virtual ~ode_vfunct_cmfptr() {}; 00360 00361 /** \brief Compute the \c nv derivatives as a function of the \c nv 00362 functions specified in \c y at the point \c x. 00363 */ 00364 virtual int operator()(double x, size_t nvar, const double y[nv], 00365 double dydx[nv], param_t &pa) { 00366 return (*tptr.*fptr)(x,nv,y,dydx,pa); 00367 } 00368 00369 #ifndef DOXYGEN_INTERNAL 00370 00371 protected: 00372 00373 /// Pointer to the member function 00374 int (tclass::*fptr)(double x, size_t nvar, const double y[nv], 00375 double dydx[nv], param_t &) const; 00376 00377 /// Pointer to the class 00378 tclass *tptr; 00379 00380 private: 00381 00382 ode_vfunct_cmfptr(const ode_vfunct_cmfptr &); 00383 ode_vfunct_cmfptr& operator=(const ode_vfunct_cmfptr&); 00384 00385 #endif 00386 00387 }; 00388 00389 #ifndef DOXYGENP 00390 } 00391 #endif 00392 00393 #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