From e5280dbe59b4a6966b3939201f110d2b07a974d4 Mon Sep 17 00:00:00 2001 From: Lars Kaiser <71793357+kaiserls@users.noreply.github.com> Date: Thu, 23 Nov 2023 14:26:45 +0100 Subject: [PATCH] [SimpleH2O][test] Add unit test for simpleh2o/h2o gasEnthalpy consistency --- test/material/components/CMakeLists.txt | 4 ++ .../test_h2o_simpleh2o_consistency.cc | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 test/material/components/test_h2o_simpleh2o_consistency.cc diff --git a/test/material/components/CMakeLists.txt b/test/material/components/CMakeLists.txt index 602a9a406f..5db2de41a3 100644 --- a/test/material/components/CMakeLists.txt +++ b/test/material/components/CMakeLists.txt @@ -7,6 +7,10 @@ dumux_add_test(SOURCES test_componenttraits.cc add_executable(plot_component plotproperties.cc) +dumux_add_test(NAME test_h2o_simpleh2o_consistency + SOURCES test_h2o_simpleh2o_consistency.cc + LABELS unit material) + dumux_add_test(NAME plot_air TARGET plot_component COMMAND ./plot_component diff --git a/test/material/components/test_h2o_simpleh2o_consistency.cc b/test/material/components/test_h2o_simpleh2o_consistency.cc new file mode 100644 index 0000000000..050ec92677 --- /dev/null +++ b/test/material/components/test_h2o_simpleh2o_consistency.cc @@ -0,0 +1,45 @@ +// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +// vi: set et ts=4 sw=4 sts=4: +// +// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder +// SPDX-License-Identifier: GPL-3.0-or-later +// +/*! + * \file + * \ingroup MaterialTests + * \brief Test some components for consistency of their physical properties. + */ + +#include "config.h" + +#include <cmath> +#include <dune/common/exceptions.hh> +#include <dumux/material/components/h2o.hh> +#include <dumux/material/components/simpleh2o.hh> + +int main(int argc, char *argv[]) +{ + using namespace Dumux; + + // See the currently allowed range in simpleh2O.hh + constexpr double lowerTemperatureBound = 273.15 + 0.0; // 0°C + constexpr double upperTemperatureBound = 273.15 + 150.0; // 150°C + constexpr int nTemperatures = 20; + constexpr double pressure = 1.0e5; // 1 bar + + for (int i = 0; i < nTemperatures; ++i) + { + const double temperature = lowerTemperatureBound + (upperTemperatureBound - lowerTemperatureBound) * i / (nTemperatures - 1); + const double simpleH2OGasEnthalpy = Components::SimpleH2O<double>::gasEnthalpy(temperature, pressure); + const double h2OGasEnthalpy = Components::H2O<double>::gasEnthalpy(temperature, pressure); + // compare the two gas enthalpies + const double relDiff = (simpleH2OGasEnthalpy - h2OGasEnthalpy) / h2OGasEnthalpy; + const double relTol = 0.05; // We allow a relative error of 5% + if (std::abs(relDiff) > relTol) { + DUNE_THROW(Dune::Exception, "The gas enthalpy of the simple H2O component is not consistent with the H2O component. " + << "The relative difference " << relDiff << " at temperature " << temperature << " K." + << " is larger than the relative tolerance " << relTol << "."); + } + } + return 0; +} -- GitLab