00001 #ifndef LUTFORBDLFUNCTION_H 00002 #define LUTFORBDLFUNCTION_H 1 00003 00004 /* 00005 LutForBdlFunction class 00006 Lookup table implementation to tabulate 00007 function of n double arguments 00008 00009 Idea: 00010 fun(x1,x2,x3,...) - function to tabulate 00011 00012 Initialize 00013 constructor - specify ranges and nr of bins for x1,x2,x3... (n-dim net) 00014 resetIndexVector - set start point (the lowest values x1,x2,x3,...) 00015 00016 Loop to fill table 00017 incrementIndexVector - increment over all (x1,x2,x3,...) n-dim points 00018 getVariableVector - to get (x1,x2,x3...) n-dim point 00019 fillTable - fill table with f(x1,x2,x3,...) values 00020 00021 Retrieve stored values 00022 getValueFromTable - get value stored in node closest to (x1,x2,x3,...) 00023 getInterpolatedValueFromTable - get value using interpolation 00024 00025 getInterpolatedValueFromTable is slower than getValueFromTable by a factor of 2 approximately 00026 but uses less memory 00027 00028 Example: 00029 00030 int nvar =3; 00031 int nbin[3] = {30, 30, 30}; 00032 double lv[3] = { 0., 0., 0.}; 00033 double rv[3] = { 5., 5., 5.}; 00034 LutForBdlFunction tabfun(nvar, nbin, lv, rv); 00035 00036 tabfun.resetIndexVector(); 00037 double var[3]; 00038 int iover = 0; 00039 while(!iover) { 00040 tabfun.getVariableVector(var); 00041 tabfun.fillTable( fun (var[0],var[1],var[2]) ); 00042 iover= tabfun.incrementIndexVector(); 00043 } 00044 00045 ... 00046 00047 Retrieve information 00048 00049 var[0]=1.5; 00050 var[1]=4.1; 00051 var[2]=2.9; 00052 tabfun.getValueFromTable(var); 00053 or 00054 tabfun.getInterpolatedValueFromTable(var); 00055 00056 00057 */ 00058 00059 00060 class LutForBdlFunction { 00061 00062 public: 00063 00064 LutForBdlFunction(int nVar, int* nBinVar, double* minVar, double* maxVar); 00065 00066 ~LutForBdlFunction(); 00067 00068 void resetIndexVector(); 00069 int incrementIndexVector(); 00070 void fillTable(double lutValue); 00071 double getVariable(int ivar); 00072 void getVariableVector(double* var); 00073 double getValueFromTable(double* var); 00074 double getInterpolatedValueFromTable(double* var); 00075 00076 00077 private: 00078 00079 void createVectors(); 00080 void deleteVectors(); 00081 void createTable(); 00082 void deleteTable(); 00083 void resetVariableVector(); 00084 int tableLocation(); 00085 void calculateVariableVector(); 00086 void calculateIndexVector(double* var); 00087 void calculateClosestIndexVector(double* var); 00088 00089 00090 00091 int m_nVar; 00092 int* m_nPointVar; 00093 double* m_minVar; 00094 double* m_maxVar; 00095 double* m_deltaVar; 00096 float* m_table; 00097 00098 int* m_indexVector; 00099 double* m_variableVector; 00100 00101 }; 00102 00103 #endif // LUTFORBDLFUNCTION_H 00104