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>
|
|
|
|
|
2017-05-19 06:34:51 -05:00
|
|
|
|
2016-12-05 11:27:31 -06:00
|
|
|
#include <opm/simulators/ParallelFileMerger.hpp>
|
2017-04-06 05:14:54 -05:00
|
|
|
#include <opm/simulators/ensureDirectoryExists.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/NewtonIterationBlackoilSimple.hpp>
|
|
|
|
#include <opm/autodiff/NewtonIterationBlackoilCPR.hpp>
|
|
|
|
#include <opm/autodiff/NewtonIterationBlackoilInterleaved.hpp>
|
|
|
|
#include <opm/autodiff/MissingFeatures.hpp>
|
|
|
|
#include <opm/autodiff/moduleVersion.hpp>
|
2016-12-06 13:05:24 -06:00
|
|
|
#include <opm/autodiff/ExtractParallelGridInformationToISTL.hpp>
|
2017-01-25 13:36:37 -06:00
|
|
|
#include <opm/autodiff/RedistributeDataHandles.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>
|
|
|
|
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
|
|
|
#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
|
|
|
|
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
|
|
|
{
|
2017-06-20 04:57:47 -05:00
|
|
|
enum FileOutputValue{
|
|
|
|
//! \brief No output to files.
|
|
|
|
OUTPUT_NONE = 0,
|
2017-06-20 06:36:22 -05:00
|
|
|
//! \brief Output only to log files, no eclipse output.
|
2017-06-20 04:57:47 -05:00
|
|
|
OUTPUT_LOG_ONLY = 1,
|
|
|
|
//! \brief Output to all files.
|
|
|
|
OUTPUT_ALL = 3
|
|
|
|
};
|
|
|
|
|
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-12-05 11:27:31 -06:00
|
|
|
typedef typename Simulator::ReservoirState ReservoirState;
|
|
|
|
typedef typename Simulator::OutputWriter OutputWriter;
|
2016-07-12 12:01:14 -05:00
|
|
|
|
2016-12-05 11:27:31 -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.
|
2017-10-10 07:07:07 -05:00
|
|
|
int execute(int argc, char** argv)
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
|
|
|
try {
|
2017-10-10 07:07:07 -05:00
|
|
|
setupParallelism();
|
2016-12-05 11:27:31 -06:00
|
|
|
printStartupMessage();
|
|
|
|
const bool ok = setupParameters(argc, argv);
|
|
|
|
if (!ok) {
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-10-10 07:07:07 -05:00
|
|
|
setupEbosSimulator();
|
2017-03-16 10:05:33 -05:00
|
|
|
setupOutput();
|
2016-12-05 11:27:31 -06:00
|
|
|
setupLogging();
|
2017-05-09 06:58:21 -05:00
|
|
|
printPRTHeader();
|
2016-12-05 11:27:31 -06:00
|
|
|
extractMessages();
|
|
|
|
runDiagnostics();
|
|
|
|
setupState();
|
|
|
|
writeInit();
|
|
|
|
setupOutputWriter();
|
|
|
|
setupLinearSolver();
|
|
|
|
createSimulator();
|
|
|
|
|
|
|
|
// Run.
|
|
|
|
auto ret = runSimulator();
|
|
|
|
|
|
|
|
mergeParallelLogFiles();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
catch (const std::exception &e) {
|
|
|
|
std::ostringstream message;
|
|
|
|
message << "Program threw an exception: " << e.what();
|
|
|
|
|
|
|
|
if( output_cout_ )
|
|
|
|
{
|
|
|
|
// 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:
|
2017-10-10 07:07:07 -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
|
|
|
|
// involved in the simulation. MPI must have already been initialized here.
|
|
|
|
#if HAVE_MPI
|
|
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank_);
|
|
|
|
int mpi_size;
|
|
|
|
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
|
|
|
|
#else
|
|
|
|
mpi_rank_ = 0;
|
|
|
|
const int mpi_size = 1;
|
|
|
|
#endif
|
2016-12-05 11:27:31 -06:00
|
|
|
output_cout_ = ( mpi_rank_ == 0 );
|
|
|
|
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) {
|
|
|
|
// 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 {
|
|
|
|
std::cout << "OpenMP using " << num_omp_threads << " threads on MPI rank " << mpi_rank_ << "." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2016-08-08 08:26:09 -05:00
|
|
|
|
2016-11-14 07:05:24 -06:00
|
|
|
// Print startup message if on output rank.
|
|
|
|
void printStartupMessage()
|
2017-08-23 08:58:55 -05:00
|
|
|
{
|
|
|
|
|
2016-11-14 07:05:24 -06:00
|
|
|
if (output_cout_) {
|
|
|
|
const int lineLen = 70;
|
|
|
|
const std::string version = moduleVersionName();
|
2017-10-11 10:20:17 -05:00
|
|
|
const std::string banner = "This is flow "+version;
|
2016-11-14 07:05:24 -06:00
|
|
|
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";
|
2017-10-11 10:20:17 -05:00
|
|
|
std::cout << "* including solvent and polymer capabilities. *\n";
|
|
|
|
std::cout << "* For more information, see http://opm-project.org *\n";
|
2016-11-14 07:05:24 -06:00
|
|
|
std::cout << "* *\n";
|
|
|
|
std::cout << "**********************************************************************\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:27:31 -06:00
|
|
|
// Read parameters, see if a deck was specified on the command line, and if
|
|
|
|
// it was, insert it into parameters.
|
2016-08-08 08:26:09 -05:00
|
|
|
// Writes to:
|
2016-12-05 11:27:31 -06:00
|
|
|
// param_
|
|
|
|
// Returns true if ok, false if not.
|
|
|
|
bool setupParameters(int argc, char** argv)
|
|
|
|
{
|
2017-04-28 08:36:25 -05:00
|
|
|
param_ = ParameterGroup(argc, argv, false, output_cout_);
|
2016-12-05 11:27:31 -06:00
|
|
|
|
|
|
|
// 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 {
|
|
|
|
const auto casename = this->simulationCaseName( param_.unhandledArguments()[ 0 ] );
|
|
|
|
param_.insertParameter("deck_filename", casename.string() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
{
|
2017-06-20 08:27:05 -05:00
|
|
|
const std::string output = param_.getDefault("output", std::string("all"));
|
2017-06-20 04:57:47 -05:00
|
|
|
static std::map<std::string, FileOutputValue> string2OutputEnum =
|
|
|
|
{ {"none", OUTPUT_NONE },
|
|
|
|
{"false", OUTPUT_LOG_ONLY },
|
|
|
|
{"log", OUTPUT_LOG_ONLY },
|
|
|
|
{"all" , OUTPUT_ALL },
|
|
|
|
{"true" , OUTPUT_ALL }};
|
|
|
|
auto converted = string2OutputEnum.find(output);
|
|
|
|
if ( converted != string2OutputEnum.end() )
|
|
|
|
{
|
|
|
|
output_ = string2OutputEnum[output];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-20 08:27:05 -05:00
|
|
|
std::cerr << "Value " << output <<
|
|
|
|
" passed to option output was invalid. Using \"all\" instead."
|
|
|
|
<< std::endl;
|
2017-06-20 04:57:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
output_to_files_ = output_cout_ && output_ > OUTPUT_NONE;
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2017-03-16 10:05:33 -05:00
|
|
|
// Setup output directory.
|
|
|
|
auto& ioConfig = eclState().getIOConfig();
|
|
|
|
// Default output directory is the directory where the deck is found.
|
|
|
|
const std::string default_output_dir = ioConfig.getOutputDir();
|
|
|
|
output_dir_ = param_.getDefault("output_dir", default_output_dir);
|
|
|
|
// Override output directory if user specified.
|
|
|
|
ioConfig.setOutputDir(output_dir_);
|
|
|
|
|
|
|
|
// Write parameters used for later reference. (only if rank is zero)
|
2016-12-05 11:27:31 -06:00
|
|
|
if (output_to_files_) {
|
|
|
|
// Create output directory if needed.
|
2017-04-06 05:14:54 -05:00
|
|
|
ensureDirectoryExists(output_dir_);
|
2016-12-05 11:27:31 -06:00
|
|
|
// Write simulation parameters.
|
|
|
|
param_.writeParam(output_dir_ + "/simulation.param");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 13:05:24 -06:00
|
|
|
// Setup OpmLog backend with output_dir.
|
2016-12-05 11:27:31 -06:00
|
|
|
void setupLogging()
|
|
|
|
{
|
|
|
|
std::string deck_filename = param_.get<std::string>("deck_filename");
|
|
|
|
// create logFile
|
2016-12-06 13:05:24 -06:00
|
|
|
using boost::filesystem::path;
|
2016-12-05 11:27:31 -06:00
|
|
|
path fpath(deck_filename);
|
|
|
|
std::string baseName;
|
|
|
|
std::ostringstream debugFileStream;
|
|
|
|
std::ostringstream logFileStream;
|
|
|
|
|
|
|
|
if (boost::to_upper_copy(path(fpath.extension()).string()) == ".DATA") {
|
|
|
|
baseName = path(fpath.stem()).string();
|
|
|
|
} else {
|
|
|
|
baseName = path(fpath.filename()).string();
|
|
|
|
}
|
|
|
|
|
2017-03-16 10:05:33 -05:00
|
|
|
logFileStream << output_dir_ << "/" << baseName;
|
|
|
|
debugFileStream << output_dir_ << "/" << "." << baseName;
|
2016-12-05 11:27:31 -06:00
|
|
|
|
|
|
|
if ( must_distribute_ && mpi_rank_ != 0 )
|
|
|
|
{
|
|
|
|
// 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_;
|
|
|
|
}
|
|
|
|
logFileStream << ".PRT";
|
|
|
|
debugFileStream << ".DEBUG";
|
|
|
|
|
|
|
|
logFile_ = logFileStream.str();
|
|
|
|
|
2017-06-20 04:57:47 -05:00
|
|
|
if( output_ > OUTPUT_NONE)
|
2017-06-20 01:30:22 -05:00
|
|
|
{
|
|
|
|
std::shared_ptr<EclipsePRTLog> prtLog = std::make_shared<EclipsePRTLog>(logFile_ , Log::NoDebugMessageTypes, false, output_cout_);
|
|
|
|
OpmLog::addBackend( "ECLIPSEPRTLOG" , prtLog );
|
|
|
|
prtLog->setMessageLimiter(std::make_shared<MessageLimiter>());
|
|
|
|
prtLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(false));
|
|
|
|
}
|
|
|
|
|
2017-06-20 06:36:22 -05:00
|
|
|
if( output_ >= OUTPUT_LOG_ONLY && !param_.getDefault("no_debug_log", false) )
|
2017-06-20 01:30:22 -05:00
|
|
|
{
|
|
|
|
std::string debugFile = debugFileStream.str();
|
|
|
|
std::shared_ptr<StreamLog> debugLog = std::make_shared<EclipsePRTLog>(debugFile, Log::DefaultMessageTypes, false, output_cout_);
|
|
|
|
OpmLog::addBackend( "DEBUGLOG" , debugLog);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
const auto& msgLimits = eclState().getSchedule().getMessageLimits();
|
|
|
|
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));
|
|
|
|
|
|
|
|
if ( output_cout_ )
|
2017-08-23 08:58:55 -05:00
|
|
|
{
|
2017-05-09 06:58:21 -05:00
|
|
|
// Read Parameters.
|
2017-05-17 10:46:10 -05:00
|
|
|
OpmLog::debug("\n--------------- Reading parameters ---------------\n");
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
}
|
2017-08-23 08:58:55 -05:00
|
|
|
|
2017-05-09 06:58:21 -05:00
|
|
|
void printPRTHeader()
|
|
|
|
{
|
2017-08-23 08:58:55 -05:00
|
|
|
// Print header for PRT file.
|
2017-05-17 10:46:10 -05:00
|
|
|
if ( output_cout_ ) {
|
|
|
|
const std::string version = moduleVersionName();
|
|
|
|
const double megabyte = 1024 * 1024;
|
2017-08-23 08:58:55 -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);
|
2017-08-23 08:58:55 -05:00
|
|
|
const double mem_size = getTotalSystemMemory() / megabyte;
|
2017-05-17 10:46:10 -05:00
|
|
|
std::ostringstream ss;
|
2017-08-23 08:58:55 -05:00
|
|
|
ss << "\n\n\n ######## # ###### # #\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,";
|
|
|
|
ss << " and is part of OPM.\nFor more information visit: http://opm-project.org \n\n";
|
|
|
|
ss << "Flow Version = " + version + "\n";
|
|
|
|
if (uname(&arch) == 0) {
|
|
|
|
ss << "System = " << arch.nodename << " (Number of cores: " << num_cpu;
|
|
|
|
ss << ", RAM: " << std::fixed << std::setprecision (2) << mem_size << " MB) \n";
|
|
|
|
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";
|
2017-05-17 10:46:10 -05:00
|
|
|
OpmLog::note(ss.str());
|
2017-05-09 06:58:21 -05:00
|
|
|
}
|
|
|
|
}
|
2017-08-23 08:58:55 -05:00
|
|
|
|
2016-12-05 11:27:31 -06:00
|
|
|
void mergeParallelLogFiles()
|
|
|
|
{
|
|
|
|
// force closing of all log files.
|
|
|
|
OpmLog::removeAllBackends();
|
|
|
|
|
2017-01-09 05:07:27 -06:00
|
|
|
if( mpi_rank_ != 0 || !must_distribute_ || !output_to_files_ )
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
fs::path output_path(".");
|
|
|
|
if ( param_.has("output_dir") )
|
|
|
|
{
|
|
|
|
output_path = fs::path(output_dir_);
|
|
|
|
}
|
|
|
|
|
|
|
|
fs::path deck_filename(param_.get<std::string>("deck_filename"));
|
|
|
|
|
|
|
|
std::for_each(fs::directory_iterator(output_path),
|
|
|
|
fs::directory_iterator(),
|
|
|
|
detail::ParallelFileMerger(output_path, deck_filename.stem().string()));
|
|
|
|
}
|
|
|
|
|
2017-10-10 07:07:07 -05:00
|
|
|
void setupEbosSimulator()
|
2016-08-08 08:26:09 -05:00
|
|
|
{
|
|
|
|
std::string progName("flow_ebos");
|
|
|
|
std::string deckFile("--ecl-deck-file-name=");
|
|
|
|
deckFile += param_.get<std::string>("deck_filename");
|
|
|
|
char* ptr[2];
|
|
|
|
ptr[ 0 ] = const_cast< char * > (progName.c_str());
|
|
|
|
ptr[ 1 ] = const_cast< char * > (deckFile.c_str());
|
|
|
|
EbosSimulator::registerParameters();
|
|
|
|
Ewoms::setupParameters_< TypeTag > ( 2, ptr );
|
2017-10-05 09:55:30 -05:00
|
|
|
ebosSimulator_.reset(new EbosSimulator(/*verbose=*/false));
|
2016-08-08 08:26:09 -05:00
|
|
|
ebosSimulator_->model().applyInitialSolution();
|
|
|
|
|
2017-01-25 14:37:29 -06:00
|
|
|
// Create a grid with a global view.
|
|
|
|
globalGrid_.reset(new Grid(grid()));
|
|
|
|
globalGrid_->switchToGlobalView();
|
|
|
|
|
2016-12-05 11:27:31 -06:00
|
|
|
try {
|
|
|
|
if (output_cout_) {
|
|
|
|
MissingFeatures::checkKeywords(deck());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Possible to force initialization only behavior (NOSIM).
|
|
|
|
if (param_.has("nosim")) {
|
|
|
|
const bool nosim = param_.get<bool>("nosim");
|
2017-03-16 10:05:33 -05:00
|
|
|
auto& ioConfig = eclState().getIOConfig();
|
2016-12-05 11:27:31 -06:00
|
|
|
ioConfig.overrideNOSIM( nosim );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2016-08-08 08:26:09 -05:00
|
|
|
|
|
|
|
// Possibly override IOConfig setting (from deck) for how often RESTART files should get written to disk (every N report step)
|
2016-12-05 11:27:31 -06:00
|
|
|
if (param_.has("output_interval")) {
|
|
|
|
const int output_interval = param_.get<int>("output_interval");
|
|
|
|
eclState().getRestartConfig().overrideRestartWriteInterval( size_t( output_interval ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Deck& deck() const
|
|
|
|
{ return ebosSimulator_->gridManager().deck(); }
|
|
|
|
|
|
|
|
Deck& deck()
|
|
|
|
{ return ebosSimulator_->gridManager().deck(); }
|
|
|
|
|
|
|
|
const EclipseState& eclState() const
|
|
|
|
{ return ebosSimulator_->gridManager().eclState(); }
|
|
|
|
|
|
|
|
EclipseState& eclState()
|
|
|
|
{ return ebosSimulator_->gridManager().eclState(); }
|
|
|
|
|
|
|
|
// Initialise the reservoir state. Updated fluid props for SWATINIT.
|
|
|
|
// Writes to:
|
|
|
|
// state_
|
|
|
|
// threshold_pressures_
|
|
|
|
void setupState()
|
|
|
|
{
|
|
|
|
const PhaseUsage pu = Opm::phaseUsageFromDeck(deck());
|
|
|
|
const Grid& grid = this->grid();
|
|
|
|
|
|
|
|
// Need old-style fluid object for init purposes (only).
|
|
|
|
BlackoilPropertiesFromDeck props(deck(),
|
|
|
|
eclState(),
|
2017-01-11 10:16:46 -06:00
|
|
|
materialLawManager(),
|
2016-12-05 11:27:31 -06:00
|
|
|
grid.size(/*codim=*/0),
|
|
|
|
grid.globalCell().data(),
|
|
|
|
grid.logicalCartesianSize().data(),
|
|
|
|
param_);
|
|
|
|
|
|
|
|
|
|
|
|
// Init state variables (saturation and pressure).
|
|
|
|
if (param_.has("init_saturation")) {
|
|
|
|
state_.reset(new ReservoirState(grid.size(/*codim=*/0),
|
|
|
|
grid.numFaces(),
|
|
|
|
props.numPhases()));
|
|
|
|
|
|
|
|
initStateBasic(grid.size(/*codim=*/0),
|
|
|
|
grid.globalCell().data(),
|
|
|
|
grid.logicalCartesianSize().data(),
|
|
|
|
grid.numFaces(),
|
|
|
|
Opm::UgGridHelpers::faceCells(grid),
|
|
|
|
Opm::UgGridHelpers::beginFaceCentroids(grid),
|
|
|
|
Opm::UgGridHelpers::beginCellCentroids(grid),
|
|
|
|
Grid::dimension,
|
2017-01-11 10:19:52 -06:00
|
|
|
props, param_, gravity(), *state_);
|
2016-12-05 11:27:31 -06:00
|
|
|
|
|
|
|
initBlackoilSurfvol(Opm::UgGridHelpers::numCells(grid), props, *state_);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
for (int c = 0; c < numCells; ++c) {
|
|
|
|
// 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]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (deck().hasKeyword("EQUIL")) {
|
|
|
|
// 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()));
|
|
|
|
|
2017-01-11 10:19:52 -06:00
|
|
|
initStateEquil(grid, props, deck(), eclState(), gravity(), *state_);
|
2016-12-05 11:27:31 -06:00
|
|
|
//state_.faceflux().resize(Opm::UgGridHelpers::numFaces(grid), 0.0);
|
|
|
|
} else {
|
|
|
|
state_.reset( new ReservoirState( Opm::UgGridHelpers::numCells(grid),
|
|
|
|
Opm::UgGridHelpers::numFaces(grid),
|
|
|
|
props.numPhases()));
|
|
|
|
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),
|
2017-01-11 10:19:52 -06:00
|
|
|
props, deck(), gravity(), *state_);
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
initHydroCarbonState(*state_, pu, Opm::UgGridHelpers::numCells(grid), deck().hasKeyword("DISGAS"), deck().hasKeyword("VAPOIL"));
|
2017-06-07 02:29:31 -05:00
|
|
|
|
|
|
|
// Get initial polymer concentration from ebos
|
|
|
|
if (GET_PROP_VALUE(TypeTag, EnablePolymer)) {
|
|
|
|
auto& cpolymer = state_->getCellData( state_->POLYMER );
|
|
|
|
const int numCells = Opm::UgGridHelpers::numCells(grid);
|
|
|
|
for (int c = 0; c < numCells; ++c) {
|
|
|
|
cpolymer[c] = ebosProblem().polymerConcentration(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Get initial solvent saturation from ebos
|
|
|
|
if (GET_PROP_VALUE(TypeTag, EnableSolvent)) {
|
|
|
|
auto& solvent = state_->getCellData( state_->SSOL );
|
|
|
|
auto& sat = state_->saturation();
|
|
|
|
const int np = props.numPhases();
|
|
|
|
const int numCells = Opm::UgGridHelpers::numCells(grid);
|
|
|
|
for (int c = 0; c < numCells; ++c) {
|
|
|
|
solvent[c] = ebosProblem().solventSaturation(c);
|
|
|
|
sat[c * np + pu.phase_pos[Water]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extract messages from parser.
|
|
|
|
// Writes to:
|
|
|
|
// OpmLog singleton.
|
|
|
|
void extractMessages()
|
|
|
|
{
|
|
|
|
if ( !output_cout_ )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto extractMessage = [this](const Message& msg) {
|
|
|
|
auto log_type = this->convertMessageType(msg.mtype);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Extract messages from Deck.
|
|
|
|
for(const auto& msg : deck().getMessageContainer()) {
|
|
|
|
extractMessage(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract messages from EclipseState.
|
|
|
|
for (const auto& msg : eclState().getMessageContainer()) {
|
|
|
|
extractMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run diagnostics.
|
|
|
|
// Writes to:
|
|
|
|
// OpmLog singleton.
|
|
|
|
void runDiagnostics()
|
|
|
|
{
|
|
|
|
if( ! output_cout_ )
|
|
|
|
{
|
|
|
|
return;
|
2016-08-08 08:26:09 -05:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:27:31 -06:00
|
|
|
// Run relperm diagnostics
|
|
|
|
RelpermDiagnostics diagnostic;
|
|
|
|
diagnostic.diagnosis(eclState(), deck(), this->grid());
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeInit()
|
|
|
|
{
|
2017-06-20 06:21:26 -05:00
|
|
|
bool output = ( output_ > OUTPUT_LOG_ONLY );
|
2016-12-05 11:27:31 -06:00
|
|
|
bool output_ecl = param_.getDefault("output_ecl", true);
|
2017-05-12 08:26:57 -05:00
|
|
|
if( output && output_ecl && grid().comm().rank() == 0 )
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
2017-05-12 08:26:57 -05:00
|
|
|
exportNncStructure_();
|
2017-01-25 13:36:37 -06:00
|
|
|
|
2017-04-05 08:48:25 -05:00
|
|
|
const EclipseGrid& inputGrid = eclState().getInputGrid();
|
2017-05-12 08:26:57 -05:00
|
|
|
eclIO_.reset(new EclipseIO(eclState(), UgGridHelpers::createEclipseGrid( this->globalGrid() , inputGrid )));
|
2017-04-05 08:48:25 -05:00
|
|
|
eclIO_->writeInitial(computeLegacySimProps_(), nnc_);
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup output writer.
|
|
|
|
// Writes to:
|
|
|
|
// output_writer_
|
|
|
|
void setupOutputWriter()
|
|
|
|
{
|
2017-01-25 13:36:37 -06:00
|
|
|
// 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-12-05 11:27:31 -06:00
|
|
|
output_writer_.reset(new OutputWriter(grid(),
|
|
|
|
param_,
|
|
|
|
eclState(),
|
2017-01-25 13:36:37 -06:00
|
|
|
std::move(eclIO_),
|
2017-02-09 06:54:42 -06:00
|
|
|
Opm::phaseUsageFromDeck(deck())) );
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run the simulator.
|
|
|
|
// Returns EXIT_SUCCESS if it does not throw.
|
|
|
|
int runSimulator()
|
|
|
|
{
|
|
|
|
const auto& schedule = eclState().getSchedule();
|
|
|
|
const auto& timeMap = schedule.getTimeMap();
|
|
|
|
auto& ioConfig = eclState().getIOConfig();
|
|
|
|
SimulatorTimer simtimer;
|
|
|
|
|
|
|
|
// initialize variables
|
|
|
|
const auto& initConfig = eclState().getInitConfig();
|
|
|
|
simtimer.init(timeMap, (size_t)initConfig.getRestartStep());
|
|
|
|
|
|
|
|
if (!ioConfig.initOnly()) {
|
|
|
|
if (output_cout_) {
|
|
|
|
std::string msg;
|
|
|
|
msg = "\n\n================ Starting main simulation loop ===============\n";
|
|
|
|
OpmLog::info(msg);
|
|
|
|
}
|
|
|
|
|
2017-04-10 08:55:30 -05:00
|
|
|
SimulatorReport successReport = simulator_->run(simtimer, *state_);
|
|
|
|
SimulatorReport failureReport = simulator_->failureReport();
|
2016-12-05 11:27:31 -06:00
|
|
|
|
|
|
|
if (output_cout_) {
|
|
|
|
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());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output_to_files_) {
|
|
|
|
std::string filename = output_dir_ + "/walltime.txt";
|
|
|
|
std::fstream tot_os(filename.c_str(), std::fstream::trunc | std::fstream::out);
|
2017-04-10 08:55:30 -05:00
|
|
|
successReport.reportParam(tot_os);
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (output_cout_) {
|
|
|
|
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
|
|
|
}
|
|
|
|
|
2016-08-08 08:26:09 -05:00
|
|
|
}
|
2016-12-05 11:27:31 -06:00
|
|
|
return EXIT_SUCCESS;
|
2016-08-08 08:26:09 -05:00
|
|
|
}
|
|
|
|
|
2016-11-02 07:10:44 -05:00
|
|
|
// Setup linear solver.
|
|
|
|
// Writes to:
|
|
|
|
// fis_solver_
|
|
|
|
void setupLinearSolver()
|
|
|
|
{
|
2017-06-07 02:29:31 -05:00
|
|
|
typedef typename BlackoilModelEbos<TypeTag> :: ISTLSolverType ISTLSolverType;
|
2016-12-06 13:05:24 -06:00
|
|
|
|
|
|
|
extractParallelGridInformationToISTL(grid(), parallel_information_);
|
2016-12-05 11:27:31 -06:00
|
|
|
fis_solver_.reset( new ISTLSolverType( param_, parallel_information_ ) );
|
2016-11-02 07:10:44 -05:00
|
|
|
}
|
|
|
|
|
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_
|
|
|
|
void createSimulator()
|
|
|
|
{
|
|
|
|
// Create the simulator instance.
|
2016-12-05 11:27:31 -06:00
|
|
|
simulator_.reset(new Simulator(*ebosSimulator_,
|
|
|
|
param_,
|
|
|
|
*fis_solver_,
|
|
|
|
FluidSystem::enableDissolvedGas(),
|
|
|
|
FluidSystem::enableVaporizedOil(),
|
|
|
|
eclState(),
|
2016-12-06 12:43:47 -06:00
|
|
|
*output_writer_,
|
|
|
|
defunctWellNames()));
|
2016-07-12 12:01:14 -05:00
|
|
|
}
|
2016-08-08 08:26:09 -05:00
|
|
|
|
|
|
|
private:
|
2016-12-05 11:27:31 -06:00
|
|
|
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 );
|
|
|
|
}
|
2017-08-23 08:58:55 -05:00
|
|
|
|
2017-05-17 10:46:10 -05:00
|
|
|
unsigned long long getTotalSystemMemory()
|
|
|
|
{
|
|
|
|
long pages = sysconf(_SC_PHYS_PAGES);
|
|
|
|
long page_size = sysconf(_SC_PAGE_SIZE);
|
|
|
|
return pages * page_size;
|
|
|
|
}
|
2016-12-05 11:27:31 -06:00
|
|
|
|
|
|
|
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;
|
|
|
|
case Message::type::Note:
|
|
|
|
return Log::MessageType::Note;
|
|
|
|
}
|
|
|
|
throw std::logic_error("Invalid messages type!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
Grid& grid()
|
|
|
|
{ return ebosSimulator_->gridManager().grid(); }
|
|
|
|
|
2017-01-25 13:36:37 -06:00
|
|
|
const Grid& globalGrid()
|
2017-01-25 14:37:29 -06:00
|
|
|
{ return *globalGrid_; }
|
2017-01-25 13:36:37 -06:00
|
|
|
|
2017-01-11 10:19:52 -06:00
|
|
|
Problem& ebosProblem()
|
|
|
|
{ return ebosSimulator_->problem(); }
|
|
|
|
|
|
|
|
const Problem& ebosProblem() const
|
|
|
|
{ return ebosSimulator_->problem(); }
|
|
|
|
|
2017-01-11 10:16:46 -06:00
|
|
|
std::shared_ptr<MaterialLawManager> materialLawManager()
|
2017-01-11 10:19:52 -06:00
|
|
|
{ return ebosProblem().materialLawManager(); }
|
|
|
|
|
|
|
|
Scalar gravity() const
|
|
|
|
{ return ebosProblem().gravity()[2]; }
|
2017-01-11 10:16:46 -06:00
|
|
|
|
2016-12-06 12:43:47 -06:00
|
|
|
std::unordered_set<std::string> defunctWellNames() const
|
|
|
|
{ return ebosSimulator_->gridManager().defunctWellNames(); }
|
|
|
|
|
2017-04-05 08:48:23 -05:00
|
|
|
data::Solution computeLegacySimProps_()
|
|
|
|
{
|
|
|
|
const int* dims = UgGridHelpers::cartDims(grid());
|
|
|
|
const int globalSize = dims[0]*dims[1]*dims[2];
|
|
|
|
|
|
|
|
data::CellData tranx = {UnitSystem::measure::transmissibility, std::vector<double>( globalSize ), data::TargetType::INIT};
|
|
|
|
data::CellData trany = {UnitSystem::measure::transmissibility, std::vector<double>( globalSize ), data::TargetType::INIT};
|
|
|
|
data::CellData tranz = {UnitSystem::measure::transmissibility, std::vector<double>( globalSize ), data::TargetType::INIT};
|
|
|
|
|
2017-05-11 09:31:58 -05:00
|
|
|
for (size_t i = 0; i < tranx.data.size(); ++i) {
|
|
|
|
tranx.data[0] = 0.0;
|
|
|
|
trany.data[0] = 0.0;
|
|
|
|
tranz.data[0] = 0.0;
|
|
|
|
}
|
|
|
|
|
2017-05-12 08:26:57 -05:00
|
|
|
const Grid& globalGrid = this->globalGrid();
|
|
|
|
const auto& globalGridView = globalGrid.leafGridView();
|
2017-10-05 09:55:26 -05:00
|
|
|
typedef typename Grid::LeafGridView GridView;
|
|
|
|
typedef Dune::MultipleCodimMultipleGeomTypeMapper<GridView, Dune::MCMGElementLayout> ElementMapper;
|
2017-05-12 08:26:57 -05:00
|
|
|
ElementMapper globalElemMapper(globalGridView);
|
|
|
|
const auto& cartesianCellIdx = globalGrid.globalCell();
|
|
|
|
|
|
|
|
const auto* globalTrans = &(ebosSimulator_->gridManager().globalTransmissibility());
|
|
|
|
if (grid().comm().size() < 2) {
|
|
|
|
// in the sequential case we must use the transmissibilites defined by
|
|
|
|
// the problem. (because in the sequential case, the grid manager does
|
|
|
|
// not compute "global" transmissibilities for performance reasons. in
|
|
|
|
// the parallel case, the problem's transmissibilities can't be used
|
|
|
|
// because this object refers to the distributed grid and we need the
|
|
|
|
// sequential version here.)
|
|
|
|
globalTrans = &ebosSimulator_->problem().eclTransmissibilities();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto elemIt = globalGridView.template begin</*codim=*/0>();
|
|
|
|
const auto& elemEndIt = globalGridView.template end</*codim=*/0>();
|
|
|
|
for (; elemIt != elemEndIt; ++ elemIt) {
|
|
|
|
const auto& elem = *elemIt;
|
2017-04-05 08:48:23 -05:00
|
|
|
|
2017-05-12 08:26:57 -05:00
|
|
|
auto isIt = globalGridView.ibegin(elem);
|
|
|
|
const auto& isEndIt = globalGridView.iend(elem);
|
|
|
|
for (; isIt != isEndIt; ++ isIt) {
|
|
|
|
const auto& is = *isIt;
|
2017-04-05 08:48:23 -05:00
|
|
|
|
2017-05-12 08:26:57 -05:00
|
|
|
if (!is.neighbor())
|
|
|
|
{
|
|
|
|
continue; // intersection is on the domain boundary
|
|
|
|
}
|
2017-04-05 08:48:23 -05:00
|
|
|
|
2017-05-12 08:26:57 -05:00
|
|
|
unsigned c1 = globalElemMapper.index(is.inside());
|
|
|
|
unsigned c2 = globalElemMapper.index(is.outside());
|
2017-04-05 08:48:23 -05:00
|
|
|
|
2017-05-12 08:26:57 -05:00
|
|
|
if (c1 > c2)
|
|
|
|
{
|
|
|
|
continue; // we only need to handle each connection once, thank you.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int gc1 = std::min(cartesianCellIdx[c1], cartesianCellIdx[c2]);
|
|
|
|
int gc2 = std::max(cartesianCellIdx[c1], cartesianCellIdx[c2]);
|
|
|
|
if (gc2 - gc1 == 1) {
|
|
|
|
tranx.data[gc1] = globalTrans->transmissibility(c1, c2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gc2 - gc1 == dims[0]) {
|
|
|
|
trany.data[gc1] = globalTrans->transmissibility(c1, c2);
|
|
|
|
}
|
2017-04-05 08:48:23 -05:00
|
|
|
|
2017-05-12 08:26:57 -05:00
|
|
|
if (gc2 - gc1 == dims[0]*dims[1]) {
|
|
|
|
tranz.data[gc1] = globalTrans->transmissibility(c1, c2);
|
|
|
|
}
|
2017-04-05 08:48:23 -05:00
|
|
|
}
|
|
|
|
}
|
2017-05-12 08:26:57 -05:00
|
|
|
|
|
|
|
return {{"TRANX" , tranx},
|
|
|
|
{"TRANY" , trany} ,
|
|
|
|
{"TRANZ" , tranz}};
|
2017-04-05 08:48:23 -05:00
|
|
|
}
|
|
|
|
|
2017-04-05 08:48:25 -05:00
|
|
|
void exportNncStructure_()
|
|
|
|
{
|
|
|
|
nnc_ = eclState().getInputNNC();
|
|
|
|
int nx = eclState().getInputGrid().getNX();
|
|
|
|
int ny = eclState().getInputGrid().getNY();
|
|
|
|
//int nz = eclState().getInputGrid().getNZ()
|
|
|
|
|
2017-05-12 08:26:57 -05:00
|
|
|
const Grid& globalGrid = this->globalGrid();
|
|
|
|
const auto& globalGridView = globalGrid.leafGridView();
|
2017-10-05 09:55:26 -05:00
|
|
|
typedef typename Grid::LeafGridView GridView;
|
|
|
|
typedef Dune::MultipleCodimMultipleGeomTypeMapper<GridView, Dune::MCMGElementLayout> ElementMapper;
|
2017-05-12 08:26:57 -05:00
|
|
|
ElementMapper globalElemMapper(globalGridView);
|
2017-04-05 08:48:25 -05:00
|
|
|
|
2017-05-12 08:26:57 -05:00
|
|
|
const auto* globalTrans = &(ebosSimulator_->gridManager().globalTransmissibility());
|
|
|
|
if (grid().comm().size() < 2) {
|
2017-04-05 08:48:25 -05:00
|
|
|
// in the sequential case we must use the transmissibilites defined by
|
|
|
|
// the problem. (because in the sequential case, the grid manager does
|
|
|
|
// not compute "global" transmissibilities for performance reasons. in
|
|
|
|
// the parallel case, the problem's transmissibilities can't be used
|
|
|
|
// because this object refers to the distributed grid and we need the
|
|
|
|
// sequential version here.)
|
2017-05-12 08:26:57 -05:00
|
|
|
globalTrans = &ebosSimulator_->problem().eclTransmissibilities();
|
2017-04-05 08:48:25 -05:00
|
|
|
}
|
|
|
|
|
2017-05-12 08:26:57 -05:00
|
|
|
auto elemIt = globalGridView.template begin</*codim=*/0>();
|
|
|
|
const auto& elemEndIt = globalGridView.template end</*codim=*/0>();
|
2017-04-05 08:48:25 -05:00
|
|
|
for (; elemIt != elemEndIt; ++ elemIt) {
|
|
|
|
const auto& elem = *elemIt;
|
|
|
|
|
2017-05-12 08:26:57 -05:00
|
|
|
auto isIt = globalGridView.ibegin(elem);
|
|
|
|
const auto& isEndIt = globalGridView.iend(elem);
|
2017-04-05 08:48:25 -05:00
|
|
|
for (; isIt != isEndIt; ++ isIt) {
|
|
|
|
const auto& is = *isIt;
|
|
|
|
|
|
|
|
if (!is.neighbor())
|
|
|
|
{
|
|
|
|
continue; // intersection is on the domain boundary
|
|
|
|
}
|
|
|
|
|
2017-05-12 08:26:57 -05:00
|
|
|
unsigned c1 = globalElemMapper.index(is.inside());
|
|
|
|
unsigned c2 = globalElemMapper.index(is.outside());
|
2017-04-05 08:48:25 -05:00
|
|
|
|
|
|
|
if (c1 > c2)
|
|
|
|
{
|
|
|
|
continue; // we only need to handle each connection once, thank you.
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO (?): use the cartesian index mapper to make this code work
|
|
|
|
// with grids other than Dune::CpGrid. The problem is that we need
|
|
|
|
// the a mapper for the sequential grid, not for the distributed one.
|
2017-05-12 08:26:57 -05:00
|
|
|
int cc1 = globalGrid.globalCell()[c1];
|
|
|
|
int cc2 = globalGrid.globalCell()[c2];
|
2017-04-05 08:48:25 -05:00
|
|
|
|
|
|
|
if (std::abs(cc1 - cc2) != 1 &&
|
|
|
|
std::abs(cc1 - cc2) != nx &&
|
|
|
|
std::abs(cc1 - cc2) != nx*ny)
|
|
|
|
{
|
2017-05-12 08:26:57 -05:00
|
|
|
nnc_.addNNC(cc1, cc2, globalTrans->transmissibility(c1, c2));
|
2017-04-05 08:48:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-08 08:26:09 -05:00
|
|
|
std::unique_ptr<EbosSimulator> ebosSimulator_;
|
2016-12-05 11:27:31 -06:00
|
|
|
int mpi_rank_ = 0;
|
|
|
|
bool output_cout_ = false;
|
2017-06-20 04:57:47 -05:00
|
|
|
FileOutputValue output_ = OUTPUT_ALL;
|
2016-12-05 11:27:31 -06:00
|
|
|
bool must_distribute_ = false;
|
2017-04-28 08:36:25 -05:00
|
|
|
ParameterGroup param_;
|
2016-12-05 11:27:31 -06:00
|
|
|
bool output_to_files_ = false;
|
|
|
|
std::string output_dir_ = std::string(".");
|
|
|
|
std::unique_ptr<ReservoirState> state_;
|
2017-04-05 08:48:25 -05:00
|
|
|
NNC nnc_;
|
2017-01-06 08:13:53 -06:00
|
|
|
std::unique_ptr<EclipseIO> eclIO_;
|
2016-12-05 11:27:31 -06:00
|
|
|
std::unique_ptr<OutputWriter> output_writer_;
|
|
|
|
boost::any parallel_information_;
|
|
|
|
std::unique_ptr<NewtonIterationBlackoilInterface> fis_solver_;
|
|
|
|
std::unique_ptr<Simulator> simulator_;
|
|
|
|
std::string logFile_;
|
2017-01-25 14:37:29 -06:00
|
|
|
// Needs to be shared pointer because it gets initialzed before MPI_Init.
|
|
|
|
std::shared_ptr<Grid> globalGrid_;
|
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
|