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" diff --git a/configure.ac b/configure.ac index f4bcd5bb..edc6e2d5 100644 --- a/configure.ac +++ b/configure.ac @@ -133,6 +133,21 @@ 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])) +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_LDFLAGS="$CPPUNIT_LIBS $antioch_optional_test_LDFLAGS" +fi +AM_CONDITIONAL(ANTIOCH_ENABLE_CPPUNIT, test x$enablecppunit = xyes) AC_SUBST(antioch_optional_INCLUDES) AC_SUBST(antioch_optional_test_INCLUDES) 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. 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 diff --git a/test/Makefile.am b/test/Makefile.am index f79c42e3..63a9667d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,6 +1,11 @@ EXTRA_DIST = input_files check_PROGRAMS = +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 @@ -14,8 +19,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 check_PROGRAMS += berthelothercourtessen_rate_unit @@ -66,8 +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 # Eigen Tests @@ -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,28 @@ 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/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 + +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 + +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 +pkginclude_HEADERS += standard_unit/arrhenius_rate_test_helper.h + # Sources for these tests chem_mixture_unit_SOURCES = chem_mixture_unit.C chem_mixture_vec_unit_SOURCES = chem_mixture_vec_unit.C @@ -107,8 +131,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 kooij_rate_unit_SOURCES = kooij_rate_unit.C @@ -158,8 +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 @@ -170,6 +190,11 @@ 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 += 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 @@ -183,8 +208,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 TESTS += kooij_rate_unit @@ -235,8 +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_unit -TESTS += gsl_spline_vec_unit TESTS += Stockmayer_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()); -} 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; -} 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..3edebd64 --- /dev/null +++ b/test/eigen_unit/arrhenius_rate_eigen_test.C @@ -0,0 +1,110 @@ +//-----------------------------------------------------------------------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" + +namespace AntiochTesting +{ + 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 ); + +} // end namespace AntiochTesting + +#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 +} 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 -} 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; -} diff --git a/test/gsl_unit/gsl_spliner_test.C b/test/gsl_unit/gsl_spliner_test.C new file mode 100644 index 00000000..e204efba --- /dev/null +++ b/test/gsl_unit/gsl_spliner_test.C @@ -0,0 +1,175 @@ +//-----------------------------------------------------------------------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" + +namespace AntiochTesting +{ + template + class GSLSplinerTest : public GSLSplinerTestBase + { + public: + + void setUp() + { + this->init_data(); + } + + // Helper function + template + 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; + 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; + 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); + + 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() * 10; + + this->run_manually_inited_test >(tol); + } + + void test_constructor_inited_spline_constant_func() + { + 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() * 50; + + this->run_manually_inited_test >(tol); + } + + void test_constructor_inited_spline_linear_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; + + this->run_constructor_inited_test >(tol); + } + + void test_manually_inited_spline_cubic_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; + + this->run_manually_inited_test >(tol); + } + + void test_constructor_inited_spline_cubic_func() + { + const Scalar tol = std::numeric_limits::epsilon() * 50; + + 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 ); + +} // 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 new file mode 100644 index 00000000..b86241bd --- /dev/null +++ b/test/gsl_unit/gsl_spliner_test_base.h @@ -0,0 +1,146 @@ +//-----------------------------------------------------------------------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 + +namespace AntiochTesting +{ + template + struct GSLSplinerTestFunction + { + typedef typename Antioch::value_type::type Scalar; + + virtual PairScalars operator()( const PairScalars 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 + 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 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: + + 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 + +#endif // ANTIOCH_GSL_SPLINER_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..d6e3b351 --- /dev/null +++ b/test/gsl_unit/gsl_spliner_vec_test.C @@ -0,0 +1,469 @@ +//-----------------------------------------------------------------------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" + +namespace AntiochTesting +{ + 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 + +} // end namespace AntiochTesting + +#endif // ANTIOCH_HAVE_CPPUNIT 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 +} 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..0b9293e4 --- /dev/null +++ b/test/metaphysicl_unit/arrhenius_rate_metaphysicl_test.C @@ -0,0 +1,110 @@ +//-----------------------------------------------------------------------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" + +namespace AntiochTesting +{ + 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 ); + +} // end namespace AntiochTesting + +#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 +} diff --git a/test/standard_unit/arrhenius_rate_test.C b/test/standard_unit/arrhenius_rate_test.C new file mode 100644 index 00000000..98794068 --- /dev/null +++ b/test/standard_unit/arrhenius_rate_test.C @@ -0,0 +1,192 @@ +//-----------------------------------------------------------------------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/physical_constants.h" +#include "antioch/units.h" + +// Base class +#include "arrhenius_rate_test_helper.h" +#include "reaction_rate_test_base.h" + +namespace AntiochTesting +{ + template + class ArrheniusRateTest : public ArrheniusRateTestHelper, + public ReactionRateTestBase,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 Antioch::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 = Antioch::Constants::R_universal()*Antioch::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 = Antioch::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: + + Antioch::ArrheniusRate* _rate; + + virtual Scalar exact_rate( Scalar T ) + { + return this->value(T); + } + + virtual Scalar exact_deriv( Scalar T ) + { + return this->deriv(T); + } + + }; + + 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_SUITE_END(); + }; + + 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_SUITE_END(); + }; + + 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_SUITE_END(); + }; + + 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 new file mode 100644 index 00000000..efe67066 --- /dev/null +++ b/test/standard_unit/arrhenius_rate_test_helper.h @@ -0,0 +1,76 @@ +//-----------------------------------------------------------------------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_TEST_HELPER_H +#define ANTIOCH_ARRHENIUS_RATE_TEST_HELPER_H + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +// Antioch +#include "antioch/arrhenius_rate.h" + +namespace AntiochTesting +{ + + 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)); + } + + }; + +} // end namespace AntiochTesting + +#endif // ANTIOCH_HAVE_CPPUNIT + +#endif // ANTIOCH_ARRHENIUS_RATE_TEST_HELPER_H diff --git a/test/standard_unit/arrhenius_rate_valarray_test.C b/test/standard_unit/arrhenius_rate_valarray_test.C new file mode 100644 index 00000000..3a57817a --- /dev/null +++ b/test/standard_unit/arrhenius_rate_valarray_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 + +// 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" + +namespace AntiochTesting +{ + 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 ); + +} // 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 new file mode 100644 index 00000000..564367aa --- /dev/null +++ b/test/standard_unit/arrhenius_rate_vector_test_base.h @@ -0,0 +1,127 @@ +//-----------------------------------------------------------------------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" + +namespace AntiochTesting +{ + template + class ArrheniusRateVectorTestBase : public ArrheniusRateTestHelper::type>, + public ReactionRateVectorTestBase::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; + } + + }; + +} // end namespace AntiochTesting + +#endif // ANTIOCH_HAVE_CPPUNIT + +#endif // ANTIOCH_ARRHENIUS_RATE_VECTOR_TEST_BASE_H 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..cd627c89 --- /dev/null +++ b/test/standard_unit/reaction_rate_test_base.h @@ -0,0 +1,104 @@ +//-----------------------------------------------------------------------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_TEST_BASE_H +#define ANTIOCH_REACTION_RATE_TEST_BASE_H + +#include "antioch_config.h" + +#ifdef ANTIOCH_HAVE_CPPUNIT + +#include +#include + +namespace AntiochTesting +{ + template + class ReactionRateTestBase : 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; + + }; + +} // end namespace AntiochTesting + +#endif // ANTIOCH_HAVE_CPPUNIT + +#endif // ANTIOCH_REACTION_RATE_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..c804a4ed --- /dev/null +++ b/test/standard_unit/reaction_rate_vector_test_base.h @@ -0,0 +1,143 @@ +//-----------------------------------------------------------------------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 + +namespace AntiochTesting +{ + template + class ReactionRateVectorTestBase : 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; + + }; + +} // end namespace AntiochTesting + +#endif // ANTIOCH_HAVE_CPPUNIT + +#endif // ANTIOCH_REACTION_RATE_VECTOR_TEST_BASE_H 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 +} 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..59cf9a05 --- /dev/null +++ b/test/vexcl_unit/arrhenius_rate_vexcl_test.C @@ -0,0 +1,118 @@ +//-----------------------------------------------------------------------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" + +namespace AntiochTesting +{ + 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 ); + +} // end namespace AntiochTesting + +#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 +}