Last change
on this file since 2683 was 2618, checked in by cmv, 21 years ago |
Tabulation de fonctions avec acces rapide cmv 13/09/04
|
File size:
1.5 KB
|
Rev | Line | |
---|
[2618] | 1 | #ifndef FUNCTAB_SEEN
|
---|
| 2 | #define VFUNCTAB_SEEN
|
---|
| 3 |
|
---|
| 4 | #include "machdefs.h"
|
---|
| 5 | #include "tvector.h"
|
---|
| 6 | #include "tarray.h"
|
---|
| 7 |
|
---|
| 8 | namespace SOPHYA {
|
---|
| 9 |
|
---|
| 10 | class FuncTab {
|
---|
| 11 | public:
|
---|
| 12 | FuncTab(double (*func)(double const),uint_4 nbin,r_8 xmin,r_8 xmax);
|
---|
| 13 | virtual ~FuncTab(void);
|
---|
| 14 |
|
---|
| 15 | //! Give values for the index [0] and [NTab+1]
|
---|
| 16 | void SetLimVal(void);
|
---|
| 17 | void SetLimVal(r_8 val0,r_8 valn);
|
---|
| 18 |
|
---|
| 19 | //! Interpolation type
|
---|
| 20 | void SetInterp(uint_2 typ=0);
|
---|
| 21 |
|
---|
| 22 | //! L'index de la valeur tabulee la plus proche de x (entre 1 et NTab)
|
---|
| 23 | inline uint_4 IndexNear(r_8 x)
|
---|
| 24 | {uint_4 i=(uint_4)((x-XMin)/Dx+0.5) +1; return (i>NTab)? NTab: i;}
|
---|
| 25 | //! L'index de la valeur tabulee juste inferieure a x (entre 1 et NTab)
|
---|
| 26 | inline uint_4 IndexLow(r_8 x)
|
---|
| 27 | {uint_4 i=(uint_4)((x-XMin)/Dx) +1; return (i>NTab)? NTab: i;}
|
---|
| 28 |
|
---|
| 29 | //! L'abscisse pour la valeur i de l'index
|
---|
| 30 | inline r_8 X(uint_4 i) {return XMin+(i-1)*Dx;}
|
---|
| 31 |
|
---|
| 32 | //! Le valeur tabulee la plus proche de x
|
---|
| 33 | inline r_8 Value(r_8 x) {return Tabul[IndexNear(x)];}
|
---|
| 34 |
|
---|
| 35 | //! L'interpolation lineaire dans le bin (attention no-protection for time saving)
|
---|
| 36 | inline r_8 ValueL(r_8 x)
|
---|
| 37 | {uint_4 i=IndexLow(x);
|
---|
| 38 | return Tabul[i]+PInterpL[i]*(x-X(i));}
|
---|
| 39 |
|
---|
| 40 | //! L'interpolation parabolique (attention no-protection for time saving)
|
---|
| 41 | inline r_8 ValueP(r_8 x)
|
---|
| 42 | {uint_4 i=IndexLow(x); x -= X(i);
|
---|
| 43 | return Tabul[i]+PInterpP[0][i]*x*x+PInterpP[1][i]*x;}
|
---|
| 44 |
|
---|
| 45 | protected:
|
---|
| 46 | double (*Func)(double const);
|
---|
| 47 | uint_4 NTab;
|
---|
| 48 | r_8 XMin,XMax,Dx;
|
---|
| 49 | r_8 *Tabul;
|
---|
| 50 | r_8 *PInterpL;
|
---|
| 51 | r_8 *PInterpP[2];
|
---|
| 52 | };
|
---|
| 53 |
|
---|
| 54 | } // Fin du namespace
|
---|
| 55 |
|
---|
| 56 | #endif
|
---|
Note:
See
TracBrowser
for help on using the repository browser.