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_MM_FUNCT_H 00024 #define O2SCL_MM_FUNCT_H 00025 00026 #include <string> 00027 #include <o2scl/collection.h> 00028 #include <o2scl/ovector_tlate.h> 00029 00030 #ifndef DOXYGENP 00031 namespace o2scl { 00032 #endif 00033 00034 /** 00035 \brief Array of multi-dimensional functions [abstract base] 00036 00037 This class generalizes \c nv functions of \c nv variables, i.e. 00038 \f$ y_j(x_0,x_1,...,x_{nv-1}) \f$ for \f$ 0\leq j \leq 00039 nv-1 \f$ . 00040 00041 For functions with C-style arrays, use 00042 the corresponding children of \ref mm_vfunct . 00043 */ 00044 template<class param_t, class vec_t=ovector_view> 00045 class mm_funct { 00046 public: 00047 00048 mm_funct() {} 00049 00050 virtual ~mm_funct() {} 00051 00052 /** \brief Compute \c nv functions, \c y, of \c nv variables 00053 stored in \c x with parameter \c pa. 00054 */ 00055 virtual int operator()(size_t nv, const vec_t &x, vec_t &y, 00056 param_t &pa)=0; 00057 00058 #ifndef DOXYGENP 00059 00060 private: 00061 00062 mm_funct(const mm_funct &); 00063 mm_funct& operator=(const mm_funct&); 00064 00065 #endif 00066 00067 }; 00068 00069 /** \brief Function pointer to array of multi-dimensional functions 00070 */ 00071 template<class param_t, class vec_t=ovector_view> 00072 class mm_funct_fptr : public mm_funct<param_t,vec_t> { 00073 00074 public: 00075 00076 mm_funct_fptr() {} 00077 00078 virtual ~mm_funct_fptr() {} 00079 00080 /** \brief Specify the function pointer 00081 */ 00082 mm_funct_fptr(int (*fp)(size_t nv, const vec_t &x, vec_t &y, 00083 param_t &pa)) { 00084 fptr=fp; 00085 } 00086 00087 /** \brief Specify the function pointer 00088 */ 00089 int set_function(int (*fp)(size_t nv, const vec_t &x, vec_t &y, 00090 param_t &pa)) { 00091 fptr=fp; 00092 return 0; 00093 } 00094 00095 /** \brief Compute \c nv functions, \c y, of \c nv variables 00096 stored in \c x with parameter \c pa. 00097 */ 00098 virtual int operator()(size_t nv, const vec_t &x, vec_t &y, param_t &pa) { 00099 return fptr(nv,x,y,pa); 00100 } 00101 00102 00103 #ifndef DOXYGEN_INTERNAL 00104 00105 protected: 00106 00107 friend class io_tlate<mm_funct_fptr>; 00108 00109 /// The function pointer to the user-supplied function 00110 int (*fptr)(size_t nv, const vec_t &x, vec_t &y, param_t &pa); 00111 00112 private: 00113 00114 mm_funct_fptr(const mm_funct_fptr &); 00115 mm_funct_fptr& operator=(const mm_funct_fptr&); 00116 00117 #endif 00118 00119 }; 00120 00121 /** \brief Function pointer to array of multi-dimensional functions with 00122 no parameters 00123 */ 00124 template<class param_t, class vec_t=ovector_view> 00125 class mm_funct_fptr_nopar : public mm_funct<param_t,vec_t> { 00126 00127 public: 00128 00129 mm_funct_fptr_nopar() {} 00130 00131 virtual ~mm_funct_fptr_nopar() {} 00132 00133 /** \brief Specify the function pointer 00134 */ 00135 mm_funct_fptr_nopar(int (*fp)(size_t nv, const vec_t &x, vec_t &y)) { 00136 fptr=fp; 00137 } 00138 00139 /** \brief Specify the function pointer 00140 */ 00141 int set_function(int (*fp)(size_t nv, const vec_t &x, vec_t &y)) { 00142 fptr=fp; 00143 return 0; 00144 } 00145 00146 /** \brief Compute \c nv functions, \c y, of \c nv variables 00147 stored in \c x with parameter \c pa. 00148 */ 00149 virtual int operator()(size_t nv, const vec_t &x, vec_t &y, param_t &pa) { 00150 return fptr(nv,x,y); 00151 } 00152 00153 00154 #ifndef DOXYGEN_INTERNAL 00155 00156 protected: 00157 00158 friend class io_tlate<mm_funct_fptr_nopar>; 00159 00160 /// The function pointer to the user-supplied function 00161 int (*fptr)(size_t nv, const vec_t &x, vec_t &y); 00162 00163 private: 00164 00165 mm_funct_fptr_nopar(const mm_funct_fptr_nopar &); 00166 mm_funct_fptr_nopar& operator=(const mm_funct_fptr_nopar&); 00167 00168 #endif 00169 00170 }; 00171 00172 /** 00173 \brief Function pointer to a gsl_multiroot_function 00174 00175 This works because with the template parameter \c vec_t as an 00176 \ref ovector_view class because \ref ovector_view is inherited 00177 from \c gsl_vector. 00178 */ 00179 template<class param_t, class vec_t=ovector_view> 00180 class mm_funct_gsl : public mm_funct<param_t,vec_t> { 00181 public: 00182 00183 /** \brief Specify the function pointer 00184 */ 00185 mm_funct_gsl(int (*fp)(const gsl_vector *x, param_t &pa, gsl_vector *f)) { 00186 fptr=fp; 00187 } 00188 00189 /** \brief Compute \c nv functions, \c y, of \c nv variables 00190 stored in \c x with parameter \c pa. 00191 */ 00192 virtual int operator()(size_t nv, const vec_t &x, vec_t &y, param_t &pa) { 00193 const gsl_vector *gx=(const gsl_vector *)(&x); 00194 gsl_vector *gy=(gsl_vector *)(&y); 00195 return fptr(gx,pa,gy); 00196 } 00197 00198 #ifndef DOXYGEN_INTERNAL 00199 00200 protected: 00201 00202 friend class io_tlate<mm_funct_gsl>; 00203 00204 /// The function pointer to the user-supplied function 00205 int (*fptr)(const gsl_vector *x, param_t &pa, gsl_vector *f); 00206 00207 private: 00208 00209 mm_funct_gsl(const mm_funct_gsl &); 00210 mm_funct_gsl& operator=(const mm_funct_gsl&); 00211 00212 #endif 00213 00214 }; 00215 00216 /** \brief Member function pointer to an array of 00217 multi-dimensional functions 00218 */ 00219 template<class tclass, class param_t, class vec_t=ovector_view> 00220 class mm_funct_mfptr : public mm_funct<param_t,vec_t> { 00221 public: 00222 00223 /** \brief Empty constructor 00224 */ 00225 mm_funct_mfptr() { 00226 } 00227 00228 /** \brief Specify the member function pointer 00229 */ 00230 mm_funct_mfptr(tclass *tp, int (tclass::*fp) 00231 (size_t nv, const vec_t &x, vec_t &y, param_t &pa)) { 00232 tptr=tp; 00233 fptr=fp; 00234 } 00235 00236 /** \brief Specify the member function pointer 00237 */ 00238 int set_function(tclass *tp, int (tclass::*fp) 00239 (size_t nv, const vec_t &x, vec_t &y, param_t &pa)) 00240 { 00241 tptr=tp; 00242 fptr=fp; 00243 return 0; 00244 } 00245 00246 virtual ~mm_funct_mfptr() {}; 00247 00248 /** \brief Compute \c nv functions, \c y, of \c nv variables 00249 stored in \c x with parameter \c pa. 00250 */ 00251 virtual int operator()(size_t nv, const vec_t &x, vec_t &y, param_t &pa) { 00252 return (*tptr.*fptr)(nv,x,y,pa); 00253 } 00254 00255 #ifndef DOXYGEN_INTERNAL 00256 00257 protected: 00258 00259 /// The member function pointer 00260 int (tclass::*fptr)(size_t nv, const vec_t &x, vec_t &y, param_t &pa); 00261 00262 /// The class pointer 00263 tclass *tptr; 00264 00265 private: 00266 00267 mm_funct_mfptr(const mm_funct_mfptr &); 00268 mm_funct_mfptr& operator=(const mm_funct_mfptr&); 00269 00270 #endif 00271 00272 }; 00273 00274 /** \brief Member function pointer to an array of 00275 multi-dimensional functions 00276 */ 00277 template<class tclass, class param_t, class vec_t=ovector_view> 00278 class mm_funct_mfptr_nopar : public mm_funct<param_t,vec_t> { 00279 public: 00280 00281 /** \brief Empty constructor 00282 */ 00283 mm_funct_mfptr_nopar() { 00284 } 00285 00286 /** \brief Specify the member function pointer 00287 */ 00288 mm_funct_mfptr_nopar(tclass *tp, int (tclass::*fp) 00289 (size_t nv, const vec_t &x, vec_t &y)) { 00290 tptr=tp; 00291 fptr=fp; 00292 } 00293 00294 /** \brief Specify the member function pointer 00295 */ 00296 int set_function(tclass *tp, int (tclass::*fp) 00297 (size_t nv, const vec_t &x, vec_t &y)) 00298 { 00299 tptr=tp; 00300 fptr=fp; 00301 return 0; 00302 } 00303 00304 virtual ~mm_funct_mfptr_nopar() {}; 00305 00306 /** \brief Compute \c nv functions, \c y, of \c nv variables 00307 stored in \c x with parameter \c pa. 00308 */ 00309 virtual int operator()(size_t nv, const vec_t &x, vec_t &y, param_t &pa) { 00310 return (*tptr.*fptr)(nv,x,y); 00311 } 00312 00313 #ifndef DOXYGEN_INTERNAL 00314 00315 protected: 00316 00317 /// The member function pointer 00318 int (tclass::*fptr)(size_t nv, const vec_t &x, vec_t &y); 00319 00320 /// The class pointer 00321 tclass *tptr; 00322 00323 private: 00324 00325 mm_funct_mfptr_nopar(const mm_funct_mfptr_nopar &); 00326 mm_funct_mfptr_nopar& operator=(const mm_funct_mfptr_nopar&); 00327 00328 #endif 00329 00330 }; 00331 00332 /** 00333 \brief Array of multi-dimensional functions with arrays [abstract 00334 base] 00335 00336 This class generalizes \c nv functions of \c nv variables, i.e. 00337 \f$ y_j(x_0,x_1,...,x_{nv-1}) \f$ for \f$ 0\leq j \leq 00338 nv-1 \f$. 00339 00340 To use ovector_view objects instead of C-style arrays, 00341 use \ref mm_funct. 00342 00343 */ 00344 template<class param_t, size_t nv> 00345 class mm_vfunct { 00346 public: 00347 00348 mm_vfunct() {} 00349 00350 virtual ~mm_vfunct() {} 00351 00352 /** \brief Compute \c nv functions, \c y, of \c nv variables 00353 stored in \c x with parameter \c pa. 00354 */ 00355 virtual int operator()(size_t nvar, const double x[nv], 00356 double y[nv], param_t &pa)=0; 00357 00358 #ifndef DOXYGENP 00359 00360 private: 00361 00362 mm_vfunct(const mm_vfunct &); 00363 mm_vfunct& operator=(const mm_vfunct&); 00364 00365 #endif 00366 00367 }; 00368 00369 /** \brief Function pointer to array of multi-dimensional functions 00370 with arrays 00371 */ 00372 template<class param_t, size_t nv> class mm_vfunct_fptr : 00373 public mm_vfunct<param_t,nv> { 00374 public: 00375 00376 /** \brief Specify the function pointer 00377 */ 00378 mm_vfunct_fptr(int (*fp)(size_t nvar, const double x[nv], double y[nv], 00379 param_t &pa)) { 00380 fptr=fp; 00381 } 00382 00383 00384 virtual ~mm_vfunct_fptr() {}; 00385 00386 /** \brief Compute \c nv functions, \c y, of \c nv variables 00387 stored in \c x with parameter \c pa. 00388 */ 00389 virtual int operator()(size_t nvar, const double x[nv], double y[nv], 00390 param_t &pa) { 00391 return fptr(nv,x,y,pa); 00392 } 00393 00394 00395 #ifndef DOXYGEN_INTERNAL 00396 00397 protected: 00398 00399 friend class io_tlate<mm_vfunct_fptr>; 00400 00401 mm_vfunct_fptr() {}; 00402 00403 /// The function pointer 00404 int (*fptr)(size_t nvar, const double x[nv], double y[nv], param_t &pa); 00405 00406 private: 00407 00408 mm_vfunct_fptr(const mm_vfunct_fptr &); 00409 mm_vfunct_fptr& operator=(const mm_vfunct_fptr&); 00410 00411 #endif 00412 00413 }; 00414 00415 /** \brief Function pointer to array of multi-dimensional functions 00416 with arrays and no parameters 00417 */ 00418 template<class param_t, size_t nv> class mm_vfunct_fptr_nopar : 00419 public mm_vfunct<param_t,nv> 00420 { 00421 public: 00422 00423 /** \brief Specify the function pointer 00424 */ 00425 mm_vfunct_fptr_nopar(int (*fp)(size_t nvar, const double x[nv], 00426 double y[nv])) { 00427 fptr=fp; 00428 } 00429 00430 00431 virtual ~mm_vfunct_fptr_nopar() {}; 00432 00433 /** \brief Compute \c nv functions, \c y, of \c nv variables 00434 stored in \c x with parameter \c pa. 00435 */ 00436 virtual int operator()(size_t nvar, const double x[nv], double y[nv], 00437 param_t &pa) { 00438 return fptr(nv,x,y); 00439 } 00440 00441 00442 #ifndef DOXYGEN_INTERNAL 00443 00444 protected: 00445 00446 friend class io_tlate<mm_vfunct_fptr_nopar>; 00447 00448 mm_vfunct_fptr_nopar() {}; 00449 00450 /// The function pointer 00451 int (*fptr)(size_t nvar, const double x[nv], double y[nv]); 00452 00453 private: 00454 00455 mm_vfunct_fptr_nopar(const mm_vfunct_fptr_nopar &); 00456 mm_vfunct_fptr_nopar& operator=(const mm_vfunct_fptr_nopar&); 00457 00458 #endif 00459 00460 }; 00461 00462 /** \brief Function pointer to a gsl_multiroot_function with arrays 00463 */ 00464 template<class param_t, size_t nv> 00465 class mm_vfunct_gsl : public mm_vfunct<param_t,nv> { 00466 public: 00467 00468 /** \brief Specify the function pointer 00469 */ 00470 mm_vfunct_gsl(int (*fp)(const gsl_vector *x, param_t &pa, gsl_vector *f)) { 00471 fptr=fp; 00472 } 00473 00474 /** \brief Compute \c nv functions, \c y, of \c nv variables 00475 stored in \c x with parameter \c pa. 00476 */ 00477 virtual int operator()(size_t nvar, const double x[nv], 00478 double y[nv], param_t &pa) { 00479 const gsl_vector *gx=(const gsl_vector *)(&x); 00480 gsl_vector *gy=(gsl_vector *)(&y); 00481 return fptr(gx,pa,gy); 00482 } 00483 00484 #ifndef DOXYGEN_INTERNAL 00485 00486 protected: 00487 00488 friend class io_tlate<mm_vfunct_gsl>; 00489 00490 /// The function pointer 00491 int (*fptr)(const gsl_vector *x, param_t &pa, gsl_vector *f); 00492 00493 private: 00494 00495 mm_vfunct_gsl(const mm_vfunct_gsl &); 00496 mm_vfunct_gsl& operator=(const mm_vfunct_gsl&); 00497 00498 #endif 00499 00500 }; 00501 00502 /** \brief Member function pointer to an array of 00503 multi-dimensional functions with arrays 00504 */ 00505 template<class tclass, class param_t, size_t nv> 00506 class mm_vfunct_mfptr : public mm_vfunct<param_t,nv> { 00507 public: 00508 00509 /** \brief Specify the member function pointer 00510 */ 00511 mm_vfunct_mfptr(tclass *tp, int (tclass::*fp) 00512 (size_t nvar, const double x[nv], double y[nv], 00513 param_t &pa)) { 00514 tptr=tp; 00515 fptr=fp; 00516 } 00517 00518 virtual ~mm_vfunct_mfptr() {}; 00519 00520 /** \brief Compute \c nv functions, \c y, of \c nv variables 00521 stored in \c x with parameter \c pa. 00522 */ 00523 virtual int operator()(size_t nvar, const double x[nv], double y[nv], 00524 param_t &pa) { 00525 return (*tptr.*fptr)(nv,x,y,pa); 00526 } 00527 00528 #ifndef DOXYGEN_INTERNAL 00529 00530 protected: 00531 00532 /// The member function pointer 00533 int (tclass::*fptr)(size_t nvar, const double x[nv], double y[nv], 00534 param_t &pa); 00535 00536 /// The class pointer 00537 tclass *tptr; 00538 00539 private: 00540 00541 mm_vfunct_mfptr(const mm_vfunct_mfptr &); 00542 mm_vfunct_mfptr& operator=(const mm_vfunct_mfptr&); 00543 00544 #endif 00545 00546 }; 00547 00548 /** \brief Member function pointer to an array of 00549 multi-dimensional functions with arrays 00550 */ 00551 template<class tclass, class param_t, size_t nv> 00552 class mm_vfunct_mfptr_nopar : public mm_vfunct<param_t,nv> { 00553 00554 public: 00555 00556 /** \brief Specify the member function pointer 00557 */ 00558 mm_vfunct_mfptr_nopar(tclass *tp, int (tclass::*fp) 00559 (size_t nvar, const double x[nv], double y[nv])) { 00560 tptr=tp; 00561 fptr=fp; 00562 } 00563 00564 virtual ~mm_vfunct_mfptr_nopar() {}; 00565 00566 /** \brief Compute \c nv functions, \c y, of \c nv variables 00567 stored in \c x with parameter \c pa. 00568 */ 00569 virtual int operator()(size_t nvar, const double x[nv], double y[nv], 00570 param_t &pa) { 00571 return (*tptr.*fptr)(nv,x,y); 00572 } 00573 00574 #ifndef DOXYGEN_INTERNAL 00575 00576 protected: 00577 00578 /// The member function pointer 00579 int (tclass::*fptr)(size_t nvar, const double x[nv], double y[nv]); 00580 00581 /// The class pointer 00582 tclass *tptr; 00583 00584 private: 00585 00586 mm_vfunct_mfptr_nopar(const mm_vfunct_mfptr_nopar &); 00587 mm_vfunct_mfptr_nopar& operator=(const mm_vfunct_mfptr_nopar&); 00588 00589 #endif 00590 00591 }; 00592 00593 #ifndef DOXYGENP 00594 } 00595 #endif 00596 00597 #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