RegionMapping<>: Support arbitrary region IDs
This commit introduces a new public method, activeRegions(), that
retrieves those region IDs that contain at least one active cell.
We furthermore extend the cells() method to support lookup of
arbitrary region IDs. Non-active region IDs produce empty cell
ranges.
Intended use case is
for (const auto& reg : rmap.activeRegions()) {
const auto& c = rmap.cells(reg);
// use c
}
This commit is contained in:
@@ -307,10 +307,8 @@ BOOST_AUTO_TEST_CASE (RegMapping)
|
||||
Opm::RegionMapping<> eqlmap(eqlnum);
|
||||
|
||||
PPress ppress(2, PVal(G->number_of_cells, 0));
|
||||
for (int r = 0, e = eqlmap.numRegions(); r != e; ++r)
|
||||
{
|
||||
const Opm::RegionMapping<>::CellRange&
|
||||
rng = eqlmap.cells(r);
|
||||
for (const auto& r : eqlmap.activeRegions()) {
|
||||
const auto& rng = eqlmap.cells(r);
|
||||
|
||||
const int rno = r;
|
||||
const double grav = 10;
|
||||
@@ -318,14 +316,13 @@ BOOST_AUTO_TEST_CASE (RegMapping)
|
||||
Opm::Equil::phasePressures(*G, region[rno], rng, grav);
|
||||
|
||||
PVal::size_type i = 0;
|
||||
for (Opm::RegionMapping<>::CellRange::const_iterator
|
||||
c = rng.begin(), ce = rng.end();
|
||||
c != ce; ++c, ++i)
|
||||
{
|
||||
for (const auto& c : rng) {
|
||||
assert (i < p[0].size());
|
||||
|
||||
ppress[0][*c] = p[0][i];
|
||||
ppress[1][*c] = p[1][i];
|
||||
ppress[0][c] = p[0][i];
|
||||
ppress[1][c] = p[1][i];
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,42 +26,130 @@
|
||||
|
||||
#define NVERBOSE // Suppress own messages when throw()ing
|
||||
|
||||
#define BOOST_TEST_MODULE UnitsTest
|
||||
#define BOOST_TEST_MODULE RegionMapping
|
||||
|
||||
#include <opm/core/utility/platform_dependent/disable_warnings.h>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/floating_point_comparison.hpp>
|
||||
#include <opm/core/utility/platform_dependent/reenable_warnings.h>
|
||||
|
||||
/* --- our own headers --- */
|
||||
|
||||
#include <opm/core/utility/RegionMapping.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE ()
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE (RegionMapping)
|
||||
BOOST_AUTO_TEST_CASE (Forward)
|
||||
{
|
||||
// 0 1 2 3 4 5 6 7 8
|
||||
std::vector<int> regions = { 2, 5, 2, 4, 2, 7, 6, 3, 6 };
|
||||
|
||||
Opm::RegionMapping<> rm(regions);
|
||||
for (size_t i = 0; i < regions.size(); ++i) {
|
||||
|
||||
for (decltype(regions.size()) i = 0, n = regions.size(); i < n; ++i) {
|
||||
BOOST_CHECK_EQUAL(rm.region(i), regions[i]);
|
||||
}
|
||||
std::vector<int> region_ids = { 2, 3, 4, 5, 6, 7 };
|
||||
std::vector< std::vector<int> > region_cells = { { 0, 2, 4 }, { 7 }, { 3 }, { 1 }, { 6, 8 }, { 5 } };
|
||||
BOOST_REQUIRE_EQUAL(rm.numRegions(), region_ids.size());
|
||||
for (size_t i = 0; i < region_ids.size(); ++i) {
|
||||
auto cells = rm.cells(region_ids[i]);
|
||||
BOOST_REQUIRE_EQUAL(std::distance(cells.begin(), cells.end()), region_cells[i].size());
|
||||
size_t count = 0;
|
||||
for (auto iter = cells.begin(); iter != cells.end(); ++iter, ++count) {
|
||||
BOOST_CHECK_EQUAL(*iter, region_cells[i][count]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE (ActiveRegions)
|
||||
{
|
||||
// 0 1 2 3 4 5 6 7 8
|
||||
std::vector<int> regions = { 2, 5, 2, 4, 2, 7, 6, 3, 6 };
|
||||
|
||||
Opm::RegionMapping<> rm(regions);
|
||||
|
||||
std::vector<int> region_ids = { 2, 3, 4, 5, 6, 7 };
|
||||
|
||||
auto active = [®ion_ids](const int reg)
|
||||
{
|
||||
auto b = region_ids.begin();
|
||||
auto e = region_ids.end();
|
||||
|
||||
return std::find(b, e, reg) != e;
|
||||
};
|
||||
|
||||
BOOST_CHECK_EQUAL(rm.activeRegions().size(), region_ids.size());
|
||||
|
||||
for (const auto& reg : rm.activeRegions()) {
|
||||
BOOST_CHECK(active(reg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE (Consecutive)
|
||||
{
|
||||
using RegionCells = std::map<int, std::vector<int>>;
|
||||
|
||||
// 0 1 2 3 4 5 6 7 8
|
||||
std::vector<int> regions = { 2, 5, 2, 4, 2, 7, 6, 3, 6 };
|
||||
|
||||
Opm::RegionMapping<> rm(regions);
|
||||
|
||||
std::vector<int> region_ids = { 2, 3, 4, 5, 6, 7 };
|
||||
RegionCells region_cells;
|
||||
{
|
||||
using VT = RegionCells::value_type;
|
||||
|
||||
region_cells.insert(VT(2, { 0, 2, 4 }));
|
||||
region_cells.insert(VT(3, { 7 }));
|
||||
region_cells.insert(VT(4, { 3 }));
|
||||
region_cells.insert(VT(5, { 1 }));
|
||||
region_cells.insert(VT(6, { 6, 8 }));
|
||||
region_cells.insert(VT(7, { 5 }));
|
||||
}
|
||||
|
||||
for (const auto& reg : region_ids) {
|
||||
const auto& cells = rm.cells(reg);
|
||||
const auto& expect = region_cells[reg];
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(cells .begin(), cells .end(),
|
||||
expect.begin(), expect.end());
|
||||
}
|
||||
|
||||
// Verify that there are no cells in unused regions 0 and 1.
|
||||
for (const auto& r : { 0, 1 }) {
|
||||
BOOST_CHECK(rm.cells(r).empty());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE (NonConsecutive)
|
||||
{
|
||||
using RegionCells = std::map<int, std::vector<int>>;
|
||||
|
||||
// 0 1 2 3 4 5 6 7 8
|
||||
std::vector<int> regions = { 2, 4, 2, 4, 2, 7, 6, 3, 6 };
|
||||
|
||||
Opm::RegionMapping<> rm(regions);
|
||||
|
||||
std::vector<int> region_ids = { 2, 3, 4, 6, 7 };
|
||||
RegionCells region_cells;
|
||||
{
|
||||
using VT = RegionCells::value_type;
|
||||
|
||||
region_cells.insert(VT(2, { 0, 2, 4 }));
|
||||
region_cells.insert(VT(3, { 7 }));
|
||||
region_cells.insert(VT(4, { 1, 3 }));
|
||||
region_cells.insert(VT(6, { 6, 8 }));
|
||||
region_cells.insert(VT(7, { 5 }));
|
||||
}
|
||||
|
||||
for (const auto& reg : region_ids) {
|
||||
const auto& cells = rm.cells(reg);
|
||||
const auto& expect = region_cells[reg];
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(cells .begin(), cells .end(),
|
||||
expect.begin(), expect.end());
|
||||
}
|
||||
|
||||
// Verify that there are no cells in unused regions 0, 1, and 5.
|
||||
for (const auto& r : { 0, 1, 5 }) {
|
||||
BOOST_CHECK(rm.cells(r).empty());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user