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