/* Copyright 2014 SINTEF ICT, Applied Mathematics. Copyright 2014 Statoil ASA. This file is part of the Open Porous Media Project (OPM). OPM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OPM 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 General Public License for more details. You should have received a copy of the GNU General Public License along with OPM. If not, see . */ #include #if HAVE_DYNAMIC_BOOST_TEST #define BOOST_TEST_DYN_LINK #endif #define NVERBOSE #define BOOST_TEST_MODULE CompressedPropertyTest #include #include #include #include #include #include #include #include struct SetupSimple { SetupSimple() { Opm::ParserPtr parser(new Opm::Parser()); deck = parser->parseFile("compressed_gridproperty.data"); ecl.reset(new Opm::EclipseState(deck)); } Opm::DeckConstPtr deck; Opm::EclipseStateConstPtr ecl; }; template struct TestFixture : public Setup { TestFixture() : Setup () , grid (deck) , reltol(1.0e-10) { } using Setup::deck; using Setup::ecl; Opm::GridManager grid; const double reltol; }; BOOST_AUTO_TEST_SUITE(CompressedPropertyHandling) // Construct global array by extracting an "undefined" (unspecified) // double vector from the input deck. BOOST_FIXTURE_TEST_CASE(APExtractDoubleUndefined, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::ExtractFromDeck ECLGlobalDoubleArray; ECLGlobalDoubleArray multpv(ecl, "MULTPV", 1.0); BOOST_CHECK_CLOSE(multpv[0], 1.0, reltol); BOOST_CHECK_CLOSE(multpv[1], 1.0, reltol); BOOST_CHECK_CLOSE(multpv[2], 1.0, reltol); BOOST_CHECK_CLOSE(multpv[3], 1.0, reltol); } // Construct global array by extracting a fully defined (specified) // double vector from the input deck. BOOST_FIXTURE_TEST_CASE(APExtractDoubleDefined, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::ExtractFromDeck ECLGlobalDoubleArray; ECLGlobalDoubleArray ntg(ecl, "NTG", 1.0); BOOST_CHECK_CLOSE(ntg[0], 0.1, reltol); BOOST_CHECK_CLOSE(ntg[1], 0.2, reltol); BOOST_CHECK_CLOSE(ntg[2], 0.3, reltol); BOOST_CHECK_CLOSE(ntg[3], 0.4, reltol); } // Construct global array by extracting an undefined (unspecified) // integer (int) vector from the input deck. BOOST_FIXTURE_TEST_CASE(APExtractIntUndefined, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::ExtractFromDeck ECLGlobalIntArray; ECLGlobalIntArray imbnum(ecl, "IMBNUM", 1); BOOST_CHECK_EQUAL(imbnum[0], 1); BOOST_CHECK_EQUAL(imbnum[1], 1); BOOST_CHECK_EQUAL(imbnum[2], 1); BOOST_CHECK_EQUAL(imbnum[3], 1); } // Construct global array by extracting a fully defined (specified) // integer (int) vector from the input deck. BOOST_FIXTURE_TEST_CASE(APExtractIntDefined, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::ExtractFromDeck ECLGlobalIntArray; ECLGlobalIntArray satnum(ecl, "SATNUM", 1); BOOST_CHECK_EQUAL(satnum[0], 4); BOOST_CHECK_EQUAL(satnum[1], 3); BOOST_CHECK_EQUAL(satnum[2], 2); BOOST_CHECK_EQUAL(satnum[3], 1); } // Construct global, infinitely sized, double array by specifying a // single constant for all cells. BOOST_FIXTURE_TEST_CASE(APConstantDouble, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::Constant ConstantDoubleArray; const double c = 1.234e5; ConstantDoubleArray x(c); BOOST_CHECK_CLOSE(x[ 0], c, reltol); BOOST_CHECK_CLOSE(x[ 1], c, reltol); BOOST_CHECK_CLOSE(x[ 2], c, reltol); BOOST_CHECK_CLOSE(x[10000], c, reltol); // Infinite size array } // Construct global, infinitely sized, integer (int) array by // specifying a single constant for all cells. BOOST_FIXTURE_TEST_CASE(APConstantInt, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::Constant ConstantIntArray; const int i = 12345; ConstantIntArray a(i); BOOST_CHECK_EQUAL(a[ 0], i); BOOST_CHECK_EQUAL(a[ 1], i); BOOST_CHECK_EQUAL(a[ 2], i); BOOST_CHECK_EQUAL(a[10001], i); // Inifinite size array } // Construct compressed double array based on global, undefined array // extracted from input deck. Default ("any") type-check tag. BOOST_FIXTURE_TEST_CASE(CAExtractDoubleUndefinedAny, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::ExtractFromDeck ECLGlobalDoubleArray; typedef Opm::GridPropertyAccess:: Compressed CompressedArray; ECLGlobalDoubleArray multpv_glob(ecl, "MULTPV", 1.0); CompressedArray multpv(multpv_glob, grid.c_grid()->global_cell); BOOST_CHECK_CLOSE(multpv[0], 1.0, reltol); BOOST_CHECK_CLOSE(multpv[1], 1.0, reltol); } // Construct compressed double array based on global, fully specified // array extracted from input deck. Type-check tag: NTG. BOOST_FIXTURE_TEST_CASE(CAExtractDoubleDefinedNTG, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::ExtractFromDeck ECLGlobalDoubleArray; typedef Opm::GridPropertyAccess::Tag::NTG NTG; typedef Opm::GridPropertyAccess:: Compressed CompressedArray; ECLGlobalDoubleArray ntg_glob(ecl, "NTG", 1.0); CompressedArray ntg(ntg_glob, grid.c_grid()->global_cell); BOOST_CHECK_CLOSE(ntg[0], 0.2, reltol); BOOST_CHECK_CLOSE(ntg[1], 0.4, reltol); } // Construct compressed integer (int) array based on global, undefined // (unspecified) array extracted from input deck. Default ("any") // type-check tag. BOOST_FIXTURE_TEST_CASE(CAExtractIntUndefinedAny, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::ExtractFromDeck ECLGlobalIntArray; typedef Opm::GridPropertyAccess:: Compressed CompressedArray; ECLGlobalIntArray imbnum_glob(ecl, "IMBNUM", 1); CompressedArray imbnum(imbnum_glob, grid.c_grid()->global_cell); BOOST_CHECK_EQUAL(imbnum[0], 1); BOOST_CHECK_EQUAL(imbnum[1], 1); } // Construct compressed integer (int) array based on global, fully // specified array extracted from input deck. Custom type-check tag. struct RegionID : public Opm::GridPropertyAccess::Tag::Any {}; BOOST_FIXTURE_TEST_CASE(CAExtractIntDefinedCustom, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::ExtractFromDeck ECLGlobalIntArray; typedef Opm::GridPropertyAccess:: Compressed CompressedArray; ECLGlobalIntArray satnum_glob(ecl, "SATNUM", 1); CompressedArray satnum(satnum_glob, grid.c_grid()->global_cell); BOOST_CHECK_EQUAL(satnum[0], 3); BOOST_CHECK_EQUAL(satnum[1], 1); } // Construct compressed double array based on global constant value // for all cells. Default ("any") type-check tag. BOOST_FIXTURE_TEST_CASE(CAConstantDoubleAny, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::Constant ConstantDoubleArray; typedef Opm::GridPropertyAccess:: Compressed CompressedArray; const double c = 1.234e5; ConstantDoubleArray x_glob(c); CompressedArray x(x_glob, grid.c_grid()->global_cell); BOOST_CHECK_CLOSE(x[0], c, reltol); BOOST_CHECK_CLOSE(x[1], c, reltol); } // Construct compressed double array based on global constant value // for all cells. Custom type-check tag. struct MyTag : public Opm::GridPropertyAccess::Tag::Any {}; BOOST_FIXTURE_TEST_CASE(CAConstantDoubleCustom, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::Constant ConstantDoubleArray; typedef Opm::GridPropertyAccess:: Compressed CompressedArray; const double c = 1.234e5; ConstantDoubleArray x_glob(c); CompressedArray x(x_glob, grid.c_grid()->global_cell); BOOST_CHECK_CLOSE(x[0], c, reltol); BOOST_CHECK_CLOSE(x[1], c, reltol); } // Construct compressed integer (int) array based on global constant // value for all cells. Custom type-check tag. BOOST_FIXTURE_TEST_CASE(CAConstantIntAny, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::Constant ConstantIntArray; typedef Opm::GridPropertyAccess:: Compressed CompressedArray; const int i = 12345; ConstantIntArray x_glob(i); CompressedArray x(x_glob, grid.c_grid()->global_cell); BOOST_CHECK_EQUAL(x[0], i); BOOST_CHECK_EQUAL(x[1], i); } // Construct compressed integer (int) array based on global constant // value for all cells. Custom type-check tag. BOOST_FIXTURE_TEST_CASE(CAConstantIntCustom, TestFixture) { typedef Opm::GridPropertyAccess::ArrayPolicy ::Constant ConstantIntArray; typedef Opm::GridPropertyAccess:: Compressed CompressedArray; const int i = 12345; ConstantIntArray x_glob(i); CompressedArray x(x_glob, grid.c_grid()->global_cell); BOOST_CHECK_EQUAL(x[0], i); BOOST_CHECK_EQUAL(x[1], i); } BOOST_AUTO_TEST_SUITE_END()