Intg.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  $RCSfile: Intg.h,v $ --- $Date: 2006/07/19 13:21:43 $ --- $Revision: 1.3 $
00003  *****************************************************************************
00004  PREPROCESSOR DIRECTIVES
00005  *****************************************************************************/
00006 
00007  #ifndef CALC_INTG_H
00008  #define CALC_INTG_H
00009 
00010 /*****************************************************************************
00011  INCLUDE FILES
00012  *****************************************************************************/
00013 
00014  #include "Base.h"
00015 
00016 /*****************************************************************************
00017  NAMESPACE IDENTIFICATIONS
00018  *****************************************************************************/
00019 
00020  namespace calc {
00021 
00022 /*****************************************************************************
00023  IntgErr CLASS
00024  *****************************************************************************/
00033 
00034 
00045  class IntgErr:public Err {
00046 
00047  public:
00048 
00049  // Enumerations
00050 
00052     enum ERR_ENUM {
00053        INIT=0,    
00054        MEMORY,    
00055        LOOP,      
00056        ERR_CNT,   
00057     };
00058 
00059  // Constructors
00060 
00067     IntgErr(enum IntgErr::ERR_ENUM indErr):
00068     Err() {
00069        const char* const CLASS_NAME="Intg";
00070        const char* const ERR_STR[ERR_CNT]={
00071           "object initialization error",   // text for index INIT
00072           "memory allocation error",       // text for index MEMORY
00073           "maximum loop count exceeded",   // text for index LOOP
00074        };
00075        setError(indErr,CLASS_NAME,ERR_STR[indErr]);
00076     }
00077  };
00078 
00079 /*****************************************************************************
00080  Intg CLASS TEMPLATE
00081  *****************************************************************************/
00083 
00099  template <typename xType, typename yType>
00100  class Intg:public Base {
00101 
00102  public:
00103 
00104  // Member Enumerations
00105 
00107     enum CTYPE {
00108        TRAPEZOID=0,    
00109        SIMPSON,        
00110        ROMBERG,        
00111        CTYPE_CNT,      
00112     };
00113 
00115     enum VTYPE {
00116        LOOP_CURRENT=0,   
00117        LOOP_MAXIMUM,     
00118        VTYPE_CNT,        
00119     };
00120 
00121  // Member Functions
00122 
00123     yType  eval       (xType x1, xType x2) throw (IntgErr);
00124     bool   setEpsilon (xType dEps);
00125 
00126     virtual bool setCount (int nMaximum);
00127 
00136     yType evalIntegrand(xType x) const {return (*pFn)(x);}
00143     xType getError(void) const {return eps;}
00158     enum Intg<xType,yType>::CTYPE getMethod(void) const {return cTyp;}
00172     int getCount(enum Intg<xType,yType>::VTYPE vType) const
00173        {return ((!nogo)&&(vType>=0)&&(vType<VTYPE_CNT)?nCount[vType]:-1);}
00174 
00175     static const int DEF_LOOP_MAX;
00176 
00177  protected:
00178 
00179  // Constructors
00180 
00181     Intg(yType (&rFn)(xType), xType dEps);
00182     Intg(const Intg &ig);
00183 
00187     ~Intg(void) {}
00188 
00189  // Member Functions
00190 
00191     yType refine(int ninc);
00192 
00204     virtual yType intgMethod(void) throw (IntgErr)=0;
00205 
00206  // Data Members
00207 
00208     xType      eps;                
00209     int        nCount[VTYPE_CNT];  
00210     enum Intg<xType,yType>::CTYPE cTyp;  
00212  private:
00213 
00214  // Member Functions
00215 
00216     virtual void varInit(void);
00217 
00218  // Data Members
00219 
00220     yType (*pFn)(xType);              
00221     xType xBnd[Base::BOUND_CNT];      
00222     xType xDel;                       
00223     yType iintg;                      
00224  };
00225 
00226 /*****************************************************************************/
00227 
00229  template <typename xType, typename yType>
00230  const int calc::Intg<xType,yType>::DEF_LOOP_MAX=20;
00231 
00232 /*****************************************************************************
00233  Trap CLASS TEMPLATE
00234  *****************************************************************************/
00236 
00252  template <typename xType, typename yType>
00253  class Trap:public Intg<xType,yType> {
00254 
00255  // Inherited Member Functions & Data Members
00256 
00257     using Intg<xType,yType>::refine;
00258     using Intg<xType,yType>::eps;
00259     using Intg<xType,yType>::nCount;
00260     using Intg<xType,yType>::cTyp;
00261     using Intg<xType,yType>::TRAPEZOID;
00262     using Intg<xType,yType>::LOOP_CURRENT;
00263     using Intg<xType,yType>::LOOP_MAXIMUM;
00264 
00265  public:
00266 
00267  // Constructors
00268 
00285     Trap(yType (&rFn)(xType), xType dEps):
00286     Intg<xType,yType>(rFn,dEps) {cTyp=TRAPEZOID;}
00293     Trap(const Trap &tr):
00294     Intg<xType,yType>(tr) {}
00301     Trap(const Intg<xType,yType> &ig):
00302     Intg<xType,yType>(ig) {cTyp=TRAPEZOID;}
00306    ~Trap(void) {}
00307 
00308  private:
00309 
00310  // Member Functions
00311 
00312     virtual yType intgMethod(void) throw (IntgErr);
00313  };
00314 
00315 /*****************************************************************************
00316  Simp CLASS TEMPLATE
00317  *****************************************************************************/
00319 
00335  template <typename xType, typename yType>
00336  class Simp:public Intg<xType,yType> {
00337 
00338  // Inherited Member Functions & Data Members
00339 
00340     using Intg<xType,yType>::refine;
00341     using Intg<xType,yType>::eps;
00342     using Intg<xType,yType>::nCount;
00343     using Intg<xType,yType>::cTyp;
00344     using Intg<xType,yType>::SIMPSON;
00345     using Intg<xType,yType>::LOOP_CURRENT;
00346     using Intg<xType,yType>::LOOP_MAXIMUM;
00347 
00348  public:
00349 
00350  // Constructors
00351 
00368     Simp(yType (&rFn)(xType), xType dEps):
00369     Intg<xType,yType>(rFn,dEps) {cTyp=SIMPSON;}
00376     Simp(const Simp &si):
00377     Intg<xType,yType>(si) {}
00384     Simp(const Intg<xType,yType> &ig):
00385     Intg<xType,yType>(ig) {cTyp=SIMPSON;}
00389    ~Simp(void) {}
00390 
00391  private:
00392 
00393  // Member Functions
00394 
00395     virtual yType intgMethod(void) throw (IntgErr);
00396  };
00397 
00398 /*****************************************************************************
00399  Romb CLASS TEMPLATE
00400  *****************************************************************************/
00402 
00421  template <typename xType, typename yType>
00422  class Romb:public Intg<xType,yType> {
00423 
00424  // Inherited Member Functions & Data Members
00425 
00426     using Intg<xType,yType>::refine;
00427     using Intg<xType,yType>::nogo;
00428     using Intg<xType,yType>::eps;
00429     using Intg<xType,yType>::nCount;
00430     using Intg<xType,yType>::cTyp;
00431     using Intg<xType,yType>::ROMBERG;
00432     using Intg<xType,yType>::LOOP_CURRENT;
00433     using Intg<xType,yType>::LOOP_MAXIMUM;
00434     using Intg<xType,yType>::LO;
00435     using Intg<xType,yType>::HI;
00436     using Intg<xType,yType>::BOUND_CNT;
00437     using Intg<xType,yType>::memCopy;
00438 
00439  public:
00440 
00441  // Constructors
00442 
00443    ~Romb(void);
00444 
00461     Romb(yType (&rFn)(xType), xType dEps):
00462     Intg<xType,yType>(rFn,dEps)
00463        {varInit(); cTyp=ROMBERG; if(!nogo) nogo=varAlloc(nCount[LOOP_MAXIMUM]);}
00470     Romb(const Romb &ro):
00471     Intg<xType,yType>(ro)
00472        {varInit(); if(!nogo) nogo=varAlloc(nCount[LOOP_MAXIMUM]);} 
00479     Romb(const Intg<xType,yType> &ig):
00480     Intg<xType,yType>(ig)
00481        {varInit(); cTyp=ROMBERG; if(!nogo) nogo=varAlloc(nCount[LOOP_MAXIMUM]);} 
00482 
00483     static const int DEF_POL_CNT;
00484 
00485  // Member Functions
00486 
00487     virtual bool setCount(int nMaximum);
00488 
00489  private:
00490 
00491  // Member Functions
00492 
00493     virtual void varInit     (void);
00494     virtual yType intgMethod (void) throw (IntgErr);
00495 
00496     bool varAlloc (int nLoops);
00497     void evalPoly (const yType *arY, const double *arX, yType &yIntg, xType &yError);
00498 
00499  // Data Members
00500 
00501     double *romStep;               
00502     yType  *romIntg;               
00503     yType  *yDel[Base::BOUND_CNT]; 
00504  };}
00505 
00506 /*****************************************************************************/
00507 
00509  template <typename xType, typename yType>
00510  const int calc::Romb<xType,yType>::DEF_POL_CNT=5;
00511 
00512 /*****************************************************************************
00513  PREPROCESSOR DIRECTIVES
00514  *****************************************************************************/
00515 
00516  #endif
00517 
00518 /*****************************************************************************
00519  CLASS TEMPLATE SOURCE
00520  *****************************************************************************/
00521 
00522  #include "Intg.cpp"
00523  #include "Trap.cpp"
00524  #include "Simp.cpp"
00525  #include "Romb.cpp"
00526 
00527 /*****************************************************************************/

Generated on Wed Jul 19 09:23:35 2006 for CalcLib by  doxygen 1.4.7