From 38fb67496d3301c13bc39e8349e6ce5725d6b9e7 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 23 May 2023 22:16:47 +0200 Subject: [PATCH 1/2] fixed: avoid dead stores in test_co2brinepvt --- tests/material/test_co2brinepvt.cpp | 127 +++++++++++++--------------- 1 file changed, 60 insertions(+), 67 deletions(-) diff --git a/tests/material/test_co2brinepvt.cpp b/tests/material/test_co2brinepvt.cpp index 27348a50b..be4c1303b 100644 --- a/tests/material/test_co2brinepvt.cpp +++ b/tests/material/test_co2brinepvt.cpp @@ -49,6 +49,8 @@ #include #include +#include + // values of strings based on the first SPE1 test case of opm-data. note that in the // real world it does not make much sense to specify a fluid phase using more than a // single keyword, but for a unit test, this saves a lot of boiler-plate code. @@ -130,24 +132,20 @@ void ensurePvtApiBrine(const BrinePvt& brinePvt) Evaluation pressure = 1e5; Evaluation saltconcentration = 0.0; Evaluation rs = 0.0; - Evaluation tmp; //// // Water PVT API ///// - tmp = brinePvt.viscosity(/*regionIdx=*/0, - temperature, - pressure, - rs, - saltconcentration); - tmp = brinePvt.inverseFormationVolumeFactor(/*regionIdx=*/0, - temperature, - pressure, - rs, - saltconcentration); - - // prevent GCC from producing a "variable assigned but unused" warning - tmp = 2.0*tmp; + std::cout << brinePvt.viscosity(/*regionIdx=*/0, + temperature, + pressure, + rs, + saltconcentration); + std::cout << brinePvt.inverseFormationVolumeFactor(/*regionIdx=*/0, + temperature, + pressure, + rs, + saltconcentration); } } @@ -162,41 +160,37 @@ void ensurePvtApiGas(const Co2Pvt& co2Pvt) Evaluation Rvw = 0.0; Evaluation So = 0.5; Evaluation maxSo = 1.0; - Evaluation tmp; ///// // co2 PVT API ///// - tmp = co2Pvt.viscosity(/*regionIdx=*/0, - temperature, - pressure, - Rv, - Rvw); - tmp = co2Pvt.inverseFormationVolumeFactor(/*regionIdx=*/0, - temperature, - pressure, - Rv, - Rvw); - tmp = co2Pvt.saturatedViscosity(/*regionIdx=*/0, - temperature, - pressure); - tmp = co2Pvt.saturatedInverseFormationVolumeFactor(/*regionIdx=*/0, + std::cout << co2Pvt.viscosity(/*regionIdx=*/0, + temperature, + pressure, + Rv, + Rvw); + std::cout << co2Pvt.inverseFormationVolumeFactor(/*regionIdx=*/0, + temperature, + pressure, + Rv, + Rvw); + std::cout << co2Pvt.saturatedViscosity(/*regionIdx=*/0, + temperature, + pressure); + std::cout << co2Pvt.saturatedInverseFormationVolumeFactor(/*regionIdx=*/0, + temperature, + pressure); + std::cout << co2Pvt.saturationPressure(/*regionIdx=*/0, + temperature, + Rv); + std::cout << co2Pvt.saturatedOilVaporizationFactor(/*regionIdx=*/0, temperature, pressure); - tmp = co2Pvt.saturationPressure(/*regionIdx=*/0, - temperature, - Rv); - tmp = co2Pvt.saturatedOilVaporizationFactor(/*regionIdx=*/0, - temperature, - pressure); - tmp = co2Pvt.saturatedOilVaporizationFactor(/*regionIdx=*/0, - temperature, - pressure, - So, - maxSo); - - // prevent GCC from producing a "variable assigned but unused" warning - tmp = 2.0*tmp; + std::cout << co2Pvt.saturatedOilVaporizationFactor(/*regionIdx=*/0, + temperature, + pressure, + So, + maxSo); } } @@ -210,36 +204,35 @@ void ensurePvtApiBrineOil(const BrinePvt& brinePvt) Evaluation Rs = 0.0; Evaluation So = 0.5; Evaluation maxSo = 1.0; - Evaluation tmp; ///// // brine PVT API ///// - tmp = brinePvt.viscosity(/*regionIdx=*/0, - temperature, - pressure, - Rs); - tmp = brinePvt.inverseFormationVolumeFactor(/*regionIdx=*/0, - temperature, - pressure, - Rs); - tmp = brinePvt.saturatedViscosity(/*regionIdx=*/0, - temperature, - pressure); - tmp = brinePvt.saturatedInverseFormationVolumeFactor(/*regionIdx=*/0, - temperature, - pressure); - tmp = brinePvt.saturationPressure(/*regionIdx=*/0, + std::cout << brinePvt.viscosity(/*regionIdx=*/0, temperature, + pressure, Rs); - tmp = brinePvt.saturatedGasDissolutionFactor(/*regionIdx=*/0, - temperature, - pressure); - tmp = brinePvt.saturatedGasDissolutionFactor(/*regionIdx=*/0, - temperature, - pressure, - So, - maxSo); + std::cout << brinePvt.inverseFormationVolumeFactor(/*regionIdx=*/0, + temperature, + pressure, + Rs); + std::cout << brinePvt.saturatedViscosity(/*regionIdx=*/0, + temperature, + pressure); + std::cout << brinePvt.saturatedInverseFormationVolumeFactor(/*regionIdx=*/0, + temperature, + pressure); + std::cout << brinePvt.saturationPressure(/*regionIdx=*/0, + temperature, + Rs); + std::cout << brinePvt.saturatedGasDissolutionFactor(/*regionIdx=*/0, + temperature, + pressure); + std::cout << brinePvt.saturatedGasDissolutionFactor(/*regionIdx=*/0, + temperature, + pressure, + So, + maxSo); } } From 89b1a95a2dc4d1be908099c0fcdbba5f406286fe Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 23 May 2023 22:31:50 +0200 Subject: [PATCH 2/2] test_co2brinepvt: convert to Boost::Test --- tests/material/test_co2brinepvt.cpp | 53 +++++++++++++++-------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/tests/material/test_co2brinepvt.cpp b/tests/material/test_co2brinepvt.cpp index be4c1303b..9a909bff0 100644 --- a/tests/material/test_co2brinepvt.cpp +++ b/tests/material/test_co2brinepvt.cpp @@ -29,6 +29,9 @@ */ #include "config.h" +#define BOOST_TEST_MODULE Co2BrinePvt +#include + #if !HAVE_ECL_INPUT #error "The test for the co2 brine PVT classes requires eclipse input support in opm-common" #endif @@ -54,7 +57,7 @@ // values of strings based on the first SPE1 test case of opm-data. note that in the // real world it does not make much sense to specify a fluid phase using more than a // single keyword, but for a unit test, this saves a lot of boiler-plate code. -static const char* deckString1 = +constexpr const char* deckString1 = "RUNSPEC\n" "\n" "DIMENS\n" @@ -89,7 +92,7 @@ static const char* deckString1 = "\n"; -static const char* deckString2 = +constexpr const char* deckString2 = "RUNSPEC\n" "\n" "DIMENS\n" @@ -236,44 +239,44 @@ void ensurePvtApiBrineOil(const BrinePvt& brinePvt) } } -template -inline void testAll() +using Types = std::tuple; + +BOOST_AUTO_TEST_CASE_TEMPLATE(Oil, Scalar, Types) { Opm::Parser parser; auto python = std::make_shared(); - auto deck1 = parser.parseString(deckString1); - Opm::EclipseState eclState1(deck1); - Opm::Schedule schedule1(deck1, eclState1, python); + auto deck = parser.parseString(deckString1); + Opm::EclipseState eclState(deck); + Opm::Schedule schedule(deck, eclState, python); Opm::GasPvtMultiplexer co2Pvt_oil; Opm::OilPvtMultiplexer brinePvt_oil; - co2Pvt_oil.initFromState(eclState1, schedule1); - brinePvt_oil.initFromState(eclState1, schedule1); + BOOST_CHECK_NO_THROW(co2Pvt_oil.initFromState(eclState, schedule)); + BOOST_CHECK_NO_THROW(brinePvt_oil.initFromState(eclState, schedule)); - typedef Opm::DenseAd::Evaluation FooEval; + using Eval = Opm::DenseAd::Evaluation; ensurePvtApiGas(co2Pvt_oil); - ensurePvtApiBrineOil(brinePvt_oil); + ensurePvtApiBrineOil(brinePvt_oil); +} - auto deck2 = parser.parseString(deckString2); - Opm::EclipseState eclState2(deck2); - Opm::Schedule schedule2(deck2, eclState2, python); +BOOST_AUTO_TEST_CASE_TEMPLATE(Water, Scalar, Types) +{ + Opm::Parser parser; + auto python = std::make_shared(); + + auto deck = parser.parseString(deckString2); + Opm::EclipseState eclState(deck); + Opm::Schedule schedule(deck, eclState, python); Opm::GasPvtMultiplexer co2Pvt; Opm::WaterPvtMultiplexer brinePvt; - co2Pvt.initFromState(eclState2, schedule2); - brinePvt.initFromState(eclState2, schedule2); + BOOST_CHECK_NO_THROW(co2Pvt.initFromState(eclState, schedule)); + BOOST_CHECK_NO_THROW(brinePvt.initFromState(eclState, schedule)); - typedef Opm::DenseAd::Evaluation FooEval; + using Eval = Opm::DenseAd::Evaluation; ensurePvtApiGas(co2Pvt); - ensurePvtApiBrine(brinePvt); -} - -int main() -{ - testAll(); - testAll(); - return 0; + ensurePvtApiBrine(brinePvt); }