Changeset 728 for XIOS/trunk/src/parse_expr/operator_expr.hpp
- Timestamp:
- 10/09/15 16:42:23 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/parse_expr/operator_expr.hpp
r501 r728 8 8 #include "array_new.hpp" 9 9 10 using namespace std 10 using namespace std; 11 11 12 12 namespace xios … … 14 14 class COperatorExpr 15 15 { 16 public: 17 typedef double (*functionScalar)(double) 18 typedef double (*functionScalarScalar)(double, double) 19 typedef CArray<double,1> (*functionField)(const CArray<double,1>&) 20 typedef CArray<double,1> (*functionFieldField)(const CArray<double,1>&, const CArray<double,1>&) 21 typedef CArray<double,1> (*functionFieldScalar)(const CArray<double,1>&, double) 22 typedef CArray<double,1> (*functionScalarField)(double, const CArray<double,1>&) 23 16 public: 17 typedef double (*functionScalar)(double); 18 typedef double (*functionScalarScalar)(double, double); 19 typedef CArray<double,1> (*functionField)(const CArray<double,1>&); 20 typedef CArray<double,1> (*functionFieldField)(const CArray<double,1>&, const CArray<double,1>&); 21 typedef CArray<double,1> (*functionFieldScalar)(const CArray<double,1>&, double); 22 typedef CArray<double,1> (*functionScalarField)(double, const CArray<double,1>&); 23 24 24 COperatorExpr(void) 25 25 { 26 opScalar[string("neg")]=neg_s ; 27 opScalar[string("cos")]=cos_s ; 28 opScalar[string("sin")]=sin_s ; 29 opScalar[string("tan")]=tan_s ; 30 opScalar[string("exp")]=exp_s ; 31 opScalar[string("log")]=log_s ; 32 opScalar[string("log10")]=log10_s ; 33 opScalar[string("sqrt")]=sqrt_s ; 34 35 opScalarScalar[string("add")]=add_ss ; 36 opScalarScalar[string("minus")]=minus_ss ; 37 opScalarScalar[string("mult")]=mult_ss ; 38 opScalarScalar[string("div")]=div_ss ; 39 opScalarScalar[string("pow")]=pow_ss ; 40 41 opField[string("neg")]=neg_f ; 42 opField[string("cos")]=cos_f ; 43 opField[string("sin")]=sin_f ; 44 opField[string("tan")]=tan_f ; 45 opField[string("exp")]=exp_f ; 46 opField[string("log")]=log_f ; 47 opField[string("log10")]=log10_f ; 48 opField[string("sqrt")]=sqrt_f ; 49 50 opFieldField[string("add")]=add_ff ; 51 opFieldField[string("minus")]=minus_ff ; 52 opFieldField[string("mult")]=mult_ff ; 53 opFieldField[string("div")]=div_ff ; 54 opFieldField[string("pow")]=pow_ff ; 55 56 opFieldScalar[string("add")]=add_fs ; 57 opFieldScalar[string("minus")]=minus_fs ; 58 opFieldScalar[string("mult")]=mult_fs ; 59 opFieldScalar[string("div")]=div_fs ; 60 opFieldScalar[string("pow")]=pow_fs ; 61 62 opScalarField[string("add")]=add_sf ; 63 opScalarField[string("minus")]=minus_sf ; 64 opScalarField[string("mult")]=mult_sf ; 65 opScalarField[string("div")]=div_sf ; 66 } 26 opScalar[string("neg")] = neg_s; 27 opScalar[string("cos")] = cos_s; 28 opScalar[string("sin")] = sin_s; 29 opScalar[string("tan")] = tan_s; 30 opScalar[string("exp")] = exp_s; 31 opScalar[string("log")] = log_s; 32 opScalar[string("log10")] = log10_s; 33 opScalar[string("sqrt")] = sqrt_s; 34 35 opScalarScalar[string("add")] = add_ss; 36 opScalarScalar[string("minus")] = minus_ss; 37 opScalarScalar[string("mult")] = mult_ss; 38 opScalarScalar[string("div")] = div_ss; 39 opScalarScalar[string("pow")] = pow_ss; 40 opScalarScalar[string("eq")] = eq_ss; 41 opScalarScalar[string("lt")] = lt_ss; 42 opScalarScalar[string("gt")] = gt_ss; 43 opScalarScalar[string("le")] = le_ss; 44 opScalarScalar[string("ge")] = ge_ss; 45 46 opField[string("neg")] = neg_f; 47 opField[string("cos")] = cos_f; 48 opField[string("sin")] = sin_f; 49 opField[string("tan")] = tan_f; 50 opField[string("exp")] = exp_f; 51 opField[string("log")] = log_f; 52 opField[string("log10")] = log10_f; 53 opField[string("sqrt")] = sqrt_f; 54 55 opFieldField[string("add")] = add_ff; 56 opFieldField[string("minus")] = minus_ff; 57 opFieldField[string("mult")] = mult_ff; 58 opFieldField[string("div")] = div_ff; 59 opFieldField[string("pow")] = pow_ff; 60 opFieldField[string("eq")] = eq_ff; 61 opFieldField[string("lt")] = lt_ff; 62 opFieldField[string("gt")] = gt_ff; 63 opFieldField[string("le")] = le_ff; 64 opFieldField[string("ge")] = ge_ff; 65 66 opFieldScalar[string("add")] = add_fs; 67 opFieldScalar[string("minus")] = minus_fs; 68 opFieldScalar[string("mult")] = mult_fs; 69 opFieldScalar[string("div")] = div_fs; 70 opFieldScalar[string("pow")] = pow_fs; 71 opFieldScalar[string("eq")] = eq_fs; 72 opFieldScalar[string("lt")] = lt_fs; 73 opFieldScalar[string("gt")] = gt_fs; 74 opFieldScalar[string("le")] = le_fs; 75 opFieldScalar[string("ge")] = ge_fs; 76 77 opScalarField[string("add")] = add_sf; 78 opScalarField[string("minus")] = minus_sf; 79 opScalarField[string("mult")] = mult_sf; 80 opScalarField[string("div")] = div_sf; 81 opScalarField[string("eq")] = eq_sf; 82 opScalarField[string("lt")] = lt_sf; 83 opScalarField[string("gt")] = gt_sf; 84 opScalarField[string("le")] = le_sf; 85 opScalarField[string("ge")] = ge_sf; 86 } 67 87 68 88 functionScalar getOpScalar(const string& id) 69 89 { 70 map<string,double (*)(double)>::iterator it 71 it =opScalar.find(id);72 if (it ==opScalar.end()) ERROR("double (*)(double) COperatorExpr::getOpScalar(const string& id)",<<"unknown operator : "<<id)73 return it->second 74 } 75 90 map<string,double (*)(double)>::iterator it; 91 it = opScalar.find(id); 92 if (it == opScalar.end()) ERROR("functionScalar COperatorExpr::getOpScalar(const string& id)", << "unknown operator : " << id) 93 return it->second; 94 } 95 76 96 functionScalarScalar getOpScalarScalar(const string& id) 77 97 { 78 map<string,double (*)(double,double)>::iterator it 79 it =opScalarScalar.find(id);80 if (it ==opScalarScalar.end()) ERROR("double (*)(double) COperatorExpr::getOpScalarScalar(const string& id)",<<"unknown operator : "<<id)81 return it->second ;82 } 83 98 map<string,double (*)(double,double)>::iterator it; 99 it = opScalarScalar.find(id); 100 if (it == opScalarScalar.end()) ERROR("functionScalarScalar COperatorExpr::getOpScalarScalar(const string& id)", << "unknown operator : " << id) 101 return it->second; 102 } 103 84 104 functionField getOpField(const string& id) 85 105 { 86 map<string,functionField>::iterator it 87 it =opField.find(id);88 if (it ==opField.end()) ERROR("functionField COperatorExpr::getOpField(const string& id)",<<"unknown operator : "<<id)89 return it->second ;90 } 91 106 map<string,functionField>::iterator it; 107 it = opField.find(id); 108 if (it == opField.end()) ERROR("functionField COperatorExpr::getOpField(const string& id)", << "unknown operator : " << id) 109 return it->second; 110 } 111 92 112 functionFieldField getOpFieldField(const string& id) 93 113 { 94 map<string,functionFieldField>::iterator it 95 it =opFieldField.find(id);96 if (it ==opFieldField.end()) ERROR("dfunctionFieldField COperatorExpr::getOpFieldField(const string& id)",<<"unknown operator : "<<id)97 return it->second ;98 } 99 114 map<string,functionFieldField>::iterator it; 115 it = opFieldField.find(id); 116 if (it == opFieldField.end()) ERROR("dfunctionFieldField COperatorExpr::getOpFieldField(const string& id)", << "unknown operator : " << id) 117 return it->second; 118 } 119 100 120 functionFieldScalar getOpFieldScalar(const string& id) 101 121 { 102 map<string,functionFieldScalar>::iterator it 103 it =opFieldScalar.find(id);104 if (it ==opFieldScalar.end()) ERROR("functionFieldScalar COperatorExpr::getOpFieldScalar(const string& id)",<<"unknown operator : "<<id)105 return it->second ;106 } 107 122 map<string,functionFieldScalar>::iterator it; 123 it = opFieldScalar.find(id); 124 if (it == opFieldScalar.end()) ERROR("functionFieldScalar COperatorExpr::getOpFieldScalar(const string& id)", << "unknown operator : " << id) 125 return it->second; 126 } 127 108 128 functionScalarField getOpScalarField(const string& id) 109 129 { 110 map<string,functionScalarField>::iterator it ; 111 it=opScalarField.find(id) ; 112 if (it==opScalarField.end()) ERROR("functionScalarField COperatorExpr::getOpFieldField(const string& id)",<<"unknown operator : "<<id) 113 return it->second ; 114 } 115 116 map<string,functionScalar> opScalar ; 117 map<string,functionScalarScalar> opScalarScalar ; 118 map<string,functionField> opField ; 119 map<string,functionFieldField> opFieldField ; 120 map<string,functionFieldScalar> opFieldScalar ; 121 map<string,functionScalarField> opScalarField ; 122 123 static inline double neg_s(double x) {return -x;} 124 static inline double cos_s(double x) {return std::cos(x);} 125 static inline double sin_s(double x) {return std::sin(x);} 126 static inline double tan_s(double x) {return std::tan(x);} 127 static inline double exp_s(double x) {return std::exp(x);} 128 static inline double log_s(double x) {return std::log(x);} 129 static inline double log10_s(double x) {return std::log10(x);} 130 static inline double sqrt_s(double x) {return std::sqrt(x);} 131 132 static inline double add_ss(double x, double y) {return x+y;} 133 static inline double minus_ss(double x, double y) {return x-y;} 134 static inline double mult_ss(double x, double y) {return x*y;} 135 static inline double div_ss(double x, double y) {return x/y;} 136 static inline double pow_ss(double x, double y) {return std::pow(x,y);} 137 138 static inline CArray<double,1> neg_f(const CArray<double,1>& x) {return Array<double,1>(-x);} 139 static inline CArray<double,1> cos_f(const CArray<double,1>& x) {return Array<double,1>(cos(x));} 140 static inline CArray<double,1> sin_f(const CArray<double,1>& x) {return Array<double,1>(sin(x));} 141 static inline CArray<double,1> tan_f(const CArray<double,1>& x) {return Array<double,1>(tan(x));} 142 static inline CArray<double,1> exp_f(const CArray<double,1>& x) {return Array<double,1>(exp(x));} 143 static inline CArray<double,1> log_f(const CArray<double,1>& x) {return Array<double,1>(log(x));} 144 static inline CArray<double,1> log10_f(const CArray<double,1>& x) {return Array<double,1>(log10(x));} 145 static inline CArray<double,1> sqrt_f(const CArray<double,1>& x) {return Array<double,1>(sqrt(x));} 146 147 static inline CArray<double,1> add_ff(const CArray<double,1>& x, const CArray<double,1>& y) {return Array<double,1>(x+y);} 148 static inline CArray<double,1> minus_ff(const CArray<double,1>& x, const CArray<double,1>& y) {return Array<double,1>(x-y);} 149 static inline CArray<double,1> mult_ff(const CArray<double,1>& x, const CArray<double,1>& y) {return Array<double,1>(x*y);} 150 static inline CArray<double,1> div_ff(const CArray<double,1>& x, const CArray<double,1>& y) {return Array<double,1>(x/y);} 151 static inline CArray<double,1> pow_ff(const CArray<double,1>& x, const CArray<double,1>& y) {return Array<double,1>(pow(x,y));} 152 153 static inline CArray<double,1> add_fs(const CArray<double,1>& x, double y) {return Array<double,1>(x+y);} 154 static inline CArray<double,1> minus_fs(const CArray<double,1>& x, double y) {return Array<double,1>(x-y);} 155 static inline CArray<double,1> mult_fs(const CArray<double,1>& x, double y) {return Array<double,1>(x*y);} 156 static inline CArray<double,1> div_fs(const CArray<double,1>& x, double y) {return Array<double,1>(x/y);} 157 static inline CArray<double,1> pow_fs(const CArray<double,1>& x, double y) {return Array<double,1>(pow(x,y));} 158 159 static inline CArray<double,1> add_sf(double x, const CArray<double,1>& y) {return Array<double,1>(x+y);} 160 static inline CArray<double,1> minus_sf(double x, const CArray<double,1>& y) {return Array<double,1>(x-y);} 161 static inline CArray<double,1> mult_sf(double x, const CArray<double,1>& y) {return Array<double,1>(x*y);} 162 static inline CArray<double,1> div_sf(double x, const CArray<double,1>& y) {return Array<double,1>(x/y);} 163 164 165 } ; 166 167 extern COperatorExpr operatorExpr ; 168 130 map<string,functionScalarField>::iterator it; 131 it = opScalarField.find(id); 132 if (it == opScalarField.end()) ERROR("functionScalarField COperatorExpr::getOpFieldField(const string& id)", << "unknown operator : " << id) 133 return it->second; 134 } 135 136 map<string,functionScalar> opScalar; 137 map<string,functionScalarScalar> opScalarScalar; 138 map<string,functionField> opField; 139 map<string,functionFieldField> opFieldField; 140 map<string,functionFieldScalar> opFieldScalar; 141 map<string,functionScalarField> opScalarField; 142 143 static inline double neg_s(double x) { return -x; } 144 static inline double cos_s(double x) { return std::cos(x); } 145 static inline double sin_s(double x) { return std::sin(x); } 146 static inline double tan_s(double x) { return std::tan(x); } 147 static inline double exp_s(double x) { return std::exp(x); } 148 static inline double log_s(double x) { return std::log(x); } 149 static inline double log10_s(double x) { return std::log10(x); } 150 static inline double sqrt_s(double x) { return std::sqrt(x); } 151 152 static inline double add_ss(double x, double y) { return x + y; } 153 static inline double minus_ss(double x, double y) { return x - y; } 154 static inline double mult_ss(double x, double y) { return x * y; } 155 static inline double div_ss(double x, double y) { return x / y; } 156 static inline double pow_ss(double x, double y) { return std::pow(x,y); } 157 static inline double eq_ss(double x, double y) { return x == y; } 158 static inline double lt_ss(double x, double y) { return x < y; } 159 static inline double gt_ss(double x, double y) { return x > y; } 160 static inline double le_ss(double x, double y) { return x <= y; } 161 static inline double ge_ss(double x, double y) { return x >= y; } 162 163 static inline CArray<double,1> neg_f(const CArray<double,1>& x) { return Array<double,1>(-x); } 164 static inline CArray<double,1> cos_f(const CArray<double,1>& x) { return Array<double,1>(cos(x)); } 165 static inline CArray<double,1> sin_f(const CArray<double,1>& x) { return Array<double,1>(sin(x)); } 166 static inline CArray<double,1> tan_f(const CArray<double,1>& x) { return Array<double,1>(tan(x)); } 167 static inline CArray<double,1> exp_f(const CArray<double,1>& x) { return Array<double,1>(exp(x)); } 168 static inline CArray<double,1> log_f(const CArray<double,1>& x) { return Array<double,1>(log(x)); } 169 static inline CArray<double,1> log10_f(const CArray<double,1>& x) { return Array<double,1>(log10(x)); } 170 static inline CArray<double,1> sqrt_f(const CArray<double,1>& x) { return Array<double,1>(sqrt(x)); } 171 172 static inline CArray<double,1> add_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x + y); } 173 static inline CArray<double,1> minus_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x - y); } 174 static inline CArray<double,1> mult_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x * y); } 175 static inline CArray<double,1> div_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x / y); } 176 static inline CArray<double,1> pow_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(pow(x,y)); } 177 static inline CArray<double,1> eq_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x == y); } 178 static inline CArray<double,1> lt_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x < y); } 179 static inline CArray<double,1> gt_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x > y); } 180 static inline CArray<double,1> le_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x <= y); } 181 static inline CArray<double,1> ge_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x >= y); } 182 183 static inline CArray<double,1> add_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x + y); } 184 static inline CArray<double,1> minus_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x - y); } 185 static inline CArray<double,1> mult_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x * y); } 186 static inline CArray<double,1> div_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x / y); } 187 static inline CArray<double,1> pow_fs(const CArray<double,1>& x, double y) { return Array<double,1>(pow(x,y)); } 188 static inline CArray<double,1> eq_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x == y); } 189 static inline CArray<double,1> lt_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x < y); } 190 static inline CArray<double,1> gt_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x > y); } 191 static inline CArray<double,1> le_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x <= y); } 192 static inline CArray<double,1> ge_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x >= y); } 193 194 static inline CArray<double,1> add_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x + y); } 195 static inline CArray<double,1> minus_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x - y); } 196 static inline CArray<double,1> mult_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x * y); } 197 static inline CArray<double,1> div_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x / y); } 198 static inline CArray<double,1> eq_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x == y); } 199 static inline CArray<double,1> lt_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x < y); } 200 static inline CArray<double,1> gt_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x > y); } 201 static inline CArray<double,1> le_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x <= y); } 202 static inline CArray<double,1> ge_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x >= y); } 203 }; 204 205 extern COperatorExpr operatorExpr; 169 206 } 170 207
Note: See TracChangeset
for help on using the changeset viewer.