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