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_MULTI_FUNCT_H 00024 #define O2SCL_MULTI_FUNCT_H 00025 00026 #include <string> 00027 #include <o2scl/collection.h> 00028 00029 #ifndef DOXYGENP 00030 namespace o2scl { 00031 #endif 00032 00033 /** 00034 \brief Multi-dimensional function [abstract base] 00035 00036 This class generalizes one function of several variables, 00037 i.e. \f$ y(x_0,x_1,...,x_{nv-1}) \f$ where \c nv is the number 00038 of variables in the function y. 00039 00040 For functions with C-style arrays, use 00041 the corresponding children of \ref multi_vfunct . 00042 00043 This class is one of a large number of function object classes 00044 in \o2 designed to provide a mechanism for the user to 00045 supply functions to solvers, minimizers, integrators, etc. 00046 See \ref funct_section for a general description. 00047 00048 */ 00049 00050 template<class param_t, class vec_t=ovector_base> class multi_funct { 00051 00052 public: 00053 00054 multi_funct() {} 00055 00056 virtual ~multi_funct() {} 00057 00058 /** \brief Compute a function \c y of \c nv variables stored in \c x 00059 with parameter \c pa. 00060 */ 00061 virtual int operator()(size_t nv, const vec_t &x, double &y, 00062 param_t &pa)=0; 00063 00064 00065 /** \brief Return the value of a function of \c nv variables 00066 stored in \c x with parameter \c pa. 00067 00068 Note that this is reimplemented in all children because 00069 if one member function operator() is reimplemented, all must be. 00070 */ 00071 virtual double operator()(size_t nv, const vec_t &x, param_t &pa) { 00072 double y; 00073 operator()(nv,x,y,pa); 00074 return y; 00075 } 00076 00077 #ifndef DOXYGENP 00078 00079 private: 00080 00081 multi_funct(const multi_funct &); 00082 multi_funct& operator=(const multi_funct&); 00083 00084 #endif 00085 00086 }; 00087 00088 /** \brief Function pointer to a multi-dimensional function 00089 */ 00090 template<class param_t, class vec_t=ovector_base> 00091 class multi_funct_fptr : public multi_funct<param_t,vec_t> { 00092 00093 public: 00094 00095 /** \brief Specify the function pointer 00096 */ 00097 multi_funct_fptr(int (*fp)(size_t nv, const vec_t &x, double &y, 00098 param_t &pa)) { 00099 fptr=fp; 00100 } 00101 00102 00103 virtual ~multi_funct_fptr() {}; 00104 00105 /** \brief Compute a function \c y of \c nv variables stored in \c x 00106 with parameter \c pa. 00107 */ 00108 virtual int operator()(size_t nv, const vec_t &x, double &y, param_t &pa) { 00109 return fptr(nv,x,y,pa); 00110 } 00111 00112 /** \brief Return the value of a function of \c nv variables 00113 stored in \c x with parameter \c pa. 00114 00115 Note that this is reimplemented in all children because 00116 if one member function operator() is reimplemented, all must be. 00117 */ 00118 virtual double operator()(size_t nv, const vec_t &x, param_t &pa) { 00119 double y; 00120 operator()(nv,x,y,pa); 00121 return y; 00122 } 00123 00124 #ifndef DOXYGEN_INTERNAL 00125 00126 protected: 00127 00128 friend class io_tlate<multi_funct_fptr>; 00129 00130 /// Store the function pointer 00131 int (*fptr)(size_t nv, const vec_t &x, double &y, param_t &pa); 00132 00133 multi_funct_fptr() {} 00134 00135 #ifndef DOXYGENP 00136 #endif 00137 00138 private: 00139 00140 multi_funct_fptr(const multi_funct_fptr &); 00141 multi_funct_fptr& operator=(const multi_funct_fptr&); 00142 00143 #endif 00144 00145 }; 00146 00147 /** \brief Function pointer to a gsl_multimin_function 00148 */ 00149 template<class param_t, class vec_t=ovector_base> 00150 class multi_funct_gsl : public multi_funct<param_t,vec_t> { 00151 public: 00152 00153 /** \brief Specify the function pointer 00154 */ 00155 multi_funct_gsl(double (*fp)(const gsl_vector *x, param_t &pa)) { 00156 fptr=fp; 00157 } 00158 00159 virtual ~multi_funct_gsl() {} 00160 00161 /** \brief Compute a function \c y of \c nv variables stored in \c x 00162 with parameter \c pa. 00163 */ 00164 virtual int operator()(size_t nv, const vec_t &x, double &y, param_t &pa) { 00165 const gsl_vector *gx=(const gsl_vector *)(&x); 00166 y=fptr(gx,pa); 00167 return 0; 00168 } 00169 00170 /** \brief Return the value of a function of \c nv variables 00171 stored in \c x with parameter \c pa. 00172 00173 Note that this is reimplemented in all children because 00174 if one member function operator() is reimplemented, all must be. 00175 */ 00176 virtual double operator()(size_t nv, const vec_t &x, param_t &pa) { 00177 double y; 00178 operator()(nv,x,y,pa); 00179 return y; 00180 } 00181 00182 #ifndef DOXYGEN_INTERNAL 00183 00184 protected: 00185 00186 friend class io_tlate<multi_funct_gsl>; 00187 00188 /// Store the function pointer 00189 double (*fptr)(const gsl_vector *x, param_t &pa); 00190 00191 multi_funct_gsl() {} 00192 00193 #ifndef DOXYGENP 00194 #endif 00195 00196 private: 00197 00198 multi_funct_gsl(const multi_funct_gsl &); 00199 multi_funct_gsl& operator=(const multi_funct_gsl&); 00200 00201 #endif 00202 00203 }; 00204 00205 /** \brief Function pointer to a multi-dimensional function without 00206 error control 00207 */ 00208 template<class param_t, class vec_t=ovector_base> 00209 class multi_funct_fptr_noerr : public multi_funct<param_t,vec_t> { 00210 public: 00211 00212 /** \brief Specify the function pointer 00213 */ 00214 multi_funct_fptr_noerr(double (*fp)(size_t nv, const vec_t &x, 00215 param_t &pa)) { 00216 fptr=fp; 00217 } 00218 00219 virtual ~multi_funct_fptr_noerr() {} 00220 00221 /** \brief Compute a function \c y of \c nv variables stored in \c x 00222 with parameter \c pa. 00223 */ 00224 virtual int operator()(size_t nv, const vec_t &x, double &y, param_t &pa) { 00225 y=fptr(nv,x,pa); 00226 return 0; 00227 } 00228 00229 /** \brief Return the value of a function of \c nv variables 00230 stored in \c x with parameter \c pa. 00231 00232 Note that this is reimplemented in all children because 00233 if one member function operator() is reimplemented, all must be. 00234 */ 00235 virtual double operator()(size_t nv, const vec_t &x, param_t &pa) { 00236 double y; 00237 operator()(nv,x,y,pa); 00238 return y; 00239 } 00240 00241 #ifndef DOXYGEN_INTERNAL 00242 00243 protected: 00244 00245 friend class io_tlate<multi_funct_fptr_noerr>; 00246 00247 multi_funct_fptr_noerr() {} 00248 00249 /// Store the function pointer 00250 double (*fptr)(size_t nv, const vec_t &x, param_t &pa); 00251 00252 #ifndef DOXYGENP 00253 #endif 00254 00255 private: 00256 00257 multi_funct_fptr_noerr(const multi_funct_fptr_noerr &); 00258 multi_funct_fptr_noerr& operator=(const multi_funct_fptr_noerr&); 00259 00260 #endif 00261 00262 }; 00263 00264 /** \brief Member function pointer to a multi-dimensional function 00265 */ 00266 template<class tclass, class param_t, class vec_t=ovector_base> 00267 class multi_funct_mfptr : public multi_funct<param_t,vec_t> { 00268 public: 00269 00270 /** \brief Specify the member function pointer 00271 */ 00272 multi_funct_mfptr(tclass *tp, int (tclass::*fp) 00273 (size_t nv, const vec_t &x, double &y, param_t &pa)) { 00274 tptr=tp; 00275 fptr=fp; 00276 } 00277 00278 virtual ~multi_funct_mfptr() {} 00279 00280 /** \brief Compute a function \c y of \c nv variables stored in \c x 00281 with parameter \c pa. 00282 */ 00283 virtual int operator()(size_t nv, const vec_t &x, double &y, param_t &pa) { 00284 return (*tptr.*fptr)(nv,x,y,pa); 00285 } 00286 00287 /** \brief Return the value of a function of \c nv variables 00288 stored in \c x with parameter \c pa. 00289 00290 Note that this is reimplemented in all children because 00291 if one member function operator() is reimplemented, all must be. 00292 */ 00293 virtual double operator()(size_t nv, const vec_t &x, param_t &pa) { 00294 double y; 00295 operator()(nv,x,y,pa); 00296 return y; 00297 } 00298 00299 #ifndef DOXYGEN_INTERNAL 00300 00301 protected: 00302 00303 /// Store the function pointer 00304 int (tclass::*fptr)(size_t nv, const vec_t &x, double &y, param_t &pa); 00305 /// Store a pointer to the class instance 00306 tclass *tptr; 00307 00308 #ifndef DOXYGENP 00309 #endif 00310 00311 private: 00312 00313 multi_funct_mfptr(const multi_funct_mfptr &); 00314 multi_funct_mfptr& operator=(const multi_funct_mfptr&); 00315 00316 #endif 00317 00318 }; 00319 00320 /** \brief Member function pointer to a multi-dimensional function 00321 */ 00322 template<class tclass, class param_t, class vec_t=ovector_base> 00323 class multi_funct_mfptr_noerr : public multi_funct<param_t,vec_t> { 00324 public: 00325 00326 /** \brief Specify the member function pointer 00327 */ 00328 multi_funct_mfptr_noerr(tclass *tp, double (tclass::*fp) 00329 (size_t nv, const vec_t &x, param_t &pa)) { 00330 tptr=tp; 00331 fptr=fp; 00332 } 00333 00334 virtual ~multi_funct_mfptr_noerr() {} 00335 00336 /** \brief Compute a function \c y of \c nv variables stored in \c x 00337 with parameter \c pa. 00338 */ 00339 virtual int operator()(size_t nv, const vec_t &x, double &y, param_t &pa) { 00340 y=(*tptr.*fptr)(nv,x,pa); 00341 return 0; 00342 } 00343 00344 /** \brief Return the value of a function of \c nv variables 00345 stored in \c x with parameter \c pa. 00346 00347 Note that this is reimplemented in all children because 00348 if one member function operator() is reimplemented, all must be. 00349 */ 00350 virtual double operator()(size_t nv, const vec_t &x, param_t &pa) { 00351 double y; 00352 operator()(nv,x,y,pa); 00353 return y; 00354 } 00355 00356 #ifndef DOXYGEN_INTERNAL 00357 00358 protected: 00359 00360 /// Store the function pointer 00361 double (tclass::*fptr)(size_t nv, const vec_t &x, param_t &pa); 00362 /// Store a pointer to the class instance 00363 tclass *tptr; 00364 00365 #ifndef DOXYGENP 00366 #endif 00367 00368 private: 00369 00370 multi_funct_mfptr_noerr(const multi_funct_mfptr_noerr &); 00371 multi_funct_mfptr_noerr& operator=(const multi_funct_mfptr_noerr&); 00372 00373 #endif 00374 00375 }; 00376 00377 /** \brief Const member function pointer to a multi-dimensional function 00378 */ 00379 template<class tclass, class param_t, class vec_t=ovector_base> 00380 class multi_funct_cmfptr : public multi_funct<param_t,vec_t> { 00381 public: 00382 00383 /** \brief Specify the member function pointer 00384 */ 00385 multi_funct_cmfptr(tclass *tp, int (tclass::*fp) 00386 (size_t nv, const vec_t &x, double &y, 00387 param_t &pa) const) { 00388 tptr=tp; 00389 fptr=fp; 00390 } 00391 00392 virtual ~multi_funct_cmfptr() {} 00393 00394 /** \brief Compute a function \c y of \c nv variables stored in \c x 00395 with parameter \c pa. 00396 */ 00397 virtual int operator()(size_t nv, const vec_t &x, double &y, param_t &pa) { 00398 return (*tptr.*fptr)(nv,x,y,pa); 00399 } 00400 00401 /** \brief Return the value of a function of \c nv variables 00402 stored in \c x with parameter \c pa. 00403 00404 Note that this is reimplemented in all children because 00405 if one member function operator() is reimplemented, all must be. 00406 */ 00407 virtual double operator()(size_t nv, const vec_t &x, param_t &pa) { 00408 double y; 00409 operator()(nv,x,y,pa); 00410 return y; 00411 } 00412 00413 #ifndef DOXYGEN_INTERNAL 00414 00415 protected: 00416 00417 /// Store the function pointer 00418 int (tclass::*fptr)(size_t nv, const vec_t &x, double &y, 00419 param_t &pa) const; 00420 /// Store a pointer to the class instance 00421 tclass *tptr; 00422 00423 #ifndef DOXYGENP 00424 #endif 00425 00426 private: 00427 00428 multi_funct_cmfptr(const multi_funct_cmfptr &); 00429 multi_funct_cmfptr& operator=(const multi_funct_cmfptr&); 00430 00431 #endif 00432 00433 }; 00434 00435 /** \brief Const member function pointer to a multi-dimensional function 00436 */ 00437 template<class tclass, class param_t, class vec_t=ovector_base> 00438 class multi_funct_cmfptr_noerr : public multi_funct<param_t,vec_t> { 00439 public: 00440 00441 /** \brief Specify the member function pointer 00442 */ 00443 multi_funct_cmfptr_noerr(tclass *tp, double (tclass::*fp) 00444 (size_t nv, const vec_t &x, param_t &pa) const) { 00445 tptr=tp; 00446 fptr=fp; 00447 } 00448 00449 virtual ~multi_funct_cmfptr_noerr() {} 00450 00451 /** \brief Compute a function \c y of \c nv variables stored in \c x 00452 with parameter \c pa. 00453 */ 00454 virtual int operator()(size_t nv, const vec_t &x, double &y, param_t &pa) { 00455 y=(*tptr.*fptr)(nv,x,pa); 00456 return 0; 00457 } 00458 00459 /** \brief Return the value of a function of \c nv variables 00460 stored in \c x with parameter \c pa. 00461 00462 Note that this is reimplemented in all children because 00463 if one member function operator() is reimplemented, all must be. 00464 */ 00465 virtual double operator()(size_t nv, const vec_t &x, param_t &pa) { 00466 double y; 00467 operator()(nv,x,y,pa); 00468 return y; 00469 } 00470 00471 #ifndef DOXYGEN_INTERNAL 00472 00473 protected: 00474 00475 /// Store the function pointer 00476 double (tclass::*fptr)(size_t nv, const vec_t &x, param_t &pa) const; 00477 /// Store a pointer to the class instance 00478 tclass *tptr; 00479 00480 #ifndef DOXYGENP 00481 #endif 00482 00483 private: 00484 00485 multi_funct_cmfptr_noerr(const multi_funct_cmfptr_noerr &); 00486 multi_funct_cmfptr_noerr& operator=(const multi_funct_cmfptr_noerr&); 00487 00488 #endif 00489 00490 }; 00491 00492 // --------------------------------------------------------------------- 00493 // --------------------------------------------------------------------- 00494 00495 /** 00496 \brief Multi-dimensional function base with arrays [abstract base] 00497 00498 This class generalizes one function of several variables, 00499 i.e. \f$ y(x_0,x_1,...,x_{nv-1}) \f$ where \c nv is the number 00500 of variables in the function y. 00501 00502 This class is one of a large number of function object classes 00503 in \o2 designed to provide a mechanism for the user to 00504 supply functions to solvers, minimizers, integrators, etc. 00505 See \ref funct_section for a general description. 00506 */ 00507 template<class param_t, size_t nvar> class multi_vfunct { 00508 00509 public: 00510 00511 multi_vfunct() {} 00512 00513 virtual ~multi_vfunct() {} 00514 00515 /** \brief Compute a function \c y of \c nv variables stored in \c x 00516 with parameter \c pa. 00517 */ 00518 virtual int operator()(size_t nv, const double x[nvar], double &y, 00519 param_t &pa)=0; 00520 00521 /** \brief Return the value of a function of \c nv variables 00522 stored in \c x with parameter \c pa. 00523 00524 Note that this is reimplemented in all children because 00525 if one member function operator() is reimplemented, all must be. 00526 */ 00527 virtual double operator()(size_t nv, const double x[nvar], param_t &pa) { 00528 double y; 00529 operator()(nv,x,y,pa); 00530 return y; 00531 } 00532 00533 #ifndef DOXYGENP 00534 00535 private: 00536 00537 multi_vfunct(const multi_vfunct &); 00538 multi_vfunct& operator=(const multi_vfunct&); 00539 00540 #endif 00541 00542 }; 00543 00544 /** \brief Function pointer to a multi-dimensional function with arrays 00545 */ 00546 template<class param_t, size_t nvar> 00547 class multi_vfunct_fptr : public multi_vfunct<param_t,nvar> { 00548 00549 public: 00550 00551 /** \brief Specify the function pointer 00552 */ 00553 multi_vfunct_fptr(int (*fp)(size_t nv, const double x[nvar], double &y, 00554 param_t &pa)) { 00555 fptr=fp; 00556 } 00557 00558 00559 virtual ~multi_vfunct_fptr() {} 00560 00561 /** \brief Compute a function \c y of \c nv variables stored in \c x 00562 with parameter \c pa. 00563 */ 00564 virtual int operator()(size_t nv, const double x[nvar], double &y, 00565 param_t &pa) { 00566 return fptr(nv,x,y,pa); 00567 } 00568 00569 /** \brief Return the value of a function of \c nv variables 00570 stored in \c x with parameter \c pa. 00571 00572 Note that this is reimplemented in all children because 00573 if one member function operator() is reimplemented, all must be. 00574 */ 00575 virtual double operator()(size_t nv, const double x[nvar], param_t &pa) { 00576 double y; 00577 operator()(nv,x,y,pa); 00578 return y; 00579 } 00580 00581 #ifndef DOXYGEN_INTERNAL 00582 00583 protected: 00584 00585 friend class io_tlate<multi_vfunct_fptr>; 00586 00587 /// Store the function pointer 00588 int (*fptr)(size_t nv, const double x[nvar], double &y, param_t &pa); 00589 00590 multi_vfunct_fptr() {} 00591 00592 #ifndef DOXYGENP 00593 #endif 00594 00595 private: 00596 00597 multi_vfunct_fptr(const multi_vfunct_fptr &); 00598 multi_vfunct_fptr& operator=(const multi_vfunct_fptr&); 00599 00600 #endif 00601 00602 }; 00603 00604 /** \brief Function pointer to a gsl_multimin_function with arrays 00605 */ 00606 template<class param_t, size_t nvar> 00607 class multi_vfunct_gsl : public multi_vfunct<param_t,nvar> { 00608 public: 00609 00610 /** \brief Specify the function pointer 00611 */ 00612 multi_vfunct_gsl(double (*fp)(const gsl_vector *x, param_t &pa)) { 00613 fptr=fp; 00614 } 00615 00616 virtual ~multi_vfunct_gsl() {} 00617 00618 /** \brief Compute a function \c y of \c nv variables stored in \c x 00619 with parameter \c pa. 00620 */ 00621 virtual int operator()(size_t nv, const double x[nvar], double &y, 00622 param_t &pa) { 00623 const gsl_vector *gx=(const gsl_vector *)(&x); 00624 y=fptr(gx,pa); 00625 return 0; 00626 } 00627 00628 /** \brief Return the value of a function of \c nv variables 00629 stored in \c x with parameter \c pa. 00630 00631 Note that this is reimplemented in all children because 00632 if one member function operator() is reimplemented, all must be. 00633 */ 00634 virtual double operator()(size_t nv, const double x[nvar], param_t &pa) { 00635 double y; 00636 operator()(nv,x,y,pa); 00637 return y; 00638 } 00639 00640 #ifndef DOXYGEN_INTERNAL 00641 00642 protected: 00643 00644 friend class io_tlate<multi_vfunct_gsl>; 00645 00646 /// Store the function pointer 00647 double (*fptr)(const gsl_vector *x, param_t &pa); 00648 00649 multi_vfunct_gsl() {} 00650 00651 #ifndef DOXYGENP 00652 #endif 00653 00654 private: 00655 00656 multi_vfunct_gsl(const multi_vfunct_gsl &); 00657 multi_vfunct_gsl& operator=(const multi_vfunct_gsl&); 00658 00659 #endif 00660 00661 }; 00662 00663 /** \brief Function pointer to a multi-dimensional function with 00664 arrays and without error control 00665 */ 00666 template<class param_t, size_t nvar> 00667 class multi_vfunct_fptr_noerr : public multi_vfunct<param_t,nvar> { 00668 public: 00669 00670 /** \brief Specify the function pointer 00671 */ 00672 multi_vfunct_fptr_noerr(double (*fp)(size_t nv, const double x[nvar], 00673 param_t &pa)) { 00674 fptr=fp; 00675 } 00676 00677 virtual ~multi_vfunct_fptr_noerr() {} 00678 00679 /** \brief Compute a function \c y of \c nv variables stored in \c x 00680 with parameter \c pa. 00681 */ 00682 virtual int operator()(size_t nv, const double x[nvar], double &y, 00683 param_t &pa) { 00684 y=fptr(nv,x,pa); 00685 return 0; 00686 } 00687 00688 /** \brief Return the value of a function of \c nv variables 00689 stored in \c x with parameter \c pa. 00690 00691 Note that this is reimplemented in all children because 00692 if one member function operator() is reimplemented, all must be. 00693 */ 00694 virtual double operator()(size_t nv, const double x[nvar], param_t &pa) { 00695 double y; 00696 operator()(nv,x,y,pa); 00697 return y; 00698 } 00699 00700 #ifndef DOXYGEN_INTERNAL 00701 00702 protected: 00703 00704 friend class io_tlate<multi_vfunct_fptr_noerr>; 00705 00706 multi_vfunct_fptr_noerr() {} 00707 00708 /// Store the function pointer 00709 double (*fptr)(size_t nv, const double x[nvar], param_t &pa); 00710 00711 #ifndef DOXYGENP 00712 #endif 00713 00714 private: 00715 00716 multi_vfunct_fptr_noerr(const multi_vfunct_fptr_noerr &); 00717 multi_vfunct_fptr_noerr& operator=(const multi_vfunct_fptr_noerr&); 00718 00719 #endif 00720 00721 }; 00722 00723 /** \brief Member function pointer to a multi-dimensional function 00724 with arrays 00725 */ 00726 template<class tclass, class param_t, size_t nvar> 00727 class multi_vfunct_mfptr : public multi_vfunct<param_t,nvar> { 00728 public: 00729 00730 /** \brief Specify the member function pointer 00731 */ 00732 multi_vfunct_mfptr(tclass *tp, int (tclass::*fp) 00733 (size_t nv, const double x[nvar], double &y, 00734 param_t &pa)) { 00735 tptr=tp; 00736 fptr=fp; 00737 } 00738 00739 virtual ~multi_vfunct_mfptr() {} 00740 00741 /** \brief Compute a function \c y of \c nv variables stored in \c x 00742 with parameter \c pa. 00743 */ 00744 virtual int operator()(size_t nv, const double x[nvar], double &y, 00745 param_t &pa) { 00746 return (*tptr.*fptr)(nv,x,y,pa); 00747 } 00748 00749 /** \brief Return the value of a function of \c nv variables 00750 stored in \c x with parameter \c pa. 00751 00752 Note that this is reimplemented in all children because 00753 if one member function operator() is reimplemented, all must be. 00754 */ 00755 virtual double operator()(size_t nv, const double x[nvar], param_t &pa) { 00756 double y; 00757 operator()(nv,x,y,pa); 00758 return y; 00759 } 00760 00761 #ifndef DOXYGEN_INTERNAL 00762 00763 protected: 00764 00765 /// Store the function pointer 00766 int (tclass::*fptr)(size_t nv, const double x[nvar], double &y, 00767 param_t &pa); 00768 00769 /// Store a pointer to the class instance 00770 tclass *tptr; 00771 00772 #ifndef DOXYGENP 00773 #endif 00774 00775 private: 00776 00777 multi_vfunct_mfptr(const multi_vfunct_mfptr &); 00778 multi_vfunct_mfptr& operator=(const multi_vfunct_mfptr&); 00779 00780 #endif 00781 00782 }; 00783 00784 /** \brief Member function pointer to a multi-dimensional function 00785 with arrays 00786 */ 00787 template<class tclass, class param_t, size_t nvar> 00788 class multi_vfunct_mfptr_noerr : public multi_vfunct<param_t,nvar> { 00789 public: 00790 00791 /** \brief Specify the member function pointer 00792 */ 00793 multi_vfunct_mfptr_noerr(tclass *tp, double (tclass::*fp) 00794 (size_t nv, const double x[nvar], param_t &pa)) { 00795 tptr=tp; 00796 fptr=fp; 00797 } 00798 00799 virtual ~multi_vfunct_mfptr_noerr() {} 00800 00801 /** \brief Compute a function \c y of \c nv variables stored in \c x 00802 with parameter \c pa. 00803 */ 00804 virtual int operator()(size_t nv, const double x[nvar], double &y, 00805 param_t &pa) { 00806 y=(*tptr.*fptr)(nv,x,pa); 00807 return 0; 00808 } 00809 00810 /** \brief Return the value of a function of \c nv variables 00811 stored in \c x with parameter \c pa. 00812 00813 Note that this is reimplemented in all children because 00814 if one member function operator() is reimplemented, all must be. 00815 */ 00816 virtual double operator()(size_t nv, const double x[nvar], param_t &pa) { 00817 double y; 00818 operator()(nv,x,y,pa); 00819 return y; 00820 } 00821 00822 #ifndef DOXYGEN_INTERNAL 00823 00824 protected: 00825 00826 /// Store the function pointer 00827 double (tclass::*fptr)(size_t nv, const double x[nvar], param_t &pa); 00828 00829 /// Store a pointer to the class instance 00830 tclass *tptr; 00831 00832 #ifndef DOXYGENP 00833 #endif 00834 00835 private: 00836 00837 multi_vfunct_mfptr_noerr(const multi_vfunct_mfptr_noerr &); 00838 multi_vfunct_mfptr_noerr& operator=(const multi_vfunct_mfptr_noerr&); 00839 00840 #endif 00841 00842 }; 00843 00844 /** \brief Member function pointer to a multi-dimensional function 00845 with arrays 00846 */ 00847 template<class tclass, class param_t, size_t nvar> 00848 class multi_vfunct_cmfptr : public multi_vfunct<param_t,nvar> { 00849 public: 00850 00851 /** \brief Specify the member function pointer 00852 */ 00853 multi_vfunct_cmfptr(tclass *tp, int (tclass::*fp) 00854 (size_t nv, const double x[nvar], double &y, 00855 param_t &pa) const) { 00856 tptr=tp; 00857 fptr=fp; 00858 } 00859 00860 virtual ~multi_vfunct_cmfptr() {} 00861 00862 /** \brief Compute a function \c y of \c nv variables stored in \c x 00863 with parameter \c pa. 00864 */ 00865 virtual int operator()(size_t nv, const double x[nvar], double &y, 00866 param_t &pa) { 00867 return (*tptr.*fptr)(nv,x,y,pa); 00868 } 00869 00870 /** \brief Return the value of a function of \c nv variables 00871 stored in \c x with parameter \c pa. 00872 00873 Note that this is reimplemented in all children because 00874 if one member function operator() is reimplemented, all must be. 00875 */ 00876 virtual double operator()(size_t nv, const double x[nvar], param_t &pa) { 00877 double y; 00878 operator()(nv,x,y,pa); 00879 return y; 00880 } 00881 00882 #ifndef DOXYGEN_INTERNAL 00883 00884 protected: 00885 00886 /// Store the function pointer 00887 int (tclass::*fptr)(size_t nv, const double x[nvar], double &y, 00888 param_t &pa) const; 00889 00890 /// Store a pointer to the class instance 00891 tclass *tptr; 00892 00893 #ifndef DOXYGENP 00894 #endif 00895 00896 private: 00897 00898 multi_vfunct_cmfptr(const multi_vfunct_cmfptr &); 00899 multi_vfunct_cmfptr& operator=(const multi_vfunct_cmfptr&); 00900 00901 #endif 00902 00903 }; 00904 00905 /** \brief Member function pointer to a multi-dimensional function 00906 with arrays 00907 */ 00908 template<class tclass, class param_t, size_t nvar> 00909 class multi_vfunct_cmfptr_noerr : public multi_vfunct<param_t,nvar> { 00910 public: 00911 00912 /** \brief Specify the member function pointer 00913 */ 00914 multi_vfunct_cmfptr_noerr(tclass *tp, double (tclass::*fp) 00915 (size_t nv, const double x[nvar], 00916 param_t &pa) const) { 00917 tptr=tp; 00918 fptr=fp; 00919 } 00920 00921 virtual ~multi_vfunct_cmfptr_noerr() {} 00922 00923 /** \brief Compute a function \c y of \c nv variables stored in \c x 00924 with parameter \c pa. 00925 */ 00926 virtual int operator()(size_t nv, const double x[nvar], double &y, 00927 param_t &pa) { 00928 y=(*tptr.*fptr)(nv,x,pa); 00929 return 0; 00930 } 00931 00932 /** \brief Return the value of a function of \c nv variables 00933 stored in \c x with parameter \c pa. 00934 00935 Note that this is reimplemented in all children because 00936 if one member function operator() is reimplemented, all must be. 00937 */ 00938 virtual double operator()(size_t nv, const double x[nvar], param_t &pa) { 00939 double y; 00940 operator()(nv,x,y,pa); 00941 return y; 00942 } 00943 00944 #ifndef DOXYGEN_INTERNAL 00945 00946 protected: 00947 00948 /// Store the function pointer 00949 double (tclass::*fptr)(size_t nv, const double x[nvar], param_t &pa) const; 00950 00951 /// Store a pointer to the class instance 00952 tclass *tptr; 00953 00954 #ifndef DOXYGENP 00955 #endif 00956 00957 private: 00958 00959 multi_vfunct_cmfptr_noerr(const multi_vfunct_cmfptr_noerr &); 00960 multi_vfunct_cmfptr_noerr& operator=(const multi_vfunct_cmfptr_noerr&); 00961 00962 #endif 00963 00964 }; 00965 00966 #ifndef DOXYGENP 00967 } 00968 #endif 00969 00970 #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