From 34cf806d0b061b9506ad0e6bb20573678c636da7 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 11 Sep 2024 13:35:15 -0600 Subject: [PATCH] Add a new test for ParsedFunction. --- tests/bits/parsed_function_constants.cc | 54 +++++++++++++++++++ ...nction_constants.with_muparser=true.output | 5 ++ 2 files changed, 59 insertions(+) create mode 100644 tests/bits/parsed_function_constants.cc create mode 100644 tests/bits/parsed_function_constants.with_muparser=true.output diff --git a/tests/bits/parsed_function_constants.cc b/tests/bits/parsed_function_constants.cc new file mode 100644 index 0000000000..0be4abab95 --- /dev/null +++ b/tests/bits/parsed_function_constants.cc @@ -0,0 +1,54 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2007 - 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// This program tests the functionality of the function parser +// wrapper. + +#include +#include +#include + +#include + +#include "../tests.h" + +void +test() +{ + // A parameter handler + ParameterHandler prm; + + Functions::ParsedFunction<1>::declare_parameters(prm, 1); + prm.set("Function constants", "f=2"); + + prm.set("Function expression", "f*f+2*x"); + + Functions::ParsedFunction<1> function(1); + function.parse_parameters(prm); + + const double value = function.value(Point<1>(3.0)); + deallog << "Value at x=3: " << value << std::endl; + + prm.log_parameters(deallog); +} + +int +main() +{ + initlog(); + + test(); +} diff --git a/tests/bits/parsed_function_constants.with_muparser=true.output b/tests/bits/parsed_function_constants.with_muparser=true.output new file mode 100644 index 0000000000..11c21dfc2c --- /dev/null +++ b/tests/bits/parsed_function_constants.with_muparser=true.output @@ -0,0 +1,5 @@ + +DEAL::Value at x=3: 10.0000 +DEAL:parameters::Function constants: f=2 +DEAL:parameters::Function expression: f*f+2*x +DEAL:parameters::Variable names: x,t -- 2.39.5