From 97631fd79cbf7b2f3aea52682a4794f2d741a5b7 Mon Sep 17 00:00:00 2001 From: luca Date: Thu, 31 Mar 2005 17:31:27 +0000 Subject: [PATCH] Function parser Test suite. git-svn-id: https://svn.dealii.org/trunk@10332 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/base/Makefile | 3 +- tests/base/function_parser.cc | 95 +++++++++++++++++++ .../base/function_parser.output | 9 ++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 tests/base/function_parser.cc create mode 100644 tests/results/i686-pc-linux-gnu+gcc3.4/base/function_parser.output diff --git a/tests/base/Makefile b/tests/base/Makefile index 7d677602d2..6dfa667f9d 100644 --- a/tests/base/Makefile +++ b/tests/base/Makefile @@ -36,7 +36,8 @@ tests_x = logtest \ auto_derivative_function \ anisotropic_* \ hierarchical \ - data_out_base + data_out_base \ + function_parser # from above list of regular expressions, generate the real set of # tests diff --git a/tests/base/function_parser.cc b/tests/base/function_parser.cc new file mode 100644 index 0000000000..2cbdc9c01e --- /dev/null +++ b/tests/base/function_parser.cc @@ -0,0 +1,95 @@ +//---------------------------- function_parser.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2005 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- function_parser.cc --------------------------- + + +// This program tests the functionality of the function parser +// wrapper. + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + + +int main () +{ + std::ofstream logfile("function_parser.output"); + deallog.attach(logfile); + deallog.depth_console(0); + + // Define some constants that will be used by the function parser + std::map constants; + constants["pi"] = M_PI; + + // Define the variables that will be used inside the expressions + std::string variables = "x,y"; + + // Define the expressions of the vector_valued function. + std::vector expressions; + expressions.push_back("sin(2*pi*x)"); + expressions.push_back("cos(2*pi*y*x)"); + expressions.push_back("if(x<.5,y,exp(x))"); + expressions.push_back("if(x<.5,y,exp(x)*exp(x*y))"); + + // Concatenate the declared expressions, to test the second way of + // initializing + std::string concatenated="cos(pi*y)"; + // Now test each possibility + for(unsigned int i=1; i<=expressions.size(); ++i) { + try { + { + FunctionParser<2> function(i); + function.initialize(variables, + expressions, + constants); + deallog << "Initialize Succeded with dim = 2, " + << i << " components, " + << expressions.size() << " expressions, " + << variables << " as variables." << std::endl; + } + } catch(...) { + deallog << "Initialize Failed with dim = 2, " + << i << " components, " + << expressions.size() << " expressions, " + << variables << " as variables." << std::endl; + } + + try { + { + FunctionParser<2> function_bis(i); + function_bis.initialize(variables, + concatenated, + constants); + deallog << "Initialize Succeded with dim = 2, " + << i << " components, " + << concatenated << " as function and " + << variables << " as variables." << std::endl; + } + } catch(...) { + deallog << "Initialize Failed with dim = 2, " + << i << " components, " + << concatenated << " as function and " + << variables << " as variables." << std::endl; + } + + concatenated += "; " + expressions[i-1]; + } +} + + + + diff --git a/tests/results/i686-pc-linux-gnu+gcc3.4/base/function_parser.output b/tests/results/i686-pc-linux-gnu+gcc3.4/base/function_parser.output new file mode 100644 index 0000000000..4ecbff8c22 --- /dev/null +++ b/tests/results/i686-pc-linux-gnu+gcc3.4/base/function_parser.output @@ -0,0 +1,9 @@ + +DEAL::Initialize Failed with dim = 2, 1 components, 4 expressions, x,y as variables. +DEAL::Initialize Succeded with dim = 2, 1 components, cos(pi*y) as function and x,y as variables. +DEAL::Initialize Failed with dim = 2, 2 components, 4 expressions, x,y as variables. +DEAL::Initialize Succeded with dim = 2, 2 components, cos(pi*y); sin(2*pi*x) as function and x,y as variables. +DEAL::Initialize Failed with dim = 2, 3 components, 4 expressions, x,y as variables. +DEAL::Initialize Succeded with dim = 2, 3 components, cos(pi*y); sin(2*pi*x); cos(2*pi*y*x) as function and x,y as variables. +DEAL::Initialize Succeded with dim = 2, 4 components, 4 expressions, x,y as variables. +DEAL::Initialize Succeded with dim = 2, 4 components, cos(pi*y); sin(2*pi*x); cos(2*pi*y*x); if(x<.5,y,exp(x)) as function and x,y as variables. -- 2.39.5