00001 #ifndef _FV_MATH_PARSER_H_ 00002 #define _FV_MATH_PARSER_H_ 00003 00004 /* dictionary */ 00005 //#include"fv_dictstr.h" 00006 #include<vector> 00007 #include<stack> 00008 #include<string> 00009 #include<cstdlib> 00010 00011 00012 namespace fvmathParser { 00013 extern double my_apr_elem_calc_3D_mod( 00014 /* returns: Jacobian determinant at a point, either for */ 00015 /* volume integration if Vec_norm==NULL, */ 00016 /* or for surface integration otherwise */ 00017 int Control, /* in: control parameter (what to compute): */ 00018 /* 1 - shape functions and values */ 00019 /* 2 - derivatives and jacobian */ 00020 /* >2 - computations on the (Control-2)-th */ 00021 /* element's face */ 00022 int Nreq, /* in: number of equations */ 00023 int *Pdeg_vec, /* in: element degree of polynomial */ 00024 int Base_type, /* in: type of basis functions: */ 00025 /* (APC_BASE_TENSOR_DG) - tensor product */ 00026 /* (APC_BASE_COMPLETE_DG) - complete polynomials */ 00027 double *Eta, /* in: local coordinates of the input point */ 00028 double *Node_coor, /* in: array of coordinates of vertices of element */ 00029 double *Sol_dofs, /* in: array of element' dofs */ 00030 double *Base_phi, /* out: basis functions */ 00031 double *Base_dphix, /* out: x-derivatives of basis functions */ 00032 double *Base_dphiy, /* out: y-derivatives of basis functions */ 00033 double *Base_dphiz, /* out: z-derivatives of basis functions */ 00034 double *Xcoor, /* out: global coordinates of the point*/ 00035 double *Sol, /* out: solution at the point */ 00036 double *Dsolx, /* out: derivatives of solution at the point */ 00037 double *Dsoly, /* out: derivatives of solution at the point */ 00038 double *Dsolz, /* out: derivatives of solution at the point */ 00039 double *Vec_nor /* out: outward unit vector normal to the face */ 00040 ); 00041 00042 //namespace fvmathParser { 00043 00044 // Types of math elements 00045 enum ElemType { 00046 Number, 00047 Vector, 00048 Plus, 00049 Minus, 00050 Multiply, 00051 Divide, 00052 Power, 00053 Open, 00054 Close 00055 }; 00056 00057 // MathElement definition 00058 struct MathElement { 00059 ElemType type; double value; 00060 }; 00061 00062 00063 class MathCalculator { 00064 public: 00065 00066 //zwraca gtowy element na podstawie tekstu 00067 //1 - rozpoznano poprawnie 00068 //<0 - blad 00069 static int GetElement(ElemType &type, double &value, std::string &str); 00070 00071 //zwraca wypelniony element 00072 //zapis elementu 00073 //maksymalny rozmiar wektora ktory nie moze byc pzekroczony podczas analizy, jesli wiekszy to blad 00074 static void GetElement(MathElement & el, std::string &str); 00075 00076 00077 00078 //ciag funkcji 00079 //rozmiar wektora n (0:n-1) 00080 00081 //static int Test(std::string func, int vectorSize); 00082 00083 //testowanie poprawnosci sk��dni 00084 //analizuje 00085 00086 //analizuje 00087 //zapisuje do vectora 00088 //wykonuje wyliczenia przechodzac po wektorze w kolejnosci wykoanywania dzia�a� 00089 //nie zmienia� pierwotnego wektora i generowanie nast�pnych na bazie poprzednich 00090 00091 //-1 - nieznany lb koncowy blad 00092 //-2 - blad analizy elementu z funkcji wejsiowej 00093 //-3 - blad zakresu podania wektora 00094 //<-10 - blad elementu analizy n-tego elementu (liczac od zera) -10-n 00095 //static int ONP(std::string func, int vectorSize); 00096 static int ONP(std::string func, unsigned int vectorSize, std::vector<MathElement> &wyjscie); 00097 00098 //podaje priorytet w zalezno�ci od rodzaju elementu 00099 //3 - ^ - POW 00100 //2 - *, / - Multiply, Divide 00101 //1 - +, - - PLUS, MIN 00102 //0 - (, ) - OPEN, CLOSE 00103 //-1 - - NUM, VEC 00104 static int GetPriority(ElemType ElType); 00105 00106 00107 //zwraca wyjscie onp i wierzcho�ek stosu jako string 00108 //static std::string GetString(std::vector<Element> &wyjscie); 00109 //static std::string GetString(std::vector<Element> &vElement); 00110 static std::string GetString(std::vector<MathElement> &vElement, std::stack<MathElement> &stos); 00111 00112 //zwraca wektor (wyjscie) onp jako string 00113 static std::string GetString(std::vector<MathElement> &vElement); 00114 00115 //(2+3)*5 00116 //2 3 + 5 * 00117 00118 //((2+7)/3+(14-3)*4)/2 00119 //2 7 + 3 / 14 3 - 4 * + 2 / 00120 00121 //obliczenie wyrazenia onp 00122 //wykorzystanie Calculate 00123 // 1 - wszytsko wporzadku 00124 // <0 - blad 00125 static int ONPCalculate(std::vector<MathElement> &vElement, std::vector<double> v, double &result); 00126 00127 //matematyczna operacja typu v 00128 //podawane sa dwa argumenty i znak opracji 00129 //jednym z argumentow lub oba moga by� wektorem 00130 //trzy elementy, wektor rozwiazania 00131 //dwa pierwsze sa wartoscia lub reprezentacja 00132 //trzeci znakiem 00133 //czwarty - wynik rozwiazania double 00134 //wektor rozwiazan - wektor typu double 00135 static void Calculate(MathElement &a, MathElement &b, MathElement &sign, MathElement &result, std::vector<double> v); 00136 00137 }; 00138 } // end Namespace 00139 00140 #endif /* _FV_MATH_PARSER_H_ 00141 */