2017-08-23 08:58:55 -05:00
|
|
|
/*
|
|
|
|
Copyright 2013, 2014, 2015 SINTEF ICT, Applied Mathematics.
|
|
|
|
Copyright 2014 Dr. Blatt - HPC-Simulation-Software & Services
|
|
|
|
Copyright 2015, 2017 IRIS AS
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
2017-10-05 09:55:30 -05:00
|
|
|
#include <opm/simulators/flow_ebos_blackoil.hpp>
|
|
|
|
#include <opm/simulators/flow_ebos_gasoil.hpp>
|
|
|
|
#include <opm/simulators/flow_ebos_oilwater.hpp>
|
|
|
|
#include <opm/simulators/flow_ebos_solvent.hpp>
|
|
|
|
#include <opm/simulators/flow_ebos_polymer.hpp>
|
2018-03-26 03:50:33 -05:00
|
|
|
#include <opm/simulators/flow_ebos_energy.hpp>
|
2018-02-27 04:18:56 -06:00
|
|
|
#include <opm/simulators/flow_ebos_oilwater_polymer.hpp>
|
2017-08-23 08:58:55 -05:00
|
|
|
|
2017-10-05 09:55:30 -05:00
|
|
|
#include <opm/autodiff/MissingFeatures.hpp>
|
2018-01-30 06:25:35 -06:00
|
|
|
#include <opm/common/utility/parameters/ParameterGroup.hpp>
|
2018-02-07 03:27:32 -06:00
|
|
|
#include <opm/material/common/ResetLocale.hpp>
|
2017-10-05 09:55:26 -05:00
|
|
|
|
2017-08-23 08:58:55 -05:00
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
|
|
|
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/checkDeck.hpp>
|
|
|
|
|
2017-10-05 09:55:30 -05:00
|
|
|
#if HAVE_DUNE_FEM
|
|
|
|
#include <dune/fem/misc/mpimanager.hh>
|
|
|
|
#else
|
|
|
|
#include <dune/common/parallel/mpihelper.hh>
|
|
|
|
#endif
|
2017-08-23 08:58:55 -05:00
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
boost::filesystem::path simulationCaseName( const std::string& casename ) {
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
|
|
|
const auto exists = []( const fs::path& f ) -> bool {
|
|
|
|
if( !fs::exists( f ) ) return false;
|
|
|
|
|
|
|
|
if( fs::is_regular_file( f ) ) return true;
|
|
|
|
|
|
|
|
return fs::is_symlink( f )
|
|
|
|
&& fs::is_regular_file( fs::read_symlink( f ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto simcase = fs::path( casename );
|
|
|
|
|
|
|
|
if( exists( simcase ) ) {
|
|
|
|
return simcase;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const auto& ext : { std::string("data"), std::string("DATA") } ) {
|
|
|
|
if( exists( simcase.replace_extension( ext ) ) ) {
|
|
|
|
return simcase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw std::invalid_argument( "Cannot find input case " + casename );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------- Main program -----------------
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
// MPI setup.
|
2017-10-05 09:55:26 -05:00
|
|
|
#if HAVE_DUNE_FEM
|
|
|
|
Dune::Fem::MPIManager::initialize(argc, argv);
|
|
|
|
int mpiRank = Dune::Fem::MPIManager::rank();
|
|
|
|
#else
|
|
|
|
// the design of the plain dune MPIHelper class is quite flawed: there is no way to
|
|
|
|
// get the instance without having the argc and argv parameters available and it is
|
|
|
|
// not possible to determine the MPI rank and size without an instance. (IOW: the
|
|
|
|
// rank() and size() methods are supposed to be static.)
|
|
|
|
const auto& mpiHelper = Dune::MPIHelper::instance(argc, argv);
|
|
|
|
int mpiRank = mpiHelper.rank();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const bool outputCout = (mpiRank == 0);
|
|
|
|
|
|
|
|
// we always want to use the default locale, and thus spare us the trouble
|
|
|
|
// with incorrect locale settings.
|
|
|
|
Opm::resetLocale();
|
2017-08-23 08:58:55 -05:00
|
|
|
|
|
|
|
Opm::ParameterGroup param(argc, argv, false, outputCout);
|
2017-08-24 04:39:46 -05:00
|
|
|
|
2017-08-23 08:58:55 -05:00
|
|
|
// See if a deck was specified on the command line.
|
|
|
|
if (!param.unhandledArguments().empty()) {
|
|
|
|
if (param.unhandledArguments().size() != 1) {
|
2017-10-05 09:55:26 -05:00
|
|
|
if (outputCout)
|
|
|
|
std::cerr << "You can only specify a single input deck on the command line.\n";
|
2017-08-24 04:39:46 -05:00
|
|
|
return EXIT_FAILURE;
|
2017-08-23 08:58:55 -05:00
|
|
|
} else {
|
|
|
|
const auto casename = detail::simulationCaseName( param.unhandledArguments()[ 0 ] );
|
|
|
|
param.insertParameter("deck_filename", casename.string() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 04:39:46 -05:00
|
|
|
// We must have an input deck. Grid and props will be read from that.
|
|
|
|
if (!param.has("deck_filename")) {
|
2017-10-05 09:55:26 -05:00
|
|
|
if (outputCout)
|
|
|
|
std::cerr << "This program must be run with an input deck.\n"
|
|
|
|
"Specify the deck filename either\n"
|
|
|
|
" a) as a command line argument by itself\n"
|
|
|
|
" b) as a command line parameter with the syntax deck_filename=<path to your deck>, or\n"
|
|
|
|
" c) as a parameter in a parameter file (.param or .xml) passed to the program.\n";
|
2017-08-24 04:39:46 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-08-23 08:58:55 -05:00
|
|
|
std::string deckFilename = param.get<std::string>("deck_filename");
|
|
|
|
|
|
|
|
// Create Deck and EclipseState.
|
|
|
|
try {
|
|
|
|
Opm::Parser parser;
|
|
|
|
typedef std::pair<std::string, Opm::InputError::Action> ParseModePair;
|
|
|
|
typedef std::vector<ParseModePair> ParseModePairs;
|
|
|
|
ParseModePairs tmp;
|
|
|
|
tmp.push_back(ParseModePair(Opm::ParseContext::PARSE_RANDOM_SLASH, Opm::InputError::IGNORE));
|
|
|
|
tmp.push_back(ParseModePair(Opm::ParseContext::PARSE_MISSING_DIMS_KEYWORD, Opm::InputError::WARN));
|
|
|
|
tmp.push_back(ParseModePair(Opm::ParseContext::SUMMARY_UNKNOWN_WELL, Opm::InputError::WARN));
|
|
|
|
tmp.push_back(ParseModePair(Opm::ParseContext::SUMMARY_UNKNOWN_GROUP, Opm::InputError::WARN));
|
|
|
|
Opm::ParseContext parseContext(tmp);
|
|
|
|
|
|
|
|
std::shared_ptr<Opm::Deck> deck = std::make_shared< Opm::Deck >( parser.parseFile(deckFilename , parseContext) );
|
|
|
|
if ( outputCout ) {
|
2017-10-05 09:55:26 -05:00
|
|
|
Opm::checkDeck(*deck, parser);
|
2017-08-23 08:58:55 -05:00
|
|
|
Opm::MissingFeatures::checkKeywords(*deck);
|
|
|
|
}
|
|
|
|
Opm::Runspec runspec( *deck );
|
|
|
|
const auto& phases = runspec.phases();
|
|
|
|
|
2017-10-29 15:06:19 -05:00
|
|
|
std::shared_ptr<Opm::EclipseState> eclipseState = std::make_shared< Opm::EclipseState > ( *deck, parseContext );
|
|
|
|
std::shared_ptr<Opm::Schedule> schedule = std::make_shared<Opm::Schedule>(*deck, eclipseState->getInputGrid(), eclipseState->get3DProperties(), phases, parseContext);
|
|
|
|
std::shared_ptr<Opm::SummaryConfig> summary_config = std::make_shared<Opm::SummaryConfig>(*deck, *schedule, eclipseState->getTableManager(), parseContext);
|
|
|
|
// Twophase cases
|
2017-08-23 08:58:55 -05:00
|
|
|
if( phases.size() == 2 ) {
|
2017-08-31 00:50:28 -05:00
|
|
|
// oil-gas
|
|
|
|
if (phases.active( Opm::Phase::GAS ))
|
|
|
|
{
|
2017-10-29 15:06:19 -05:00
|
|
|
Opm::flowEbosGasOilSetDeck(*deck, *eclipseState, *schedule, *summary_config);
|
2017-10-05 09:55:30 -05:00
|
|
|
return Opm::flowEbosGasOilMain(argc, argv);
|
2017-08-31 00:50:28 -05:00
|
|
|
}
|
|
|
|
// oil-water
|
|
|
|
else if ( phases.active( Opm::Phase::WATER ) )
|
|
|
|
{
|
2017-10-29 15:06:19 -05:00
|
|
|
Opm::flowEbosOilWaterSetDeck(*deck, *eclipseState, *schedule, *summary_config);
|
2017-10-05 09:55:30 -05:00
|
|
|
return Opm::flowEbosOilWaterMain(argc, argv);
|
2017-08-31 00:50:28 -05:00
|
|
|
}
|
|
|
|
else {
|
2017-10-05 09:55:26 -05:00
|
|
|
if (outputCout)
|
|
|
|
std::cerr << "No suitable configuration found, valid are Twophase (oilwater and oilgas), polymer, solvent, or blackoil" << std::endl;
|
2017-08-31 00:50:28 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2017-08-23 08:58:55 -05:00
|
|
|
}
|
|
|
|
// Polymer case
|
|
|
|
else if ( phases.active( Opm::Phase::POLYMER ) ) {
|
2018-02-27 04:18:56 -06:00
|
|
|
|
|
|
|
if ( !phases.active( Opm::Phase::WATER) ) {
|
|
|
|
if (outputCout)
|
|
|
|
std::cerr << "No valid configuration is found for polymer simulation, valid options include "
|
|
|
|
<< "oilwater + polymer and blackoil + polymer" << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( phases.size() == 3 ) { // oil water polymer case
|
|
|
|
Opm::flowEbosOilWaterPolymerSetDeck(*deck, *eclipseState, *schedule, *summary_config);
|
|
|
|
return Opm::flowEbosOilWaterPolymerMain(argc, argv);
|
|
|
|
} else {
|
|
|
|
Opm::flowEbosPolymerSetDeck(*deck, *eclipseState, *schedule, *summary_config);
|
|
|
|
return Opm::flowEbosPolymerMain(argc, argv);
|
|
|
|
}
|
2017-08-23 08:58:55 -05:00
|
|
|
}
|
|
|
|
// Solvent case
|
|
|
|
else if ( phases.active( Opm::Phase::SOLVENT ) ) {
|
2017-10-29 15:06:19 -05:00
|
|
|
Opm::flowEbosSolventSetDeck(*deck, *eclipseState, *schedule, *summary_config);
|
2017-10-05 09:55:30 -05:00
|
|
|
return Opm::flowEbosSolventMain(argc, argv);
|
2017-08-23 08:58:55 -05:00
|
|
|
}
|
2018-03-26 03:50:33 -05:00
|
|
|
// Energy case
|
|
|
|
else if ( phases.active( Opm::Phase::ENERGY ) ) {
|
|
|
|
Opm::flowEbosEnergySetDeck(*deck, *eclipseState, *schedule, *summary_config);
|
|
|
|
return Opm::flowEbosEnergyMain(argc, argv);
|
|
|
|
}
|
2017-08-23 08:58:55 -05:00
|
|
|
// Blackoil case
|
|
|
|
else if( phases.size() == 3 ) {
|
2017-10-29 15:06:19 -05:00
|
|
|
Opm::flowEbosBlackoilSetDeck(*deck, *eclipseState, *schedule, *summary_config);
|
2017-10-05 09:55:30 -05:00
|
|
|
return Opm::flowEbosBlackoilMain(argc, argv);
|
2017-08-23 08:58:55 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-05 09:55:26 -05:00
|
|
|
if (outputCout)
|
2018-03-26 03:50:33 -05:00
|
|
|
std::cerr << "No suitable configuration found, valid are Twophase, polymer, solvent, energy, or blackoil" << std::endl;
|
2017-08-23 08:58:55 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::invalid_argument& e)
|
|
|
|
{
|
2017-10-05 09:55:26 -05:00
|
|
|
if (outputCout) {
|
|
|
|
std::cerr << "Failed to create valid EclipseState object." << std::endl;
|
|
|
|
std::cerr << "Exception caught: " << e.what() << std::endl;
|
|
|
|
}
|
2017-08-23 08:58:55 -05:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|