Merge pull request #2786 from daniepin/completed_cells-refactor

Refactored ScheduleGrid to use public struct cell
This commit is contained in:
Joakim Hove
2021-10-30 17:10:32 +02:00
committed by GitHub
7 changed files with 17 additions and 50 deletions

View File

@@ -30,16 +30,9 @@ public:
ScheduleGrid(const EclipseGrid& ecl_grid, CompletedCells& completed_cells);
explicit ScheduleGrid(CompletedCells& completed_cells);
std::size_t getActiveIndex(std::size_t i, std::size_t j, std::size_t k) const;
bool isCellActive(std::size_t i, std::size_t j, std::size_t k) const;
std::size_t getGlobalIndex(std::size_t i, std::size_t j, std::size_t k) const;
double getCellDepth(std::size_t i, std::size_t j, std::size_t k) const;
std::array<double, 3> getCellDimensions(std::size_t i, std::size_t j, std::size_t k) const;
private:
const CompletedCells::Cell& get_cell(std::size_t i, std::size_t j, std::size_t k) const;
private:
const EclipseGrid* grid{nullptr};
CompletedCells& cells;
};

View File

@@ -281,8 +281,7 @@ namespace {
// will decide the segment number based on the distance in a process later.
}
if (!record.getItem<ParserKeywords::COMPSEGS::END_IJK>().hasValue(0)) { // only one compsegs
if (grid.isCellActive(I, J, K)) {
if (grid.get_cell(I, J, K).active_index.has_value()) {
std::size_t seqIndex = compsegs.size();
compsegs.emplace_back( I, J, K,
branch,
@@ -323,7 +322,7 @@ namespace {
const int i = compseg.m_i;
const int j = compseg.m_j;
const int k = compseg.m_k;
if (grid.isCellActive(i, j, k)) {
if (grid.get_cell(i, j, k).active_index.has_value()) {
Connection& connection = new_connection_set.getFromIJK(i, j, k);
connection.updateSegment(compseg.segment_number,
compseg.center_depth,

View File

@@ -30,32 +30,6 @@ Opm::ScheduleGrid::ScheduleGrid(Opm::CompletedCells& completed_cells)
: cells(completed_cells)
{}
std::size_t Opm::ScheduleGrid::getActiveIndex(std::size_t i, std::size_t j, std::size_t k) const {
const auto& cell = this->get_cell(i,j,k);
return cell.active_index.value();
}
bool Opm::ScheduleGrid::isCellActive(std::size_t i, std::size_t j, std::size_t k) const {
const auto& cell = this->get_cell(i,j,k);
return cell.active_index.has_value();
}
std::size_t Opm::ScheduleGrid::getGlobalIndex(std::size_t i, std::size_t j, std::size_t k) const {
const auto& cell = this->get_cell(i,j,k);
return cell.global_index;
}
double Opm::ScheduleGrid::getCellDepth(std::size_t i, std::size_t j, std::size_t k) const {
const auto& cell = this->get_cell(i,j,k);
return cell.depth;
}
std::array<double, 3> Opm::ScheduleGrid::getCellDimensions(std::size_t i, std::size_t j, std::size_t k) const {
const auto& cell = this->get_cell(i,j,k);
return cell.dimensions;
}
const Opm::CompletedCells::Cell& Opm::ScheduleGrid::get_cell(std::size_t i, std::size_t j, std::size_t k) const {
if (this->grid) {
auto [valid, cell] = this->cells.try_get(i,j,k);

View File

@@ -94,14 +94,14 @@ Connection::Connection(const RestartIO::RstConnection& rst_connection, const Sch
m_skin_factor(rst_connection.skin_factor),
ijk(rst_connection.ijk),
m_ctfkind(rst_connection.cf_kind),
m_global_index(grid.getGlobalIndex(this->ijk[0], this->ijk[1], this->ijk[2])),
m_global_index(grid.get_cell(this->ijk[0], this->ijk[1], this->ijk[2]).global_index),
m_sort_value(rst_connection.rst_index),
m_defaultSatTabId(defaultSatTabId),
segment_number(rst_connection.segment)
{
if (this->m_defaultSatTabId) {
const auto& satnum = fp.get_int("SATNUM");
auto active_index = grid.getActiveIndex(this->ijk[0], this->ijk[1], this->ijk[2]);
auto active_index = grid.get_cell(this->ijk[0], this->ijk[1], this->ijk[2]).active_index.value();
this->sat_tableId = satnum[active_index];
}
if (this->segment_number > 0)

View File

@@ -693,7 +693,7 @@ bool Well::updateConnections(std::shared_ptr<WellConnections> connections_arg, c
bool update = this->updateConnections(connections_arg, false);
if (this->pvt_table == 0 && !this->connections->empty()) {
const auto& lowest = this->connections->lowest();
auto active_index = grid.getActiveIndex(lowest.getI(), lowest.getJ(), lowest.getK());
auto active_index = grid.get_cell(lowest.getI(), lowest.getJ(), lowest.getK()).active_index.value();
this->pvt_table = pvtnum[active_index];
update = true;
}

View File

@@ -327,7 +327,8 @@ inline std::array< size_t, 3> directionIndices(const Opm::Connection::Direction
rw = 0.5*unit::feet;
for (int k = K1; k <= K2; k++) {
if (!grid.isCellActive(I, J, k)) {
const CompletedCells::Cell& cell = grid.get_cell(I, J, k);
if (!cell.active_index.has_value()) {
auto msg = fmt::format("Problem with COMPDAT keyword\n"
"In {} line {}\n"
"The cell ({},{},{}) in well {} is not active and the connection will be ignored", location.filename, location.lineno, I,J,k, wname);
@@ -335,7 +336,7 @@ inline std::array< size_t, 3> directionIndices(const Opm::Connection::Direction
continue;
}
size_t active_index = grid.getActiveIndex(I,J,k);
size_t active_index = cell.active_index.value();
double CF = -1;
double Kh = -1;
double r0 = -1;
@@ -360,7 +361,7 @@ inline std::array< size_t, 3> directionIndices(const Opm::Connection::Direction
// Angle of completion exposed to flow. We assume centre
// placement so there's complete exposure (= 2\pi).
const double angle = 6.2831853071795864769252867665590057683943387987502116419498;
std::array<double,3> cell_size = grid.getCellDimensions(I,J,k);
std::array<double,3> cell_size = cell.dimensions;
const auto& D = effectiveExtent(direction, ntg[active_index], cell_size);
/* We start with the absolute happy path; both CF and Kh are explicitly given in the deck. */
@@ -407,8 +408,8 @@ inline std::array< size_t, 3> directionIndices(const Opm::Connection::Direction
if (prev == this->m_connections.end()) {
std::size_t noConn = this->m_connections.size();
this->addConnection(I,J,k,
grid.getGlobalIndex(I,J,k),
grid.getCellDepth( I,J,k ),
cell.global_index,
cell.depth,
state,
CF,
Kh,
@@ -426,9 +427,9 @@ inline std::array< size_t, 3> directionIndices(const Opm::Connection::Direction
std::size_t css_ind = prev->sort_value();
int conSegNo = prev->segment();
const auto& perf_range = prev->perf_range();
double depth = grid.getCellDepth(I,J,k);
double depth = cell.depth;
*prev = Connection(I,J,k,
grid.getGlobalIndex(I,J,k),
cell.global_index,
prev->complnum(),
depth,
state,

View File

@@ -4813,13 +4813,13 @@ BOOST_AUTO_TEST_CASE(TestScheduleGrid) {
{
ScheduleGrid sched_grid(grid, cells);
auto depth = sched_grid.getCellDepth(1,1,1);
auto depth = sched_grid.get_cell(1,1,1).depth;
BOOST_CHECK_EQUAL(depth, 1.50);
}
{
ScheduleGrid sched_grid(cells);
auto depth = sched_grid.getCellDepth(1,1,1);
auto depth = sched_grid.get_cell(1,1,1).depth;
BOOST_CHECK_EQUAL(depth, 1.50);
BOOST_CHECK_THROW(sched_grid.getCellDepth(2,2,2), std::exception);
BOOST_CHECK_THROW(sched_grid.get_cell(2,2,2), std::exception);
}
}