Refactored tests

Move 2 decks from strings to seperate files

Started to make test_writeReadRestartfile more simple
This commit is contained in:
Kjell W. Kongsvik
2016-04-21 15:33:45 +02:00
parent bd1d8dc576
commit 35e7507f3e
5 changed files with 96 additions and 89 deletions

View File

@@ -1430,7 +1430,7 @@ EclipseWriter::EclipseWriter(Opm::EclipseStateConstPtr eclipseState,
//TODO
//This should be calculated in EclipseGrid
std::shared_ptr<Opm::GridManager> ourFineGridManagerPtr = std::make_shared<Opm::GridManager>(eclipseState->getEclipseGrid());
std::shared_ptr<Opm::GridManager> ourFineGridManagerPtr = std::make_shared<Opm::GridManager>(eclipseState->getInputGrid());
const UnstructuredGrid &ourFinerUnstructuredGrid = *ourFineGridManagerPtr->c_grid();
auto compressedToCartesianCellIdx__ = Opm::UgGridHelpers::globalCell(ourFinerUnstructuredGrid);

44
tests/testRFT.DATA Normal file
View File

@@ -0,0 +1,44 @@
RUNSPEC
OIL
GAS
WATER
DIMENS
10 10 10 /
GRID
DXV
10*0.25 /
DYV
10*0.25 /
DZV
10*0.25 /
TOPS
100*0.25 /
START -- 0
1 NOV 1979 /
SCHEDULE
DATES -- 1
1 DES 1979/
/
WELSPECS
'OP_1' 'OP' 9 9 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* /
'OP_2' 'OP' 4 4 1* 'OIL' 1* 1* 1* 1* 1* 1* 1* /
/
COMPDAT
'OP_1' 9 9 1 1 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 /
'OP_1' 9 9 2 2 'OPEN' 1* 46.825 0.311 4332.346 1* 1* 'X' 22.123 /
'OP_1' 9 9 3 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 /
'OP_2' 4 4 4 9 'OPEN' 1* 32.948 0.311 3047.839 1* 1* 'X' 22.100 /
/
DATES -- 2
10 OKT 2008 /
/
WRFT
/
WELOPEN
'OP_1' OPEN /
'OP_2' OPEN /
/
DATES -- 3
10 NOV 2008 /
/

View File

@@ -91,9 +91,9 @@ void verifyRFTFile(const std::string& rft_filename) {
Opm::DeckConstPtr createDeck(const std::string& input_str) {
Opm::DeckConstPtr createDeck(const std::string& eclipse_data_filename) {
Opm::ParserPtr parser = std::make_shared<Opm::Parser>();
Opm::DeckConstPtr deck = parser->parseString(input_str , Opm::ParseContext());
Opm::DeckConstPtr deck = parser->parseFile(eclipse_data_filename , Opm::ParseContext());
return deck;
}
@@ -127,13 +127,9 @@ std::shared_ptr<Opm::EclipseWriter> createEclipseWriter(std::shared_ptr<const Op
std::shared_ptr<Opm::EclipseState> eclipseState,
std::shared_ptr<Opm::GridManager> ourFineGridManagerPtr)
{
auto ioConfig = eclipseState->getIOConfig();
ioConfig->setDeckFileName("testcase.data");
Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck);
const UnstructuredGrid &ourFinerUnstructuredGrid = *ourFineGridManagerPtr->c_grid();
std::shared_ptr<Opm::EclipseWriter> eclipseWriter = std::make_shared<Opm::EclipseWriter>(eclipseState,
phaseUsage);
@@ -144,67 +140,21 @@ std::shared_ptr<Opm::EclipseWriter> createEclipseWriter(std::shared_ptr<const Op
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";
std::string eclipse_data_filename = "testRFT.DATA";
test_work_area_type * new_ptr = test_work_area_alloc("test_EclipseWriterRFTHandler");
std::shared_ptr<test_work_area_type> test_area;
test_area.reset(new_ptr, test_work_area_free);
test_work_area_copy_file(test_area.get(), eclipse_data_filename.c_str());
std::shared_ptr<const Opm::Deck> deck = createDeck(deckString);
std::shared_ptr<const Opm::Deck> deck = createDeck(eclipse_data_filename);
std::shared_ptr<Opm::EclipseState> eclipseState = std::make_shared<Opm::EclipseState>(deck , Opm::ParseContext());
std::shared_ptr<Opm::SimulatorTimer> simulatorTimer = std::make_shared<Opm::SimulatorTimer>();
simulatorTimer->init(eclipseState->getSchedule()->getTimeMap());
std::shared_ptr<Opm::GridManager> ourFineGridManagerPtr = std::make_shared<Opm::GridManager>(eclipseState->getInputGrid());
const UnstructuredGrid &ourFinerUnstructuredGrid = *ourFineGridManagerPtr->c_grid();
const int* compressedToCartesianCellIdx = Opm::UgGridHelpers::globalCell(ourFinerUnstructuredGrid);
std::shared_ptr<Opm::EclipseWriter> eclipseWriter = createEclipseWriter(deck,
eclipseState,
@@ -219,9 +169,10 @@ BOOST_AUTO_TEST_CASE(test_EclipseWriterRFTHandler)
}
std::string cwd(test_work_area_get_cwd(test_area.get()));
std::string rft_filename = cwd + "/TESTCASE.RFT";
std::string rft_filename = cwd + "/TESTRFT.RFT";
verifyRFTFile(rft_filename);
}

View File

@@ -86,7 +86,7 @@ std::string input =
"SOLUTION\n"
"RESTART\n"
"TESTWELLSTATE 1/\n"
"FIRST_SIM 1/\n"
"\n"
"START -- 0 \n"
@@ -242,25 +242,22 @@ void setValuesInWellState(std::shared_ptr<Opm::WellState> wellState){
wellState->perfRates()[8] = 38.45;
}
BOOST_AUTO_TEST_CASE(EclipseReadWriteWellStateData)
{
std::string eclipse_data_filename = "TestWellState.DATA";
test_work_area_type * test_area = test_work_area_alloc("EclipseReadWriteWellStateData");
std::shared_ptr<Opm::BlackoilState> first_sim(test_work_area_type * test_area, std::shared_ptr<Opm::WellState> wellState){//const Wells* wells, std::shared_ptr<Opm::BlackoilState> &blackoilState){
std::string eclipse_data_filename = "FIRST_SIM.DATA";
test_work_area_copy_file(test_area, eclipse_data_filename.c_str());
Opm::Parser parser;
Opm::ParseContext parseContext;
Opm::DeckConstPtr deck = parser.parseString(input, parseContext);
Opm::EclipseStatePtr eclipseState(new Opm::EclipseState(deck , parseContext));
auto ioConfig = eclipseState->getIOConfig();
ioConfig->setDeckFileName(eclipse_data_filename);
Opm::DeckConstPtr deck = parser.parseFile(eclipse_data_filename, Opm::ParseContext());
Opm::EclipseStatePtr eclipseState(new Opm::EclipseState(deck, parseContext));
Opm::EclipseWriterPtr eclipseWriter = createEclipseWriter(deck, eclipseState);
std::shared_ptr<Opm::SimulatorTimer> simTimer( new Opm::SimulatorTimer() );
simTimer->init(eclipseState->getSchedule()->getTimeMap());
eclipseWriter->writeInit(*simTimer);
std::shared_ptr<Opm::WellState> wellState(new Opm::WellState());
//
Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck);
Opm::GridManager gridManager(eclipseState->getInputGrid());
@@ -270,16 +267,12 @@ BOOST_AUTO_TEST_CASE(EclipseReadWriteWellStateData)
wellState->init(wells, *blackoilState);
//Set test data for pressure
std::vector<double>& pressure = blackoilState->pressure();
for (std::vector<double>::iterator iter = pressure.begin(); iter != pressure.end(); ++iter) {
*iter = 6.0;
}
auto &pressure = blackoilState->pressure();
pressure.assign(pressure.size(), 6.0 );
//Set test data for temperature
std::vector<double>& temperature = blackoilState->temperature();
for (std::vector<double>::iterator iter = temperature.begin(); iter != temperature.end(); ++iter) {
*iter = 7.0;
}
auto &temperature = blackoilState->temperature();
temperature.assign(temperature.size(), 7.0);
//Set test data for saturation water
std::vector<double> swatdata(1000, 8);
@@ -292,16 +285,16 @@ BOOST_AUTO_TEST_CASE(EclipseReadWriteWellStateData)
// Set test data for rs
double rs = 300.0;
std::vector<double>& rs_vec = blackoilState->gasoilratio();
for (std::vector<double>::iterator rs_iter = rs_vec.begin(); rs_iter != rs_vec.end(); ++ rs_iter) {
*rs_iter = rs;
for (auto &ratio: rs_vec) {
ratio = rs;
rs = rs + 1.0;
}
// Set testdata for rv
double rv = 400.0;
std::vector<double>& rv_vec = blackoilState->rv();
for (std::vector<double>::iterator rv_iter = rv_vec.begin(); rv_iter != rv_vec.end(); ++rv_iter) {
*rv_iter = rv;
for (auto &v: rv_vec) {
v = rv;
rv = rv + 1.0;
}
@@ -309,13 +302,27 @@ BOOST_AUTO_TEST_CASE(EclipseReadWriteWellStateData)
simTimer->setCurrentStepNum(1);
eclipseWriter->writeTimeStep(*simTimer, *blackoilState, *wellState , false);
return blackoilState;
}
void second_sim(test_work_area_type * test_area, std::shared_ptr<Opm::WellState> wellState, std::shared_ptr<Opm::BlackoilState> blackoilState) {
Opm::Parser parser;
Opm::ParseContext parseContext;
Opm::DeckConstPtr deck = parser.parseString(input, parseContext);
Opm::EclipseStatePtr eclipseState(new Opm::EclipseState(deck , parseContext));
Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck);
std::shared_ptr<Opm::WellState> wellStateRestored(new Opm::WellState());
Opm::GridManager gridManager(eclipseState->getInputGrid());
Opm::WellsManager wellsManager(eclipseState, 1, *gridManager.c_grid(), NULL);
const Wells* wells = wellsManager.c_wells();
wellStateRestored->init(wells, *blackoilState);
//Read and verify OPM XWEL data, and solution data: pressure, temperature, saturation data, rs and rv
std::shared_ptr<Opm::BlackoilState> blackoilStateRestored = createBlackOilState(eclipseState->getInputGrid(), 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());
@@ -338,11 +345,19 @@ BOOST_AUTO_TEST_CASE(EclipseReadWriteWellStateData)
BOOST_CHECK_CLOSE(sgas[cellindex], sgas_restored[cellindex], 0.00001);
}
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);
}
}
BOOST_AUTO_TEST_CASE(EclipseReadWriteWellStateData) {
test_work_area_type * test_area = test_work_area_alloc("EclipseReadWriteWellStateData");
std::shared_ptr<Opm::WellState> wellState(new Opm::WellState());
std::shared_ptr<Opm::BlackoilState> blackoilState = first_sim(test_area, wellState);
second_sim(test_area, wellState, blackoilState);
test_work_area_free(test_area);
}

View File

@@ -169,9 +169,6 @@ BOOST_AUTO_TEST_CASE(EclipseWriteRestartWellInfo)
Opm::DeckConstPtr deck = createDeck(eclipse_data_filename);
Opm::EclipseStatePtr eclipseState(new Opm::EclipseState(deck , parseContext));
auto ioConfig = eclipseState->getIOConfig();
ioConfig->setDeckFileName(eclipse_data_filename);
Opm::EclipseWriterPtr eclipseWriter = createEclipseWriter(deck, eclipseState);
std::shared_ptr<Opm::SimulatorTimer> simTimer( new Opm::SimulatorTimer() );
@@ -185,9 +182,9 @@ BOOST_AUTO_TEST_CASE(EclipseWriteRestartWellInfo)
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->getInputGrid(), eclipseState->getSchedule());