From 6f88ca459fe7425edead02b3d0d8fd6c62d7f8c7 Mon Sep 17 00:00:00 2001 From: heister Date: Mon, 24 Feb 2014 16:20:24 +0000 Subject: [PATCH] update and add tests git-svn-id: https://svn.dealii.org/branches/branch_muparser@32536 0785d39b-7218-0410-832d-ea1e28bc413d --- ...function_parser.with_muparser=true.output} | 0 tests/base/function_parser_02.cc | 1 + ...ction_parser_02.with_muparser=true.output} | 0 ...ction_parser_03.with_muparser=true.output} | 0 ...th_muparser=true.with_threads=true.output} | 0 tests/base/function_parser_05.cc | 86 ++++++++++++++++++ ...nction_parser_05.with_muparser=true.output | 4 + tests/base/function_parser_06.cc | 91 +++++++++++++++++++ ...nction_parser_06.with_muparser=true.output | 37 ++++++++ 9 files changed, 219 insertions(+) rename tests/base/{function_parser.with_functionparser=true.output => function_parser.with_muparser=true.output} (100%) rename tests/base/{function_parser_02.with_functionparser=true.output => function_parser_02.with_muparser=true.output} (100%) rename tests/base/{function_parser_03.with_functionparser=true.output => function_parser_03.with_muparser=true.output} (100%) rename tests/base/{function_parser_04.with_functionparser=true.with_threads=true.output => function_parser_04.with_muparser=true.with_threads=true.output} (100%) create mode 100644 tests/base/function_parser_05.cc create mode 100644 tests/base/function_parser_05.with_muparser=true.output create mode 100644 tests/base/function_parser_06.cc create mode 100644 tests/base/function_parser_06.with_muparser=true.output diff --git a/tests/base/function_parser.with_functionparser=true.output b/tests/base/function_parser.with_muparser=true.output similarity index 100% rename from tests/base/function_parser.with_functionparser=true.output rename to tests/base/function_parser.with_muparser=true.output diff --git a/tests/base/function_parser_02.cc b/tests/base/function_parser_02.cc index ea1fea3535..ae6e088af8 100644 --- a/tests/base/function_parser_02.cc +++ b/tests/base/function_parser_02.cc @@ -38,6 +38,7 @@ int main () deallog.depth_console(0); deallog.threshold_double(1.e-10); + std::vector function(1); std::map constants; diff --git a/tests/base/function_parser_02.with_functionparser=true.output b/tests/base/function_parser_02.with_muparser=true.output similarity index 100% rename from tests/base/function_parser_02.with_functionparser=true.output rename to tests/base/function_parser_02.with_muparser=true.output diff --git a/tests/base/function_parser_03.with_functionparser=true.output b/tests/base/function_parser_03.with_muparser=true.output similarity index 100% rename from tests/base/function_parser_03.with_functionparser=true.output rename to tests/base/function_parser_03.with_muparser=true.output diff --git a/tests/base/function_parser_04.with_functionparser=true.with_threads=true.output b/tests/base/function_parser_04.with_muparser=true.with_threads=true.output similarity index 100% rename from tests/base/function_parser_04.with_functionparser=true.with_threads=true.output rename to tests/base/function_parser_04.with_muparser=true.with_threads=true.output diff --git a/tests/base/function_parser_05.cc b/tests/base/function_parser_05.cc new file mode 100644 index 0000000000..1241430e3b --- /dev/null +++ b/tests/base/function_parser_05.cc @@ -0,0 +1,86 @@ +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + +// simple function parser example (this is the basis for the example code in the documentation) + +void test1() +{ + // set up problem: + std::string variables = "x,y"; + std::string expression = "cos(x)+sqrt(y)"; + std::map constants; + + // FunctionParser with 2 variables and 1 component: + FunctionParser<2> fp(1); + fp.initialize(variables, + expression, + constants); + + // Point at which we want to evaluate the function + Point<2> point(0.0, 4.0); + + // evaluate the expression at 'point': + double result = fp.value(point); + + deallog << "Function '" << expression << "'" + << " @ " << point + << " is " << result << std::endl; +} + + +void test2() +{ + // Define some constants that will be used by the function parser + std::map constants; + constants["pi"] = numbers::PI; + + // Define the variables that will be used inside the expressions + std::string variables = "x,y,z"; + + // Define the expressions of the individual components of a + // vector valued function with two components: + std::vector expressions(2); + expressions[0] = "sin(2*pi*x)+sinh(pi*z)"; + expressions[1] = "sin(2*pi*y)*exp(x^2)"; + + // function parser with 3 variables and 2 components + FunctionParser<3> vector_function(2); + + // And populate it with the newly created objects. + vector_function.initialize(variables, + expressions, + constants); + + // Point at which we want to evaluate the function + Point<3> point(0.0, 1.0, 1.0); + + // This Vector will store the result + Vector result(2); + + // Fill 'result' by evaluating the function + vector_function.vector_value(point, result); + + // We can also only evaluate the 2nd component: + double c = vector_function.value(point, 1); + + // Output the evaluated function + deallog << "Function '" << expressions[0] << "," << expressions[1] << "'" + << " @ " << point + << " is " << result << std::endl; + } + + +int main() +{ + initlog(); + + test1(); + test2(); + +} diff --git a/tests/base/function_parser_05.with_muparser=true.output b/tests/base/function_parser_05.with_muparser=true.output new file mode 100644 index 0000000000..6f6db0c597 --- /dev/null +++ b/tests/base/function_parser_05.with_muparser=true.output @@ -0,0 +1,4 @@ + +DEAL::Function 'cos(x)+sqrt(y)' @ 0.00000 4.00000 is 3.00000 +DEAL::Function 'sin(2*pi*x)+sinh(pi*z),sin(2*pi*y)*exp(x^2)' @ 0.00000 1.00000 1.00000 is 11.5487 -2.44929e-16 +DEAL:: diff --git a/tests/base/function_parser_06.cc b/tests/base/function_parser_06.cc new file mode 100644 index 0000000000..5815253a85 --- /dev/null +++ b/tests/base/function_parser_06.cc @@ -0,0 +1,91 @@ +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + +// various checks (compatibility functionparser -> muparser) + +void eval(const std::string & exp, const Point<2> & p, double expected) +{ + std::string variables = "x,y"; + std::map constants; + + FunctionParser<2> fp(1); + fp.initialize(variables, + exp, + constants); + + double result = fp.value(p); + deallog << "'" << exp << "' @ " << p << " is " << result + << " ( expected " << expected << " )" << std::endl; + if (fabs(result-expected)>1e-10) + deallog << "ERROR!" << std::endl; + + + +} + + +void test() +{ + eval("if(x<0.0,0.0,if(x>1.0,1.0,x))",Point<2>(0.5,0.0), 0.5); + eval("if(x<0.0,0.0,if(x>1.0,1.0,x))",Point<2>(-2.0,0.0), 0.0); + eval("if(x<0.0,0.0,if(x>1.0,1.0,x))",Point<2>(42.0,0.0), 1.0); + + eval("if(x<1.0 | y<1.0,0,y)",Point<2>(0.5,1.5), 0.0); + eval("if(x<1.0 | y<1.0,0,y)",Point<2>(1.5,1.5), 1.5); + eval("if(x<1.0 | y<1.0,0,y)",Point<2>(1.5,0.5), 0.0); + eval("if(x<1.0 | y<1.0,0,y)",Point<2>(0.5,-2), 0.0); + + eval("if(x<1.0 & y<1.0,0,y)",Point<2>(1.5,-2.0), -2.0); + + double x,y; + x=1.0; + y=-3.1; + eval("atan2(x,y)",Point<2>(x,y), atan2(x,y)); + x=-1.0; + y=3.1; + eval("atan2(x,y)",Point<2>(x,y), atan2(x,y)); + + eval("if(x==1.0,0,y)",Point<2>(1.0,-2.0), 0.0); + eval("if(x==1.0,0,y)",Point<2>(1.1,-2.0), -2.0); + + eval("int(2.1)",Point<2>(1.1,-2.0), 2.0); + eval("int(-3.8)",Point<2>(1.1,-2.0), -4.0); + + eval("abs(-2.3)",Point<2>(0,0), 2.3); + eval("acos(0.5)",Point<2>(0,0), acos(0.5)); + eval("acosh(0.5)",Point<2>(0,0), acosh(0.5)); + eval("asin(0.5)",Point<2>(0,0), asin(0.5)); + eval("asinh(0.5)",Point<2>(0,0), asinh(0.5)); + eval("atan(0.5)",Point<2>(0,0), atan(0.5)); + eval("atanh(0.5)",Point<2>(0,0), atanh(0.5)); + eval("ceil(0.5)",Point<2>(0,0), ceil(0.5)); + eval("cos(0.5)",Point<2>(0,0), cos(0.5)); + eval("cosh(0.5)",Point<2>(0,0), cosh(0.5)); + eval("cot(0.5)",Point<2>(0,0), 1.0/tan(0.5)); + eval("csc(0.5)",Point<2>(0,0), 1.0/sin(0.5)); + eval("exp(0.5)",Point<2>(0,0), exp(0.5)); + eval("floor(0.5)",Point<2>(0,0), floor(0.5)); + eval("log(0.5)",Point<2>(0,0), log(0.5)); + eval("log10(0.5)",Point<2>(0,0), log(0.5)/log(10.0)); + eval("sec(0.5)",Point<2>(0,0), 1.0/cos(0.5)); + eval("sin(0.5)",Point<2>(0,0), sin(0.5)); + eval("sinh(0.5)",Point<2>(0,0), sinh(0.5)); + eval("sqrt(0.5)",Point<2>(0,0), sqrt(0.5)); + eval("tan(0.5)",Point<2>(0,0), tan(0.5)); + eval("tanh(0.5)",Point<2>(0,0), tanh(0.5)); + + +} + +int main() +{ + initlog(); + + test(); +} diff --git a/tests/base/function_parser_06.with_muparser=true.output b/tests/base/function_parser_06.with_muparser=true.output new file mode 100644 index 0000000000..c6d2e0089b --- /dev/null +++ b/tests/base/function_parser_06.with_muparser=true.output @@ -0,0 +1,37 @@ + +DEAL::'if(x<0.0,0.0,if(x>1.0,1.0,x))' @ 0.500000 0.00000 is 0.500000 ( expected 0.500000 ) +DEAL::'if(x<0.0,0.0,if(x>1.0,1.0,x))' @ -2.00000 0.00000 is 0.00000 ( expected 0.00000 ) +DEAL::'if(x<0.0,0.0,if(x>1.0,1.0,x))' @ 42.0000 0.00000 is 1.00000 ( expected 1.00000 ) +DEAL::'if(x<1.0 | y<1.0,0,y)' @ 0.500000 1.50000 is 0.00000 ( expected 0.00000 ) +DEAL::'if(x<1.0 | y<1.0,0,y)' @ 1.50000 1.50000 is 1.50000 ( expected 1.50000 ) +DEAL::'if(x<1.0 | y<1.0,0,y)' @ 1.50000 0.500000 is 0.00000 ( expected 0.00000 ) +DEAL::'if(x<1.0 | y<1.0,0,y)' @ 0.500000 -2.00000 is 0.00000 ( expected 0.00000 ) +DEAL::'if(x<1.0 & y<1.0,0,y)' @ 1.50000 -2.00000 is -2.00000 ( expected -2.00000 ) +DEAL::'atan2(x,y)' @ 1.00000 -3.10000 is 2.82955 ( expected 2.82955 ) +DEAL::'atan2(x,y)' @ -1.00000 3.10000 is -0.312042 ( expected -0.312042 ) +DEAL::'if(x==1.0,0,y)' @ 1.00000 -2.00000 is 0.00000 ( expected 0.00000 ) +DEAL::'if(x==1.0,0,y)' @ 1.10000 -2.00000 is -2.00000 ( expected -2.00000 ) +DEAL::'int(2.1)' @ 1.10000 -2.00000 is 2.00000 ( expected 2.00000 ) +DEAL::'int(-3.8)' @ 1.10000 -2.00000 is -4.00000 ( expected -4.00000 ) +DEAL::'abs(-2.3)' @ 0.00000 0.00000 is 2.30000 ( expected 2.30000 ) +DEAL::'acos(0.5)' @ 0.00000 0.00000 is 1.04720 ( expected 1.04720 ) +DEAL::'acosh(0.5)' @ 0.00000 0.00000 is -nan ( expected -nan ) +DEAL::'asin(0.5)' @ 0.00000 0.00000 is 0.523599 ( expected 0.523599 ) +DEAL::'asinh(0.5)' @ 0.00000 0.00000 is 0.481212 ( expected 0.481212 ) +DEAL::'atan(0.5)' @ 0.00000 0.00000 is 0.463648 ( expected 0.463648 ) +DEAL::'atanh(0.5)' @ 0.00000 0.00000 is 0.549306 ( expected 0.549306 ) +DEAL::'ceil(0.5)' @ 0.00000 0.00000 is 1.00000 ( expected 1.00000 ) +DEAL::'cos(0.5)' @ 0.00000 0.00000 is 0.877583 ( expected 0.877583 ) +DEAL::'cosh(0.5)' @ 0.00000 0.00000 is 1.12763 ( expected 1.12763 ) +DEAL::'cot(0.5)' @ 0.00000 0.00000 is 1.83049 ( expected 1.83049 ) +DEAL::'csc(0.5)' @ 0.00000 0.00000 is 2.08583 ( expected 2.08583 ) +DEAL::'exp(0.5)' @ 0.00000 0.00000 is 1.64872 ( expected 1.64872 ) +DEAL::'floor(0.5)' @ 0.00000 0.00000 is 0.00000 ( expected 0.00000 ) +DEAL::'log(0.5)' @ 0.00000 0.00000 is -0.693147 ( expected -0.693147 ) +DEAL::'log10(0.5)' @ 0.00000 0.00000 is -0.301030 ( expected -0.301030 ) +DEAL::'sec(0.5)' @ 0.00000 0.00000 is 1.13949 ( expected 1.13949 ) +DEAL::'sin(0.5)' @ 0.00000 0.00000 is 0.479426 ( expected 0.479426 ) +DEAL::'sinh(0.5)' @ 0.00000 0.00000 is 0.521095 ( expected 0.521095 ) +DEAL::'sqrt(0.5)' @ 0.00000 0.00000 is 0.707107 ( expected 0.707107 ) +DEAL::'tan(0.5)' @ 0.00000 0.00000 is 0.546302 ( expected 0.546302 ) +DEAL::'tanh(0.5)' @ 0.00000 0.00000 is 0.462117 ( expected 0.462117 ) -- 2.39.5