![]() |
Object-oriented Scientific Computing Library: Version 0.910
|
00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006-2012, 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/err_hnd.h> 00028 #include <o2scl/ovector_tlate.h> 00029 00030 #ifndef DOXYGENP 00031 namespace o2scl { 00032 #endif 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 00041 This class is one of a large number of function object classes 00042 in \o2 designed to provide a mechanism for the user to 00043 supply functions to solvers, minimizers, integrators, etc. 00044 See \ref funct_section for a general description. 00045 00046 */ 00047 template<class vec_t=ovector_base> class multi_funct { 00048 00049 public: 00050 00051 multi_funct() {} 00052 00053 virtual ~multi_funct() {} 00054 00055 /** \brief Compute a function \c y of \c nv variables stored in \c x 00056 with parameter \c pa. 00057 */ 00058 virtual double operator()(size_t nv, const vec_t &x)=0; 00059 00060 #ifndef DOXYGENP 00061 00062 private: 00063 00064 multi_funct(const multi_funct &); 00065 multi_funct& operator=(const multi_funct&); 00066 00067 #endif 00068 00069 }; 00070 00071 /** \brief Function pointer to a multi-dimensional function 00072 */ 00073 template<class vec_t=ovector_base> 00074 class multi_funct_fptr : public multi_funct<vec_t> { 00075 00076 public: 00077 00078 /** \brief Specify the function pointer 00079 */ 00080 multi_funct_fptr(double (*fp)(size_t nv, const vec_t &x)) { 00081 fptr=fp; 00082 } 00083 00084 virtual ~multi_funct_fptr() {}; 00085 00086 /** \brief Compute a function \c y of \c nv variables stored in \c x 00087 with parameter \c pa. 00088 */ 00089 virtual double operator()(size_t nv, const vec_t &x) { 00090 return fptr(nv,x); 00091 } 00092 00093 #ifndef DOXYGEN_INTERNAL 00094 00095 protected: 00096 00097 /// Store the function pointer 00098 double (*fptr)(size_t nv, const vec_t &x); 00099 00100 multi_funct_fptr() {} 00101 00102 #ifndef DOXYGENP 00103 #endif 00104 00105 private: 00106 00107 multi_funct_fptr(const multi_funct_fptr &); 00108 multi_funct_fptr& operator=(const multi_funct_fptr&); 00109 00110 #endif 00111 00112 }; 00113 00114 /** \brief Function pointer to a multi-dimensional function 00115 */ 00116 template<class param_t, class vec_t=ovector_base> 00117 class multi_funct_fptr_param : public multi_funct<vec_t> { 00118 00119 public: 00120 00121 /** \brief Specify the function pointer 00122 */ 00123 multi_funct_fptr_param(double (*fp)(size_t nv, const vec_t &x, 00124 param_t &), param_t &pa) { 00125 fptr=fp; 00126 pp=&pa; 00127 } 00128 00129 virtual ~multi_funct_fptr_param() {}; 00130 00131 /** \brief Compute a function \c y of \c nv variables stored in \c x 00132 with parameter \c pa. 00133 */ 00134 virtual double operator()(size_t nv, const vec_t &x) { 00135 return fptr(nv,x,*pp); 00136 } 00137 00138 #ifndef DOXYGEN_INTERNAL 00139 00140 protected: 00141 00142 /// Store the function pointer 00143 double (*fptr)(size_t nv, const vec_t &x, param_t &); 00144 00145 /// Parameter 00146 param_t *pp; 00147 00148 multi_funct_fptr_param() {} 00149 00150 #ifndef DOXYGENP 00151 #endif 00152 00153 private: 00154 00155 multi_funct_fptr_param(const multi_funct_fptr_param &); 00156 multi_funct_fptr_param& operator=(const multi_funct_fptr_param&); 00157 00158 #endif 00159 00160 }; 00161 00162 /** \brief Member function pointer to a multi-dimensional function 00163 */ 00164 template<class tclass, class vec_t=ovector_base> 00165 class multi_funct_mfptr : public multi_funct<vec_t> { 00166 public: 00167 00168 /** \brief Specify the member function pointer 00169 */ 00170 multi_funct_mfptr(tclass *tp, double (tclass::*fp) 00171 (size_t nv, const vec_t &x)) { 00172 tptr=tp; 00173 fptr=fp; 00174 } 00175 00176 virtual ~multi_funct_mfptr() {} 00177 00178 /** \brief Compute a function \c y of \c nv variables stored in \c x 00179 with parameter \c pa. 00180 */ 00181 virtual double operator()(size_t nv, const vec_t &x) { 00182 return (*tptr.*fptr)(nv,x); 00183 } 00184 00185 #ifndef DOXYGEN_INTERNAL 00186 00187 protected: 00188 00189 /// Store the function pointer 00190 double (tclass::*fptr)(size_t nv, const vec_t &x); 00191 00192 /// Store a pointer to the class instance 00193 tclass *tptr; 00194 00195 #ifndef DOXYGENP 00196 #endif 00197 00198 private: 00199 00200 multi_funct_mfptr(const multi_funct_mfptr &); 00201 multi_funct_mfptr& operator=(const multi_funct_mfptr&); 00202 00203 #endif 00204 00205 }; 00206 00207 /** \brief Member function pointer to a multi-dimensional function 00208 */ 00209 template<class tclass, class param_t, class vec_t=ovector_base> 00210 class multi_funct_mfptr_param : public multi_funct<vec_t> { 00211 public: 00212 00213 /** \brief Specify the member function pointer 00214 */ 00215 multi_funct_mfptr_param(tclass *tp, double (tclass::*fp) 00216 (size_t nv, const vec_t &x, param_t &), 00217 param_t &pa) { 00218 tptr=tp; 00219 fptr=fp; 00220 pp=&pa; 00221 } 00222 00223 virtual ~multi_funct_mfptr_param() {} 00224 00225 /** \brief Compute a function \c y of \c nv variables stored in \c x 00226 with parameter \c pa. 00227 */ 00228 virtual double operator()(size_t nv, const vec_t &x) { 00229 return (*tptr.*fptr)(nv,x,*pp); 00230 } 00231 00232 #ifndef DOXYGEN_INTERNAL 00233 00234 protected: 00235 00236 /// Store the function pointer 00237 double (tclass::*fptr)(size_t nv, const vec_t &x, param_t &); 00238 00239 /// Parameter 00240 param_t *pp; 00241 00242 /// Store a pointer to the class instance 00243 tclass *tptr; 00244 00245 #ifndef DOXYGENP 00246 #endif 00247 00248 private: 00249 00250 multi_funct_mfptr_param(const multi_funct_mfptr_param &); 00251 multi_funct_mfptr_param& operator=(const multi_funct_mfptr_param&); 00252 00253 #endif 00254 00255 }; 00256 00257 /** \brief Const member function pointer to a multi-dimensional function 00258 */ 00259 template<class tclass, class vec_t=ovector_base> 00260 class multi_funct_cmfptr : public multi_funct<vec_t> { 00261 00262 public: 00263 00264 /** \brief Specify the member function pointer 00265 */ 00266 multi_funct_cmfptr(tclass *tp, double (tclass::*fp) 00267 (size_t nv, const vec_t &x) const) { 00268 00269 tptr=tp; 00270 fptr=fp; 00271 } 00272 00273 virtual ~multi_funct_cmfptr() {} 00274 00275 /** \brief Compute a function \c y of \c nv variables stored in \c x 00276 with parameter \c pa. 00277 */ 00278 virtual double operator()(size_t nv, const vec_t &x) { 00279 return (*tptr.*fptr)(nv,x); 00280 } 00281 00282 #ifndef DOXYGEN_INTERNAL 00283 00284 protected: 00285 00286 /// Store the function pointer 00287 double (tclass::*fptr)(size_t nv, const vec_t &x) const; 00288 00289 /// Store a pointer to the class instance 00290 tclass *tptr; 00291 00292 #ifndef DOXYGENP 00293 #endif 00294 00295 private: 00296 00297 multi_funct_cmfptr(const multi_funct_cmfptr &); 00298 multi_funct_cmfptr& operator=(const multi_funct_cmfptr&); 00299 00300 #endif 00301 00302 }; 00303 00304 #ifndef DOXYGENP 00305 } 00306 #endif 00307 00308 #endif
Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).