Object-oriented Scientific Computing Library: Version 0.910
mm_funct.h
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_MM_FUNCT_H
00024 #define O2SCL_MM_FUNCT_H
00025 
00026 #include <string>
00027 #include <o2scl/ovector_tlate.h>
00028 
00029 #ifndef DOXYGENP
00030 namespace o2scl {
00031 #endif
00032 
00033   /** \brief Array of multi-dimensional functions [abstract base]
00034       
00035       This class generalizes \c nv functions of \c nv variables, i.e.
00036       \f$ y_j(x_0,x_1,...,x_{nv-1}) \f$ for \f$ 0\leq j \leq 
00037       nv-1 \f$ .
00038 
00039       This class is one of a large number of function object classes
00040       in \o2 designed to provide a mechanism for the user to 
00041       supply functions to solvers, minimizers, integrators, etc.
00042       See \ref funct_section for a general description.
00043   */
00044   template<class vec_t=ovector_base> class mm_funct {
00045     public:  
00046 
00047     mm_funct() {}
00048     
00049     virtual ~mm_funct() {}
00050     
00051     /** \brief Compute \c nv functions, \c y, of \c nv variables
00052         stored in \c x with parameter \c pa.
00053     */
00054     virtual int operator()(size_t nv, const vec_t &x, vec_t &y)=0;
00055     
00056 #ifndef DOXYGENP
00057 
00058     private:
00059 
00060     mm_funct(const mm_funct &);
00061     mm_funct& operator=(const mm_funct&);
00062 
00063 #endif
00064 
00065   };
00066   
00067   /** \brief Function pointer to array of multi-dimensional functions
00068    */
00069   template<class vec_t=ovector_base> class mm_funct_fptr : 
00070   public mm_funct<vec_t> {
00071     
00072     public:
00073     
00074     mm_funct_fptr() {}
00075 
00076     virtual ~mm_funct_fptr() {}
00077 
00078     /** \brief Specify the function pointer
00079      */
00080     mm_funct_fptr(int (*fp)(size_t nv, const vec_t &x, vec_t &y)) {
00081       fptr=fp;
00082     }
00083     
00084     /** \brief Specify the function pointer
00085      */
00086     int set_function(int (*fp)(size_t nv, const vec_t &x, vec_t &y)) {
00087       fptr=fp;
00088       return 0;
00089     }
00090     
00091     /** \brief Compute \c nv functions, \c y, of \c nv variables
00092         stored in \c x with parameter \c pa.
00093     */
00094     virtual int operator()(size_t nv, const vec_t &x, vec_t &y) {
00095       return fptr(nv,x,y);
00096     }
00097     
00098     
00099 #ifndef DOXYGEN_INTERNAL
00100     
00101     protected:
00102     
00103     /// The function pointer to the user-supplied function
00104     int (*fptr)(size_t nv, const vec_t &x, vec_t &y);
00105     
00106     private:
00107     
00108     mm_funct_fptr(const mm_funct_fptr &);
00109     mm_funct_fptr& operator=(const mm_funct_fptr&);
00110     
00111 #endif
00112     
00113   };
00114   
00115   /** \brief Function pointer to array of multi-dimensional functions
00116    */
00117   template<class param_t, class vec_t=ovector_base> 
00118     class mm_funct_fptr_param : public mm_funct<vec_t> {
00119     
00120     public:
00121     
00122     mm_funct_fptr_param() {}
00123 
00124     virtual ~mm_funct_fptr_param() {}
00125 
00126     /** \brief Specify the function pointer
00127      */
00128     mm_funct_fptr_param(int (*fp)
00129                         (size_t nv, const vec_t &x, vec_t &y, param_t &),
00130                         param_t &pa) {
00131       fptr=fp;
00132       pp=&pa;
00133     }
00134     
00135     /** \brief Specify the function pointer
00136      */
00137     int set_function(int (*fp)(size_t nv, const vec_t &x, vec_t &y, param_t &),
00138                      param_t &pa) {
00139       fptr=fp;
00140       pp=&pa;
00141       return 0;
00142     }
00143     
00144     /** \brief Compute \c nv functions, \c y, of \c nv variables
00145         stored in \c x with parameter \c pa.
00146     */
00147     virtual int operator()(size_t nv, const vec_t &x, vec_t &y) {
00148       return fptr(nv,x,y,*pp);
00149     }
00150     
00151     
00152 #ifndef DOXYGEN_INTERNAL
00153     
00154     protected:
00155     
00156     /// The function pointer to the user-supplied function
00157     int (*fptr)(size_t nv, const vec_t &x, vec_t &y, param_t &);
00158     
00159     /// The parameter
00160     param_t *pp;
00161 
00162     private:
00163     
00164     mm_funct_fptr_param(const mm_funct_fptr_param &);
00165     mm_funct_fptr_param& operator=(const mm_funct_fptr_param&);
00166     
00167 #endif
00168     
00169   };
00170   
00171   /** \brief Member function pointer to an array of 
00172       multi-dimensional functions
00173   */
00174   template<class tclass, class vec_t=ovector_base>
00175     class mm_funct_mfptr : public mm_funct<vec_t> {
00176     public:
00177     
00178     /** \brief Empty constructor
00179      */
00180     mm_funct_mfptr() {
00181     }
00182 
00183     /** \brief Specify the member function pointer
00184      */
00185     mm_funct_mfptr(tclass *tp, int (tclass::*fp)
00186                    (size_t nv, const vec_t &x, vec_t &y)) {
00187       tptr=tp;
00188       fptr=fp;
00189     }
00190 
00191     /** \brief Specify the member function pointer
00192      */
00193     int set_function(tclass *tp, int (tclass::*fp)
00194                      (size_t nv, const vec_t &x, vec_t &y)) 
00195     {
00196       tptr=tp;
00197       fptr=fp;
00198       return 0;
00199     }
00200     
00201     virtual ~mm_funct_mfptr() {};
00202     
00203     /** \brief Compute \c nv functions, \c y, of \c nv variables
00204         stored in \c x with parameter \c pa.
00205     */
00206     virtual int operator()(size_t nv, const vec_t &x, vec_t &y) {
00207       return (*tptr.*fptr)(nv,x,y);
00208     }
00209     
00210 #ifndef DOXYGEN_INTERNAL
00211     
00212     protected:
00213     
00214     /// The member function pointer
00215     int (tclass::*fptr)(size_t nv, const vec_t &x, vec_t &y);
00216 
00217     /// The class pointer
00218     tclass *tptr;
00219     
00220     private:
00221     
00222     mm_funct_mfptr(const mm_funct_mfptr &);
00223     mm_funct_mfptr& operator=(const mm_funct_mfptr&);
00224     
00225 #endif
00226     
00227   };
00228 
00229   /** \brief Member function pointer to an array of 
00230       multi-dimensional functions
00231   */
00232   template<class tclass, class param_t, class vec_t=ovector_base>
00233     class mm_funct_mfptr_param : public mm_funct<vec_t> {
00234     public:
00235     
00236     /** \brief Empty constructor
00237      */
00238     mm_funct_mfptr_param() {
00239     }
00240 
00241     /** \brief Specify the member function pointer
00242      */
00243     mm_funct_mfptr_param(tclass *tp, int (tclass::*fp)
00244                          (size_t nv, const vec_t &x, vec_t &y, param_t &), 
00245                          param_t &pa) {
00246       tptr=tp;
00247       fptr=fp;
00248       pp=&pa;
00249     }
00250 
00251     /** \brief Specify the member function pointer
00252      */
00253     int set_function(tclass *tp, int (tclass::*fp)
00254                      (size_t nv, const vec_t &x, vec_t &y, param_t &), 
00255                      param_t &pa) {
00256       tptr=tp;
00257       fptr=fp;
00258       pp=&pa;
00259       return 0;
00260     }
00261     
00262     virtual ~mm_funct_mfptr_param() {};
00263     
00264     /** \brief Compute \c nv functions, \c y, of \c nv variables
00265         stored in \c x with parameter \c pa.
00266     */
00267     virtual int operator()(size_t nv, const vec_t &x, vec_t &y) {
00268       return (*tptr.*fptr)(nv,x,y,*pp);
00269     }
00270     
00271 #ifndef DOXYGEN_INTERNAL
00272     
00273     protected:
00274     
00275     /// The member function pointer
00276     int (tclass::*fptr)(size_t nv, const vec_t &x, vec_t &y, param_t &pa);
00277 
00278     /// The class pointer
00279     tclass *tptr;
00280 
00281     /// Parameter
00282     param_t *pp;
00283     
00284     private:
00285     
00286     mm_funct_mfptr_param(const mm_funct_mfptr_param &);
00287     mm_funct_mfptr_param& operator=(const mm_funct_mfptr_param&);
00288     
00289 #endif
00290     
00291   };
00292 
00293   /** \brief Const member function pointer to an array of 
00294       multi-dimensional functions
00295   */
00296   template<class tclass, class vec_t=ovector_base>
00297     class mm_funct_cmfptr : public mm_funct<vec_t> {
00298 
00299     public:
00300     
00301     /** \brief Empty constructor
00302      */
00303     mm_funct_cmfptr() {
00304     }
00305 
00306     /** \brief Specify the member function pointer
00307      */
00308     mm_funct_cmfptr(tclass *tp, int (tclass::*fp)
00309                    (size_t nv, const vec_t &x, vec_t &y) const) {
00310       tptr=tp;
00311       fptr=fp;
00312     }
00313 
00314     /** \brief Specify the member function pointer
00315      */
00316     int set_function(tclass *tp, int (tclass::*fp)
00317                      (size_t nv, const vec_t &x, vec_t &y) const) 
00318     {
00319       tptr=tp;
00320       fptr=fp;
00321       return 0;
00322     }
00323     
00324     virtual ~mm_funct_cmfptr() {};
00325     
00326     /** \brief Compute \c nv functions, \c y, of \c nv variables
00327         stored in \c x with parameter \c pa.
00328     */
00329     virtual int operator()(size_t nv, const vec_t &x, vec_t &y) {
00330       return (*tptr.*fptr)(nv,x,y);
00331     }
00332     
00333 #ifndef DOXYGEN_INTERNAL
00334     
00335     protected:
00336     
00337     /// The member function pointer
00338     int (tclass::*fptr)(size_t nv, const vec_t &x, vec_t &y) const;
00339 
00340     /// The class pointer
00341     tclass *tptr;
00342     
00343     private:
00344     
00345     mm_funct_cmfptr(const mm_funct_cmfptr &);
00346     mm_funct_cmfptr& operator=(const mm_funct_cmfptr&);
00347     
00348 #endif
00349     
00350   };
00351 
00352 #ifndef DOXYGENP
00353 }
00354 #endif
00355 
00356 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.