mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #565 from chflo/OPM-188-restart
Start Flow from restart file
This commit is contained in:
commit
00a6a6c9be
@ -124,5 +124,24 @@ endif (NOT EIGEN3_FOUND)
|
||||
|
||||
|
||||
if (HAVE_OPM_DATA)
|
||||
add_test( NAME flow_SPE1 COMMAND flow ${OPM_DATA_ROOT}/spe1/SPE1CASE1.DATA )
|
||||
add_test( NAME flow_SPE1 COMMAND flow ${OPM_DATA_ROOT}/spe1/SPE1CASE1.DATA )
|
||||
|
||||
add_test( NAME flow_SPE1CASE2 COMMAND flow ${OPM_DATA_ROOT}/spe1/SPE1CASE2.DATA )
|
||||
add_test( NAME flow_SPE1CASE2_restart COMMAND flow ${OPM_DATA_ROOT}/spe1/SPE1CASE2_RESTART.DATA )
|
||||
|
||||
set_tests_properties(flow_SPE1CASE2_restart PROPERTIES DEPENDS flow_SPE1CASE2) # Dependes on the restart file from test flow_SPE1CASE2
|
||||
|
||||
add_executable( test_restart tests/test_restart.cpp )
|
||||
target_link_libraries( test_restart opmautodiff ${Boost_LIBRARIES})
|
||||
|
||||
add_test( compare_restart_files
|
||||
${CMAKE_BINARY_DIR}/bin/test_restart
|
||||
SPE1CASE2.UNRST
|
||||
SPE1CASE2_RESTART.UNRST # Restart from step 60
|
||||
120
|
||||
)
|
||||
|
||||
set_tests_properties(compare_restart_files PROPERTIES DEPENDS flow_SPE1CASE2_restart) # Compares the restart files from tests flow_SPE1CASE2_restart and flow_SPE1CASE2
|
||||
|
||||
|
||||
endif()
|
||||
|
@ -79,6 +79,7 @@
|
||||
#include <opm/parser/eclipse/EclipseState/checkDeck.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 <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
@ -583,7 +584,8 @@ namespace Opm
|
||||
SimulatorTimer simtimer;
|
||||
|
||||
// initialize variables
|
||||
simtimer.init(timeMap);
|
||||
const auto initConfig = eclipse_state_->getInitConfig();
|
||||
simtimer.init(timeMap, initConfig->getRestartInitiated(), (size_t)initConfig->getRestartStep());
|
||||
|
||||
|
||||
|
||||
|
@ -81,6 +81,12 @@ namespace Opm
|
||||
{
|
||||
WellState prev_well_state;
|
||||
|
||||
|
||||
if (output_writer_.isRestart()) {
|
||||
// This is a restart, populate WellState and ReservoirState state objects from restart file
|
||||
output_writer_.initFromRestartFile(props_.phaseUsage(), props_.permeability(), grid_, state, prev_well_state);
|
||||
}
|
||||
|
||||
// Create timers and file for writing timing info.
|
||||
Opm::time::StopWatch solver_timer;
|
||||
double stime = 0.0;
|
||||
@ -144,6 +150,7 @@ namespace Opm
|
||||
// write simulation state at the report stage
|
||||
output_writer_.writeTimeStep( timer, state, well_state );
|
||||
|
||||
|
||||
// Max oil saturation (for VPPARS), hysteresis update.
|
||||
props_.updateSatOilMax(state.saturation());
|
||||
props_.updateSatHyst(state.saturation(), allcells_);
|
||||
|
@ -30,6 +30,9 @@
|
||||
#include <opm/autodiff/GridHelpers.hpp>
|
||||
#include <opm/autodiff/BackupRestore.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/InitConfig/InitConfig.hpp>
|
||||
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
@ -280,7 +283,12 @@ namespace Opm
|
||||
}
|
||||
// ECL output
|
||||
if ( eclWriter_ ) {
|
||||
eclWriter_->writeTimeStep(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 );
|
||||
}
|
||||
}
|
||||
|
||||
// write backup file
|
||||
@ -393,4 +401,10 @@ namespace Opm
|
||||
std::cerr << "Warning: Couldn't open restore file '" << filename << "'" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool BlackoilOutputWriter::isRestart() const {
|
||||
const auto initconfig = eclipseState_->getInitConfig();
|
||||
return initconfig->getRestartInitiated();
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <opm/core/simulator/WellState.hpp>
|
||||
#include <opm/core/utility/DataMap.hpp>
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <opm/core/io/eclipse/EclipseReader.hpp>
|
||||
#include <opm/core/utility/miscUtilities.hpp>
|
||||
#include <opm/core/utility/parameters/ParameterGroup.hpp>
|
||||
|
||||
@ -35,6 +36,10 @@
|
||||
|
||||
#include <opm/autodiff/WellStateFullyImplicitBlackoil.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/InitConfig/InitConfig.hpp>
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
@ -194,6 +199,7 @@ namespace Opm
|
||||
/** \brief Wrapper class for VTK, Matlab, and ECL output. */
|
||||
class BlackoilOutputWriter : public OutputWriter
|
||||
{
|
||||
|
||||
public:
|
||||
// constructor creating different sub writers
|
||||
template <class Grid>
|
||||
@ -209,7 +215,7 @@ namespace Opm
|
||||
/** \copydoc Opm::OutputWriter::writeTimeStep */
|
||||
void writeTimeStep(const SimulatorTimerInterface& timer,
|
||||
const SimulatorState& reservoirState,
|
||||
const WellState& wellState,
|
||||
const Opm::WellState& wellState,
|
||||
bool substep = false);
|
||||
|
||||
/** \brief return output directory */
|
||||
@ -224,6 +230,16 @@ namespace Opm
|
||||
const std::string& filename,
|
||||
const int desiredReportStep);
|
||||
|
||||
|
||||
template <class Grid>
|
||||
void initFromRestartFile(const PhaseUsage& phaseusage,
|
||||
const double* permeability,
|
||||
const Grid& grid,
|
||||
SimulatorState& simulatorstate,
|
||||
WellStateFullyImplicitBlackoil& wellstate);
|
||||
|
||||
bool isRestart() const;
|
||||
|
||||
protected:
|
||||
const bool output_;
|
||||
std::unique_ptr< ParallelDebugOutputInterface > parallelOutput_;
|
||||
@ -238,6 +254,7 @@ namespace Opm
|
||||
std::unique_ptr< OutputWriter > vtkWriter_;
|
||||
std::unique_ptr< OutputWriter > matlabWriter_;
|
||||
std::unique_ptr< EclipseWriter > eclWriter_;
|
||||
EclipseStateConstPtr eclipseState_;
|
||||
};
|
||||
|
||||
|
||||
@ -269,7 +286,8 @@ namespace Opm
|
||||
new EclipseWriter(param, eclipseState, phaseUsage,
|
||||
parallelOutput_->numCells(),
|
||||
parallelOutput_->globalCell() )
|
||||
: 0 )
|
||||
: 0 ),
|
||||
eclipseState_(eclipseState)
|
||||
{
|
||||
// For output.
|
||||
if (output_ && parallelOutput_->isIORank() ) {
|
||||
@ -289,5 +307,32 @@ namespace Opm
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class Grid>
|
||||
inline void
|
||||
BlackoilOutputWriter::
|
||||
initFromRestartFile( const PhaseUsage& phaseusage,
|
||||
const double* permeability,
|
||||
const Grid& grid,
|
||||
SimulatorState& simulatorstate,
|
||||
WellStateFullyImplicitBlackoil& wellstate)
|
||||
{
|
||||
WellsManager wellsmanager(eclipseState_,
|
||||
eclipseState_->getInitConfig()->getRestartStep(),
|
||||
Opm::UgGridHelpers::numCells(grid),
|
||||
Opm::UgGridHelpers::globalCell(grid),
|
||||
Opm::UgGridHelpers::cartDims(grid),
|
||||
Opm::UgGridHelpers::dimensions(grid),
|
||||
Opm::UgGridHelpers::cell2Faces(grid),
|
||||
Opm::UgGridHelpers::beginFaceCentroids(grid),
|
||||
permeability);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
|
@ -169,6 +169,13 @@ namespace Opm
|
||||
}
|
||||
}
|
||||
|
||||
template <class State>
|
||||
void resize(const Wells* wells, const State& state) {
|
||||
const WellStateFullyImplicitBlackoil dummy_state; //Init with an empty previous state only resizes
|
||||
init(wells, state, dummy_state) ;
|
||||
}
|
||||
|
||||
|
||||
/// One rate per phase and well connection.
|
||||
std::vector<double>& perfPhaseRates() { return perfphaserates_; }
|
||||
const std::vector<double>& perfPhaseRates() const { return perfphaserates_; }
|
||||
|
73
tests/test_restart.cpp
Normal file
73
tests/test_restart.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
Copyright 2014 SINTEF ICT, Applied Mathematics.
|
||||
Copyright 2015 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/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if HAVE_DYNAMIC_BOOST_TEST
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MODULE RestartTests
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include <ert/ecl/ecl_rst_file.h>
|
||||
#include <ert/ecl/ecl_kw.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CompareRestartFileResults)
|
||||
{
|
||||
const std::string& filename1 = boost::unit_test::framework::master_test_suite().argv[1];
|
||||
const std::string& filename2 = boost::unit_test::framework::master_test_suite().argv[2];
|
||||
int last_report_step = std::atoi(boost::unit_test::framework::master_test_suite().argv[3]);
|
||||
|
||||
std::map<std::string, double> relative_diffs;
|
||||
relative_diffs["SWAT"] = 0.000200; //0.02 %
|
||||
relative_diffs["SGAS"] = 0.000200;
|
||||
|
||||
relative_diffs["RS"] = 0.000010; //0.001 %
|
||||
relative_diffs["RV"] = 0.000010;
|
||||
relative_diffs["PRESSURE"] = 0.000010;
|
||||
|
||||
ecl_file_type* file1 = ecl_file_open_rstblock_report_step( filename1.c_str() , last_report_step, 1);
|
||||
ecl_file_type* file2 = ecl_file_open_rstblock_report_step( filename2.c_str() , last_report_step, 1);
|
||||
|
||||
for (auto key : {"PRESSURE", "SWAT", "SGAS", "RS", "RV"}) {
|
||||
ecl_kw_type * kw_1 = ecl_file_iget_named_kw( file1 , key, 0);
|
||||
ecl_kw_type * kw_2 = ecl_file_iget_named_kw( file2 , key, 0);
|
||||
|
||||
bool numeric_equal = ecl_kw_numeric_equal(kw_1, kw_2, relative_diffs[key]);
|
||||
if (numeric_equal) {
|
||||
std::cout << " Restart results for " << key << " compared ok" << std::endl;
|
||||
} else {
|
||||
std::cout << " Restart results for " << key << " not ok, failing test " << std::endl;
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL(numeric_equal, true);
|
||||
}
|
||||
|
||||
ecl_file_close(file1);
|
||||
ecl_file_close(file2);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user