From fa65ce92d8c1929f68119939619f00b4822a9010 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 9 Oct 2020 13:51:45 +0200 Subject: [PATCH] Allow loading of RstState for restart files without wells --- opm/io/eclipse/rst/state.hpp | 5 ++ src/opm/io/eclipse/rst/state.cpp | 78 ++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/opm/io/eclipse/rst/state.hpp b/opm/io/eclipse/rst/state.hpp index 5520aa4ca..c3d8689d6 100644 --- a/opm/io/eclipse/rst/state.hpp +++ b/opm/io/eclipse/rst/state.hpp @@ -35,6 +35,11 @@ namespace Opm { namespace RestartIO { struct RstState { + RstState(const ::Opm::UnitSystem& unit_system, + const std::vector& intehead, + const std::vector& logihead, + const std::vector& doubhead); + RstState(const ::Opm::UnitSystem& unit_system, const std::vector& intehead, const std::vector& logihead, diff --git a/src/opm/io/eclipse/rst/state.cpp b/src/opm/io/eclipse/rst/state.cpp index 74d46d618..adad43bbc 100644 --- a/src/opm/io/eclipse/rst/state.cpp +++ b/src/opm/io/eclipse/rst/state.cpp @@ -34,6 +34,16 @@ namespace VI = ::Opm::RestartIO::Helpers::VectorItems; namespace Opm { namespace RestartIO { +RstState::RstState(const ::Opm::UnitSystem& unit_system_, + const std::vector& intehead, + const std::vector& logihead, + const std::vector& doubhead): + unit_system(unit_system_), + header(intehead, logihead, doubhead) +{ + this->load_tuning(intehead, doubhead); +} + RstState::RstState(const ::Opm::UnitSystem& unit_system_, const std::vector& intehead, const std::vector& logihead, @@ -49,11 +59,9 @@ RstState::RstState(const ::Opm::UnitSystem& unit_system_, const std::vector& icon, const std::vector& scon, const std::vector& xcon): - unit_system(unit_system_), - header(intehead, logihead, doubhead) + RstState(unit_system_, intehead, logihead, doubhead) { this->add_groups(zgrp, igrp, sgrp, xgrp); - this->load_tuning(intehead, doubhead); for (int iw = 0; iw < this->header.num_wells; iw++) { std::size_t zwel_offset = iw * this->header.nzwelz; @@ -99,11 +107,9 @@ RstState::RstState(const ::Opm::UnitSystem& unit_system_, const std::vector& xcon, const std::vector& iseg, const std::vector& rseg) : - unit_system(unit_system_), - header(intehead, logihead, doubhead) + RstState(unit_system_, intehead, logihead, doubhead) { this->add_groups(zgrp, igrp, sgrp, xgrp); - this->load_tuning(intehead, doubhead); for (int iw = 0; iw < this->header.num_wells; iw++) { std::size_t zwel_offset = iw * this->header.nzwelz; @@ -207,39 +213,43 @@ RstState RstState::load(EclIO::ERst& rst_file, int report_step) { const auto& logihead = rst_file.getRst("LOGIHEAD", report_step, 0); const auto& doubhead = rst_file.getRst("DOUBHEAD", report_step, 0); - const auto& zgrp = rst_file.getRst("ZGRP", report_step, 0); - const auto& igrp = rst_file.getRst("IGRP", report_step, 0); - const auto& sgrp = rst_file.getRst("SGRP", report_step, 0); - const auto& xgrp = rst_file.getRst("XGRP", report_step, 0); - - const auto& zwel = rst_file.getRst("ZWEL", report_step, 0); - const auto& iwel = rst_file.getRst("IWEL", report_step, 0); - const auto& swel = rst_file.getRst("SWEL", report_step, 0); - const auto& xwel = rst_file.getRst("XWEL", report_step, 0); - - const auto& icon = rst_file.getRst("ICON", report_step, 0); - const auto& scon = rst_file.getRst("SCON", report_step, 0); - const auto& xcon = rst_file.getRst("XCON", report_step, 0); - auto unit_id = intehead[VI::intehead::UNIT]; ::Opm::UnitSystem unit_system(unit_id); - if (rst_file.hasKey("ISEG")) { - const auto& iseg = rst_file.getRst("ISEG", report_step, 0); - const auto& rseg = rst_file.getRst("RSEG", report_step, 0); + if (intehead[VI::intehead::NWELLS] != 0) { + const auto& zgrp = rst_file.getRst("ZGRP", report_step, 0); + const auto& igrp = rst_file.getRst("IGRP", report_step, 0); + const auto& sgrp = rst_file.getRst("SGRP", report_step, 0); + const auto& xgrp = rst_file.getRst("XGRP", report_step, 0); - return RstState(unit_system, - intehead, logihead, doubhead, - zgrp, igrp, sgrp, xgrp, - zwel, iwel, swel, xwel, - icon, scon, xcon, - iseg, rseg); + const auto& zwel = rst_file.getRst("ZWEL", report_step, 0); + const auto& iwel = rst_file.getRst("IWEL", report_step, 0); + const auto& swel = rst_file.getRst("SWEL", report_step, 0); + const auto& xwel = rst_file.getRst("XWEL", report_step, 0); + + const auto& icon = rst_file.getRst("ICON", report_step, 0); + const auto& scon = rst_file.getRst("SCON", report_step, 0); + const auto& xcon = rst_file.getRst("XCON", report_step, 0); + + + if (rst_file.hasKey("ISEG")) { + const auto& iseg = rst_file.getRst("ISEG", report_step, 0); + const auto& rseg = rst_file.getRst("RSEG", report_step, 0); + + return RstState(unit_system, + intehead, logihead, doubhead, + zgrp, igrp, sgrp, xgrp, + zwel, iwel, swel, xwel, + icon, scon, xcon, + iseg, rseg); + } else + return RstState(unit_system, + intehead, logihead, doubhead, + zgrp, igrp, sgrp, xgrp, + zwel, iwel, swel, xwel, + icon, scon, xcon); } else - return RstState(unit_system, - intehead, logihead, doubhead, - zgrp, igrp, sgrp, xgrp, - zwel, iwel, swel, xwel, - icon, scon, xcon); + return RstState(unit_system, intehead, logihead, doubhead); } }