Merge pull request #1904 from joakim-hove/box-global-list

Box global list
This commit is contained in:
Bård Skaflestad
2020-09-03 23:51:08 +02:00
committed by GitHub
3 changed files with 41 additions and 49 deletions

View File

@@ -21,8 +21,9 @@
#ifndef BOX_HPP_
#define BOX_HPP_
#include <vector>
#include <cstddef>
#include <limits>
#include <vector>
namespace Opm {
class DeckRecord;
@@ -31,17 +32,32 @@ namespace Opm {
class Box {
public:
struct cell_index {
std::size_t global_index;
std::size_t active_index;
std::size_t data_index;
cell_index(std::size_t g,std::size_t a, std::size_t d) :
global_index(g),
active_index(a),
data_index(d)
{}
/*
This constructor should is used by the global_index_list() member
which will return a list of *all* the cells in the box. In this
case the active_index will be set to the global_index. This is a
hack to simplify the treatment of global fields in the FieldProps
implementation.
*/
cell_index(std::size_t g, std::size_t d) :
global_index(g),
active_index(g),
data_index(d)
{}
};
Box(const EclipseGrid& grid);
@@ -53,7 +69,7 @@ namespace Opm {
bool isGlobal() const;
size_t getDim(size_t idim) const;
const std::vector<cell_index>& index_list() const;
const std::vector<size_t>& getIndexList() const;
const std::vector<Box::cell_index>& global_index_list() const;
bool equal(const Box& other) const;
@@ -73,8 +89,8 @@ namespace Opm {
size_t m_offset[3];
bool m_isGlobal;
std::vector<size_t> global_index_list;
std::vector<cell_index> m_index_list;
std::vector<cell_index> m_active_index_list;
std::vector<cell_index> m_global_index_list;
int lower(int dim) const;
int upper(int dim) const;

View File

@@ -142,18 +142,19 @@ namespace Opm {
const std::vector<size_t>& Box::getIndexList() const {
return global_index_list;
const std::vector<Box::cell_index>& Box::index_list() const {
return this->m_active_index_list;
}
const std::vector<Box::cell_index>& Box::index_list() const {
return m_index_list;
const std::vector<Box::cell_index>& Box::global_index_list() const {
return this->m_global_index_list;
}
void Box::initIndexList() {
global_index_list.clear();
m_index_list.clear();
m_active_index_list.clear();
m_global_index_list.clear();
size_t ii,ij,ik;
for (ik=0; ik < m_dims[2]; ik++) {
@@ -161,16 +162,16 @@ namespace Opm {
for (ij=0; ij < m_dims[1]; ij++) {
size_t j = ij + m_offset[1];
for (ii=0; ii < m_dims[0]; ii++) {
size_t i = ii + m_offset[0];
size_t g = i * m_stride[0] + j*m_stride[1] + k*m_stride[2];
std::size_t i = ii + m_offset[0];
std::size_t global_index = i * m_stride[0] + j*m_stride[1] + k*m_stride[2];
std::size_t data_index = ii + ij*this->m_dims[0] + ik*this->m_dims[0]*this->m_dims[1];
global_index_list.push_back(g);
if (this->grid.cellActive(g)) {
std::size_t global_index = g;
std::size_t active_index = this->grid.activeIndex(g);
std::size_t data_index = ii + ij*this->m_dims[0] + ik*this->m_dims[0]*this->m_dims[1];
m_index_list.push_back({global_index, active_index, data_index});
if (this->grid.cellActive(global_index)) {
std::size_t active_index = this->grid.activeIndex(global_index);
m_active_index_list.emplace_back(global_index, active_index, data_index);
}
this->m_global_index_list.emplace_back( global_index, data_index );
}
}
}

View File

@@ -40,22 +40,6 @@ BOOST_AUTO_TEST_CASE(CreateBox) {
BOOST_CHECK_EQUAL( 2 , box.getDim(2) );
BOOST_CHECK_THROW( box.getDim(5) , std::invalid_argument);
{
size_t i,j,k;
const std::vector<size_t>& indexList = box.getIndexList();
for (k=0; k < box.getDim(2); k++) {
for (j=0; j < box.getDim(1); j++) {
for (i=0; i < box.getDim(0); i++) {
size_t g = i + j*box.getDim(0) + k*box.getDim(0)*box.getDim(1);
BOOST_CHECK_EQUAL( indexList[g] , g);
}
}
}
}
}
@@ -75,21 +59,6 @@ BOOST_AUTO_TEST_CASE(CreateSubBox) {
Opm::Box subBox2(grid, 1,3,1,4,1,5);
BOOST_CHECK( !subBox2.isGlobal());
BOOST_CHECK_EQUAL( 60U , subBox2.size() );
size_t i,j,k;
size_t d = 0;
const std::vector<size_t>& indexList = subBox2.getIndexList();
for (k=0; k < subBox2.getDim(2); k++) {
for (j=0; j < subBox2.getDim(1); j++) {
for (i=0; i < subBox2.getDim(0); i++) {
size_t g = (i + 1) + (j + 1)*globalBox.getDim(0) + (k + 1)*globalBox.getDim(0)*globalBox.getDim(1);
BOOST_CHECK_EQUAL( indexList[d] , g);
d++;
}
}
}
}
@@ -192,6 +161,12 @@ BOOST_AUTO_TEST_CASE(TestKeywordBox2) {
BOOST_CHECK_EQUAL(p.active_index + 1, p.global_index);
BOOST_CHECK_EQUAL(box.index_list().size() + 1, grid.getCartesianSize());
const auto& global_index_list = box.global_index_list();
BOOST_CHECK_EQUAL( global_index_list.size(), grid.getCartesianSize());
const auto& c0 = global_index_list[0];
BOOST_CHECK_EQUAL(c0.global_index, 0);
BOOST_CHECK_EQUAL(c0.active_index, c0.global_index);
BOOST_CHECK_EQUAL(c0.data_index, 0);
Opm::Box box2(grid,9,9,9,9,0,9);
const auto& il = box2.index_list();