From b437658f82328076c713ffde9275f3714e53efa0 Mon Sep 17 00:00:00 2001 From: Luca Heltai 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 +++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tests/base/function_parser.cc 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]; + } +} + + + + -- 2.39.5