Changeset 3098 in Sophya
- Timestamp:
- Nov 2, 2006, 3:32:37 PM (19 years ago)
- Location:
- trunk/SophyaLib/NTools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/classfunc.h
r2283 r3098 10 10 namespace SOPHYA { 11 11 12 // abstract class-function12 //! Abstract interface definition for functions (double f(double)) viewed as classes 13 13 class ClassFunc { 14 14 public: 15 virtual double operator()(double x) =0;15 virtual double operator()(double x) const =0; 16 16 }; 17 17 … … 22 22 public: 23 23 Function(double (*g)(double)):f(g){} 24 inline double operator()(double x){ return f(x);}24 virtual double operator()(double x) const { return f(x);} 25 25 }; 26 26 -
trunk/SophyaLib/NTools/integ.cc
r2808 r3098 17 17 18 18 On fournit une fonction double f(double) au constructeur, ou 19 une classe-fonction (ClassFuc) ou 19 20 une GeneralFunction avec des paramètres définis. 20 21 L'objet Integrator est convertible en valeur double qui est la valeur … … 28 29 //! Constructeur par défaut. L'objet n'est pas utilisable en l'état. 29 30 Integrator::Integrator() 30 : mFunc(NULL), m GFF(NULL), mGFFParm(NULL),31 : mFunc(NULL), mClFun(NULL), mGFF(NULL), mGFFParm(NULL), 31 32 mNStep(50), mDX(-1), mReqPrec(-1), 32 33 mXMin(0), mXMax(1) 34 {} 35 36 //! Constructeur à partir d'une classe-fonction, et des bornes d'intégration. 37 Integrator::Integrator(ClassFunc const & f, double xmin, double xmax) 38 : mFunc(NULL), mClFun(&f), mGFF(NULL), mGFFParm(NULL), 39 mNStep(50), mDX(-1), mReqPrec(-1), 40 mXMin(xmin), mXMax(xmax) 33 41 {} 34 42 35 43 //! Constructeur à partir de la fonction double->double, et des bornes d'intégration. 36 44 Integrator::Integrator(FUNC f, double xmin, double xmax) 37 : mFunc(f), m GFF(NULL), mGFFParm(NULL),45 : mFunc(f), mClFun(NULL), mGFF(NULL), mGFFParm(NULL), 38 46 mNStep(50), mDX(-1), mReqPrec(-1), 39 47 mXMin(xmin), mXMax(xmax) 40 48 {} 41 49 42 //! Constructeur à partir de la fonction double->double, et des bornes d'intégration. 43 Integrator::Integrator(fun f, double xmin, double xmax) 44 : mFunc(new Function(f)), mGFF(NULL), mGFFParm(NULL), 45 mNStep(50), mDX(-1), mReqPrec(-1), 46 mXMin(xmin), mXMax(xmax) 47 {} 48 50 51 /*! 52 Constructeur a partir d'une classe-fonction 53 sans spécifier les bornes. Elles sont positionnées 54 à [0,1], et on pourra les modifier plus tard. 55 */ 56 Integrator::Integrator(ClassFunc const & f) 57 : mFunc(NULL), mClFun(&f), mGFF(NULL), mGFFParm(NULL), 58 mNStep(50), mDX(-1), mReqPrec(-1), 59 mXMin(0), mXMax(1) 60 {} 49 61 50 62 /*! … … 53 65 */ 54 66 Integrator::Integrator(FUNC f) 55 : mFunc(f), mGFF(NULL), mGFFParm(NULL), 56 mNStep(50), mDX(-1), mReqPrec(-1), 57 mXMin(0), mXMax(1) 58 {} 59 60 /*! 61 Constructeur sans spécifier les bornes. Elles sont positionnées 62 à [0,1], et on pourra les modifier plus tard. 63 */ 64 Integrator::Integrator(fun f) 65 : mFunc(new Function(f)), mGFF(NULL), mGFFParm(NULL), 67 : mFunc(f), mClFun(NULL), mGFF(NULL), mGFFParm(NULL), 66 68 mNStep(50), mDX(-1), mReqPrec(-1), 67 69 mXMin(0), mXMax(1) … … 74 76 */ 75 77 Integrator::Integrator(GeneralFunction* gff, double* par, double xmin, double xmax) 76 : mFunc(NULL), m GFF(gff), mGFFParm(par),78 : mFunc(NULL), mClFun(NULL), mGFF(gff), mGFFParm(par), 77 79 mNStep(50), mDX(-1), mReqPrec(-1), 78 80 mXMin(xmin), mXMax(xmax) … … 88 90 */ 89 91 Integrator::Integrator(GeneralFunction* gff, double* par) 90 : mFunc(NULL), m GFF(gff), mGFFParm(par),92 : mFunc(NULL), mClFun(NULL), mGFF(gff), mGFFParm(par), 91 93 mNStep(50), mDX(-1), mReqPrec(-1), 92 94 mXMin(0), mXMax(1) … … 96 98 97 99 Integrator::~Integrator() 98 {if(mFunc) delete mFunc;} 100 { 101 } 102 99 103 100 104 /*! … … 121 125 { 122 126 mDX = d; 123 mNStep = mReqPrec = -1; 127 mNStep = -1; 128 mReqPrec = -1.; 124 129 StepsChanged(); 125 130 return *this; … … 154 159 //! Spécifie la fonction à intégrer, sous forme double f(double). 155 160 Integrator& 156 Integrator::Func(FUNC f) 157 { 158 mFunc = f; 161 Integrator::SetFunc(ClassFunc const & f) 162 { 163 mFunc = NULL; 164 mClFun = &f; 159 165 mGFFParm = NULL; 160 166 mFunc = NULL; … … 163 169 } 164 170 171 //! Spécifie la fonction à intégrer, sous forme double f(double). 172 Integrator& 173 Integrator::SetFunc(FUNC f) 174 { 175 mFunc = f; 176 mClFun = NULL; 177 mGFFParm = NULL; 178 mFunc = NULL; 179 FuncChanged(); 180 return *this; 181 } 182 165 183 /*! 166 184 \brief Spécifie la fonction à intégrer, sous forme de GeneralFunction … … 168 186 */ 169 187 Integrator& 170 Integrator:: Func(GeneralFunction* gff, double* par)188 Integrator::SetFunc(GeneralFunction* gff, double* par) 171 189 { 172 190 mGFF = gff; … … 181 199 Integrator::FVal(double x) const 182 200 { 183 DBASSERT( mFunc || (mGFF && mGFFParm) ); 184 return mFunc ? (*mFunc)(x) : mGFF->Value(&x, mGFFParm); 185 } 201 DBASSERT( mFunc || mClFun || (mGFF && mGFFParm) ); 202 if (mFunc) return mFunc(x); 203 else return mClFun ? (*mClFun)(x) : mGFF->Value(&x, mGFFParm); 204 } 186 205 187 206 double … … 197 216 cout<<"Integrator between "<<mXMin<<" and "<<mXMax 198 217 <<" in "<<mNStep<<" steps"<<endl; 199 if(lp>1) cout<<"mFunc="<<mFunc<<"m GFF="<<mGFF218 if(lp>1) cout<<"mFunc="<<mFunc<<"mClFun="<<mClFun<<"mGFF="<<mGFF 200 219 <<"mReqPrec="<<mReqPrec<<"mDX="<<mDX<<endl; 201 220 } … … 220 239 {} 221 240 241 TrpzInteg::TrpzInteg(ClassFunc const & f, double xmin, double xmax) 242 : Integrator(f, xmin, xmax) 243 {} 244 222 245 TrpzInteg::TrpzInteg(FUNC f, double xmin, double xmax) 223 246 : Integrator(f, xmin, xmax) 224 247 {} 225 248 226 TrpzInteg::TrpzInteg( fun f, double xmin, double xmax)227 : Integrator(f , xmin, xmax)249 TrpzInteg::TrpzInteg(ClassFunc const & f) 250 : Integrator(f) 228 251 {} 229 252 230 253 TrpzInteg::TrpzInteg(FUNC f) 231 : Integrator(f)232 {}233 234 TrpzInteg::TrpzInteg(fun f)235 254 : Integrator(f) 236 255 {} … … 301 320 302 321 322 GLInteg::GLInteg(ClassFunc const & f, double xmin, double xmax) 323 : Integrator(f, xmin, xmax), mXPos(NULL), mWeights(NULL), mOrder(8) 324 { 325 NStep(1); 326 } 327 303 328 GLInteg::GLInteg(FUNC f, double xmin, double xmax) 304 329 : Integrator(f, xmin, xmax), mXPos(NULL), mWeights(NULL), mOrder(8) … … 307 332 } 308 333 309 GLInteg::GLInteg( fun f, double xmin, double xmax)310 : Integrator(f , xmin, xmax), mXPos(NULL), mWeights(NULL), mOrder(8)334 GLInteg::GLInteg(ClassFunc const & f) 335 : Integrator(f), mXPos(NULL), mWeights(NULL), mOrder(8) 311 336 { 312 337 NStep(1); … … 314 339 315 340 GLInteg::GLInteg(FUNC f) 316 : Integrator(f), mXPos(NULL), mWeights(NULL), mOrder(8)317 {318 NStep(1);319 }320 321 GLInteg::GLInteg(fun f)322 341 : Integrator(f), mXPos(NULL), mWeights(NULL), mOrder(8) 323 342 { -
trunk/SophyaLib/NTools/integ.h
r2423 r3098 18 18 class Integrator { 19 19 public: 20 //typedef double(*FUNC)(double); 21 typedef ClassFunc *FUNC; 22 typedef double (*fun)(double); 20 typedef double(*FUNC)(double); 23 21 24 22 Integrator(); 23 Integrator(ClassFunc const &, double xmin, double xmax); 24 Integrator(ClassFunc const &); 25 25 26 Integrator(FUNC, double xmin, double xmax); 26 27 Integrator(FUNC); 27 28 Integrator(fun, double xmin, double xmax);29 Integrator(fun);30 28 31 29 Integrator(GeneralFunction*, double* par, double xmin, double xmax); … … 41 39 virtual Integrator& ReqPrec(double); // NOT YET ! 42 40 virtual Integrator& Limits(double xmin, double xmax); 43 virtual Integrator& Func(FUNC); 44 virtual Integrator& Func(GeneralFunction*, double* par); 41 virtual Integrator& SetFunc(ClassFunc const &); 42 virtual Integrator& SetFunc(FUNC); 43 virtual Integrator& SetFunc(GeneralFunction*, double* par); 45 44 46 45 virtual inline int GetNStep(void) {return mNStep;} … … 49 48 protected: 50 49 FUNC mFunc; 50 ClassFunc const* mClFun; 51 51 GeneralFunction* mGFF; 52 52 double* mGFFParm; … … 68 68 public: 69 69 TrpzInteg(); 70 TrpzInteg(ClassFunc const &, double xmin, double xmax); 71 TrpzInteg(ClassFunc const &); 70 72 TrpzInteg(FUNC, double xmin, double xmax); 71 73 TrpzInteg(FUNC); 72 TrpzInteg(fun, double xmin, double xmax);73 TrpzInteg(fun);74 74 TrpzInteg(GeneralFunction*, double* par, double xmin, double xmax); 75 75 TrpzInteg(GeneralFunction*, double* par); … … 83 83 public: 84 84 GLInteg(); 85 GLInteg(ClassFunc const &, double xmin, double xmax); 86 GLInteg(ClassFunc const &); 85 87 GLInteg(FUNC, double xmin, double xmax); 86 88 GLInteg(FUNC); 87 GLInteg(fun, double xmin, double xmax);88 GLInteg(fun);89 89 GLInteg(GeneralFunction*, double* par, double xmin, double xmax); 90 90 GLInteg(GeneralFunction*, double* par);
Note:
See TracChangeset
for help on using the changeset viewer.