mirror of
https://github.com/OPM/opm-simulators.git
synced 2024-11-21 16:57:25 -06:00
Merge pull request #688 from jokva/refactor-output-restart
Breaking opm-core dependency in opm-output; new summary implementation
This commit is contained in:
commit
dd5d9b34a2
@ -731,7 +731,7 @@ namespace Opm
|
||||
fullReport.reportParam(tot_os);
|
||||
}
|
||||
} else {
|
||||
output_writer_->writeInit( simtimer, geoprops_->nonCartesianConnections() );
|
||||
output_writer_->writeInit( geoprops_->nonCartesianConnections() );
|
||||
if (output_cout_) {
|
||||
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
||||
}
|
||||
|
@ -110,14 +110,19 @@ namespace Opm
|
||||
}
|
||||
|
||||
// init output writer
|
||||
output_writer_.writeInit( timer, geo_.nonCartesianConnections() );
|
||||
output_writer_.writeInit( geo_.nonCartesianConnections() );
|
||||
|
||||
std::string restorefilename = param_.getDefault("restorefile", std::string("") );
|
||||
if( ! restorefilename.empty() )
|
||||
{
|
||||
// -1 means that we'll take the last report step that was written
|
||||
const int desiredRestoreStep = param_.getDefault("restorestep", int(-1) );
|
||||
output_writer_.restore( timer, state, prev_well_state, restorefilename, desiredRestoreStep );
|
||||
|
||||
output_writer_.restore( timer,
|
||||
state,
|
||||
prev_well_state,
|
||||
restorefilename,
|
||||
desiredRestoreStep );
|
||||
}
|
||||
|
||||
unsigned int totalNonlinearIterations = 0;
|
||||
@ -179,7 +184,7 @@ namespace Opm
|
||||
// \Note: The report steps are met in any case
|
||||
// \Note: The sub stepping will require a copy of the state variables
|
||||
if( adaptiveTimeStepping ) {
|
||||
adaptiveTimeStepping->step( timer, *solver, state, well_state, output_writer_ );
|
||||
adaptiveTimeStepping->step( timer, *solver, state, well_state, output_writer_ );
|
||||
}
|
||||
else {
|
||||
// solve for complete report step
|
||||
|
@ -73,14 +73,18 @@ namespace Opm
|
||||
}
|
||||
|
||||
// init output writer
|
||||
output_writer_.writeInit( timer, geo_.nonCartesianConnections());
|
||||
output_writer_.writeInit( geo_.nonCartesianConnections());
|
||||
|
||||
std::string restorefilename = param_.getDefault("restorefile", std::string("") );
|
||||
if( ! restorefilename.empty() )
|
||||
{
|
||||
// -1 means that we'll take the last report step that was written
|
||||
const int desiredRestoreStep = param_.getDefault("restorestep", int(-1) );
|
||||
output_writer_.restore( timer, state, prev_well_state, restorefilename, desiredRestoreStep );
|
||||
output_writer_.restore( timer,
|
||||
state,
|
||||
prev_well_state,
|
||||
restorefilename,
|
||||
desiredRestoreStep );
|
||||
}
|
||||
|
||||
unsigned int totalNonlinearIterations = 0;
|
||||
@ -141,7 +145,7 @@ namespace Opm
|
||||
// \Note: The report steps are met in any case
|
||||
// \Note: The sub stepping will require a copy of the state variables
|
||||
if( adaptiveTimeStepping ) {
|
||||
adaptiveTimeStepping->step( timer, *solver, state, well_state, output_writer_ );
|
||||
adaptiveTimeStepping->step( timer, *solver, state, well_state, output_writer_ );
|
||||
}
|
||||
else {
|
||||
// solve for complete report step
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#include <opm/core/simulator/BlackoilState.hpp>
|
||||
#include <opm/core/utility/DataMap.hpp>
|
||||
#include <opm/core/utility/Compat.hpp>
|
||||
#include <opm/output/vtk/writeVtkData.hpp>
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
@ -246,10 +247,10 @@ namespace Opm
|
||||
|
||||
void
|
||||
BlackoilOutputWriter::
|
||||
writeInit(const SimulatorTimerInterface& timer, const NNC& non_cartesian_connections)
|
||||
writeInit(const NNC& nnc)
|
||||
{
|
||||
if( eclWriter_ ) {
|
||||
eclWriter_->writeInit(timer, non_cartesian_connections);
|
||||
eclWriter_->writeInit( nnc );
|
||||
}
|
||||
}
|
||||
|
||||
@ -342,7 +343,11 @@ namespace Opm
|
||||
if (initConfig->restartRequested() && ((initConfig->getRestartStep()) == (timer.currentStepNum()))) {
|
||||
std::cout << "Skipping restart write in start of step " << timer.currentStepNum() << std::endl;
|
||||
} else {
|
||||
eclWriter_->writeTimeStep(timer, state, wellState, substep );
|
||||
eclWriter_->writeTimeStep(timer.currentStepNum(),
|
||||
timer.simulationTimeElapsed(),
|
||||
simToSolution( state, phaseUsage_ ),
|
||||
wellState.report(),
|
||||
substep );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,9 @@
|
||||
#ifndef OPM_SIMULATORFULLYIMPLICITBLACKOILOUTPUT_HEADER_INCLUDED
|
||||
#define OPM_SIMULATORFULLYIMPLICITBLACKOILOUTPUT_HEADER_INCLUDED
|
||||
#include <opm/core/grid.h>
|
||||
#include <opm/core/simulator/SimulatorTimerInterface.hpp>
|
||||
#include <opm/core/simulator/WellState.hpp>
|
||||
#include <opm/core/utility/Compat.hpp>
|
||||
#include <opm/core/utility/DataMap.hpp>
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <opm/output/eclipse/EclipseReader.hpp>
|
||||
@ -140,68 +142,66 @@ namespace Opm
|
||||
}
|
||||
}
|
||||
|
||||
/** Wrapper class satisfying the OutputWriter interface and writing VTK output. */
|
||||
template <class Grid>
|
||||
class BlackoilVTKWriter : public OutputWriter
|
||||
{
|
||||
public:
|
||||
// constructor taking grid and directory
|
||||
BlackoilVTKWriter(const Grid& grid,
|
||||
const std::string& outputDir)
|
||||
: grid_( grid ),
|
||||
outputDir_( outputDir )
|
||||
class BlackoilSubWriter {
|
||||
public:
|
||||
BlackoilSubWriter( const std::string& outputDir )
|
||||
: outputDir_( outputDir )
|
||||
{}
|
||||
|
||||
/** \copydoc Opm::OutputWriter::writeInit */
|
||||
void writeInit(const SimulatorTimerInterface& /* timer */, const NNC& /* non_cartesian_connections */)
|
||||
{}
|
||||
|
||||
/** \copydoc Opm::OutputWriter::writeTimeStep */
|
||||
void writeTimeStep(const SimulatorTimerInterface& timer,
|
||||
virtual void writeTimeStep(const SimulatorTimerInterface& timer,
|
||||
const SimulationDataContainer& state,
|
||||
const WellState&,
|
||||
bool /*substep*/ = false)
|
||||
{
|
||||
outputStateVtk(grid_, state, timer.currentStepNum(), outputDir_);
|
||||
}
|
||||
|
||||
protected:
|
||||
const Grid& grid_;
|
||||
const std::string outputDir_;
|
||||
bool /*substep*/ = false) = 0;
|
||||
protected:
|
||||
const std::string outputDir_;
|
||||
};
|
||||
|
||||
/** Wrapper class satisfying the OutputWriter interface and writing Matlab output. */
|
||||
template <class Grid>
|
||||
class BlackoilMatlabWriter : public OutputWriter
|
||||
template< class Grid >
|
||||
class BlackoilVTKWriter : public BlackoilSubWriter {
|
||||
public:
|
||||
BlackoilVTKWriter( const Grid& grid,
|
||||
const std::string& outputDir )
|
||||
: BlackoilSubWriter( outputDir )
|
||||
, grid_( grid )
|
||||
{}
|
||||
|
||||
void writeTimeStep(const SimulatorTimerInterface& timer,
|
||||
const SimulationDataContainer& state,
|
||||
const WellState&,
|
||||
bool /*substep*/ = false) override
|
||||
{
|
||||
outputStateVtk(grid_, state, timer.currentStepNum(), outputDir_);
|
||||
}
|
||||
|
||||
protected:
|
||||
const Grid& grid_;
|
||||
};
|
||||
|
||||
template< typename Grid >
|
||||
class BlackoilMatlabWriter : public BlackoilSubWriter
|
||||
{
|
||||
public:
|
||||
// constructor taking grid and directory
|
||||
BlackoilMatlabWriter(const Grid& grid,
|
||||
const std::string& outputDir)
|
||||
: grid_( grid ),
|
||||
outputDir_( outputDir )
|
||||
public:
|
||||
BlackoilMatlabWriter( const Grid& grid,
|
||||
const std::string& outputDir )
|
||||
: BlackoilSubWriter( outputDir )
|
||||
, grid_( grid )
|
||||
{}
|
||||
|
||||
/** \copydoc Opm::OutputWriter::writeInit */
|
||||
void writeInit(const SimulatorTimerInterface& /* timer */, const NNC& /* non_cartesian_connections */)
|
||||
{}
|
||||
|
||||
/** \copydoc Opm::OutputWriter::writeTimeStep */
|
||||
void writeTimeStep(const SimulatorTimerInterface& timer,
|
||||
const SimulationDataContainer& reservoirState,
|
||||
const WellState& wellState,
|
||||
bool /*substep*/ = false)
|
||||
bool /*substep*/ = false) override
|
||||
{
|
||||
outputStateMatlab(grid_, reservoirState, timer.currentStepNum(), outputDir_);
|
||||
outputWellStateMatlab(wellState, timer.currentStepNum(), outputDir_);
|
||||
}
|
||||
protected:
|
||||
const Grid& grid_;
|
||||
const std::string outputDir_;
|
||||
|
||||
protected:
|
||||
const Grid& grid_;
|
||||
};
|
||||
|
||||
/** \brief Wrapper class for VTK, Matlab, and ECL output. */
|
||||
class BlackoilOutputWriter : public OutputWriter
|
||||
class BlackoilOutputWriter
|
||||
{
|
||||
|
||||
public:
|
||||
@ -214,7 +214,7 @@ namespace Opm
|
||||
const double* permeability );
|
||||
|
||||
/** \copydoc Opm::OutputWriter::writeInit */
|
||||
void writeInit(const SimulatorTimerInterface &timer, const NNC& non_cartesian_connections);
|
||||
void writeInit(const NNC& non_cartesian_connections);
|
||||
|
||||
/** \copydoc Opm::OutputWriter::writeTimeStep */
|
||||
void writeTimeStep(const SimulatorTimerInterface& timer,
|
||||
@ -261,8 +261,9 @@ namespace Opm
|
||||
int lastBackupReportStep_;
|
||||
|
||||
std::ofstream backupfile_;
|
||||
std::unique_ptr< OutputWriter > vtkWriter_;
|
||||
std::unique_ptr< OutputWriter > matlabWriter_;
|
||||
Opm::PhaseUsage phaseUsage_;
|
||||
std::unique_ptr< BlackoilSubWriter > vtkWriter_;
|
||||
std::unique_ptr< BlackoilSubWriter > matlabWriter_;
|
||||
std::unique_ptr< EclipseWriter > eclWriter_;
|
||||
EclipseStateConstPtr eclipseState_;
|
||||
|
||||
@ -288,6 +289,7 @@ namespace Opm
|
||||
outputDir_( output_ ? param.getDefault("output_dir", std::string("output")) : "." ),
|
||||
output_interval_( output_ ? param.getDefault("output_interval", 1): 0 ),
|
||||
lastBackupReportStep_( -1 ),
|
||||
phaseUsage_( phaseUsage ),
|
||||
vtkWriter_( output_ && param.getDefault("output_vtk",false) ?
|
||||
new BlackoilVTKWriter< Grid >( grid, outputDir_ ) : 0 ),
|
||||
matlabWriter_( output_ && parallelOutput_->isIORank() &&
|
||||
@ -359,7 +361,12 @@ namespace Opm
|
||||
|
||||
const Wells* wells = wellsmanager.c_wells();
|
||||
wellstate.resize(wells, simulatorstate); //Resize for restart step
|
||||
Opm::init_from_restart_file(eclipseState_, Opm::UgGridHelpers::numCells(grid), phaseusage, simulatorstate, wellstate);
|
||||
auto restarted = Opm::init_from_restart_file(
|
||||
*eclipseState_,
|
||||
Opm::UgGridHelpers::numCells(grid) );
|
||||
|
||||
solutionToSim( restarted.first, phaseusage, simulatorstate );
|
||||
wellsToState( restarted.second, wellstate );
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <opm/core/simulator/SimulatorReport.hpp>
|
||||
#include <opm/core/simulator/SimulatorTimer.hpp>
|
||||
#include <opm/core/utility/StopWatch.hpp>
|
||||
#include <opm/core/utility/DataMap.hpp>
|
||||
#include <opm/output/vtk/writeVtkData.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
|
||||
|
@ -191,6 +191,60 @@ namespace Opm
|
||||
std::vector<double>& wellPotentials() { return well_potentials_; }
|
||||
const std::vector<double>& wellPotentials() const { return well_potentials_; }
|
||||
|
||||
data::Wells report() const override {
|
||||
data::Wells res = WellState::report();
|
||||
|
||||
const int nw = this->numWells();
|
||||
const int np = this->numPhases();
|
||||
|
||||
/* this is a reference or example on **how** to convert from
|
||||
* WellState to something understood by opm-output. it is intended
|
||||
* to be properly implemented and maintained as a part of
|
||||
* simulators, as it relies on simulator internals, details and
|
||||
* representations.
|
||||
*/
|
||||
|
||||
for( auto w = 0; w < nw; ++w ) {
|
||||
using rt = data::Rates::opt;
|
||||
std::map< size_t, data::Completion > completions;
|
||||
|
||||
// completions aren't supported yet
|
||||
//const auto* begin = wells_->well_connpos + w;
|
||||
//const auto* end = wells_->well_connpos + w + 1;
|
||||
//for( auto* i = begin; i != end; ++i ) {
|
||||
// const auto perfrate = this->perfPhaseRates().begin() + *i;
|
||||
// data::Rates perfrates;
|
||||
// perfrates.set( rt::wat, *(perfrate + 0) );
|
||||
// perfrates.set( rt::oil, *(perfrate + 1) );
|
||||
// perfrates.set( rt::gas, *(perfrate + 2) );
|
||||
|
||||
// const size_t active_index = wells_->well_cells[ *i ];
|
||||
|
||||
// completions.emplace( active_index,
|
||||
// data::Completion{ active_index, perfrates } );
|
||||
//}
|
||||
|
||||
const auto wellrate_index = np * w;
|
||||
const auto& wv = this->wellRates();
|
||||
|
||||
data::Rates wellrates;
|
||||
if( np == 3 ) {
|
||||
/* only write if 3-phase solution */
|
||||
wellrates.set( rt::wat, wv[ wellrate_index + 0 ] );
|
||||
wellrates.set( rt::oil, wv[ wellrate_index + 1 ] );
|
||||
wellrates.set( rt::gas, wv[ wellrate_index + 2 ] );
|
||||
}
|
||||
|
||||
const double bhp = this->bhp()[ w ];
|
||||
const double thp = this->thp()[ w ];
|
||||
|
||||
res.emplace( wells_->name[ w ],
|
||||
data::Well { wellrates, bhp, thp, std::move( completions ) } );
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<double> perfphaserates_;
|
||||
std::vector<int> current_controls_;
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <opm/core/simulator/SimulatorReport.hpp>
|
||||
#include <opm/core/simulator/SimulatorTimer.hpp>
|
||||
#include <opm/core/utility/StopWatch.hpp>
|
||||
#include <opm/core/utility/DataMap.hpp>
|
||||
#include <opm/output/vtk/writeVtkData.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
#include <opm/core/utility/miscUtilitiesBlackoil.hpp>
|
||||
|
@ -36,6 +36,8 @@
|
||||
#include <opm/core/simulator/SimulatorReport.hpp>
|
||||
#include <opm/core/simulator/SimulatorTimer.hpp>
|
||||
#include <opm/core/utility/StopWatch.hpp>
|
||||
#include <opm/core/utility/Compat.hpp>
|
||||
#include <opm/core/utility/DataMap.hpp>
|
||||
#include <opm/output/vtk/writeVtkData.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
|
||||
@ -608,17 +610,20 @@ namespace Opm
|
||||
const std::string& output_dir)
|
||||
{
|
||||
#ifdef HAVE_ERT
|
||||
Opm::DataMap dm;
|
||||
dm["saturation"] = &state.saturation();
|
||||
dm["pressure"] = &state.pressure();
|
||||
dm["concentration"] = &state.getCellData( state.CONCENTRATION ) ;
|
||||
dm["cmax"] = &state.getCellData( state.CMAX ) ;
|
||||
std::vector<double> cell_velocity;
|
||||
Opm::estimateCellVelocity(grid, state.faceflux(), cell_velocity);
|
||||
dm["velocity"] = &cell_velocity;
|
||||
using ds = data::Solution::key;
|
||||
data::Solution sol;
|
||||
sol.insert( ds::PRESSURE, state.pressure() );
|
||||
sol.insert( ds::SWAT, destripe( state.saturation(), 0, 2 ) );
|
||||
|
||||
writeECLData(grid, dm, simtimer.currentStepNum(), simtimer.simulationTimeElapsed(), simtimer.currentDateTime(),
|
||||
output_dir, "polymer_ecl");
|
||||
writeECLData( grid.cartdims[ 0 ],
|
||||
grid.cartdims[ 1 ],
|
||||
grid.cartdims[ 2 ],
|
||||
grid.number_of_cells,
|
||||
sol,
|
||||
simtimer.currentStepNum(),
|
||||
simtimer.simulationTimeElapsed(),
|
||||
simtimer.currentPosixTime(),
|
||||
output_dir, "polymer_ecl");
|
||||
#else
|
||||
OPM_THROW(std::runtime_error, "Cannot call outputStateBinary() without ert library support. Reconfigure with --with-ert and recompile.");
|
||||
#endif
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <opm/core/simulator/SimulatorReport.hpp>
|
||||
#include <opm/core/simulator/SimulatorTimer.hpp>
|
||||
#include <opm/core/utility/StopWatch.hpp>
|
||||
#include <opm/core/utility/DataMap.hpp>
|
||||
#include <opm/output/vtk/writeVtkData.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
#include <opm/core/utility/miscUtilitiesBlackoil.hpp>
|
||||
@ -158,6 +159,7 @@ namespace Opm
|
||||
if (!vtkfile) {
|
||||
OPM_THROW(std::runtime_error, "Failed to open " << vtkfilename.str());
|
||||
}
|
||||
|
||||
Opm::DataMap dm;
|
||||
dm["saturation"] = &state.saturation();
|
||||
dm["pressure"] = &state.pressure();
|
||||
|
@ -34,6 +34,7 @@
|
||||
|
||||
#include <opm/core/simulator/SimulatorReport.hpp>
|
||||
#include <opm/core/simulator/SimulatorTimer.hpp>
|
||||
#include <opm/core/utility/DataMap.hpp>
|
||||
#include <opm/core/utility/StopWatch.hpp>
|
||||
#include <opm/output/vtk/writeVtkData.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
|
Loading…
Reference in New Issue
Block a user