44 #include <Epetra_ConfigDefs.h> 51 #include <lifev/core/LifeV.hpp> 52 #include <lifev/core/util/StringUtility.hpp> 53 #include <lifev/core/util/LifeChrono.hpp> 55 #include <lifev/core/util/Parser.hpp> 57 using namespace LifeV;
64 check (
const bool& expression )
79 std::cout <<
"MPI Initialization" << std::endl;
80 MPI_Init ( &argc, &argv );
83 std::string expression;
85 Real tolerance = 1e-15;
87 std::cout << std::setprecision (30) << std::endl;
92 std::cout <<
"READY TO TEST WITH 10+ EXPRESSIONS:" << std::endl << std::endl;
95 expression =
"-sqrt(4)+1*2";
96 parser.setString (expression);
98 std::cout <<
"TEST 0: " << check ( std::fabs (result - 0) > tolerance )
99 << expression <<
" = " << result << std::endl;
102 expression =
"(1+1)/(2+2)";
103 parser.setString (expression);
106 std::cout <<
"TEST 1: " << check ( std::abs (result - 0.5) > tolerance )
107 << expression <<
" = " << result << std::endl;
110 expression =
"1-2-3+4*5-6-7+8*9+1";
111 parser.setString (expression);
113 std::cout <<
"TEST 2: " << check ( std::abs (result - 76) > tolerance )
114 << expression <<
" = " << result << std::endl;;
117 expression =
"-(1+1)+(250+250+(-2))";
118 parser.setString (expression);
120 std::cout <<
"TEST 3: " << check ( std::abs (result - 496) > tolerance )
121 << expression <<
" = " << result << std::endl;
124 expression =
"(0.8 > 0.9)";
125 parser.setString (expression);
127 std::cout <<
"TEST 4: " << check ( std::abs (result - 0) > tolerance )
128 << expression <<
" = " << result << std::endl;
131 expression =
"(0.800000000000000 <= 0.8)";
132 parser.setString (expression);
134 std::cout <<
"TEST 5: " << check ( std::abs (result - 1) > tolerance )
135 << expression <<
" = " << result << std::endl;
138 expression =
"sin(3/4*pi) * -sin(3/4*pi) + -(cos(3/4*pi))^2";
139 parser.setString (expression);
141 std::cout <<
"TEST 6: " << check ( std::abs (result - -1) > tolerance )
142 << expression <<
" = " << result << std::endl;
145 expression =
"144^0.5 * sqrt(144)";
146 parser.setString (expression);
148 std::cout <<
"TEST 7: " << check ( std::abs (result - 144) > tolerance )
149 << expression <<
" = " << result << std::endl;
151 std::cout << std::endl <<
"TEST ENDS SUCCESFULLY" << std::endl;
155 expression =
"abc = -2^3^-3; abc";
156 parser.setString (expression);
158 std::cout <<
"TEST 8: " << check ( std::abs (result - -0.001953125) > tolerance )
159 << expression <<
" = " << result << std::endl;
163 expression =
"c=2; [0., c, c*c, c*c*c]";
164 parser.setString (expression);
165 std::cout <<
"TEST 9: " << check ( std::abs ( parser.evaluate (0) - 0 ) > tolerance
166 || std::abs ( parser.evaluate (1) - 2 ) > tolerance
167 || std::abs ( parser.evaluate (2) - 4 ) > tolerance
168 || std::abs ( parser.evaluate (3) - 8 ) > tolerance )
169 << expression <<
" = [" << parser.evaluate (0) <<
", " 170 << parser.evaluate (1) <<
", " 171 << parser.evaluate (2) <<
", " 172 << parser.evaluate (3) <<
"]" << std::endl;
176 expression =
"[0, 0, -(x^2)+y^2]";
177 parser.setString (expression);
178 parser.setVariable (
"x", 1);
179 parser.setVariable (
"y", 2);
180 std::cout <<
"TEST 10a: " << check ( std::abs ( parser.evaluate (0) - 0 ) > tolerance ||
181 std::abs ( parser.evaluate (1) - 0 ) > tolerance ||
182 std::abs ( parser.evaluate (2) - 3 ) > tolerance )
183 <<
"x = " << 1 <<
", y = " << 2 <<
" ==> " 184 << expression <<
" = [" << parser.evaluate (0) <<
", " 185 << parser.evaluate (1) <<
", " 186 << parser.evaluate (2) <<
"]" << std::endl;
188 parser.setString (expression);
189 parser.setVariable (
"x", 4);
190 parser.setVariable (
"y", 5);
191 std::cout <<
"TEST 10b: " << check ( std::abs ( parser.evaluate (0) - 0 ) > tolerance ||
192 std::abs ( parser.evaluate (1) - 0 ) > tolerance ||
193 std::abs ( parser.evaluate (2) - 9 ) > tolerance )
194 <<
"x = " << 4 <<
", y = " << 5 <<
" ==> " 195 << expression <<
" = [" << parser.evaluate (0) <<
", " 196 << parser.evaluate (1) <<
", " 197 << parser.evaluate (2) <<
"]" << std::endl;
229 std::cout << std::endl <<
"MPI Finalization" << std::endl;
std::string check(const bool &expression)
int32_type Int
Generic integer data.
void updateInverseJacobian(const UInt &iQuadPt)
Parser - A string parser for algebraic expressions.
int main(int argc, char **argv)
double Real
Generic real data.
const Real & evaluate(const ID &id=0)
Evaluate the expression.