Added DEPTHZ as alternative to TOPS.

This commit is contained in:
Joakim Hove
2014-04-27 23:17:50 +02:00
parent 3718df3972
commit 7bf588a166
3 changed files with 209 additions and 10 deletions

View File

@@ -20,6 +20,8 @@
#include <iostream>
#include <boost/lexical_cast.hpp>
#include <opm/parser/eclipse/Deck/Section.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
@@ -47,6 +49,10 @@ namespace Opm {
throw std::invalid_argument("The RUNSPEC section must have the DIMENS keyword with grid dimensions");
}
bool EclipseGrid::equal(const EclipseGrid& other) const {
return ecl_grid_compare( m_grid.get() , other.m_grid.get() , true , false );
}
int EclipseGrid::getNumActive( ) const {
return ecl_grid_get_nactive( m_grid.get() );
@@ -81,19 +87,19 @@ namespace Opm {
{
DeckKeywordConstPtr ZCORNKeyWord = gridSection->getKeyword("ZCORN");
if (ZCORNKeyWord->getDataSize() != 8 * nx*ny*nz)
if (ZCORNKeyWord->getDataSize() != static_cast<size_t>(8*nx*ny*nz))
throw std::invalid_argument("Wrong size in ZCORN keyword - expected 8*x*ny*nz = " + 8*nx*ny*nz);
}
{
DeckKeywordConstPtr COORDKeyWord = gridSection->getKeyword("COORD");
if (COORDKeyWord->getDataSize() != 6*(nx + 1)*(ny + 1))
if (COORDKeyWord->getDataSize() != static_cast<size_t>(6*(nx + 1)*(ny + 1)))
throw std::invalid_argument("Wrong size in COORD keyword - expected 6*(nx + 1)*(ny + 1) = " + 6*(nx + 1)*(ny + 1));
}
if (gridSection->hasKeyword("ACTNUM")) {
DeckKeywordConstPtr ACTNUMKeyWord = gridSection->getKeyword("ACTNUM");
if (ACTNUMKeyWord->getDataSize() != nx*ny*nz)
if (ACTNUMKeyWord->getDataSize() != static_cast<size_t>(nx*ny*nz))
throw std::invalid_argument("Wrong size in ACTNUM keyword - expected 8*x*ny*nz = " + nx*ny*nz);
}
}
@@ -151,8 +157,25 @@ namespace Opm {
}
bool EclipseGrid::hasCartesianKeywords(std::shared_ptr<const GRIDSection> gridSection) {
if (hasDVDEPTHZKeywords( gridSection ))
return true;
else
return hasDTOPSKeywords(gridSection);
}
bool EclipseGrid::hasDVDEPTHZKeywords(std::shared_ptr<const GRIDSection> gridSection) {
if (gridSection->hasKeyword("DXV") &&
gridSection->hasKeyword("DYV") &&
gridSection->hasKeyword("DZV") &&
gridSection->hasKeyword("DEPTHZ"))
return true;
else
return false;
}
bool EclipseGrid::hasDTOPSKeywords(std::shared_ptr<const GRIDSection> gridSection) {
if ((gridSection->hasKeyword("DX") || gridSection->hasKeyword("DXV")) &&
(gridSection->hasKeyword("DY") || gridSection->hasKeyword("DYV")) &&
(gridSection->hasKeyword("DZ") || gridSection->hasKeyword("DZV")) &&
@@ -164,6 +187,36 @@ namespace Opm {
void EclipseGrid::initCartesianGrid(const std::vector<int>& dims , std::shared_ptr<const GRIDSection> gridSection) {
if (hasDVDEPTHZKeywords( gridSection ))
initDVDEPTHZGrid( dims , gridSection );
else if (hasDTOPSKeywords(gridSection))
initDTOPSGrid( dims ,gridSection );
else
throw std::invalid_argument("Tried to initialize cartesian grid without all required keywords");
}
void EclipseGrid::assertVectorSize(const std::vector<double>& vector , size_t expectedSize , const std::string& vectorName) {
if (vector.size() != expectedSize)
throw std::invalid_argument("Wrong size for keyword: " + vectorName + ". Expected: " + boost::lexical_cast<std::string>(expectedSize) + " got: " + boost::lexical_cast<std::string>(vector.size()));
}
void EclipseGrid::initDVDEPTHZGrid(const std::vector<int>& dims , std::shared_ptr<const GRIDSection> gridSection) {
const std::vector<double>& DXV = gridSection->getKeyword("DXV")->getSIDoubleData();
const std::vector<double>& DYV = gridSection->getKeyword("DYV")->getSIDoubleData();
const std::vector<double>& DZV = gridSection->getKeyword("DZV")->getSIDoubleData();
const std::vector<double>& DEPTHZ = gridSection->getKeyword("DEPTHZ")->getSIDoubleData();
assertVectorSize( DEPTHZ , static_cast<size_t>( (dims[0] + 1)*(dims[1] +1 )) , "DEPTHZ");
assertVectorSize( DXV , static_cast<size_t>( dims[0] ) , "DXV");
assertVectorSize( DYV , static_cast<size_t>( dims[1] ) , "DYV");
assertVectorSize( DZV , static_cast<size_t>( dims[2] ) , "DZV");
m_grid.reset( ecl_grid_alloc_dxv_dyv_dzv_depthz( dims[0] , dims[1] , dims[2] , DXV.data() , DYV.data() , DZV.data() , DEPTHZ.data() , NULL ) , ecl_grid_free);
}
void EclipseGrid::initDTOPSGrid(const std::vector<int>& dims , std::shared_ptr<const GRIDSection> gridSection) {
std::vector<double> DX = createDVector( dims , 0 , "DX" , "DXV" , gridSection);
std::vector<double> DY = createDVector( dims , 1 , "DY" , "DYV" , gridSection);
std::vector<double> DZ = createDVector( dims , 2 , "DZ" , "DZV" , gridSection);
@@ -171,7 +224,6 @@ namespace Opm {
m_grid.reset( ecl_grid_alloc_dx_dy_dz_tops( dims[0] , dims[1] , dims[2] , DX.data() , DY.data() , DZ.data() , TOPS.data() , NULL ) , ecl_grid_free);
}
std::vector<double> EclipseGrid::createTOPSVector(const std::vector<int>& dims , const std::vector<double>& DZ , std::shared_ptr<const GRIDSection> gridSection) {

View File

@@ -46,10 +46,16 @@ namespace Opm {
void exportCOORD( std::vector<double>& coord) const;
void exportZCORN( std::vector<double>& zcorn) const;
void exportACTNUM( std::vector<int>& actnum) const;
bool equal(const EclipseGrid& other) const;
private:
std::shared_ptr<ecl_grid_type> m_grid;
void assertCornerPointKeywords( const std::vector<int>& dims , std::shared_ptr<const GRIDSection> gridSection ) const ;
void initDTOPSGrid(const std::vector<int>& dims , std::shared_ptr<const GRIDSection> gridSection);
void initDVDEPTHZGrid(const std::vector<int>& dims , std::shared_ptr<const GRIDSection> gridSection);
static bool hasDVDEPTHZKeywords(std::shared_ptr<const GRIDSection> gridSection);
static bool hasDTOPSKeywords(std::shared_ptr<const GRIDSection> gridSection);
static void assertVectorSize(const std::vector<double>& vector , size_t expectedSize , const std::string& msg);
std::vector<double> createTOPSVector(const std::vector<int>& dims , const std::vector<double>& DZ , std::shared_ptr<const GRIDSection> gridSection);
std::vector<double> createDVector(const std::vector<int>& dims , size_t dim , const std::string& DKey , const std::string& DVKey, std::shared_ptr<const GRIDSection> gridSection);
void scatterDim(const std::vector<int>& dims , size_t dim , const std::vector<double>& DV , std::vector<double>& D);

View File

@@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(CreateMissingDIMENS_throws) {
Opm::DeckPtr createDeck1() {
Opm::DeckPtr createDeckHeaders() {
const char *deckData =
"RUNSPEC\n"
"\n"
@@ -68,7 +68,7 @@ Opm::DeckPtr createDeck1() {
BOOST_AUTO_TEST_CASE(HasGridKeywords) {
Opm::DeckPtr deck = createDeck1();
Opm::DeckPtr deck = createDeckHeaders();
std::shared_ptr<Opm::GRIDSection> gridSection(new Opm::GRIDSection(deck) );
BOOST_CHECK( !Opm::EclipseGrid::hasCornerPointKeywords( gridSection ));
BOOST_CHECK( !Opm::EclipseGrid::hasCartesianKeywords( gridSection ));
@@ -103,11 +103,34 @@ Opm::DeckPtr createCARTDeck() {
"DX\n"
"1000*0.25 /\n"
"DYV\n"
"1000*0.25 /\n"
"10*0.25 /\n"
"DZ\n"
"1000*0.25 /\n"
"TOPS\n"
"1000*0.25 /\n"
"100*0.25 /\n"
"EDIT\n"
"\n";
Opm::ParserPtr parser(new Opm::Parser());
return parser->parseString(deckData) ;
}
Opm::DeckPtr createCARTDeckDEPTHZ() {
const char *deckData =
"RUNSPEC\n"
"\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"
"DEPTHZ\n"
"121*0.25 /\n"
"EDIT\n"
"\n";
@@ -136,6 +159,20 @@ Opm::DeckPtr createCARTInvalidDeck() {
return parser->parseString(deckData) ;
}
BOOST_AUTO_TEST_CASE(DEPTHZ_EQUAL_TOPS) {
Opm::DeckPtr deck1 = createCARTDeck();
Opm::DeckPtr deck2 = createCARTDeckDEPTHZ();
std::shared_ptr<Opm::RUNSPECSection> runspecSection(new Opm::RUNSPECSection(deck1) );
std::shared_ptr<Opm::GRIDSection> gridSection1(new Opm::GRIDSection(deck1) );
std::shared_ptr<Opm::GRIDSection> gridSection2(new Opm::GRIDSection(deck2) );
std::shared_ptr<Opm::EclipseGrid> grid1(new Opm::EclipseGrid( runspecSection , gridSection1 ));
std::shared_ptr<Opm::EclipseGrid> grid2(new Opm::EclipseGrid( runspecSection , gridSection2 ));
BOOST_CHECK( grid1->equal( *(grid2.get()) ));
}
BOOST_AUTO_TEST_CASE(HasCPKeywords) {
@@ -154,6 +191,14 @@ BOOST_AUTO_TEST_CASE(HasCartKeywords) {
}
BOOST_AUTO_TEST_CASE(HasCartKeywordsDEPTHZ) {
Opm::DeckPtr deck = createCARTDeckDEPTHZ();
std::shared_ptr<Opm::GRIDSection> gridSection(new Opm::GRIDSection(deck) );
BOOST_CHECK( !Opm::EclipseGrid::hasCornerPointKeywords( gridSection ));
BOOST_CHECK( Opm::EclipseGrid::hasCartesianKeywords( gridSection ));
}
BOOST_AUTO_TEST_CASE(HasINVALIDCartKeywords) {
Opm::DeckPtr deck = createCARTInvalidDeck();
std::shared_ptr<Opm::GRIDSection> gridSection(new Opm::GRIDSection(deck) );
@@ -163,8 +208,10 @@ BOOST_AUTO_TEST_CASE(HasINVALIDCartKeywords) {
BOOST_AUTO_TEST_CASE(CreateMissingGRID_throws) {
Opm::DeckPtr deck = createDeck1();
Opm::DeckPtr deck = createDeckHeaders();
std::shared_ptr<Opm::RUNSPECSection> runspecSection(new Opm::RUNSPECSection(deck) );
std::shared_ptr<Opm::GRIDSection> gridSection(new Opm::GRIDSection(deck) );
BOOST_CHECK_THROW(new Opm::EclipseGrid( runspecSection , gridSection ) , std::invalid_argument);
@@ -202,6 +249,39 @@ BOOST_AUTO_TEST_CASE(CreateCartesianGRID) {
BOOST_CHECK_THROW(new Opm::EclipseGrid( runspecSection , gridSection ) , std::invalid_argument);
}
Opm::DeckPtr createInvalidDXYZCARTDeckDEPTHZ() {
const char *deckData =
"RUNSPEC\n"
"\n"
"DIMENS\n"
" 10 10 10 /\n"
"GRID\n"
"DX\n"
"100*0.25 /\n"
"DY\n"
"1000*0.25 /\n"
"DZ\n"
"1000*0.25 /\n"
"DEPTHZ\n"
"101*0.25 /\n"
"EDIT\n"
"\n";
Opm::ParserPtr parser(new Opm::Parser());
return parser->parseString(deckData) ;
}
BOOST_AUTO_TEST_CASE(CreateCartesianGRIDDEPTHZ) {
Opm::DeckPtr deck = createInvalidDXYZCARTDeckDEPTHZ();
std::shared_ptr<Opm::RUNSPECSection> runspecSection(new Opm::RUNSPECSection(deck) );
std::shared_ptr<Opm::GRIDSection> gridSection(new Opm::GRIDSection(deck) );
BOOST_CHECK_THROW(new Opm::EclipseGrid( runspecSection , gridSection ) , std::invalid_argument);
}
Opm::DeckPtr createOnlyTopDZCartGrid() {
const char *deckData =
"RUNSPEC\n"
@@ -225,6 +305,67 @@ Opm::DeckPtr createOnlyTopDZCartGrid() {
}
Opm::DeckPtr createInvalidDEPTHZDeck1 () {
const char *deckData =
"RUNSPEC\n"
"\n"
"DIMENS\n"
" 10 5 20 /\n"
"GRID\n"
"DXV\n"
"1000*0.25 /\n"
"DYV\n"
"5*0.25 /\n"
"DZV\n"
"20*0.25 /\n"
"DEPTHZ\n"
"66*0.25 /\n"
"EDIT\n"
"\n";
Opm::ParserPtr parser(new Opm::Parser());
return parser->parseString(deckData) ;
}
BOOST_AUTO_TEST_CASE(CreateCartesianGRIDInvalidDEPTHZ1) {
Opm::DeckPtr deck = createInvalidDEPTHZDeck1();
std::shared_ptr<Opm::RUNSPECSection> runspecSection(new Opm::RUNSPECSection(deck) );
std::shared_ptr<Opm::GRIDSection> gridSection(new Opm::GRIDSection(deck) );
BOOST_CHECK_THROW(new Opm::EclipseGrid( runspecSection , gridSection ) , std::invalid_argument);
}
Opm::DeckPtr createInvalidDEPTHZDeck2 () {
const char *deckData =
"RUNSPEC\n"
"\n"
"DIMENS\n"
" 10 5 20 /\n"
"GRID\n"
"DXV\n"
"10*0.25 /\n"
"DYV\n"
"5*0.25 /\n"
"DZV\n"
"20*0.25 /\n"
"DEPTHZ\n"
"67*0.25 /\n"
"EDIT\n"
"\n";
Opm::ParserPtr parser(new Opm::Parser());
return parser->parseString(deckData) ;
}
BOOST_AUTO_TEST_CASE(CreateCartesianGRIDInvalidDEPTHZ2) {
Opm::DeckPtr deck = createInvalidDEPTHZDeck2();
std::shared_ptr<Opm::RUNSPECSection> runspecSection(new Opm::RUNSPECSection(deck) );
std::shared_ptr<Opm::GRIDSection> gridSection(new Opm::GRIDSection(deck) );
BOOST_CHECK_THROW(new Opm::EclipseGrid( runspecSection , gridSection ) , std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(CreateCartesianGRIDOnlyTopLayerDZ) {
Opm::DeckPtr deck = createOnlyTopDZCartGrid();