2015-12-08 03:36:44 -06: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_FLOWMAIN_HEADER_INCLUDED
|
|
|
|
#define OPM_FLOWMAIN_HEADER_INCLUDED
|
|
|
|
|
|
|
|
|
|
|
|
#include <opm/common/utility/platform_dependent/disable_warnings.h>
|
|
|
|
|
|
|
|
#include <dune/common/version.hh>
|
|
|
|
#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3)
|
|
|
|
#include <dune/common/parallel/mpihelper.hh>
|
|
|
|
#else
|
|
|
|
#include <dune/common/mpihelper.hh>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <opm/common/utility/platform_dependent/reenable_warnings.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <opm/core/grid/GridManager.hpp>
|
|
|
|
#include <opm/autodiff/GridHelpers.hpp>
|
|
|
|
#include <opm/autodiff/createGlobalCellArray.hpp>
|
|
|
|
#include <opm/autodiff/GridInit.hpp>
|
2016-10-05 03:53:28 -05:00
|
|
|
#include <opm/simulators/ParallelFileMerger.hpp>
|
2015-12-08 03:36:44 -06:00
|
|
|
|
|
|
|
#include <opm/core/wells.h>
|
|
|
|
#include <opm/core/wells/WellsManager.hpp>
|
|
|
|
#include <opm/common/ErrorMacros.hpp>
|
|
|
|
#include <opm/core/simulator/initState.hpp>
|
|
|
|
#include <opm/core/simulator/initStateEquil.hpp>
|
|
|
|
#include <opm/core/simulator/SimulatorReport.hpp>
|
|
|
|
#include <opm/core/simulator/SimulatorTimer.hpp>
|
|
|
|
#include <opm/core/utility/miscUtilities.hpp>
|
|
|
|
#include <opm/core/utility/parameters/ParameterGroup.hpp>
|
2016-04-11 09:22:09 -05:00
|
|
|
#include <opm/simulators/thresholdPressures.hpp> // Note: the GridHelpers must be included before this (to make overloads available). \TODO: Fix.
|
2015-12-08 03:36:44 -06:00
|
|
|
|
|
|
|
#include <opm/material/fluidmatrixinteractions/EclMaterialLawManager.hpp>
|
|
|
|
#include <opm/core/props/BlackoilPropertiesBasic.hpp>
|
|
|
|
#include <opm/core/props/BlackoilPropertiesFromDeck.hpp>
|
|
|
|
#include <opm/core/props/rock/RockCompressibility.hpp>
|
2016-02-18 22:45:23 -06:00
|
|
|
#include <opm/core/props/satfunc/RelpermDiagnostics.hpp>
|
2015-12-08 03:36:44 -06:00
|
|
|
#include <opm/core/linalg/LinearSolverFactory.hpp>
|
|
|
|
#include <opm/autodiff/NewtonIterationBlackoilSimple.hpp>
|
|
|
|
#include <opm/autodiff/NewtonIterationBlackoilCPR.hpp>
|
|
|
|
#include <opm/autodiff/NewtonIterationBlackoilInterleaved.hpp>
|
|
|
|
|
|
|
|
#include <opm/autodiff/WellStateFullyImplicitBlackoil.hpp>
|
|
|
|
|
|
|
|
#include <opm/autodiff/BlackoilPropsAdFromDeck.hpp>
|
|
|
|
#include <opm/autodiff/RedistributeDataHandles.hpp>
|
|
|
|
#include <opm/autodiff/moduleVersion.hpp>
|
2016-07-06 21:38:29 -05:00
|
|
|
#include <opm/autodiff/MissingFeatures.hpp>
|
2015-12-08 03:36:44 -06:00
|
|
|
|
|
|
|
#include <opm/core/utility/share_obj.hpp>
|
2016-05-13 02:04:48 -05:00
|
|
|
#include <opm/core/utility/initHydroCarbonState.hpp>
|
2016-03-17 10:19:07 -05:00
|
|
|
#include <opm/common/OpmLog/OpmLog.hpp>
|
|
|
|
#include <opm/common/OpmLog/EclipsePRTLog.hpp>
|
2016-04-29 01:13:21 -05:00
|
|
|
#include <opm/common/OpmLog/LogUtil.hpp>
|
2015-12-08 03:36:44 -06:00
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
|
|
|
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
2016-03-16 19:55:52 -05:00
|
|
|
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
2015-12-08 03:36:44 -06:00
|
|
|
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
2016-01-20 08:11:30 -06:00
|
|
|
#include <opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp>
|
2016-01-05 05:39:02 -06:00
|
|
|
#include <opm/parser/eclipse/EclipseState/InitConfig/InitConfig.hpp>
|
2016-07-07 02:38:03 -05:00
|
|
|
#include <opm/parser/eclipse/EclipseState/checkDeck.hpp>
|
2016-12-08 05:13:31 -06:00
|
|
|
#include <opm/common/ResetLocale.hpp>
|
2015-12-08 03:36:44 -06:00
|
|
|
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _OPENMP
|
|
|
|
#include <omp.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <numeric>
|
|
|
|
#include <cstdlib>
|
2016-03-16 08:40:54 -05:00
|
|
|
#include <stdexcept>
|
2015-12-08 03:36:44 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
2016-03-16 08:40:54 -05:00
|
|
|
|
2016-04-29 07:59:18 -05:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
boost::filesystem::path simulationCaseName( const std::string& casename );
|
|
|
|
int64_t convertMessageType(const Message::type& mtype);
|
2016-03-16 08:40:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-14 03:46:00 -06:00
|
|
|
/// This class encapsulates the setup and running of
|
|
|
|
/// a simulator based on an input deck.
|
2015-12-14 06:51:59 -06:00
|
|
|
template <class Implementation, class Grid, class Simulator>
|
|
|
|
class FlowMainBase
|
2015-12-09 02:56:09 -06:00
|
|
|
{
|
|
|
|
public:
|
2015-12-11 10:01:08 -06:00
|
|
|
|
|
|
|
|
2015-12-14 03:46:00 -06:00
|
|
|
/// This is the main function of Flow.
|
|
|
|
/// It runs a complete simulation, with the given grid and
|
|
|
|
/// simulator classes, based on user command-line input. The
|
|
|
|
/// content of this function used to be in the main() function of
|
|
|
|
/// flow.cpp.
|
2015-12-09 02:56:09 -06:00
|
|
|
int execute(int argc, char** argv)
|
2015-12-08 03:36:44 -06:00
|
|
|
try {
|
2016-12-08 05:13:31 -06:00
|
|
|
// we always want to use the default locale, and thus spare us the trouble
|
|
|
|
// with incorrect locale settings.
|
|
|
|
resetLocale();
|
|
|
|
|
2015-12-11 10:01:08 -06:00
|
|
|
// Setup.
|
2015-12-14 06:51:59 -06:00
|
|
|
asImpl().setupParallelism(argc, argv);
|
|
|
|
asImpl().printStartupMessage();
|
|
|
|
const bool ok = asImpl().setupParameters(argc, argv);
|
2015-12-09 06:20:32 -06:00
|
|
|
if (!ok) {
|
2015-12-08 03:36:44 -06:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2015-12-14 06:51:59 -06:00
|
|
|
asImpl().setupOutput();
|
|
|
|
asImpl().readDeckInput();
|
2016-10-20 02:54:02 -05:00
|
|
|
asImpl().setupLogging();
|
2016-04-29 01:13:21 -05:00
|
|
|
asImpl().extractMessages();
|
2016-10-20 03:27:46 -05:00
|
|
|
asImpl().setupGridAndProps();
|
2016-02-19 02:40:45 -06:00
|
|
|
asImpl().runDiagnostics();
|
2015-12-14 06:51:59 -06:00
|
|
|
asImpl().setupState();
|
2016-07-22 10:37:14 -05:00
|
|
|
asImpl().writeInit();
|
2015-12-14 06:51:59 -06:00
|
|
|
asImpl().distributeData();
|
|
|
|
asImpl().setupOutputWriter();
|
|
|
|
asImpl().setupLinearSolver();
|
|
|
|
asImpl().createSimulator();
|
2016-11-22 09:36:40 -06:00
|
|
|
|
2015-12-11 10:01:08 -06:00
|
|
|
// Run.
|
2016-09-27 07:30:21 -05:00
|
|
|
auto ret = asImpl().runSimulator();
|
|
|
|
|
|
|
|
asImpl().mergeParallelLogFiles();
|
|
|
|
|
|
|
|
return ret;
|
2015-12-08 03:36:44 -06:00
|
|
|
}
|
|
|
|
catch (const std::exception &e) {
|
2016-09-23 04:50:11 -05:00
|
|
|
std::ostringstream message;
|
|
|
|
message << "Program threw an exception: " << e.what();
|
|
|
|
|
|
|
|
if( output_cout_ )
|
|
|
|
{
|
2016-11-03 10:02:04 -05: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";
|
|
|
|
}
|
2016-09-23 04:50:11 -05:00
|
|
|
}
|
|
|
|
|
2015-12-08 03:36:44 -06:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-12-09 03:51:03 -06:00
|
|
|
|
|
|
|
|
2015-12-14 06:51:59 -06:00
|
|
|
protected:
|
2015-12-09 03:51:03 -06:00
|
|
|
|
2015-12-14 03:46:00 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ------------ Types ------------
|
|
|
|
|
|
|
|
|
2015-12-11 10:01:08 -06:00
|
|
|
typedef BlackoilPropsAdFromDeck FluidProps;
|
|
|
|
typedef FluidProps::MaterialLawManager MaterialLawManager;
|
|
|
|
typedef typename Simulator::ReservoirState ReservoirState;
|
2016-09-12 16:28:44 -05:00
|
|
|
typedef typename Simulator::OutputWriter OutputWriter;
|
2015-12-11 10:01:08 -06:00
|
|
|
|
2015-12-09 03:51:03 -06:00
|
|
|
|
2015-12-14 03:46:00 -06:00
|
|
|
// ------------ Data members ------------
|
2015-12-09 04:20:53 -06:00
|
|
|
|
|
|
|
|
2015-12-14 03:46:00 -06:00
|
|
|
// The comments indicate in which method the
|
|
|
|
// members first occur.
|
2015-12-09 04:20:53 -06:00
|
|
|
|
2015-12-09 08:06:44 -06:00
|
|
|
// setupParallelism()
|
2016-09-19 09:51:02 -05:00
|
|
|
int mpi_rank_ = 0;
|
2015-12-09 03:51:03 -06:00
|
|
|
bool output_cout_ = false;
|
|
|
|
bool must_distribute_ = false;
|
2015-12-09 08:06:44 -06:00
|
|
|
// setupParameters()
|
2015-12-09 06:20:32 -06:00
|
|
|
parameter::ParameterGroup param_;
|
2015-12-09 08:06:44 -06:00
|
|
|
// setupOutput()
|
2015-12-09 06:37:20 -06:00
|
|
|
bool output_to_files_ = false;
|
2016-05-03 10:38:29 -05:00
|
|
|
std::string output_dir_ = std::string(".");
|
2015-12-09 08:06:44 -06:00
|
|
|
// readDeckInput()
|
2016-10-14 02:23:26 -05:00
|
|
|
std::shared_ptr<Deck> deck_;
|
2015-12-09 08:06:44 -06:00
|
|
|
std::shared_ptr<EclipseState> eclipse_state_;
|
2015-12-11 10:01:08 -06:00
|
|
|
// setupGridAndProps()
|
|
|
|
std::unique_ptr<GridInit<Grid>> grid_init_;
|
|
|
|
std::shared_ptr<MaterialLawManager> material_law_manager_;
|
|
|
|
std::unique_ptr<FluidProps> fluidprops_;
|
|
|
|
std::unique_ptr<RockCompressibility> rock_comp_;
|
|
|
|
std::array<double, 3> gravity_;
|
|
|
|
bool use_local_perm_ = true;
|
|
|
|
std::unique_ptr<DerivedGeology> geoprops_;
|
|
|
|
// setupState()
|
2016-02-28 04:27:00 -06:00
|
|
|
std::unique_ptr<ReservoirState> state_;
|
|
|
|
|
2015-12-11 10:01:08 -06:00
|
|
|
std::vector<double> threshold_pressures_;
|
|
|
|
// distributeData()
|
|
|
|
boost::any parallel_information_;
|
|
|
|
// setupOutputWriter()
|
2017-01-06 08:13:53 -06:00
|
|
|
std::unique_ptr<EclipseIO> eclipse_writer_;
|
2016-09-12 16:28:44 -05:00
|
|
|
std::unique_ptr<OutputWriter> output_writer_;
|
2015-12-11 10:01:08 -06:00
|
|
|
// setupLinearSolver
|
|
|
|
std::unique_ptr<NewtonIterationBlackoilInterface> fis_solver_;
|
|
|
|
// createSimulator()
|
|
|
|
std::unique_ptr<Simulator> simulator_;
|
2016-02-18 22:45:23 -06:00
|
|
|
// create log file
|
|
|
|
std::string logFile_;
|
2016-09-12 05:31:59 -05:00
|
|
|
// The names of wells that are artifically defunct in parallel runs.
|
|
|
|
// Those wells are handled on a another process.
|
|
|
|
std::unordered_set<std::string> defunct_well_names_;
|
2015-12-09 03:51:03 -06:00
|
|
|
// ------------ Methods ------------
|
|
|
|
|
2015-12-09 04:20:53 -06:00
|
|
|
|
|
|
|
// Set up MPI and OpenMP.
|
|
|
|
// Writes to:
|
|
|
|
// output_cout_
|
|
|
|
// must_distribute_
|
2015-12-09 03:51:03 -06:00
|
|
|
void setupParallelism(int argc, char** argv)
|
|
|
|
{
|
|
|
|
// MPI setup.
|
|
|
|
// Must ensure an instance of the helper is created to initialise MPI.
|
|
|
|
// For a build without MPI the Dune::FakeMPIHelper is used, so rank will
|
|
|
|
// be 0 and size 1.
|
|
|
|
const Dune::MPIHelper& mpi_helper = Dune::MPIHelper::instance(argc, argv);
|
2016-09-19 09:51:02 -05:00
|
|
|
mpi_rank_ = mpi_helper.rank();
|
2015-12-09 03:51:03 -06:00
|
|
|
const int mpi_size = mpi_helper.size();
|
2016-09-19 09:51:02 -05:00
|
|
|
output_cout_ = ( mpi_rank_ == 0 );
|
2015-12-09 03:51:03 -06:00
|
|
|
must_distribute_ = ( mpi_size > 1 );
|
|
|
|
|
|
|
|
#ifdef _OPENMP
|
|
|
|
// OpenMP setup.
|
|
|
|
if (!getenv("OMP_NUM_THREADS")) {
|
|
|
|
// Default to at most 4 threads, regardless of
|
|
|
|
// number of cores (unless ENV(OMP_NUM_THREADS) is defined)
|
|
|
|
int num_cores = omp_get_num_procs();
|
|
|
|
int num_threads = std::min(4, num_cores);
|
|
|
|
omp_set_num_threads(num_threads);
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
if (omp_get_thread_num() == 0) {
|
2015-12-09 04:12:43 -06:00
|
|
|
// omp_get_num_threads() only works as expected within a parallel region.
|
|
|
|
const int num_omp_threads = omp_get_num_threads();
|
|
|
|
if (mpi_size == 1) {
|
|
|
|
std::cout << "OpenMP using " << num_omp_threads << " threads." << std::endl;
|
|
|
|
} else {
|
2016-09-19 09:51:02 -05:00
|
|
|
std::cout << "OpenMP using " << num_omp_threads << " threads on MPI rank " << mpi_rank_ << "." << std::endl;
|
2015-12-09 04:12:43 -06:00
|
|
|
}
|
2015-12-09 03:51:03 -06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-05-03 03:12:29 -05:00
|
|
|
/// checks cartesian adjacency of global indices g1 and g2
|
|
|
|
bool cartesianAdjacent(const Grid& grid, int g1, int g2) {
|
|
|
|
// we need cartDims from UgGridHelpers
|
|
|
|
using namespace UgGridHelpers;
|
|
|
|
|
|
|
|
int diff = std::abs(g1 - g2);
|
|
|
|
|
|
|
|
const int * dimens = cartDims(grid);
|
|
|
|
if (diff == 1)
|
|
|
|
return true;
|
|
|
|
if (diff == dimens[0])
|
|
|
|
return true;
|
|
|
|
if (diff == dimens[0] * dimens[1])
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-09 04:20:53 -06:00
|
|
|
// Print startup message if on output rank.
|
|
|
|
void printStartupMessage()
|
|
|
|
{
|
|
|
|
if (output_cout_) {
|
|
|
|
const std::string version = moduleVersionName();
|
|
|
|
std::cout << "**********************************************************************\n";
|
|
|
|
std::cout << "* *\n";
|
|
|
|
std::cout << "* This is Flow (version " << version << ")"
|
|
|
|
<< std::string(26 - version.size(), ' ') << "*\n";
|
|
|
|
std::cout << "* *\n";
|
|
|
|
std::cout << "* Flow is a simulator for fully implicit three-phase black-oil flow, *\n";
|
|
|
|
std::cout << "* and is part of OPM. For more information see: *\n";
|
|
|
|
std::cout << "* http://opm-project.org *\n";
|
|
|
|
std::cout << "* *\n";
|
|
|
|
std::cout << "**********************************************************************\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-09 06:20:32 -06:00
|
|
|
// Read parameters, see if a deck was specified on the command line, and if
|
|
|
|
// it was, insert it into parameters.
|
|
|
|
// Writes to:
|
|
|
|
// param_
|
|
|
|
// Returns true if ok, false if not.
|
|
|
|
bool setupParameters(int argc, char** argv)
|
|
|
|
{
|
|
|
|
param_ = parameter::ParameterGroup(argc, argv, false, output_cout_);
|
|
|
|
|
|
|
|
// See if a deck was specified on the command line.
|
|
|
|
if (!param_.unhandledArguments().empty()) {
|
|
|
|
if (param_.unhandledArguments().size() != 1) {
|
|
|
|
std::cerr << "You can only specify a single input deck on the command line.\n";
|
|
|
|
return false;
|
|
|
|
} else {
|
2016-04-29 07:59:18 -05:00
|
|
|
const auto casename = detail::simulationCaseName( param_.unhandledArguments()[ 0 ] );
|
2016-03-16 08:40:54 -05:00
|
|
|
param_.insertParameter("deck_filename", casename.string() );
|
2015-12-09 06:20:32 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We must have an input deck. Grid and props will be read from that.
|
|
|
|
if (!param_.has("deck_filename")) {
|
|
|
|
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";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-09 06:37:20 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-06-16 01:02:34 -05:00
|
|
|
// Set output_to_files_ and set/create output dir. Write parameter file.
|
|
|
|
// Writes to:
|
|
|
|
// output_to_files_
|
|
|
|
// output_dir_
|
|
|
|
// Throws std::runtime_error if failed to create (if requested) output dir.
|
|
|
|
void setupOutput()
|
|
|
|
{
|
|
|
|
// Write parameters used for later reference. (only if rank is zero)
|
|
|
|
output_to_files_ = output_cout_ && param_.getDefault("output", true);
|
2016-09-15 14:42:14 -05:00
|
|
|
// Always read output_dir as it will be set unconditionally later.
|
|
|
|
// Not doing this might cause files to be created in the current
|
|
|
|
// directory.
|
|
|
|
output_dir_ =
|
|
|
|
param_.getDefault("output_dir", std::string("."));
|
|
|
|
|
2016-06-16 01:02:34 -05:00
|
|
|
if (output_to_files_) {
|
|
|
|
// Create output directory if needed.
|
|
|
|
boost::filesystem::path fpath(output_dir_);
|
|
|
|
if (!is_directory(fpath)) {
|
|
|
|
try {
|
|
|
|
create_directories(fpath);
|
|
|
|
}
|
|
|
|
catch (...) {
|
|
|
|
OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Write simulation parameters.
|
|
|
|
param_.writeParam(output_dir_ + "/simulation.param");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-15 02:24:05 -05:00
|
|
|
|
2016-06-16 01:02:34 -05:00
|
|
|
|
|
|
|
|
2016-11-22 09:36:40 -06:00
|
|
|
// Setup OpmLog backend with output_dir.
|
2016-06-15 02:24:05 -05:00
|
|
|
void setupLogging()
|
|
|
|
{
|
|
|
|
std::string deck_filename = param_.get<std::string>("deck_filename");
|
|
|
|
// create logFile
|
2016-11-22 09:36:40 -06:00
|
|
|
using boost::filesystem::path;
|
2016-06-15 02:24:05 -05:00
|
|
|
path fpath(deck_filename);
|
|
|
|
std::string baseName;
|
2016-09-19 09:51:02 -05:00
|
|
|
std::ostringstream debugFileStream;
|
|
|
|
std::ostringstream logFileStream;
|
|
|
|
|
2016-06-15 02:24:05 -05:00
|
|
|
if (boost::to_upper_copy(path(fpath.extension()).string()) == ".DATA") {
|
|
|
|
baseName = path(fpath.stem()).string();
|
|
|
|
} else {
|
|
|
|
baseName = path(fpath.filename()).string();
|
|
|
|
}
|
|
|
|
if (param_.has("output_dir")) {
|
2016-09-27 07:30:21 -05:00
|
|
|
logFileStream << output_dir_ << "/";
|
|
|
|
debugFileStream << output_dir_ + "/";
|
2016-09-19 09:51:02 -05:00
|
|
|
}
|
2016-09-27 07:30:21 -05:00
|
|
|
|
|
|
|
logFileStream << baseName;
|
|
|
|
debugFileStream << "." << baseName;
|
|
|
|
|
|
|
|
if ( must_distribute_ && mpi_rank_ != 0 )
|
2016-09-19 09:51:02 -05:00
|
|
|
{
|
|
|
|
// Added rank to log file for non-zero ranks.
|
|
|
|
// This prevents message loss.
|
|
|
|
debugFileStream << "."<< mpi_rank_;
|
|
|
|
// If the following file appears then there is a bug.
|
|
|
|
logFileStream << "." << mpi_rank_;
|
2016-06-15 02:24:05 -05:00
|
|
|
}
|
2016-09-27 07:30:21 -05:00
|
|
|
logFileStream << ".PRT";
|
|
|
|
debugFileStream << ".DEBUG";
|
|
|
|
|
2016-09-19 09:51:02 -05:00
|
|
|
std::string debugFile = debugFileStream.str();
|
|
|
|
logFile_ = logFileStream.str();
|
|
|
|
|
2016-09-15 14:28:53 -05:00
|
|
|
std::shared_ptr<EclipsePRTLog> prtLog = std::make_shared<EclipsePRTLog>(logFile_ , Log::NoDebugMessageTypes, false, output_cout_);
|
2016-06-15 02:24:05 -05:00
|
|
|
std::shared_ptr<StreamLog> streamLog = std::make_shared<StreamLog>(std::cout, Log::StdoutMessageTypes);
|
|
|
|
OpmLog::addBackend( "ECLIPSEPRTLOG" , prtLog );
|
|
|
|
OpmLog::addBackend( "STREAMLOG", streamLog);
|
2016-09-15 14:28:53 -05:00
|
|
|
std::shared_ptr<StreamLog> debugLog = std::make_shared<EclipsePRTLog>(debugFile, Log::DefaultMessageTypes, false, output_cout_);
|
2016-06-15 02:24:05 -05:00
|
|
|
OpmLog::addBackend( "DEBUGLOG" , debugLog);
|
2016-10-21 04:21:02 -05:00
|
|
|
const auto& msgLimits = eclipse_state_->getSchedule().getMessageLimits();
|
2016-10-20 08:00:51 -05:00
|
|
|
const std::map<int64_t, int> limits = {{Log::MessageType::Note, msgLimits.getCommentPrintLimit(0)},
|
2016-10-20 03:27:46 -05:00
|
|
|
{Log::MessageType::Info, msgLimits.getMessagePrintLimit(0)},
|
|
|
|
{Log::MessageType::Warning, msgLimits.getWarningPrintLimit(0)},
|
|
|
|
{Log::MessageType::Error, msgLimits.getErrorPrintLimit(0)},
|
|
|
|
{Log::MessageType::Problem, msgLimits.getProblemPrintLimit(0)},
|
|
|
|
{Log::MessageType::Bug, msgLimits.getBugPrintLimit(0)}};
|
2016-10-20 08:00:51 -05:00
|
|
|
prtLog->setMessageLimiter(std::make_shared<MessageLimiter>());
|
2016-06-15 02:24:05 -05:00
|
|
|
prtLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(false));
|
2016-10-20 02:54:02 -05:00
|
|
|
streamLog->setMessageLimiter(std::make_shared<MessageLimiter>(10, limits));
|
2016-06-15 02:24:05 -05:00
|
|
|
streamLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(true));
|
2016-10-05 03:53:28 -05:00
|
|
|
|
2016-06-15 20:48:39 -05:00
|
|
|
// Read parameters.
|
2016-09-19 09:49:47 -05:00
|
|
|
if ( output_cout_ )
|
|
|
|
{
|
|
|
|
OpmLog::debug("\n--------------- Reading parameters ---------------\n");
|
|
|
|
}
|
2016-06-15 02:24:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-09-27 07:30:21 -05:00
|
|
|
void mergeParallelLogFiles()
|
|
|
|
{
|
|
|
|
// force closing of all log files.
|
|
|
|
OpmLog::removeAllBackends();
|
2016-06-15 02:24:05 -05:00
|
|
|
|
2017-01-09 05:07:27 -06:00
|
|
|
if( mpi_rank_ != 0 || !must_distribute_ || !output_to_files_ )
|
2016-09-27 07:30:21 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-06-15 02:24:05 -05:00
|
|
|
|
2016-09-27 07:30:21 -05:00
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
fs::path output_path(".");
|
|
|
|
if ( param_.has("output_dir") )
|
|
|
|
{
|
|
|
|
output_path = fs::path(output_dir_);
|
|
|
|
}
|
2016-06-15 02:24:05 -05:00
|
|
|
|
2016-09-27 07:30:21 -05:00
|
|
|
fs::path deck_filename(param_.get<std::string>("deck_filename"));
|
2016-06-15 02:24:05 -05:00
|
|
|
|
2016-09-27 07:30:21 -05:00
|
|
|
std::for_each(fs::directory_iterator(output_path),
|
|
|
|
fs::directory_iterator(),
|
|
|
|
detail::ParallelFileMerger(output_path, deck_filename.stem().string()));
|
|
|
|
}
|
2016-06-15 02:24:05 -05:00
|
|
|
|
2015-12-09 08:06:44 -06:00
|
|
|
// Parser the input and creates the Deck and EclipseState objects.
|
|
|
|
// Writes to:
|
|
|
|
// deck_
|
|
|
|
// eclipse_state_
|
|
|
|
// May throw if errors are encountered, here configured to be somewhat tolerant.
|
|
|
|
void readDeckInput()
|
2016-06-29 01:03:38 -05:00
|
|
|
{
|
2016-02-18 22:45:23 -06:00
|
|
|
std::string deck_filename = param_.get<std::string>("deck_filename");
|
2016-06-15 02:24:05 -05:00
|
|
|
|
2015-12-09 08:06:44 -06:00
|
|
|
// Create Parser
|
2016-10-14 02:23:26 -05:00
|
|
|
Parser parser;
|
2015-12-09 08:06:44 -06:00
|
|
|
|
|
|
|
// Create Deck and EclipseState.
|
|
|
|
try {
|
2017-01-13 04:07:02 -06:00
|
|
|
ParseContext parseContext({ { ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE },
|
|
|
|
{ ParseContext::PARSE_MISSING_DIMS_KEYWORD, InputError::WARN } });
|
2016-10-14 02:23:26 -05:00
|
|
|
deck_ = std::make_shared< Deck >( parser.parseFile(deck_filename, parseContext) );
|
|
|
|
checkDeck(*deck_, parser);
|
2016-09-15 13:38:40 -05:00
|
|
|
|
|
|
|
if ( output_cout_)
|
|
|
|
{
|
|
|
|
MissingFeatures::checkKeywords(*deck_);
|
|
|
|
}
|
|
|
|
|
2016-08-08 03:07:09 -05:00
|
|
|
eclipse_state_.reset(new EclipseState(*deck_, parseContext));
|
2016-10-14 02:23:26 -05:00
|
|
|
auto& ioConfig = eclipse_state_->getIOConfig();
|
|
|
|
ioConfig.setOutputDir(output_dir_);
|
2015-12-09 08:06:44 -06:00
|
|
|
}
|
|
|
|
catch (const std::invalid_argument& e) {
|
2016-02-18 22:45:23 -06:00
|
|
|
std::cerr << "Failed to create valid EclipseState object. See logfile: " << logFile_ << std::endl;
|
2015-12-09 08:06:44 -06:00
|
|
|
std::cerr << "Exception caught: " << e.what() << std::endl;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Possibly override IOConfig setting (from deck) for how often RESTART files should get written to disk (every N report step)
|
|
|
|
if (param_.has("output_interval")) {
|
|
|
|
const int output_interval = param_.get<int>("output_interval");
|
2016-08-11 02:59:07 -05:00
|
|
|
eclipse_state_->getRestartConfig().overrideRestartWriteInterval( size_t( output_interval ) );
|
2015-12-09 08:06:44 -06:00
|
|
|
}
|
2016-06-29 01:03:38 -05:00
|
|
|
|
|
|
|
// Possible to force initialization only behavior (NOSIM).
|
|
|
|
if (param_.has("nosim")) {
|
|
|
|
const bool nosim = param_.get<bool>("nosim");
|
2016-10-14 02:23:26 -05:00
|
|
|
auto& ioConfig = eclipse_state_->getIOConfig();
|
|
|
|
ioConfig.overrideNOSIM( nosim );
|
2016-06-29 01:03:38 -05:00
|
|
|
}
|
2015-12-09 08:06:44 -06:00
|
|
|
}
|
|
|
|
|
2015-12-11 10:01:08 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create grid and property objects.
|
|
|
|
// Writes to:
|
|
|
|
// grid_init_
|
|
|
|
// material_law_manager_
|
|
|
|
// fluidprops_
|
|
|
|
// rock_comp_
|
|
|
|
// gravity_
|
|
|
|
// use_local_perm_
|
|
|
|
// geoprops_
|
|
|
|
void setupGridAndProps()
|
|
|
|
{
|
|
|
|
// Create grid.
|
2016-04-11 02:15:06 -05:00
|
|
|
const std::vector<double>& porv =
|
2016-04-11 08:15:27 -05:00
|
|
|
eclipse_state_->get3DProperties().getDoubleGridProperty("PORV").getData();
|
2016-10-14 02:23:26 -05:00
|
|
|
grid_init_.reset(new GridInit<Grid>(*eclipse_state_, porv));
|
2015-12-11 10:01:08 -06:00
|
|
|
const Grid& grid = grid_init_->grid();
|
|
|
|
|
|
|
|
// Create material law manager.
|
|
|
|
std::vector<int> compressedToCartesianIdx;
|
|
|
|
Opm::createGlobalCellArray(grid, compressedToCartesianIdx);
|
|
|
|
material_law_manager_.reset(new MaterialLawManager());
|
2016-10-14 02:23:26 -05:00
|
|
|
material_law_manager_->initFromDeck(*deck_, *eclipse_state_, compressedToCartesianIdx);
|
2015-12-11 10:01:08 -06:00
|
|
|
|
|
|
|
// Rock and fluid properties.
|
2016-10-14 02:23:26 -05:00
|
|
|
fluidprops_.reset(new BlackoilPropsAdFromDeck(*deck_, *eclipse_state_, material_law_manager_, grid));
|
2015-12-11 10:01:08 -06:00
|
|
|
|
|
|
|
// Rock compressibility.
|
2016-12-20 05:39:34 -06:00
|
|
|
rock_comp_.reset(new RockCompressibility(*eclipse_state_, output_cout_));
|
2015-12-11 10:01:08 -06:00
|
|
|
|
|
|
|
// Gravity.
|
|
|
|
assert(UgGridHelpers::dimensions(grid) == 3);
|
|
|
|
gravity_.fill(0.0);
|
|
|
|
gravity_[2] = deck_->hasKeyword("NOGRAV")
|
|
|
|
? param_.getDefault("gravity", 0.0)
|
|
|
|
: param_.getDefault("gravity", unit::gravity);
|
|
|
|
|
|
|
|
// Geological properties
|
|
|
|
use_local_perm_ = param_.getDefault("use_local_perm", use_local_perm_);
|
2016-10-14 02:23:26 -05:00
|
|
|
geoprops_.reset(new DerivedGeology(grid, *fluidprops_, *eclipse_state_, use_local_perm_, gravity_.data()));
|
2015-12-11 10:01:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialise the reservoir state. Updated fluid props for SWATINIT.
|
|
|
|
// Writes to:
|
|
|
|
// state_
|
|
|
|
// threshold_pressures_
|
|
|
|
// fluidprops_ (if SWATINIT is used)
|
|
|
|
void setupState()
|
|
|
|
{
|
2016-10-14 02:23:26 -05:00
|
|
|
const PhaseUsage pu = Opm::phaseUsageFromDeck(*deck_);
|
2015-12-11 10:01:08 -06:00
|
|
|
const Grid& grid = grid_init_->grid();
|
|
|
|
|
|
|
|
// Need old-style fluid object for init purposes (only).
|
2016-10-14 02:23:26 -05:00
|
|
|
BlackoilPropertiesFromDeck props( *deck_, *eclipse_state_, material_law_manager_,
|
2015-12-11 10:01:08 -06:00
|
|
|
Opm::UgGridHelpers::numCells(grid),
|
|
|
|
Opm::UgGridHelpers::globalCell(grid),
|
|
|
|
Opm::UgGridHelpers::cartDims(grid),
|
|
|
|
param_);
|
|
|
|
|
2016-02-28 04:27:00 -06:00
|
|
|
|
2015-12-11 10:01:08 -06:00
|
|
|
// Init state variables (saturation and pressure).
|
|
|
|
if (param_.has("init_saturation")) {
|
2016-02-28 04:27:00 -06:00
|
|
|
state_.reset( new ReservoirState( Opm::UgGridHelpers::numCells(grid),
|
|
|
|
Opm::UgGridHelpers::numFaces(grid),
|
|
|
|
props.numPhases() ));
|
|
|
|
|
2015-12-11 10:01:08 -06:00
|
|
|
initStateBasic(Opm::UgGridHelpers::numCells(grid),
|
|
|
|
Opm::UgGridHelpers::globalCell(grid),
|
|
|
|
Opm::UgGridHelpers::cartDims(grid),
|
|
|
|
Opm::UgGridHelpers::numFaces(grid),
|
|
|
|
Opm::UgGridHelpers::faceCells(grid),
|
|
|
|
Opm::UgGridHelpers::beginFaceCentroids(grid),
|
|
|
|
Opm::UgGridHelpers::beginCellCentroids(grid),
|
|
|
|
Opm::UgGridHelpers::dimensions(grid),
|
2016-02-28 04:27:00 -06:00
|
|
|
props, param_, gravity_[2], *state_);
|
2015-12-11 10:01:08 -06:00
|
|
|
|
2016-02-28 04:27:00 -06:00
|
|
|
initBlackoilSurfvol(Opm::UgGridHelpers::numCells(grid), props, *state_);
|
2015-12-11 10:01:08 -06:00
|
|
|
|
|
|
|
enum { Oil = BlackoilPhases::Liquid, Gas = BlackoilPhases::Vapour };
|
|
|
|
if (pu.phase_used[Oil] && pu.phase_used[Gas]) {
|
|
|
|
const int numPhases = props.numPhases();
|
|
|
|
const int numCells = Opm::UgGridHelpers::numCells(grid);
|
2016-02-28 04:27:00 -06:00
|
|
|
|
|
|
|
// Uglyness 1: The state is a templated type, here we however make explicit use BlackoilState.
|
|
|
|
auto& gor = state_->getCellData( BlackoilState::GASOILRATIO );
|
|
|
|
const auto& surface_vol = state_->getCellData( BlackoilState::SURFACEVOL );
|
2015-12-11 10:01:08 -06:00
|
|
|
for (int c = 0; c < numCells; ++c) {
|
2016-02-28 04:27:00 -06:00
|
|
|
// Uglyness 2: Here we explicitly use the layout of the saturation in the surface_vol field.
|
|
|
|
gor[c] = surface_vol[ c * numPhases + pu.phase_pos[Gas]] / surface_vol[ c * numPhases + pu.phase_pos[Oil]];
|
2015-12-11 10:01:08 -06:00
|
|
|
}
|
|
|
|
}
|
2016-06-08 02:22:52 -05:00
|
|
|
} else if (deck_->hasKeyword("EQUIL")) {
|
2016-02-28 04:27:00 -06:00
|
|
|
// Which state class are we really using - what a f... mess?
|
|
|
|
state_.reset( new ReservoirState( Opm::UgGridHelpers::numCells(grid),
|
|
|
|
Opm::UgGridHelpers::numFaces(grid),
|
|
|
|
props.numPhases()));
|
|
|
|
|
2016-10-14 02:23:26 -05:00
|
|
|
initStateEquil(grid, props, *deck_, *eclipse_state_, gravity_[2], *state_);
|
2016-02-28 04:27:00 -06:00
|
|
|
//state_.faceflux().resize(Opm::UgGridHelpers::numFaces(grid), 0.0);
|
2015-12-11 10:01:08 -06:00
|
|
|
} else {
|
2016-03-15 08:03:55 -05:00
|
|
|
state_.reset( new ReservoirState( Opm::UgGridHelpers::numCells(grid),
|
|
|
|
Opm::UgGridHelpers::numFaces(grid),
|
|
|
|
props.numPhases()));
|
2015-12-11 10:01:08 -06:00
|
|
|
initBlackoilStateFromDeck(Opm::UgGridHelpers::numCells(grid),
|
|
|
|
Opm::UgGridHelpers::globalCell(grid),
|
|
|
|
Opm::UgGridHelpers::numFaces(grid),
|
|
|
|
Opm::UgGridHelpers::faceCells(grid),
|
|
|
|
Opm::UgGridHelpers::beginFaceCentroids(grid),
|
|
|
|
Opm::UgGridHelpers::beginCellCentroids(grid),
|
|
|
|
Opm::UgGridHelpers::dimensions(grid),
|
2016-10-14 02:23:26 -05:00
|
|
|
props, *deck_, gravity_[2], *state_);
|
2015-12-11 10:01:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Threshold pressures.
|
|
|
|
std::map<std::pair<int, int>, double> maxDp;
|
2016-10-14 02:23:26 -05:00
|
|
|
computeMaxDp(maxDp, *deck_, *eclipse_state_, grid_init_->grid(), *state_, props, gravity_[2]);
|
|
|
|
threshold_pressures_ = thresholdPressures(*deck_, *eclipse_state_, grid, maxDp);
|
|
|
|
std::vector<double> threshold_pressures_nnc = thresholdPressuresNNC(*eclipse_state_, geoprops_->nnc(), maxDp);
|
2015-12-21 04:12:55 -06:00
|
|
|
threshold_pressures_.insert(threshold_pressures_.end(), threshold_pressures_nnc.begin(), threshold_pressures_nnc.end());
|
2015-12-11 10:01:08 -06:00
|
|
|
|
|
|
|
// The capillary pressure is scaled in fluidprops_ to match the scaled capillary pressure in props.
|
|
|
|
if (deck_->hasKeyword("SWATINIT")) {
|
|
|
|
const int numCells = Opm::UgGridHelpers::numCells(grid);
|
|
|
|
std::vector<int> cells(numCells);
|
|
|
|
for (int c = 0; c < numCells; ++c) { cells[c] = c; }
|
2016-02-28 04:27:00 -06:00
|
|
|
std::vector<double> pc = state_->saturation();
|
|
|
|
props.capPress(numCells, state_->saturation().data(), cells.data(), pc.data(), nullptr);
|
|
|
|
fluidprops_->setSwatInitScaling(state_->saturation(), pc);
|
2015-12-11 10:01:08 -06:00
|
|
|
}
|
2016-06-06 08:45:50 -05:00
|
|
|
initHydroCarbonState(*state_, pu, Opm::UgGridHelpers::numCells(grid), deck_->hasKeyword("DISGAS"), deck_->hasKeyword("VAPOIL"));
|
|
|
|
|
|
|
|
|
2015-12-11 10:01:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Distribute the grid, properties and state.
|
|
|
|
// Writes to:
|
|
|
|
// grid_init_->grid()
|
|
|
|
// state_
|
|
|
|
// fluidprops_
|
|
|
|
// geoprops_
|
|
|
|
// material_law_manager_
|
|
|
|
// parallel_information_
|
|
|
|
void distributeData()
|
|
|
|
{
|
|
|
|
// At this point all properties and state variables are correctly initialized
|
|
|
|
// If there are more than one processors involved, we now repartition the grid
|
|
|
|
// and initilialize new properties and states for it.
|
|
|
|
if (must_distribute_) {
|
2016-09-12 05:31:59 -05:00
|
|
|
defunct_well_names_ =
|
2016-10-14 02:23:26 -05:00
|
|
|
distributeGridAndData(grid_init_->grid(), *deck_, *eclipse_state_,
|
2016-09-12 05:31:59 -05:00
|
|
|
*state_, *fluidprops_, *geoprops_,
|
|
|
|
material_law_manager_, threshold_pressures_,
|
|
|
|
parallel_information_, use_local_perm_);
|
2015-12-11 10:01:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-29 07:59:18 -05:00
|
|
|
// Extract messages from parser.
|
2016-02-18 22:45:23 -06:00
|
|
|
// Writes to:
|
2016-04-29 07:59:18 -05:00
|
|
|
// OpmLog singleton.
|
2016-04-29 01:13:21 -05:00
|
|
|
void extractMessages()
|
|
|
|
{
|
2016-09-15 09:35:45 -05:00
|
|
|
if ( !output_cout_ )
|
2016-10-05 03:53:28 -05:00
|
|
|
{
|
2016-09-15 09:35:45 -05:00
|
|
|
return;
|
2016-10-05 03:53:28 -05:00
|
|
|
}
|
2016-09-15 09:35:45 -05:00
|
|
|
|
2016-04-29 07:58:44 -05:00
|
|
|
auto extractMessage = [](const Message& msg) {
|
|
|
|
auto log_type = detail::convertMessageType(msg.mtype);
|
2016-04-29 01:13:21 -05:00
|
|
|
const auto& location = msg.location;
|
|
|
|
if (location) {
|
|
|
|
OpmLog::addMessage(log_type, Log::fileMessage(location.filename, location.lineno, msg.message));
|
|
|
|
} else {
|
|
|
|
OpmLog::addMessage(log_type, msg.message);
|
|
|
|
}
|
2016-04-29 07:58:44 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// Extract messages from Deck.
|
|
|
|
for(const auto& msg : deck_->getMessageContainer()) {
|
|
|
|
extractMessage(msg);
|
2016-04-29 01:13:21 -05:00
|
|
|
}
|
2016-04-29 07:58:44 -05:00
|
|
|
|
|
|
|
// Extract messages from EclipseState.
|
2016-04-29 01:13:21 -05:00
|
|
|
for (const auto& msg : eclipse_state_->getMessageContainer()) {
|
2016-04-29 07:58:44 -05:00
|
|
|
extractMessage(msg);
|
2016-04-29 01:13:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-29 07:59:18 -05:00
|
|
|
|
|
|
|
// Run diagnostics.
|
2016-02-18 22:45:23 -06:00
|
|
|
// Writes to:
|
2016-04-29 07:59:18 -05:00
|
|
|
// OpmLog singleton.
|
2016-02-18 22:45:23 -06:00
|
|
|
void runDiagnostics()
|
|
|
|
{
|
2016-09-15 14:29:58 -05:00
|
|
|
if( ! output_cout_ )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-18 22:45:23 -06:00
|
|
|
// Run relperm diagnostics
|
2016-03-31 23:33:02 -05:00
|
|
|
RelpermDiagnostics diagnostic;
|
2016-10-14 02:23:26 -05:00
|
|
|
diagnostic.diagnosis(*eclipse_state_, *deck_, grid_init_->grid());
|
2016-02-18 22:45:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-22 10:37:14 -05:00
|
|
|
void writeInit()
|
|
|
|
{
|
|
|
|
bool output = param_.getDefault("output", true);
|
|
|
|
bool output_ecl = param_.getDefault("output_ecl", true);
|
|
|
|
const Grid& grid = grid_init_->grid();
|
|
|
|
if( output && output_ecl && output_cout_)
|
|
|
|
{
|
2016-10-14 02:23:26 -05:00
|
|
|
const EclipseGrid& inputGrid = eclipse_state_->getInputGrid();
|
2017-01-06 08:13:53 -06:00
|
|
|
eclipse_writer_.reset(new EclipseIO(*eclipse_state_, UgGridHelpers::createEclipseGrid( grid , inputGrid )));
|
2016-11-22 02:52:41 -06:00
|
|
|
eclipse_writer_->writeInitial(geoprops_->simProps(grid),
|
|
|
|
geoprops_->nonCartesianConnections());
|
2016-07-22 10:37:14 -05:00
|
|
|
}
|
|
|
|
}
|
2016-02-18 22:45:23 -06:00
|
|
|
|
|
|
|
|
2015-12-11 10:01:08 -06:00
|
|
|
// Setup output writer.
|
|
|
|
// Writes to:
|
|
|
|
// output_writer_
|
|
|
|
void setupOutputWriter()
|
|
|
|
{
|
|
|
|
// create output writer after grid is distributed, otherwise the parallel output
|
|
|
|
// won't work correctly since we need to create a mapping from the distributed to
|
|
|
|
// the global view
|
2016-09-12 16:28:44 -05:00
|
|
|
output_writer_.reset(new OutputWriter(grid_init_->grid(),
|
|
|
|
param_,
|
2016-10-20 13:16:42 -05:00
|
|
|
*eclipse_state_,
|
2016-11-11 09:34:19 -06:00
|
|
|
std::move(eclipse_writer_),
|
2017-01-26 10:29:22 -06:00
|
|
|
Opm::phaseUsageFromDeck(*deck_)));
|
2015-12-11 10:01:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Setup linear solver.
|
|
|
|
// Writes to:
|
|
|
|
// fis_solver_
|
|
|
|
void setupLinearSolver()
|
|
|
|
{
|
|
|
|
const std::string cprSolver = "cpr";
|
|
|
|
const std::string interleavedSolver = "interleaved";
|
|
|
|
const std::string directSolver = "direct";
|
2016-02-11 08:37:30 -06:00
|
|
|
std::string flowDefaultSolver = interleavedSolver;
|
2015-12-11 10:01:08 -06:00
|
|
|
|
2016-02-11 08:37:30 -06:00
|
|
|
if (!param_.has("solver_approach")) {
|
2016-08-08 03:07:09 -05:00
|
|
|
if (eclipse_state_->getSimulationConfig().useCPR()) {
|
2016-02-11 08:37:30 -06:00
|
|
|
flowDefaultSolver = cprSolver;
|
2015-12-11 10:01:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-17 04:48:04 -05:00
|
|
|
const std::string solver_approach = param_.getDefault("solver_approach", flowDefaultSolver);
|
2016-02-11 08:37:30 -06:00
|
|
|
|
2015-12-11 10:01:08 -06:00
|
|
|
if (solver_approach == cprSolver) {
|
|
|
|
fis_solver_.reset(new NewtonIterationBlackoilCPR(param_, parallel_information_));
|
|
|
|
} else if (solver_approach == interleavedSolver) {
|
|
|
|
fis_solver_.reset(new NewtonIterationBlackoilInterleaved(param_, parallel_information_));
|
|
|
|
} else if (solver_approach == directSolver) {
|
|
|
|
fis_solver_.reset(new NewtonIterationBlackoilSimple(param_, parallel_information_));
|
|
|
|
} else {
|
|
|
|
OPM_THROW( std::runtime_error , "Internal error - solver approach " << solver_approach << " not recognized.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Run the simulator.
|
|
|
|
// Returns EXIT_SUCCESS if it does not throw.
|
|
|
|
int runSimulator()
|
|
|
|
{
|
2016-10-14 02:23:26 -05:00
|
|
|
const auto& schedule = eclipse_state_->getSchedule();
|
|
|
|
const auto& timeMap = schedule.getTimeMap();
|
|
|
|
auto& ioConfig = eclipse_state_->getIOConfig();
|
2015-12-11 10:01:08 -06:00
|
|
|
SimulatorTimer simtimer;
|
|
|
|
|
|
|
|
// initialize variables
|
2016-08-08 03:07:09 -05:00
|
|
|
const auto& initConfig = eclipse_state_->getInitConfig();
|
|
|
|
simtimer.init(timeMap, (size_t)initConfig.getRestartStep());
|
2015-12-11 10:01:08 -06:00
|
|
|
|
2016-10-14 02:23:26 -05:00
|
|
|
if (!ioConfig.initOnly()) {
|
2015-12-11 10:01:08 -06:00
|
|
|
if (output_cout_) {
|
2016-05-09 00:33:44 -05:00
|
|
|
std::string msg;
|
|
|
|
msg = "\n\n================ Starting main simulation loop ===============\n";
|
|
|
|
OpmLog::info(msg);
|
2015-12-11 10:01:08 -06:00
|
|
|
}
|
|
|
|
|
2016-02-28 04:27:00 -06:00
|
|
|
SimulatorReport fullReport = simulator_->run(simtimer, *state_);
|
2015-12-11 10:01:08 -06:00
|
|
|
|
|
|
|
if (output_cout_) {
|
2016-05-09 00:33:44 -05:00
|
|
|
std::ostringstream ss;
|
|
|
|
ss << "\n\n================ End of simulation ===============\n\n";
|
|
|
|
fullReport.reportFullyImplicit(ss);
|
|
|
|
OpmLog::info(ss.str());
|
2015-12-14 03:21:21 -06:00
|
|
|
if (param_.anyUnused()) {
|
|
|
|
// This allows a user to catch typos and misunderstandings in the
|
|
|
|
// use of simulator parameters.
|
|
|
|
std::cout << "-------------------- Unused parameters: --------------------\n";
|
|
|
|
param_.displayUsage();
|
|
|
|
std::cout << "----------------------------------------------------------------" << std::endl;
|
|
|
|
}
|
2015-12-11 10:01:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (output_to_files_) {
|
|
|
|
std::string filename = output_dir_ + "/walltime.txt";
|
|
|
|
std::fstream tot_os(filename.c_str(), std::fstream::trunc | std::fstream::out);
|
|
|
|
fullReport.reportParam(tot_os);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (output_cout_) {
|
|
|
|
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
|
|
|
}
|
2016-05-03 03:12:29 -05:00
|
|
|
|
2015-12-11 10:01:08 -06:00
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-14 06:51:59 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Access the most-derived class used for
|
|
|
|
// static polymorphism (CRTP).
|
|
|
|
Implementation& asImpl()
|
|
|
|
{
|
|
|
|
return static_cast<Implementation&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}; // class FlowMainBase
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The FlowMain class is the basic black-oil simulator case.
|
|
|
|
template <class Grid, class Simulator>
|
|
|
|
class FlowMain : public FlowMainBase<FlowMain<Grid, Simulator>, Grid, Simulator>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
using Base = FlowMainBase<FlowMain<Grid, Simulator>, Grid, Simulator>;
|
|
|
|
friend Base;
|
|
|
|
|
|
|
|
// Create simulator instance.
|
|
|
|
// Writes to:
|
|
|
|
// simulator_
|
|
|
|
void createSimulator()
|
|
|
|
{
|
|
|
|
// Create the simulator instance.
|
|
|
|
Base::simulator_.reset(new Simulator(Base::param_,
|
|
|
|
Base::grid_init_->grid(),
|
|
|
|
*Base::geoprops_,
|
|
|
|
*Base::fluidprops_,
|
|
|
|
Base::rock_comp_->isActive() ? Base::rock_comp_.get() : nullptr,
|
|
|
|
*Base::fis_solver_,
|
|
|
|
Base::gravity_.data(),
|
|
|
|
Base::deck_->hasKeyword("DISGAS"),
|
|
|
|
Base::deck_->hasKeyword("VAPOIL"),
|
|
|
|
Base::eclipse_state_,
|
|
|
|
*Base::output_writer_,
|
2016-09-12 05:31:59 -05:00
|
|
|
Base::threshold_pressures_,
|
|
|
|
Base::defunct_well_names_));
|
2015-12-14 06:51:59 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-09 02:56:09 -06:00
|
|
|
|
2015-12-08 03:36:44 -06:00
|
|
|
|
2016-04-29 07:59:18 -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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int64_t convertMessageType(const Message::type& mtype)
|
|
|
|
{
|
|
|
|
switch (mtype) {
|
|
|
|
case Message::type::Debug:
|
|
|
|
return Log::MessageType::Debug;
|
|
|
|
case Message::type::Info:
|
|
|
|
return Log::MessageType::Info;
|
|
|
|
case Message::type::Warning:
|
|
|
|
return Log::MessageType::Warning;
|
|
|
|
case Message::type::Error:
|
|
|
|
return Log::MessageType::Error;
|
|
|
|
case Message::type::Problem:
|
|
|
|
return Log::MessageType::Problem;
|
|
|
|
case Message::type::Bug:
|
|
|
|
return Log::MessageType::Bug;
|
2016-06-08 02:18:10 -05:00
|
|
|
case Message::type::Note:
|
|
|
|
return Log::MessageType::Note;
|
2016-04-29 07:59:18 -05:00
|
|
|
}
|
|
|
|
throw std::logic_error("Invalid messages type!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-08 03:36:44 -06:00
|
|
|
} // namespace Opm
|
|
|
|
|
|
|
|
#endif // OPM_FLOWMAIN_HEADER_INCLUDED
|