Merge flow_tag.hpp into Main.hpp.

Addresses the comments in PR #2521 regarding code duplication in
Main.hpp and flow_tag.hpp. This PR merges the code in flow_tag.hpp
into Main.hpp such that flow_tag.hpp can be eliminated (will be done
in the next PR).
This commit is contained in:
Håkon Hægland 2020-04-05 00:39:59 +02:00
parent a7126f45cd
commit 3624725885
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/>.
*/
#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)
{
auto mainObject = Opm::Main(argc, argv);
using TypeTag = TTAG(EclFlowProblemMain);
auto mainObject = Opm::Main<TypeTag>(argc, argv);
return mainObject.run();
}

View File

@ -24,21 +24,39 @@
#include <flow/flow_ebos_blackoil.hpp>
#ifndef FLOW_BLACKOIL_ONLY
#include <flow/flow_ebos_gasoil.hpp>
#include <flow/flow_ebos_oilwater.hpp>
#include <flow/flow_ebos_solvent.hpp>
#include <flow/flow_ebos_polymer.hpp>
#include <flow/flow_ebos_foam.hpp>
#include <flow/flow_ebos_brine.hpp>
#include <flow/flow_ebos_energy.hpp>
#include <flow/flow_ebos_oilwater_polymer.hpp>
#include <flow/flow_ebos_oilwater_polymer_injectivity.hpp>
#ifdef OPM_FLOW_MAIN
# ifndef FLOW_BLACKOIL_ONLY
# include <flow/flow_ebos_gasoil.hpp>
# include <flow/flow_ebos_oilwater.hpp>
# include <flow/flow_ebos_solvent.hpp>
# include <flow/flow_ebos_polymer.hpp>
# include <flow/flow_ebos_foam.hpp>
# include <flow/flow_ebos_brine.hpp>
# include <flow/flow_ebos_energy.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
#include <opm/simulators/flow/Main.hpp>
#include <opm/simulators/flow/FlowMainEbos.hpp>
#include <opm/simulators/utils/moduleVersion.hpp>
#include <opm/models/utils/propertysystem.hh>
#include <opm/models/utils/parametersystem.hh>
#include <opm/simulators/flow/MissingFeatures.hpp>
@ -47,18 +65,11 @@
#include <opm/common/OpmLog/EclipsePRTLog.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/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/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>
#if HAVE_DUNE_FEM
@ -72,6 +83,8 @@
#include <opm/simulators/utils/ParallelSerialization.hpp>
#endif
#include <type_traits>
BEGIN_PROPERTIES
// this is a dummy type tag that is used to setup the parameters before the actual
@ -80,6 +93,39 @@ NEW_TYPE_TAG(FlowEarlyBird, INHERITS_FROM(EclFlowProblem));
END_PROPERTIES
#ifndef OPM_FLOW_MAIN
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
{
// ----------------- Main class -----------------
@ -89,6 +135,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 TypeTag>
class Main
{
private:
@ -329,17 +376,22 @@ 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<PreTypeTag>(PreProblem::helpPreamble(
argc, const_cast<const char**>(argv)), e.what());
#endif
#if HAVE_MPI
MPI_Finalize();
#endif
return 1;
}
#ifdef OPM_FLOW_MAIN
if (outputCout) {
Opm::FlowMainEbos<PreTypeTag>::printBanner();
}
#endif
// 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<TypeTag>(deck.get(), *eclipseState, *schedule, *summaryConfig);
return Opm::flowEbosMain<TypeTag>(argc, argv, outputCout, outputFiles);
#endif /* OPM_FLOW_MAIN */
}
catch (const std::invalid_argument& e)
{