Merge pull request #2535 from hakonhagland/flow_tag_new_try

Merge flow_tag.hpp into Main.hpp (new try)
This commit is contained in:
Atgeirr Flø Rasmussen 2020-04-15 13:29:59 +02:00 committed by GitHub
commit 302474ade6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 95 additions and 25 deletions

View File

@ -19,12 +19,22 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>. along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "config.h" #include "config.h"
#include <opm/simulators/flow/Main.hpp> #include <opm/models/utils/propertysystem.hh>
#include <opm/models/utils/parametersystem.hh>
BEGIN_PROPERTIES
NEW_TYPE_TAG(EclFlowProblemMain);
END_PROPERTIES
#define OPM_FLOW_MAIN
#include <opm/simulators/flow/Main.hpp>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
auto mainObject = Opm::Main(argc, argv); using TypeTag = TTAG(EclFlowProblemMain);
auto mainObject = Opm::Main<TypeTag>(argc, argv);
return mainObject.run(); return mainObject.run();
} }

View File

@ -24,21 +24,39 @@
#include <flow/flow_ebos_blackoil.hpp> #include <flow/flow_ebos_blackoil.hpp>
#ifndef FLOW_BLACKOIL_ONLY #ifdef OPM_FLOW_MAIN
#include <flow/flow_ebos_gasoil.hpp> # ifndef FLOW_BLACKOIL_ONLY
#include <flow/flow_ebos_oilwater.hpp> # include <flow/flow_ebos_gasoil.hpp>
#include <flow/flow_ebos_solvent.hpp> # include <flow/flow_ebos_oilwater.hpp>
#include <flow/flow_ebos_polymer.hpp> # include <flow/flow_ebos_solvent.hpp>
#include <flow/flow_ebos_foam.hpp> # include <flow/flow_ebos_polymer.hpp>
#include <flow/flow_ebos_brine.hpp> # include <flow/flow_ebos_foam.hpp>
#include <flow/flow_ebos_energy.hpp> # include <flow/flow_ebos_brine.hpp>
#include <flow/flow_ebos_oilwater_polymer.hpp> # include <flow/flow_ebos_energy.hpp>
#include <flow/flow_ebos_oilwater_polymer_injectivity.hpp> # include <flow/flow_ebos_oilwater_polymer.hpp>
# include <flow/flow_ebos_oilwater_polymer_injectivity.hpp>
# endif
# include <opm/simulators/utils/moduleVersion.hpp>
# include <opm/io/eclipse/rst/state.hpp>
# include <opm/io/eclipse/ERst.hpp>
# include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
# include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
#else /* OPM_FLOW_MAIN */
# include <opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp>
# include <opm/common/utility/parameters/ParameterGroup.hpp>
# include <opm/material/common/ResetLocale.hpp>
# include <opm/parser/eclipse/Python/Python.hpp>
# include <opm/parser/eclipse/Parser/ParseContext.hpp>
# include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
# include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQAssign.hpp>
//# include <opm/material/fluidsystems/BlackOilFluidSystemSimple.hpp>
//# include <opm/material/fluidsystems/BlackOilFluidSystemSimple.hpp>
# include <opm/models/blackoil/blackoilintensivequantities.hh>
# include <opm/material/fluidstates/BlackOilFluidState.hpp>
//# include <opm/material/fluidstates/BlackOilFluidStateSimple.hpp>
#endif #endif
#include <opm/simulators/flow/Main.hpp>
#include <opm/simulators/flow/FlowMainEbos.hpp> #include <opm/simulators/flow/FlowMainEbos.hpp>
#include <opm/simulators/utils/moduleVersion.hpp>
#include <opm/models/utils/propertysystem.hh> #include <opm/models/utils/propertysystem.hh>
#include <opm/models/utils/parametersystem.hh> #include <opm/models/utils/parametersystem.hh>
#include <opm/simulators/flow/MissingFeatures.hpp> #include <opm/simulators/flow/MissingFeatures.hpp>
@ -47,18 +65,11 @@
#include <opm/common/OpmLog/EclipsePRTLog.hpp> #include <opm/common/OpmLog/EclipsePRTLog.hpp>
#include <opm/common/OpmLog/LogUtil.hpp> #include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/io/eclipse/rst/state.hpp>
#include <opm/io/eclipse/ERst.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp> #include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp> #include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp> #include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/checkDeck.hpp> #include <opm/parser/eclipse/EclipseState/checkDeck.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ArrayDimChecker.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/ArrayDimChecker.hpp>
#if HAVE_DUNE_FEM #if HAVE_DUNE_FEM
@ -72,6 +83,8 @@
#include <opm/simulators/utils/ParallelSerialization.hpp> #include <opm/simulators/utils/ParallelSerialization.hpp>
#endif #endif
#include <type_traits>
BEGIN_PROPERTIES BEGIN_PROPERTIES
// this is a dummy type tag that is used to setup the parameters before the actual // 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 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 <class TypeTag>
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 <class TypeTag>
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<TypeTag> mainfunc;
return mainfunc.execute(argc, argv, outputCout, outputFiles);
}
}
//#endif /* #ifndef OPM_FLOW_MAIN */
namespace Opm namespace Opm
{ {
// ----------------- Main class ----------------- // ----------------- Main class -----------------
@ -89,6 +137,7 @@ namespace Opm
// want to run the whole simulation by calling run(), it is also // 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 // 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. // usage scenarios, we refactored the original run() in flow.cpp into this class.
template <class TypeTag>
class Main class Main
{ {
private: private:
@ -329,17 +378,20 @@ namespace Opm
} }
catch (const std::exception& e) { catch (const std::exception& e) {
if ( mpiRank == 0 ) if ( mpiRank == 0 )
#ifdef OPM_FLOW_MAIN
std::cerr << "Exception received: " << e.what() << ". Try '--help' for a usage description.\n"; std::cerr << "Exception received: " << e.what() << ". Try '--help' for a usage description.\n";
#else
Opm::Parameters::printUsage<PreTypeTag>(PreProblem::helpPreamble(
argc, const_cast<const char**>(argv)), e.what());
#endif
#if HAVE_MPI #if HAVE_MPI
MPI_Finalize(); MPI_Finalize();
#endif #endif
return 1; return 1;
} }
if (outputCout) { if (outputCout) {
Opm::FlowMainEbos<PreTypeTag>::printBanner(); Opm::FlowMainEbos<PreTypeTag>::printBanner();
} }
// Create Deck and EclipseState. // Create Deck and EclipseState.
try { try {
if (outputCout) { if (outputCout) {
@ -380,6 +432,7 @@ namespace Opm
#else #else
eclipseState.reset(new Opm::EclipseState(*deck)); eclipseState.reset(new Opm::EclipseState(*deck));
#endif #endif
#ifdef OPM_FLOW_MAIN
/* /*
For the time being initializing wells and groups from the For the time being initializing wells and groups from the
restart file is not possible, but work is underways and it is 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) ); schedule.reset(new Opm::Schedule(*deck, *eclipseState, parseContext, errorGuard, python, &rst_state) );
} else } else
schedule.reset(new Opm::Schedule(*deck, *eclipseState, parseContext, errorGuard, python)); 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"); setupMessageLimiter_(schedule->getMessageLimits(), "STDOUT_LOGGER");
summaryConfig.reset( new Opm::SummaryConfig(*deck, *schedule, eclipseState->getTableManager(), parseContext, errorGuard)); 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."); throw std::runtime_error("Unrecoverable errors were encountered while loading input.");
} }
} }
const auto& phases = eclipseState->runspec().phases();
bool outputFiles = (outputMode != FileOutputMode::OUTPUT_NONE); bool outputFiles = (outputMode != FileOutputMode::OUTPUT_NONE);
#ifdef OPM_FLOW_MAIN
const auto& phases = eclipseState->runspec().phases();
// run the actual simulator // run the actual simulator
// //
// TODO: make sure that no illegal combinations like thermal and twophase are // 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; std::cerr << "No suitable configuration found, valid are Twophase, polymer, foam, brine, solvent, energy, blackoil." << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
#else
Opm::flowEbosSetDeck<TypeTag>(deck.get(), *eclipseState, *schedule, *summaryConfig);
return Opm::flowEbosMain<TypeTag>(argc, argv, outputCout, outputFiles);
#endif /* OPM_FLOW_MAIN */
} }
catch (const std::invalid_argument& e) catch (const std::invalid_argument& e)
{ {