mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #625 from OPM/revert-623-PR/async-output
Revert "Asynchronous output."
This commit is contained in:
commit
6a4bd4516c
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2014 SINTEF ICT, Applied Mathematics.
|
Copyright (c) 2014 SINTEF ICT, Applied Mathematics.
|
||||||
Copyright (c) 2015-2016 IRIS AS
|
Copyright (c) 2015 IRIS AS
|
||||||
|
|
||||||
This file is part of the Open Porous Media project (OPM).
|
This file is part of the Open Porous Media project (OPM).
|
||||||
|
|
||||||
@ -19,8 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <future>
|
|
||||||
|
|
||||||
#include "SimulatorFullyImplicitBlackoilOutput.hpp"
|
#include "SimulatorFullyImplicitBlackoilOutput.hpp"
|
||||||
|
|
||||||
#include <opm/common/data/SimulationDataContainer.hpp>
|
#include <opm/common/data/SimulationDataContainer.hpp>
|
||||||
@ -255,45 +253,6 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WriterCall
|
|
||||||
{
|
|
||||||
BlackoilOutputWriter& writer_;
|
|
||||||
std::unique_ptr< SimulatorTimerInterface > timer_;
|
|
||||||
const SimulationDataContainer state_;
|
|
||||||
const WellState wellState_;
|
|
||||||
const bool substep_;
|
|
||||||
|
|
||||||
std::future< bool > asyncWait_;
|
|
||||||
|
|
||||||
explicit WriterCall( BlackoilOutputWriter& writer,
|
|
||||||
const SimulatorTimerInterface& timer,
|
|
||||||
const SimulationDataContainer& state,
|
|
||||||
const WellState& wellState,
|
|
||||||
bool substep,
|
|
||||||
std::future< bool >&& asyncWait)
|
|
||||||
: writer_( writer ),
|
|
||||||
timer_( timer.clone() ),
|
|
||||||
state_( state ),
|
|
||||||
wellState_( wellState ),
|
|
||||||
substep_( substep ),
|
|
||||||
asyncWait_( std::move( asyncWait ) )
|
|
||||||
{}
|
|
||||||
|
|
||||||
// callback to writer's serial writeTimeStep method
|
|
||||||
bool operator () ()
|
|
||||||
{
|
|
||||||
// wait for previous time step thread to be finished
|
|
||||||
// to ensure that write history is correct.
|
|
||||||
if( asyncWait_.valid() ) {
|
|
||||||
asyncWait_.wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
writer_.writeTimeStepSerial( *timer_, state_, wellState_, substep_ );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BlackoilOutputWriter::
|
BlackoilOutputWriter::
|
||||||
writeTimeStep(const SimulatorTimerInterface& timer,
|
writeTimeStep(const SimulatorTimerInterface& timer,
|
||||||
@ -306,7 +265,7 @@ namespace Opm
|
|||||||
vtkWriter_->writeTimeStep( timer, localState, localWellState, false );
|
vtkWriter_->writeTimeStep( timer, localState, localWellState, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isIORank = output_ ;
|
bool isIORank = true ;
|
||||||
if( parallelOutput_ && parallelOutput_->isParallel() )
|
if( parallelOutput_ && parallelOutput_->isParallel() )
|
||||||
{
|
{
|
||||||
// collect all solutions to I/O rank
|
// collect all solutions to I/O rank
|
||||||
@ -316,74 +275,65 @@ namespace Opm
|
|||||||
const SimulationDataContainer& state = (parallelOutput_ && parallelOutput_->isParallel() ) ? parallelOutput_->globalReservoirState() : localState;
|
const SimulationDataContainer& state = (parallelOutput_ && parallelOutput_->isParallel() ) ? parallelOutput_->globalReservoirState() : localState;
|
||||||
const WellState& wellState = (parallelOutput_ && parallelOutput_->isParallel() ) ? parallelOutput_->globalWellState() : localWellState;
|
const WellState& wellState = (parallelOutput_ && parallelOutput_->isParallel() ) ? parallelOutput_->globalWellState() : localWellState;
|
||||||
|
|
||||||
// serial output is only done on I/O rank
|
// output is only done on I/O rank
|
||||||
if( isIORank )
|
if( isIORank )
|
||||||
{
|
{
|
||||||
if( asyncOutput_ ) {
|
// Matlab output
|
||||||
|
if( matlabWriter_ ) {
|
||||||
// spawn write thread that calls eclWriter.writeTimeStepSerial
|
matlabWriter_->writeTimeStep( timer, state, wellState, substep );
|
||||||
// timer, state, and wellState are copied, previous async future is moved
|
|
||||||
WriterCall call( *this, timer, state, wellState, substep, std::move( asyncWait_ ) );
|
|
||||||
asyncWait_ = std::move( std::async( std::move( call ) ) );
|
|
||||||
}
|
}
|
||||||
else {
|
// ECL output
|
||||||
// just write the data to disk
|
if ( eclWriter_ ) {
|
||||||
writeTimeStepSerial( timer, state, wellState, substep );
|
const auto initConfig = eclipseState_->getInitConfig();
|
||||||
|
if (initConfig->getRestartInitiated() && ((initConfig->getRestartStep()) == (timer.currentStepNum()))) {
|
||||||
|
std::cout << "Skipping restart write in start of step " << timer.currentStepNum() << std::endl;
|
||||||
|
} else {
|
||||||
|
eclWriter_->writeTimeStep(timer, state, wellState, substep );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
// write backup file
|
||||||
BlackoilOutputWriter::
|
if( backupfile_ )
|
||||||
writeTimeStepSerial(const SimulatorTimerInterface& timer,
|
|
||||||
const SimulationDataContainer& state,
|
|
||||||
const WellState& wellState,
|
|
||||||
bool substep)
|
|
||||||
{
|
|
||||||
// Matlab output
|
|
||||||
if( matlabWriter_ ) {
|
|
||||||
matlabWriter_->writeTimeStep( timer, state, wellState, substep );
|
|
||||||
}
|
|
||||||
|
|
||||||
// ECL output
|
|
||||||
if ( eclWriter_ )
|
|
||||||
{
|
|
||||||
const auto initConfig = eclipseState_->getInitConfig();
|
|
||||||
if (initConfig->getRestartInitiated() && ((initConfig->getRestartStep()) == (timer.currentStepNum()))) {
|
|
||||||
std::cout << "Skipping restart write in start of step " << timer.currentStepNum() << std::endl;
|
|
||||||
} else {
|
|
||||||
eclWriter_->writeTimeStep(timer, state, wellState, substep );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// write backup file
|
|
||||||
if( backupfile_ )
|
|
||||||
{
|
|
||||||
int reportStep = timer.reportStepNum();
|
|
||||||
int currentTimeStep = timer.currentStepNum();
|
|
||||||
if( (reportStep == currentTimeStep || // true for SimulatorTimer
|
|
||||||
currentTimeStep == 0 || // true for AdaptiveSimulatorTimer at reportStep
|
|
||||||
timer.done() ) // true for AdaptiveSimulatorTimer at reportStep
|
|
||||||
&& lastBackupReportStep_ != reportStep ) // only backup report step once
|
|
||||||
{
|
{
|
||||||
// store report step
|
int reportStep = timer.reportStepNum();
|
||||||
lastBackupReportStep_ = reportStep;
|
int currentTimeStep = timer.currentStepNum();
|
||||||
// write resport step number
|
if( (reportStep == currentTimeStep || // true for SimulatorTimer
|
||||||
backupfile_.write( (const char *) &reportStep, sizeof(int) );
|
currentTimeStep == 0 || // true for AdaptiveSimulatorTimer at reportStep
|
||||||
|
timer.done() ) // true for AdaptiveSimulatorTimer at reportStep
|
||||||
try {
|
&& lastBackupReportStep_ != reportStep ) // only backup report step once
|
||||||
backupfile_ << state;
|
|
||||||
|
|
||||||
const WellStateFullyImplicitBlackoil& boWellState = static_cast< const WellStateFullyImplicitBlackoil& > (wellState);
|
|
||||||
backupfile_ << boWellState;
|
|
||||||
}
|
|
||||||
catch ( const std::bad_cast& e )
|
|
||||||
{
|
{
|
||||||
}
|
// store report step
|
||||||
|
lastBackupReportStep_ = reportStep;
|
||||||
|
// write resport step number
|
||||||
|
backupfile_.write( (const char *) &reportStep, sizeof(int) );
|
||||||
|
|
||||||
backupfile_ << std::flush;
|
/*
|
||||||
}
|
try {
|
||||||
} // end backup
|
const BlackoilState& boState = dynamic_cast< const BlackoilState& > (state);
|
||||||
|
backupfile_ << boState;
|
||||||
|
|
||||||
|
const WellStateFullyImplicitBlackoil& boWellState = static_cast< const WellStateFullyImplicitBlackoil& > (wellState);
|
||||||
|
backupfile_ << boWellState;
|
||||||
|
}
|
||||||
|
catch ( const std::bad_cast& e )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
const WellStateFullyImplicitBlackoil* boWellState =
|
||||||
|
dynamic_cast< const WellStateFullyImplicitBlackoil* > (&wellState);
|
||||||
|
if( boWellState ) {
|
||||||
|
backupfile_ << (*boWellState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
OPM_THROW(std::logic_error,"cast to WellStateFullyImplicitBlackoil failed");
|
||||||
|
*/
|
||||||
|
backupfile_ << std::flush;
|
||||||
|
}
|
||||||
|
} // end backup
|
||||||
|
} // end isIORank
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -43,7 +43,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <future>
|
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
@ -86,7 +85,7 @@ namespace Opm
|
|||||||
Opm::DataMap dm;
|
Opm::DataMap dm;
|
||||||
dm["saturation"] = &state.saturation();
|
dm["saturation"] = &state.saturation();
|
||||||
dm["pressure"] = &state.pressure();
|
dm["pressure"] = &state.pressure();
|
||||||
for (const auto& pair : state.cellData())
|
for (const auto& pair : state.cellData())
|
||||||
{
|
{
|
||||||
const std::string& name = pair.first;
|
const std::string& name = pair.first;
|
||||||
std::string key;
|
std::string key;
|
||||||
@ -221,12 +220,6 @@ namespace Opm
|
|||||||
const Opm::WellState& wellState,
|
const Opm::WellState& wellState,
|
||||||
bool substep = false);
|
bool substep = false);
|
||||||
|
|
||||||
/** \copydoc Opm::OutputWriter::writeTimeStep */
|
|
||||||
void writeTimeStepSerial(const SimulatorTimerInterface& timer,
|
|
||||||
const SimulationDataContainer& reservoirState,
|
|
||||||
const Opm::WellState& wellState,
|
|
||||||
bool substep);
|
|
||||||
|
|
||||||
/** \brief return output directory */
|
/** \brief return output directory */
|
||||||
const std::string& outputDirectory() const { return outputDir_; }
|
const std::string& outputDirectory() const { return outputDir_; }
|
||||||
|
|
||||||
@ -264,8 +257,6 @@ namespace Opm
|
|||||||
std::unique_ptr< OutputWriter > matlabWriter_;
|
std::unique_ptr< OutputWriter > matlabWriter_;
|
||||||
std::unique_ptr< EclipseWriter > eclWriter_;
|
std::unique_ptr< EclipseWriter > eclWriter_;
|
||||||
EclipseStateConstPtr eclipseState_;
|
EclipseStateConstPtr eclipseState_;
|
||||||
const bool asyncOutput_ ;
|
|
||||||
std::future< bool > asyncWait_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -298,8 +289,7 @@ namespace Opm
|
|||||||
parallelOutput_->numCells(),
|
parallelOutput_->numCells(),
|
||||||
parallelOutput_->globalCell() )
|
parallelOutput_->globalCell() )
|
||||||
: 0 ),
|
: 0 ),
|
||||||
eclipseState_(eclipseState),
|
eclipseState_(eclipseState)
|
||||||
asyncOutput_( output_ ? param.getDefault("async_output", bool( false ) ) : false )
|
|
||||||
{
|
{
|
||||||
// For output.
|
// For output.
|
||||||
if (output_ && parallelOutput_->isIORank() ) {
|
if (output_ && parallelOutput_->isIORank() ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user