From 206243c78d58c0f173b451ec4781c5d6f5c1f842 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Thu, 8 Oct 2020 22:02:46 +0200 Subject: [PATCH] Compare string and integere members from well using RestartIO data --- test_util/EclRegressionTest.cpp | 55 ++++++++++++++++++++++++++++++++ tests/test_EclRegressionTest.cpp | 51 +++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/test_util/EclRegressionTest.cpp b/test_util/EclRegressionTest.cpp index 744f0907b..c1c4708cc 100644 --- a/test_util/EclRegressionTest.cpp +++ b/test_util/EclRegressionTest.cpp @@ -18,11 +18,15 @@ #include "EclRegressionTest.hpp" +#include + #include #include #include #include #include +#include +#include #include #include @@ -58,6 +62,52 @@ std::vector sorted(std::vector v) { } +template +int compare(const std::string& name, const T& v1, const T& v2, const std::string& fmt) { + if (v1 == v2) + return 0; + else { + fmt::print(stderr, fmt + std::string{"\n"}, name, v1, v2); + return 1; + } +} + + +bool rst_cmp(const Opm::RestartIO::RstState& rst1, const Opm::RestartIO::RstState& rst2) { + int error_count = 0; + const auto& header1 = rst1.header; + const auto& header2 = rst2.header; + if (header1.num_wells != header2.num_wells) { + fmt::print(stderr,"Different number of wells - reference: {} simulation: {}\n", header1.num_wells, header2.num_wells); + return false; + } + + for (std::size_t iw=0; iw < static_cast(header1.num_wells); iw++) { + const auto& well1 = rst1.wells[iw]; + const auto& well2 = rst2.wells[iw]; + + fmt::print(stderr, "Comparing well: {}", well1.name); + error_count += compare(well1.name, well1.name, well2.name, "Different names for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.group, well2.group, "Different groups for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.ij[0], well2.ij[0], "Different wellhead.i for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.ij[1], well2.ij[1], "Different wellhead.j for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.k1k2.first, well2.k1k2.first, "Different k1 for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.k1k2.second, well2.k1k2.second, "Different k2 for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.wtype.ecl_wtype(), well2.wtype.ecl_wtype(), "Different well_type for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.wtype.producer(), well2.wtype.producer(), "Different producer for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.well_status, well2.well_status, "Different status for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.active_control, well2.active_control, "Different active_control for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.vfp_table, well2.vfp_table, "Different vfp_table for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.pred_requested_control, well2.pred_requested_control,"Different pred_requested_control for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.allow_xflow, well2.allow_xflow, "Different allow_xflow for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.hist_requested_control, well2.hist_requested_control,"Different hist_requested_control for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.msw_index, well2.msw_index, "Different msw_index for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.completion_ordering, well2.completion_ordering, "Different completion_ordering for well: {} case1: {} case2: {}"); + error_count += compare(well1.name, well1.pvt_table, well2.pvt_table, "Different pvt_table for well: {} case1: {} case2: {}"); + } + return error_count == 0; +} + using namespace Opm::EclIO; @@ -844,6 +894,11 @@ void ECLRegressionTest::results_rst() std::cout << " done." << std::endl; } } + if (seqn > 0) { + const auto& rst_state1 = Opm::RestartIO::RstState::load(rst1, seqn); + const auto& rst_state2 = Opm::RestartIO::RstState::load(rst2, seqn); + rst_cmp(rst_state1, rst_state2); + } } } diff --git a/tests/test_EclRegressionTest.cpp b/tests/test_EclRegressionTest.cpp index de49798a4..939d86bdc 100644 --- a/tests/test_EclRegressionTest.cpp +++ b/tests/test_EclRegressionTest.cpp @@ -23,6 +23,8 @@ #include #include +#include +#include #include #include @@ -98,6 +100,7 @@ void makeInitFile(const std::string &fileName, std::vector floatKey } } +namespace VI = Opm::RestartIO::Helpers::VectorItems; void makeUnrstFile(const std::string &fileName, std::vector seqnum, const std::vector>& dates, @@ -133,6 +136,54 @@ void makeUnrstFile(const std::string &fileName, std::vector seqnum, eclTest.write("DOUBHEAD", doubhead); eclTest.write("ZGRP", zgrp); eclTest.write("IWEL", iwel); + + + // The blocks added below for groups, wells and connections respectively + // is just adding default data of correct consistent size to be able to + // load restart data. The content of these vectors is never used/checked. + { + std::size_t num_groups = intehead[VI::intehead::NGRP] + 1; + std::size_t nigrpz = intehead[VI::intehead::NIGRPZ]; + std::size_t nsgrpz = intehead[VI::intehead::NSGRPZ]; + std::size_t nxgrpz = intehead[VI::intehead::NXGRPZ]; + + std::vector igrp( num_groups * nigrpz ); + std::vector sgrp( num_groups * nsgrpz ); + std::vector xgrp( num_groups * nxgrpz ); + + eclTest.write("IGRP", igrp); + eclTest.write("SGRP", sgrp); + eclTest.write("XGRP", xgrp); + } + { + std::size_t num_wells = intehead[VI::intehead::NWELLS]; + std::size_t nzwelz = intehead[VI::intehead::NZWELZ]; + std::size_t nswelz = intehead[VI::intehead::NSWELZ]; + std::size_t nxwelz = intehead[VI::intehead::NXWELZ]; + + std::vector zwel( num_wells * nzwelz ); + std::vector swel( num_wells * nswelz ); + std::vector xwel( num_wells * nxwelz ); + + eclTest.write("ZWEL", zwel); + eclTest.write("SWEL", swel); + eclTest.write("XWEL", xwel); + } + { + std::size_t num_wells = intehead[VI::intehead::NWELLS]; + std::size_t num_connections = num_wells * intehead[VI::intehead::NCWMAX]; + std::size_t niconz = intehead[VI::intehead::NICONZ]; + std::size_t nsconz = intehead[VI::intehead::NSCONZ]; + std::size_t nxconz = intehead[VI::intehead::NXCONZ]; + + std::vector icon( num_connections * niconz ); + std::vector scon( num_connections * nsconz ); + std::vector xcon( num_connections * nxconz ); + + eclTest.write("ICON", icon); + eclTest.write("SCON", scon); + eclTest.write("XCON", xcon); + } eclTest.write("STARTSOL", std::vector()); for (size_t n = 0; n < solutionNames.size(); n++) {