Merge pull request #817 from joakim-hove/eclipsegrid-copy

EclipseGrid copy constructor.
This commit is contained in:
Joakim Hove 2016-05-28 08:06:14 +02:00
commit a6e9f7a3b0
4 changed files with 74 additions and 25 deletions

View File

@ -114,7 +114,7 @@ namespace Opm {
} }
EclipseGridPtr EclipseState::getInputGridCopy() const { EclipseGridPtr EclipseState::getInputGridCopy() const {
return std::make_shared<EclipseGrid>( m_inputGrid->c_ptr() ); return std::make_shared<EclipseGrid>( *m_inputGrid );
} }
const SummaryConfig& EclipseState::getSummaryConfig() const { const SummaryConfig& EclipseState::getSummaryConfig() const {
@ -129,7 +129,7 @@ namespace Opm {
return m_messageContainer; return m_messageContainer;
} }
MessageContainer& EclipseState::getMessageContainer() { MessageContainer& EclipseState::getMessageContainer() {
return m_messageContainer; return m_messageContainer;
} }

View File

@ -65,18 +65,21 @@ namespace Opm {
m_nz = static_cast<size_t>( ecl_grid_get_nz( c_ptr() )); m_nz = static_cast<size_t>( ecl_grid_get_nz( c_ptr() ));
} }
EclipseGrid::EclipseGrid(const ecl_grid_type * src_ptr) /* Copy constructor */
: m_minpvValue(0), EclipseGrid::EclipseGrid(const EclipseGrid& src)
m_minpvMode(MinpvMode::ModeEnum::Inactive), : m_minpvValue( src.m_minpvValue ),
m_pinch("PINCH"), m_minpvMode( src.m_minpvMode ),
m_pinchoutMode(PinchMode::ModeEnum::TOPBOT), m_pinch( src.m_pinch ),
m_multzMode(PinchMode::ModeEnum::TOP) m_pinchoutMode( src.m_pinchoutMode ),
m_multzMode( src.m_multzMode ),
m_nx( src.m_nx ),
m_ny( src.m_ny ),
m_nz( src.m_nz ),
m_messages( src.m_messages )
{ {
m_grid.reset( ecl_grid_alloc_copy( src_ptr ) ); if (src.hasCellInfo())
m_grid.reset( ecl_grid_alloc_copy( src.c_ptr() ) );
m_nx = static_cast<size_t>( ecl_grid_get_nx( c_ptr() ));
m_ny = static_cast<size_t>( ecl_grid_get_ny( c_ptr() ));
m_nz = static_cast<size_t>( ecl_grid_get_nz( c_ptr() ));
} }
/* /*
@ -254,6 +257,23 @@ namespace Opm {
} }
size_t EclipseGrid::activeIndex(size_t i, size_t j, size_t k) const {
return activeIndex( getGlobalIndex( i,j,k ));
}
size_t EclipseGrid::activeIndex(size_t globalIndex) const {
assertCellInfo();
{
int active_index = ecl_grid_get_active_index1( m_grid.get() , globalIndex );
if (active_index < 0)
throw std::invalid_argument("Input argument does not correspond to an active cell");
return static_cast<size_t>( active_index );
}
}
size_t EclipseGrid::getNX( ) const { size_t EclipseGrid::getNX( ) const {
return m_nx; return m_nx;

View File

@ -71,7 +71,7 @@ namespace Opm {
class EclipseGrid { class EclipseGrid {
public: public:
explicit EclipseGrid(const std::string& filename); explicit EclipseGrid(const std::string& filename);
explicit EclipseGrid(const ecl_grid_type * src_ptr); explicit EclipseGrid(const EclipseGrid& srcGrid);
explicit EclipseGrid(size_t nx, size_t ny, size_t nz, explicit EclipseGrid(size_t nx, size_t ny, size_t nz,
double dx = 1.0, double dy = 1.0, double dz = 1.0); double dx = 1.0, double dy = 1.0, double dz = 1.0);
@ -99,6 +99,16 @@ namespace Opm {
bool hasCellInfo() const; bool hasCellInfo() const;
/// The activeIndex methods will return from (i,j,k) or g,
/// where g \in [0,nx*n*nz) to the corresponding active index
/// in the range [0,numActive). Observe that if the input
/// argument corresponds to a cell which is not active an
/// exception will be raised - check with cellActive() first
/// if that is a possibillity.
size_t activeIndex(size_t i, size_t j, size_t k) const;
size_t activeIndex(size_t globalIndex) const;
size_t getGlobalIndex(size_t i, size_t j, size_t k) const; size_t getGlobalIndex(size_t i, size_t j, size_t k) const;
std::array<int, 3> getIJK(size_t globalIndex) const; std::array<int, 3> getIJK(size_t globalIndex) const;
void assertGlobalIndex(size_t globalIndex) const; void assertGlobalIndex(size_t globalIndex) const;

View File

@ -901,19 +901,34 @@ BOOST_AUTO_TEST_CASE(GridBoxActnum) {
BOOST_CHECK_EQUAL(es.getInputGrid()->getNumActive(), active); BOOST_CHECK_EQUAL(es.getInputGrid()->getNumActive(), active);
for (size_t x = 0; x < 10; x++) { {
for (size_t y = 0; y < 10; y++) { size_t active_index = 0;
for (size_t z = 0; z < 10; z++) { // NB: The implementation of this test actually assumes that
if (z == 0) // the loops are running with z as the outer and x as the
BOOST_CHECK(!grid->cellActive(x, y, z)); // inner direction.
else if (x >= 4 && x <= 6 && y >= 4 && y <= 6 && z >= 4 && z <= 6) for (size_t z = 0; z < grid->getNZ(); z++) {
BOOST_CHECK(!grid->cellActive(x, y, z)); for (size_t y = 0; y < grid->getNY(); y++) {
else if (x >= 5 && x <= 7 && y >= 5 && y <= 7 && z >= 5 && z <= 7) for (size_t x = 0; x < grid->getNX(); x++) {
BOOST_CHECK(!grid->cellActive(x, y, z)); if (z == 0)
else BOOST_CHECK(!grid->cellActive(x, y, z));
BOOST_CHECK(grid->cellActive(x, y, z)); else if (x >= 4 && x <= 6 && y >= 4 && y <= 6 && z >= 4 && z <= 6)
BOOST_CHECK(!grid->cellActive(x, y, z));
else if (x >= 5 && x <= 7 && y >= 5 && y <= 7 && z >= 5 && z <= 7)
BOOST_CHECK(!grid->cellActive(x, y, z));
else {
size_t g = grid->getGlobalIndex( x,y,z );
BOOST_CHECK(grid->cellActive(x, y, z));
BOOST_CHECK_EQUAL( grid->activeIndex(x,y,z) , active_index );
BOOST_CHECK_EQUAL( grid->activeIndex(g) , active_index );
active_index++;
}
}
} }
} }
BOOST_CHECK_THROW( grid->activeIndex(0,0,0) , std::invalid_argument );
} }
} }
@ -923,12 +938,16 @@ BOOST_AUTO_TEST_CASE(GridActnumVia3D) {
Opm::EclipseState es(deck, Opm::ParseContext()); Opm::EclipseState es(deck, Opm::ParseContext());
auto ep = es.get3DProperties(); auto ep = es.get3DProperties();
auto grid = es.getInputGrid(); auto grid = es.getInputGrid();
Opm::EclipseGrid grid2( *grid );
BOOST_CHECK_NO_THROW(ep.getIntGridProperty("ACTNUM")); BOOST_CHECK_NO_THROW(ep.getIntGridProperty("ACTNUM"));
BOOST_CHECK_NO_THROW(grid->getNumActive()); BOOST_CHECK_NO_THROW(grid->getNumActive());
BOOST_CHECK(grid->hasCellInfo()); BOOST_CHECK(grid->hasCellInfo());
BOOST_CHECK_EQUAL(grid->getNumActive(), 2 * 2 * 2 - 1); BOOST_CHECK_EQUAL(grid->getNumActive(), 2 * 2 * 2 - 1);
BOOST_CHECK_NO_THROW(grid2.getNumActive());
BOOST_CHECK(grid2.hasCellInfo());
BOOST_CHECK_EQUAL(grid2.getNumActive(), 2 * 2 * 2 - 1);
} }
BOOST_AUTO_TEST_CASE(GridActnumViaState) { BOOST_AUTO_TEST_CASE(GridActnumViaState) {