allow to specify the ECL output directory

by default, it is the current directory.
This commit is contained in:
Andreas Lauser 2018-01-15 10:13:41 +01:00 committed by Tor Harald Sandve
parent 8b7c14c4db
commit 9e7857ec1c
2 changed files with 49 additions and 28 deletions

View File

@ -113,6 +113,9 @@ NEW_PROP_TAG(EnableWriteAllSolutions);
// The number of time steps skipped between writing two consequtive restart files // The number of time steps skipped between writing two consequtive restart files
NEW_PROP_TAG(RestartWritingInterval); NEW_PROP_TAG(RestartWritingInterval);
// The default location for the ECL output files
NEW_PROP_TAG(EclOutputDir);
// Disable well treatment (for users which do this externally) // Disable well treatment (for users which do this externally)
NEW_PROP_TAG(DisableWells); NEW_PROP_TAG(DisableWells);
@ -220,8 +223,8 @@ SET_TYPE_PROP(EclBaseProblem, FluxModule, Ewoms::EclTransFluxModule<TypeTag>);
// Use the dummy gradient calculator in order not to do unnecessary work. // Use the dummy gradient calculator in order not to do unnecessary work.
SET_TYPE_PROP(EclBaseProblem, GradientCalculator, Ewoms::EclDummyGradientCalculator<TypeTag>); SET_TYPE_PROP(EclBaseProblem, GradientCalculator, Ewoms::EclDummyGradientCalculator<TypeTag>);
// The default name of the data file to load // The default location for the ECL output files
SET_STRING_PROP(EclBaseProblem, GridFile, "data/ecl.DATA"); SET_STRING_PROP(EclBaseProblem, EclOutputDir, ".");
// The frequency of writing restart (*.ers) files. This is the number of time steps // The frequency of writing restart (*.ers) files. This is the number of time steps
// between writing restart files // between writing restart files
@ -317,6 +320,8 @@ public:
EWOMS_REGISTER_PARAM(TypeTag, bool, EnableEclOutput, EWOMS_REGISTER_PARAM(TypeTag, bool, EnableEclOutput,
"Write binary output which is compatible with the commercial " "Write binary output which is compatible with the commercial "
"Eclipse simulator"); "Eclipse simulator");
EWOMS_REGISTER_PARAM(TypeTag, std::string, EclOutputDir,
"The directory to which the ECL result files are written");
EWOMS_REGISTER_PARAM(TypeTag, unsigned, RestartWritingInterval, EWOMS_REGISTER_PARAM(TypeTag, unsigned, RestartWritingInterval,
"The frequencies of which time steps are serialized to disk"); "The frequencies of which time steps are serialized to disk");
} }
@ -329,8 +334,6 @@ public:
, transmissibilities_(simulator.gridManager()) , transmissibilities_(simulator.gridManager())
, thresholdPressures_(simulator) , thresholdPressures_(simulator)
, wellManager_(simulator) , wellManager_(simulator)
, eclWriter_( EWOMS_GET_PARAM(TypeTag, bool, EnableEclOutput)
? new EclWriterType(simulator) : nullptr )
, pffDofData_(simulator.gridView(), this->elementMapper()) , pffDofData_(simulator.gridView(), this->elementMapper())
{ {
// Tell the extra modules to initialize its internal data structures // Tell the extra modules to initialize its internal data structures
@ -338,6 +341,32 @@ public:
SolventModule::initFromDeck(gridManager.deck(), gridManager.eclState()); SolventModule::initFromDeck(gridManager.deck(), gridManager.eclState());
PolymerModule::initFromDeck(gridManager.deck(), gridManager.eclState()); PolymerModule::initFromDeck(gridManager.deck(), gridManager.eclState());
if (EWOMS_GET_PARAM(TypeTag, bool, EnableEclOutput)) {
// retrieve the location where the output is supposed to go
const auto& outputDir = EWOMS_GET_PARAM(TypeTag, std::string, EclOutputDir);
// ensure that the output directory exists and that it is a directory
if (outputDir != ".") { // Do not try to create the current directory.
if (!boost::filesystem::is_directory(outputDir)) {
try {
boost::filesystem::create_directories(outputDir);
}
catch (...) {
OPM_THROW(std::runtime_error, "Creation of output directory '"<<outputDir<<"' failed\n");
}
}
}
// specify the directory output. This is not a very nice mechanism because
// the eclState is supposed to be immutable here, IMO.
auto& eclState = this->simulator().gridManager().eclState();
auto& ioConfig = eclState.getIOConfig();
ioConfig.setOutputDir(outputDir);
// create the actual ECL writer
eclWriter_.reset(new EclWriterType(simulator));
}
// Hack to compute the initial thpressure values for restarts // Hack to compute the initial thpressure values for restarts
restartApplied = false; restartApplied = false;
} }
@ -684,10 +713,8 @@ public:
ParentType::writeOutput(verbose); ParentType::writeOutput(verbose);
// output using eclWriter if enabled // output using eclWriter if enabled
if ( eclWriter_ ) { if (eclWriter_)
eclWriter_->writeOutput(dw, t, substep, totalSolverTime, nextstep, fip); eclWriter_->writeOutput(dw, t, substep, totalSolverTime, nextstep, fip);
}
} }
/*! /*!
@ -1139,12 +1166,11 @@ public:
return initialFluidStates_[globalDofIdx]; return initialFluidStates_[globalDofIdx];
} }
void setEclIO(std::unique_ptr<Opm::EclipseIO>&& eclIO) { void setEclIO(std::unique_ptr<Opm::EclipseIO>&& eclIO)
eclWriter_->setEclIO(std::move(eclIO)); { eclWriter_->setEclIO(std::move(eclIO)); }
}
const Opm::EclipseIO& eclIO() const const Opm::EclipseIO& eclIO() const
{return eclWriter_->eclIO();} { return eclWriter_->eclIO(); }
private: private:
Scalar cellCenterDepth( const Element& element ) const Scalar cellCenterDepth( const Element& element ) const
@ -1840,7 +1866,7 @@ private:
EclWellManager<TypeTag> wellManager_; EclWellManager<TypeTag> wellManager_;
std::unique_ptr< EclWriterType > eclWriter_; std::unique_ptr<EclWriterType> eclWriter_;
PffGridVector<GridView, Stencil, PffDofData_, DofMapper> pffDofData_; PffGridVector<GridView, Stencil, PffDofData_, DofMapper> pffDofData_;

View File

@ -28,13 +28,12 @@
#ifndef EWOMS_ECL_WRITER_HH #ifndef EWOMS_ECL_WRITER_HH
#define EWOMS_ECL_WRITER_HH #define EWOMS_ECL_WRITER_HH
#include <opm/material/densead/Evaluation.hpp>
#include "collecttoiorank.hh" #include "collecttoiorank.hh"
#include "ecloutputblackoilmodule.hh" #include "ecloutputblackoilmodule.hh"
#include <ewoms/disc/ecfv/ecfvdiscretization.hh> #include <ewoms/disc/ecfv/ecfvdiscretization.hh>
#include <ewoms/io/baseoutputwriter.hh> #include <ewoms/io/baseoutputwriter.hh>
#include <opm/output/eclipse/EclipseIO.hpp> #include <opm/output/eclipse/EclipseIO.hpp>
#include <opm/common/Valgrind.hpp> #include <opm/common/Valgrind.hpp>
@ -59,7 +58,6 @@ NEW_PROP_TAG(EnableEclOutput);
template <class TypeTag> template <class TypeTag>
class EclWriter; class EclWriter;
/*! /*!
* \ingroup EclBlackOilSimulator * \ingroup EclBlackOilSimulator
* *
@ -87,17 +85,15 @@ class EclWriter
typedef typename GridView::template Codim<0>::Entity Element; typedef typename GridView::template Codim<0>::Entity Element;
typedef typename GridView::template Codim<0>::Iterator ElementIterator; typedef typename GridView::template Codim<0>::Iterator ElementIterator;
typedef CollectDataToIORank< GridManager > CollectDataToIORankType; typedef CollectDataToIORank< GridManager > CollectDataToIORankType;
typedef std::vector<Scalar> ScalarBuffer; typedef std::vector<Scalar> ScalarBuffer;
public: public:
EclWriter(const Simulator& simulator) EclWriter(const Simulator& simulator)
: simulator_(simulator) : simulator_(simulator)
, eclOutputModule_(simulator) , eclOutputModule_(simulator)
, collectToIORank_( simulator_.gridManager() ) , collectToIORank_(simulator_.gridManager())
{ {
Grid globalGrid = simulator_.gridManager().grid(); Grid globalGrid = simulator_.gridManager().grid();
globalGrid.switchToGlobalView(); globalGrid.switchToGlobalView();
@ -110,23 +106,21 @@ public:
~EclWriter() ~EclWriter()
{ } { }
void setEclIO(std::unique_ptr<Opm::EclipseIO>&& eclIO) { void setEclIO(std::unique_ptr<Opm::EclipseIO>&& eclIO)
eclIO_ = std::move(eclIO); { eclIO_ = std::move(eclIO); }
}
const Opm::EclipseIO& eclIO() const const Opm::EclipseIO& eclIO() const
{return *eclIO_;} { return *eclIO_; }
/*! /*!
* \brief collect and pass data and pass it to eclIO writer * \brief collect and pass data and pass it to eclIO writer
*/ */
void writeOutput(const Opm::data::Wells& dw, Scalar t, bool substep, Scalar totalSolverTime, Scalar nextstep, const Opm::data::Solution& fip) void writeOutput(const Opm::data::Wells& dw, Scalar t, bool substep, Scalar totalSolverTime, Scalar nextstep, const Opm::data::Solution& fip)
{ {
#if !HAVE_OPM_OUTPUT
#if !HAVE_OPM_OUTPUT OPM_THROW(std::runtime_error,
OPM_THROW(std::runtime_error, "Opm-output must be available to write ECL output!");
"Opm-output must be available to write ECL output!"); #else
#else
int episodeIdx = simulator_.episodeIndex() + 1; int episodeIdx = simulator_.episodeIndex() + 1;
const auto& gridView = simulator_.gridManager().gridView(); const auto& gridView = simulator_.gridManager().gridView();
@ -179,7 +173,8 @@ public:
#endif #endif
} }
void restartBegin() { void restartBegin()
{
std::map<std::string, Opm::RestartKey> solution_keys {{"PRESSURE" , Opm::RestartKey(Opm::UnitSystem::measure::pressure)}, std::map<std::string, Opm::RestartKey> solution_keys {{"PRESSURE" , Opm::RestartKey(Opm::UnitSystem::measure::pressure)},
{"SWAT" , Opm::RestartKey(Opm::UnitSystem::measure::identity)}, {"SWAT" , Opm::RestartKey(Opm::UnitSystem::measure::identity)},
{"SGAS" , Opm::RestartKey(Opm::UnitSystem::measure::identity)}, {"SGAS" , Opm::RestartKey(Opm::UnitSystem::measure::identity)},