diff --git a/flow/flow.cpp b/flow/flow.cpp index 1abc4acfd..50063aa74 100644 --- a/flow/flow.cpp +++ b/flow/flow.cpp @@ -19,12 +19,22 @@ along with OPM. If not, see . */ #include "config.h" -#include +#include +#include +BEGIN_PROPERTIES + +NEW_TYPE_TAG(EclFlowProblemMain); + +END_PROPERTIES + +#define OPM_FLOW_MAIN +#include int main(int argc, char** argv) { - auto mainObject = Opm::Main(argc, argv); + using TypeTag = TTAG(EclFlowProblemMain); + auto mainObject = Opm::Main(argc, argv); return mainObject.run(); } diff --git a/opm/simulators/flow/Main.hpp b/opm/simulators/flow/Main.hpp index 6419ae56e..bf7398858 100644 --- a/opm/simulators/flow/Main.hpp +++ b/opm/simulators/flow/Main.hpp @@ -24,21 +24,39 @@ #include -#ifndef FLOW_BLACKOIL_ONLY -#include -#include -#include -#include -#include -#include -#include -#include -#include +#ifdef OPM_FLOW_MAIN +# ifndef FLOW_BLACKOIL_ONLY +# include +# include +# include +# include +# include +# include +# include +# include +# include +# endif +# include +# include +# include +# include +# include +#else /* OPM_FLOW_MAIN */ +# include +# include +# include +# include +# include +# include +# include +//# include +//# include +# include +# include +//# include #endif -#include #include -#include #include #include #include @@ -47,18 +65,11 @@ #include #include -#include -#include #include #include -#include -#include #include #include -#include -#include - #include #if HAVE_DUNE_FEM @@ -72,6 +83,8 @@ #include #endif +#include + BEGIN_PROPERTIES // this is a dummy type tag that is used to setup the parameters before the actual @@ -80,6 +93,41 @@ NEW_TYPE_TAG(FlowEarlyBird, INHERITS_FROM(EclFlowProblem)); END_PROPERTIES +//#ifndef OPM_FLOW_MAIN // NOTE: since the methods in this #ifndef block are +// are template functions they will not be included +// in the code if not used, so #ifndef is commented out +namespace Opm { + template + void flowEbosSetDeck(Deck *deck, EclipseState& eclState, Schedule& schedule, SummaryConfig& summaryConfig) + { + typedef typename GET_PROP_TYPE(TypeTag, Vanguard) Vanguard; + Vanguard::setExternalDeck(deck); + Vanguard::setExternalEclState(&eclState); + Vanguard::setExternalSchedule(&schedule); + Vanguard::setExternalSummaryConfig(&summaryConfig); + } + +// ----------------- Main program ----------------- + template + int flowEbosMain(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. + Opm::resetLocale(); + +# if HAVE_DUNE_FEM + Dune::Fem::MPIManager::initialize(argc, argv); +# else + Dune::MPIHelper::instance(argc, argv); +# endif + Opm::FlowMainEbos mainfunc; + return mainfunc.execute(argc, argv, outputCout, outputFiles); + } + +} + +//#endif /* #ifndef OPM_FLOW_MAIN */ + namespace Opm { // ----------------- Main class ----------------- @@ -89,6 +137,7 @@ namespace Opm // want to run the whole simulation by calling run(), it is also // useful to just run one report step at a time. According to these different // usage scenarios, we refactored the original run() in flow.cpp into this class. + template class Main { private: @@ -329,17 +378,20 @@ namespace Opm } catch (const std::exception& e) { if ( mpiRank == 0 ) +#ifdef OPM_FLOW_MAIN std::cerr << "Exception received: " << e.what() << ". Try '--help' for a usage description.\n"; +#else + Opm::Parameters::printUsage(PreProblem::helpPreamble( + argc, const_cast(argv)), e.what()); +#endif #if HAVE_MPI MPI_Finalize(); #endif return 1; } - if (outputCout) { Opm::FlowMainEbos::printBanner(); } - // Create Deck and EclipseState. try { if (outputCout) { @@ -380,6 +432,7 @@ namespace Opm #else eclipseState.reset(new Opm::EclipseState(*deck)); #endif +#ifdef OPM_FLOW_MAIN /* For the time being initializing wells and groups from the restart file is not possible, but work is underways and it is @@ -395,7 +448,9 @@ namespace Opm schedule.reset(new Opm::Schedule(*deck, *eclipseState, parseContext, errorGuard, python, &rst_state) ); } else schedule.reset(new Opm::Schedule(*deck, *eclipseState, parseContext, errorGuard, python)); - +#else + schedule.reset(new Opm::Schedule(*deck, *eclipseState, parseContext, errorGuard, python)); +#endif /*OPM_FLOW_MAIN */ setupMessageLimiter_(schedule->getMessageLimits(), "STDOUT_LOGGER"); summaryConfig.reset( new Opm::SummaryConfig(*deck, *schedule, eclipseState->getTableManager(), parseContext, errorGuard)); } @@ -417,8 +472,9 @@ namespace Opm throw std::runtime_error("Unrecoverable errors were encountered while loading input."); } } - const auto& phases = eclipseState->runspec().phases(); bool outputFiles = (outputMode != FileOutputMode::OUTPUT_NONE); +#ifdef OPM_FLOW_MAIN + const auto& phases = eclipseState->runspec().phases(); // run the actual simulator // // TODO: make sure that no illegal combinations like thermal and twophase are @@ -504,6 +560,10 @@ namespace Opm std::cerr << "No suitable configuration found, valid are Twophase, polymer, foam, brine, solvent, energy, blackoil." << std::endl; return EXIT_FAILURE; } +#else + Opm::flowEbosSetDeck(deck.get(), *eclipseState, *schedule, *summaryConfig); + return Opm::flowEbosMain(argc, argv, outputCout, outputFiles); +#endif /* OPM_FLOW_MAIN */ } catch (const std::invalid_argument& e) {