Merge pull request #268 from joakim-hove/EclipseGrid-reset-actnum

Eclipse grid reset actnum
This commit is contained in:
Joakim Hove 2014-07-16 09:48:01 +02:00
commit b41e66594e
3 changed files with 95 additions and 1 deletions

View File

@ -30,6 +30,18 @@
#include <ert/ecl/ecl_grid.h>
namespace Opm {
/**
Will create an EclipseGrid instance based on an existing
GRID/EGRID file.
*/
EclipseGrid::EclipseGrid(const std::string& filename ) {
ecl_grid_type * c_ptr = ecl_grid_load_case( filename.c_str() );
if (c_ptr)
m_grid.reset( c_ptr , ecl_grid_free );
else
throw std::invalid_argument("Could not load grid from binary file: " + filename);
}
EclipseGrid::EclipseGrid(std::shared_ptr<const RUNSPECSection> runspecSection, std::shared_ptr<const GRIDSection> gridSection) {
if (runspecSection->hasKeyword("DIMENS")) {
@ -372,6 +384,17 @@ namespace Opm {
ecl_grid_init_zcorn_data_double( m_grid.get() , zcorn.data() );
}
void EclipseGrid::resetACTNUM( const int * actnum) {
ecl_grid_reset_actnum( m_grid.get() , actnum );
}
void EclipseGrid::fwriteEGRID( const std::string& filename ) {
ecl_grid_fwrite_EGRID( m_grid.get() , filename.c_str() );
}
}

View File

@ -31,6 +31,7 @@ namespace Opm {
class EclipseGrid {
public:
EclipseGrid(const std::string& filename);
EclipseGrid(std::shared_ptr<const RUNSPECSection> runspecSection, std::shared_ptr<const GRIDSection> gridSection);
static bool hasCornerPointKeywords(std::shared_ptr<const GRIDSection> gridSection);
@ -54,7 +55,9 @@ namespace Opm {
void exportCOORD( std::vector<double>& coord) const;
void exportZCORN( std::vector<double>& zcorn) const;
void exportACTNUM( std::vector<int>& actnum) const;
void resetACTNUM( const int * actnum);
bool equal(const EclipseGrid& other) const;
void fwriteEGRID( const std::string& filename );
private:
std::shared_ptr<ecl_grid_type> m_grid;

View File

@ -20,6 +20,7 @@
#include <stdexcept>
#include <iostream>
#include <boost/filesystem.hpp>
#include <cstdio>
#define BOOST_TEST_MODULE EclipseGridTests
#include <boost/test/unit_test.hpp>
@ -500,6 +501,73 @@ BOOST_AUTO_TEST_CASE(CornerPointSizeMismatchACTNUM) {
Opm::DeckConstPtr deck = parser->parseString(deckData) ;
std::shared_ptr<Opm::RUNSPECSection> runspecSection(new Opm::RUNSPECSection(deck) );
std::shared_ptr<Opm::GRIDSection> gridSection(new Opm::GRIDSection(deck) );
Opm::DeckKeywordConstPtr zcorn = gridSection->getKeyword("ZCORN");
BOOST_CHECK_THROW(Opm::EclipseGrid( runspecSection , gridSection ) , std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(ResetACTNUM) {
const char *deckData =
"RUNSPEC\n"
"\n"
"DIMENS\n"
" 10 10 10 /\n"
"GRID\n"
"COORD\n"
" 726*1 / \n"
"ZCORN \n"
" 8000*1 / \n"
"EDIT\n"
"\n";
Opm::ParserPtr parser(new Opm::Parser());
Opm::DeckConstPtr deck = parser->parseString(deckData) ;
std::shared_ptr<Opm::RUNSPECSection> runspecSection(new Opm::RUNSPECSection(deck) );
std::shared_ptr<Opm::GRIDSection> gridSection(new Opm::GRIDSection(deck) );
Opm::EclipseGrid grid(runspecSection , gridSection );
BOOST_CHECK_EQUAL( 1000U , grid.getNumActive());
std::vector<int> actnum(1000);
actnum[0] = 1;
grid.resetACTNUM( actnum.data() );
BOOST_CHECK_EQUAL( 1U , grid.getNumActive() );
grid.resetACTNUM( NULL );
BOOST_CHECK_EQUAL( 1000U , grid.getNumActive() );
}
BOOST_AUTO_TEST_CASE(LoadFromBinary) {
BOOST_CHECK_THROW(Opm::EclipseGrid( "No/does/not/exist" ) , std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(Fwrite) {
const char *deckData =
"RUNSPEC\n"
"\n"
"DIMENS\n"
" 10 10 10 /\n"
"GRID\n"
"COORD\n"
" 726*1 / \n"
"ZCORN \n"
" 8000*1 / \n"
"EDIT\n"
"\n";
Opm::ParserPtr parser(new Opm::Parser());
Opm::DeckConstPtr deck = parser->parseString(deckData) ;
std::shared_ptr<Opm::RUNSPECSection> runspecSection(new Opm::RUNSPECSection(deck) );
std::shared_ptr<Opm::GRIDSection> gridSection(new Opm::GRIDSection(deck) );
Opm::EclipseGrid grid1(runspecSection , gridSection );
grid1.fwriteEGRID( "TEST.EGRID" );
Opm::EclipseGrid grid2( "TEST.EGRID" );
BOOST_CHECK( grid1.equal( grid2 ));
remove("TEST.EGRID");
}