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
|
|
|
|
|
2022-12-13 07:05:17 -06:00
|
|
|
#include <opm/simulators/flow/ConvergenceOutputConfiguration.hpp>
|
2023-02-01 01:40:41 -06:00
|
|
|
#include <opm/simulators/flow/Banners.hpp>
|
2019-06-20 02:09:19 -05:00
|
|
|
#include <opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp>
|
2019-05-07 06:06:02 -05:00
|
|
|
#include <opm/simulators/utils/ParallelFileMerger.hpp>
|
|
|
|
#include <opm/simulators/utils/moduleVersion.hpp>
|
2020-11-10 01:54:44 -06:00
|
|
|
#include <opm/simulators/utils/ParallelEclipseState.hpp>
|
2022-10-04 04:44:35 -05:00
|
|
|
#include <flow/flow_ebos_blackoil.hpp>
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2021-12-14 01:30:15 -06:00
|
|
|
#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
|
|
|
|
#include <opm/input/eclipse/EclipseState/IOConfig/IOConfig.hpp>
|
|
|
|
#include <opm/input/eclipse/EclipseState/InitConfig/InitConfig.hpp>
|
2020-04-04 09:28:16 -05:00
|
|
|
#include <opm/common/utility/String.hpp>
|
2016-07-12 12:01:14 -05:00
|
|
|
|
2021-11-01 06:31:40 -05:00
|
|
|
#include <filesystem>
|
2020-10-02 07:06:25 -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
|
|
|
|
2020-08-21 06:42:08 -05:00
|
|
|
namespace Opm::Properties {
|
2018-06-21 05:14:17 -05:00
|
|
|
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag, class MyTypeTag>
|
|
|
|
struct EnableDryRun {
|
|
|
|
using type = UndefinedProperty;
|
|
|
|
};
|
|
|
|
template<class TypeTag, class MyTypeTag>
|
|
|
|
struct OutputInterval {
|
|
|
|
using type = UndefinedProperty;
|
|
|
|
};
|
|
|
|
template<class TypeTag, class MyTypeTag>
|
|
|
|
struct EnableLoggingFalloutWarning {
|
|
|
|
using type = UndefinedProperty;
|
|
|
|
};
|
2018-06-21 05:14:17 -05:00
|
|
|
|
|
|
|
// TODO: enumeration parameters. we use strings for now.
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag>
|
|
|
|
struct EnableDryRun<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr auto value = "auto";
|
|
|
|
};
|
2019-01-14 06:06:21 -06:00
|
|
|
// Do not merge parallel output files or warn about them
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag>
|
|
|
|
struct EnableLoggingFalloutWarning<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag>
|
|
|
|
struct OutputInterval<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr int value = 1;
|
|
|
|
};
|
2018-06-21 05:14:17 -05:00
|
|
|
|
2020-08-21 06:42:08 -05:00
|
|
|
} // namespace Opm::Properties
|
2018-06-21 05:14:17 -05:00
|
|
|
|
2016-07-12 12:01:14 -05:00
|
|
|
namespace Opm
|
|
|
|
{
|
2021-04-29 03:14:58 -05:00
|
|
|
|
|
|
|
class Deck;
|
|
|
|
|
2016-07-12 12:01:14 -05:00
|
|
|
// 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
|
|
|
{
|
2016-12-05 11:27:31 -06:00
|
|
|
public:
|
2020-08-27 03:30:29 -05:00
|
|
|
using MaterialLawManager = typename GetProp<TypeTag, Properties::MaterialLaw>::EclMaterialLawManager;
|
2020-08-26 03:49:52 -05:00
|
|
|
using EbosSimulator = GetPropType<TypeTag, Properties::Simulator>;
|
|
|
|
using Grid = GetPropType<TypeTag, Properties::Grid>;
|
|
|
|
using GridView = GetPropType<TypeTag, Properties::GridView>;
|
|
|
|
using Problem = GetPropType<TypeTag, Properties::Problem>;
|
|
|
|
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
|
|
|
|
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2021-05-05 04:22:44 -05:00
|
|
|
typedef SimulatorFullyImplicitBlackoilEbos<TypeTag> Simulator;
|
2016-07-12 12:01:14 -05:00
|
|
|
|
2020-06-25 13:04:19 -05:00
|
|
|
FlowMainEbos(int argc, char **argv, bool output_cout, bool output_files )
|
|
|
|
: argc_{argc}, argv_{argv},
|
|
|
|
output_cout_{output_cout}, output_files_{output_files}
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-21 05:14:17 -05:00
|
|
|
// Read the command line parameters. Throws an exception if something goes wrong.
|
2021-05-25 05:57:11 -05:00
|
|
|
static int setupParameters_(int argc, char** argv, Parallel::Communication comm)
|
2018-06-21 05:14:17 -05:00
|
|
|
{
|
2020-08-27 03:30:29 -05:00
|
|
|
using ParamsMeta = GetProp<TypeTag, Properties::ParameterMetaData>;
|
2020-05-05 09:19:10 -05:00
|
|
|
if (!ParamsMeta::registrationOpen()) {
|
|
|
|
// We have already successfully run setupParameters_().
|
|
|
|
// For the dynamically chosen runs (as from the main flow
|
|
|
|
// executable) we must run this function again with the
|
|
|
|
// real typetag to be used, as the first time was with the
|
|
|
|
// "FlowEarlyBird" typetag. However, for the static ones (such
|
|
|
|
// as 'flow_onephase_energy') it has already been run with the
|
|
|
|
// correct typetag.
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2018-06-21 05:14:17 -05:00
|
|
|
// register the flow specific parameters
|
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
|
2021-05-05 04:22:44 -05:00
|
|
|
registerAllParameters_<TypeTag>(/*finalizeRegistration=*/false);
|
2018-06-29 06:41:54 -05:00
|
|
|
|
|
|
|
// 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, EclEnableTuning);
|
|
|
|
|
2018-06-29 06:41:54 -05:00
|
|
|
// flow also does not use the eWoms Newton method
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, NewtonMaxError);
|
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);
|
2020-05-26 14:56:51 -05:00
|
|
|
// hide all vtk related it is not currently possible to do this dependet on if the vtk writing is used
|
2020-05-26 15:04:42 -05:00
|
|
|
//if(not(EWOMS_GET_PARAM(TypeTag,bool,EnableVtkOutput))){
|
2020-05-26 09:16:42 -05:00
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteOilFormationVolumeFactor);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteOilSaturationPressure);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteOilVaporizationFactor);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWritePorosity);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWritePotentialGradients);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWritePressures);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWritePrimaryVars);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWritePrimaryVarsMeaning);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteProcessRank);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteRelativePermeabilities);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteSaturatedGasOilVaporizationFactor);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteSaturatedOilGasDissolutionFactor);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteSaturationRatios);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteSaturations);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteTemperature);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteViscosities);
|
2022-10-14 03:46:45 -05:00
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteWaterFormationVolumeFactor);
|
2020-05-26 14:56:51 -05:00
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteGasDissolutionFactor);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteGasFormationVolumeFactor);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteGasSaturationPressure);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteIntrinsicPermeabilities);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteEclTracerConcentration);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteExtrusionFactor);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteFilterVelocities);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteDensities);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteDofIndex);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteMobilities);
|
|
|
|
//}
|
2022-10-14 03:46:45 -05:00
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteAverageMolarMasses);
|
2020-05-26 14:56:51 -05:00
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteFugacities);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteFugacityCoeffs);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteMassFractions);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteMolarities);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteMoleFractions);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteTotalMassFractions);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteTotalMoleFractions);
|
2022-10-14 03:46:45 -05:00
|
|
|
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteTortuosities);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteDiffusionCoefficients);
|
|
|
|
EWOMS_HIDE_PARAM(TypeTag, VtkWriteEffectiveDiffusionCoefficients);
|
|
|
|
|
2018-06-29 06:41:54 -05:00
|
|
|
EWOMS_END_PARAM_REGISTRATION(TypeTag);
|
2018-06-21 05:14:17 -05:00
|
|
|
|
2021-05-25 05:57:11 -05:00
|
|
|
int mpiRank = comm.rank();
|
2019-09-19 07:20:05 -05:00
|
|
|
|
2019-10-29 11:00:24 -05:00
|
|
|
// read in the command line parameters
|
2021-05-05 04:22:44 -05:00
|
|
|
int status = ::Opm::setupParameters_<TypeTag>(argc, const_cast<const char**>(argv), /*doRegistration=*/false, /*allowUnused=*/true, /*handleHelp=*/(mpiRank==0));
|
2019-10-29 11:00:24 -05:00
|
|
|
if (status == 0) {
|
|
|
|
|
2019-09-19 07:20:05 -05:00
|
|
|
// deal with unknown parameters.
|
|
|
|
|
|
|
|
int unknownKeyWords = 0;
|
|
|
|
if (mpiRank == 0) {
|
2021-05-05 04:22:44 -05:00
|
|
|
unknownKeyWords = Parameters::printUnused<TypeTag>(std::cerr);
|
2019-09-19 07:20:05 -05:00
|
|
|
}
|
2021-05-25 05:57:11 -05:00
|
|
|
int globalUnknownKeyWords = comm.sum(unknownKeyWords);
|
2019-09-19 07:20:05 -05:00
|
|
|
unknownKeyWords = globalUnknownKeyWords;
|
|
|
|
if ( unknownKeyWords )
|
|
|
|
{
|
|
|
|
if ( mpiRank == 0 )
|
|
|
|
{
|
|
|
|
std::string msg = "Aborting simulation due to unknown "
|
|
|
|
"parameters. Please query \"flow --help\" for "
|
|
|
|
"supported command line parameters.";
|
|
|
|
if (OpmLog::hasBackend("STREAMLOG"))
|
|
|
|
{
|
|
|
|
OpmLog::error(msg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::cerr << msg << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// deal with --print-properties and --print-parameters and unknown parameters.
|
|
|
|
|
|
|
|
bool doExit = false;
|
|
|
|
|
2018-06-29 06:41:54 -05:00
|
|
|
if (EWOMS_GET_PARAM(TypeTag, int, PrintProperties) == 1) {
|
|
|
|
doExit = true;
|
|
|
|
if (mpiRank == 0)
|
2023-01-03 08:24:28 -06:00
|
|
|
Properties::printValues<TypeTag>(std::cout);
|
2018-06-29 06:41:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EWOMS_GET_PARAM(TypeTag, int, PrintParameters) == 1) {
|
|
|
|
doExit = true;
|
|
|
|
if (mpiRank == 0)
|
2021-05-05 04:22:44 -05:00
|
|
|
Parameters::printValues<TypeTag>();
|
2018-06-29 06:41:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (doExit)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
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.
|
2020-06-25 13:04:19 -05:00
|
|
|
int execute()
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
2020-06-25 13:04:19 -05:00
|
|
|
return execute_(&FlowMainEbos::runSimulator, /*cleanup=*/true);
|
2016-12-05 11:27:31 -06:00
|
|
|
}
|
|
|
|
|
2020-06-26 12:50:38 -05:00
|
|
|
int executeInitStep()
|
|
|
|
{
|
|
|
|
return execute_(&FlowMainEbos::runSimulatorInit, /*cleanup=*/false);
|
|
|
|
}
|
|
|
|
|
2020-08-25 06:42:29 -05:00
|
|
|
// Returns true unless "EXIT" was encountered in the schedule
|
|
|
|
// section of the input datafile.
|
|
|
|
int executeStep()
|
|
|
|
{
|
|
|
|
return simulator_->runStep(*simtimer_);
|
|
|
|
}
|
|
|
|
|
2020-10-01 16:54:48 -05:00
|
|
|
// Called from Python to cleanup after having executed the last
|
|
|
|
// executeStep()
|
|
|
|
int executeStepsCleanup()
|
|
|
|
{
|
|
|
|
SimulatorReport report = simulator_->finalize();
|
|
|
|
runSimulatorAfterSim_(report);
|
|
|
|
return report.success.exit_status;
|
|
|
|
}
|
|
|
|
|
2020-10-08 12:50:42 -05:00
|
|
|
EbosSimulator *getSimulatorPtr() {
|
|
|
|
return ebosSimulator_.get();
|
|
|
|
}
|
|
|
|
|
2022-05-02 11:43:04 -05:00
|
|
|
SimulatorTimer* getSimTimer() {
|
|
|
|
return simtimer_.get();
|
|
|
|
}
|
|
|
|
|
2020-05-13 09:59:29 -05:00
|
|
|
private:
|
|
|
|
// called by execute() or executeInitStep()
|
2020-06-25 13:04:19 -05:00
|
|
|
int execute_(int (FlowMainEbos::* runOrInitFunc)(), bool cleanup)
|
2020-05-13 09:59:29 -05:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
// deal with some administrative boilerplate
|
|
|
|
|
2021-05-25 05:57:11 -05:00
|
|
|
int status = setupParameters_(this->argc_, this->argv_, EclGenericVanguard::comm());
|
2020-05-13 09:59:29 -05:00
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
setupParallelism();
|
|
|
|
setupEbosSimulator();
|
|
|
|
createSimulator();
|
|
|
|
|
|
|
|
// if run, do the actual work, else just initialize
|
2020-06-25 13:04:19 -05:00
|
|
|
int exitCode = (this->*runOrInitFunc)();
|
2020-05-13 09:59:29 -05:00
|
|
|
if (cleanup) {
|
2020-06-25 13:04:19 -05:00
|
|
|
executeCleanup_();
|
2020-05-13 09:59:29 -05:00
|
|
|
}
|
|
|
|
return exitCode;
|
|
|
|
}
|
|
|
|
catch (const std::exception& e) {
|
|
|
|
std::ostringstream message;
|
|
|
|
message << "Program threw an exception: " << e.what();
|
|
|
|
|
2020-08-24 01:35:04 -05:00
|
|
|
if (this->output_cout_) {
|
2020-05-13 09:59:29 -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";
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 04:43:12 -05:00
|
|
|
#if HAVE_MPI
|
|
|
|
if (this->mpi_size_ > 1)
|
|
|
|
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
|
|
|
|
#endif
|
2020-05-13 09:59:29 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-25 13:04:19 -05:00
|
|
|
void executeCleanup_() {
|
2020-05-13 09:59:29 -05:00
|
|
|
// clean up
|
2020-06-25 13:04:19 -05:00
|
|
|
mergeParallelLogFiles();
|
2020-05-13 09:59:29 -05:00
|
|
|
}
|
2017-08-23 08:58:55 -05:00
|
|
|
|
2019-10-03 05:13:13 -05:00
|
|
|
protected:
|
|
|
|
void setupParallelism()
|
|
|
|
{
|
|
|
|
// determine the rank of the current process and the number of processes
|
|
|
|
// involved in the simulation. MPI must have already been initialized
|
|
|
|
// here. (yes, the name of this method is misleading.)
|
2021-05-25 05:57:11 -05:00
|
|
|
auto comm = EclGenericVanguard::comm();
|
|
|
|
mpi_rank_ = comm.rank();
|
|
|
|
mpi_size_ = comm.size();
|
2019-10-03 05:13:13 -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
|
|
|
|
|
2020-08-26 03:49:52 -05:00
|
|
|
using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
|
2019-10-03 05:13:13 -05:00
|
|
|
ThreadManager::init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-06-25 13:04:19 -05:00
|
|
|
void mergeParallelLogFiles()
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
|
|
|
// force closing of all log files.
|
|
|
|
OpmLog::removeAllBackends();
|
|
|
|
|
2020-08-24 01:35:04 -05:00
|
|
|
if (mpi_rank_ != 0 || mpi_size_ < 2 || !this->output_files_) {
|
2016-12-05 11:27:31 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-01 06:31:40 -05:00
|
|
|
namespace fs = ::std::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"
|
2020-02-19 04:01:53 -06:00
|
|
|
std::string extension = uppercase(deck_filename.extension().string());
|
2019-01-16 04:58:47 -06:00
|
|
|
if ( extension == ".DATA" || extension == "." )
|
|
|
|
{
|
2020-02-19 04:01:53 -06:00
|
|
|
basename = uppercase(deck_filename.stem().string());
|
2019-01-16 04:58:47 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-19 04:01:53 -06:00
|
|
|
basename = uppercase(deck_filename.filename().string());
|
2019-01-16 04:58:47 -06:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2020-03-23 09:46:04 -05:00
|
|
|
void setupEbosSimulator()
|
2016-08-08 08:26:09 -05:00
|
|
|
{
|
2021-05-25 05:57:11 -05:00
|
|
|
ebosSimulator_.reset(new EbosSimulator(EclGenericVanguard::comm(), /*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 {
|
|
|
|
// 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) {
|
2019-08-27 15:41:48 -05:00
|
|
|
std::cerr << "Failed to create valid EclipseState object" << std::endl;
|
2016-12-05 11:27:31 -06:00
|
|
|
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 the simulator.
|
2020-06-25 13:04:19 -05:00
|
|
|
int runSimulator()
|
2016-12-05 11:27:31 -06:00
|
|
|
{
|
2020-06-25 13:04:19 -05:00
|
|
|
return runSimulatorInitOrRun_(&FlowMainEbos::runSimulatorRunCallback_);
|
2020-05-19 09:52:46 -05:00
|
|
|
}
|
|
|
|
|
2020-06-26 12:50:38 -05:00
|
|
|
int runSimulatorInit()
|
|
|
|
{
|
|
|
|
return runSimulatorInitOrRun_(&FlowMainEbos::runSimulatorInitCallback_);
|
|
|
|
}
|
|
|
|
|
2020-05-19 09:52:46 -05:00
|
|
|
private:
|
|
|
|
// Callback that will be called from runSimulatorInitOrRun_().
|
2020-06-25 13:04:19 -05:00
|
|
|
int runSimulatorRunCallback_()
|
2020-05-19 09:52:46 -05:00
|
|
|
{
|
|
|
|
SimulatorReport report = simulator_->run(*simtimer_);
|
2020-06-25 13:04:19 -05:00
|
|
|
runSimulatorAfterSim_(report);
|
2020-05-19 09:52:46 -05:00
|
|
|
return report.success.exit_status;
|
|
|
|
}
|
|
|
|
|
2020-06-26 12:50:38 -05:00
|
|
|
// Callback that will be called from runSimulatorInitOrRun_().
|
|
|
|
int runSimulatorInitCallback_()
|
|
|
|
{
|
|
|
|
simulator_->init(*simtimer_);
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-05-19 09:52:46 -05:00
|
|
|
// Output summary after simulation has completed
|
2020-06-25 13:04:19 -05:00
|
|
|
void runSimulatorAfterSim_(SimulatorReport &report)
|
2020-05-19 09:52:46 -05:00
|
|
|
{
|
2022-12-13 07:05:17 -06:00
|
|
|
if (! this->output_cout_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int threads
|
|
|
|
#if !defined(_OPENMP) || !_OPENMP
|
|
|
|
= 1;
|
2020-05-19 09:52:46 -05:00
|
|
|
#else
|
2022-12-13 07:05:17 -06:00
|
|
|
= omp_get_max_threads();
|
2020-05-19 09:52:46 -05:00
|
|
|
#endif
|
2022-12-13 07:05:17 -06:00
|
|
|
|
2023-02-01 01:40:41 -06:00
|
|
|
printFlowTrailer(mpi_size_, threads, report);
|
2022-12-13 07:05:17 -06:00
|
|
|
|
|
|
|
const auto extraConvOutput = ConvergenceOutputConfiguration {
|
2022-12-16 07:49:28 -06:00
|
|
|
EWOMS_GET_PARAM(TypeTag, std::string, OutputExtraConvergenceInfo),
|
|
|
|
R"(OutputExtraConvergenceInfo (--output-extra-convergence-info))"
|
2022-12-13 07:05:17 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
if (extraConvOutput.want(ConvergenceOutputConfiguration::Option::Steps)) {
|
2021-11-01 06:31:40 -05:00
|
|
|
namespace fs = ::std::filesystem;
|
2022-12-13 07:05:17 -06:00
|
|
|
|
|
|
|
const auto infostep = fs::path { eclState().getIOConfig().getOutputDir() } /
|
|
|
|
fs::path { eclState().getIOConfig().getBaseName() }.concat(".INFOSTEP");
|
|
|
|
|
|
|
|
std::ofstream os(infostep);
|
|
|
|
report.fullReports(os);
|
2020-05-19 09:52:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run the simulator.
|
2020-06-25 13:04:19 -05:00
|
|
|
int runSimulatorInitOrRun_(int (FlowMainEbos::* initOrRunFunc)())
|
2020-05-19 09:52:46 -05:00
|
|
|
{
|
|
|
|
|
2018-06-26 06:42:57 -05:00
|
|
|
const auto& schedule = this->schedule();
|
|
|
|
auto& ioConfig = eclState().getIOConfig();
|
2020-05-19 09:52:46 -05:00
|
|
|
simtimer_ = std::make_unique<SimulatorTimer>();
|
2016-12-05 11:27:31 -06:00
|
|
|
|
|
|
|
// initialize variables
|
2018-06-26 06:42:57 -05:00
|
|
|
const auto& initConfig = eclState().getInitConfig();
|
2021-02-22 11:43:56 -06:00
|
|
|
simtimer_->init(schedule, (size_t)initConfig.getRestartStep());
|
2016-12-05 11:27:31 -06:00
|
|
|
|
2020-08-24 01:35:04 -05:00
|
|
|
if (this->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.
|
2021-05-05 04:22:44 -05:00
|
|
|
if (Parameters::printUnused<TypeTag>(oss)) {
|
2018-08-13 03:31:18 -05:00
|
|
|
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()) {
|
2020-08-24 01:35:04 -05:00
|
|
|
if (this->output_cout_) {
|
2016-12-05 11:27:31 -06:00
|
|
|
std::string msg;
|
|
|
|
msg = "\n\n================ Starting main simulation loop ===============\n";
|
|
|
|
OpmLog::info(msg);
|
|
|
|
}
|
|
|
|
|
2020-06-25 13:04:19 -05:00
|
|
|
return (this->*initOrRunFunc)();
|
2020-05-19 09:52:46 -05:00
|
|
|
}
|
|
|
|
else {
|
2020-08-24 01:35:04 -05:00
|
|
|
if (this->output_cout_) {
|
2016-12-05 11:27:31 -06:00
|
|
|
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
|
|
|
}
|
2020-04-15 08:21:17 -05:00
|
|
|
return EXIT_SUCCESS;
|
2016-08-08 08:26:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 09:52:46 -05:00
|
|
|
protected:
|
|
|
|
|
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
|
|
|
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;
|
2020-02-19 03:14:49 -06:00
|
|
|
std::any parallel_information_;
|
2016-12-05 11:27:31 -06:00
|
|
|
std::unique_ptr<Simulator> simulator_;
|
2020-05-19 09:52:46 -05:00
|
|
|
std::unique_ptr<SimulatorTimer> simtimer_;
|
2020-06-25 13:04:19 -05:00
|
|
|
int argc_;
|
|
|
|
char **argv_;
|
|
|
|
bool output_cout_;
|
|
|
|
bool output_files_;
|
2016-07-12 12:01:14 -05:00
|
|
|
};
|
2023-02-01 01:40:41 -06:00
|
|
|
|
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
|