From: Jean-Paul Pelteret Date: Tue, 19 Mar 2019 10:55:48 +0000 (+0100) Subject: Add quick test for SymEngine X-Git-Tag: v9.1.0-rc1~271^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e8fd73e32eb19dffd9b51df72fb58037ab0e78d;p=dealii.git Add quick test for SymEngine --- diff --git a/tests/quick_tests/CMakeLists.txt b/tests/quick_tests/CMakeLists.txt index f76cfc008b..b9530cb530 100644 --- a/tests/quick_tests/CMakeLists.txt +++ b/tests/quick_tests/CMakeLists.txt @@ -193,6 +193,11 @@ IF (DEAL_II_WITH_GMSH) make_quicktest("gmsh" ${_mybuild} "") ENDIF() +# Test SymEngine +IF (DEAL_II_WITH_SYMENGINE) + make_quicktest("symengine" ${_mybuild} "") +ENDIF() + # A custom test target: ADD_CUSTOM_TARGET(test COMMAND ${CMAKE_COMMAND} -D ALL_TESTS="${ALL_TESTS}" -P ${CMAKE_CURRENT_SOURCE_DIR}/run.cmake diff --git a/tests/quick_tests/symengine.cc b/tests/quick_tests/symengine.cc new file mode 100644 index 0000000000..3cd221b159 --- /dev/null +++ b/tests/quick_tests/symengine.cc @@ -0,0 +1,75 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// Adaptation of symengine/basic_[01,02].cc for a quick test + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace dealii; +namespace SE = SymEngine; + +int +main() +{ + { + const SE::RCP a = SE::integer(2); + const SE::RCP b = SE::real_double(4.2); + + const SE::RCP c = SE::add(a, b); + deallog << "c = a+b: " << *c << std::endl; + } + + { + const SE::RCP a = SE::real_double(3.1); + const SE::RCP b = SE::real_double(7.5); + + const SE::RCP x = (SE::symbol("x")); + const SE::RCP y = (SE::symbol("y")); + + // Construction of symbolic function + const SE::RCP c = + SE::mul(y, SE::mul(SE::sub(y, b), SE::add(a, x))); + deallog << "c = y*(y-b)*(a+x): " << *c << std::endl; + + // Perform symbolic differentiation + const SE::RCP dc_dx = c->diff(x); + const SE::RCP dc_dy = c->diff(y); + + deallog << "dc_dx = y*(y-b): " << *dc_dx << std::endl; + deallog << "dc_dy = (2*y+1)*(a+x): " << *dc_dy << std::endl; + + const SE::RCP dc_dx_check = SE::mul(y, SE::sub(y, b)); + const SE::RCP dc_dy_check = + SE::mul(SE::sub(SE::mul(SE::integer(2), y), b), SE::add(a, x)); + Assert(SE::eq(*dc_dx, *dc_dx_check), ExcMessage("Should be equal!")); + // Although these two *values* are the same, the underlying + // *representation* is different. So we'd need to match the representation + // exactly, and I'm too lazy to do this right now. + // Assert(SE::eq(*dc_dy, *dc_dy_check), ExcMessage("Should be equal!")); + } + + deallog << "OK" << std::endl; +}