From 5cb5bb58d9f0196e3ed24dbc0ecc14e6d9cb8ae4 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Sat, 22 Aug 2015 00:29:24 -0400 Subject: [PATCH 01/29] Setup build system to detect CPPUnit --- configure.ac | 16 ++++++++ m4/common/cppunit.m4 | 98 ++++++++++++++++++++++++++++++++++++++++++++ m4/config_summary.m4 | 10 +++++ 3 files changed, 124 insertions(+) create mode 100644 m4/common/cppunit.m4 diff --git a/configure.ac b/configure.ac index f4bcd5bb..b49ef85d 100644 --- a/configure.ac +++ b/configure.ac @@ -133,6 +133,22 @@ if (test x$HAVE_GSL = x1); then fi AM_CONDITIONAL(ANTIOCH_ENABLE_GSL, test x$HAVE_GSL = x1) +# ------------------------------------------------------------- +# cppunit C++ unit testing -- enabled by default +# ------------------------------------------------------------- +AC_ARG_ENABLE(cppunit, + AS_HELP_STRING([--disable-cppunit], + [Build without cppunit C++ unit testing support]), + [case "${enableval}" in + yes) enablecppunit=yes ;; + no) enablecppunit=no ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-cppunit) ;; + esac], + [enablecppunit=$enableoptional]) +if (test "$enablecppunit" = yes) ; then + AM_PATH_CPPUNIT([1.10.0],[enablecppunit=yes],[enablecppunit=no]) +fi +AM_CONDITIONAL(ANTIOCH_ENABLE_CPPUNIT, test x$enablecppunit = xyes) AC_SUBST(antioch_optional_INCLUDES) AC_SUBST(antioch_optional_test_INCLUDES) diff --git a/m4/common/cppunit.m4 b/m4/common/cppunit.m4 new file mode 100644 index 00000000..ef719e09 --- /dev/null +++ b/m4/common/cppunit.m4 @@ -0,0 +1,98 @@ +dnl +dnl AM_PATH_CPPUNIT(MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) +dnl +AC_DEFUN([AM_PATH_CPPUNIT], +[ + +AC_ARG_WITH(cppunit-prefix,[ --with-cppunit-prefix=PFX Prefix where CppUnit is installed (optional)], + cppunit_config_prefix="$withval", cppunit_config_prefix="") +AC_ARG_WITH(cppunit-exec-prefix,[ --with-cppunit-exec-prefix=PFX Exec prefix where CppUnit is installed (optional)], + cppunit_config_exec_prefix="$withval", cppunit_config_exec_prefix="") + + if test x$cppunit_config_exec_prefix != x ; then + cppunit_config_args="$cppunit_config_args --exec-prefix=$cppunit_config_exec_prefix" + if test x${CPPUNIT_CONFIG+set} != xset ; then + CPPUNIT_CONFIG=$cppunit_config_exec_prefix/bin/cppunit-config + fi + fi + if test x$cppunit_config_prefix != x ; then + cppunit_config_args="$cppunit_config_args --prefix=$cppunit_config_prefix" + if test x${CPPUNIT_CONFIG+set} != xset ; then + CPPUNIT_CONFIG=$cppunit_config_prefix/bin/cppunit-config + fi + fi + + AC_PATH_PROG(CPPUNIT_CONFIG, cppunit-config, no) + cppunit_version_min=$1 + + AC_MSG_CHECKING(for Cppunit - version >= $cppunit_version_min) + no_cppunit="" + if test "$CPPUNIT_CONFIG" = "no" ; then + AC_MSG_RESULT(no) + no_cppunit=yes + else + CPPUNIT_CPPFLAGS=`$CPPUNIT_CONFIG --cflags` + CPPUNIT_LIBS=`$CPPUNIT_CONFIG --libs` + CPPUNIT_VERSION=`$CPPUNIT_CONFIG --version` + CPPUNIT_PREFIX=`$CPPUNIT_CONFIG --prefix` + cppunit_version=`$CPPUNIT_CONFIG --version` + + cppunit_major_version=`echo $cppunit_version | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` + cppunit_minor_version=`echo $cppunit_version | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` + cppunit_micro_version=`echo $cppunit_version | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` + + cppunit_major_min=`echo $cppunit_version_min | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` + if test "x${cppunit_major_min}" = "x" ; then + cppunit_major_min=0 + fi + + cppunit_minor_min=`echo $cppunit_version_min | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` + if test "x${cppunit_minor_min}" = "x" ; then + cppunit_minor_min=0 + fi + + cppunit_micro_min=`echo $cppunit_version_min | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` + if test "x${cppunit_micro_min}" = "x" ; then + cppunit_micro_min=0 + fi + + cppunit_version_proper=`expr \ + $cppunit_major_version \> $cppunit_major_min \| \ + $cppunit_major_version \= $cppunit_major_min \& \ + $cppunit_minor_version \> $cppunit_minor_min \| \ + $cppunit_major_version \= $cppunit_major_min \& \ + $cppunit_minor_version \= $cppunit_minor_min \& \ + $cppunit_micro_version \>= $cppunit_micro_min ` + + if test "$cppunit_version_proper" = "1" ; then + AC_MSG_RESULT([$cppunit_major_version.$cppunit_minor_version.$cppunit_micro_version]) + else + AC_MSG_RESULT(no) + no_cppunit=yes + fi + fi + + if test "x$no_cppunit" = x ; then + ifelse([$2], , :, [$2]) + AC_SUBST(HAVE_CPPUNIT,[1]) + AC_DEFINE([HAVE_CPPUNIT], [1], [Enable CPPUnit Tests]) + else + CPPUNIT_CPPFLAGS="" + CPPUNIT_LIBS="" + ifelse([$3], , :, [$3]) + fi + + AC_SUBST(CPPUNIT_VERSION) + AC_SUBST(CPPUNIT_PREFIX) + AC_SUBST(CPPUNIT_CPPFLAGS) + AC_SUBST(CPPUNIT_LIBS) +]) + + + diff --git a/m4/config_summary.m4 b/m4/config_summary.m4 index 3bf90bac..e5d55a29 100644 --- a/m4/config_summary.m4 +++ b/m4/config_summary.m4 @@ -32,6 +32,16 @@ echo Revision id................... : $BUILD_VERSION echo echo Testing Options: echo ' 'Number of tuples............ : $n_tuples +if test "x$HAVE_CPPUNIT" = "x1"; then + echo ' 'CPPUnit..................... : yes + echo ' 'CPPUNIT_VERSION........... : $CPPUNIT_VERSION + echo ' 'CPPUNIT_CPPFLAGS.......... : $CPPUNIT_CPPFLAGS + echo ' 'CPPUNIT_LIBS.............. : $CPPUNIT_LIBS +else + echo ' 'CPPUnit..................... : no +fi +echo +echo Optional Libraries: if test "x$HAVE_EIGEN" = "x1"; then echo ' 'Eigen....................... : yes else From cf11ae3c277b16fb9ddc04f2c23bbca479515c90 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Sat, 22 Aug 2015 10:58:38 -0400 Subject: [PATCH 02/29] Pass CPPUnit flags to tests --- configure.ac | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/configure.ac b/configure.ac index b49ef85d..5e55b31a 100644 --- a/configure.ac +++ b/configure.ac @@ -148,6 +148,10 @@ AC_ARG_ENABLE(cppunit, if (test "$enablecppunit" = yes) ; then AM_PATH_CPPUNIT([1.10.0],[enablecppunit=yes],[enablecppunit=no]) fi +if (test x$HAVE_CPPUNIT = x1); then + antioch_optional_test_INCLUDES="$CPPUNIT_CPPFLAGS $antioch_optional_test_INCLUDES" + antioch_optional_test_LIBS="$CPPUNIT_LIBS $antioch_optional_test_LIBS" +fi AM_CONDITIONAL(ANTIOCH_ENABLE_CPPUNIT, test x$enablecppunit = xyes) AC_SUBST(antioch_optional_INCLUDES) From acc85ff659fb6a10ecd4fecb6c783e66bf158c90 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Sat, 22 Aug 2015 11:01:09 -0400 Subject: [PATCH 03/29] Setup first "standard" CPPUnit based test "standard" means no other optional libraries are needed. We'll setup separate programs for other tests that require optional libraries so we can see what's skipped and what's not from the `make check` report. This commit only has the (scalar) Arrhenius rate test. We'll start migrating some of the other tests now. --- test/Makefile.am | 10 + test/standard_unit/arrhenius_rate_test.C | 206 +++++++++++++++++++ test/standard_unit/reaction_rate_test_base.h | 95 +++++++++ test/standard_unit/standard_unit_tests.C | 52 +++++ 4 files changed, 363 insertions(+) create mode 100644 test/standard_unit/arrhenius_rate_test.C create mode 100644 test/standard_unit/reaction_rate_test_base.h create mode 100644 test/standard_unit/standard_unit_tests.C diff --git a/test/Makefile.am b/test/Makefile.am index f79c42e3..d6c3cb5c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,6 +1,7 @@ EXTRA_DIST = input_files check_PROGRAMS = +check_PROGRAMS += standard_unit_tests check_PROGRAMS += chem_mixture_unit check_PROGRAMS += chem_mixture_vec_unit check_PROGRAMS += nasa_evaluator_unit @@ -86,6 +87,7 @@ AM_CPPFLAGS += -I$(top_srcdir)/src/thermal_conduction/include AM_CPPFLAGS += -I$(top_srcdir)/src/transport/include AM_CPPFLAGS += -I$(top_srcdir)/src/utilities/include AM_CPPFLAGS += -I$(top_builddir)/src/utilities/include #antioch_version.h +AM_CPPFLAGS += -I$(top_srcdir)/test/standard_unit AM_CPPFLAGS += $(antioch_optional_test_INCLUDES) AM_LDFLAGS = $(antioch_optional_test_LDFLAGS) @@ -93,6 +95,13 @@ LIBS = $(antioch_optional_test_LIBS) LDADD = $(top_builddir)/src/libantioch.la +pkginclude_HEADERS = + +standard_unit_tests_SOURCES = standard_unit/arrhenius_rate_test.C \ + standard_unit/standard_unit_tests.C + +pkginclude_HEADERS += standard_unit/reaction_rate_test_base.h + # Sources for these tests chem_mixture_unit_SOURCES = chem_mixture_unit.C chem_mixture_vec_unit_SOURCES = chem_mixture_vec_unit.C @@ -170,6 +179,7 @@ stat_mech_thermo_unit_eigen_SOURCES = stat_mech_thermo_unit_eigen.C #Define tests to actually be run TESTS = +TESTS += standard_unit_tests TESTS += chem_mixture_unit TESTS += chem_mixture_vec_unit TESTS += nasa_evaluator_unit.sh diff --git a/test/standard_unit/arrhenius_rate_test.C b/test/standard_unit/arrhenius_rate_test.C new file mode 100644 index 00000000..872b173f --- /dev/null +++ b/test/standard_unit/arrhenius_rate_test.C @@ -0,0 +1,206 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +// C++ +#include + +// Antioch +#include "antioch/arrhenius_rate.h" +#include "antioch/physical_constants.h" +#include "antioch/units.h" + +// Base class +#include "reaction_rate_test_base.h" + +using namespace Antioch; + +template +class ArrheniusRateBaseTest : public ReactionRateBaseTest,Scalar> +{ +public: + void setUp() + { + Scalar Cf = 1.4L; + Scalar Ea = 298.0L; + Scalar R = 1.0L; // Ea in K + + this->reset_params(Cf,Ea,R); + _rate = new ArrheniusRate(Cf,Ea,R); + } + + void tearDown() + { + delete _rate; + } + + void test_standard() + { + const Scalar tol = std::numeric_limits::epsilon() * 100; + + this->test_rate( *_rate, tol ); + this->test_deriv( *_rate, tol ); + this->test_rate_and_deriv( *_rate, tol ); + } + + void test_reset_scalar_params() + { + Scalar Cf = 1e-7L; + Scalar Ea = 36000.L; + Scalar R = Constants::R_universal()*Units("cal").get_SI_factor(); + + this->reset_params( Cf, Ea, R ); + + _rate->set_Cf(Cf); + _rate->set_Ea(Ea); + _rate->set_rscale(R); + + const Scalar tol = std::numeric_limits::epsilon() * 100; + + this->test_rate( *_rate, tol ); + this->test_deriv( *_rate, tol ); + this->test_rate_and_deriv( *_rate, tol ); + } + + void test_reset_vector_params2() + { + Scalar Cf = 2.5e-7L; + Scalar Ea = 43000.L; //still in cal + + this->reset_params( Cf, Ea ); + + std::vector values(2); + values[0] = Cf; + values[1] = Ea; + _rate->reset_coefs(values); + + const Scalar tol = std::numeric_limits::epsilon() * 100; + + this->test_rate( *_rate, tol ); + this->test_deriv( *_rate, tol ); + this->test_rate_and_deriv( *_rate, tol ); + } + + void test_reset_vector_params3() + { + Scalar Cf = 2.1e-11L; + Scalar Ea = 100000.L; + Scalar R = Constants::R_universal(); + + this->reset_params( Cf, Ea, R ); + + std::vector values(3); + values[0] = Cf; + values[1] = Ea; + values[2] = R; + _rate->reset_coefs(values); + + const Scalar tol = std::numeric_limits::epsilon() * 100; + + this->test_rate( *_rate, tol ); + this->test_deriv( *_rate, tol ); + this->test_rate_and_deriv( *_rate, tol ); + } + +protected: + + Scalar _Cf, _Ea, _R; + + ArrheniusRate* _rate; + + void reset_params( Scalar Cf, Scalar Ea ) + { + _Cf = Cf; + _Ea = Ea; + } + + void reset_params( Scalar Cf, Scalar Ea, Scalar R ) + { + _Cf = Cf; + _Ea = Ea; + _R = R; + } + + virtual Scalar exact_rate( Scalar T ) + { + using std::exp; + return _Cf*exp(-_Ea/(_R*T)); + } + + virtual Scalar exact_deriv( Scalar T ) + { + using std::exp; + return _Ea/(_R*T*T)*_Cf *exp(-_Ea/(_R*T)); + } + +}; + +class ArrheniusRateFloatTest : public ArrheniusRateBaseTest +{ +public: + CPPUNIT_TEST_SUITE( ArrheniusRateFloatTest ); + + CPPUNIT_TEST( test_standard ); + CPPUNIT_TEST( test_reset_scalar_params ); + CPPUNIT_TEST( test_reset_vector_params2 ); + CPPUNIT_TEST( test_reset_vector_params3 ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class ArrheniusRateDoubleTest : public ArrheniusRateBaseTest +{ +public: + CPPUNIT_TEST_SUITE( ArrheniusRateDoubleTest ); + + CPPUNIT_TEST( test_standard ); + CPPUNIT_TEST( test_reset_scalar_params ); + CPPUNIT_TEST( test_reset_vector_params2 ); + CPPUNIT_TEST( test_reset_vector_params3 ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class ArrheniusRateLongDoubleTest : public ArrheniusRateBaseTest +{ +public: + CPPUNIT_TEST_SUITE( ArrheniusRateLongDoubleTest ); + + CPPUNIT_TEST( test_standard ); + CPPUNIT_TEST( test_reset_scalar_params ); + CPPUNIT_TEST( test_reset_vector_params2 ); + CPPUNIT_TEST( test_reset_vector_params3 ); + + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateFloatTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateDoubleTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateLongDoubleTest ); + +#endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/standard_unit/reaction_rate_test_base.h b/test/standard_unit/reaction_rate_test_base.h new file mode 100644 index 00000000..0311dc12 --- /dev/null +++ b/test/standard_unit/reaction_rate_test_base.h @@ -0,0 +1,95 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +#include +#include + +template +class ReactionRateBaseTest : public CppUnit::TestCase +{ +public: + void test_rate( const ReactionRate& reaction_rate, + Scalar tol ) + { + for(Scalar T = 300.1; T <= 2500.1; T += 10.) + { + Scalar rate = reaction_rate(T); + Scalar exact_rate = this->exact_rate(T); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( rate, + exact_rate, + tol ); + } + } + + void test_deriv( const ReactionRate& reaction_rate, + Scalar tol ) + { + for(Scalar T = 300.1; T <= 2500.1; T += 10.) + { + Scalar deriv = reaction_rate.derivative(T); + Scalar exact_deriv = this->exact_deriv(T); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv, + exact_deriv, + tol ); + } + } + + void test_rate_and_deriv( const ReactionRate& reaction_rate, + Scalar tol ) + { + for(Scalar T = 300.1; T <= 2500.1; T += 10.) + { + Scalar rate; + Scalar deriv; + + reaction_rate.rate_and_derivative(T,rate,deriv); + + Scalar exact_rate = this->exact_rate(T); + Scalar exact_deriv = this->exact_deriv(T); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( rate, + exact_rate, + tol ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv, + exact_deriv, + tol ); + } + } + +protected: + + virtual Scalar exact_rate( Scalar T ) =0; + virtual Scalar exact_deriv( Scalar T ) =0; + +}; + +#endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/standard_unit/standard_unit_tests.C b/test/standard_unit/standard_unit_tests.C new file mode 100644 index 00000000..93b5e2c0 --- /dev/null +++ b/test/standard_unit/standard_unit_tests.C @@ -0,0 +1,52 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT +#include +#include +#endif // ANTIOCH_HAVE_CPPUNIT + +int main() +{ +#ifdef ANTIOCH_HAVE_CPPUNIT + CppUnit::TextUi::TestRunner runner; + CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + runner.addTest( registry.makeTest() ); + + // If the tests all succeed, report success + if (runner.run()) + return 0; + + // If any test fails report failure + return 1; + +#else + // If we don't have CPPUnit, report we skipped + // 77 return code tells Automake we skipped this. + return 77; +#endif // ANTIOCH_HAVE_CPPUNIT +} From 514717850e5cde7e7491ad3b2ebbc481281b6b9e Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Sat, 22 Aug 2015 11:08:26 -0400 Subject: [PATCH 04/29] Remote now stale arrhenius_rate_unit --- test/Makefile.am | 3 - test/arrhenius_rate_unit.C | 155 ------------------------------------- 2 files changed, 158 deletions(-) delete mode 100644 test/arrhenius_rate_unit.C diff --git a/test/Makefile.am b/test/Makefile.am index d6c3cb5c..dc0078cd 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -15,7 +15,6 @@ check_PROGRAMS += hercourtessen_rate_vec_unit check_PROGRAMS += berthelot_rate_unit check_PROGRAMS += berthelot_rate_vec_unit check_PROGRAMS += arrhenius_rate_deriv -check_PROGRAMS += arrhenius_rate_unit check_PROGRAMS += arrhenius_rate_vec_unit check_PROGRAMS += kooij_rate_unit check_PROGRAMS += kooij_rate_vec_unit @@ -116,7 +115,6 @@ hercourtessen_rate_vec_unit_SOURCES = hercourtessen_rate_vec_unit.C berthelot_rate_unit_SOURCES = berthelot_rate_unit.C berthelot_rate_vec_unit_SOURCES = berthelot_rate_vec_unit.C arrhenius_rate_deriv_SOURCES = arrhenius_rate_deriv.C -arrhenius_rate_unit_SOURCES = arrhenius_rate_unit.C arrhenius_rate_vec_unit_SOURCES = arrhenius_rate_vec_unit.C berthelothercourtessen_rate_unit_SOURCES = berthelothercourtessen_rate_unit.C berthelothercourtessen_rate_vec_unit_SOURCES = berthelothercourtessen_rate_vec_unit.C @@ -193,7 +191,6 @@ TESTS += hercourtessen_rate_unit TESTS += berthelot_rate_vec_unit TESTS += berthelot_rate_vec_unit TESTS += arrhenius_rate_deriv -TESTS += arrhenius_rate_unit TESTS += arrhenius_rate_vec_unit TESTS += berthelothercourtessen_rate_unit TESTS += berthelothercourtessen_rate_vec_unit diff --git a/test/arrhenius_rate_unit.C b/test/arrhenius_rate_unit.C deleted file mode 100644 index 80792c25..00000000 --- a/test/arrhenius_rate_unit.C +++ /dev/null @@ -1,155 +0,0 @@ -//-----------------------------------------------------------------------bl- -//-------------------------------------------------------------------------- -// -// Antioch - A Gas Dynamics Thermochemistry Library -// -// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, -// Roy H. Stonger -// Copyright (C) 2013 The PECOS Development Team -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the Version 2.1 GNU Lesser General -// Public License as published by the Free Software Foundation. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc. 51 Franklin Street, Fifth Floor, -// Boston, MA 02110-1301 USA -// -//-----------------------------------------------------------------------el- -// -// $Id$ -// -//-------------------------------------------------------------------------- -//-------------------------------------------------------------------------- - -// C++ -#include -#include -// Antioch -#include "antioch/arrhenius_rate.h" -#include "antioch/physical_constants.h" -#include "antioch/units.h" - -template -int test_values(const Scalar & Cf, const Scalar & Ea, const Scalar & R, const Antioch::ArrheniusRate & arrhenius_rate) -{ - using std::abs; - using std::exp; - int return_flag = 0; - - const Scalar tol = std::numeric_limits::epsilon() * 100; - - for(Scalar T = 300.1; T <= 2500.1; T += 10.) - { - const Scalar rate_exact = Cf*exp(-Ea/(R*T)); - const Scalar derive_exact = Ea/(R*T*T) * Cf * exp(-Ea/(R*T)); - - Scalar rate1 = arrhenius_rate(T); - Scalar deriveRate1 = arrhenius_rate.derivative(T); - Scalar rate; - Scalar deriveRate; - - arrhenius_rate.rate_and_derivative(T,rate,deriveRate); - - if( abs( (rate1 - rate_exact)/rate_exact ) > tol ) - { - std::cout << std::scientific << std::setprecision(16) - << "Error: Mismatch in rate values." << std::endl - << "T = " << T << " K" << std::endl - << "rate(T) = " << rate1 << std::endl - << "rate_exact = " << rate_exact << std::endl; - - return_flag = 1; - } - if( abs( (rate - rate_exact)/rate_exact ) > tol ) - { - std::cout << std::scientific << std::setprecision(16) - << "Error: Mismatch in rate values." << std::endl - << "T = " << T << " K" << std::endl - << "rate(T) = " << rate << std::endl - << "rate_exact = " << rate_exact << std::endl; - - return_flag = 1; - } - if( abs( (deriveRate1 - derive_exact)/derive_exact ) > tol ) - { - std::cout << std::scientific << std::setprecision(16) - << "Error: Mismatch in rate derivative values." << std::endl - << "T = " << T << " K" << std::endl - << "drate_dT(T) = " << deriveRate1 << std::endl - << "derive_exact = " << derive_exact << std::endl; - - return_flag = 1; - } - if( abs( (deriveRate - derive_exact)/derive_exact ) > tol ) - { - std::cout << std::scientific << std::setprecision(16) - << "Error: Mismatch in rate derivative values." << std::endl - << "T = " << T << " K" << std::endl - << "drate_dT(T) = " << deriveRate << std::endl - << "derive_exact = " << derive_exact << std::endl; - - return_flag = 1; - } - if(return_flag)break; - } - - return return_flag; - -} - -template -int tester() -{ - Scalar Cf = 1.4L; - Scalar Ea = 298.0L; - Scalar R = 1.0L; // Ea in K - - Antioch::ArrheniusRate arrhenius_rate(Cf,Ea,R); - - int return_flag = test_values(Cf,Ea,R,arrhenius_rate); - - Cf = 1e-7L; - Ea = 36000.L; - R = Antioch::Constants::R_universal() * Antioch::Units("cal").get_SI_factor(); - arrhenius_rate.set_Cf(Cf); - arrhenius_rate.set_Ea(Ea); - arrhenius_rate.set_rscale(R); - - return_flag = test_values(Cf,Ea,R,arrhenius_rate) || return_flag; - - Cf = 2.5e-7L; - Ea = 43000.L; //still in cal - std::vector values(2); - values[0] = Cf; - values[1] = Ea; - arrhenius_rate.reset_coefs(values); - - return_flag = test_values(Cf,Ea,R,arrhenius_rate) || return_flag; - - Cf = 2.1e-11L; - Ea = 100000.L; - R = Antioch::Constants::R_universal(); - values.resize(3); - values[0] = Cf; - values[1] = Ea; - values[2] = R; - arrhenius_rate.reset_coefs(values); - - return_flag = test_values(Cf,Ea,R,arrhenius_rate) || return_flag; - - return return_flag; -} - -int main() -{ - return (tester() || - tester() || - tester()); -} From bba342cee5ee745df646b6a476cee45a2f674fb8 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Mon, 24 Aug 2015 09:08:35 -0400 Subject: [PATCH 05/29] Factor out "raw" Arrhenius parts This is so we can reuse them for the vector version of the test. --- test/Makefile.am | 1 + test/standard_unit/arrhenius_rate_test.C | 33 +++------ .../arrhenius_rate_test_helper.h | 69 +++++++++++++++++++ 3 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 test/standard_unit/arrhenius_rate_test_helper.h diff --git a/test/Makefile.am b/test/Makefile.am index dc0078cd..e3a237e6 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -100,6 +100,7 @@ standard_unit_tests_SOURCES = standard_unit/arrhenius_rate_test.C \ standard_unit/standard_unit_tests.C pkginclude_HEADERS += standard_unit/reaction_rate_test_base.h +pkginclude_HEADERS += standard_unit/arrhenius_rate_test_helper.h # Sources for these tests chem_mixture_unit_SOURCES = chem_mixture_unit.C diff --git a/test/standard_unit/arrhenius_rate_test.C b/test/standard_unit/arrhenius_rate_test.C index 872b173f..71e7ec90 100644 --- a/test/standard_unit/arrhenius_rate_test.C +++ b/test/standard_unit/arrhenius_rate_test.C @@ -31,17 +31,17 @@ #include // Antioch -#include "antioch/arrhenius_rate.h" #include "antioch/physical_constants.h" #include "antioch/units.h" // Base class -#include "reaction_rate_test_base.h" +#include "arrhenius_rate_test_helper.h" using namespace Antioch; template -class ArrheniusRateBaseTest : public ReactionRateBaseTest,Scalar> +class ArrheniusRateTest : public ArrheniusRateTestHelper, + public ReactionRateBaseTest,Scalar> { public: void setUp() @@ -129,38 +129,21 @@ public: protected: - Scalar _Cf, _Ea, _R; - ArrheniusRate* _rate; - void reset_params( Scalar Cf, Scalar Ea ) - { - _Cf = Cf; - _Ea = Ea; - } - - void reset_params( Scalar Cf, Scalar Ea, Scalar R ) - { - _Cf = Cf; - _Ea = Ea; - _R = R; - } - virtual Scalar exact_rate( Scalar T ) { - using std::exp; - return _Cf*exp(-_Ea/(_R*T)); + return this->value(T); } virtual Scalar exact_deriv( Scalar T ) { - using std::exp; - return _Ea/(_R*T*T)*_Cf *exp(-_Ea/(_R*T)); + return this->deriv(T); } }; -class ArrheniusRateFloatTest : public ArrheniusRateBaseTest +class ArrheniusRateFloatTest : public ArrheniusRateTest { public: CPPUNIT_TEST_SUITE( ArrheniusRateFloatTest ); @@ -173,7 +156,7 @@ public: CPPUNIT_TEST_SUITE_END(); }; -class ArrheniusRateDoubleTest : public ArrheniusRateBaseTest +class ArrheniusRateDoubleTest : public ArrheniusRateTest { public: CPPUNIT_TEST_SUITE( ArrheniusRateDoubleTest ); @@ -186,7 +169,7 @@ public: CPPUNIT_TEST_SUITE_END(); }; -class ArrheniusRateLongDoubleTest : public ArrheniusRateBaseTest +class ArrheniusRateLongDoubleTest : public ArrheniusRateTest { public: CPPUNIT_TEST_SUITE( ArrheniusRateLongDoubleTest ); diff --git a/test/standard_unit/arrhenius_rate_test_helper.h b/test/standard_unit/arrhenius_rate_test_helper.h new file mode 100644 index 00000000..2e9d1072 --- /dev/null +++ b/test/standard_unit/arrhenius_rate_test_helper.h @@ -0,0 +1,69 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +// Antioch +#include "antioch/arrhenius_rate.h" + +// Base class +#include "reaction_rate_test_base.h" + +template +class ArrheniusRateTestHelper +{ +protected: + Scalar _Cf, _Ea, _R; + + void reset_params( Scalar Cf, Scalar Ea ) + { + _Cf = Cf; + _Ea = Ea; + } + + void reset_params( Scalar Cf, Scalar Ea, Scalar R ) + { + _Cf = Cf; + _Ea = Ea; + _R = R; + } + + Scalar value( Scalar T ) + { + using std::exp; + return _Cf*exp(-_Ea/(_R*T)); + } + + Scalar deriv( Scalar T ) + { + using std::exp; + return _Ea/(_R*T*T)*_Cf *exp(-_Ea/(_R*T)); + } + +}; + +#endif // ANTIOCH_HAVE_CPPUNIT From 0d1df7357460625f87ebeed4a9490e9342fb8cb2 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Mon, 24 Aug 2015 09:20:48 -0400 Subject: [PATCH 06/29] Forgot header guards --- test/standard_unit/arrhenius_rate_test_helper.h | 5 +++++ test/standard_unit/reaction_rate_test_base.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/test/standard_unit/arrhenius_rate_test_helper.h b/test/standard_unit/arrhenius_rate_test_helper.h index 2e9d1072..14929b83 100644 --- a/test/standard_unit/arrhenius_rate_test_helper.h +++ b/test/standard_unit/arrhenius_rate_test_helper.h @@ -23,6 +23,9 @@ // //-----------------------------------------------------------------------el- +#ifndef ANTIOCH_ARRHENIUS_RATE_TEST_HELPER_H +#define ANTIOCH_ARRHENIUS_RATE_TEST_HELPER_H + #include "antioch_config.h" #ifdef ANTIOCH_HAVE_CPPUNIT @@ -67,3 +70,5 @@ class ArrheniusRateTestHelper }; #endif // ANTIOCH_HAVE_CPPUNIT + +#endif // ANTIOCH_ARRHENIUS_RATE_TEST_HELPER_H diff --git a/test/standard_unit/reaction_rate_test_base.h b/test/standard_unit/reaction_rate_test_base.h index 0311dc12..b80fb643 100644 --- a/test/standard_unit/reaction_rate_test_base.h +++ b/test/standard_unit/reaction_rate_test_base.h @@ -23,6 +23,9 @@ // //-----------------------------------------------------------------------el- +#ifndef ANTIOCH_REACTION_RATE_TEST_BASE_H +#define ANTIOCH_REACTION_RATE_TEST_BASE_H + #include "antioch_config.h" #ifdef ANTIOCH_HAVE_CPPUNIT @@ -93,3 +96,5 @@ class ReactionRateBaseTest : public CppUnit::TestCase }; #endif // ANTIOCH_HAVE_CPPUNIT + +#endif // ANTIOCH_REACTION_RATE_TEST_BASE_H From 522ad38a7f53eae429844ef42ce720b1991bb9e0 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Mon, 24 Aug 2015 11:26:30 -0400 Subject: [PATCH 07/29] Header cleanup --- test/standard_unit/arrhenius_rate_test.C | 1 + test/standard_unit/arrhenius_rate_test_helper.h | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/test/standard_unit/arrhenius_rate_test.C b/test/standard_unit/arrhenius_rate_test.C index 71e7ec90..d7902144 100644 --- a/test/standard_unit/arrhenius_rate_test.C +++ b/test/standard_unit/arrhenius_rate_test.C @@ -36,6 +36,7 @@ // Base class #include "arrhenius_rate_test_helper.h" +#include "reaction_rate_test_base.h" using namespace Antioch; diff --git a/test/standard_unit/arrhenius_rate_test_helper.h b/test/standard_unit/arrhenius_rate_test_helper.h index 14929b83..09d27c66 100644 --- a/test/standard_unit/arrhenius_rate_test_helper.h +++ b/test/standard_unit/arrhenius_rate_test_helper.h @@ -33,9 +33,6 @@ // Antioch #include "antioch/arrhenius_rate.h" -// Base class -#include "reaction_rate_test_base.h" - template class ArrheniusRateTestHelper { From 6ba8836465b6f2cd167075876259fef46626a6b6 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Mon, 24 Aug 2015 11:35:05 -0400 Subject: [PATCH 08/29] Setup reaction rate vector tests Only valarray so far. Idea will be to have separate programs for each of the optional libraries and drop those tests in there so we can see what we're skipping from `make check`. I've tried to set it up to adhere to DRY as much as possible. --- test/Makefile.am | 3 +- .../arrhenius_rate_vector_test.C | 102 +++++++++++++ .../arrhenius_rate_vector_test_base.h | 123 ++++++++++++++++ .../reaction_rate_vector_test_base.h | 139 ++++++++++++++++++ 4 files changed, 366 insertions(+), 1 deletion(-) create mode 100644 test/standard_unit/arrhenius_rate_vector_test.C create mode 100644 test/standard_unit/arrhenius_rate_vector_test_base.h create mode 100644 test/standard_unit/reaction_rate_vector_test_base.h diff --git a/test/Makefile.am b/test/Makefile.am index e3a237e6..43322285 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -96,7 +96,8 @@ LDADD = $(top_builddir)/src/libantioch.la pkginclude_HEADERS = -standard_unit_tests_SOURCES = standard_unit/arrhenius_rate_test.C \ +standard_unit_tests_SOURCES = standard_unit/arrhenius_rate_test.C \ + standard_unit/arrhenius_rate_vector_test.C \ standard_unit/standard_unit_tests.C pkginclude_HEADERS += standard_unit/reaction_rate_test_base.h diff --git a/test/standard_unit/arrhenius_rate_vector_test.C b/test/standard_unit/arrhenius_rate_vector_test.C new file mode 100644 index 00000000..d50df85f --- /dev/null +++ b/test/standard_unit/arrhenius_rate_vector_test.C @@ -0,0 +1,102 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +// C++ +#include + +// Antioch +#include "antioch/valarray_utils_decl.h" +#include "antioch/physical_constants.h" +#include "antioch/units.h" +#include "arrhenius_rate_vector_test_base.h" +#include "antioch/valarray_utils.h" + +template +class ArrheniusRateValarrayTest : public ArrheniusRateVectorTestBase > +{ +public: + + virtual void setUp() + { + this->init(); + this->_example = new std::valarray(2*ANTIOCH_N_TUPLES); + } + + virtual void tearDown() + { + this->clear(); + delete this->_example; + } + +}; + +class ArrheniusRateValarrayFloatTest : public ArrheniusRateValarrayTest +{ +public: + + CPPUNIT_TEST_SUITE( ArrheniusRateValarrayFloatTest ); + + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class ArrheniusRateValarrayDoubleTest : public ArrheniusRateValarrayTest +{ +public: + + CPPUNIT_TEST_SUITE( ArrheniusRateValarrayDoubleTest ); + + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class ArrheniusRateValarrayLongDoubleTest : public ArrheniusRateValarrayTest +{ +public: + + CPPUNIT_TEST_SUITE( ArrheniusRateValarrayLongDoubleTest ); + + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); + + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateValarrayFloatTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateValarrayDoubleTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateValarrayLongDoubleTest ); + +#endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/standard_unit/arrhenius_rate_vector_test_base.h b/test/standard_unit/arrhenius_rate_vector_test_base.h new file mode 100644 index 00000000..204eb196 --- /dev/null +++ b/test/standard_unit/arrhenius_rate_vector_test_base.h @@ -0,0 +1,123 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#ifndef ANTIOCH_ARRHENIUS_RATE_VECTOR_TEST_BASE_H +#define ANTIOCH_ARRHENIUS_RATE_VECTOR_TEST_BASE_H + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +// C++ +#include + +// Antioch +#include "antioch/physical_constants.h" +#include "antioch/units.h" + +// Base class +#include "arrhenius_rate_test_helper.h" +#include "reaction_rate_vector_test_base.h" + +template +class ArrheniusRateVectorTestBase : public ArrheniusRateTestHelper::type>, + public ReactionRateVectorBaseTest::type>,PairScalars> +{ +public: + virtual void init() + { + typedef typename Antioch::value_type::type Scalar; + + Scalar Cf = 1.4L; + Scalar Ea = 5.0L; + Scalar R = 1.0L; // Ea in K + + this->reset_params(Cf,Ea,R); + _rate = new Antioch::ArrheniusRate(Cf,Ea,R); + } + + virtual void clear() + { + delete _rate; + } + + void test_standard_rate() + { + typedef typename Antioch::value_type::type Scalar; + + const Scalar tol = std::numeric_limits::epsilon() * 100; + PairScalars T = this->setup_T(*(this->_example)); + this->test_rate( *_rate, T, tol ); + } + + void test_standard_deriv() + { + typedef typename Antioch::value_type::type Scalar; + + const Scalar tol = std::numeric_limits::epsilon() * 100; + PairScalars T = this->setup_T(*(this->_example)); + this->test_deriv( *_rate, T, tol ); + } + + void test_standard_rate_and_deriv() + { + typedef typename Antioch::value_type::type Scalar; + + const Scalar tol = std::numeric_limits::epsilon() * 100; + PairScalars T = this->setup_T(*(this->_example)); + this->test_rate_and_deriv( *_rate, T, tol ); + } + +protected: + + Antioch::ArrheniusRate::type>* _rate; + + virtual PairScalars exact_rate( PairScalars T ) + { + PairScalars e_rate = *(this->_example); + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + e_rate[2*tuple] = this->value(T[2*tuple]); + e_rate[2*tuple+1] = this->value(T[2*tuple+1]); + } + return e_rate; + } + + virtual PairScalars exact_deriv( PairScalars T ) + { + PairScalars e_deriv = *(this->_example); + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + e_deriv[2*tuple] = this->deriv(T[2*tuple]); + e_deriv[2*tuple+1] = this->deriv(T[2*tuple+1]); + } + return e_deriv; + } + +}; + +#endif // ANTIOCH_HAVE_CPPUNIT + +#endif // ANTIOCH_ARRHENIUS_RATE_VECTOR_TEST_BASE_H diff --git a/test/standard_unit/reaction_rate_vector_test_base.h b/test/standard_unit/reaction_rate_vector_test_base.h new file mode 100644 index 00000000..250202e3 --- /dev/null +++ b/test/standard_unit/reaction_rate_vector_test_base.h @@ -0,0 +1,139 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#ifndef ANTIOCH_REACTION_RATE_VECTOR_TEST_BASE_H +#define ANTIOCH_REACTION_RATE_VECTOR_TEST_BASE_H + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +#include +#include + +template +class ReactionRateVectorBaseTest : public CppUnit::TestCase +{ +public: + + void test_rate( const ReactionRate& reaction_rate, + const PairScalars& T, + typename Antioch::value_type::type /*Scalar*/ tol ) + { + const PairScalars rate = reaction_rate(T); + const PairScalars exact_rate = this->exact_rate(T); + + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple], + exact_rate[0], + tol ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple+1], + exact_rate[1], + tol ); + + } + } + + void test_deriv( const ReactionRate& reaction_rate, + const PairScalars& T, + typename Antioch::value_type::type /*Scalar*/ tol ) + { + const PairScalars deriv = reaction_rate.derivative(T); + const PairScalars exact_deriv = this->exact_deriv(T); + + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple], + exact_deriv[0], + tol ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple+1], + exact_deriv[1], + tol ); + + } + } + + void test_rate_and_deriv( const ReactionRate& reaction_rate, + const PairScalars& T, + typename Antioch::value_type::type /*Scalar*/ tol ) + { + // Init using T as the "example" + PairScalars rate = T; + PairScalars deriv = T; + + reaction_rate.rate_and_derivative(T,rate,deriv); + + const PairScalars exact_rate = this->exact_rate(T); + const PairScalars exact_deriv = this->exact_deriv(T); + + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple], + exact_rate[0], + tol ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple+1], + exact_rate[1], + tol ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple], + exact_deriv[0], + tol ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple+1], + exact_deriv[1], + tol ); + } + } + + +protected: + + // Should be new'd/deleted in subclasses for each PairScalar type + PairScalars* _example; + + PairScalars setup_T( const PairScalars& example ) + { + // Construct from example to avoid resizing issues + PairScalars T = example; + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + T[2*tuple] = 1500.1; + T[2*tuple+1] = 1600.1; + } + return T; + } + + virtual PairScalars exact_rate( PairScalars T ) =0; + virtual PairScalars exact_deriv( PairScalars T ) =0; + +}; + +#endif // ANTIOCH_HAVE_CPPUNIT + +#endif // ANTIOCH_REACTION_RATE_VECTOR_TEST_BASE_H From 97e659c4017760946aa82cfeb83d425f69e6a45d Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Mon, 24 Aug 2015 11:51:31 -0400 Subject: [PATCH 09/29] Rename arrhenius valarray file Have file actually indicate valarray instead of ambiguous vector. That way we can later add arrhenius_rate_eigen_test, for example. --- test/Makefile.am | 2 +- ...henius_rate_vector_test.C => arrhenius_rate_valarray_test.C} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename test/standard_unit/{arrhenius_rate_vector_test.C => arrhenius_rate_valarray_test.C} (100%) diff --git a/test/Makefile.am b/test/Makefile.am index 43322285..9b58ade8 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -97,7 +97,7 @@ LDADD = $(top_builddir)/src/libantioch.la pkginclude_HEADERS = standard_unit_tests_SOURCES = standard_unit/arrhenius_rate_test.C \ - standard_unit/arrhenius_rate_vector_test.C \ + standard_unit/arrhenius_rate_valarray_test.C \ standard_unit/standard_unit_tests.C pkginclude_HEADERS += standard_unit/reaction_rate_test_base.h diff --git a/test/standard_unit/arrhenius_rate_vector_test.C b/test/standard_unit/arrhenius_rate_valarray_test.C similarity index 100% rename from test/standard_unit/arrhenius_rate_vector_test.C rename to test/standard_unit/arrhenius_rate_valarray_test.C From f8e678673230b771567cb4a62115599e18f85b81 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Mon, 24 Aug 2015 13:40:16 -0400 Subject: [PATCH 10/29] Add Eigen tests platform And the Arrhenius-Eigen-vector unit test. --- test/Makefile.am | 5 + test/eigen_unit/arrhenius_rate_eigen_test.C | 106 ++++++++++++++++++++ test/eigen_unit/eigen_unit_tests.C | 58 +++++++++++ 3 files changed, 169 insertions(+) create mode 100644 test/eigen_unit/arrhenius_rate_eigen_test.C create mode 100644 test/eigen_unit/eigen_unit_tests.C diff --git a/test/Makefile.am b/test/Makefile.am index 9b58ade8..c92c44fe 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -2,6 +2,7 @@ EXTRA_DIST = input_files check_PROGRAMS = check_PROGRAMS += standard_unit_tests +check_PROGRAMS += eigen_unit_tests check_PROGRAMS += chem_mixture_unit check_PROGRAMS += chem_mixture_vec_unit check_PROGRAMS += nasa_evaluator_unit @@ -100,6 +101,9 @@ standard_unit_tests_SOURCES = standard_unit/arrhenius_rate_test.C \ standard_unit/arrhenius_rate_valarray_test.C \ standard_unit/standard_unit_tests.C +eigen_unit_tests_SOURCES = eigen_unit/arrhenius_rate_eigen_test.C \ + eigen_unit/eigen_unit_tests.C + pkginclude_HEADERS += standard_unit/reaction_rate_test_base.h pkginclude_HEADERS += standard_unit/arrhenius_rate_test_helper.h @@ -180,6 +184,7 @@ stat_mech_thermo_unit_eigen_SOURCES = stat_mech_thermo_unit_eigen.C #Define tests to actually be run TESTS = TESTS += standard_unit_tests +TESTS += eigen_unit_tests TESTS += chem_mixture_unit TESTS += chem_mixture_vec_unit TESTS += nasa_evaluator_unit.sh diff --git a/test/eigen_unit/arrhenius_rate_eigen_test.C b/test/eigen_unit/arrhenius_rate_eigen_test.C new file mode 100644 index 00000000..823d955e --- /dev/null +++ b/test/eigen_unit/arrhenius_rate_eigen_test.C @@ -0,0 +1,106 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +#ifdef ANTIOCH_HAVE_EIGEN + +// Eigen +#include "Eigen/Dense" + +// Antioch +#include "antioch/eigen_utils_decl.h" +#include "antioch/physical_constants.h" +#include "antioch/units.h" +#include "arrhenius_rate_vector_test_base.h" +#include "antioch/eigen_utils.h" + +template +class ArrheniusRateEigenTest : public ArrheniusRateVectorTestBase > +{ +public: + + virtual void setUp() + { + this->init(); + this->_example = new Eigen::Array(); + } + + virtual void tearDown() + { + this->clear(); + delete this->_example; + } + +}; + +class ArrheniusRateEigenFloatTest : public ArrheniusRateEigenTest +{ +public: + + CPPUNIT_TEST_SUITE( ArrheniusRateEigenFloatTest ); + + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class ArrheniusRateEigenDoubleTest : public ArrheniusRateEigenTest +{ +public: + + CPPUNIT_TEST_SUITE( ArrheniusRateEigenDoubleTest ); + + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class ArrheniusRateEigenLongDoubleTest : public ArrheniusRateEigenTest +{ +public: + + CPPUNIT_TEST_SUITE( ArrheniusRateEigenLongDoubleTest ); + + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); + + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateEigenFloatTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateEigenDoubleTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateEigenLongDoubleTest ); + +#endif // ANTIOCH_HAVE_EIGEN + +#endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/eigen_unit/eigen_unit_tests.C b/test/eigen_unit/eigen_unit_tests.C new file mode 100644 index 00000000..757a2367 --- /dev/null +++ b/test/eigen_unit/eigen_unit_tests.C @@ -0,0 +1,58 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT +#include +#include +#endif // ANTIOCH_HAVE_CPPUNIT + +int main() +{ +#ifdef ANTIOCH_HAVE_EIGEN +#ifdef ANTIOCH_HAVE_CPPUNIT + CppUnit::TextUi::TestRunner runner; + CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + runner.addTest( registry.makeTest() ); + + // If the tests all succeed, report success + if (runner.run()) + return 0; + + // If any test fails report failure + return 1; +#else // ANTIOCH_HAVE_CPPUNIT + // If we don't have CPPUnit, report we skipped + // 77 return code tells Automake we skipped this. + return 77; +#endif // ANTIOCH_HAVE_CPPUNIT + +#else // ANTIOCH_HAVE_EIGEN + // If we don't have Eigen, report we skipped + // 77 return code tells Automake we skipped this. + return 77; +#endif // ANTIOCH_HAVE_EIGEN +} From a78a604c86fc0f1ef3c56f948d51f788fe972f3d Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Mon, 24 Aug 2015 14:25:05 -0400 Subject: [PATCH 11/29] Have Travis grab/use CPPUnit --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 539d5c95..2ba75c22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ compiler: - clang before_script: - sudo apt-get update -qq - - sudo apt-get install -qq libeigen3-dev libgsl0-dev + - sudo apt-get install -qq libeigen3-dev libgsl0-dev libcppunit-1.12-1 libcppunit-dev script: - - echo apt-get install -qq libeigen3-dev libgsl0-dev fglrx=2:8.960-0ubuntu1 opencl-headers libboost-chrono1.48-dev libboost-date-time1.48-dev libboost-filesystem1.48-dev libboost-system1.48-dev libboost-thread1.48-dev libboost-program-options1.48-dev libboost-test1.48-dev + - echo apt-get install -qq libeigen3-dev libgsl0-dev libcppunit-1.12-1 libcppunit-dev fglrx=2:8.960-0ubuntu1 opencl-headers libboost-chrono1.48-dev libboost-date-time1.48-dev libboost-filesystem1.48-dev libboost-system1.48-dev libboost-thread1.48-dev libboost-program-options1.48-dev libboost-test1.48-dev - echo git clone https://github.com/ddemidov/vexcl - ./bootstrap - echo ./configure --with-vexcl=${PWD}/vexcl "takes too much RAM to compile" From c578029adf95fd2ccfcc2c0f62b12be8109a7f51 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Wed, 26 Aug 2015 01:58:50 -0400 Subject: [PATCH 12/29] Clearer logic on making CPPUnit default at configure --- configure.ac | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 5e55b31a..3fee4525 100644 --- a/configure.ac +++ b/configure.ac @@ -138,16 +138,11 @@ AM_CONDITIONAL(ANTIOCH_ENABLE_GSL, test x$HAVE_GSL = x1) # ------------------------------------------------------------- AC_ARG_ENABLE(cppunit, AS_HELP_STRING([--disable-cppunit], - [Build without cppunit C++ unit testing support]), - [case "${enableval}" in - yes) enablecppunit=yes ;; - no) enablecppunit=no ;; - *) AC_MSG_ERROR(bad value ${enableval} for --enable-cppunit) ;; - esac], - [enablecppunit=$enableoptional]) -if (test "$enablecppunit" = yes) ; then - AM_PATH_CPPUNIT([1.10.0],[enablecppunit=yes],[enablecppunit=no]) -fi + [Build without cppunit C++ unit testing support])) +AS_IF([test "x$enable_cppunit" != "xno"], [ + AM_PATH_CPPUNIT([1.10.0],[enablecppunit=yes],[enablecppunit=no]) +]) + if (test x$HAVE_CPPUNIT = x1); then antioch_optional_test_INCLUDES="$CPPUNIT_CPPFLAGS $antioch_optional_test_INCLUDES" antioch_optional_test_LIBS="$CPPUNIT_LIBS $antioch_optional_test_LIBS" From 7c3480674367cebbb5bbdcddeca9dfe91cd74933 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Wed, 26 Aug 2015 01:59:27 -0400 Subject: [PATCH 13/29] Park CPPUnit linking in LDFLAGS instead of LIBS The cppunit config program doesn't split them up, but it's more convenient on Mac to put them in LDFLAGS, otherwise it tries to find the Macports version of CPPUnit and it's annoying. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 3fee4525..edc6e2d5 100644 --- a/configure.ac +++ b/configure.ac @@ -145,7 +145,7 @@ AS_IF([test "x$enable_cppunit" != "xno"], [ if (test x$HAVE_CPPUNIT = x1); then antioch_optional_test_INCLUDES="$CPPUNIT_CPPFLAGS $antioch_optional_test_INCLUDES" - antioch_optional_test_LIBS="$CPPUNIT_LIBS $antioch_optional_test_LIBS" + antioch_optional_test_LDFLAGS="$CPPUNIT_LIBS $antioch_optional_test_LDFLAGS" fi AM_CONDITIONAL(ANTIOCH_ENABLE_CPPUNIT, test x$enablecppunit = xyes) From 70c4c231dd2b78860cad51ec48a4cc8de1a9a987 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Wed, 26 Aug 2015 02:01:17 -0400 Subject: [PATCH 14/29] Add CPPUnit based VexCL test program And ArrheniusRate VexCL unit tests. --- test/Makefile.am | 5 + test/vexcl_unit/arrhenius_rate_vexcl_test.C | 114 ++++++++++++++++++++ test/vexcl_unit/vexcl_unit_tests.C | 58 ++++++++++ 3 files changed, 177 insertions(+) create mode 100644 test/vexcl_unit/arrhenius_rate_vexcl_test.C create mode 100644 test/vexcl_unit/vexcl_unit_tests.C diff --git a/test/Makefile.am b/test/Makefile.am index c92c44fe..697be1a3 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -3,6 +3,7 @@ EXTRA_DIST = input_files check_PROGRAMS = check_PROGRAMS += standard_unit_tests check_PROGRAMS += eigen_unit_tests +check_PROGRAMS += vexcl_unit_tests check_PROGRAMS += chem_mixture_unit check_PROGRAMS += chem_mixture_vec_unit check_PROGRAMS += nasa_evaluator_unit @@ -104,6 +105,9 @@ standard_unit_tests_SOURCES = standard_unit/arrhenius_rate_test.C \ eigen_unit_tests_SOURCES = eigen_unit/arrhenius_rate_eigen_test.C \ eigen_unit/eigen_unit_tests.C +vexcl_unit_tests_SOURCES = vexcl_unit/arrhenius_rate_vexcl_test.C \ + vexcl_unit/vexcl_unit_tests.C + pkginclude_HEADERS += standard_unit/reaction_rate_test_base.h pkginclude_HEADERS += standard_unit/arrhenius_rate_test_helper.h @@ -185,6 +189,7 @@ stat_mech_thermo_unit_eigen_SOURCES = stat_mech_thermo_unit_eigen.C TESTS = TESTS += standard_unit_tests TESTS += eigen_unit_tests +TESTS += vexcl_unit_tests TESTS += chem_mixture_unit TESTS += chem_mixture_vec_unit TESTS += nasa_evaluator_unit.sh diff --git a/test/vexcl_unit/arrhenius_rate_vexcl_test.C b/test/vexcl_unit/arrhenius_rate_vexcl_test.C new file mode 100644 index 00000000..5f12be62 --- /dev/null +++ b/test/vexcl_unit/arrhenius_rate_vexcl_test.C @@ -0,0 +1,114 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +#ifdef ANTIOCH_HAVE_VEXCL + +// VexCL +#include "vexcl/vexcl.hpp" + +// Antioch +#include "antioch/vexcl_utils_decl.h" +#include "antioch/physical_constants.h" +#include "antioch/units.h" +#include "arrhenius_rate_vector_test_base.h" +#include "antioch/vexcl_utils.h" + +class ArrheniusRateVexCLFloatTest : public ArrheniusRateVectorTestBase > +{ +public: + + CPPUNIT_TEST_SUITE( ArrheniusRateVexCLFloatTest ); + + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); + + CPPUNIT_TEST_SUITE_END(); + +private: + + vex::Context* _ctx; + +public: + + virtual void setUp() + { + this->init(); + _ctx = new vex::Context(vex::Filter::All); + this->_example = new vex::vector(*_ctx, 2*ANTIOCH_N_TUPLES); + } + + virtual void tearDown() + { + this->clear(); + delete _ctx; + delete this->_example; + } + +}; + +class ArrheniusRateVexCLDoubleTest : public ArrheniusRateVectorTestBase > +{ +public: + + CPPUNIT_TEST_SUITE( ArrheniusRateVexCLDoubleTest ); + + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); + + CPPUNIT_TEST_SUITE_END(); + + private: + + vex::Context* _ctx; + +public: + + virtual void setUp() + { + this->init(); + _ctx = new vex::Context(vex::Filter::DoublePrecision); + this->_example = new vex::vector(*_ctx, 2*ANTIOCH_N_TUPLES); + } + + virtual void tearDown() + { + this->clear(); + delete _ctx; + delete this->_example; + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateVexCLFloatTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateVexCLDoubleTest ); + +#endif // ANTIOCH_HAVE_VEXCL + +#endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/vexcl_unit/vexcl_unit_tests.C b/test/vexcl_unit/vexcl_unit_tests.C new file mode 100644 index 00000000..70d207ff --- /dev/null +++ b/test/vexcl_unit/vexcl_unit_tests.C @@ -0,0 +1,58 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT +#include +#include +#endif // ANTIOCH_HAVE_CPPUNIT + +int main() +{ +#ifdef ANTIOCH_HAVE_VEXCL +#ifdef ANTIOCH_HAVE_CPPUNIT + CppUnit::TextUi::TestRunner runner; + CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + runner.addTest( registry.makeTest() ); + + // If the tests all succeed, report success + if (runner.run()) + return 0; + + // If any test fails report failure + return 1; +#else // ANTIOCH_HAVE_CPPUNIT + // If we don't have CPPUnit, report we skipped + // 77 return code tells Automake we skipped this. + return 77; +#endif // ANTIOCH_HAVE_CPPUNIT + +#else // ANTIOCH_HAVE_VEXCL + // If we don't have VexCL, report we skipped + // 77 return code tells Automake we skipped this. + return 77; +#endif // ANTIOCH_HAVE_VEXCL +} From bcffa5e34c25b7f5d2c34ae27d6c6c755f804ed7 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Wed, 26 Aug 2015 09:29:52 -0400 Subject: [PATCH 15/29] Add CPPUnit-based MetaPhysicL unit testing Includes ArrheniusRate vector test for MetaPhysicL --- test/Makefile.am | 5 + .../arrhenius_rate_metaphysicl_test.C | 106 ++++++++++++++++++ .../metaphysicl_unit/metaphysicl_unit_tests.C | 58 ++++++++++ 3 files changed, 169 insertions(+) create mode 100644 test/metaphysicl_unit/arrhenius_rate_metaphysicl_test.C create mode 100644 test/metaphysicl_unit/metaphysicl_unit_tests.C diff --git a/test/Makefile.am b/test/Makefile.am index 697be1a3..d17c9dce 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -4,6 +4,7 @@ check_PROGRAMS = check_PROGRAMS += standard_unit_tests check_PROGRAMS += eigen_unit_tests check_PROGRAMS += vexcl_unit_tests +check_PROGRAMS += metaphysicl_unit_tests check_PROGRAMS += chem_mixture_unit check_PROGRAMS += chem_mixture_vec_unit check_PROGRAMS += nasa_evaluator_unit @@ -108,6 +109,9 @@ eigen_unit_tests_SOURCES = eigen_unit/arrhenius_rate_eigen_test.C \ vexcl_unit_tests_SOURCES = vexcl_unit/arrhenius_rate_vexcl_test.C \ vexcl_unit/vexcl_unit_tests.C +metaphysicl_unit_tests_SOURCES = metaphysicl_unit/arrhenius_rate_metaphysicl_test.C \ + metaphysicl_unit/metaphysicl_unit_tests.C + pkginclude_HEADERS += standard_unit/reaction_rate_test_base.h pkginclude_HEADERS += standard_unit/arrhenius_rate_test_helper.h @@ -190,6 +194,7 @@ TESTS = TESTS += standard_unit_tests TESTS += eigen_unit_tests TESTS += vexcl_unit_tests +TESTS += metaphysicl_unit_tests TESTS += chem_mixture_unit TESTS += chem_mixture_vec_unit TESTS += nasa_evaluator_unit.sh diff --git a/test/metaphysicl_unit/arrhenius_rate_metaphysicl_test.C b/test/metaphysicl_unit/arrhenius_rate_metaphysicl_test.C new file mode 100644 index 00000000..63768d9a --- /dev/null +++ b/test/metaphysicl_unit/arrhenius_rate_metaphysicl_test.C @@ -0,0 +1,106 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +#ifdef ANTIOCH_HAVE_METAPHYSICL + +// MetaPhysicL +#include "metaphysicl/numberarray.h" + +// Antioch +#include "antioch/metaphysicl_utils_decl.h" +#include "antioch/physical_constants.h" +#include "antioch/units.h" +#include "arrhenius_rate_vector_test_base.h" +#include "antioch/metaphysicl_utils.h" + +template +class ArrheniusRateMetaPhysicLTest : public ArrheniusRateVectorTestBase > +{ +public: + + virtual void setUp() + { + this->init(); + this->_example = new MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float>(0); + } + + virtual void tearDown() + { + this->clear(); + delete this->_example; + } + +}; + +class ArrheniusRateMetaPhysicLFloatTest : public ArrheniusRateMetaPhysicLTest +{ +public: + + CPPUNIT_TEST_SUITE( ArrheniusRateMetaPhysicLFloatTest ); + + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class ArrheniusRateMetaPhysicLDoubleTest : public ArrheniusRateMetaPhysicLTest +{ +public: + + CPPUNIT_TEST_SUITE( ArrheniusRateMetaPhysicLDoubleTest ); + + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class ArrheniusRateMetaPhysicLLongDoubleTest : public ArrheniusRateMetaPhysicLTest +{ +public: + + CPPUNIT_TEST_SUITE( ArrheniusRateMetaPhysicLLongDoubleTest ); + + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); + + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateMetaPhysicLFloatTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateMetaPhysicLDoubleTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateMetaPhysicLLongDoubleTest ); + +#endif // ANTIOCH_HAVE_METAPHYSICL + +#endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/metaphysicl_unit/metaphysicl_unit_tests.C b/test/metaphysicl_unit/metaphysicl_unit_tests.C new file mode 100644 index 00000000..2f0173da --- /dev/null +++ b/test/metaphysicl_unit/metaphysicl_unit_tests.C @@ -0,0 +1,58 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT +#include +#include +#endif // ANTIOCH_HAVE_CPPUNIT + +int main() +{ +#ifdef ANTIOCH_HAVE_METAPHYSICL +#ifdef ANTIOCH_HAVE_CPPUNIT + CppUnit::TextUi::TestRunner runner; + CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + runner.addTest( registry.makeTest() ); + + // If the tests all succeed, report success + if (runner.run()) + return 0; + + // If any test fails report failure + return 1; +#else // ANTIOCH_HAVE_CPPUNIT + // If we don't have CPPUnit, report we skipped + // 77 return code tells Automake we skipped this. + return 77; +#endif // ANTIOCH_HAVE_CPPUNIT + +#else // ANTIOCH_HAVE_METAPHYSICL + // If we don't have MetaPhysicL, report we skipped + // 77 return code tells Automake we skipped this. + return 77; +#endif // ANTIOCH_HAVE_METAPHYSICL +} From 80bdb369ff07cabeb72a202068c4f376818cfba0 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Wed, 26 Aug 2015 09:34:05 -0400 Subject: [PATCH 16/29] Remove now stale arrhenius_rate_vec_unit We have all that coverage (and more actually) in all the new CPPUnit based tests so it's no longer needed. --- test/Makefile.am | 3 - test/arrhenius_rate_vec_unit.C | 207 --------------------------------- 2 files changed, 210 deletions(-) delete mode 100644 test/arrhenius_rate_vec_unit.C diff --git a/test/Makefile.am b/test/Makefile.am index d17c9dce..f0ec7320 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -18,7 +18,6 @@ check_PROGRAMS += hercourtessen_rate_vec_unit check_PROGRAMS += berthelot_rate_unit check_PROGRAMS += berthelot_rate_vec_unit check_PROGRAMS += arrhenius_rate_deriv -check_PROGRAMS += arrhenius_rate_vec_unit check_PROGRAMS += kooij_rate_unit check_PROGRAMS += kooij_rate_vec_unit check_PROGRAMS += berthelothercourtessen_rate_unit @@ -129,7 +128,6 @@ hercourtessen_rate_vec_unit_SOURCES = hercourtessen_rate_vec_unit.C berthelot_rate_unit_SOURCES = berthelot_rate_unit.C berthelot_rate_vec_unit_SOURCES = berthelot_rate_vec_unit.C arrhenius_rate_deriv_SOURCES = arrhenius_rate_deriv.C -arrhenius_rate_vec_unit_SOURCES = arrhenius_rate_vec_unit.C berthelothercourtessen_rate_unit_SOURCES = berthelothercourtessen_rate_unit.C berthelothercourtessen_rate_vec_unit_SOURCES = berthelothercourtessen_rate_vec_unit.C kooij_rate_unit_SOURCES = kooij_rate_unit.C @@ -208,7 +206,6 @@ TESTS += hercourtessen_rate_unit TESTS += berthelot_rate_vec_unit TESTS += berthelot_rate_vec_unit TESTS += arrhenius_rate_deriv -TESTS += arrhenius_rate_vec_unit TESTS += berthelothercourtessen_rate_unit TESTS += berthelothercourtessen_rate_vec_unit TESTS += kooij_rate_unit diff --git a/test/arrhenius_rate_vec_unit.C b/test/arrhenius_rate_vec_unit.C deleted file mode 100644 index 6f0b9361..00000000 --- a/test/arrhenius_rate_vec_unit.C +++ /dev/null @@ -1,207 +0,0 @@ -//-----------------------------------------------------------------------bl- -//-------------------------------------------------------------------------- -// -// Antioch - A Gas Dynamics Thermochemistry Library -// -// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, -// Roy H. Stonger -// Copyright (C) 2013 The PECOS Development Team -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the Version 2.1 GNU Lesser General -// Public License as published by the Free Software Foundation. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc. 51 Franklin Street, Fifth Floor, -// Boston, MA 02110-1301 USA -// -//-----------------------------------------------------------------------el- -// -// $Id$ -// -//-------------------------------------------------------------------------- -//-------------------------------------------------------------------------- - -// valarray has to be declared before Antioch or gcc can't find the -// right versions of exp() and pow() to use?? - -#include "antioch_config.h" - -#include - -#ifdef ANTIOCH_HAVE_EIGEN -#include "Eigen/Dense" -#endif - -#ifdef ANTIOCH_HAVE_METAPHYSICL -#include "metaphysicl/numberarray.h" -#endif - -#ifdef ANTIOCH_HAVE_VEXCL -#include "vexcl/vexcl.hpp" -#endif - -#include "antioch/eigen_utils_decl.h" -#include "antioch/metaphysicl_utils_decl.h" -#include "antioch/valarray_utils_decl.h" -#include "antioch/vexcl_utils_decl.h" - -#include "antioch/arrhenius_rate.h" - -#include "antioch/eigen_utils.h" -#include "antioch/metaphysicl_utils.h" -#include "antioch/valarray_utils.h" -#include "antioch/vexcl_utils.h" - -#ifdef ANTIOCH_HAVE_GRVY -#include "grvy.h" - -GRVY::GRVY_Timer_Class gt; -#endif - -#include -#include - -template -int vectester(const PairScalars& example, const std::string& testname) -{ - using std::abs; - using std::exp; - - typedef typename Antioch::value_type::type Scalar; - - const Scalar Cf = 1.4; - const Scalar Ea = 5.0; - - Antioch::ArrheniusRate arrhenius_rate(Cf,Ea,1.); - - // Construct from example to avoid resizing issues - PairScalars T = example; - for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) - { - T[2*tuple] = 1500.1; - T[2*tuple+1] = 1600.1; - } - - const Scalar rate_exact0 = Cf*exp(-Ea/1500.1); - const Scalar rate_exact1 = Cf*exp(-Ea/1600.1); - const Scalar derive_exact0 = Ea/(Scalar(1500.1)*Scalar(1500.1)) * Cf * exp(-Ea/Scalar(1500.1)); - const Scalar derive_exact1 = Ea/(Scalar(1600.1)*Scalar(1600.1)) * Cf * exp(-Ea/Scalar(1600.1)); - - int return_flag = 0; - -#ifdef ANTIOCH_HAVE_GRVY - gt.BeginTimer(testname); -#endif - - const PairScalars rate = arrhenius_rate(T); - const PairScalars deriveRate = arrhenius_rate.derivative(T); - -#ifdef ANTIOCH_HAVE_GRVY - gt.EndTimer(testname); -#endif - - const Scalar tol = std::numeric_limits::epsilon()*10; - - for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) - { - if( abs( (rate[2*tuple] - rate_exact0)/rate_exact0 ) > tol ) - { - std::cout << "Error: Mismatch in rate values." << std::endl - << "rate(T0) = " << rate[2*tuple] << std::endl - << "rate_exact = " << rate_exact0 << std::endl - << "difference = " << rate[2*tuple] - rate_exact0 << std::endl; - - return_flag = 1; - break; - } - - if( abs( (rate[2*tuple+1] - rate_exact1)/rate_exact1 ) > tol ) - { - std::cout << "Error: Mismatch in rate values." << std::endl - << "rate(T1) = " << rate[2*tuple+1] << std::endl - << "rate_exact = " << rate_exact1 << std::endl - << "difference = " << rate[2*tuple+1] - rate_exact1 << std::endl; - - return_flag = 1; - break; - } - } - if( abs( (deriveRate[0] - derive_exact0)/derive_exact0 ) > tol ) - { - std::cout << std::scientific << std::setprecision(16) - << "Error: Mismatch in rate derivative values." << std::endl - << "drate_dT(T0) = " << deriveRate[0] << std::endl - << "derive_exact = " << derive_exact0 << std::endl; - - return_flag = 1; - } - if( abs( (deriveRate[1] - derive_exact1)/derive_exact1 ) > tol ) - { - std::cout << std::scientific << std::setprecision(16) - << "Error: Mismatch in rate derivative values." << std::endl - << "drate_dT(T1) = " << deriveRate[1] << std::endl - << "derive_exact = " << derive_exact1 << std::endl; - - return_flag = 1; - } - - std::cout << "Arrhenius rate: " << arrhenius_rate << std::endl; - - return return_flag; -} - - -int main() -{ - int returnval = 0; - - returnval = returnval || - vectester (std::valarray(2*ANTIOCH_N_TUPLES), "valarray"); - returnval = returnval || - vectester (std::valarray(2*ANTIOCH_N_TUPLES), "valarray"); - returnval = returnval || - vectester (std::valarray(2*ANTIOCH_N_TUPLES), "valarray"); -#ifdef ANTIOCH_HAVE_EIGEN - returnval = returnval || - vectester (Eigen::Array(), "Eigen::ArrayXf"); - returnval = returnval || - vectester (Eigen::Array(), "Eigen::ArrayXd"); - returnval = returnval || - vectester (Eigen::Array(), "Eigen::ArrayXld"); -#endif -#ifdef ANTIOCH_HAVE_METAPHYSICL - returnval = returnval || - vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float> (0), "NumberArray"); - returnval = returnval || - vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, double> (0), "NumberArray"); - returnval = returnval || - vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, long double> (0), "NumberArray"); -#endif -#ifdef ANTIOCH_HAVE_VEXCL -std::cout << "vexcl start" << std::endl; - vex::Context ctx_f (vex::Filter::All); -std::cout << "vexcl start" << std::endl; - if (!ctx_f.empty()) - returnval = returnval || - vectester (vex::vector (ctx_f, 2*ANTIOCH_N_TUPLES), "vex::vector"); -std::cout << "vexcl float ok" << std::endl; - vex::Context ctx_d (vex::Filter::DoublePrecision); - if (!ctx_d.empty()) - returnval = returnval || - vectester (vex::vector (ctx_d, 2*ANTIOCH_N_TUPLES), "vex::vector"); -#endif - -#ifdef ANTIOCH_HAVE_GRVY - gt.Finalize(); - gt.Summarize(); -#endif - - return returnval; -} From 7794623c2451201d0614b2056d1b0efce77b894d Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Wed, 26 Aug 2015 17:24:32 -0400 Subject: [PATCH 17/29] Adding GSL unit test framework Have started GSLSpliner unit test, checkpointing work on it. Currently testing we exactly fit/eval constants, linears. I want to construct and analytic case for the cubic function that satifies the natural boundary conditions so that we have a much better test than we had before. --- test/Makefile.am | 5 + test/gsl_unit/gsl_spliner_test.C | 168 ++++++++++++++++++++++++++ test/gsl_unit/gsl_spliner_test_base.h | 117 ++++++++++++++++++ test/gsl_unit/gsl_unit_tests.C | 58 +++++++++ 4 files changed, 348 insertions(+) create mode 100644 test/gsl_unit/gsl_spliner_test.C create mode 100644 test/gsl_unit/gsl_spliner_test_base.h create mode 100644 test/gsl_unit/gsl_unit_tests.C diff --git a/test/Makefile.am b/test/Makefile.am index f0ec7320..089105ca 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -5,6 +5,7 @@ check_PROGRAMS += standard_unit_tests check_PROGRAMS += eigen_unit_tests check_PROGRAMS += vexcl_unit_tests check_PROGRAMS += metaphysicl_unit_tests +check_PROGRAMS += gsl_unit_tests check_PROGRAMS += chem_mixture_unit check_PROGRAMS += chem_mixture_vec_unit check_PROGRAMS += nasa_evaluator_unit @@ -111,6 +112,9 @@ vexcl_unit_tests_SOURCES = vexcl_unit/arrhenius_rate_vexcl_test.C \ metaphysicl_unit_tests_SOURCES = metaphysicl_unit/arrhenius_rate_metaphysicl_test.C \ metaphysicl_unit/metaphysicl_unit_tests.C +gsl_unit_tests_SOURCES = gsl_unit/gsl_spliner_test.C \ + gsl_unit/gsl_unit_tests.C + pkginclude_HEADERS += standard_unit/reaction_rate_test_base.h pkginclude_HEADERS += standard_unit/arrhenius_rate_test_helper.h @@ -193,6 +197,7 @@ TESTS += standard_unit_tests TESTS += eigen_unit_tests TESTS += vexcl_unit_tests TESTS += metaphysicl_unit_tests +TESTS += gsl_unit_tests TESTS += chem_mixture_unit TESTS += chem_mixture_vec_unit TESTS += nasa_evaluator_unit.sh diff --git a/test/gsl_unit/gsl_spliner_test.C b/test/gsl_unit/gsl_spliner_test.C new file mode 100644 index 00000000..ef09ea79 --- /dev/null +++ b/test/gsl_unit/gsl_spliner_test.C @@ -0,0 +1,168 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +// C++ +#include +#include + +// Antioch +#include "antioch/vector_utils_decl.h" +#include "antioch/gsl_spliner.h" +#include "antioch/vector_utils.h" + +// Base class +#include "gsl_spliner_test_base.h" + +template +class GSLSplinerTest : public GSLSplinerTestBase +{ +public: + + void setUp() + { + this->init_data(); + } + + // Helper function + template + void run_manually_inited_test( Scalar tol ) + { + FunctionType exact_func; + this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); + + Antioch::GSLSpliner spline; + spline.spline_init(this->_x_ref, this->_y_ref); + + this->compare_values( tol, spline, exact_func ); + } + + // Helper function + template + void run_constructor_inited_test( Scalar tol ) + { + FunctionType exact_func; + this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); + + Antioch::GSLSpliner spline(this->_x_ref, this->_y_ref); + + this->compare_values( tol, spline, exact_func ); + } + + // Helper function + void compare_values( Scalar tol, Antioch::GSLSpliner& spline, GSLSplinerTestFunction& exact_func ) + { + for(unsigned int n = 0; n < this->_n_test; n++) + { + Scalar x = this->_x_min + (Scalar)(n) * (this->_x_max - this->_x_min) / (Scalar)(this->_n_test-1); + Scalar exact_value = exact_func(x); + Scalar interp_value = spline.interpolated_value(x); + CPPUNIT_ASSERT_DOUBLES_EQUAL( interp_value, + exact_value, + tol ); + } + } + + void test_manually_inited_spline_constant_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 100; + + this->run_manually_inited_test >(tol); + } + + void test_constructor_inited_spline_constant_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 100; + + this->run_constructor_inited_test >(tol); + } + + void test_manually_inited_spline_linear_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 100; + + this->run_manually_inited_test >(tol); + } + + void test_constructor_inited_spline_linear_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 100; + + this->run_constructor_inited_test >(tol); + } + + void test_manually_inited_cubic_spline() + { + const Scalar tol = std::numeric_limits::epsilon() * 100; + + this->run_manually_inited_test >(tol); + } + + void test_constructor_inited_cubic_spline() + { + const Scalar tol = std::numeric_limits::epsilon() * 100; + + this->run_constructor_inited_test >(tol); + } +}; + +class GslSplinerFloatTest : public GSLSplinerTest +{ +public: + CPPUNIT_TEST_SUITE( GslSplinerFloatTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + //CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + //CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class GslSplinerDoubleTest : public GSLSplinerTest +{ +public: + CPPUNIT_TEST_SUITE( GslSplinerDoubleTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + //CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + //CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerFloatTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerDoubleTest ); + + +#endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/gsl_unit/gsl_spliner_test_base.h b/test/gsl_unit/gsl_spliner_test_base.h new file mode 100644 index 00000000..7c7dcc92 --- /dev/null +++ b/test/gsl_unit/gsl_spliner_test_base.h @@ -0,0 +1,117 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#ifndef ANTIOCH_GSL_SPLINER_TEST_BASE_H +#define ANTIOCH_GSL_SPLINER_TEST_BASE_H + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +#include +#include + +template +struct GSLSplinerTestFunction +{ + virtual Scalar operator()( const Scalar x ) =0; +}; + +template +struct ConstantTestFunction : public GSLSplinerTestFunction +{ + virtual Scalar operator()( const Scalar x ) + { + // Scalar may actually be a PairScalar, so do this to handle those cases too. + return Antioch::constant_clone(x,10); + } +}; + +template +struct LinearTestFunction : public GSLSplinerTestFunction +{ + virtual Scalar operator()( const Scalar x ) + { + // Scalar may actually be a PairScalar, so do this to handle those cases too. + Scalar ten = Antioch::constant_clone(x,10); + Scalar five = Antioch::constant_clone(x,5); + + return ten + five * x; + } +}; + +template +struct CubicTestFunction : public GSLSplinerTestFunction +{ + virtual Scalar operator()( const Scalar x ) + { + // Scalar may actually be a PairScalar, so do this to handle those cases too. + Scalar ten = Antioch::constant_clone(x,10); + Scalar two = Antioch::constant_clone(x,2); + Scalar five = Antioch::constant_clone(x,5); + + return ten + five * x + ten * x * x - two * x * x * x; + } +}; + +template +class GSLSplinerTestBase : public CppUnit::TestCase +{ +public: + + void init_data() + { + _n_data = 40; + _n_test = 39; + _x_ref.resize(_n_data); + _y_ref.resize(_n_data); + _x_min = -5.0L; + _x_max = 8.0L; + } + + void fill_ref(std::vector& x_ref, std::vector& y_ref, + unsigned int n_data, const Scalar& x_min, const Scalar& x_max, + GSLSplinerTestFunction& exact_func) + { + for(unsigned int i = 0; i < n_data; i++) + { + x_ref[i] = x_min + (Scalar)(i) * (x_max - x_min) / (Scalar)(n_data-1); + y_ref[i] = exact_func(x_ref[i]); + } + } + +protected: + + unsigned int _n_data; + unsigned int _n_test; + Scalar _x_min; + Scalar _x_max; + std::vector _x_ref; + std::vector _y_ref; +}; + +#endif // ANTIOCH_HAVE_CPPUNIT + +#endif // ANTIOCH_GSL_SPLINER_TEST_BASE_H diff --git a/test/gsl_unit/gsl_unit_tests.C b/test/gsl_unit/gsl_unit_tests.C new file mode 100644 index 00000000..b78b02fc --- /dev/null +++ b/test/gsl_unit/gsl_unit_tests.C @@ -0,0 +1,58 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT +#include +#include +#endif // ANTIOCH_HAVE_CPPUNIT + +int main() +{ +#ifdef ANTIOCH_HAVE_GSL +#ifdef ANTIOCH_HAVE_CPPUNIT + CppUnit::TextUi::TestRunner runner; + CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + runner.addTest( registry.makeTest() ); + + // If the tests all succeed, report success + if (runner.run()) + return 0; + + // If any test fails report failure + return 1; +#else // ANTIOCH_HAVE_CPPUNIT + // If we don't have CPPUnit, report we skipped + // 77 return code tells Automake we skipped this. + return 77; +#endif // ANTIOCH_HAVE_CPPUNIT + +#else // ANTIOCH_HAVE_GSL + // If we don't have Eigen, report we skipped + // 77 return code tells Automake we skipped this. + return 77; +#endif // ANTIOCH_HAVE_GSL +} From 0ff168aef36b1087f6a9cd6dc7a71df1dba7c520 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Fri, 4 Sep 2015 09:47:15 -0400 Subject: [PATCH 18/29] Tighten tolerances on current GSL tests --- test/gsl_unit/gsl_spliner_test.C | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/gsl_unit/gsl_spliner_test.C b/test/gsl_unit/gsl_spliner_test.C index ef09ea79..be5337d6 100644 --- a/test/gsl_unit/gsl_spliner_test.C +++ b/test/gsl_unit/gsl_spliner_test.C @@ -90,28 +90,28 @@ public: void test_manually_inited_spline_constant_func() { - const Scalar tol = std::numeric_limits::epsilon() * 100; + const Scalar tol = std::numeric_limits::epsilon() * 10; this->run_manually_inited_test >(tol); } void test_constructor_inited_spline_constant_func() { - const Scalar tol = std::numeric_limits::epsilon() * 100; + const Scalar tol = std::numeric_limits::epsilon() * 10; this->run_constructor_inited_test >(tol); } void test_manually_inited_spline_linear_func() { - const Scalar tol = std::numeric_limits::epsilon() * 100; + const Scalar tol = std::numeric_limits::epsilon() * 50; this->run_manually_inited_test >(tol); } void test_constructor_inited_spline_linear_func() { - const Scalar tol = std::numeric_limits::epsilon() * 100; + const Scalar tol = std::numeric_limits::epsilon() * 50; this->run_constructor_inited_test >(tol); } From 783f69d1256b200b1549180da692cae034ff4bb7 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Fri, 4 Sep 2015 09:49:39 -0400 Subject: [PATCH 19/29] Supply bounds to GSL testing functions --- test/gsl_unit/gsl_spliner_test.C | 4 ++++ test/gsl_unit/gsl_spliner_test_base.h | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/test/gsl_unit/gsl_spliner_test.C b/test/gsl_unit/gsl_spliner_test.C index be5337d6..2e0b748a 100644 --- a/test/gsl_unit/gsl_spliner_test.C +++ b/test/gsl_unit/gsl_spliner_test.C @@ -54,6 +54,8 @@ public: void run_manually_inited_test( Scalar tol ) { FunctionType exact_func; + exact_func.init(this->_x_min, this->_x_max); + this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); Antioch::GSLSpliner spline; @@ -67,6 +69,8 @@ public: void run_constructor_inited_test( Scalar tol ) { FunctionType exact_func; + exact_func.init(this->_x_min, this->_x_max); + this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); Antioch::GSLSpliner spline(this->_x_ref, this->_y_ref); diff --git a/test/gsl_unit/gsl_spliner_test_base.h b/test/gsl_unit/gsl_spliner_test_base.h index 7c7dcc92..58fe29b6 100644 --- a/test/gsl_unit/gsl_spliner_test_base.h +++ b/test/gsl_unit/gsl_spliner_test_base.h @@ -37,6 +37,15 @@ template struct GSLSplinerTestFunction { virtual Scalar operator()( const Scalar x ) =0; + + void init( Scalar x_min, Scalar x_max ) + { + _x_min = x_min; + _x_max = x_max; + }; + +protected: + Scalar _x_min, _x_max; }; template From 1e2a2df4608dff869e35ecd184d09336205b382a Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Fri, 4 Sep 2015 09:50:30 -0400 Subject: [PATCH 20/29] Test GSL spline on cubic function GSL cubic splining uses natural conditions by default, so I constructed a cubic Hermite function with f''(xmin) = f''(xmax) = 0. --- test/gsl_unit/gsl_spliner_test.C | 16 ++++++++-------- test/gsl_unit/gsl_spliner_test_base.h | 22 ++++++++++++++++++---- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/test/gsl_unit/gsl_spliner_test.C b/test/gsl_unit/gsl_spliner_test.C index 2e0b748a..c07baf6d 100644 --- a/test/gsl_unit/gsl_spliner_test.C +++ b/test/gsl_unit/gsl_spliner_test.C @@ -120,16 +120,16 @@ public: this->run_constructor_inited_test >(tol); } - void test_manually_inited_cubic_spline() + void test_manually_inited_spline_cubic_func() { - const Scalar tol = std::numeric_limits::epsilon() * 100; + const Scalar tol = std::numeric_limits::epsilon() * 50; this->run_manually_inited_test >(tol); } - void test_constructor_inited_cubic_spline() + void test_constructor_inited_spline_cubic_func() { - const Scalar tol = std::numeric_limits::epsilon() * 100; + const Scalar tol = std::numeric_limits::epsilon() * 50; this->run_constructor_inited_test >(tol); } @@ -144,8 +144,8 @@ public: CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); CPPUNIT_TEST( test_manually_inited_spline_linear_func ); CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - //CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - //CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); CPPUNIT_TEST_SUITE_END(); }; @@ -159,8 +159,8 @@ public: CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); CPPUNIT_TEST( test_manually_inited_spline_linear_func ); CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - //CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - //CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); CPPUNIT_TEST_SUITE_END(); }; diff --git a/test/gsl_unit/gsl_spliner_test_base.h b/test/gsl_unit/gsl_spliner_test_base.h index 58fe29b6..94b5881a 100644 --- a/test/gsl_unit/gsl_spliner_test_base.h +++ b/test/gsl_unit/gsl_spliner_test_base.h @@ -77,11 +77,25 @@ struct CubicTestFunction : public GSLSplinerTestFunction virtual Scalar operator()( const Scalar x ) { // Scalar may actually be a PairScalar, so do this to handle those cases too. - Scalar ten = Antioch::constant_clone(x,10); + Scalar one = Antioch::constant_clone(x,1); Scalar two = Antioch::constant_clone(x,2); - Scalar five = Antioch::constant_clone(x,5); - - return ten + five * x + ten * x * x - two * x * x * x; + Scalar three = Antioch::constant_clone(x,3); + Scalar xmin = Antioch::constant_clone(x,this->_x_min); + Scalar xmax = Antioch::constant_clone(x,this->_x_max); + + Scalar t = (x-xmin)/(xmax-xmin); + + // Constructing cubit hermite that interpolates xmin/xmax + // and has second derivatives of 0 at xmin,xmax + // Turns out you need first derivatives = 1 at the end points + Scalar t2 = t*t; + Scalar t3 = t*t*t; + Scalar h00 = two*t3 - three*t2 + one; + Scalar h10 = t3 - 2*t2 + t; + Scalar h01 = -two*t3 + three*t2; + Scalar h11 = t3 - t2; + + return h00*xmin + h10*(xmax-xmin) + h01*xmax + h11*(xmax-xmin); } }; From 47f56074a92c903b46e98352d2391945f9a63ddd Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Fri, 4 Sep 2015 09:57:15 -0400 Subject: [PATCH 21/29] Remove now redundant gsl_spline_unit Replaced by the GSL CppUnit tests. --- test/Makefile.am | 3 - test/gsl_spline_unit.C | 128 ----------------------------------------- 2 files changed, 131 deletions(-) delete mode 100644 test/gsl_spline_unit.C diff --git a/test/Makefile.am b/test/Makefile.am index 089105ca..53cb30ea 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -69,7 +69,6 @@ check_PROGRAMS += molecular_binary_diffusion_unit check_PROGRAMS += molecular_binary_diffusion_vec_unit check_PROGRAMS += kinetics_theory_viscosity_unit check_PROGRAMS += kinetics_theory_viscosity_vec_unit -check_PROGRAMS += gsl_spline_unit check_PROGRAMS += gsl_spline_vec_unit check_PROGRAMS += Stockmayer_unit @@ -181,7 +180,6 @@ molecular_binary_diffusion_unit_SOURCES = molecular_binary_diffusion_unit.C molecular_binary_diffusion_vec_unit_SOURCES = molecular_binary_diffusion_vec_unit.C kinetics_theory_viscosity_unit_SOURCES = kinetics_theory_viscosity_unit.C kinetics_theory_viscosity_vec_unit_SOURCES = kinetics_theory_viscosity_vec_unit.C -gsl_spline_unit_SOURCES = gsl_spline_unit.C gsl_spline_vec_unit_SOURCES = gsl_spline_vec_unit.C ideal_gas_micro_thermo_unit_SOURCES = ideal_gas_micro_thermo_unit.C Stockmayer_unit_SOURCES = Stockmayer_unit.C @@ -261,7 +259,6 @@ TESTS += molecular_binary_diffusion_unit TESTS += molecular_binary_diffusion_vec_unit TESTS += kinetics_theory_viscosity_unit TESTS += kinetics_theory_viscosity_vec_unit -TESTS += gsl_spline_unit TESTS += gsl_spline_vec_unit TESTS += Stockmayer_unit diff --git a/test/gsl_spline_unit.C b/test/gsl_spline_unit.C deleted file mode 100644 index d4eb5cd4..00000000 --- a/test/gsl_spline_unit.C +++ /dev/null @@ -1,128 +0,0 @@ -//-----------------------------------------------------------------------bl- -//-------------------------------------------------------------------------- -// -// Antioch - A Gas Dynamics Thermochemistry Library -// -// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, -// Roy H. Stonger -// Copyright (C) 2013 The PECOS Development Team -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the Version 2.1 GNU Lesser General -// Public License as published by the Free Software Foundation. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc. 51 Franklin Street, Fifth Floor, -// Boston, MA 02110-1301 USA -// -//-----------------------------------------------------------------------el- - -#include "antioch_config.h" - -// Antioch -#include "antioch/vector_utils_decl.h" -#include "antioch/gsl_spliner.h" -#include "antioch/vector_utils.h" - -// C++ -#include -#include -#include -#include -#include -#include -#include - -#ifdef ANTIOCH_HAVE_GSL - -template -int check_value(const Scalar & ref, const Scalar & candidate, const Scalar & x, const std::string & words) -{ - /*because not the real test function impossible due to boundary conditions - */ - const Scalar tol = 5e-3;//std::numeric_limits::epsilon() * 10.; - - if(std::abs((ref - candidate)/ref) > tol) - { - std::cerr << std::scientific << std::setprecision(15); - std::cerr << "ERROR in gsl spline test at point: " << x << "; " << words << std::endl - << " reference = " << ref << std::endl - << " candidate = " << candidate << std::endl - << " relative difference = " << std::abs((ref - candidate) / ref) << std::endl - << " absolute difference = " << std::abs(ref - candidate) << std::endl - << " tolerance = " << tol << std::endl; - return 1; - } - - return 0; -} - -template -Scalar function(const Scalar x) -{ - return 10.L + 5.L * x + 10.L * x * x - 2.L * x * x * x; -} - -template -void fill_ref(std::vector & x_ref, std::vector & y_ref, - unsigned int n_data, const Scalar & min, - const Scalar & max) -{ - for(unsigned int i = 0; i < n_data; i++) - { - x_ref[i] = min + (Scalar)(i) * (max - min) / (Scalar)(n_data-1); - y_ref[i] = function(x_ref[i]); - } -} - -template -int tester() -{ - const unsigned int n_data(40); - const unsigned int n_test(39); - std::vector x_ref(n_data,0),y_ref(n_data,0); - - const Scalar min = -5L; - const Scalar max = 8L; - fill_ref(x_ref,y_ref,n_data,min, max); - - Antioch::GSLSpliner default_constructor; - Antioch::GSLSpliner explicit_constructor(x_ref,y_ref); - - default_constructor.spline_init(x_ref,y_ref); - - int return_flag(0); - - for(unsigned int n = 0; n < n_test; n++) - { - Scalar x = min + (Scalar)(n) * (max - min) / (Scalar)(n_test-1); - Scalar exact = function(x); - Scalar spline_default = default_constructor.interpolated_value(x); - Scalar spline_explicit = explicit_constructor.interpolated_value(x); - return_flag = check_value(exact,spline_default,x,"default constructor") || return_flag; - return_flag = check_value(exact,spline_explicit,x,"explicit constructor") || return_flag; - } - - - return return_flag; -} -#endif // ANTIOCH_HAVE_GSL - -int main() -{ -#ifdef ANTIOCH_HAVE_GSL -// gsl work in double... - return (tester() || - tester()); - // tester() || -#else - // 77 return code tells Automake we skipped this. - return 77; -#endif -} From 76af1347485181b75be27eb644f1b3ef3830d27e Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Fri, 4 Sep 2015 19:02:32 -0400 Subject: [PATCH 22/29] Use cloned two in GSLSpliner test --- test/gsl_unit/gsl_spliner_test_base.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/gsl_unit/gsl_spliner_test_base.h b/test/gsl_unit/gsl_spliner_test_base.h index 94b5881a..f9f50e19 100644 --- a/test/gsl_unit/gsl_spliner_test_base.h +++ b/test/gsl_unit/gsl_spliner_test_base.h @@ -91,7 +91,7 @@ struct CubicTestFunction : public GSLSplinerTestFunction Scalar t2 = t*t; Scalar t3 = t*t*t; Scalar h00 = two*t3 - three*t2 + one; - Scalar h10 = t3 - 2*t2 + t; + Scalar h10 = t3 - two*t2 + t; Scalar h01 = -two*t3 + three*t2; Scalar h11 = t3 - t2; From 15ddbbaf4117621795c411a10029a048e7f9d8af Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Fri, 4 Sep 2015 19:03:11 -0400 Subject: [PATCH 23/29] Update GSL test function base template param Need data was Scalar, but operator() was on PairScalars --- test/gsl_unit/gsl_spliner_test_base.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/gsl_unit/gsl_spliner_test_base.h b/test/gsl_unit/gsl_spliner_test_base.h index f9f50e19..91259666 100644 --- a/test/gsl_unit/gsl_spliner_test_base.h +++ b/test/gsl_unit/gsl_spliner_test_base.h @@ -33,10 +33,12 @@ #include #include -template +template struct GSLSplinerTestFunction { - virtual Scalar operator()( const Scalar x ) =0; + typedef typename Antioch::value_type::type Scalar; + + virtual PairScalars operator()( const PairScalars x ) =0; void init( Scalar x_min, Scalar x_max ) { From 136c2871d8aa388f6152f2ddd294deaeeeb4a943 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Fri, 4 Sep 2015 19:08:10 -0400 Subject: [PATCH 24/29] Add vector versions of GSLSpliner tests Within the CppUnit framework. Instead of splitting up the tests further I just put all the different vector types in there knowing that we'll see if Eigen, VexCL, etc. are skipped or not from other tests so we'll know implicitly whehter they're being skipped in the GSL tests too or not. --- test/Makefile.am | 1 + test/gsl_unit/gsl_spliner_vec_test.C | 465 +++++++++++++++++++++++++++ 2 files changed, 466 insertions(+) create mode 100644 test/gsl_unit/gsl_spliner_vec_test.C diff --git a/test/Makefile.am b/test/Makefile.am index 53cb30ea..f5f7bb19 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -112,6 +112,7 @@ metaphysicl_unit_tests_SOURCES = metaphysicl_unit/arrhenius_rate_metaphysicl_tes metaphysicl_unit/metaphysicl_unit_tests.C gsl_unit_tests_SOURCES = gsl_unit/gsl_spliner_test.C \ + gsl_unit/gsl_spliner_vec_test.C \ gsl_unit/gsl_unit_tests.C pkginclude_HEADERS += standard_unit/reaction_rate_test_base.h diff --git a/test/gsl_unit/gsl_spliner_vec_test.C b/test/gsl_unit/gsl_spliner_vec_test.C new file mode 100644 index 00000000..c413aca3 --- /dev/null +++ b/test/gsl_unit/gsl_spliner_vec_test.C @@ -0,0 +1,465 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// Antioch - A Gas Dynamics Thermochemistry Library +// +// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, +// Roy H. Stonger +// Copyright (C) 2013 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +// C++ +#include +#include + +#ifdef ANTIOCH_HAVE_EIGEN +#include "Eigen/Dense" +#endif + +#ifdef ANTIOCH_HAVE_METAPHYSICL +#include "metaphysicl/numberarray.h" +#endif + +#ifdef ANTIOCH_HAVE_VEXCL +#include "vexcl/vexcl.hpp" +#endif + +// Antioch +#include "antioch/eigen_utils_decl.h" +#include "antioch/metaphysicl_utils_decl.h" +#include "antioch/vexcl_utils_decl.h" +#include "antioch/valarray_utils_decl.h" +#include "antioch/vector_utils_decl.h" +#include "antioch/gsl_spliner.h" +#include "antioch/vector_utils.h" +#include "antioch/eigen_utils.h" +#include "antioch/metaphysicl_utils.h" +#include "antioch/vexcl_utils.h" +#include "antioch/valarray_utils.h" + +// Base class +#include "gsl_spliner_test_base.h" + +template +class GSLSplinerVecTest : public GSLSplinerTestBase::type> +{ +public: + + typedef typename Antioch::value_type::type Scalar; + + void init_vec_data() + { + this->init_data(); + } + + // Helper function + template + void run_manually_inited_test( Scalar tol ) + { + ScalarFunctionType exact_func; + exact_func.init(this->_x_min, this->_x_max); + + this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); + + Antioch::GSLSpliner spline; + spline.spline_init(this->_x_ref, this->_y_ref); + + VecFunctionType vec_exact_func; + vec_exact_func.init(this->_x_min, this->_x_max); + + this->compare_values( tol, spline, vec_exact_func ); + } + + // Helper function + template + void run_constructor_inited_test( Scalar tol ) + { + ScalarFunctionType exact_func; + exact_func.init(this->_x_min, this->_x_max); + + this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); + + Antioch::GSLSpliner spline(this->_x_ref, this->_y_ref); + + VecFunctionType vec_exact_func; + vec_exact_func.init(this->_x_min, this->_x_max); + + this->compare_values( tol, spline, vec_exact_func ); + } + + // Helper function + void compare_values( Scalar tol, + Antioch::GSLSpliner& spline, + GSLSplinerTestFunction& exact_func) + { + // Construct from example to avoid resizing issues + PairScalars x = *(this->_example); + + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + x[2*tuple] = -3.5; + x[2*tuple+1] = 5.1; + } + + const PairScalars gsl_value = spline.interpolated_value(x); + + const PairScalars exact_value = exact_func(x); + + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL( gsl_value[2*tuple], + exact_value[2*tuple], + tol ); + } + } + + void test_manually_inited_spline_constant_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 10; + + this->run_manually_inited_test,ConstantTestFunction >(tol); + } + + void test_constructor_inited_spline_constant_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 10; + + this->run_constructor_inited_test,ConstantTestFunction >(tol); + } + + void test_manually_inited_spline_linear_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; + + this->run_manually_inited_test,LinearTestFunction >(tol); + } + + void test_constructor_inited_spline_linear_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; + + this->run_constructor_inited_test,LinearTestFunction >(tol); + } + + void test_manually_inited_spline_cubic_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; + + this->run_manually_inited_test,CubicTestFunction >(tol); + } + + void test_constructor_inited_spline_cubic_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; + + this->run_constructor_inited_test,CubicTestFunction >(tol); + } + +protected: + // Should be new'd/deleted in subclasses for each PairScalar type + PairScalars* _example; +}; + +//---------------------------------------------------------------------- +// valarray tests +//---------------------------------------------------------------------- +template +class GslSplinerValarrayTest : public GSLSplinerVecTest > +{ +public: + + virtual void setUp() + { + this->init_vec_data(); + this->_example = new std::valarray(2*ANTIOCH_N_TUPLES); + } + + virtual void tearDown() + { + delete this->_example; + } + +}; + +class GslSplinerValarrayFloatTest : public GslSplinerValarrayTest +{ + CPPUNIT_TEST_SUITE( GslSplinerValarrayFloatTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class GslSplinerValarrayDoubleTest : public GslSplinerValarrayTest +{ + CPPUNIT_TEST_SUITE( GslSplinerValarrayDoubleTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class GslSplinerValarrayLongDoubleTest : public GslSplinerValarrayTest +{ + CPPUNIT_TEST_SUITE( GslSplinerValarrayLongDoubleTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerValarrayFloatTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerValarrayDoubleTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerValarrayLongDoubleTest ); + +//---------------------------------------------------------------------- +// Eigen tests +//---------------------------------------------------------------------- +#ifdef ANTIOCH_HAVE_EIGEN + +template +class GslSplinerEigenTest : public GSLSplinerVecTest > +{ +public: + virtual void setUp() + { + this->init_vec_data(); + this->_example = new Eigen::Array(); + } + + virtual void tearDown() + { + delete this->_example; + } +}; + +class GslSplinerEigenFloatTest : public GslSplinerEigenTest +{ + CPPUNIT_TEST_SUITE( GslSplinerEigenFloatTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class GslSplinerEigenDoubleTest : public GslSplinerEigenTest +{ + CPPUNIT_TEST_SUITE( GslSplinerEigenDoubleTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class GslSplinerEigenLongDoubleTest : public GslSplinerEigenTest +{ + CPPUNIT_TEST_SUITE( GslSplinerEigenLongDoubleTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerEigenFloatTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerEigenDoubleTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerEigenLongDoubleTest ); + +#endif // ANTIOCH_HAVE_EIGEN + + +//---------------------------------------------------------------------- +// MetaPhysicL tests +//---------------------------------------------------------------------- +#ifdef ANTIOCH_HAVE_METAPHYSICL + +template +class GslSplinerMetaPhysicLTest : public GSLSplinerVecTest > +{ +public: + virtual void setUp() + { + this->init_vec_data(); + this->_example = new MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES,Scalar>(0); + } + + virtual void tearDown() + { + delete this->_example; + } +}; + +class GslSplinerMetaPhysicLFloatTest : public GslSplinerMetaPhysicLTest +{ + CPPUNIT_TEST_SUITE( GslSplinerMetaPhysicLFloatTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class GslSplinerMetaPhysicLDoubleTest : public GslSplinerMetaPhysicLTest +{ + CPPUNIT_TEST_SUITE( GslSplinerMetaPhysicLDoubleTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); +}; + +class GslSplinerMetaPhysicLLongDoubleTest : public GslSplinerMetaPhysicLTest +{ + CPPUNIT_TEST_SUITE( GslSplinerMetaPhysicLLongDoubleTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerMetaPhysicLFloatTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerMetaPhysicLDoubleTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerMetaPhysicLLongDoubleTest ); + +#endif // ANTIOCH_HAVE_METAPHYSICL + + +//---------------------------------------------------------------------- +// VexCL tests +//---------------------------------------------------------------------- +#ifdef ANTIOCH_HAVE_VEXCL + +class GslSplinerVexCLFloatTest : public GSLSplinerVecTest > +{ + CPPUNIT_TEST_SUITE( GslSplinerVexCLFloatTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); + + private: + + vex::Context* _ctx; + +public: + + virtual void setUp() + { + this->init_vec_data(); + _ctx = new vex::Context(vex::Filter::All); + this->_example = new vex::vector(*_ctx, 2*ANTIOCH_N_TUPLES); + } + + virtual void tearDown() + { + delete _ctx; + delete this->_example; + } +}; + +class GslSplinerVexCLDoubleTest : public GSLSplinerVecTest > +{ + CPPUNIT_TEST_SUITE( GslSplinerVexCLDoubleTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); + +private: + + vex::Context* _ctx; + +public: + + virtual void setUp() + { + this->init_vec_data(); + _ctx = new vex::Context(vex::Filter::DoublePrecision); + this->_example = new vex::vector(*_ctx, 2*ANTIOCH_N_TUPLES); + } + + virtual void tearDown() + { + delete _ctx; + delete this->_example; + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerVexCLFloatTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerVexCLDoubleTest ); + +#endif // ANTIOCH_HAVE_VEXCL + +#endif // ANTIOCH_HAVE_CPPUNIT From e811f3ef0254fd3d3783e273da4cb719d367434f Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Fri, 4 Sep 2015 19:13:33 -0400 Subject: [PATCH 25/29] Test naming consistency Made CppUnit-based testing classes more consistent with the naming. Thanks @dmcdougall --- test/standard_unit/arrhenius_rate_test.C | 2 +- test/standard_unit/arrhenius_rate_vector_test_base.h | 2 +- test/standard_unit/reaction_rate_test_base.h | 2 +- test/standard_unit/reaction_rate_vector_test_base.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/standard_unit/arrhenius_rate_test.C b/test/standard_unit/arrhenius_rate_test.C index d7902144..50ee1760 100644 --- a/test/standard_unit/arrhenius_rate_test.C +++ b/test/standard_unit/arrhenius_rate_test.C @@ -42,7 +42,7 @@ using namespace Antioch; template class ArrheniusRateTest : public ArrheniusRateTestHelper, - public ReactionRateBaseTest,Scalar> + public ReactionRateTestBase,Scalar> { public: void setUp() diff --git a/test/standard_unit/arrhenius_rate_vector_test_base.h b/test/standard_unit/arrhenius_rate_vector_test_base.h index 204eb196..a9cac33c 100644 --- a/test/standard_unit/arrhenius_rate_vector_test_base.h +++ b/test/standard_unit/arrhenius_rate_vector_test_base.h @@ -43,7 +43,7 @@ template class ArrheniusRateVectorTestBase : public ArrheniusRateTestHelper::type>, - public ReactionRateVectorBaseTest::type>,PairScalars> + public ReactionRateVectorTestBase::type>,PairScalars> { public: virtual void init() diff --git a/test/standard_unit/reaction_rate_test_base.h b/test/standard_unit/reaction_rate_test_base.h index b80fb643..48c69d30 100644 --- a/test/standard_unit/reaction_rate_test_base.h +++ b/test/standard_unit/reaction_rate_test_base.h @@ -34,7 +34,7 @@ #include template -class ReactionRateBaseTest : public CppUnit::TestCase +class ReactionRateTestBase : public CppUnit::TestCase { public: void test_rate( const ReactionRate& reaction_rate, diff --git a/test/standard_unit/reaction_rate_vector_test_base.h b/test/standard_unit/reaction_rate_vector_test_base.h index 250202e3..19e07552 100644 --- a/test/standard_unit/reaction_rate_vector_test_base.h +++ b/test/standard_unit/reaction_rate_vector_test_base.h @@ -34,7 +34,7 @@ #include template -class ReactionRateVectorBaseTest : public CppUnit::TestCase +class ReactionRateVectorTestBase : public CppUnit::TestCase { public: From 14d4e43b61426f0a7084b863be71bf7125660f20 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Fri, 4 Sep 2015 19:23:05 -0400 Subject: [PATCH 26/29] Drop `using namespace Antioch` from test In preparation for putting the tests in their own namespace. --- test/standard_unit/arrhenius_rate_test.C | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/standard_unit/arrhenius_rate_test.C b/test/standard_unit/arrhenius_rate_test.C index 50ee1760..ce5cc12b 100644 --- a/test/standard_unit/arrhenius_rate_test.C +++ b/test/standard_unit/arrhenius_rate_test.C @@ -38,8 +38,6 @@ #include "arrhenius_rate_test_helper.h" #include "reaction_rate_test_base.h" -using namespace Antioch; - template class ArrheniusRateTest : public ArrheniusRateTestHelper, public ReactionRateTestBase,Scalar> @@ -52,7 +50,7 @@ public: Scalar R = 1.0L; // Ea in K this->reset_params(Cf,Ea,R); - _rate = new ArrheniusRate(Cf,Ea,R); + _rate = new Antioch::ArrheniusRate(Cf,Ea,R); } void tearDown() @@ -73,7 +71,7 @@ public: { Scalar Cf = 1e-7L; Scalar Ea = 36000.L; - Scalar R = Constants::R_universal()*Units("cal").get_SI_factor(); + Scalar R = Antioch::Constants::R_universal()*Antioch::Units("cal").get_SI_factor(); this->reset_params( Cf, Ea, R ); @@ -111,7 +109,7 @@ public: { Scalar Cf = 2.1e-11L; Scalar Ea = 100000.L; - Scalar R = Constants::R_universal(); + Scalar R = Antioch::Constants::R_universal(); this->reset_params( Cf, Ea, R ); @@ -130,7 +128,7 @@ public: protected: - ArrheniusRate* _rate; + Antioch::ArrheniusRate* _rate; virtual Scalar exact_rate( Scalar T ) { From ca4cbd4e2e1cb178d4bb2c96c00cf24ce2e1a00b Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Fri, 4 Sep 2015 19:28:29 -0400 Subject: [PATCH 27/29] Have Doxygen build docs for optional packages In particular so we can see the CppUnit testing hierarchies. --- doxygen/antioch.dox.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doxygen/antioch.dox.in b/doxygen/antioch.dox.in index 605f2b8c..af8c770e 100644 --- a/doxygen/antioch.dox.in +++ b/doxygen/antioch.dox.in @@ -1263,7 +1263,11 @@ INCLUDE_FILE_PATTERNS = # undefined via #undef or recursively expanded use the := operator # instead of the = operator. -PREDEFINED = +PREDEFINED = ANTIOCH_HAVE_CPPUNIT \ + ANTIOCH_HAVE_EIGEN \ + ANTIOCH_HAVE_METAPHYSICL \ + ANTIOCH_HAVE_VEXCL \ + ATNIOCH_HAVE_GSL # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. From 1e3f3e4fbe828c243370bbd211fef09d071fd96d Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Fri, 4 Sep 2015 19:39:42 -0400 Subject: [PATCH 28/29] Put all CppUnit testing in separate namespace Use AntiochTesting as the namespace for all the testing. This helps in the Doxygen documentation. Bracket needs to go outside VexCL ifdef --- test/eigen_unit/arrhenius_rate_eigen_test.C | 92 +-- test/gsl_unit/gsl_spliner_test.C | 201 +++--- test/gsl_unit/gsl_spliner_test_base.h | 186 +++--- test/gsl_unit/gsl_spliner_vec_test.C | 606 +++++++++--------- .../arrhenius_rate_metaphysicl_test.C | 92 +-- test/standard_unit/arrhenius_rate_test.C | 224 +++---- .../arrhenius_rate_test_helper.h | 55 +- .../arrhenius_rate_valarray_test.C | 92 +-- .../arrhenius_rate_vector_test_base.h | 152 ++--- test/standard_unit/reaction_rate_test_base.h | 122 ++-- .../reaction_rate_vector_test_base.h | 200 +++--- test/vexcl_unit/arrhenius_rate_vexcl_test.C | 102 +-- 12 files changed, 1086 insertions(+), 1038 deletions(-) diff --git a/test/eigen_unit/arrhenius_rate_eigen_test.C b/test/eigen_unit/arrhenius_rate_eigen_test.C index 823d955e..3edebd64 100644 --- a/test/eigen_unit/arrhenius_rate_eigen_test.C +++ b/test/eigen_unit/arrhenius_rate_eigen_test.C @@ -39,67 +39,71 @@ #include "arrhenius_rate_vector_test_base.h" #include "antioch/eigen_utils.h" -template -class ArrheniusRateEigenTest : public ArrheniusRateVectorTestBase > +namespace AntiochTesting { -public: - - virtual void setUp() + template + class ArrheniusRateEigenTest : public ArrheniusRateVectorTestBase > { - this->init(); - this->_example = new Eigen::Array(); - } + public: - virtual void tearDown() - { - this->clear(); - delete this->_example; - } + virtual void setUp() + { + this->init(); + this->_example = new Eigen::Array(); + } -}; + virtual void tearDown() + { + this->clear(); + delete this->_example; + } -class ArrheniusRateEigenFloatTest : public ArrheniusRateEigenTest -{ -public: + }; - CPPUNIT_TEST_SUITE( ArrheniusRateEigenFloatTest ); + class ArrheniusRateEigenFloatTest : public ArrheniusRateEigenTest + { + public: - CPPUNIT_TEST( test_standard_rate ); - CPPUNIT_TEST( test_standard_deriv ); - CPPUNIT_TEST( test_standard_rate_and_deriv ); + CPPUNIT_TEST_SUITE( ArrheniusRateEigenFloatTest ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); -class ArrheniusRateEigenDoubleTest : public ArrheniusRateEigenTest -{ -public: + CPPUNIT_TEST_SUITE_END(); + }; - CPPUNIT_TEST_SUITE( ArrheniusRateEigenDoubleTest ); + class ArrheniusRateEigenDoubleTest : public ArrheniusRateEigenTest + { + public: - CPPUNIT_TEST( test_standard_rate ); - CPPUNIT_TEST( test_standard_deriv ); - CPPUNIT_TEST( test_standard_rate_and_deriv ); + CPPUNIT_TEST_SUITE( ArrheniusRateEigenDoubleTest ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); -class ArrheniusRateEigenLongDoubleTest : public ArrheniusRateEigenTest -{ -public: + CPPUNIT_TEST_SUITE_END(); + }; + + class ArrheniusRateEigenLongDoubleTest : public ArrheniusRateEigenTest + { + public: + + CPPUNIT_TEST_SUITE( ArrheniusRateEigenLongDoubleTest ); - CPPUNIT_TEST_SUITE( ArrheniusRateEigenLongDoubleTest ); + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); - CPPUNIT_TEST( test_standard_rate ); - CPPUNIT_TEST( test_standard_deriv ); - CPPUNIT_TEST( test_standard_rate_and_deriv ); + CPPUNIT_TEST_SUITE_END(); + }; - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateEigenFloatTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateEigenDoubleTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateEigenLongDoubleTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateEigenFloatTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateEigenDoubleTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateEigenLongDoubleTest ); +} // end namespace AntiochTesting #endif // ANTIOCH_HAVE_EIGEN diff --git a/test/gsl_unit/gsl_spliner_test.C b/test/gsl_unit/gsl_spliner_test.C index c07baf6d..e204efba 100644 --- a/test/gsl_unit/gsl_spliner_test.C +++ b/test/gsl_unit/gsl_spliner_test.C @@ -39,134 +39,137 @@ // Base class #include "gsl_spliner_test_base.h" -template -class GSLSplinerTest : public GSLSplinerTestBase +namespace AntiochTesting { -public: - - void setUp() + template + class GSLSplinerTest : public GSLSplinerTestBase { - this->init_data(); - } + public: - // Helper function - template - void run_manually_inited_test( Scalar tol ) - { - FunctionType exact_func; - exact_func.init(this->_x_min, this->_x_max); + void setUp() + { + this->init_data(); + } - this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); + // Helper function + template + void run_manually_inited_test( Scalar tol ) + { + FunctionType exact_func; + exact_func.init(this->_x_min, this->_x_max); - Antioch::GSLSpliner spline; - spline.spline_init(this->_x_ref, this->_y_ref); + this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); - this->compare_values( tol, spline, exact_func ); - } + Antioch::GSLSpliner spline; + spline.spline_init(this->_x_ref, this->_y_ref); - // Helper function - template - void run_constructor_inited_test( Scalar tol ) - { - FunctionType exact_func; - exact_func.init(this->_x_min, this->_x_max); + this->compare_values( tol, spline, exact_func ); + } - this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); + // Helper function + template + void run_constructor_inited_test( Scalar tol ) + { + FunctionType exact_func; + exact_func.init(this->_x_min, this->_x_max); - Antioch::GSLSpliner spline(this->_x_ref, this->_y_ref); + this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); - this->compare_values( tol, spline, exact_func ); - } + Antioch::GSLSpliner spline(this->_x_ref, this->_y_ref); - // Helper function - void compare_values( Scalar tol, Antioch::GSLSpliner& spline, GSLSplinerTestFunction& exact_func ) - { - for(unsigned int n = 0; n < this->_n_test; n++) - { - Scalar x = this->_x_min + (Scalar)(n) * (this->_x_max - this->_x_min) / (Scalar)(this->_n_test-1); - Scalar exact_value = exact_func(x); - Scalar interp_value = spline.interpolated_value(x); - CPPUNIT_ASSERT_DOUBLES_EQUAL( interp_value, - exact_value, - tol ); - } - } - - void test_manually_inited_spline_constant_func() - { - const Scalar tol = std::numeric_limits::epsilon() * 10; + this->compare_values( tol, spline, exact_func ); + } - this->run_manually_inited_test >(tol); - } + // Helper function + void compare_values( Scalar tol, Antioch::GSLSpliner& spline, GSLSplinerTestFunction& exact_func ) + { + for(unsigned int n = 0; n < this->_n_test; n++) + { + Scalar x = this->_x_min + (Scalar)(n) * (this->_x_max - this->_x_min) / (Scalar)(this->_n_test-1); + Scalar exact_value = exact_func(x); + Scalar interp_value = spline.interpolated_value(x); + CPPUNIT_ASSERT_DOUBLES_EQUAL( interp_value, + exact_value, + tol ); + } + } - void test_constructor_inited_spline_constant_func() - { - const Scalar tol = std::numeric_limits::epsilon() * 10; + void test_manually_inited_spline_constant_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 10; - this->run_constructor_inited_test >(tol); - } + this->run_manually_inited_test >(tol); + } - void test_manually_inited_spline_linear_func() - { - const Scalar tol = std::numeric_limits::epsilon() * 50; + void test_constructor_inited_spline_constant_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 10; - this->run_manually_inited_test >(tol); - } + this->run_constructor_inited_test >(tol); + } - void test_constructor_inited_spline_linear_func() - { - const Scalar tol = std::numeric_limits::epsilon() * 50; + void test_manually_inited_spline_linear_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; - this->run_constructor_inited_test >(tol); - } + this->run_manually_inited_test >(tol); + } - void test_manually_inited_spline_cubic_func() - { - const Scalar tol = std::numeric_limits::epsilon() * 50; + void test_constructor_inited_spline_linear_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; - this->run_manually_inited_test >(tol); - } + this->run_constructor_inited_test >(tol); + } - void test_constructor_inited_spline_cubic_func() - { - const Scalar tol = std::numeric_limits::epsilon() * 50; + void test_manually_inited_spline_cubic_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; - this->run_constructor_inited_test >(tol); - } -}; + this->run_manually_inited_test >(tol); + } -class GslSplinerFloatTest : public GSLSplinerTest -{ -public: - CPPUNIT_TEST_SUITE( GslSplinerFloatTest ); + void test_constructor_inited_spline_cubic_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; + + this->run_constructor_inited_test >(tol); + } + }; - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + class GslSplinerFloatTest : public GSLSplinerTest + { + public: + CPPUNIT_TEST_SUITE( GslSplinerFloatTest ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); -class GslSplinerDoubleTest : public GSLSplinerTest -{ -public: - CPPUNIT_TEST_SUITE( GslSplinerDoubleTest ); + CPPUNIT_TEST_SUITE_END(); + }; + + class GslSplinerDoubleTest : public GSLSplinerTest + { + public: + CPPUNIT_TEST_SUITE( GslSplinerDoubleTest ); - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST_SUITE_END(); + }; -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerFloatTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerDoubleTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerFloatTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerDoubleTest ); +} // end namespace AntiochTesting #endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/gsl_unit/gsl_spliner_test_base.h b/test/gsl_unit/gsl_spliner_test_base.h index 91259666..b86241bd 100644 --- a/test/gsl_unit/gsl_spliner_test_base.h +++ b/test/gsl_unit/gsl_spliner_test_base.h @@ -33,109 +33,113 @@ #include #include -template -struct GSLSplinerTestFunction +namespace AntiochTesting { - typedef typename Antioch::value_type::type Scalar; + template + struct GSLSplinerTestFunction + { + typedef typename Antioch::value_type::type Scalar; - virtual PairScalars operator()( const PairScalars x ) =0; + virtual PairScalars operator()( const PairScalars x ) =0; - void init( Scalar x_min, Scalar x_max ) - { - _x_min = x_min; - _x_max = x_max; - }; + void init( Scalar x_min, Scalar x_max ) + { + _x_min = x_min; + _x_max = x_max; + }; -protected: - Scalar _x_min, _x_max; -}; + protected: + Scalar _x_min, _x_max; + }; -template -struct ConstantTestFunction : public GSLSplinerTestFunction -{ - virtual Scalar operator()( const Scalar x ) + template + struct ConstantTestFunction : public GSLSplinerTestFunction { - // Scalar may actually be a PairScalar, so do this to handle those cases too. - return Antioch::constant_clone(x,10); - } -}; + virtual Scalar operator()( const Scalar x ) + { + // Scalar may actually be a PairScalar, so do this to handle those cases too. + return Antioch::constant_clone(x,10); + } + }; -template -struct LinearTestFunction : public GSLSplinerTestFunction -{ - virtual Scalar operator()( const Scalar x ) + template + struct LinearTestFunction : public GSLSplinerTestFunction { - // Scalar may actually be a PairScalar, so do this to handle those cases too. - Scalar ten = Antioch::constant_clone(x,10); - Scalar five = Antioch::constant_clone(x,5); - - return ten + five * x; - } -}; + virtual Scalar operator()( const Scalar x ) + { + // Scalar may actually be a PairScalar, so do this to handle those cases too. + Scalar ten = Antioch::constant_clone(x,10); + Scalar five = Antioch::constant_clone(x,5); + + return ten + five * x; + } + }; -template -struct CubicTestFunction : public GSLSplinerTestFunction -{ - virtual Scalar operator()( const Scalar x ) + template + struct CubicTestFunction : public GSLSplinerTestFunction { - // Scalar may actually be a PairScalar, so do this to handle those cases too. - Scalar one = Antioch::constant_clone(x,1); - Scalar two = Antioch::constant_clone(x,2); - Scalar three = Antioch::constant_clone(x,3); - Scalar xmin = Antioch::constant_clone(x,this->_x_min); - Scalar xmax = Antioch::constant_clone(x,this->_x_max); - - Scalar t = (x-xmin)/(xmax-xmin); - - // Constructing cubit hermite that interpolates xmin/xmax - // and has second derivatives of 0 at xmin,xmax - // Turns out you need first derivatives = 1 at the end points - Scalar t2 = t*t; - Scalar t3 = t*t*t; - Scalar h00 = two*t3 - three*t2 + one; - Scalar h10 = t3 - two*t2 + t; - Scalar h01 = -two*t3 + three*t2; - Scalar h11 = t3 - t2; - - return h00*xmin + h10*(xmax-xmin) + h01*xmax + h11*(xmax-xmin); - } -}; - -template -class GSLSplinerTestBase : public CppUnit::TestCase -{ -public: + virtual Scalar operator()( const Scalar x ) + { + // Scalar may actually be a PairScalar, so do this to handle those cases too. + Scalar one = Antioch::constant_clone(x,1); + Scalar two = Antioch::constant_clone(x,2); + Scalar three = Antioch::constant_clone(x,3); + Scalar xmin = Antioch::constant_clone(x,this->_x_min); + Scalar xmax = Antioch::constant_clone(x,this->_x_max); + + Scalar t = (x-xmin)/(xmax-xmin); + + // Constructing cubit hermite that interpolates xmin/xmax + // and has second derivatives of 0 at xmin,xmax + // Turns out you need first derivatives = 1 at the end points + Scalar t2 = t*t; + Scalar t3 = t*t*t; + Scalar h00 = two*t3 - three*t2 + one; + Scalar h10 = t3 - two*t2 + t; + Scalar h01 = -two*t3 + three*t2; + Scalar h11 = t3 - t2; + + return h00*xmin + h10*(xmax-xmin) + h01*xmax + h11*(xmax-xmin); + } + }; - void init_data() + template + class GSLSplinerTestBase : public CppUnit::TestCase { - _n_data = 40; - _n_test = 39; - _x_ref.resize(_n_data); - _y_ref.resize(_n_data); - _x_min = -5.0L; - _x_max = 8.0L; - } - - void fill_ref(std::vector& x_ref, std::vector& y_ref, - unsigned int n_data, const Scalar& x_min, const Scalar& x_max, - GSLSplinerTestFunction& exact_func) - { - for(unsigned int i = 0; i < n_data; i++) - { - x_ref[i] = x_min + (Scalar)(i) * (x_max - x_min) / (Scalar)(n_data-1); - y_ref[i] = exact_func(x_ref[i]); - } - } - -protected: - - unsigned int _n_data; - unsigned int _n_test; - Scalar _x_min; - Scalar _x_max; - std::vector _x_ref; - std::vector _y_ref; -}; + public: + + void init_data() + { + _n_data = 40; + _n_test = 39; + _x_ref.resize(_n_data); + _y_ref.resize(_n_data); + _x_min = -5.0L; + _x_max = 8.0L; + } + + void fill_ref(std::vector& x_ref, std::vector& y_ref, + unsigned int n_data, const Scalar& x_min, const Scalar& x_max, + GSLSplinerTestFunction& exact_func) + { + for(unsigned int i = 0; i < n_data; i++) + { + x_ref[i] = x_min + (Scalar)(i) * (x_max - x_min) / (Scalar)(n_data-1); + y_ref[i] = exact_func(x_ref[i]); + } + } + + protected: + + unsigned int _n_data; + unsigned int _n_test; + Scalar _x_min; + Scalar _x_max; + std::vector _x_ref; + std::vector _y_ref; + }; + +} // end namespace AntiochTesting #endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/gsl_unit/gsl_spliner_vec_test.C b/test/gsl_unit/gsl_spliner_vec_test.C index c413aca3..d6e3b351 100644 --- a/test/gsl_unit/gsl_spliner_vec_test.C +++ b/test/gsl_unit/gsl_spliner_vec_test.C @@ -59,407 +59,411 @@ // Base class #include "gsl_spliner_test_base.h" -template -class GSLSplinerVecTest : public GSLSplinerTestBase::type> +namespace AntiochTesting { -public: - - typedef typename Antioch::value_type::type Scalar; - - void init_vec_data() + template + class GSLSplinerVecTest : public GSLSplinerTestBase::type> { - this->init_data(); - } + public: - // Helper function - template - void run_manually_inited_test( Scalar tol ) - { - ScalarFunctionType exact_func; - exact_func.init(this->_x_min, this->_x_max); + typedef typename Antioch::value_type::type Scalar; - this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); + void init_vec_data() + { + this->init_data(); + } - Antioch::GSLSpliner spline; - spline.spline_init(this->_x_ref, this->_y_ref); + // Helper function + template + void run_manually_inited_test( Scalar tol ) + { + ScalarFunctionType exact_func; + exact_func.init(this->_x_min, this->_x_max); - VecFunctionType vec_exact_func; - vec_exact_func.init(this->_x_min, this->_x_max); + this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); - this->compare_values( tol, spline, vec_exact_func ); - } + Antioch::GSLSpliner spline; + spline.spline_init(this->_x_ref, this->_y_ref); - // Helper function - template - void run_constructor_inited_test( Scalar tol ) - { - ScalarFunctionType exact_func; - exact_func.init(this->_x_min, this->_x_max); + VecFunctionType vec_exact_func; + vec_exact_func.init(this->_x_min, this->_x_max); - this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); + this->compare_values( tol, spline, vec_exact_func ); + } - Antioch::GSLSpliner spline(this->_x_ref, this->_y_ref); + // Helper function + template + void run_constructor_inited_test( Scalar tol ) + { + ScalarFunctionType exact_func; + exact_func.init(this->_x_min, this->_x_max); - VecFunctionType vec_exact_func; - vec_exact_func.init(this->_x_min, this->_x_max); + this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func ); - this->compare_values( tol, spline, vec_exact_func ); - } + Antioch::GSLSpliner spline(this->_x_ref, this->_y_ref); - // Helper function - void compare_values( Scalar tol, - Antioch::GSLSpliner& spline, - GSLSplinerTestFunction& exact_func) - { - // Construct from example to avoid resizing issues - PairScalars x = *(this->_example); + VecFunctionType vec_exact_func; + vec_exact_func.init(this->_x_min, this->_x_max); - for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) - { - x[2*tuple] = -3.5; - x[2*tuple+1] = 5.1; - } + this->compare_values( tol, spline, vec_exact_func ); + } - const PairScalars gsl_value = spline.interpolated_value(x); + // Helper function + void compare_values( Scalar tol, + Antioch::GSLSpliner& spline, + GSLSplinerTestFunction& exact_func) + { + // Construct from example to avoid resizing issues + PairScalars x = *(this->_example); - const PairScalars exact_value = exact_func(x); + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + x[2*tuple] = -3.5; + x[2*tuple+1] = 5.1; + } - for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) - { - CPPUNIT_ASSERT_DOUBLES_EQUAL( gsl_value[2*tuple], - exact_value[2*tuple], - tol ); - } - } + const PairScalars gsl_value = spline.interpolated_value(x); - void test_manually_inited_spline_constant_func() - { - const Scalar tol = std::numeric_limits::epsilon() * 10; + const PairScalars exact_value = exact_func(x); - this->run_manually_inited_test,ConstantTestFunction >(tol); - } + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL( gsl_value[2*tuple], + exact_value[2*tuple], + tol ); + } + } - void test_constructor_inited_spline_constant_func() - { - const Scalar tol = std::numeric_limits::epsilon() * 10; + void test_manually_inited_spline_constant_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 10; - this->run_constructor_inited_test,ConstantTestFunction >(tol); - } + this->run_manually_inited_test,ConstantTestFunction >(tol); + } - void test_manually_inited_spline_linear_func() - { - const Scalar tol = std::numeric_limits::epsilon() * 50; + void test_constructor_inited_spline_constant_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 10; - this->run_manually_inited_test,LinearTestFunction >(tol); - } + this->run_constructor_inited_test,ConstantTestFunction >(tol); + } - void test_constructor_inited_spline_linear_func() - { - const Scalar tol = std::numeric_limits::epsilon() * 50; + void test_manually_inited_spline_linear_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; - this->run_constructor_inited_test,LinearTestFunction >(tol); - } + this->run_manually_inited_test,LinearTestFunction >(tol); + } - void test_manually_inited_spline_cubic_func() - { - const Scalar tol = std::numeric_limits::epsilon() * 50; + void test_constructor_inited_spline_linear_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; - this->run_manually_inited_test,CubicTestFunction >(tol); - } + this->run_constructor_inited_test,LinearTestFunction >(tol); + } - void test_constructor_inited_spline_cubic_func() - { - const Scalar tol = std::numeric_limits::epsilon() * 50; + void test_manually_inited_spline_cubic_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; - this->run_constructor_inited_test,CubicTestFunction >(tol); - } + this->run_manually_inited_test,CubicTestFunction >(tol); + } -protected: - // Should be new'd/deleted in subclasses for each PairScalar type - PairScalars* _example; -}; + void test_constructor_inited_spline_cubic_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; -//---------------------------------------------------------------------- -// valarray tests -//---------------------------------------------------------------------- -template -class GslSplinerValarrayTest : public GSLSplinerVecTest > -{ -public: + this->run_constructor_inited_test,CubicTestFunction >(tol); + } - virtual void setUp() - { - this->init_vec_data(); - this->_example = new std::valarray(2*ANTIOCH_N_TUPLES); - } + protected: + // Should be new'd/deleted in subclasses for each PairScalar type + PairScalars* _example; + }; - virtual void tearDown() + //---------------------------------------------------------------------- + // valarray tests + //---------------------------------------------------------------------- + template + class GslSplinerValarrayTest : public GSLSplinerVecTest > { - delete this->_example; - } + public: -}; + virtual void setUp() + { + this->init_vec_data(); + this->_example = new std::valarray(2*ANTIOCH_N_TUPLES); + } -class GslSplinerValarrayFloatTest : public GslSplinerValarrayTest -{ - CPPUNIT_TEST_SUITE( GslSplinerValarrayFloatTest ); + virtual void tearDown() + { + delete this->_example; + } - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + }; - CPPUNIT_TEST_SUITE_END(); -}; + class GslSplinerValarrayFloatTest : public GslSplinerValarrayTest + { + CPPUNIT_TEST_SUITE( GslSplinerValarrayFloatTest ); -class GslSplinerValarrayDoubleTest : public GslSplinerValarrayTest -{ - CPPUNIT_TEST_SUITE( GslSplinerValarrayDoubleTest ); + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST_SUITE_END(); + }; - CPPUNIT_TEST_SUITE_END(); -}; + class GslSplinerValarrayDoubleTest : public GslSplinerValarrayTest + { + CPPUNIT_TEST_SUITE( GslSplinerValarrayDoubleTest ); -class GslSplinerValarrayLongDoubleTest : public GslSplinerValarrayTest -{ - CPPUNIT_TEST_SUITE( GslSplinerValarrayLongDoubleTest ); + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST_SUITE_END(); + }; - CPPUNIT_TEST_SUITE_END(); -}; + class GslSplinerValarrayLongDoubleTest : public GslSplinerValarrayTest + { + CPPUNIT_TEST_SUITE( GslSplinerValarrayLongDoubleTest ); + + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + + CPPUNIT_TEST_SUITE_END(); + }; -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerValarrayFloatTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerValarrayDoubleTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerValarrayLongDoubleTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerValarrayFloatTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerValarrayDoubleTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerValarrayLongDoubleTest ); -//---------------------------------------------------------------------- -// Eigen tests -//---------------------------------------------------------------------- + //---------------------------------------------------------------------- + // Eigen tests + //---------------------------------------------------------------------- #ifdef ANTIOCH_HAVE_EIGEN -template -class GslSplinerEigenTest : public GSLSplinerVecTest > -{ -public: - virtual void setUp() + template + class GslSplinerEigenTest : public GSLSplinerVecTest > { - this->init_vec_data(); - this->_example = new Eigen::Array(); - } - - virtual void tearDown() + public: + virtual void setUp() + { + this->init_vec_data(); + this->_example = new Eigen::Array(); + } + + virtual void tearDown() + { + delete this->_example; + } + }; + + class GslSplinerEigenFloatTest : public GslSplinerEigenTest { - delete this->_example; - } -}; + CPPUNIT_TEST_SUITE( GslSplinerEigenFloatTest ); -class GslSplinerEigenFloatTest : public GslSplinerEigenTest -{ - CPPUNIT_TEST_SUITE( GslSplinerEigenFloatTest ); + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST_SUITE_END(); + }; - CPPUNIT_TEST_SUITE_END(); -}; - -class GslSplinerEigenDoubleTest : public GslSplinerEigenTest -{ - CPPUNIT_TEST_SUITE( GslSplinerEigenDoubleTest ); + class GslSplinerEigenDoubleTest : public GslSplinerEigenTest + { + CPPUNIT_TEST_SUITE( GslSplinerEigenDoubleTest ); - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST_SUITE_END(); + }; -class GslSplinerEigenLongDoubleTest : public GslSplinerEigenTest -{ - CPPUNIT_TEST_SUITE( GslSplinerEigenLongDoubleTest ); + class GslSplinerEigenLongDoubleTest : public GslSplinerEigenTest + { + CPPUNIT_TEST_SUITE( GslSplinerEigenLongDoubleTest ); - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST_SUITE_END(); + }; -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerEigenFloatTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerEigenDoubleTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerEigenLongDoubleTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerEigenFloatTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerEigenDoubleTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerEigenLongDoubleTest ); #endif // ANTIOCH_HAVE_EIGEN -//---------------------------------------------------------------------- -// MetaPhysicL tests -//---------------------------------------------------------------------- + //---------------------------------------------------------------------- + // MetaPhysicL tests + //---------------------------------------------------------------------- #ifdef ANTIOCH_HAVE_METAPHYSICL -template -class GslSplinerMetaPhysicLTest : public GSLSplinerVecTest > -{ -public: - virtual void setUp() + template + class GslSplinerMetaPhysicLTest : public GSLSplinerVecTest > { - this->init_vec_data(); - this->_example = new MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES,Scalar>(0); - } - - virtual void tearDown() + public: + virtual void setUp() + { + this->init_vec_data(); + this->_example = new MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES,Scalar>(0); + } + + virtual void tearDown() + { + delete this->_example; + } + }; + + class GslSplinerMetaPhysicLFloatTest : public GslSplinerMetaPhysicLTest { - delete this->_example; - } -}; - -class GslSplinerMetaPhysicLFloatTest : public GslSplinerMetaPhysicLTest -{ - CPPUNIT_TEST_SUITE( GslSplinerMetaPhysicLFloatTest ); + CPPUNIT_TEST_SUITE( GslSplinerMetaPhysicLFloatTest ); - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST_SUITE_END(); + }; -class GslSplinerMetaPhysicLDoubleTest : public GslSplinerMetaPhysicLTest -{ - CPPUNIT_TEST_SUITE( GslSplinerMetaPhysicLDoubleTest ); + class GslSplinerMetaPhysicLDoubleTest : public GslSplinerMetaPhysicLTest + { + CPPUNIT_TEST_SUITE( GslSplinerMetaPhysicLDoubleTest ); - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST_SUITE_END(); + }; -class GslSplinerMetaPhysicLLongDoubleTest : public GslSplinerMetaPhysicLTest -{ - CPPUNIT_TEST_SUITE( GslSplinerMetaPhysicLLongDoubleTest ); + class GslSplinerMetaPhysicLLongDoubleTest : public GslSplinerMetaPhysicLTest + { + CPPUNIT_TEST_SUITE( GslSplinerMetaPhysicLLongDoubleTest ); - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST_SUITE_END(); + }; -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerMetaPhysicLFloatTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerMetaPhysicLDoubleTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerMetaPhysicLLongDoubleTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerMetaPhysicLFloatTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerMetaPhysicLDoubleTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerMetaPhysicLLongDoubleTest ); #endif // ANTIOCH_HAVE_METAPHYSICL -//---------------------------------------------------------------------- -// VexCL tests -//---------------------------------------------------------------------- + //---------------------------------------------------------------------- + // VexCL tests + //---------------------------------------------------------------------- #ifdef ANTIOCH_HAVE_VEXCL -class GslSplinerVexCLFloatTest : public GSLSplinerVecTest > -{ - CPPUNIT_TEST_SUITE( GslSplinerVexCLFloatTest ); + class GslSplinerVexCLFloatTest : public GSLSplinerVecTest > + { + CPPUNIT_TEST_SUITE( GslSplinerVexCLFloatTest ); - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE_END(); private: - vex::Context* _ctx; + vex::Context* _ctx; -public: + public: - virtual void setUp() - { - this->init_vec_data(); - _ctx = new vex::Context(vex::Filter::All); - this->_example = new vex::vector(*_ctx, 2*ANTIOCH_N_TUPLES); - } + virtual void setUp() + { + this->init_vec_data(); + _ctx = new vex::Context(vex::Filter::All); + this->_example = new vex::vector(*_ctx, 2*ANTIOCH_N_TUPLES); + } - virtual void tearDown() - { - delete _ctx; - delete this->_example; - } -}; + virtual void tearDown() + { + delete _ctx; + delete this->_example; + } + }; -class GslSplinerVexCLDoubleTest : public GSLSplinerVecTest > -{ - CPPUNIT_TEST_SUITE( GslSplinerVexCLDoubleTest ); + class GslSplinerVexCLDoubleTest : public GSLSplinerVecTest > + { + CPPUNIT_TEST_SUITE( GslSplinerVexCLDoubleTest ); - CPPUNIT_TEST( test_manually_inited_spline_constant_func ); - CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); - CPPUNIT_TEST( test_manually_inited_spline_linear_func ); - CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); - CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); - CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); + CPPUNIT_TEST( test_manually_inited_spline_constant_func ); + CPPUNIT_TEST( test_constructor_inited_spline_constant_func ); + CPPUNIT_TEST( test_manually_inited_spline_linear_func ); + CPPUNIT_TEST( test_constructor_inited_spline_linear_func ); + CPPUNIT_TEST( test_manually_inited_spline_cubic_func ); + CPPUNIT_TEST( test_constructor_inited_spline_cubic_func ); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE_END(); -private: + private: - vex::Context* _ctx; + vex::Context* _ctx; -public: + public: - virtual void setUp() - { - this->init_vec_data(); - _ctx = new vex::Context(vex::Filter::DoublePrecision); - this->_example = new vex::vector(*_ctx, 2*ANTIOCH_N_TUPLES); - } + virtual void setUp() + { + this->init_vec_data(); + _ctx = new vex::Context(vex::Filter::DoublePrecision); + this->_example = new vex::vector(*_ctx, 2*ANTIOCH_N_TUPLES); + } - virtual void tearDown() - { - delete _ctx; - delete this->_example; - } -}; + virtual void tearDown() + { + delete _ctx; + delete this->_example; + } + }; -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerVexCLFloatTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerVexCLDoubleTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerVexCLFloatTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerVexCLDoubleTest ); #endif // ANTIOCH_HAVE_VEXCL +} // end namespace AntiochTesting + #endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/metaphysicl_unit/arrhenius_rate_metaphysicl_test.C b/test/metaphysicl_unit/arrhenius_rate_metaphysicl_test.C index 63768d9a..0b9293e4 100644 --- a/test/metaphysicl_unit/arrhenius_rate_metaphysicl_test.C +++ b/test/metaphysicl_unit/arrhenius_rate_metaphysicl_test.C @@ -39,67 +39,71 @@ #include "arrhenius_rate_vector_test_base.h" #include "antioch/metaphysicl_utils.h" -template -class ArrheniusRateMetaPhysicLTest : public ArrheniusRateVectorTestBase > +namespace AntiochTesting { -public: - - virtual void setUp() + template + class ArrheniusRateMetaPhysicLTest : public ArrheniusRateVectorTestBase > { - this->init(); - this->_example = new MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float>(0); - } + public: - virtual void tearDown() - { - this->clear(); - delete this->_example; - } + virtual void setUp() + { + this->init(); + this->_example = new MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float>(0); + } -}; + virtual void tearDown() + { + this->clear(); + delete this->_example; + } -class ArrheniusRateMetaPhysicLFloatTest : public ArrheniusRateMetaPhysicLTest -{ -public: + }; - CPPUNIT_TEST_SUITE( ArrheniusRateMetaPhysicLFloatTest ); + class ArrheniusRateMetaPhysicLFloatTest : public ArrheniusRateMetaPhysicLTest + { + public: - CPPUNIT_TEST( test_standard_rate ); - CPPUNIT_TEST( test_standard_deriv ); - CPPUNIT_TEST( test_standard_rate_and_deriv ); + CPPUNIT_TEST_SUITE( ArrheniusRateMetaPhysicLFloatTest ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); -class ArrheniusRateMetaPhysicLDoubleTest : public ArrheniusRateMetaPhysicLTest -{ -public: + CPPUNIT_TEST_SUITE_END(); + }; - CPPUNIT_TEST_SUITE( ArrheniusRateMetaPhysicLDoubleTest ); + class ArrheniusRateMetaPhysicLDoubleTest : public ArrheniusRateMetaPhysicLTest + { + public: - CPPUNIT_TEST( test_standard_rate ); - CPPUNIT_TEST( test_standard_deriv ); - CPPUNIT_TEST( test_standard_rate_and_deriv ); + CPPUNIT_TEST_SUITE( ArrheniusRateMetaPhysicLDoubleTest ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); -class ArrheniusRateMetaPhysicLLongDoubleTest : public ArrheniusRateMetaPhysicLTest -{ -public: + CPPUNIT_TEST_SUITE_END(); + }; + + class ArrheniusRateMetaPhysicLLongDoubleTest : public ArrheniusRateMetaPhysicLTest + { + public: + + CPPUNIT_TEST_SUITE( ArrheniusRateMetaPhysicLLongDoubleTest ); - CPPUNIT_TEST_SUITE( ArrheniusRateMetaPhysicLLongDoubleTest ); + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); - CPPUNIT_TEST( test_standard_rate ); - CPPUNIT_TEST( test_standard_deriv ); - CPPUNIT_TEST( test_standard_rate_and_deriv ); + CPPUNIT_TEST_SUITE_END(); + }; - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateMetaPhysicLFloatTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateMetaPhysicLDoubleTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateMetaPhysicLLongDoubleTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateMetaPhysicLFloatTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateMetaPhysicLDoubleTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateMetaPhysicLLongDoubleTest ); +} // end namespace AntiochTesting #endif // ANTIOCH_HAVE_METAPHYSICL diff --git a/test/standard_unit/arrhenius_rate_test.C b/test/standard_unit/arrhenius_rate_test.C index ce5cc12b..98794068 100644 --- a/test/standard_unit/arrhenius_rate_test.C +++ b/test/standard_unit/arrhenius_rate_test.C @@ -38,151 +38,155 @@ #include "arrhenius_rate_test_helper.h" #include "reaction_rate_test_base.h" -template -class ArrheniusRateTest : public ArrheniusRateTestHelper, - public ReactionRateTestBase,Scalar> +namespace AntiochTesting { -public: - void setUp() + template + class ArrheniusRateTest : public ArrheniusRateTestHelper, + public ReactionRateTestBase,Scalar> { - Scalar Cf = 1.4L; - Scalar Ea = 298.0L; - Scalar R = 1.0L; // Ea in K + public: + void setUp() + { + Scalar Cf = 1.4L; + Scalar Ea = 298.0L; + Scalar R = 1.0L; // Ea in K - this->reset_params(Cf,Ea,R); - _rate = new Antioch::ArrheniusRate(Cf,Ea,R); - } + this->reset_params(Cf,Ea,R); + _rate = new Antioch::ArrheniusRate(Cf,Ea,R); + } - void tearDown() - { - delete _rate; - } + void tearDown() + { + delete _rate; + } - void test_standard() - { - const Scalar tol = std::numeric_limits::epsilon() * 100; + void test_standard() + { + const Scalar tol = std::numeric_limits::epsilon() * 100; - this->test_rate( *_rate, tol ); - this->test_deriv( *_rate, tol ); - this->test_rate_and_deriv( *_rate, tol ); - } + this->test_rate( *_rate, tol ); + this->test_deriv( *_rate, tol ); + this->test_rate_and_deriv( *_rate, tol ); + } - void test_reset_scalar_params() - { - Scalar Cf = 1e-7L; - Scalar Ea = 36000.L; - Scalar R = Antioch::Constants::R_universal()*Antioch::Units("cal").get_SI_factor(); + void test_reset_scalar_params() + { + Scalar Cf = 1e-7L; + Scalar Ea = 36000.L; + Scalar R = Antioch::Constants::R_universal()*Antioch::Units("cal").get_SI_factor(); - this->reset_params( Cf, Ea, R ); + this->reset_params( Cf, Ea, R ); - _rate->set_Cf(Cf); - _rate->set_Ea(Ea); - _rate->set_rscale(R); + _rate->set_Cf(Cf); + _rate->set_Ea(Ea); + _rate->set_rscale(R); - const Scalar tol = std::numeric_limits::epsilon() * 100; + const Scalar tol = std::numeric_limits::epsilon() * 100; - this->test_rate( *_rate, tol ); - this->test_deriv( *_rate, tol ); - this->test_rate_and_deriv( *_rate, tol ); - } + this->test_rate( *_rate, tol ); + this->test_deriv( *_rate, tol ); + this->test_rate_and_deriv( *_rate, tol ); + } - void test_reset_vector_params2() - { - Scalar Cf = 2.5e-7L; - Scalar Ea = 43000.L; //still in cal + void test_reset_vector_params2() + { + Scalar Cf = 2.5e-7L; + Scalar Ea = 43000.L; //still in cal - this->reset_params( Cf, Ea ); + this->reset_params( Cf, Ea ); - std::vector values(2); - values[0] = Cf; - values[1] = Ea; - _rate->reset_coefs(values); + std::vector values(2); + values[0] = Cf; + values[1] = Ea; + _rate->reset_coefs(values); - const Scalar tol = std::numeric_limits::epsilon() * 100; + const Scalar tol = std::numeric_limits::epsilon() * 100; - this->test_rate( *_rate, tol ); - this->test_deriv( *_rate, tol ); - this->test_rate_and_deriv( *_rate, tol ); - } + this->test_rate( *_rate, tol ); + this->test_deriv( *_rate, tol ); + this->test_rate_and_deriv( *_rate, tol ); + } - void test_reset_vector_params3() - { - Scalar Cf = 2.1e-11L; - Scalar Ea = 100000.L; - Scalar R = Antioch::Constants::R_universal(); + void test_reset_vector_params3() + { + Scalar Cf = 2.1e-11L; + Scalar Ea = 100000.L; + Scalar R = Antioch::Constants::R_universal(); - this->reset_params( Cf, Ea, R ); + this->reset_params( Cf, Ea, R ); - std::vector values(3); - values[0] = Cf; - values[1] = Ea; - values[2] = R; - _rate->reset_coefs(values); + std::vector values(3); + values[0] = Cf; + values[1] = Ea; + values[2] = R; + _rate->reset_coefs(values); - const Scalar tol = std::numeric_limits::epsilon() * 100; + const Scalar tol = std::numeric_limits::epsilon() * 100; - this->test_rate( *_rate, tol ); - this->test_deriv( *_rate, tol ); - this->test_rate_and_deriv( *_rate, tol ); - } + this->test_rate( *_rate, tol ); + this->test_deriv( *_rate, tol ); + this->test_rate_and_deriv( *_rate, tol ); + } -protected: + protected: - Antioch::ArrheniusRate* _rate; + Antioch::ArrheniusRate* _rate; - virtual Scalar exact_rate( Scalar T ) - { - return this->value(T); - } + virtual Scalar exact_rate( Scalar T ) + { + return this->value(T); + } - virtual Scalar exact_deriv( Scalar T ) - { - return this->deriv(T); - } + virtual Scalar exact_deriv( Scalar T ) + { + return this->deriv(T); + } -}; + }; -class ArrheniusRateFloatTest : public ArrheniusRateTest -{ -public: - CPPUNIT_TEST_SUITE( ArrheniusRateFloatTest ); + class ArrheniusRateFloatTest : public ArrheniusRateTest + { + public: + CPPUNIT_TEST_SUITE( ArrheniusRateFloatTest ); - CPPUNIT_TEST( test_standard ); - CPPUNIT_TEST( test_reset_scalar_params ); - CPPUNIT_TEST( test_reset_vector_params2 ); - CPPUNIT_TEST( test_reset_vector_params3 ); + CPPUNIT_TEST( test_standard ); + CPPUNIT_TEST( test_reset_scalar_params ); + CPPUNIT_TEST( test_reset_vector_params2 ); + CPPUNIT_TEST( test_reset_vector_params3 ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST_SUITE_END(); + }; -class ArrheniusRateDoubleTest : public ArrheniusRateTest -{ -public: - CPPUNIT_TEST_SUITE( ArrheniusRateDoubleTest ); + class ArrheniusRateDoubleTest : public ArrheniusRateTest + { + public: + CPPUNIT_TEST_SUITE( ArrheniusRateDoubleTest ); - CPPUNIT_TEST( test_standard ); - CPPUNIT_TEST( test_reset_scalar_params ); - CPPUNIT_TEST( test_reset_vector_params2 ); - CPPUNIT_TEST( test_reset_vector_params3 ); + CPPUNIT_TEST( test_standard ); + CPPUNIT_TEST( test_reset_scalar_params ); + CPPUNIT_TEST( test_reset_vector_params2 ); + CPPUNIT_TEST( test_reset_vector_params3 ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST_SUITE_END(); + }; -class ArrheniusRateLongDoubleTest : public ArrheniusRateTest -{ -public: - CPPUNIT_TEST_SUITE( ArrheniusRateLongDoubleTest ); + class ArrheniusRateLongDoubleTest : public ArrheniusRateTest + { + public: + CPPUNIT_TEST_SUITE( ArrheniusRateLongDoubleTest ); + + CPPUNIT_TEST( test_standard ); + CPPUNIT_TEST( test_reset_scalar_params ); + CPPUNIT_TEST( test_reset_vector_params2 ); + CPPUNIT_TEST( test_reset_vector_params3 ); - CPPUNIT_TEST( test_standard ); - CPPUNIT_TEST( test_reset_scalar_params ); - CPPUNIT_TEST( test_reset_vector_params2 ); - CPPUNIT_TEST( test_reset_vector_params3 ); + CPPUNIT_TEST_SUITE_END(); + }; - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateFloatTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateDoubleTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateLongDoubleTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateFloatTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateDoubleTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateLongDoubleTest ); +} // end namespace AntiochTesting #endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/standard_unit/arrhenius_rate_test_helper.h b/test/standard_unit/arrhenius_rate_test_helper.h index 09d27c66..efe67066 100644 --- a/test/standard_unit/arrhenius_rate_test_helper.h +++ b/test/standard_unit/arrhenius_rate_test_helper.h @@ -33,38 +33,43 @@ // Antioch #include "antioch/arrhenius_rate.h" -template -class ArrheniusRateTestHelper +namespace AntiochTesting { -protected: - Scalar _Cf, _Ea, _R; - void reset_params( Scalar Cf, Scalar Ea ) + template + class ArrheniusRateTestHelper { - _Cf = Cf; - _Ea = Ea; - } + protected: + Scalar _Cf, _Ea, _R; - void reset_params( Scalar Cf, Scalar Ea, Scalar R ) - { - _Cf = Cf; - _Ea = Ea; - _R = R; - } + void reset_params( Scalar Cf, Scalar Ea ) + { + _Cf = Cf; + _Ea = Ea; + } - Scalar value( Scalar T ) - { - using std::exp; - return _Cf*exp(-_Ea/(_R*T)); - } + void reset_params( Scalar Cf, Scalar Ea, Scalar R ) + { + _Cf = Cf; + _Ea = Ea; + _R = R; + } - Scalar deriv( Scalar T ) - { - using std::exp; - return _Ea/(_R*T*T)*_Cf *exp(-_Ea/(_R*T)); - } + Scalar value( Scalar T ) + { + using std::exp; + return _Cf*exp(-_Ea/(_R*T)); + } + + Scalar deriv( Scalar T ) + { + using std::exp; + return _Ea/(_R*T*T)*_Cf *exp(-_Ea/(_R*T)); + } + + }; -}; +} // end namespace AntiochTesting #endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/standard_unit/arrhenius_rate_valarray_test.C b/test/standard_unit/arrhenius_rate_valarray_test.C index d50df85f..3a57817a 100644 --- a/test/standard_unit/arrhenius_rate_valarray_test.C +++ b/test/standard_unit/arrhenius_rate_valarray_test.C @@ -37,66 +37,70 @@ #include "arrhenius_rate_vector_test_base.h" #include "antioch/valarray_utils.h" -template -class ArrheniusRateValarrayTest : public ArrheniusRateVectorTestBase > +namespace AntiochTesting { -public: - - virtual void setUp() + template + class ArrheniusRateValarrayTest : public ArrheniusRateVectorTestBase > { - this->init(); - this->_example = new std::valarray(2*ANTIOCH_N_TUPLES); - } + public: - virtual void tearDown() - { - this->clear(); - delete this->_example; - } + virtual void setUp() + { + this->init(); + this->_example = new std::valarray(2*ANTIOCH_N_TUPLES); + } -}; + virtual void tearDown() + { + this->clear(); + delete this->_example; + } -class ArrheniusRateValarrayFloatTest : public ArrheniusRateValarrayTest -{ -public: + }; - CPPUNIT_TEST_SUITE( ArrheniusRateValarrayFloatTest ); + class ArrheniusRateValarrayFloatTest : public ArrheniusRateValarrayTest + { + public: - CPPUNIT_TEST( test_standard_rate ); - CPPUNIT_TEST( test_standard_deriv ); - CPPUNIT_TEST( test_standard_rate_and_deriv ); + CPPUNIT_TEST_SUITE( ArrheniusRateValarrayFloatTest ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); -class ArrheniusRateValarrayDoubleTest : public ArrheniusRateValarrayTest -{ -public: + CPPUNIT_TEST_SUITE_END(); + }; - CPPUNIT_TEST_SUITE( ArrheniusRateValarrayDoubleTest ); + class ArrheniusRateValarrayDoubleTest : public ArrheniusRateValarrayTest + { + public: - CPPUNIT_TEST( test_standard_rate ); - CPPUNIT_TEST( test_standard_deriv ); - CPPUNIT_TEST( test_standard_rate_and_deriv ); + CPPUNIT_TEST_SUITE( ArrheniusRateValarrayDoubleTest ); - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); -class ArrheniusRateValarrayLongDoubleTest : public ArrheniusRateValarrayTest -{ -public: + CPPUNIT_TEST_SUITE_END(); + }; + + class ArrheniusRateValarrayLongDoubleTest : public ArrheniusRateValarrayTest + { + public: + + CPPUNIT_TEST_SUITE( ArrheniusRateValarrayLongDoubleTest ); - CPPUNIT_TEST_SUITE( ArrheniusRateValarrayLongDoubleTest ); + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); - CPPUNIT_TEST( test_standard_rate ); - CPPUNIT_TEST( test_standard_deriv ); - CPPUNIT_TEST( test_standard_rate_and_deriv ); + CPPUNIT_TEST_SUITE_END(); + }; - CPPUNIT_TEST_SUITE_END(); -}; + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateValarrayFloatTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateValarrayDoubleTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateValarrayLongDoubleTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateValarrayFloatTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateValarrayDoubleTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateValarrayLongDoubleTest ); +} // end namespace AntiochTesting #endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/standard_unit/arrhenius_rate_vector_test_base.h b/test/standard_unit/arrhenius_rate_vector_test_base.h index a9cac33c..564367aa 100644 --- a/test/standard_unit/arrhenius_rate_vector_test_base.h +++ b/test/standard_unit/arrhenius_rate_vector_test_base.h @@ -41,82 +41,86 @@ #include "arrhenius_rate_test_helper.h" #include "reaction_rate_vector_test_base.h" -template -class ArrheniusRateVectorTestBase : public ArrheniusRateTestHelper::type>, - public ReactionRateVectorTestBase::type>,PairScalars> +namespace AntiochTesting { -public: - virtual void init() + template + class ArrheniusRateVectorTestBase : public ArrheniusRateTestHelper::type>, + public ReactionRateVectorTestBase::type>,PairScalars> { - typedef typename Antioch::value_type::type Scalar; - - Scalar Cf = 1.4L; - Scalar Ea = 5.0L; - Scalar R = 1.0L; // Ea in K - - this->reset_params(Cf,Ea,R); - _rate = new Antioch::ArrheniusRate(Cf,Ea,R); - } - - virtual void clear() - { - delete _rate; - } - - void test_standard_rate() - { - typedef typename Antioch::value_type::type Scalar; - - const Scalar tol = std::numeric_limits::epsilon() * 100; - PairScalars T = this->setup_T(*(this->_example)); - this->test_rate( *_rate, T, tol ); - } - - void test_standard_deriv() - { - typedef typename Antioch::value_type::type Scalar; - - const Scalar tol = std::numeric_limits::epsilon() * 100; - PairScalars T = this->setup_T(*(this->_example)); - this->test_deriv( *_rate, T, tol ); - } - - void test_standard_rate_and_deriv() - { - typedef typename Antioch::value_type::type Scalar; - - const Scalar tol = std::numeric_limits::epsilon() * 100; - PairScalars T = this->setup_T(*(this->_example)); - this->test_rate_and_deriv( *_rate, T, tol ); - } - -protected: - - Antioch::ArrheniusRate::type>* _rate; - - virtual PairScalars exact_rate( PairScalars T ) - { - PairScalars e_rate = *(this->_example); - for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) - { - e_rate[2*tuple] = this->value(T[2*tuple]); - e_rate[2*tuple+1] = this->value(T[2*tuple+1]); - } - return e_rate; - } - - virtual PairScalars exact_deriv( PairScalars T ) - { - PairScalars e_deriv = *(this->_example); - for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) - { - e_deriv[2*tuple] = this->deriv(T[2*tuple]); - e_deriv[2*tuple+1] = this->deriv(T[2*tuple+1]); - } - return e_deriv; - } - -}; + public: + virtual void init() + { + typedef typename Antioch::value_type::type Scalar; + + Scalar Cf = 1.4L; + Scalar Ea = 5.0L; + Scalar R = 1.0L; // Ea in K + + this->reset_params(Cf,Ea,R); + _rate = new Antioch::ArrheniusRate(Cf,Ea,R); + } + + virtual void clear() + { + delete _rate; + } + + void test_standard_rate() + { + typedef typename Antioch::value_type::type Scalar; + + const Scalar tol = std::numeric_limits::epsilon() * 100; + PairScalars T = this->setup_T(*(this->_example)); + this->test_rate( *_rate, T, tol ); + } + + void test_standard_deriv() + { + typedef typename Antioch::value_type::type Scalar; + + const Scalar tol = std::numeric_limits::epsilon() * 100; + PairScalars T = this->setup_T(*(this->_example)); + this->test_deriv( *_rate, T, tol ); + } + + void test_standard_rate_and_deriv() + { + typedef typename Antioch::value_type::type Scalar; + + const Scalar tol = std::numeric_limits::epsilon() * 100; + PairScalars T = this->setup_T(*(this->_example)); + this->test_rate_and_deriv( *_rate, T, tol ); + } + + protected: + + Antioch::ArrheniusRate::type>* _rate; + + virtual PairScalars exact_rate( PairScalars T ) + { + PairScalars e_rate = *(this->_example); + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + e_rate[2*tuple] = this->value(T[2*tuple]); + e_rate[2*tuple+1] = this->value(T[2*tuple+1]); + } + return e_rate; + } + + virtual PairScalars exact_deriv( PairScalars T ) + { + PairScalars e_deriv = *(this->_example); + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + e_deriv[2*tuple] = this->deriv(T[2*tuple]); + e_deriv[2*tuple+1] = this->deriv(T[2*tuple+1]); + } + return e_deriv; + } + + }; + +} // end namespace AntiochTesting #endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/standard_unit/reaction_rate_test_base.h b/test/standard_unit/reaction_rate_test_base.h index 48c69d30..cd627c89 100644 --- a/test/standard_unit/reaction_rate_test_base.h +++ b/test/standard_unit/reaction_rate_test_base.h @@ -33,67 +33,71 @@ #include #include -template -class ReactionRateTestBase : public CppUnit::TestCase +namespace AntiochTesting { -public: - void test_rate( const ReactionRate& reaction_rate, - Scalar tol ) + template + class ReactionRateTestBase : public CppUnit::TestCase { - for(Scalar T = 300.1; T <= 2500.1; T += 10.) - { - Scalar rate = reaction_rate(T); - Scalar exact_rate = this->exact_rate(T); - - CPPUNIT_ASSERT_DOUBLES_EQUAL( rate, - exact_rate, - tol ); - } - } - - void test_deriv( const ReactionRate& reaction_rate, - Scalar tol ) - { - for(Scalar T = 300.1; T <= 2500.1; T += 10.) - { - Scalar deriv = reaction_rate.derivative(T); - Scalar exact_deriv = this->exact_deriv(T); - - CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv, - exact_deriv, - tol ); - } - } - - void test_rate_and_deriv( const ReactionRate& reaction_rate, - Scalar tol ) - { - for(Scalar T = 300.1; T <= 2500.1; T += 10.) - { - Scalar rate; - Scalar deriv; - - reaction_rate.rate_and_derivative(T,rate,deriv); - - Scalar exact_rate = this->exact_rate(T); - Scalar exact_deriv = this->exact_deriv(T); - - CPPUNIT_ASSERT_DOUBLES_EQUAL( rate, - exact_rate, - tol ); - - CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv, - exact_deriv, - tol ); - } - } - -protected: - - virtual Scalar exact_rate( Scalar T ) =0; - virtual Scalar exact_deriv( Scalar T ) =0; - -}; + public: + void test_rate( const ReactionRate& reaction_rate, + Scalar tol ) + { + for(Scalar T = 300.1; T <= 2500.1; T += 10.) + { + Scalar rate = reaction_rate(T); + Scalar exact_rate = this->exact_rate(T); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( rate, + exact_rate, + tol ); + } + } + + void test_deriv( const ReactionRate& reaction_rate, + Scalar tol ) + { + for(Scalar T = 300.1; T <= 2500.1; T += 10.) + { + Scalar deriv = reaction_rate.derivative(T); + Scalar exact_deriv = this->exact_deriv(T); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv, + exact_deriv, + tol ); + } + } + + void test_rate_and_deriv( const ReactionRate& reaction_rate, + Scalar tol ) + { + for(Scalar T = 300.1; T <= 2500.1; T += 10.) + { + Scalar rate; + Scalar deriv; + + reaction_rate.rate_and_derivative(T,rate,deriv); + + Scalar exact_rate = this->exact_rate(T); + Scalar exact_deriv = this->exact_deriv(T); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( rate, + exact_rate, + tol ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv, + exact_deriv, + tol ); + } + } + + protected: + + virtual Scalar exact_rate( Scalar T ) =0; + virtual Scalar exact_deriv( Scalar T ) =0; + + }; + +} // end namespace AntiochTesting #endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/standard_unit/reaction_rate_vector_test_base.h b/test/standard_unit/reaction_rate_vector_test_base.h index 19e07552..c804a4ed 100644 --- a/test/standard_unit/reaction_rate_vector_test_base.h +++ b/test/standard_unit/reaction_rate_vector_test_base.h @@ -33,106 +33,110 @@ #include #include -template -class ReactionRateVectorTestBase : public CppUnit::TestCase +namespace AntiochTesting { -public: - - void test_rate( const ReactionRate& reaction_rate, - const PairScalars& T, - typename Antioch::value_type::type /*Scalar*/ tol ) - { - const PairScalars rate = reaction_rate(T); - const PairScalars exact_rate = this->exact_rate(T); - - for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) - { - CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple], - exact_rate[0], - tol ); - - CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple+1], - exact_rate[1], - tol ); - - } - } - - void test_deriv( const ReactionRate& reaction_rate, - const PairScalars& T, - typename Antioch::value_type::type /*Scalar*/ tol ) - { - const PairScalars deriv = reaction_rate.derivative(T); - const PairScalars exact_deriv = this->exact_deriv(T); - - for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) - { - CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple], - exact_deriv[0], - tol ); - - CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple+1], - exact_deriv[1], - tol ); - - } - } - - void test_rate_and_deriv( const ReactionRate& reaction_rate, - const PairScalars& T, - typename Antioch::value_type::type /*Scalar*/ tol ) - { - // Init using T as the "example" - PairScalars rate = T; - PairScalars deriv = T; - - reaction_rate.rate_and_derivative(T,rate,deriv); - - const PairScalars exact_rate = this->exact_rate(T); - const PairScalars exact_deriv = this->exact_deriv(T); - - for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) - { - CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple], - exact_rate[0], - tol ); - - CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple+1], - exact_rate[1], - tol ); - - CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple], - exact_deriv[0], - tol ); - - CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple+1], - exact_deriv[1], - tol ); - } - } - - -protected: - - // Should be new'd/deleted in subclasses for each PairScalar type - PairScalars* _example; - - PairScalars setup_T( const PairScalars& example ) + template + class ReactionRateVectorTestBase : public CppUnit::TestCase { - // Construct from example to avoid resizing issues - PairScalars T = example; - for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) - { - T[2*tuple] = 1500.1; - T[2*tuple+1] = 1600.1; - } - return T; - } - - virtual PairScalars exact_rate( PairScalars T ) =0; - virtual PairScalars exact_deriv( PairScalars T ) =0; - -}; + public: + + void test_rate( const ReactionRate& reaction_rate, + const PairScalars& T, + typename Antioch::value_type::type /*Scalar*/ tol ) + { + const PairScalars rate = reaction_rate(T); + const PairScalars exact_rate = this->exact_rate(T); + + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple], + exact_rate[0], + tol ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple+1], + exact_rate[1], + tol ); + + } + } + + void test_deriv( const ReactionRate& reaction_rate, + const PairScalars& T, + typename Antioch::value_type::type /*Scalar*/ tol ) + { + const PairScalars deriv = reaction_rate.derivative(T); + const PairScalars exact_deriv = this->exact_deriv(T); + + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple], + exact_deriv[0], + tol ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple+1], + exact_deriv[1], + tol ); + + } + } + + void test_rate_and_deriv( const ReactionRate& reaction_rate, + const PairScalars& T, + typename Antioch::value_type::type /*Scalar*/ tol ) + { + // Init using T as the "example" + PairScalars rate = T; + PairScalars deriv = T; + + reaction_rate.rate_and_derivative(T,rate,deriv); + + const PairScalars exact_rate = this->exact_rate(T); + const PairScalars exact_deriv = this->exact_deriv(T); + + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple], + exact_rate[0], + tol ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple+1], + exact_rate[1], + tol ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple], + exact_deriv[0], + tol ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple+1], + exact_deriv[1], + tol ); + } + } + + + protected: + + // Should be new'd/deleted in subclasses for each PairScalar type + PairScalars* _example; + + PairScalars setup_T( const PairScalars& example ) + { + // Construct from example to avoid resizing issues + PairScalars T = example; + for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) + { + T[2*tuple] = 1500.1; + T[2*tuple+1] = 1600.1; + } + return T; + } + + virtual PairScalars exact_rate( PairScalars T ) =0; + virtual PairScalars exact_deriv( PairScalars T ) =0; + + }; + +} // end namespace AntiochTesting #endif // ANTIOCH_HAVE_CPPUNIT diff --git a/test/vexcl_unit/arrhenius_rate_vexcl_test.C b/test/vexcl_unit/arrhenius_rate_vexcl_test.C index 5f12be62..59cf9a05 100644 --- a/test/vexcl_unit/arrhenius_rate_vexcl_test.C +++ b/test/vexcl_unit/arrhenius_rate_vexcl_test.C @@ -39,75 +39,79 @@ #include "arrhenius_rate_vector_test_base.h" #include "antioch/vexcl_utils.h" -class ArrheniusRateVexCLFloatTest : public ArrheniusRateVectorTestBase > +namespace AntiochTesting { -public: + class ArrheniusRateVexCLFloatTest : public ArrheniusRateVectorTestBase > + { + public: - CPPUNIT_TEST_SUITE( ArrheniusRateVexCLFloatTest ); + CPPUNIT_TEST_SUITE( ArrheniusRateVexCLFloatTest ); - CPPUNIT_TEST( test_standard_rate ); - CPPUNIT_TEST( test_standard_deriv ); - CPPUNIT_TEST( test_standard_rate_and_deriv ); + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE_END(); -private: + private: - vex::Context* _ctx; + vex::Context* _ctx; -public: + public: - virtual void setUp() - { - this->init(); - _ctx = new vex::Context(vex::Filter::All); - this->_example = new vex::vector(*_ctx, 2*ANTIOCH_N_TUPLES); - } + virtual void setUp() + { + this->init(); + _ctx = new vex::Context(vex::Filter::All); + this->_example = new vex::vector(*_ctx, 2*ANTIOCH_N_TUPLES); + } - virtual void tearDown() - { - this->clear(); - delete _ctx; - delete this->_example; - } + virtual void tearDown() + { + this->clear(); + delete _ctx; + delete this->_example; + } -}; + }; -class ArrheniusRateVexCLDoubleTest : public ArrheniusRateVectorTestBase > -{ -public: + class ArrheniusRateVexCLDoubleTest : public ArrheniusRateVectorTestBase > + { + public: - CPPUNIT_TEST_SUITE( ArrheniusRateVexCLDoubleTest ); + CPPUNIT_TEST_SUITE( ArrheniusRateVexCLDoubleTest ); - CPPUNIT_TEST( test_standard_rate ); - CPPUNIT_TEST( test_standard_deriv ); - CPPUNIT_TEST( test_standard_rate_and_deriv ); + CPPUNIT_TEST( test_standard_rate ); + CPPUNIT_TEST( test_standard_deriv ); + CPPUNIT_TEST( test_standard_rate_and_deriv ); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE_END(); private: - vex::Context* _ctx; + vex::Context* _ctx; -public: + public: - virtual void setUp() - { - this->init(); - _ctx = new vex::Context(vex::Filter::DoublePrecision); - this->_example = new vex::vector(*_ctx, 2*ANTIOCH_N_TUPLES); - } + virtual void setUp() + { + this->init(); + _ctx = new vex::Context(vex::Filter::DoublePrecision); + this->_example = new vex::vector(*_ctx, 2*ANTIOCH_N_TUPLES); + } - virtual void tearDown() - { - this->clear(); - delete _ctx; - delete this->_example; - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateVexCLFloatTest ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateVexCLDoubleTest ); + virtual void tearDown() + { + this->clear(); + delete _ctx; + delete this->_example; + } + }; + + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateVexCLFloatTest ); + CPPUNIT_TEST_SUITE_REGISTRATION( ArrheniusRateVexCLDoubleTest ); + +} // end namespace AntiochTesting #endif // ANTIOCH_HAVE_VEXCL From f5b0d2192bb567274386e6713abd49377602b492 Mon Sep 17 00:00:00 2001 From: "Paul T. Bauman" Date: Fri, 4 Sep 2015 19:54:04 -0400 Subject: [PATCH 29/29] Remove now redundant gsl_spline_vec_unit Replaced by CppUnit version --- test/Makefile.am | 3 - test/gsl_spline_vec_unit.C | 215 ------------------------------------- 2 files changed, 218 deletions(-) delete mode 100644 test/gsl_spline_vec_unit.C diff --git a/test/Makefile.am b/test/Makefile.am index f5f7bb19..63a9667d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -69,7 +69,6 @@ check_PROGRAMS += molecular_binary_diffusion_unit check_PROGRAMS += molecular_binary_diffusion_vec_unit check_PROGRAMS += kinetics_theory_viscosity_unit check_PROGRAMS += kinetics_theory_viscosity_vec_unit -check_PROGRAMS += gsl_spline_vec_unit check_PROGRAMS += Stockmayer_unit # Eigen Tests @@ -181,7 +180,6 @@ molecular_binary_diffusion_unit_SOURCES = molecular_binary_diffusion_unit.C molecular_binary_diffusion_vec_unit_SOURCES = molecular_binary_diffusion_vec_unit.C kinetics_theory_viscosity_unit_SOURCES = kinetics_theory_viscosity_unit.C kinetics_theory_viscosity_vec_unit_SOURCES = kinetics_theory_viscosity_vec_unit.C -gsl_spline_vec_unit_SOURCES = gsl_spline_vec_unit.C ideal_gas_micro_thermo_unit_SOURCES = ideal_gas_micro_thermo_unit.C Stockmayer_unit_SOURCES = Stockmayer_unit.C @@ -260,7 +258,6 @@ TESTS += molecular_binary_diffusion_unit TESTS += molecular_binary_diffusion_vec_unit TESTS += kinetics_theory_viscosity_unit TESTS += kinetics_theory_viscosity_vec_unit -TESTS += gsl_spline_vec_unit TESTS += Stockmayer_unit diff --git a/test/gsl_spline_vec_unit.C b/test/gsl_spline_vec_unit.C deleted file mode 100644 index 37afadcd..00000000 --- a/test/gsl_spline_vec_unit.C +++ /dev/null @@ -1,215 +0,0 @@ -//-----------------------------------------------------------------------bl- -//-------------------------------------------------------------------------- -// -// Antioch - A Gas Dynamics Thermochemistry Library -// -// Copyright (C) 2014 Paul T. Bauman, Benjamin S. Kirk, Sylvain Plessis, -// Roy H. Stonger -// Copyright (C) 2013 The PECOS Development Team -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the Version 2.1 GNU Lesser General -// Public License as published by the Free Software Foundation. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc. 51 Franklin Street, Fifth Floor, -// Boston, MA 02110-1301 USA -// -//-----------------------------------------------------------------------el- -// -// $Id$ -// -//-------------------------------------------------------------------------- -//-------------------------------------------------------------------------- - -// valarray has to be declared before Antioch or gcc can't find the -// right versions of exp() and pow() to use?? - -#include "antioch_config.h" - -#include - -#ifdef ANTIOCH_HAVE_EIGEN -#include "Eigen/Dense" -#endif - -#ifdef ANTIOCH_HAVE_METAPHYSICL -#include "metaphysicl/numberarray.h" -#endif - -#ifdef ANTIOCH_HAVE_VEXCL -#include "vexcl/vexcl.hpp" -#endif - -#include "antioch/eigen_utils_decl.h" -#include "antioch/metaphysicl_utils_decl.h" -#include "antioch/valarray_utils_decl.h" -#include "antioch/vexcl_utils_decl.h" -#include "antioch/vector_utils_decl.h" - -#include "antioch/gsl_spliner.h" - -#include "antioch/eigen_utils.h" -#include "antioch/metaphysicl_utils.h" -#include "antioch/valarray_utils.h" -#include "antioch/vexcl_utils.h" -#include "antioch/vector_utils.h" - -#ifdef ANTIOCH_HAVE_GRVY -#include "grvy.h" - -GRVY::GRVY_Timer_Class gt; -#endif - -#include -#include - -#ifdef ANTIOCH_HAVE_GSL - -template -int check_value(const Element & ref, const Element & candidate, const Element & x, const std::string & words) -{ - /*because not the real test function impossible due to boundary conditions - */ - const Scalar tol = 5e-3;//std::numeric_limits::epsilon() * 10.; - - if(std::abs((ref - candidate)/ref) > tol) - { - std::cerr << std::scientific << std::setprecision(15); - std::cerr << "ERROR in gsl spline test at point: " << x << "; " << words << std::endl - << " reference = " << ref << std::endl - << " candidate = " << candidate << std::endl - << " relative difference = " << std::abs((ref - candidate) / ref) << std::endl - << " absolute difference = " << std::abs(ref - candidate) << std::endl - << " tolerance = " << tol << std::endl; - return 1; - } - - return 0; -} - -template -Scalar function(const Scalar x) -{ - Scalar ten = Antioch::constant_clone(x,10); - Scalar two = Antioch::constant_clone(x,2); - Scalar five = Antioch::constant_clone(x,5); - - return ten + five * x + ten * x * x - two * x * x * x; -} - -template -void fill_ref(std::vector & x_ref, std::vector & y_ref, - unsigned int n_data, const Scalar & min, - const Scalar & max) -{ - for(unsigned int i = 0; i < n_data; i++) - { - x_ref[i] = min + (Scalar)(i) * (max - min) / (Scalar)(n_data-1); - y_ref[i] = function(x_ref[i]); - } -} - -template -int vectester(const PairScalars& example, const std::string& testname) -{ - typedef typename Antioch::value_type::type Scalar; - - const unsigned int n_data(40); - - std::vector x_ref(n_data,0),y_ref(n_data,0); - - const Scalar min = -5L; - const Scalar max = 8L; - fill_ref(x_ref,y_ref,n_data,min, max); - - Antioch::GSLSpliner gsl_spline(x_ref,y_ref); - - // Construct from example to avoid resizing issues - PairScalars x = example; - for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) - { - x[2*tuple] = -3.5; - x[2*tuple+1] = 5.1; - } - - int return_flag = 0; - -#ifdef ANTIOCH_HAVE_GRVY - gt.BeginTimer(testname); -#endif - - const PairScalars gsl = gsl_spline.interpolated_value(x); - -#ifdef ANTIOCH_HAVE_GRVY - gt.EndTimer(testname); -#endif - - const PairScalars exact = function(x); - for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple) - { - return_flag = check_value(exact[2*tuple], gsl[2*tuple], x[2*tuple], "gsl vectorized") || return_flag; - return_flag = check_value(exact[2*tuple+1], gsl[2*tuple+1], x[2*tuple+1], "gsl vectorized") || return_flag; - } - return return_flag; -} -#endif // ANTIOCH_HAVE_GSL - -int main() -{ - int returnval = 0; - -#ifdef ANTIOCH_HAVE_GSL - - returnval = returnval || - vectester (std::valarray(2*ANTIOCH_N_TUPLES), "valarray"); - returnval = returnval || - vectester (std::valarray(2*ANTIOCH_N_TUPLES), "valarray"); - returnval = returnval || - vectester (std::valarray(2*ANTIOCH_N_TUPLES), "valarray"); -#ifdef ANTIOCH_HAVE_EIGEN - returnval = returnval || - vectester (Eigen::Array(), "Eigen::ArrayXf"); - returnval = returnval || - vectester (Eigen::Array(), "Eigen::ArrayXd"); - returnval = returnval || - vectester (Eigen::Array(), "Eigen::ArrayXld"); -#endif -#ifdef ANTIOCH_HAVE_METAPHYSICL - returnval = returnval || - vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float> (0), "NumberArray"); - returnval = returnval || - vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, double> (0), "NumberArray"); - returnval = returnval || - vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, long double> (0), "NumberArray"); -#endif -#ifdef ANTIOCH_HAVE_VEXCL - vex::Context ctx_f (vex::Filter::All); - if (!ctx_f.empty()) - returnval = returnval || - vectester (vex::vector (ctx_f, 2*ANTIOCH_N_TUPLES), "vex::vector"); - - vex::Context ctx_d (vex::Filter::DoublePrecision); - if (!ctx_d.empty()) - returnval = returnval || - vectester (vex::vector (ctx_d, 2*ANTIOCH_N_TUPLES), "vex::vector"); -#endif - -#ifdef ANTIOCH_HAVE_GRVY - gt.Finalize(); - gt.Summarize(); -#endif - -#else // ANTIOCH_HAVE_GSL - // 77 return code tells Automake we skipped this. - returnval = 77; -#endif - - return returnval; -}