From e4df4dd48df758f3d9db8eb2a69c9773d7c01836 Mon Sep 17 00:00:00 2001 From: "Kjell W. Kongsvik" Date: Tue, 29 Mar 2016 14:45:48 +0200 Subject: [PATCH] Updated with changes from opm-core master --- opm/output/OutputWriter.cpp | 2 +- opm/output/OutputWriter.hpp | 4 +- opm/output/eclipse/CornerpointChopper.hpp | 6 +- opm/output/eclipse/EclipseReader.hpp | 8 +- opm/output/eclipse/EclipseWriteRFTHandler.hpp | 2 - opm/output/eclipse/EclipseWriter.hpp | 4 +- src/opm/output/eclipse/EclipseReader.cpp | 66 +-- .../output/eclipse/EclipseWriteRFTHandler.cpp | 2 - src/opm/output/eclipse/EclipseWriter.cpp | 23 +- tests/test_EclipseWriteRFTHandler.cpp | 294 ++++++------ tests/test_EclipseWriter.cpp | 100 ++--- tests/test_writeReadRestartFile.cpp | 422 +++++++++--------- tests/test_writenumwells.cpp | 173 +++---- 13 files changed, 557 insertions(+), 549 deletions(-) diff --git a/opm/output/OutputWriter.cpp b/opm/output/OutputWriter.cpp index b8368e9ed..88569d366 100644 --- a/opm/output/OutputWriter.cpp +++ b/opm/output/OutputWriter.cpp @@ -33,7 +33,7 @@ struct MultiWriter : public OutputWriter { } virtual void writeTimeStep(const SimulatorTimerInterface& timer, - const SimulatorState& reservoirState, + const SimulationDataContainer& reservoirState, const WellState& wellState, bool isSubstep) { for (it_t it = writers_->begin (); it != writers_->end(); ++it) { diff --git a/opm/output/OutputWriter.hpp b/opm/output/OutputWriter.hpp index 8ae515772..de9f34607 100644 --- a/opm/output/OutputWriter.hpp +++ b/opm/output/OutputWriter.hpp @@ -30,7 +30,7 @@ namespace Opm { // forward declaration class EclipseState; namespace parameter { class ParameterGroup; } -class SimulatorState; +class SimulationDataContainer; class WellState; struct PhaseUsage; @@ -87,7 +87,7 @@ public: * i.e. timer.currentStepNum () > 0. */ virtual void writeTimeStep(const SimulatorTimerInterface& timer, - const SimulatorState& reservoirState, + const SimulationDataContainer& reservoirState, const WellState& wellState, bool isSubstep) = 0; diff --git a/opm/output/eclipse/CornerpointChopper.hpp b/opm/output/eclipse/CornerpointChopper.hpp index 8cf5e9f03..57fb09ae0 100644 --- a/opm/output/eclipse/CornerpointChopper.hpp +++ b/opm/output/eclipse/CornerpointChopper.hpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include @@ -43,9 +43,9 @@ namespace Opm public: CornerPointChopper(const std::string& file) { - Opm::ParseMode parseMode; + Opm::ParseContext parseContext; Opm::ParserPtr parser(new Opm::Parser()); - deck_ = parser->parseFile(file , parseMode); + deck_ = parser->parseFile(file , parseContext); metricUnits_.reset(Opm::UnitSystem::newMETRIC()); diff --git a/opm/output/eclipse/EclipseReader.hpp b/opm/output/eclipse/EclipseReader.hpp index 70c46f7d1..8db435721 100644 --- a/opm/output/eclipse/EclipseReader.hpp +++ b/opm/output/eclipse/EclipseReader.hpp @@ -2,11 +2,13 @@ #define ECLIPSEREADER_HPP #include + #include -#include #include #include + + namespace Opm { /// @@ -23,10 +25,12 @@ namespace Opm /// An instance of a WellState object, with correct size for each of the 5 contained std::vector objects /// + class SimulationDataContainer; + void init_from_restart_file(EclipseStateConstPtr eclipse_state, int numcells, const PhaseUsage& pu, - SimulatorState& simulator_state, + SimulationDataContainer& simulator_state, WellState& wellstate); diff --git a/opm/output/eclipse/EclipseWriteRFTHandler.hpp b/opm/output/eclipse/EclipseWriteRFTHandler.hpp index b0d8f9ed6..ea178746d 100644 --- a/opm/output/eclipse/EclipseWriteRFTHandler.hpp +++ b/opm/output/eclipse/EclipseWriteRFTHandler.hpp @@ -21,8 +21,6 @@ #define OPM_ECLIPSE_WRITE_RFT_HANDLER_HPP #include -#include -#include #include diff --git a/opm/output/eclipse/EclipseWriter.hpp b/opm/output/eclipse/EclipseWriter.hpp index 19d1e83f4..97187e477 100644 --- a/opm/output/eclipse/EclipseWriter.hpp +++ b/opm/output/eclipse/EclipseWriter.hpp @@ -47,7 +47,7 @@ namespace EclipseWriterDetails { class Summary; } -class SimulatorState; +class SimulationDataContainer; class WellState; namespace parameter { class ParameterGroup; } @@ -101,7 +101,7 @@ public: * \param[in] wellState The production/injection data for all wells */ virtual void writeTimeStep(const SimulatorTimerInterface& timer, - const SimulatorState& reservoirState, + const SimulationDataContainer& reservoirState, const WellState& wellState, bool isSubstep); diff --git a/src/opm/output/eclipse/EclipseReader.cpp b/src/opm/output/eclipse/EclipseReader.cpp index 6928f9a15..210d81d34 100644 --- a/src/opm/output/eclipse/EclipseReader.cpp +++ b/src/opm/output/eclipse/EclipseReader.cpp @@ -19,7 +19,6 @@ #include "EclipseReader.hpp" #include -#include #include #include #include @@ -38,10 +37,10 @@ namespace Opm { - void restoreTemperatureData(const ecl_file_type* file, - EclipseStateConstPtr eclipse_state, - int numcells, - SimulatorState& simulator_state) { + static void restoreTemperatureData(const ecl_file_type* file, + EclipseStateConstPtr eclipse_state, + int numcells, + SimulationDataContainer& simulator_state) { const char* temperature = "TEMP"; if (ecl_file_has_kw(file , temperature)) { @@ -69,7 +68,7 @@ namespace Opm void restorePressureData(const ecl_file_type* file, EclipseStateConstPtr eclipse_state, int numcells, - SimulatorState& simulator_state) { + SimulationDataContainer& simulator_state) { const char* pressure = "PRESSURE"; if (ecl_file_has_kw(file , pressure)) { @@ -91,10 +90,10 @@ namespace Opm } - void restoreSaturation(const ecl_file_type* file_type, - const PhaseUsage& phaseUsage, - int numcells, - SimulatorState& simulator_state) { + static void restoreSaturation(const ecl_file_type* file_type, + const PhaseUsage& phaseUsage, + int numcells, + SimulationDataContainer& simulator_state) { float* sgas_data = NULL; float* swat_data = NULL; @@ -127,19 +126,20 @@ namespace Opm } - void restoreRSandRV(const ecl_file_type* file_type, - SimulationConfigConstPtr sim_config, - int numcells, - BlackoilState* blackoil_state) { + static void restoreRSandRV(const ecl_file_type* file_type, + SimulationConfigConstPtr sim_config, + int numcells, + SimulationDataContainer& simulator_state) { if (sim_config->hasDISGAS()) { const char* RS = "RS"; if (ecl_file_has_kw(file_type, RS)) { ecl_kw_type* rs_kw = ecl_file_iget_named_kw(file_type, RS, 0); float* rs_data = ecl_kw_get_float_ptr(rs_kw); - std::vector rs_datavec(&rs_data[0], &rs_data[numcells]); - blackoil_state->gasoilratio().clear(); - blackoil_state->gasoilratio().insert(blackoil_state->gasoilratio().begin(), rs_datavec.begin(), rs_datavec.end()); + auto& rs = simulator_state.getCellData( BlackoilState::GASOILRATIO ); + for (int i = 0; i < ecl_kw_get_size( rs_kw ); i++) { + rs[i] = rs_data[i]; + } } else { throw std::runtime_error("Restart file is missing RS data!\n"); } @@ -150,9 +150,10 @@ namespace Opm if (ecl_file_has_kw(file_type, RV)) { ecl_kw_type* rv_kw = ecl_file_iget_named_kw(file_type, RV, 0); float* rv_data = ecl_kw_get_float_ptr(rv_kw); - std::vector rv_datavec(&rv_data[0], &rv_data[numcells]); - blackoil_state->rv().clear(); - blackoil_state->rv().insert(blackoil_state->rv().begin(), rv_datavec.begin(), rv_datavec.end()); + auto& rv = simulator_state.getCellData( BlackoilState::RV ); + for (int i = 0; i < ecl_kw_get_size( rv_kw ); i++) { + rv[i] = rv_data[i]; + } } else { throw std::runtime_error("Restart file is missing RV data!\n"); } @@ -160,13 +161,13 @@ namespace Opm } - void restoreSOLUTION(const std::string& restart_filename, - int reportstep, - bool unified, - EclipseStateConstPtr eclipseState, - int numcells, - const PhaseUsage& phaseUsage, - SimulatorState& simulator_state) + static void restoreSOLUTION(const std::string& restart_filename, + int reportstep, + bool unified, + EclipseStateConstPtr eclipseState, + int numcells, + const PhaseUsage& phaseUsage, + SimulationDataContainer& simulator_state) { const char* filename = restart_filename.c_str(); ecl_file_type* file_type = ecl_file_open(filename, 0); @@ -178,11 +179,10 @@ namespace Opm restorePressureData(file_type, eclipseState, numcells, simulator_state); restoreTemperatureData(file_type, eclipseState, numcells, simulator_state); restoreSaturation(file_type, phaseUsage, numcells, simulator_state); - BlackoilState* blackoilState = dynamic_cast(&simulator_state); - if (blackoilState) { + if (simulator_state.hasCellData( BlackoilState::RV )) { SimulationConfigConstPtr sim_config = eclipseState->getSimulationConfig(); - restoreRSandRV(file_type, sim_config, numcells, blackoilState); - } + restoreRSandRV(file_type, sim_config, numcells, simulator_state ); + } } else { std::string error_str = "Restart file " + restart_filename + " does not contain data for report step " + std::to_string(reportstep) + "!\n"; throw std::runtime_error(error_str); @@ -195,7 +195,7 @@ namespace Opm } - void restoreOPM_XWELKeyword(const std::string& restart_filename, int reportstep, bool unified, WellState& wellstate) + static void restoreOPM_XWELKeyword(const std::string& restart_filename, int reportstep, bool unified, WellState& wellstate) { const char * keyword = "OPM_XWEL"; const char* filename = restart_filename.c_str(); @@ -229,7 +229,7 @@ namespace Opm void init_from_restart_file(EclipseStateConstPtr eclipse_state, int numcells, const PhaseUsage& phase_usage, - SimulatorState& simulator_state, + SimulationDataContainer& simulator_state, WellState& wellstate) { InitConfigConstPtr initConfig = eclipse_state->getInitConfig(); diff --git a/src/opm/output/eclipse/EclipseWriteRFTHandler.cpp b/src/opm/output/eclipse/EclipseWriteRFTHandler.cpp index 17fb89030..dee1ed08b 100644 --- a/src/opm/output/eclipse/EclipseWriteRFTHandler.cpp +++ b/src/opm/output/eclipse/EclipseWriteRFTHandler.cpp @@ -20,8 +20,6 @@ #include #include -#include -#include #include #include #include diff --git a/src/opm/output/eclipse/EclipseWriter.cpp b/src/opm/output/eclipse/EclipseWriter.cpp index 98ecf42ea..508ad2d8e 100644 --- a/src/opm/output/eclipse/EclipseWriter.cpp +++ b/src/opm/output/eclipse/EclipseWriter.cpp @@ -23,13 +23,16 @@ #include "EclipseWriter.hpp" +#include + + #include #include #include #include -#include #include #include +#include #include #include #include @@ -1184,16 +1187,19 @@ void EclipseWriter::writeInit(const SimulatorTimerInterface &timer) if (eclipseState_->hasDeckDoubleGridProperty("PERMX")) { auto data = eclipseState_->getDoubleGridProperty("PERMX")->getData(); EclipseWriterDetails::convertFromSiTo(data, Opm::prefix::milli * Opm::unit::darcy); + EclipseWriterDetails::restrictAndReorderToActiveCells(data, gridToEclipseIdx_.size(), gridToEclipseIdx_.data()); fortio.writeKeyword("PERMX", data); } if (eclipseState_->hasDeckDoubleGridProperty("PERMY")) { auto data = eclipseState_->getDoubleGridProperty("PERMY")->getData(); EclipseWriterDetails::convertFromSiTo(data, Opm::prefix::milli * Opm::unit::darcy); + EclipseWriterDetails::restrictAndReorderToActiveCells(data, gridToEclipseIdx_.size(), gridToEclipseIdx_.data()); fortio.writeKeyword("PERMY", data); } if (eclipseState_->hasDeckDoubleGridProperty("PERMZ")) { auto data = eclipseState_->getDoubleGridProperty("PERMZ")->getData(); EclipseWriterDetails::convertFromSiTo(data, Opm::prefix::milli * Opm::unit::darcy); + EclipseWriterDetails::restrictAndReorderToActiveCells(data, gridToEclipseIdx_.size(), gridToEclipseIdx_.data()); fortio.writeKeyword("PERMZ", data); } } @@ -1221,7 +1227,7 @@ void EclipseWriter::writeInit(const SimulatorTimerInterface &timer) // implementation of the writeTimeStep method void EclipseWriter::writeTimeStep(const SimulatorTimerInterface& timer, - const SimulatorState& reservoirState, + const SimulationDataContainer& reservoirState, const WellState& wellState, bool isSubstep) { @@ -1342,14 +1348,15 @@ void EclipseWriter::writeTimeStep(const SimulatorTimerInterface& timer, } - const BlackoilState* blackoilState = dynamic_cast(&reservoirState); - if (blackoilState) { - // Write RS - Dissolved GOR - const std::vector& rs = blackoilState->gasoilratio(); + // Write RS - Dissolved GOR + if (reservoirState.hasCellData( BlackoilState::GASOILRATIO )) { + const std::vector& rs = reservoirState.getCellData( BlackoilState::GASOILRATIO ); sol.add(EclipseWriterDetails::Keyword("RS", rs)); + } - // Write RV - Volatilized oil/gas ratio - const std::vector& rv = blackoilState->rv(); + // Write RV - Volatilized oil/gas ratio + if (reservoirState.hasCellData( BlackoilState::RV )) { + const std::vector& rv = reservoirState.getCellData( BlackoilState::RV ); sol.add(EclipseWriterDetails::Keyword("RV", rv)); } } diff --git a/tests/test_EclipseWriteRFTHandler.cpp b/tests/test_EclipseWriteRFTHandler.cpp index 1983b8274..db11d4672 100755 --- a/tests/test_EclipseWriteRFTHandler.cpp +++ b/tests/test_EclipseWriteRFTHandler.cpp @@ -50,185 +50,183 @@ namespace { - void verifyRFTFile(const std::string& rft_filename) { +void verifyRFTFile(const std::string& rft_filename) { - ecl_rft_file_type * new_rft_file = ecl_rft_file_alloc(rft_filename.c_str()); - std::shared_ptr rft_file; - rft_file.reset(new_rft_file, ecl_rft_file_free); + ecl_rft_file_type * new_rft_file = ecl_rft_file_alloc(rft_filename.c_str()); + std::shared_ptr rft_file; + rft_file.reset(new_rft_file, ecl_rft_file_free); - //Get RFT node for well/time OP_1/10 OKT 2008 - time_t recording_time = util_make_datetime(0, 0, 0, 10, 10, 2008); - ecl_rft_node_type * ecl_rft_node = ecl_rft_file_get_well_time_rft(rft_file.get() , "OP_1" , recording_time); - BOOST_CHECK(ecl_rft_node_is_RFT(ecl_rft_node)); + //Get RFT node for well/time OP_1/10 OKT 2008 + time_t recording_time = util_make_datetime(0, 0, 0, 10, 10, 2008); + ecl_rft_node_type * ecl_rft_node = ecl_rft_file_get_well_time_rft(rft_file.get() , "OP_1" , recording_time); + BOOST_CHECK(ecl_rft_node_is_RFT(ecl_rft_node)); - //Verify RFT data for completions (ijk) 9 9 1, 9 9 2 and 9 9 3 for OP_1 - const ecl_rft_cell_type * ecl_rft_cell1 = ecl_rft_node_lookup_ijk(ecl_rft_node, 8, 8, 0); - const ecl_rft_cell_type * ecl_rft_cell2 = ecl_rft_node_lookup_ijk(ecl_rft_node, 8, 8, 1); - const ecl_rft_cell_type * ecl_rft_cell3 = ecl_rft_node_lookup_ijk(ecl_rft_node, 8, 8, 2); + //Verify RFT data for completions (ijk) 9 9 1, 9 9 2 and 9 9 3 for OP_1 + const ecl_rft_cell_type * ecl_rft_cell1 = ecl_rft_node_lookup_ijk(ecl_rft_node, 8, 8, 0); + const ecl_rft_cell_type * ecl_rft_cell2 = ecl_rft_node_lookup_ijk(ecl_rft_node, 8, 8, 1); + const ecl_rft_cell_type * ecl_rft_cell3 = ecl_rft_node_lookup_ijk(ecl_rft_node, 8, 8, 2); - BOOST_CHECK_CLOSE(ecl_rft_cell_get_pressure(ecl_rft_cell1), 210088*0.00001, 0.00001); - BOOST_CHECK_CLOSE(ecl_rft_cell_get_pressure(ecl_rft_cell2), 210188*0.00001, 0.00001); - BOOST_CHECK_CLOSE(ecl_rft_cell_get_pressure(ecl_rft_cell3), 210288*0.00001, 0.00001); + BOOST_CHECK_CLOSE(ecl_rft_cell_get_pressure(ecl_rft_cell1), 210088*0.00001, 0.00001); + BOOST_CHECK_CLOSE(ecl_rft_cell_get_pressure(ecl_rft_cell2), 210188*0.00001, 0.00001); + BOOST_CHECK_CLOSE(ecl_rft_cell_get_pressure(ecl_rft_cell3), 210288*0.00001, 0.00001); - BOOST_CHECK_EQUAL(ecl_rft_cell_get_sgas(ecl_rft_cell1), 0.0); - BOOST_CHECK_EQUAL(ecl_rft_cell_get_sgas(ecl_rft_cell2), 0.0); - BOOST_CHECK_EQUAL(ecl_rft_cell_get_sgas(ecl_rft_cell3), 0.0); + BOOST_CHECK_EQUAL(ecl_rft_cell_get_sgas(ecl_rft_cell1), 0.0); + BOOST_CHECK_EQUAL(ecl_rft_cell_get_sgas(ecl_rft_cell2), 0.0); + BOOST_CHECK_EQUAL(ecl_rft_cell_get_sgas(ecl_rft_cell3), 0.0); - BOOST_CHECK_EQUAL(ecl_rft_cell_get_swat(ecl_rft_cell1), 0.0); - BOOST_CHECK_EQUAL(ecl_rft_cell_get_swat(ecl_rft_cell2), 0.0); - BOOST_CHECK_EQUAL(ecl_rft_cell_get_swat(ecl_rft_cell3), 0.0); + BOOST_CHECK_EQUAL(ecl_rft_cell_get_swat(ecl_rft_cell1), 0.0); + BOOST_CHECK_EQUAL(ecl_rft_cell_get_swat(ecl_rft_cell2), 0.0); + BOOST_CHECK_EQUAL(ecl_rft_cell_get_swat(ecl_rft_cell3), 0.0); - BOOST_CHECK_EQUAL(ecl_rft_cell_get_soil(ecl_rft_cell1), 1.0); - BOOST_CHECK_EQUAL(ecl_rft_cell_get_soil(ecl_rft_cell2), 1.0); - BOOST_CHECK_EQUAL(ecl_rft_cell_get_soil(ecl_rft_cell3), 1.0); + BOOST_CHECK_EQUAL(ecl_rft_cell_get_soil(ecl_rft_cell1), 1.0); + BOOST_CHECK_EQUAL(ecl_rft_cell_get_soil(ecl_rft_cell2), 1.0); + BOOST_CHECK_EQUAL(ecl_rft_cell_get_soil(ecl_rft_cell3), 1.0); - BOOST_CHECK_EQUAL(ecl_rft_cell_get_depth(ecl_rft_cell1), (0.250 + (0.250/2))); - BOOST_CHECK_EQUAL(ecl_rft_cell_get_depth(ecl_rft_cell2), (2*0.250 + (0.250/2))); - BOOST_CHECK_EQUAL(ecl_rft_cell_get_depth(ecl_rft_cell3), (3*0.250 + (0.250/2))); + BOOST_CHECK_EQUAL(ecl_rft_cell_get_depth(ecl_rft_cell1), (0.250 + (0.250/2))); + BOOST_CHECK_EQUAL(ecl_rft_cell_get_depth(ecl_rft_cell2), (2*0.250 + (0.250/2))); + BOOST_CHECK_EQUAL(ecl_rft_cell_get_depth(ecl_rft_cell3), (3*0.250 + (0.250/2))); +} + + + + +Opm::DeckConstPtr createDeck(const std::string& input_str) { + Opm::ParserPtr parser = std::make_shared(); + Opm::DeckConstPtr deck = parser->parseString(input_str , Opm::ParseContext()); + return deck; +} + + +std::shared_ptr createWellState(std::shared_ptr blackoilState) +{ + std::shared_ptr wellState = std::make_shared(); + wellState->init(0, *blackoilState); + return wellState; +} + + + +std::shared_ptr createBlackoilState(int timeStepIdx, std::shared_ptr ourFineGridManagerPtr) +{ + const UnstructuredGrid &ug_grid = *ourFineGridManagerPtr->c_grid(); + + std::shared_ptr blackoilState = std::make_shared(Opm::UgGridHelpers::numCells( ug_grid ) , Opm::UgGridHelpers::numFaces( ug_grid ), 3); + size_t numCells = Opm::UgGridHelpers::numCells( ug_grid ); + + auto &pressure = blackoilState->pressure(); + for (size_t cellIdx = 0; cellIdx < numCells; ++cellIdx) { + pressure[cellIdx] = timeStepIdx*1e5 + 1e4 + cellIdx; } + return blackoilState; +} +std::shared_ptr createEclipseWriter(std::shared_ptr deck, + std::shared_ptr eclipseState, + std::shared_ptr ourFineGridManagerPtr, + const int * compressedToCartesianCellIdx) +{ + Opm::parameter::ParameterGroup params; + params.insertParameter("deck_filename", "testcase.data"); - Opm::DeckConstPtr createDeck(const std::string& input_str) { - Opm::ParserPtr parser = std::make_shared(); - Opm::DeckConstPtr deck = parser->parseString(input_str , Opm::ParseContext()); - return deck; - } + Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck); + const UnstructuredGrid &ourFinerUnstructuredGrid = *ourFineGridManagerPtr->c_grid(); - std::shared_ptr createWellState(std::shared_ptr blackoilState) - { - std::shared_ptr wellState = std::make_shared(); - wellState->init(0, *blackoilState); - return wellState; - } + std::shared_ptr eclipseWriter = std::make_shared(params, + eclipseState, + phaseUsage, + ourFinerUnstructuredGrid.number_of_cells, + compressedToCartesianCellIdx); - - - std::shared_ptr createBlackoilState(int timeStepIdx, std::shared_ptr ourFineGridManagerPtr) - { - const UnstructuredGrid &ourFinerUnstructuredGrid = *ourFineGridManagerPtr->c_grid(); - - std::shared_ptr blackoilState = std::make_shared(); - blackoilState->init(ourFinerUnstructuredGrid, 3); - - size_t numCells = ourFinerUnstructuredGrid.number_of_cells; - - auto &pressure = blackoilState->pressure(); - for (size_t cellIdx = 0; cellIdx < numCells; ++cellIdx) { - pressure[cellIdx] = timeStepIdx*1e5 + 1e4 + cellIdx; - } - return blackoilState; - } - - - - std::shared_ptr createEclipseWriter(std::shared_ptr deck, - std::shared_ptr eclipseState, - std::shared_ptr ourFineGridManagerPtr, - const int * compressedToCartesianCellIdx) - { - Opm::parameter::ParameterGroup params; - params.insertParameter("deck_filename", "testcase.data"); - - Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck); - - const UnstructuredGrid &ourFinerUnstructuredGrid = *ourFineGridManagerPtr->c_grid(); - - std::shared_ptr eclipseWriter = std::make_shared(params, - eclipseState, - phaseUsage, - ourFinerUnstructuredGrid.number_of_cells, - compressedToCartesianCellIdx); - - return eclipseWriter; - } + return eclipseWriter; +} } BOOST_AUTO_TEST_CASE(test_EclipseWriterRFTHandler) - { - const std::string& deckString = - "RUNSPEC\n" - "OIL\n" - "GAS\n" - "WATER\n" - "DIMENS\n" - " 10 10 10 /\n" - "GRID\n" - "DXV\n" - "10*0.25 /\n" - "DYV\n" - "10*0.25 /\n" - "DZV\n" - "10*0.25 /\n" - "TOPS\n" - "100*0.25 /\n" - "\n" - "START -- 0 \n" - "1 NOV 1979 / \n" - "SCHEDULE\n" - "DATES -- 1\n" - " 1 DES 1979/ \n" - "/\n" - "WELSPECS\n" - " 'OP_1' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" - " 'OP_2' 'OP' 4 4 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" - "/\n" - "COMPDAT\n" - " 'OP_1' 9 9 1 1 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" - " 'OP_1' 9 9 2 2 'OPEN' 1* 46.825 0.311 4332.346 1* 1* 'X' 22.123 / \n" - " 'OP_1' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" - " 'OP_2' 4 4 4 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" - "/\n" - "DATES -- 2\n" - " 10 OKT 2008 / \n" - "/\n" - "WRFT \n" - "/ \n" - "WELOPEN\n" - " 'OP_1' OPEN / \n" - " 'OP_2' OPEN / \n" - "/\n" - "DATES -- 3\n" - " 10 NOV 2008 / \n" - "/\n"; +{ + const std::string& deckString = + "RUNSPEC\n" + "OIL\n" + "GAS\n" + "WATER\n" + "DIMENS\n" + " 10 10 10 /\n" + "GRID\n" + "DXV\n" + "10*0.25 /\n" + "DYV\n" + "10*0.25 /\n" + "DZV\n" + "10*0.25 /\n" + "TOPS\n" + "100*0.25 /\n" + "\n" + "START -- 0 \n" + "1 NOV 1979 / \n" + "SCHEDULE\n" + "DATES -- 1\n" + " 1 DES 1979/ \n" + "/\n" + "WELSPECS\n" + " 'OP_1' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" + " 'OP_2' 'OP' 4 4 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" + "/\n" + "COMPDAT\n" + " 'OP_1' 9 9 1 1 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" + " 'OP_1' 9 9 2 2 'OPEN' 1* 46.825 0.311 4332.346 1* 1* 'X' 22.123 / \n" + " 'OP_1' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" + " 'OP_2' 4 4 4 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" + "/\n" + "DATES -- 2\n" + " 10 OKT 2008 / \n" + "/\n" + "WRFT \n" + "/ \n" + "WELOPEN\n" + " 'OP_1' OPEN / \n" + " 'OP_2' OPEN / \n" + "/\n" + "DATES -- 3\n" + " 10 NOV 2008 / \n" + "/\n"; - test_work_area_type * new_ptr = test_work_area_alloc("test_EclipseWriterRFTHandler"); - std::shared_ptr test_area; - test_area.reset(new_ptr, test_work_area_free); + test_work_area_type * new_ptr = test_work_area_alloc("test_EclipseWriterRFTHandler"); + std::shared_ptr test_area; + test_area.reset(new_ptr, test_work_area_free); - std::shared_ptr deck = createDeck(deckString); - std::shared_ptr eclipseState = std::make_shared(deck , Opm::ParseContext()); + std::shared_ptr deck = createDeck(deckString); + std::shared_ptr eclipseState = std::make_shared(deck , Opm::ParseContext()); - std::shared_ptr simulatorTimer = std::make_shared(); - simulatorTimer->init(eclipseState->getSchedule()->getTimeMap()); + std::shared_ptr simulatorTimer = std::make_shared(); + simulatorTimer->init(eclipseState->getSchedule()->getTimeMap()); - std::shared_ptr ourFineGridManagerPtr = std::make_shared(eclipseState->getEclipseGrid()); - const UnstructuredGrid &ourFinerUnstructuredGrid = *ourFineGridManagerPtr->c_grid(); - const int* compressedToCartesianCellIdx = Opm::UgGridHelpers::globalCell(ourFinerUnstructuredGrid); + std::shared_ptr ourFineGridManagerPtr = std::make_shared(eclipseState->getEclipseGrid()); + const UnstructuredGrid &ourFinerUnstructuredGrid = *ourFineGridManagerPtr->c_grid(); + const int* compressedToCartesianCellIdx = Opm::UgGridHelpers::globalCell(ourFinerUnstructuredGrid); - std::shared_ptr eclipseWriter = createEclipseWriter(deck, - eclipseState, - ourFineGridManagerPtr, - compressedToCartesianCellIdx); - eclipseWriter->writeInit(*simulatorTimer); + std::shared_ptr eclipseWriter = createEclipseWriter(deck, + eclipseState, + ourFineGridManagerPtr, + compressedToCartesianCellIdx); + eclipseWriter->writeInit(*simulatorTimer); - for (; simulatorTimer->currentStepNum() < simulatorTimer->numSteps(); ++ (*simulatorTimer)) { - std::shared_ptr blackoilState2 = createBlackoilState(simulatorTimer->currentStepNum(),ourFineGridManagerPtr); - std::shared_ptr wellState = createWellState(blackoilState2); - eclipseWriter->writeTimeStep(*simulatorTimer, *blackoilState2, *wellState, false); - } + for (; simulatorTimer->currentStepNum() < simulatorTimer->numSteps(); ++ (*simulatorTimer)) { + std::shared_ptr blackoilState2 = createBlackoilState(simulatorTimer->currentStepNum(),ourFineGridManagerPtr); + std::shared_ptr wellState = createWellState(blackoilState2); + eclipseWriter->writeTimeStep(*simulatorTimer, *blackoilState2, *wellState, false); + } - std::string cwd(test_work_area_get_cwd(test_area.get())); - std::string rft_filename = cwd + "/TESTCASE.RFT"; - verifyRFTFile(rft_filename); + std::string cwd(test_work_area_get_cwd(test_area.get())); + std::string rft_filename = cwd + "/TESTCASE.RFT"; + verifyRFTFile(rft_filename); - } +} diff --git a/tests/test_EclipseWriter.cpp b/tests/test_EclipseWriter.cpp index 839d1c873..df4f77350 100644 --- a/tests/test_EclipseWriter.cpp +++ b/tests/test_EclipseWriter.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -109,8 +110,7 @@ void createBlackoilState(int timeStepIdx) { // allocate a new BlackoilState object const UnstructuredGrid &ourFinerUnstructuredGrid = *ourFineGridManagerPtr->c_grid(); - blackoilState.reset(new Opm::BlackoilState); - blackoilState->init(ourFinerUnstructuredGrid, 3); + blackoilState.reset(new Opm::BlackoilState( Opm::UgGridHelpers::numCells( ourFinerUnstructuredGrid ) , Opm::UgGridHelpers::numFaces( ourFinerUnstructuredGrid ), 3)); size_t numCells = ourFinerUnstructuredGrid.number_of_cells; size_t numFaces = ourFinerUnstructuredGrid.number_of_faces; @@ -367,55 +367,55 @@ void checkSummaryFile(int /*timeStepIdx*/) } BOOST_AUTO_TEST_CASE(EclipseWriterIntegration) - { - const char *deckString = - "RUNSPEC\n" - "INIT\n" - "UNIFOUT\n" - "OIL\n" - "GAS\n" - "WATER\n" - "METRIC\n" - "DIMENS\n" - "3 3 3/\n" - "GRID\n" - "DXV\n" - "1.0 2.0 3.0 /\n" - "DYV\n" - "4.0 5.0 6.0 /\n" - "DZV\n" - "7.0 8.0 9.0 /\n" - "TOPS\n" - "9*100 /\n" - "PROPS\n" - "PORO\n" - "27*0.3 /\n" - "PERMX\n" - "27*1 /\n" - "SOLUTION\n" - "RPTRST\n" - "BASIC=2\n" - "/\n" - "SCHEDULE\n" - "TSTEP\n" - "1.0 2.0 3.0 4.0 /\n" - "WELSPECS\n" - "'INJ' 'G' 1 1 2000 'GAS' /\n" - "'PROD' 'G' 3 3 1000 'OIL' /\n" - "/\n"; +{ + const char *deckString = + "RUNSPEC\n" + "INIT\n" + "UNIFOUT\n" + "OIL\n" + "GAS\n" + "WATER\n" + "METRIC\n" + "DIMENS\n" + "3 3 3/\n" + "GRID\n" + "DXV\n" + "1.0 2.0 3.0 /\n" + "DYV\n" + "4.0 5.0 6.0 /\n" + "DZV\n" + "7.0 8.0 9.0 /\n" + "TOPS\n" + "9*100 /\n" + "PROPS\n" + "PORO\n" + "27*0.3 /\n" + "PERMX\n" + "27*1 /\n" + "SOLUTION\n" + "RPTRST\n" + "BASIC=2\n" + "/\n" + "SCHEDULE\n" + "TSTEP\n" + "1.0 2.0 3.0 4.0 /\n" + "WELSPECS\n" + "'INJ' 'G' 1 1 2000 'GAS' /\n" + "'PROD' 'G' 3 3 1000 'OIL' /\n" + "/\n"; - createEclipseWriter(deckString); + createEclipseWriter(deckString); - eclWriter->writeInit(*simTimer); + eclWriter->writeInit(*simTimer); - checkEgridFile(); - checkInitFile(); + checkEgridFile(); + checkInitFile(); - for (; simTimer->currentStepNum() < simTimer->numSteps(); ++ (*simTimer)) { - createBlackoilState(simTimer->currentStepNum()); - createWellState(simTimer->currentStepNum()); - eclWriter->writeTimeStep(*simTimer, *blackoilState, *wellState, false); - checkRestartFile(simTimer->currentStepNum()); - checkSummaryFile(simTimer->currentStepNum()); - } - } + for (; simTimer->currentStepNum() < simTimer->numSteps(); ++ (*simTimer)) { + createBlackoilState(simTimer->currentStepNum()); + createWellState(simTimer->currentStepNum()); + eclWriter->writeTimeStep(*simTimer, *blackoilState, *wellState, false); + checkRestartFile(simTimer->currentStepNum()); + checkSummaryFile(simTimer->currentStepNum()); + } +} diff --git a/tests/test_writeReadRestartFile.cpp b/tests/test_writeReadRestartFile.cpp index f09524406..a9c9d0155 100644 --- a/tests/test_writeReadRestartFile.cpp +++ b/tests/test_writeReadRestartFile.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -60,155 +61,156 @@ std::string input = - "RUNSPEC\n" - "OIL\n" - "GAS\n" - "WATER\n" - "DISGAS\n" - "VAPOIL\n" - "UNIFOUT\n" - "UNIFIN\n" - "DIMENS\n" - " 10 10 10 /\n" + "RUNSPEC\n" + "OIL\n" + "GAS\n" + "WATER\n" + "DISGAS\n" + "VAPOIL\n" + "UNIFOUT\n" + "UNIFIN\n" + "DIMENS\n" + " 10 10 10 /\n" - "GRID\n" - "DXV\n" - "10*0.25 /\n" - "DYV\n" - "10*0.25 /\n" - "DZV\n" - "10*0.25 /\n" - "TOPS\n" - "100*0.25 /\n" - "\n" + "GRID\n" + "DXV\n" + "10*0.25 /\n" + "DYV\n" + "10*0.25 /\n" + "DZV\n" + "10*0.25 /\n" + "TOPS\n" + "100*0.25 /\n" + "\n" - "SOLUTION\n" - "RESTART\n" - "TESTWELLSTATE 1/\n" - "\n" + "SOLUTION\n" + "RESTART\n" + "TESTWELLSTATE 1/\n" + "\n" - "START -- 0 \n" - "1 NOV 1979 / \n" + "START -- 0 \n" + "1 NOV 1979 / \n" - "SCHEDULE\n" - "SKIPREST\n" - "RPTRST\n" - "BASIC=1\n" - "/\n" - "DATES -- 1\n" - " 10 OKT 2008 / \n" - "/\n" - "WELSPECS\n" - " 'OP_1' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" - " 'OP_2' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" - "/\n" - "COMPDAT\n" - " 'OP_1' 9 9 1 1 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" - " 'OP_2' 9 9 2 2 'OPEN' 1* 46.825 0.311 4332.346 1* 1* 'X' 22.123 / \n" - " 'OP_1' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" - "/\n" - "WCONPROD\n" - "'OP_1' 'OPEN' 'ORAT' 20000 4* 1000 /\n" - "/\n" - "WCONINJE\n" - "'OP_2' 'GAS' 'OPEN' 'RATE' 100 200 400 /\n" - "/\n" + "SCHEDULE\n" + "SKIPREST\n" + "RPTRST\n" + "BASIC=1\n" + "/\n" + "DATES -- 1\n" + " 10 OKT 2008 / \n" + "/\n" + "WELSPECS\n" + " 'OP_1' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" + " 'OP_2' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" + "/\n" + "COMPDAT\n" + " 'OP_1' 9 9 1 1 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" + " 'OP_2' 9 9 2 2 'OPEN' 1* 46.825 0.311 4332.346 1* 1* 'X' 22.123 / \n" + " 'OP_1' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" + "/\n" + "WCONPROD\n" + "'OP_1' 'OPEN' 'ORAT' 20000 4* 1000 /\n" + "/\n" + "WCONINJE\n" + "'OP_2' 'GAS' 'OPEN' 'RATE' 100 200 400 /\n" + "/\n" - "DATES -- 2\n" - " 20 JAN 2011 / \n" - "/\n" - "WELSPECS\n" - " 'OP_3' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" - "/\n" - "COMPDAT\n" - " 'OP_3' 9 9 1 1 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" - "/\n" - "WCONPROD\n" - "'OP_3' 'OPEN' 'ORAT' 20000 4* 1000 /\n" - "/\n" + "DATES -- 2\n" + " 20 JAN 2011 / \n" + "/\n" + "WELSPECS\n" + " 'OP_3' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" + "/\n" + "COMPDAT\n" + " 'OP_3' 9 9 1 1 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" + "/\n" + "WCONPROD\n" + "'OP_3' 'OPEN' 'ORAT' 20000 4* 1000 /\n" + "/\n" - "DATES -- 3\n" - " 15 JUN 2013 / \n" - "/\n" - "COMPDAT\n" - " 'OP_2' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" - " 'OP_1' 9 9 7 7 'SHUT' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" - "/\n" + "DATES -- 3\n" + " 15 JUN 2013 / \n" + "/\n" + "COMPDAT\n" + " 'OP_2' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" + " 'OP_1' 9 9 7 7 'SHUT' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" + "/\n" - "DATES -- 4\n" - " 22 APR 2014 / \n" - "/\n" - "WELSPECS\n" - " 'OP_4' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" - "/\n" - "COMPDAT\n" - " 'OP_4' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" - " 'OP_3' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" - "/\n" - "WCONPROD\n" - "'OP_4' 'OPEN' 'ORAT' 20000 4* 1000 /\n" - "/\n" + "DATES -- 4\n" + " 22 APR 2014 / \n" + "/\n" + "WELSPECS\n" + " 'OP_4' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" + "/\n" + "COMPDAT\n" + " 'OP_4' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" + " 'OP_3' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" + "/\n" + "WCONPROD\n" + "'OP_4' 'OPEN' 'ORAT' 20000 4* 1000 /\n" + "/\n" - "DATES -- 5\n" - " 30 AUG 2014 / \n" - "/\n" - "WELSPECS\n" - " 'OP_5' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" - "/\n" - "COMPDAT\n" - " 'OP_5' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" - "/\n" - "WCONPROD\n" - "'OP_5' 'OPEN' 'ORAT' 20000 4* 1000 /\n" - "/\n" + "DATES -- 5\n" + " 30 AUG 2014 / \n" + "/\n" + "WELSPECS\n" + " 'OP_5' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" + "/\n" + "COMPDAT\n" + " 'OP_5' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" + "/\n" + "WCONPROD\n" + "'OP_5' 'OPEN' 'ORAT' 20000 4* 1000 /\n" + "/\n" - "DATES -- 6\n" - " 15 SEP 2014 / \n" - "/\n" - "WCONPROD\n" - "'OP_3' 'SHUT' 'ORAT' 20000 4* 1000 /\n" - "/\n" + "DATES -- 6\n" + " 15 SEP 2014 / \n" + "/\n" + "WCONPROD\n" + "'OP_3' 'SHUT' 'ORAT' 20000 4* 1000 /\n" + "/\n" - "DATES -- 7\n" - " 9 OCT 2014 / \n" - "/\n" - "WELSPECS\n" - " 'OP_6' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" - "/\n" - "COMPDAT\n" - " 'OP_6' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" - "/\n" - "WCONPROD\n" - "'OP_6' 'OPEN' 'ORAT' 20000 4* 1000 /\n" - "/\n" - "TSTEP -- 8\n" - "10 /" - "/\n"; + "DATES -- 7\n" + " 9 OCT 2014 / \n" + "/\n" + "WELSPECS\n" + " 'OP_6' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* / \n" + "/\n" + "COMPDAT\n" + " 'OP_6' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 / \n" + "/\n" + "WCONPROD\n" + "'OP_6' 'OPEN' 'ORAT' 20000 4* 1000 /\n" + "/\n" + "TSTEP -- 8\n" + "10 /" + "/\n"; -std::shared_ptr createBlackOilState(Opm::EclipseGridConstPtr eclGrid) { - std::shared_ptr ourFineGridManagerPtr(new Opm::GridManager(eclGrid)); - std::shared_ptr blackoilState(new Opm::BlackoilState); - blackoilState->init(*ourFineGridManagerPtr->c_grid(), 3); +std::shared_ptr createBlackOilState(Opm::EclipseGridConstPtr eclGrid , const Opm::PhaseUsage& phaseUsage) { - return blackoilState; + std::shared_ptr grid(new Opm::GridManager(eclGrid)); + const UnstructuredGrid& ug_grid = *(grid->c_grid()); + std::shared_ptr blackoilState(new Opm::BlackoilState( Opm::UgGridHelpers::numCells(ug_grid) , Opm::UgGridHelpers::numFaces(ug_grid) , phaseUsage.num_phases) ); + + return blackoilState; } Opm::EclipseWriterPtr createEclipseWriter(Opm::DeckConstPtr deck, Opm::EclipseStatePtr eclipseState, std::string& eclipse_data_filename) { - Opm::parameter::ParameterGroup params; - params.insertParameter("deck_filename", eclipse_data_filename); + Opm::parameter::ParameterGroup params; + params.insertParameter("deck_filename", eclipse_data_filename); - const Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck); + const Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck); - Opm::EclipseWriterPtr eclWriter(new Opm::EclipseWriter(params, - eclipseState, - phaseUsage, - eclipseState->getEclipseGrid()->getCartesianSize(), - 0)); - return eclWriter; + Opm::EclipseWriterPtr eclWriter(new Opm::EclipseWriter(params, + eclipseState, + phaseUsage, + eclipseState->getEclipseGrid()->getCartesianSize(), + 0)); + return eclWriter; } void setValuesInWellState(std::shared_ptr wellState){ @@ -247,102 +249,102 @@ void setValuesInWellState(std::shared_ptr wellState){ } BOOST_AUTO_TEST_CASE(EclipseReadWriteWellStateData) - { - std::string eclipse_data_filename = "TestWellState.DATA"; - test_work_area_type * test_area = test_work_area_alloc("EclipseReadWriteWellStateData"); +{ + std::string eclipse_data_filename = "TestWellState.DATA"; + test_work_area_type * test_area = test_work_area_alloc("EclipseReadWriteWellStateData"); - Opm::Parser parser; - Opm::ParseContext parseContext; - Opm::DeckConstPtr deck = parser.parseString(input, parseContext); - Opm::EclipseStatePtr eclipseState(new Opm::EclipseState(deck , parseContext)); - Opm::EclipseWriterPtr eclipseWriter = createEclipseWriter(deck, eclipseState, eclipse_data_filename); + Opm::Parser parser; + Opm::ParseContext parseContext; + Opm::DeckConstPtr deck = parser.parseString(input, parseContext); + Opm::EclipseStatePtr eclipseState(new Opm::EclipseState(deck , parseContext)); + Opm::EclipseWriterPtr eclipseWriter = createEclipseWriter(deck, eclipseState, eclipse_data_filename); - std::shared_ptr simTimer( new Opm::SimulatorTimer() ); - simTimer->init(eclipseState->getSchedule()->getTimeMap()); - eclipseWriter->writeInit(*simTimer); - std::shared_ptr wellState(new Opm::WellState()); - Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck); + std::shared_ptr simTimer( new Opm::SimulatorTimer() ); + simTimer->init(eclipseState->getSchedule()->getTimeMap()); + eclipseWriter->writeInit(*simTimer); + std::shared_ptr wellState(new Opm::WellState()); + Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck); - Opm::GridManager gridManager(deck); - Opm::WellsManager wellsManager(eclipseState, 1, *gridManager.c_grid(), NULL); - const Wells* wells = wellsManager.c_wells(); - std::shared_ptr blackoilState = createBlackOilState(eclipseState->getEclipseGrid()); - wellState->init(wells, *blackoilState); + Opm::GridManager gridManager(deck); + Opm::WellsManager wellsManager(eclipseState, 1, *gridManager.c_grid(), NULL); + const Wells* wells = wellsManager.c_wells(); + std::shared_ptr blackoilState = createBlackOilState(eclipseState->getEclipseGrid(), phaseUsage); + wellState->init(wells, *blackoilState); - //Set test data for pressure - std::vector& pressure = blackoilState->pressure(); - for (std::vector::iterator iter = pressure.begin(); iter != pressure.end(); ++iter) { - *iter = 6.0; - } + //Set test data for pressure + std::vector& pressure = blackoilState->pressure(); + for (std::vector::iterator iter = pressure.begin(); iter != pressure.end(); ++iter) { + *iter = 6.0; + } - //Set test data for temperature - std::vector& temperature = blackoilState->temperature(); - for (std::vector::iterator iter = temperature.begin(); iter != temperature.end(); ++iter) { - *iter = 7.0; - } + //Set test data for temperature + std::vector& temperature = blackoilState->temperature(); + for (std::vector::iterator iter = temperature.begin(); iter != temperature.end(); ++iter) { + *iter = 7.0; + } - //Set test data for saturation water - std::vector swatdata(1000, 8); - Opm::EclipseIOUtil::addToStripedData(swatdata, blackoilState->saturation(), phaseUsage.phase_pos[Opm::BlackoilPhases::Aqua], phaseUsage.num_phases); + //Set test data for saturation water + std::vector swatdata(1000, 8); + Opm::EclipseIOUtil::addToStripedData(swatdata, blackoilState->saturation(), phaseUsage.phase_pos[Opm::BlackoilPhases::Aqua], phaseUsage.num_phases); - //Set test data for saturation gas - std::vector sgasdata(1000, 9); - Opm::EclipseIOUtil::addToStripedData(sgasdata, blackoilState->saturation(), phaseUsage.phase_pos[Opm::BlackoilPhases::Vapour], phaseUsage.num_phases); + //Set test data for saturation gas + std::vector sgasdata(1000, 9); + Opm::EclipseIOUtil::addToStripedData(sgasdata, blackoilState->saturation(), phaseUsage.phase_pos[Opm::BlackoilPhases::Vapour], phaseUsage.num_phases); - // Set test data for rs - double rs = 300.0; - std::vector& rs_vec = blackoilState->gasoilratio(); - for (std::vector::iterator rs_iter = rs_vec.begin(); rs_iter != rs_vec.end(); ++ rs_iter) { - *rs_iter = rs; - rs = rs + 1.0; - } + // Set test data for rs + double rs = 300.0; + std::vector& rs_vec = blackoilState->gasoilratio(); + for (std::vector::iterator rs_iter = rs_vec.begin(); rs_iter != rs_vec.end(); ++ rs_iter) { + *rs_iter = rs; + rs = rs + 1.0; + } - // Set testdata for rv - double rv = 400.0; - std::vector& rv_vec = blackoilState->rv(); - for (std::vector::iterator rv_iter = rv_vec.begin(); rv_iter != rv_vec.end(); ++rv_iter) { - *rv_iter = rv; - rv = rv + 1.0; - } + // Set testdata for rv + double rv = 400.0; + std::vector& rv_vec = blackoilState->rv(); + for (std::vector::iterator rv_iter = rv_vec.begin(); rv_iter != rv_vec.end(); ++rv_iter) { + *rv_iter = rv; + rv = rv + 1.0; + } - setValuesInWellState(wellState); - simTimer->setCurrentStepNum(1); - eclipseWriter->writeTimeStep(*simTimer, *blackoilState, *wellState , false); + setValuesInWellState(wellState); + simTimer->setCurrentStepNum(1); + eclipseWriter->writeTimeStep(*simTimer, *blackoilState, *wellState , false); - std::shared_ptr wellStateRestored(new Opm::WellState()); - wellStateRestored->init(wells, *blackoilState); + std::shared_ptr wellStateRestored(new Opm::WellState()); + wellStateRestored->init(wells, *blackoilState); - //Read and verify OPM XWEL data, and solution data: pressure, temperature, saturation data, rs and rv - std::shared_ptr blackoilStateRestored = createBlackOilState(eclipseState->getEclipseGrid()); - Opm::init_from_restart_file(eclipseState, Opm::UgGridHelpers::numCells(*gridManager.c_grid()), phaseUsage, *blackoilStateRestored, *wellStateRestored); + //Read and verify OPM XWEL data, and solution data: pressure, temperature, saturation data, rs and rv + std::shared_ptr blackoilStateRestored = createBlackOilState(eclipseState->getEclipseGrid(), phaseUsage); + Opm::init_from_restart_file(eclipseState, Opm::UgGridHelpers::numCells(*gridManager.c_grid()), phaseUsage, *blackoilStateRestored, *wellStateRestored); + + BOOST_CHECK_EQUAL_COLLECTIONS(wellState->bhp().begin(), wellState->bhp().end(), wellStateRestored->bhp().begin(), wellStateRestored->bhp().end()); + BOOST_CHECK_EQUAL_COLLECTIONS(wellState->temperature().begin(), wellState->temperature().end(), wellStateRestored->temperature().begin(), wellStateRestored->temperature().end()); + BOOST_CHECK_EQUAL_COLLECTIONS(wellState->wellRates().begin(), wellState->wellRates().end(), wellStateRestored->wellRates().begin(), wellStateRestored->wellRates().end()); + BOOST_CHECK_EQUAL_COLLECTIONS(wellState->perfRates().begin(), wellState->perfRates().end(), wellStateRestored->perfRates().begin(), wellStateRestored->perfRates().end()); + BOOST_CHECK_EQUAL_COLLECTIONS(wellState->perfPress().begin(), wellState->perfPress().end(), wellStateRestored->perfPress().begin(), wellStateRestored->perfPress().end()); - BOOST_CHECK_EQUAL_COLLECTIONS(wellState->bhp().begin(), wellState->bhp().end(), wellStateRestored->bhp().begin(), wellStateRestored->bhp().end()); - BOOST_CHECK_EQUAL_COLLECTIONS(wellState->temperature().begin(), wellState->temperature().end(), wellStateRestored->temperature().begin(), wellStateRestored->temperature().end()); - BOOST_CHECK_EQUAL_COLLECTIONS(wellState->wellRates().begin(), wellState->wellRates().end(), wellStateRestored->wellRates().begin(), wellStateRestored->wellRates().end()); - BOOST_CHECK_EQUAL_COLLECTIONS(wellState->perfRates().begin(), wellState->perfRates().end(), wellStateRestored->perfRates().begin(), wellStateRestored->perfRates().end()); - BOOST_CHECK_EQUAL_COLLECTIONS(wellState->perfPress().begin(), wellState->perfPress().end(), wellStateRestored->perfPress().begin(), wellStateRestored->perfPress().end()); + std::vector swat_restored; + std::vector swat; + std::vector sgas_restored; + std::vector sgas; + Opm::EclipseIOUtil::extractFromStripedData(blackoilStateRestored->saturation(), swat_restored, phaseUsage.phase_pos[Opm::BlackoilPhases::Aqua], phaseUsage.num_phases); + Opm::EclipseIOUtil::extractFromStripedData(blackoilState->saturation(), swat, phaseUsage.phase_pos[Opm::BlackoilPhases::Aqua], phaseUsage.num_phases); + Opm::EclipseIOUtil::extractFromStripedData(blackoilStateRestored->saturation(), sgas_restored, phaseUsage.phase_pos[Opm::BlackoilPhases::Vapour], phaseUsage.num_phases); + Opm::EclipseIOUtil::extractFromStripedData(blackoilState->saturation(), sgas, phaseUsage.phase_pos[Opm::BlackoilPhases::Vapour], phaseUsage.num_phases); - std::vector swat_restored; - std::vector swat; - std::vector sgas_restored; - std::vector sgas; - Opm::EclipseIOUtil::extractFromStripedData(blackoilStateRestored->saturation(), swat_restored, phaseUsage.phase_pos[Opm::BlackoilPhases::Aqua], phaseUsage.num_phases); - Opm::EclipseIOUtil::extractFromStripedData(blackoilState->saturation(), swat, phaseUsage.phase_pos[Opm::BlackoilPhases::Aqua], phaseUsage.num_phases); - Opm::EclipseIOUtil::extractFromStripedData(blackoilStateRestored->saturation(), sgas_restored, phaseUsage.phase_pos[Opm::BlackoilPhases::Vapour], phaseUsage.num_phases); - Opm::EclipseIOUtil::extractFromStripedData(blackoilState->saturation(), sgas, phaseUsage.phase_pos[Opm::BlackoilPhases::Vapour], phaseUsage.num_phases); - - for (size_t cellindex = 0; cellindex < 1000; ++cellindex) { - BOOST_CHECK_CLOSE(blackoilState->pressure()[cellindex], blackoilStateRestored->pressure()[cellindex], 0.00001); - BOOST_CHECK_CLOSE(blackoilState->temperature()[cellindex], blackoilStateRestored->temperature()[cellindex], 0.00001); - BOOST_CHECK_CLOSE(swat[cellindex], swat_restored[cellindex], 0.00001); - BOOST_CHECK_CLOSE(sgas[cellindex], sgas_restored[cellindex], 0.00001); - } + for (size_t cellindex = 0; cellindex < 10; ++cellindex) { + BOOST_CHECK_CLOSE(blackoilState->pressure()[cellindex], blackoilStateRestored->pressure()[cellindex], 0.00001); + BOOST_CHECK_CLOSE(blackoilState->temperature()[cellindex], blackoilStateRestored->temperature()[cellindex], 0.00001); + BOOST_CHECK_CLOSE(swat[cellindex], swat_restored[cellindex], 0.00001); + BOOST_CHECK_CLOSE(sgas[cellindex], sgas_restored[cellindex], 0.00001); + } - for (size_t cellindex = 0; cellindex < 1000; ++cellindex) { - BOOST_CHECK_CLOSE(blackoilState->gasoilratio()[cellindex], blackoilStateRestored->gasoilratio()[cellindex], 0.0000001); - BOOST_CHECK_CLOSE(blackoilState->rv()[cellindex], blackoilStateRestored->rv()[cellindex], 0.0000001); - } + for (size_t cellindex = 0; cellindex < 10; ++cellindex) { + BOOST_CHECK_CLOSE(blackoilState->gasoilratio()[cellindex], blackoilStateRestored->gasoilratio()[cellindex], 0.0000001); + BOOST_CHECK_CLOSE(blackoilState->rv()[cellindex], blackoilStateRestored->rv()[cellindex], 0.0000001); + } - test_work_area_free(test_area); - } + test_work_area_free(test_area); +} diff --git a/tests/test_writenumwells.cpp b/tests/test_writenumwells.cpp index 182ede7b3..3996754a1 100644 --- a/tests/test_writenumwells.cpp +++ b/tests/test_writenumwells.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -57,89 +58,89 @@ void verifyWellState(const std::string& rst_filename, Opm::EclipseGridConstPtr ecl_grid, Opm::ScheduleConstPtr schedule) { - well_info_type * well_info = well_info_alloc(ecl_grid->c_ptr()); - well_info_load_rstfile(well_info, rst_filename.c_str(), false); + well_info_type * well_info = well_info_alloc(ecl_grid->c_ptr()); + well_info_load_rstfile(well_info, rst_filename.c_str(), false); - //Verify numwells - int numwells = well_info_get_num_wells(well_info); - BOOST_CHECK(numwells == (int)schedule->numWells()); + //Verify numwells + int numwells = well_info_get_num_wells(well_info); + BOOST_CHECK(numwells == (int)schedule->numWells()); - std::vector wells = schedule->getWells(); + std::vector wells = schedule->getWells(); - for (int i = 0; i < numwells; ++i) { + for (int i = 0; i < numwells; ++i) { - //Verify wellnames - const char * wellname = well_info_iget_well_name(well_info, i); - Opm::WellConstPtr well = wells.at(i); - BOOST_CHECK(wellname == well->name()); + //Verify wellnames + const char * wellname = well_info_iget_well_name(well_info, i); + Opm::WellConstPtr well = wells.at(i); + BOOST_CHECK(wellname == well->name()); - // Verify well-head position data - well_ts_type * well_ts = well_info_get_ts(well_info , wellname); - well_state_type * well_state = well_ts_iget_state(well_ts, 0); - const well_conn_type * well_head = well_state_get_wellhead(well_state, ECL_GRID_GLOBAL_GRID); - BOOST_CHECK(well_conn_get_i(well_head) == well->getHeadI()); - BOOST_CHECK(well_conn_get_j(well_head) == well->getHeadJ()); + // Verify well-head position data + well_ts_type * well_ts = well_info_get_ts(well_info , wellname); + well_state_type * well_state = well_ts_iget_state(well_ts, 0); + const well_conn_type * well_head = well_state_get_wellhead(well_state, ECL_GRID_GLOBAL_GRID); + BOOST_CHECK(well_conn_get_i(well_head) == well->getHeadI()); + BOOST_CHECK(well_conn_get_j(well_head) == well->getHeadJ()); - for (int j = 0; j < well_ts_get_size(well_ts); ++j) { - well_state = well_ts_iget_state(well_ts, j); + for (int j = 0; j < well_ts_get_size(well_ts); ++j) { + well_state = well_ts_iget_state(well_ts, j); - //Verify welltype - int ert_well_type = well_state_get_type(well_state); - WellType welltype = well->isProducer(j) ? PRODUCER : INJECTOR; - Opm::WellInjector::TypeEnum injectortype = well->getInjectionProperties(j).injectorType; - int ecl_converted_welltype = Opm::EclipseWriter::eclipseWellTypeMask(welltype, injectortype); - int ert_converted_welltype = well_state_translate_ecl_type_int(ecl_converted_welltype); - BOOST_CHECK(ert_well_type == ert_converted_welltype); + //Verify welltype + int ert_well_type = well_state_get_type(well_state); + WellType welltype = well->isProducer(j) ? PRODUCER : INJECTOR; + Opm::WellInjector::TypeEnum injectortype = well->getInjectionProperties(j).injectorType; + int ecl_converted_welltype = Opm::EclipseWriter::eclipseWellTypeMask(welltype, injectortype); + int ert_converted_welltype = well_state_translate_ecl_type_int(ecl_converted_welltype); + BOOST_CHECK(ert_well_type == ert_converted_welltype); - //Verify wellstatus - int ert_well_status = well_state_is_open(well_state) ? 1 : 0; + //Verify wellstatus + int ert_well_status = well_state_is_open(well_state) ? 1 : 0; - Opm::WellCommon::StatusEnum status = well->getStatus(j); - int wellstatus = Opm::EclipseWriter::eclipseWellStatusMask(status); + Opm::WellCommon::StatusEnum status = well->getStatus(j); + int wellstatus = Opm::EclipseWriter::eclipseWellStatusMask(status); - BOOST_CHECK(ert_well_status == wellstatus); + BOOST_CHECK(ert_well_status == wellstatus); - //Verify number of completion connections - const well_conn_collection_type * well_connections = well_state_get_global_connections( well_state ); - size_t num_wellconnections = well_conn_collection_get_size(well_connections); + //Verify number of completion connections + const well_conn_collection_type * well_connections = well_state_get_global_connections( well_state ); + size_t num_wellconnections = well_conn_collection_get_size(well_connections); - int report_nr = well_state_get_report_nr(well_state); - Opm::CompletionSetConstPtr completions_set = well->getCompletions((size_t)report_nr); + int report_nr = well_state_get_report_nr(well_state); + Opm::CompletionSetConstPtr completions_set = well->getCompletions((size_t)report_nr); - BOOST_CHECK(num_wellconnections == completions_set->size()); + BOOST_CHECK(num_wellconnections == completions_set->size()); - //Verify coordinates for each completion connection - for (size_t k = 0; k < num_wellconnections; ++k) { - const well_conn_type * well_connection = well_conn_collection_iget_const(well_connections , k); + //Verify coordinates for each completion connection + for (size_t k = 0; k < num_wellconnections; ++k) { + const well_conn_type * well_connection = well_conn_collection_iget_const(well_connections , k); - Opm::CompletionConstPtr completion = completions_set->get(k); + Opm::CompletionConstPtr completion = completions_set->get(k); - BOOST_CHECK(well_conn_get_i(well_connection) == completion->getI()); - BOOST_CHECK(well_conn_get_j(well_connection) == completion->getJ()); - BOOST_CHECK(well_conn_get_k(well_connection) == completion->getK()); - } - } + BOOST_CHECK(well_conn_get_i(well_connection) == completion->getI()); + BOOST_CHECK(well_conn_get_j(well_connection) == completion->getJ()); + BOOST_CHECK(well_conn_get_k(well_connection) == completion->getK()); + } } + } - well_info_free(well_info); + well_info_free(well_info); } std::shared_ptr createBlackOilState(Opm::EclipseGridConstPtr eclGrid) { - std::shared_ptr ourFineGridManagerPtr(new Opm::GridManager(eclGrid)); - std::shared_ptr blackoilState(new Opm::BlackoilState); - blackoilState->init(*ourFineGridManagerPtr->c_grid(), 3); + std::shared_ptr grid(new Opm::GridManager(eclGrid)); + const UnstructuredGrid& ug_grid = *(grid->c_grid()); + std::shared_ptr blackoilState(new Opm::BlackoilState( Opm::UgGridHelpers::numCells(ug_grid) , Opm::UgGridHelpers::numFaces(ug_grid) , 3 )); - return blackoilState; + return blackoilState; } Opm::DeckConstPtr createDeck(const std::string& eclipse_data_filename) { - Opm::ParserPtr parser(new Opm::Parser()); - Opm::DeckConstPtr deck = parser->parseFile(eclipse_data_filename , Opm::ParseContext()); + Opm::ParserPtr parser(new Opm::Parser()); + Opm::DeckConstPtr deck = parser->parseFile(eclipse_data_filename , Opm::ParseContext()); - return deck; + return deck; } @@ -147,51 +148,51 @@ Opm::EclipseWriterPtr createEclipseWriter(Opm::DeckConstPtr deck, Opm::EclipseStatePtr eclipseState, std::string& eclipse_data_filename) { - Opm::parameter::ParameterGroup params; - params.insertParameter("deck_filename", eclipse_data_filename); + Opm::parameter::ParameterGroup params; + params.insertParameter("deck_filename", eclipse_data_filename); - const Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck); + const Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck); - Opm::EclipseWriterPtr eclWriter(new Opm::EclipseWriter(params, - eclipseState, - phaseUsage, - eclipseState->getEclipseGrid()->getCartesianSize(), - 0)); - return eclWriter; + Opm::EclipseWriterPtr eclWriter(new Opm::EclipseWriter(params, + eclipseState, + phaseUsage, + eclipseState->getEclipseGrid()->getCartesianSize(), + 0)); + return eclWriter; } BOOST_AUTO_TEST_CASE(EclipseWriteRestartWellInfo) - { - std::string eclipse_data_filename = "testBlackoilState3.DATA"; - std::string eclipse_restart_filename = "TESTBLACKOILSTATE3.X0004"; +{ + std::string eclipse_data_filename = "testBlackoilState3.DATA"; + std::string eclipse_restart_filename = "TESTBLACKOILSTATE3.X0004"; - test_work_area_type * test_area = test_work_area_alloc("TEST_EclipseWriteNumWells"); - test_work_area_copy_file(test_area, eclipse_data_filename.c_str()); + test_work_area_type * test_area = test_work_area_alloc("TEST_EclipseWriteNumWells"); + test_work_area_copy_file(test_area, eclipse_data_filename.c_str()); - Opm::ParseContext parseContext; - Opm::DeckConstPtr deck = createDeck(eclipse_data_filename); - Opm::EclipseStatePtr eclipseState(new Opm::EclipseState(deck , parseContext)); - Opm::EclipseWriterPtr eclipseWriter = createEclipseWriter(deck, eclipseState, eclipse_data_filename); + Opm::ParseContext parseContext; + Opm::DeckConstPtr deck = createDeck(eclipse_data_filename); + Opm::EclipseStatePtr eclipseState(new Opm::EclipseState(deck , parseContext)); + Opm::EclipseWriterPtr eclipseWriter = createEclipseWriter(deck, eclipseState, eclipse_data_filename); - std::shared_ptr simTimer( new Opm::SimulatorTimer() ); - simTimer->init(eclipseState->getSchedule()->getTimeMap()); + std::shared_ptr simTimer( new Opm::SimulatorTimer() ); + simTimer->init(eclipseState->getSchedule()->getTimeMap()); - eclipseWriter->writeInit(*simTimer); + eclipseWriter->writeInit(*simTimer); - std::shared_ptr wellState(new Opm::WellState()); - std::shared_ptr blackoilState = createBlackOilState(eclipseState->getEclipseGrid()); - wellState->init(0, *blackoilState); + std::shared_ptr wellState(new Opm::WellState()); + std::shared_ptr blackoilState = createBlackOilState(eclipseState->getEclipseGrid()); + wellState->init(0, *blackoilState); - int countTimeStep = eclipseState->getSchedule()->getTimeMap()->numTimesteps(); + int countTimeStep = eclipseState->getSchedule()->getTimeMap()->numTimesteps(); - for(int timestep=0; timestep <= countTimeStep; ++timestep){ - simTimer->setCurrentStepNum(timestep); - eclipseWriter->writeTimeStep(*simTimer, *blackoilState, *wellState, false); - } + for(int timestep=0; timestep <= countTimeStep; ++timestep){ + simTimer->setCurrentStepNum(timestep); + eclipseWriter->writeTimeStep(*simTimer, *blackoilState, *wellState, false); + } - verifyWellState(eclipse_restart_filename, eclipseState->getEclipseGrid(), eclipseState->getSchedule()); + verifyWellState(eclipse_restart_filename, eclipseState->getEclipseGrid(), eclipseState->getSchedule()); - test_work_area_free(test_area); - } + test_work_area_free(test_area); +}