From 946b5f5806b89539050b75547b638a4f47e3afe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Mon, 11 May 2020 17:57:43 +0200 Subject: [PATCH] Refactor flow_ebos_blackoil.cpp (2) NOTE: this pull request depends on #2555 which should be merged first. A rewrite of the outdated PR #2543. Refactors flow_ebos_blackoil.cpp such that we can choose not to execute the whole simulation using the flowEbosBlackoilMain() function but instead only initialize by calling flowEbosBlackoilMainInit(). This is necessary to implement a Python step() method that can advance the simulator one report step at a time. Also adds a method initFlowEbosBlackoil() to Main.hpp that can be used directly from the Python interface's BlackOilSimulator object to gain access to the FlowMainEbos object before it has initialized the simulation main loop. --- flow/flow_ebos_blackoil.cpp | 14 ++++++++++---- flow/flow_ebos_blackoil.hpp | 5 +++++ opm/simulators/flow/Main.hpp | 25 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/flow/flow_ebos_blackoil.cpp b/flow/flow_ebos_blackoil.cpp index 809610682..e02595ba2 100644 --- a/flow/flow_ebos_blackoil.cpp +++ b/flow/flow_ebos_blackoil.cpp @@ -46,8 +46,8 @@ void flowEbosBlackoilSetDeck(double setupTime, Deck *deck, EclipseState& eclStat Vanguard::setExternalSummaryConfig(&summaryConfig); } -// ----------------- Main program ----------------- -int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFiles) +std::unique_ptr> +flowEbosBlackoilMainInit(int argc, char** argv, bool outputCout, bool outputFiles) { // we always want to use the default locale, and thus spare us the trouble // with incorrect locale settings. @@ -59,8 +59,14 @@ int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFile Dune::MPIHelper::instance(argc, argv); #endif - Opm::FlowMainEbos mainfunc; - return mainfunc.execute(argc, argv, outputCout, outputFiles); + return std::make_unique>(); +} + +// ----------------- Main program ----------------- +int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFiles) +{ + auto mainfunc = flowEbosBlackoilMainInit(argc, argv, outputCout, outputFiles); + return mainfunc->execute(argc, argv, outputCout, outputFiles); } } diff --git a/flow/flow_ebos_blackoil.hpp b/flow/flow_ebos_blackoil.hpp index 641d74aa2..3ca378919 100644 --- a/flow/flow_ebos_blackoil.hpp +++ b/flow/flow_ebos_blackoil.hpp @@ -21,10 +21,15 @@ #include #include #include +#include namespace Opm { void flowEbosBlackoilSetDeck(double setupTime, Deck *deck, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig); + int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFiles); + +std::unique_ptr> + flowEbosBlackoilMainInit(int argc, char** argv, bool outputCout, bool outputFiles); } #endif // FLOW_EBOS_BLACKOIL_HPP diff --git a/opm/simulators/flow/Main.hpp b/opm/simulators/flow/Main.hpp index 10815af73..1e7814fc6 100644 --- a/opm/simulators/flow/Main.hpp +++ b/opm/simulators/flow/Main.hpp @@ -117,6 +117,7 @@ namespace Opm class Main { private: + using FlowMainEbosType = Opm::FlowMainEbos; enum class FileOutputMode { //! \brief No output to files. OUTPUT_NONE = 0, @@ -174,6 +175,30 @@ namespace Opm } } + // To be called from the Python interface code. Only do the + // initialization and then return a pointer to the FlowEbosMain + // object that can later be accessed directly from the Python interface + // to e.g. advance the simulator one report step + std::unique_ptr initFlowEbosBlackoil(int& exitCode) + { + exitCode = EXIT_SUCCESS; + if (initialize_(exitCode)) { + // TODO: check that this deck really represents a blackoil + // case. E.g. check that number of phases == 3 + Opm::flowEbosBlackoilSetDeck( + setupTime_, + deck_.get(), + *eclipseState_, + *schedule_, + *summaryConfig_); + return Opm::flowEbosBlackoilMainInit( + argc_, argv_, outputCout_, outputFiles_); + } else { + exitCode = EXIT_FAILURE; + return std::unique_ptr(); // nullptr + } + } + private: int dispatchDynamic_() {