2016-03-16 04:42:50 -05:00
|
|
|
/*
|
|
|
|
Copyright 2014 Andreas Lauser
|
|
|
|
|
|
|
|
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 EclipseWriter
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
|
|
#include <opm/output/eclipse/EclipseWriter.hpp>
|
|
|
|
|
2016-03-17 06:45:29 -05:00
|
|
|
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
2016-03-16 04:42:50 -05:00
|
|
|
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
|
|
|
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
|
2016-04-15 07:45:26 -05:00
|
|
|
#include <opm/parser/eclipse/EclipseState/IOConfig/IOConfig.hpp>
|
2016-05-13 08:44:08 -05:00
|
|
|
#include <opm/parser/eclipse/Units/ConversionFactors.hpp>
|
2016-03-16 04:42:50 -05:00
|
|
|
|
|
|
|
// ERT stuff
|
|
|
|
#include <ert/ecl/ecl_kw.h>
|
|
|
|
#include <ert/ecl/ecl_endian_flip.h>
|
|
|
|
#include <ert/ecl/fortio.h>
|
2016-04-29 08:45:40 -05:00
|
|
|
#include <ert/util/test_work_area.h>
|
2016-03-16 04:42:50 -05:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2016-05-09 03:34:46 -05:00
|
|
|
using namespace Opm;
|
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
data::Solution createBlackoilState( int timeStepIdx, int numCells ) {
|
2016-03-16 04:42:50 -05:00
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
std::vector< double > pressure( numCells );
|
|
|
|
std::vector< double > swat( numCells );
|
|
|
|
std::vector< double > sgas( numCells );
|
|
|
|
std::vector< double > rs( numCells );
|
|
|
|
std::vector< double > rv( numCells );
|
2016-03-16 04:42:50 -05:00
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
for( int cellIdx = 0; cellIdx < numCells; ++cellIdx) {
|
2016-03-16 04:42:50 -05:00
|
|
|
|
|
|
|
pressure[cellIdx] = timeStepIdx*1e5 + 1e4 + cellIdx;
|
2016-05-13 08:44:08 -05:00
|
|
|
sgas[cellIdx] = timeStepIdx*1e5 +2.2e4 + cellIdx;
|
|
|
|
swat[cellIdx] = timeStepIdx*1e5 +2.3e4 + cellIdx;
|
2016-03-16 04:42:50 -05:00
|
|
|
|
|
|
|
// oil vaporization factor
|
|
|
|
rv[cellIdx] = timeStepIdx*1e5 +3e4 + cellIdx;
|
|
|
|
// gas dissolution factor
|
2016-05-13 08:44:08 -05:00
|
|
|
rs[cellIdx] = timeStepIdx*1e5 + 4e4 + cellIdx;
|
2016-03-16 04:42:50 -05:00
|
|
|
}
|
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
data::Solution solution;
|
|
|
|
using ds = data::Solution::key;
|
2016-03-16 04:42:50 -05:00
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
solution.insert( ds::PRESSURE, pressure );
|
|
|
|
solution.insert( ds::SWAT, swat );
|
|
|
|
solution.insert( ds::SGAS, sgas );
|
|
|
|
solution.insert( ds::RS, rs );
|
|
|
|
solution.insert( ds::RV, rv );
|
|
|
|
return solution;
|
2016-03-16 04:42:50 -05:00
|
|
|
}
|
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
template< typename T >
|
|
|
|
std::vector< T > getErtData( ecl_kw_type *eclKeyword ) {
|
2016-03-16 04:42:50 -05:00
|
|
|
size_t kwSize = ecl_kw_get_size(eclKeyword);
|
2016-05-13 08:44:08 -05:00
|
|
|
T* ertData = static_cast< T* >(ecl_kw_iget_ptr(eclKeyword, 0));
|
2016-03-16 04:42:50 -05:00
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
return { ertData, ertData + kwSize };
|
2016-03-16 04:42:50 -05:00
|
|
|
}
|
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
template< typename T, typename U >
|
|
|
|
void compareErtData(const std::vector< T > &src,
|
|
|
|
const std::vector< U > &dst,
|
|
|
|
double tolerance ) {
|
2016-03-16 04:42:50 -05:00
|
|
|
BOOST_CHECK_EQUAL(src.size(), dst.size());
|
|
|
|
if (src.size() != dst.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < src.size(); ++i)
|
|
|
|
BOOST_CHECK_CLOSE(src[i], dst[i], tolerance);
|
|
|
|
}
|
|
|
|
|
2016-04-29 03:14:06 -05:00
|
|
|
void compareErtData(const std::vector<int> &src, const std::vector<int> &dst)
|
|
|
|
{
|
2016-05-13 08:44:08 -05:00
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS( src.begin(), src.end(),
|
|
|
|
dst.begin(), dst.end() );
|
2016-03-16 04:42:50 -05:00
|
|
|
}
|
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
void checkEgridFile( const EclipseGrid& eclGrid ) {
|
2016-03-16 04:42:50 -05:00
|
|
|
// use ERT directly to inspect the EGRID file produced by EclipseWriter
|
|
|
|
auto egridFile = fortio_open_reader("FOO.EGRID", /*isFormated=*/0, ECL_ENDIAN_FLIP);
|
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
const auto numCells = eclGrid.getNX() * eclGrid.getNY() * eclGrid.getNZ();
|
2016-03-16 04:42:50 -05:00
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
while( auto* eclKeyword = ecl_kw_fread_alloc( egridFile ) ) {
|
2016-03-16 04:42:50 -05:00
|
|
|
std::string keywordName(ecl_kw_get_header(eclKeyword));
|
|
|
|
if (keywordName == "COORD") {
|
2016-05-13 08:44:08 -05:00
|
|
|
std::vector< double > sourceData;
|
|
|
|
eclGrid.exportCOORD( sourceData );
|
|
|
|
auto resultData = getErtData< float >( eclKeyword );
|
|
|
|
compareErtData(sourceData, resultData, 1e-6);
|
2016-03-16 04:42:50 -05:00
|
|
|
}
|
|
|
|
else if (keywordName == "ZCORN") {
|
2016-05-13 08:44:08 -05:00
|
|
|
std::vector< double > sourceData;
|
|
|
|
eclGrid.exportZCORN(sourceData);
|
|
|
|
auto resultData = getErtData< float >( eclKeyword );
|
2016-03-16 04:42:50 -05:00
|
|
|
compareErtData(sourceData, resultData, /*percentTolerance=*/1e-6);
|
|
|
|
}
|
|
|
|
else if (keywordName == "ACTNUM") {
|
2016-05-13 08:44:08 -05:00
|
|
|
std::vector< int > sourceData( numCells );
|
|
|
|
eclGrid.exportACTNUM(sourceData);
|
|
|
|
auto resultData = getErtData< int >( eclKeyword );
|
2016-03-16 04:42:50 -05:00
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
if( sourceData.empty() )
|
|
|
|
sourceData.assign( numCells, 1 );
|
2016-03-16 04:42:50 -05:00
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
compareErtData( sourceData, resultData );
|
2016-03-16 04:42:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ecl_kw_free(eclKeyword);
|
|
|
|
}
|
|
|
|
|
|
|
|
fortio_fclose(egridFile);
|
|
|
|
}
|
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
void checkInitFile( const Deck& deck ) {
|
2016-03-16 04:42:50 -05:00
|
|
|
// use ERT directly to inspect the INIT file produced by EclipseWriter
|
|
|
|
auto initFile = fortio_open_reader("FOO.INIT", /*isFormated=*/0, ECL_ENDIAN_FLIP);
|
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
while( auto* eclKeyword = ecl_kw_fread_alloc(initFile) ) {
|
2016-03-16 04:42:50 -05:00
|
|
|
std::string keywordName(ecl_kw_get_header(eclKeyword));
|
|
|
|
|
|
|
|
if (keywordName == "PORO") {
|
2016-05-13 08:44:08 -05:00
|
|
|
const auto &sourceData = deck.getKeyword("PORO").getSIDoubleData();
|
|
|
|
auto resultData = getErtData< float >( eclKeyword );
|
|
|
|
compareErtData(sourceData, resultData, 1e-4);
|
2016-03-16 04:42:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (keywordName == "PERMX") {
|
2016-05-13 08:44:08 -05:00
|
|
|
const auto& sourceData = deck.getKeyword("PERMX").getSIDoubleData();
|
|
|
|
auto resultData = getErtData< float >( eclKeyword );
|
2016-03-16 04:42:50 -05:00
|
|
|
|
|
|
|
// convert the data from ERT from Field to SI units (mD to m^2)
|
|
|
|
for (size_t i = 0; i < resultData.size(); ++i) {
|
|
|
|
resultData[i] *= 9.869233e-16;
|
|
|
|
}
|
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
compareErtData(sourceData, resultData, 1e-4);
|
2016-03-16 04:42:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ecl_kw_free(eclKeyword);
|
|
|
|
}
|
|
|
|
|
|
|
|
fortio_fclose(initFile);
|
|
|
|
}
|
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
void checkRestartFile( int timeStepIdx ) {
|
|
|
|
using ds = data::Solution::key;
|
2016-03-16 04:42:50 -05:00
|
|
|
|
|
|
|
for (int i = 0; i <= timeStepIdx; ++i) {
|
2016-05-13 08:44:08 -05:00
|
|
|
auto sol = createBlackoilState( i, 3 * 3 * 3 );
|
2016-03-16 04:42:50 -05:00
|
|
|
|
|
|
|
// use ERT directly to inspect the restart file produced by EclipseWriter
|
|
|
|
auto rstFile = fortio_open_reader("FOO.UNRST", /*isFormated=*/0, ECL_ENDIAN_FLIP);
|
|
|
|
|
|
|
|
int curSeqnum = -1;
|
2016-05-13 08:44:08 -05:00
|
|
|
while( auto* eclKeyword = ecl_kw_fread_alloc(rstFile) ) {
|
2016-03-16 04:42:50 -05:00
|
|
|
std::string keywordName(ecl_kw_get_header(eclKeyword));
|
|
|
|
|
|
|
|
if (keywordName == "SEQNUM") {
|
|
|
|
curSeqnum = *static_cast<int*>(ecl_kw_iget_ptr(eclKeyword, 0));
|
|
|
|
}
|
|
|
|
if (curSeqnum != i)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (keywordName == "PRESSURE") {
|
2016-05-13 08:44:08 -05:00
|
|
|
const auto resultData = getErtData< float >( eclKeyword );
|
|
|
|
for( auto& x : sol[ ds::PRESSURE ] )
|
|
|
|
x /= Metric::Pressure;
|
2016-03-16 04:42:50 -05:00
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
compareErtData( sol[ ds::PRESSURE ], resultData, 1e-4 );
|
2016-03-16 04:42:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (keywordName == "SWAT") {
|
2016-05-13 08:44:08 -05:00
|
|
|
const auto resultData = getErtData< float >( eclKeyword );
|
|
|
|
compareErtData(sol[ ds::SWAT ], resultData, 1e-4);
|
2016-03-16 04:42:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (keywordName == "SGAS") {
|
2016-05-13 08:44:08 -05:00
|
|
|
const auto resultData = getErtData< float >( eclKeyword );
|
|
|
|
compareErtData( sol[ ds::SGAS ], resultData, 1e-4 );
|
2016-03-16 04:42:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fortio_fclose(rstFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(EclipseWriterIntegration)
|
2016-03-29 07:45:48 -05:00
|
|
|
{
|
2016-04-29 08:45:40 -05:00
|
|
|
|
|
|
|
test_work_area_type * test_area = test_work_area_alloc("TEST_EclipseWriterIntegration");
|
|
|
|
|
2016-03-29 07:45:48 -05:00
|
|
|
const char *deckString =
|
|
|
|
"RUNSPEC\n"
|
|
|
|
"UNIFOUT\n"
|
|
|
|
"OIL\n"
|
|
|
|
"GAS\n"
|
|
|
|
"WATER\n"
|
|
|
|
"METRIC\n"
|
|
|
|
"DIMENS\n"
|
|
|
|
"3 3 3/\n"
|
|
|
|
"GRID\n"
|
2016-06-23 03:44:47 -05:00
|
|
|
"INIT\n"
|
2016-03-29 07:45:48 -05:00
|
|
|
"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";
|
|
|
|
|
2016-05-09 03:34:46 -05:00
|
|
|
auto deck = Parser().parseString( deckString, ParseContext() );
|
2016-05-13 08:44:08 -05:00
|
|
|
auto es = std::make_shared< EclipseState >( Parser::parse( *deck ) );
|
|
|
|
es->getIOConfig()->setBaseName( "FOO" );
|
|
|
|
|
|
|
|
auto& eclGrid = *es->getInputGrid();
|
|
|
|
|
|
|
|
{
|
2016-06-16 06:16:00 -05:00
|
|
|
EclipseWriter eclWriter( es, 3 * 3 * 3, nullptr, NNC());
|
2016-05-13 08:44:08 -05:00
|
|
|
|
|
|
|
auto start_time = util_make_datetime( 0, 0, 0, 10, 10, 2008 );
|
|
|
|
auto first_step = util_make_datetime( 0, 0, 0, 10, 11, 2008 );
|
2016-06-16 06:16:00 -05:00
|
|
|
eclWriter.writeInit();
|
2016-05-13 08:44:08 -05:00
|
|
|
|
|
|
|
data::Wells wells;
|
|
|
|
|
|
|
|
for( int i = 0; i < 5; ++i ) {
|
|
|
|
eclWriter.writeTimeStep( i,
|
|
|
|
first_step - start_time,
|
|
|
|
createBlackoilState( i, 3 * 3 * 3 ),
|
|
|
|
wells, false);
|
|
|
|
|
|
|
|
checkRestartFile( i );
|
|
|
|
|
|
|
|
}
|
2016-03-29 07:45:48 -05:00
|
|
|
}
|
2016-04-29 08:45:40 -05:00
|
|
|
|
2016-05-13 08:44:08 -05:00
|
|
|
checkEgridFile( eclGrid );
|
|
|
|
checkInitFile( *deck );
|
|
|
|
|
2016-04-29 08:45:40 -05:00
|
|
|
test_work_area_free(test_area);
|
2016-03-29 07:45:48 -05:00
|
|
|
}
|