From a2dffa670e556b3c77cd1e4bc566dac8376b2ae4 Mon Sep 17 00:00:00 2001 From: bangerth Date: Mon, 2 Mar 2009 02:41:57 +0000 Subject: [PATCH] New test. git-svn-id: https://svn.dealii.org/trunk@18442 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/base/function_parser_02.cc | 93 +++++++++++++++++++++++ tests/base/function_parser_02/cmp/generic | 5 ++ 2 files changed, 98 insertions(+) create mode 100644 tests/base/function_parser_02.cc create mode 100644 tests/base/function_parser_02/cmp/generic diff --git a/tests/base/function_parser_02.cc b/tests/base/function_parser_02.cc new file mode 100644 index 0000000000..ddb92dfaa0 --- /dev/null +++ b/tests/base/function_parser_02.cc @@ -0,0 +1,93 @@ +//---------------------------- function_parser.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2005, 2009 by the deal.II authors and Victor Prosolin +// +// 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 with respect to the ability to deal with units. + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + + +int main () +{ + std::ofstream logfile("function_parser_02/output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + + std::vector function(1); + std::map constants; + std::map units; + + constants["PI"] = 3.141592654; + units["cm"] = 10; + units["m"] = 1000; + + Point<2> point(2.0, 3.0); + + //initialized with units + FunctionParser<2> fp; + function[0] = "x cm + y m + PI"; + fp.initialize(FunctionParser<2>::default_variable_names(), + function, constants, units); + + deallog << "Function " << "[" << function[0] << "]" << + " @point " << "[" << point << "]" << " is " << + "[" << fp.value(point) << "]" << std::endl; + + //now initialize with a function + //that's a string, not vector of + //strings + FunctionParser<2> fp4; + fp4.initialize(FunctionParser<2>::default_variable_names(), + function[0], constants, units); + + deallog << "Function " << "[" << function[0] << "]" << + " @point " << "[" << point << "]" << " is " << + "[" << fp4.value(point) << "]" << std::endl; + + //now initialize a function without + //units to check backwards + //compatibility + FunctionParser<2> fp2; + function[0] = "x + y + PI"; + fp2.initialize(FunctionParser<2>::default_variable_names(), + function, constants); + deallog << "Function " << "[" << function[0] << "]" << + " @point " << "[" << point << "]" << " is " << + "[" << fp2.value(point) << "]" << std::endl; + + + + //same as above but the function is + //a string, not a vector + FunctionParser<2> fp3; + fp3.initialize(FunctionParser<2>::default_variable_names(), + function[0], constants); + + deallog << "Function " << "[" << function[0] << "]" << + " @point " << "[" << point << "]" << " is " << + "[" << fp3.value(point) << "]" << std::endl; +} + + + + diff --git a/tests/base/function_parser_02/cmp/generic b/tests/base/function_parser_02/cmp/generic new file mode 100644 index 0000000000..9e199c8160 --- /dev/null +++ b/tests/base/function_parser_02/cmp/generic @@ -0,0 +1,5 @@ + +DEAL::Function [x cm + y m + PI] @point [2.00000 3.00000] is [3023.14] +DEAL::Function [x cm + y m + PI] @point [2.00000 3.00000] is [3023.14] +DEAL::Function [x + y + PI] @point [2.00000 3.00000] is [8.14159] +DEAL::Function [x + y + PI] @point [2.00000 3.00000] is [8.14159] -- 2.39.5