2016-07-12 12:01:14 -05:00
|
|
|
/*
|
|
|
|
Copyright 2013, 2014, 2015 SINTEF ICT, Applied Mathematics.
|
|
|
|
Copyright 2014 Dr. Blatt - HPC-Simulation-Software & Services
|
|
|
|
Copyright 2015 IRIS AS
|
|
|
|
Copyright 2014 STATOIL ASA.
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
#ifndef OPM_FLOW_MAIN_EBOS_HEADER_INCLUDED
|
|
|
|
#define OPM_FLOW_MAIN_EBOS_HEADER_INCLUDED
|
|
|
|
|
2017-05-19 06:34:51 -05:00
|
|
|
|
2017-05-09 06:58:21 -05:00
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
2019-05-07 06:06:02 -05:00
|
|
|
#include <opm/simulators/utils/ParallelFileMerger.hpp>
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2016-07-12 12:01:14 -05:00
|
|
|
#include <opm/autodiff/BlackoilModelEbos.hpp>
|
2016-12-05 11:27:31 -06:00
|
|
|
#include <opm/autodiff/MissingFeatures.hpp>
|
2019-05-07 06:06:02 -05:00
|
|
|
#include <opm/simulators/utils/moduleVersion.hpp>
|
|
|
|
#include <opm/simulators/linalg/ExtractParallelGridInformationToISTL.hpp>
|
2017-05-22 12:35:38 -05:00
|
|
|
#include <opm/autodiff/SimulatorFullyImplicitBlackoilEbos.hpp>
|
2016-12-05 11:27:31 -06:00
|
|
|
|
|
|
|
#include <opm/core/props/satfunc/RelpermDiagnostics.hpp>
|
|
|
|
|
|
|
|
#include <opm/common/OpmLog/OpmLog.hpp>
|
|
|
|
#include <opm/common/OpmLog/EclipsePRTLog.hpp>
|
|
|
|
#include <opm/common/OpmLog/LogUtil.hpp>
|
|
|
|
|
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
|
|
|
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
2018-11-12 04:03:54 -06:00
|
|
|
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
2016-12-05 11:27:31 -06:00
|
|
|
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/InitConfig/InitConfig.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/checkDeck.hpp>
|
2016-07-12 12:01:14 -05:00
|
|
|
|
2017-10-05 09:55:26 -05:00
|
|
|
#if HAVE_DUNE_FEM
|
|
|
|
#include <dune/fem/misc/mpimanager.hh>
|
|
|
|
#else
|
|
|
|
#include <dune/common/parallel/mpihelper.hh>
|
|
|
|
#endif
|
2016-11-14 07:05:24 -06:00
|
|
|
|
2018-09-18 06:35:27 -05:00
|
|
|
BEGIN_PROPERTIES
|
2018-06-21 05:14:17 -05:00
|
|
|
|
2018-08-06 08:59:35 -05:00
|
|
|
NEW_PROP_TAG(OutputMode);
|
|
|
|
NEW_PROP_TAG(EnableDryRun);
|
|
|
|
NEW_PROP_TAG(OutputInterval);
|
|
|
|
NEW_PROP_TAG(UseAmg);
|
2019-01-14 06:06:21 -06:00
|
|
|
NEW_PROP_TAG(EnableLoggingFalloutWarning);
|
2018-06-21 05:14:17 -05:00
|
|
|
|
2018-08-06 08:59:35 -05:00
|
|
|
SET_STRING_PROP(EclFlowProblem, OutputMode, "all");
|
2018-06-21 05:14:17 -05:00
|
|
|
|
|
|
|
// TODO: enumeration parameters. we use strings for now.
|
2018-08-06 08:59:35 -05:00
|
|
|
SET_STRING_PROP(EclFlowProblem, EnableDryRun, "auto");
|
2019-01-14 06:06:21 -06:00
|
|
|
// Do not merge parallel output files or warn about them
|
|
|
|
SET_BOOL_PROP(EclFlowProblem, EnableLoggingFalloutWarning, false);
|
2018-08-06 08:59:35 -05:00
|
|
|
SET_INT_PROP(EclFlowProblem, OutputInterval, 1);
|
2018-06-21 05:14:17 -05:00
|
|
|
|
2018-09-18 06:35:27 -05:00
|
|
|
END_PROPERTIES
|
2018-06-21 05:14:17 -05:00
|
|
|
|
2016-07-12 12:01:14 -05:00
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
// The FlowMain class is the ebos based black-oil simulator.
|
2017-06-07 02:29:31 -05:00
|
|
|
template <class TypeTag>
|
2016-12-05 11:27:31 -06:00
|
|
|
class FlowMainEbos
|
2016-07-12 12:01:14 -05:00
|
|
|
{
|
2018-06-21 05:14:17 -05:00
|
|
|
enum FileOutputMode
|
|
|
|
{
|
2017-06-20 04:57:47 -05:00
|
|
|
//! \brief No output to files.
|
2018-06-26 06:42:57 -05:00
|
|
|
OUTPUT_NONE = 0,
|
2017-06-20 06:36:22 -05:00
|
|
|
//! \brief Output only to log files, no eclipse output.
|
2018-06-26 06:42:57 -05:00
|
|
|
OUTPUT_LOG_ONLY = 1,
|
2017-06-20 04:57:47 -05:00
|
|
|
//! \brief Output to all files.
|
2018-06-26 06:42:57 -05:00
|
|
|
OUTPUT_ALL = 3
|
2017-06-20 04:57:47 -05:00
|
|
|
};
|
|
|
|
|
2016-12-05 11:27:31 -06:00
|
|
|
public:
|
|
|
|
typedef typename GET_PROP(TypeTag, MaterialLaw)::EclMaterialLawManager MaterialLawManager;
|
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, Simulator) EbosSimulator;
|
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
|
2017-10-05 09:55:26 -05:00
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
|
2017-01-11 10:19:52 -06:00
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
|
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
|
2016-12-05 11:27:31 -06:00
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
|
|
|
|
|
2017-06-07 02:29:31 -05:00
|
|
|
typedef Opm::SimulatorFullyImplicitBlackoilEbos<TypeTag> Simulator;
|
2016-07-12 12:01:14 -05:00
|
|
|
|
2018-06-21 05:14:17 -05:00
|
|
|
// Read the command line parameters. Throws an exception if something goes wrong.
|
|
|
|
static int setupParameters_(int argc, char** argv)
|
|
|
|
{
|
|
|
|
// register the flow specific parameters
|
2018-08-06 08:59:35 -05:00
|
|
|
EWOMS_REGISTER_PARAM(TypeTag, std::string, OutputMode,
|
2018-06-21 05:14:17 -05:00
|
|
|
"Specify which messages are going to be printed. Valid values are: none, log, all (default)");
|
2018-08-06 08:59:35 -05:00
|
|
|
EWOMS_REGISTER_PARAM(TypeTag, std::string, EnableDryRun,
|
2018-06-21 05:14:17 -05:00
|
|
|
"Specify if the simulation ought to be actually run, or just pretended to be");
|
2018-08-06 08:59:35 -05:00
|
|
|
EWOMS_REGISTER_PARAM(TypeTag, int, OutputInterval,
|
2018-06-21 05:14:17 -05:00
|
|
|
"Specify the number of report steps between two consecutive writes of restart data");
|
2019-01-14 06:06:21 -06:00
|
|
|
EWOMS_REGISTER_PARAM(TypeTag, bool, EnableLoggingFalloutWarning,
|
|
|
|
"Developer option to see whether logging was on non-root processors. In that case it will be appended to the *.DBG or *.PRT files");
|
|
|
|
|
2018-06-21 05:14:17 -05:00
|
|
|
Simulator::registerParameters();
|
|
|
|
|
|
|
|
// register the parameters inherited from ebos
|
2018-06-29 06:41:54 -05:00
|
|
|
Ewoms::registerAllParameters_<TypeTag>(/*finalizeRegistration=*/false);
|
|
|
|
|
|
|
|
// hide the parameters unused by flow. TODO: this is a pain to maintain
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EnableGravity);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EnableGridAdaptation);
|
|
|
|
|
|
|
|
// this parameter is actually used in eWoms, but the flow well model
|
|
|
|
// hard-codes the assumption that the intensive quantities cache is enabled,
|
|
|
|
// so flow crashes. Let's hide the parameter for that reason.
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EnableIntensiveQuantityCache);
|
|
|
|
|
|
|
|
// thermodynamic hints are not implemented/required by the eWoms blackoil
|
|
|
|
// model
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EnableThermodynamicHints);
|
|
|
|
|
|
|
|
// in flow only the deck file determines the end time of the simulation
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EndTime);
|
|
|
|
|
2019-02-20 03:51:24 -06:00
|
|
|
// time stepping is not done by the eWoms code in flow
|
2018-06-29 06:41:54 -05:00
|
|
|
EWOMS_HIDE_PARAM(TypeTag, InitialTimeStepSize);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, MaxTimeStepDivisions);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, MaxTimeStepSize);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, MinTimeStepSize);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, PredeterminedTimeStepsFile);
|
|
|
|
|
2019-02-20 03:51:24 -06:00
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EclMaxTimeStepSizeAfterWellEvent);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EclRestartShrinkFactor);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EclMaxFails);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EclEnableTuning);
|
|
|
|
|
2018-06-29 06:41:54 -05:00
|
|
|
// flow also does not use the eWoms Newton method
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, NewtonMaxError);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, NewtonMaxIterations);
|
2019-03-01 03:48:06 -06:00
|
|
|
EWOMS_HIDE_PARAM(TypeTag, NewtonTolerance);
|
2018-06-29 06:41:54 -05:00
|
|
|
EWOMS_HIDE_PARAM(TypeTag, NewtonTargetIterations);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, NewtonVerbose);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, NewtonWriteConvergence);
|
2019-03-01 03:36:29 -06:00
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EclNewtonSumTolerance);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EclNewtonSumToleranceExponent);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EclNewtonStrictIterations);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EclNewtonRelaxedVolumeFraction);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, EclNewtonRelaxedTolerance);
|
2018-06-29 06:41:54 -05:00
|
|
|
|
|
|
|
// the default eWoms checkpoint/restart mechanism does not work with flow
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, RestartTime);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, RestartWritingInterval);
|
|
|
|
|
|
|
|
EWOMS_END_PARAM_REGISTRATION(TypeTag);
|
2018-06-21 05:14:17 -05:00
|
|
|
|
|
|
|
// read in the command line parameters
|
2018-06-29 06:41:54 -05:00
|
|
|
int status = Ewoms::setupParameters_<TypeTag>(argc, const_cast<const char**>(argv), /*doRegistration=*/false);
|
|
|
|
if (status == 0) {
|
|
|
|
// deal with --print-properties and --print-parameters
|
|
|
|
|
|
|
|
bool doExit = false;
|
|
|
|
|
|
|
|
int mpiRank = 0;
|
|
|
|
#if HAVE_MPI
|
|
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &mpiRank);
|
|
|
|
#endif
|
|
|
|
if (EWOMS_GET_PARAM(TypeTag, int, PrintProperties) == 1) {
|
|
|
|
doExit = true;
|
|
|
|
if (mpiRank == 0)
|
|
|
|
Ewoms::Properties::printValues<TypeTag>();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EWOMS_GET_PARAM(TypeTag, int, PrintParameters) == 1) {
|
|
|
|
doExit = true;
|
|
|
|
if (mpiRank == 0)
|
|
|
|
Ewoms::Parameters::printValues<TypeTag>();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doExit)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2018-06-21 05:14:17 -05:00
|
|
|
}
|
|
|
|
|
2018-10-22 03:37:16 -05:00
|
|
|
static void printBanner()
|
|
|
|
{
|
|
|
|
const int lineLen = 70;
|
|
|
|
const std::string version = moduleVersionName();
|
|
|
|
const std::string banner = "This is flow "+version;
|
|
|
|
const int bannerPreLen = (lineLen - 2 - banner.size())/2;
|
|
|
|
const int bannerPostLen = bannerPreLen + (lineLen - 2 - banner.size())%2;
|
|
|
|
std::cout << "**********************************************************************\n";
|
|
|
|
std::cout << "* *\n";
|
|
|
|
std::cout << "*" << std::string(bannerPreLen, ' ') << banner << std::string(bannerPostLen, ' ') << "*\n";
|
|
|
|
std::cout << "* *\n";
|
|
|
|
std::cout << "* Flow is a simulator for fully implicit three-phase black-oil flow, *\n";
|
|
|
|
std::cout << "* including solvent and polymer capabilities. *\n";
|
|
|
|
std::cout << "* For more information, see https://opm-project.org *\n";
|
|
|
|
std::cout << "* *\n";
|
|
|
|
std::cout << "**********************************************************************\n\n";
|
|
|
|
}
|
|
|
|
|
2018-06-21 05:14:17 -05:00
|
|
|
/// This is the main function of Flow. It runs a complete simulation with the
|
|
|
|
/// given grid and simulator classes, based on the user-specified command-line
|
|
|
|
/// input.
|
2017-10-10 07:07:07 -05:00
|
|
|
int execute(int argc, char** argv)
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
|
|
|
try {
|
2018-06-21 05:14:17 -05:00
|
|
|
// deal with some administrative boilerplate
|
|
|
|
|
|
|
|
int status = setupParameters_(argc, argv);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
setupParallelism();
|
|
|
|
setupOutput();
|
|
|
|
setupEbosSimulator();
|
|
|
|
setupLogging();
|
2019-05-13 03:27:42 -05:00
|
|
|
int unknownKeyWords = printPRTHeader();
|
|
|
|
#if HAVE_MPI
|
|
|
|
int globalUnknownKeyWords;
|
|
|
|
MPI_Allreduce(&unknownKeyWords, &globalUnknownKeyWords, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
|
|
|
|
unknownKeyWords = globalUnknownKeyWords;
|
|
|
|
#endif
|
|
|
|
if ( unknownKeyWords )
|
|
|
|
{
|
|
|
|
#if HAVE_MPI
|
|
|
|
MPI_Finalize();
|
|
|
|
#endif
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2018-06-26 06:42:57 -05:00
|
|
|
runDiagnostics();
|
|
|
|
createSimulator();
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2018-06-21 05:14:17 -05:00
|
|
|
// do the actual work
|
2018-06-26 06:42:57 -05:00
|
|
|
runSimulator();
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2018-06-21 05:14:17 -05:00
|
|
|
// clean up
|
2018-06-26 06:42:57 -05:00
|
|
|
mergeParallelLogFiles();
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2018-06-21 05:14:17 -05:00
|
|
|
return EXIT_SUCCESS;
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
2018-06-21 05:14:17 -05:00
|
|
|
catch (const std::exception& e) {
|
2016-12-05 11:27:31 -06:00
|
|
|
std::ostringstream message;
|
|
|
|
message << "Program threw an exception: " << e.what();
|
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
if (output_cout_) {
|
2016-12-05 11:27:31 -06:00
|
|
|
// in some cases exceptions are thrown before the logging system is set
|
|
|
|
// up.
|
|
|
|
if (OpmLog::hasBackend("STREAMLOG")) {
|
|
|
|
OpmLog::error(message.str());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::cout << message.str() << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-06-26 06:42:57 -05:00
|
|
|
void setupParallelism()
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
2017-10-05 09:55:26 -05:00
|
|
|
// determine the rank of the current process and the number of processes
|
2018-06-21 05:14:17 -05:00
|
|
|
// involved in the simulation. MPI must have already been initialized
|
|
|
|
// here. (yes, the name of this method is misleading.)
|
2017-10-05 09:55:26 -05:00
|
|
|
#if HAVE_MPI
|
2018-06-26 06:42:57 -05:00
|
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank_);
|
|
|
|
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size_);
|
2017-10-05 09:55:26 -05:00
|
|
|
#else
|
2018-06-26 06:42:57 -05:00
|
|
|
mpi_rank_ = 0;
|
|
|
|
mpi_size_ = 1;
|
2016-12-05 11:27:31 -06:00
|
|
|
#endif
|
2018-08-31 05:32:41 -05:00
|
|
|
|
|
|
|
#if _OPENMP
|
|
|
|
// if openMP is available, default to 2 threads per process.
|
|
|
|
if (!getenv("OMP_NUM_THREADS"))
|
|
|
|
omp_set_num_threads(std::min(2, omp_get_num_procs()));
|
|
|
|
#endif
|
|
|
|
|
2018-08-24 08:44:09 -05:00
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, ThreadManager) ThreadManager;
|
|
|
|
ThreadManager::init();
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
2016-08-08 08:26:09 -05:00
|
|
|
|
2018-06-21 05:14:17 -05:00
|
|
|
// Extract the minimum priority and determines if log files ought to be created.
|
2016-12-05 11:27:31 -06:00
|
|
|
// Writes to:
|
2018-06-26 06:42:57 -05:00
|
|
|
// output_to_files_
|
|
|
|
// output_
|
|
|
|
void setupOutput()
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
2018-06-21 05:14:17 -05:00
|
|
|
const std::string outputModeString =
|
2018-08-06 08:59:35 -05:00
|
|
|
EWOMS_GET_PARAM(TypeTag, std::string, OutputMode);
|
2018-06-21 05:14:17 -05:00
|
|
|
static std::map<std::string, FileOutputMode> stringToOutputMode =
|
2018-06-26 06:42:57 -05:00
|
|
|
{ {"none", OUTPUT_NONE },
|
|
|
|
{"false", OUTPUT_LOG_ONLY },
|
|
|
|
{"log", OUTPUT_LOG_ONLY },
|
|
|
|
{"all" , OUTPUT_ALL },
|
|
|
|
{"true" , OUTPUT_ALL }};
|
2018-06-21 05:14:17 -05:00
|
|
|
auto outputModeIt = stringToOutputMode.find(outputModeString);
|
|
|
|
if (outputModeIt != stringToOutputMode.end()) {
|
2018-06-26 06:42:57 -05:00
|
|
|
output_ = outputModeIt->second;
|
2017-06-20 04:57:47 -05:00
|
|
|
}
|
2018-06-21 05:14:17 -05:00
|
|
|
else {
|
2018-06-26 06:42:57 -05:00
|
|
|
output_ = OUTPUT_ALL;
|
2018-06-21 05:14:17 -05:00
|
|
|
std::cerr << "Value " << outputModeString <<
|
|
|
|
" is not a recognized output mode. Using \"all\" instead."
|
2017-06-20 08:27:05 -05:00
|
|
|
<< std::endl;
|
2017-06-20 04:57:47 -05:00
|
|
|
}
|
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
output_cout_ = false;
|
|
|
|
if (mpi_rank_ == 0) {
|
2018-08-06 08:59:35 -05:00
|
|
|
output_cout_ = EWOMS_GET_PARAM(TypeTag, bool, EnableTerminalOutput);
|
2018-06-26 06:42:57 -05:00
|
|
|
output_to_files_ = (output_ != OUTPUT_NONE);
|
2018-06-21 05:14:17 -05:00
|
|
|
}
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
|
2018-06-21 05:14:17 -05:00
|
|
|
// Setup the OpmLog backends
|
2018-06-26 06:42:57 -05:00
|
|
|
void setupLogging()
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
2018-06-26 06:42:57 -05:00
|
|
|
std::string deck_filename = EWOMS_GET_PARAM(TypeTag, std::string, EclDeckFileName);
|
2016-12-05 11:27:31 -06:00
|
|
|
// create logFile
|
2016-12-06 13:05:24 -06:00
|
|
|
using boost::filesystem::path;
|
2018-06-26 06:42:57 -05:00
|
|
|
path fpath(deck_filename);
|
2016-12-05 11:27:31 -06:00
|
|
|
std::string baseName;
|
|
|
|
std::ostringstream debugFileStream;
|
|
|
|
std::ostringstream logFileStream;
|
|
|
|
|
2019-01-16 04:58:47 -06:00
|
|
|
// Strip extension "." or ".DATA"
|
|
|
|
std::string extension = boost::to_upper_copy(fpath.extension().string());
|
|
|
|
if ( extension == ".DATA" || extension == "." )
|
|
|
|
{
|
|
|
|
baseName = boost::to_upper_copy(fpath.stem().string());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
baseName = boost::to_upper_copy(fpath.filename().string());
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
const std::string& output_dir = eclState().getIOConfig().getOutputDir();
|
|
|
|
logFileStream << output_dir << "/" << baseName;
|
|
|
|
debugFileStream << output_dir << "/" << baseName;
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
if (mpi_rank_ != 0) {
|
2016-12-05 11:27:31 -06:00
|
|
|
// Added rank to log file for non-zero ranks.
|
|
|
|
// This prevents message loss.
|
2018-06-26 06:42:57 -05:00
|
|
|
debugFileStream << "."<< mpi_rank_;
|
2016-12-05 11:27:31 -06:00
|
|
|
// If the following file appears then there is a bug.
|
2018-06-26 06:42:57 -05:00
|
|
|
logFileStream << "." << mpi_rank_;
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
logFileStream << ".PRT";
|
2018-06-25 15:22:29 -05:00
|
|
|
debugFileStream << ".DBG";
|
2016-12-05 11:27:31 -06:00
|
|
|
|
|
|
|
logFile_ = logFileStream.str();
|
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
if (output_ > OUTPUT_NONE) {
|
|
|
|
std::shared_ptr<EclipsePRTLog> prtLog = std::make_shared<EclipsePRTLog>(logFile_ , Log::NoDebugMessageTypes, false, output_cout_);
|
2017-06-20 01:30:22 -05:00
|
|
|
OpmLog::addBackend( "ECLIPSEPRTLOG" , prtLog );
|
|
|
|
prtLog->setMessageLimiter(std::make_shared<MessageLimiter>());
|
|
|
|
prtLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(false));
|
|
|
|
}
|
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
if (output_ >= OUTPUT_LOG_ONLY) {
|
2017-06-20 01:30:22 -05:00
|
|
|
std::string debugFile = debugFileStream.str();
|
2018-06-26 06:42:57 -05:00
|
|
|
std::shared_ptr<StreamLog> debugLog = std::make_shared<EclipsePRTLog>(debugFile, Log::DefaultMessageTypes, false, output_cout_);
|
2018-06-21 05:14:17 -05:00
|
|
|
OpmLog::addBackend("DEBUGLOG", debugLog);
|
2017-06-20 01:30:22 -05:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:27:31 -06:00
|
|
|
std::shared_ptr<StreamLog> streamLog = std::make_shared<StreamLog>(std::cout, Log::StdoutMessageTypes);
|
|
|
|
OpmLog::addBackend( "STREAMLOG", streamLog);
|
2018-06-26 06:42:57 -05:00
|
|
|
const auto& msgLimits = schedule().getMessageLimits();
|
2016-12-05 11:27:31 -06:00
|
|
|
const std::map<int64_t, int> limits = {{Log::MessageType::Note, msgLimits.getCommentPrintLimit(0)},
|
|
|
|
{Log::MessageType::Info, msgLimits.getMessagePrintLimit(0)},
|
|
|
|
{Log::MessageType::Warning, msgLimits.getWarningPrintLimit(0)},
|
|
|
|
{Log::MessageType::Error, msgLimits.getErrorPrintLimit(0)},
|
|
|
|
{Log::MessageType::Problem, msgLimits.getProblemPrintLimit(0)},
|
2017-05-09 07:05:01 -05:00
|
|
|
{Log::MessageType::Bug, msgLimits.getBugPrintLimit(0)}};
|
2016-12-05 11:27:31 -06:00
|
|
|
streamLog->setMessageLimiter(std::make_shared<MessageLimiter>(10, limits));
|
|
|
|
streamLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(true));
|
|
|
|
}
|
2017-08-23 08:58:55 -05:00
|
|
|
|
2018-06-21 05:14:17 -05:00
|
|
|
// Print an ASCII-art header to the PRT and DEBUG files.
|
2019-05-13 03:27:42 -05:00
|
|
|
// \return Whether unkown keywords were seen during parsing.
|
|
|
|
bool printPRTHeader()
|
2017-05-09 06:58:21 -05:00
|
|
|
{
|
2018-06-26 06:42:57 -05:00
|
|
|
if (output_cout_) {
|
2019-05-07 06:06:02 -05:00
|
|
|
const std::string version = moduleVersion();
|
2017-05-17 10:46:10 -05:00
|
|
|
const double megabyte = 1024 * 1024;
|
2018-06-26 06:42:57 -05:00
|
|
|
unsigned num_cpu = std::thread::hardware_concurrency();
|
2017-05-17 10:46:10 -05:00
|
|
|
struct utsname arch;
|
2017-08-23 08:58:55 -05:00
|
|
|
const char* user = getlogin();
|
2017-05-17 10:46:10 -05:00
|
|
|
time_t now = std::time(0);
|
|
|
|
struct tm tstruct;
|
|
|
|
char tmstr[80];
|
|
|
|
tstruct = *localtime(&now);
|
|
|
|
strftime(tmstr, sizeof(tmstr), "%d-%m-%Y at %X", &tstruct);
|
2018-06-26 06:42:57 -05:00
|
|
|
const double mem_size = getTotalSystemMemory() / megabyte;
|
2017-05-17 10:46:10 -05:00
|
|
|
std::ostringstream ss;
|
2017-11-17 08:41:46 -06:00
|
|
|
ss << "\n\n\n";
|
|
|
|
ss << " ######## # ###### # #\n";
|
2017-05-17 10:46:10 -05:00
|
|
|
ss << " # # # # # # \n";
|
|
|
|
ss << " ##### # # # # # # \n";
|
|
|
|
ss << " # # # # # # # # \n";
|
|
|
|
ss << " # ####### ###### # # \n\n";
|
|
|
|
ss << "Flow is a simulator for fully implicit three-phase black-oil flow,";
|
2018-04-20 04:31:15 -05:00
|
|
|
ss << " and is part of OPM.\nFor more information visit: https://opm-project.org \n\n";
|
2017-05-17 10:46:10 -05:00
|
|
|
ss << "Flow Version = " + version + "\n";
|
|
|
|
if (uname(&arch) == 0) {
|
2018-06-26 06:42:57 -05:00
|
|
|
ss << "System = " << arch.nodename << " (Number of logical cores: " << num_cpu;
|
|
|
|
ss << ", RAM: " << std::fixed << std::setprecision (2) << mem_size << " MB) \n";
|
2017-05-17 10:46:10 -05:00
|
|
|
ss << "Architecture = " << arch.sysname << " " << arch.machine << " (Release: " << arch.release;
|
|
|
|
ss << ", Version: " << arch.version << " )\n";
|
|
|
|
}
|
|
|
|
if (user) {
|
|
|
|
ss << "User = " << user << std::endl;
|
|
|
|
}
|
2017-08-23 08:58:55 -05:00
|
|
|
ss << "Simulation started on " << tmstr << " hrs\n";
|
2018-08-06 03:25:28 -05:00
|
|
|
|
2018-08-13 03:31:18 -05:00
|
|
|
ss << "Parameters used by Flow:\n";
|
2018-08-06 03:25:28 -05:00
|
|
|
Ewoms::Parameters::printValues<TypeTag>(ss);
|
|
|
|
|
2017-05-17 10:46:10 -05:00
|
|
|
OpmLog::note(ss.str());
|
2019-05-13 03:27:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( mpi_rank_ == 0 )
|
|
|
|
{
|
|
|
|
return Ewoms::Parameters::printUnused<TypeTag>(std::cerr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-09 06:58:21 -05:00
|
|
|
}
|
2017-08-23 08:58:55 -05:00
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
void mergeParallelLogFiles()
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
|
|
|
// force closing of all log files.
|
|
|
|
OpmLog::removeAllBackends();
|
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
if (mpi_rank_ != 0 || mpi_size_ < 2 || !output_to_files_) {
|
2016-12-05 11:27:31 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace fs = boost::filesystem;
|
2018-06-26 06:42:57 -05:00
|
|
|
const std::string& output_dir = eclState().getIOConfig().getOutputDir();
|
2018-09-05 07:03:00 -05:00
|
|
|
fs::path output_path(output_dir);
|
2018-06-26 06:42:57 -05:00
|
|
|
fs::path deck_filename(EWOMS_GET_PARAM(TypeTag, std::string, EclDeckFileName));
|
2019-01-16 04:58:47 -06:00
|
|
|
std::string basename;
|
|
|
|
// Strip extension "." and ".DATA"
|
|
|
|
std::string extension = boost::to_upper_copy(deck_filename.extension().string());
|
|
|
|
if ( extension == ".DATA" || extension == "." )
|
|
|
|
{
|
|
|
|
basename = boost::to_upper_copy(deck_filename.stem().string());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
basename = boost::to_upper_copy(deck_filename.filename().string());
|
|
|
|
}
|
2018-06-26 06:42:57 -05:00
|
|
|
std::for_each(fs::directory_iterator(output_path),
|
2016-12-05 11:27:31 -06:00
|
|
|
fs::directory_iterator(),
|
2019-01-14 06:06:21 -06:00
|
|
|
detail::ParallelFileMerger(output_path, basename,
|
2019-01-16 05:01:34 -06:00
|
|
|
EWOMS_GET_PARAM(TypeTag, bool, EnableLoggingFalloutWarning)));
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
void setupEbosSimulator()
|
2016-08-08 08:26:09 -05:00
|
|
|
{
|
2017-10-05 09:55:30 -05:00
|
|
|
ebosSimulator_.reset(new EbosSimulator(/*verbose=*/false));
|
2018-08-16 04:51:36 -05:00
|
|
|
ebosSimulator_->executionTimer().start();
|
2016-08-08 08:26:09 -05:00
|
|
|
ebosSimulator_->model().applyInitialSolution();
|
|
|
|
|
2016-12-05 11:27:31 -06:00
|
|
|
try {
|
2018-06-26 06:42:57 -05:00
|
|
|
if (output_cout_) {
|
|
|
|
MissingFeatures::checkKeywords(deck());
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Possible to force initialization only behavior (NOSIM).
|
2018-08-06 08:59:35 -05:00
|
|
|
const std::string& dryRunString = EWOMS_GET_PARAM(TypeTag, std::string, EnableDryRun);
|
2018-06-21 05:14:17 -05:00
|
|
|
if (dryRunString != "" && dryRunString != "auto") {
|
|
|
|
bool yesno;
|
|
|
|
if (dryRunString == "true"
|
|
|
|
|| dryRunString == "t"
|
|
|
|
|| dryRunString == "1")
|
|
|
|
yesno = true;
|
|
|
|
else if (dryRunString == "false"
|
|
|
|
|| dryRunString == "f"
|
|
|
|
|| dryRunString == "0")
|
|
|
|
yesno = false;
|
|
|
|
else
|
2018-08-06 08:59:35 -05:00
|
|
|
throw std::invalid_argument("Invalid value for parameter EnableDryRun: '"
|
2018-06-21 05:14:17 -05:00
|
|
|
+dryRunString+"'");
|
2018-06-26 06:42:57 -05:00
|
|
|
auto& ioConfig = eclState().getIOConfig();
|
2018-06-21 05:14:17 -05:00
|
|
|
ioConfig.overrideNOSIM(yesno);
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::invalid_argument& e) {
|
|
|
|
std::cerr << "Failed to create valid EclipseState object. See logfile: " << logFile_ << std::endl;
|
|
|
|
std::cerr << "Exception caught: " << e.what() << std::endl;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
const Deck& deck() const
|
2018-02-01 09:27:42 -06:00
|
|
|
{ return ebosSimulator_->vanguard().deck(); }
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
Deck& deck()
|
2018-02-01 09:27:42 -06:00
|
|
|
{ return ebosSimulator_->vanguard().deck(); }
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
const EclipseState& eclState() const
|
2018-02-01 09:27:42 -06:00
|
|
|
{ return ebosSimulator_->vanguard().eclState(); }
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
EclipseState& eclState()
|
2018-02-01 09:27:42 -06:00
|
|
|
{ return ebosSimulator_->vanguard().eclState(); }
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
const Schedule& schedule() const
|
2018-02-01 09:27:42 -06:00
|
|
|
{ return ebosSimulator_->vanguard().schedule(); }
|
2017-10-29 15:06:19 -05:00
|
|
|
|
2016-12-05 11:27:31 -06:00
|
|
|
|
|
|
|
// Run diagnostics.
|
|
|
|
// Writes to:
|
|
|
|
// OpmLog singleton.
|
2018-06-26 06:42:57 -05:00
|
|
|
void runDiagnostics()
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
2018-06-26 06:42:57 -05:00
|
|
|
if (!output_cout_) {
|
2016-12-05 11:27:31 -06:00
|
|
|
return;
|
2016-08-08 08:26:09 -05:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:27:31 -06:00
|
|
|
// Run relperm diagnostics
|
|
|
|
RelpermDiagnostics diagnostic;
|
2018-06-26 06:42:57 -05:00
|
|
|
diagnostic.diagnosis(eclState(), deck(), this->grid());
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run the simulator.
|
2018-06-26 06:42:57 -05:00
|
|
|
void runSimulator()
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
2018-06-26 06:42:57 -05:00
|
|
|
const auto& schedule = this->schedule();
|
2016-12-05 11:27:31 -06:00
|
|
|
const auto& timeMap = schedule.getTimeMap();
|
2018-06-26 06:42:57 -05:00
|
|
|
auto& ioConfig = eclState().getIOConfig();
|
2016-12-05 11:27:31 -06:00
|
|
|
SimulatorTimer simtimer;
|
|
|
|
|
|
|
|
// initialize variables
|
2018-06-26 06:42:57 -05:00
|
|
|
const auto& initConfig = eclState().getInitConfig();
|
2016-12-05 11:27:31 -06:00
|
|
|
simtimer.init(timeMap, (size_t)initConfig.getRestartStep());
|
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
if (output_cout_) {
|
2018-08-13 03:31:18 -05:00
|
|
|
std::ostringstream oss;
|
|
|
|
|
2018-06-21 05:14:17 -05:00
|
|
|
// This allows a user to catch typos and misunderstandings in the
|
|
|
|
// use of simulator parameters.
|
2018-08-13 03:31:18 -05:00
|
|
|
if (Ewoms::Parameters::printUnused<TypeTag>(oss)) {
|
|
|
|
std::cout << "----------------- Unrecognized parameters: -----------------\n";
|
|
|
|
std::cout << oss.str();
|
|
|
|
std::cout << "----------------------------------------------------------------" << std::endl;
|
|
|
|
}
|
2018-06-21 05:14:17 -05:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:27:31 -06:00
|
|
|
if (!ioConfig.initOnly()) {
|
2018-06-26 06:42:57 -05:00
|
|
|
if (output_cout_) {
|
2016-12-05 11:27:31 -06:00
|
|
|
std::string msg;
|
|
|
|
msg = "\n\n================ Starting main simulation loop ===============\n";
|
|
|
|
OpmLog::info(msg);
|
|
|
|
}
|
|
|
|
|
2017-12-04 03:35:13 -06:00
|
|
|
SimulatorReport successReport = simulator_->run(simtimer);
|
2017-04-10 08:55:30 -05:00
|
|
|
SimulatorReport failureReport = simulator_->failureReport();
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
if (output_cout_) {
|
2016-12-05 11:27:31 -06:00
|
|
|
std::ostringstream ss;
|
|
|
|
ss << "\n\n================ End of simulation ===============\n\n";
|
2017-04-10 08:55:30 -05:00
|
|
|
successReport.reportFullyImplicit(ss, &failureReport);
|
2016-12-05 11:27:31 -06:00
|
|
|
OpmLog::info(ss.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2018-06-26 06:42:57 -05:00
|
|
|
if (output_cout_) {
|
2016-12-05 11:27:31 -06:00
|
|
|
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
|
|
|
}
|
|
|
|
|
2016-08-08 08:26:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This is the main function of Flow.
|
2016-07-12 12:01:14 -05:00
|
|
|
// Create simulator instance.
|
|
|
|
// Writes to:
|
|
|
|
// simulator_
|
2018-06-26 06:42:57 -05:00
|
|
|
void createSimulator()
|
2016-07-12 12:01:14 -05:00
|
|
|
{
|
|
|
|
// Create the simulator instance.
|
2018-11-12 04:03:54 -06:00
|
|
|
simulator_.reset(new Simulator(*ebosSimulator_));
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
2017-08-23 08:58:55 -05:00
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
unsigned long long getTotalSystemMemory()
|
2017-05-17 10:46:10 -05:00
|
|
|
{
|
|
|
|
long pages = sysconf(_SC_PHYS_PAGES);
|
2018-06-26 06:42:57 -05:00
|
|
|
long page_size = sysconf(_SC_PAGE_SIZE);
|
|
|
|
return pages * page_size;
|
2017-05-17 10:46:10 -05:00
|
|
|
}
|
2016-12-05 11:27:31 -06:00
|
|
|
|
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
Grid& grid()
|
2018-02-01 09:27:42 -06:00
|
|
|
{ return ebosSimulator_->vanguard().grid(); }
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2018-06-21 05:14:17 -05:00
|
|
|
private:
|
2016-08-08 08:26:09 -05:00
|
|
|
std::unique_ptr<EbosSimulator> ebosSimulator_;
|
2018-06-26 06:42:57 -05:00
|
|
|
int mpi_rank_ = 0;
|
|
|
|
int mpi_size_ = 1;
|
|
|
|
bool output_cout_ = false;
|
|
|
|
FileOutputMode output_ = OUTPUT_ALL;
|
|
|
|
bool output_to_files_ = false;
|
|
|
|
boost::any parallel_information_;
|
2016-12-05 11:27:31 -06:00
|
|
|
std::unique_ptr<Simulator> simulator_;
|
|
|
|
std::string logFile_;
|
2016-07-12 12:01:14 -05:00
|
|
|
};
|
|
|
|
} // namespace Opm
|
|
|
|
|
2017-08-23 08:58:55 -05:00
|
|
|
#endif // OPM_FLOW_MAIN_EBOS_HEADER_INCLUDED
|