00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 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 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 For functions with C-style arrays, use 00041 the corresponding children of \ref ode_vfunct . 00042 */ 00043 template <class param_t, class vec_t=ovector_view> 00044 class ode_funct { 00045 public: 00046 00047 ode_funct() {} 00048 00049 virtual ~ode_funct() {} 00050 00051 /** \brief The overloaded operator() 00052 */ 00053 virtual int operator()(double x, size_t nv, const vec_t &y, 00054 vec_t &dydx, param_t &pa)=0; 00055 00056 #ifndef DOXYGEN_INTERNAL 00057 private: 00058 ode_funct(const ode_funct &); 00059 ode_funct& operator=(const ode_funct&); 00060 #endif 00061 }; 00062 00063 /** 00064 \brief Provide ODE functions in the form of function pointers 00065 */ 00066 template <class param_t, class vec_t=ovector_view> 00067 class ode_funct_fptr : public ode_funct<param_t,vec_t> { 00068 public: 00069 00070 /** \brief Create an object given a function pointer 00071 */ 00072 ode_funct_fptr(int (*fp)(double, size_t, const vec_t &, 00073 vec_t &, param_t &)) { 00074 fptr=fp; 00075 } 00076 00077 virtual ~ode_funct_fptr() {} 00078 00079 /** \brief Compute the \c nv derivatives as a function of the \c nv 00080 functions specified in \c y at the point \c x. 00081 */ 00082 virtual int operator()(double x, size_t nv, const vec_t &y, 00083 vec_t &dydx, param_t &pa) 00084 { 00085 return fptr(x,nv,y,dydx,pa); 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, param_t &); 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 /** 00108 \brief Provide ODE functions in the form of member 00109 function pointers 00110 */ 00111 template <class tclass, class param_t, class vec_t=ovector_view> 00112 class ode_funct_mfptr : public ode_funct<param_t,vec_t> { 00113 00114 public: 00115 00116 /** \brief Create an object given a class and member function pointer 00117 */ 00118 ode_funct_mfptr 00119 (tclass *tp, int (tclass::*fp)(double x, size_t nv, 00120 const vec_t &y, 00121 vec_t &dydx, param_t &)) { 00122 tptr=tp; 00123 fptr=fp; 00124 } 00125 00126 virtual ~ode_funct_mfptr() {}; 00127 00128 /** \brief Compute the \c nv derivatives as a function of the \c nv 00129 functions specified in \c y at the point \c x. 00130 */ 00131 virtual int operator()(double x, size_t nv, const vec_t &y, 00132 vec_t &dydx, param_t &pa) { 00133 return (*tptr.*fptr)(x,nv,y,dydx,pa); 00134 } 00135 00136 #ifndef DOXYGEN_INTERNAL 00137 00138 protected: 00139 00140 /// The pointer to the member function 00141 int (tclass::*fptr)(double x, size_t nv, const vec_t &y, 00142 vec_t &dydx, param_t &); 00143 00144 /// The pointer to the class 00145 tclass *tptr; 00146 00147 private: 00148 00149 ode_funct_mfptr(const ode_funct_mfptr &); 00150 ode_funct_mfptr& operator=(const ode_funct_mfptr&); 00151 00152 #endif 00153 00154 }; 00155 00156 // --------------------------------------------------------------------- 00157 00158 /** 00159 \brief Ordinary differential equation function with arrays 00160 [abstract base] 00161 00162 This base class provides the basic format for specifying 00163 ordinary differential equations to integrate with the O2scl ODE 00164 solvers. Select the appropriate child of this class according 00165 to the kind of functions which are to be given to the solver. 00166 */ 00167 template <class param_t, size_t nv> class ode_vfunct { 00168 00169 public: 00170 00171 ode_vfunct() {} 00172 00173 virtual ~ode_vfunct() {} 00174 00175 /** \brief Compute the \c nv derivatives as a function of the \c nv 00176 functions specified in \c y at the point \c x. 00177 */ 00178 virtual int operator()(double x, size_t nvar, const double y[nv], 00179 double dydx[nv], param_t &pa)=0; 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