ActiveIndexByColumn: Remove 'build' Method
Do construction work in constructor instead. Suggested by: [at]joakim-hove
This commit is contained in:
parent
b6b81462d2
commit
6d18b3b7e6
@ -46,9 +46,9 @@ public:
|
||||
/// \param[in] cartDims Model's Cartesian dimensions.
|
||||
/// \param[in] getIJK Call-back routine for retrieving the Cartesian
|
||||
/// (I,J,K) tuple of an active cell index.
|
||||
void buildMappingTables(const std::size_t numActive,
|
||||
const std::array<int, 3>& cartDims,
|
||||
const std::function<std::array<int, 3>(const std::size_t)>& getIJK);
|
||||
explicit ActiveIndexByColumns(const std::size_t numActive,
|
||||
const std::array<int, 3>& cartDims,
|
||||
const std::function<std::array<int, 3>(const std::size_t)>& getIJK);
|
||||
|
||||
/// Map active index in natural order to active index in columnar order.
|
||||
///
|
||||
@ -67,8 +67,7 @@ private:
|
||||
};
|
||||
|
||||
/// Build natural->columnar active cell index mapping from an EclipseGrid instance.
|
||||
void buildColumnarActiveIndexMappingTables(const EclipseGrid& grid,
|
||||
ActiveIndexByColumns& map);
|
||||
ActiveIndexByColumns buildColumnarActiveIndexMappingTables(const EclipseGrid& grid);
|
||||
|
||||
} // namespace Opm
|
||||
|
||||
|
@ -46,6 +46,31 @@ namespace {
|
||||
//
|
||||
return ijk[2] + dims[2]*(ijk[1] + dims[1]*ijk[0]);
|
||||
}
|
||||
|
||||
std::vector<int>
|
||||
buildMappingTables(const std::size_t numActive,
|
||||
const std::array<int, 3>& cartDims,
|
||||
const std::function<std::array<int, 3>(const std::size_t)>& getIJK)
|
||||
{
|
||||
auto natural2columnar = std::vector<int>(numActive, 0);
|
||||
|
||||
auto activeCells = std::vector<std::size_t>(numActive, std::size_t{0});
|
||||
std::iota(activeCells.begin(), activeCells.end(), std::size_t{0});
|
||||
|
||||
std::sort(activeCells.begin(), activeCells.end(),
|
||||
[&cartDims, &getIJK](const std::size_t cell1, const std::size_t cell2) -> bool
|
||||
{
|
||||
return columnarGlobalIdx(cartDims, getIJK(cell1))
|
||||
< columnarGlobalIdx(cartDims, getIJK(cell2));
|
||||
});
|
||||
|
||||
auto columnarActiveID = 0;
|
||||
for (const auto& naturalActiveID : activeCells) {
|
||||
natural2columnar[naturalActiveID] = columnarActiveID++;
|
||||
}
|
||||
|
||||
return natural2columnar;
|
||||
}
|
||||
}
|
||||
|
||||
bool Opm::ActiveIndexByColumns::operator==(const ActiveIndexByColumns& rhs) const
|
||||
@ -53,35 +78,19 @@ bool Opm::ActiveIndexByColumns::operator==(const ActiveIndexByColumns& rhs) cons
|
||||
return this->natural2columnar_ == rhs.natural2columnar_;
|
||||
}
|
||||
|
||||
void
|
||||
Opm::ActiveIndexByColumns::
|
||||
buildMappingTables(const std::size_t numActive,
|
||||
const std::array<int, 3>& cartDims,
|
||||
const std::function<std::array<int, 3>(const std::size_t)>& getIJK)
|
||||
ActiveIndexByColumns(const std::size_t numActive,
|
||||
const std::array<int, 3>& cartDims,
|
||||
const std::function<std::array<int, 3>(const std::size_t)>& getIJK)
|
||||
: natural2columnar_{ buildMappingTables(numActive, cartDims, getIJK) }
|
||||
{}
|
||||
|
||||
Opm::ActiveIndexByColumns
|
||||
Opm::buildColumnarActiveIndexMappingTables(const EclipseGrid& grid)
|
||||
{
|
||||
auto activeCells = std::vector<std::size_t>(numActive, std::size_t{0});
|
||||
std::iota(activeCells.begin(), activeCells.end(), std::size_t{0});
|
||||
|
||||
std::sort(activeCells.begin(), activeCells.end(),
|
||||
[&cartDims, &getIJK](const std::size_t cell1, const std::size_t cell2) -> bool
|
||||
{
|
||||
return columnarGlobalIdx(cartDims, getIJK(cell1))
|
||||
< columnarGlobalIdx(cartDims, getIJK(cell2));
|
||||
});
|
||||
|
||||
this->natural2columnar_.resize(numActive, 0);
|
||||
auto columnarActiveID = 0;
|
||||
for (const auto& naturalActiveID : activeCells) {
|
||||
this->natural2columnar_[naturalActiveID] = columnarActiveID++;
|
||||
}
|
||||
}
|
||||
|
||||
void Opm::buildColumnarActiveIndexMappingTables(const EclipseGrid& grid,
|
||||
ActiveIndexByColumns& map)
|
||||
{
|
||||
map.buildMappingTables(grid.getNumActive(), grid.getNXYZ(),
|
||||
return ActiveIndexByColumns { grid.getNumActive(), grid.getNXYZ(),
|
||||
[&grid](const std::size_t activeCell)
|
||||
{
|
||||
return grid.getIJK(grid.getGlobalIndex(activeCell));
|
||||
});
|
||||
}};
|
||||
}
|
||||
|
@ -35,10 +35,21 @@ BOOST_AUTO_TEST_SUITE(Basic_Mapping)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Constructor)
|
||||
{
|
||||
auto map = Opm::ActiveIndexByColumns{};
|
||||
auto map2 = map;
|
||||
const auto cartDims = std::array<int,3>{ { 1, 1, 4 } };
|
||||
const auto actIJK = std::vector<std::array<int,3>> {
|
||||
{ 0, 0, 0 },
|
||||
{ 0, 0, 1 },
|
||||
{ 0, 0, 3 },
|
||||
};
|
||||
|
||||
auto map3 = std::move(map2);
|
||||
const auto map = Opm::ActiveIndexByColumns { actIJK.size(), cartDims,
|
||||
[&actIJK](const std::size_t i)
|
||||
{
|
||||
return actIJK[i];
|
||||
}};
|
||||
|
||||
auto map2 = map;
|
||||
const auto map3 = std::move(map2);
|
||||
BOOST_CHECK_MESSAGE(map3 == map, "Copied Map object must equal initial");
|
||||
}
|
||||
|
||||
@ -51,12 +62,11 @@ BOOST_AUTO_TEST_CASE(Single_Column)
|
||||
{ 0, 0, 3 },
|
||||
};
|
||||
|
||||
auto map = Opm::ActiveIndexByColumns{};
|
||||
map.buildMappingTables(actIJK.size(), cartDims,
|
||||
const auto map = Opm::ActiveIndexByColumns { actIJK.size(), cartDims,
|
||||
[&actIJK](const std::size_t i)
|
||||
{
|
||||
return actIJK[i];
|
||||
});
|
||||
}};
|
||||
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex(0), 0);
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex(1), 1);
|
||||
@ -73,12 +83,11 @@ BOOST_AUTO_TEST_CASE(Two_Columns)
|
||||
{ 0, 0, 3 }, { 1, 0, 3 },
|
||||
};
|
||||
|
||||
auto map = Opm::ActiveIndexByColumns{};
|
||||
map.buildMappingTables(actIJK.size(), cartDims,
|
||||
const auto map = Opm::ActiveIndexByColumns { actIJK.size(), cartDims,
|
||||
[&actIJK](const std::size_t i)
|
||||
{
|
||||
return actIJK[i];
|
||||
});
|
||||
}};
|
||||
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex(0), 0);
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex(1), 3);
|
||||
@ -100,12 +109,11 @@ BOOST_AUTO_TEST_CASE(Four_Columns)
|
||||
{ 0, 0, 3 }, { 1, 0, 3 }, { 0, 1, 3 }, { 1, 1, 3 },
|
||||
};
|
||||
|
||||
auto map = Opm::ActiveIndexByColumns{};
|
||||
map.buildMappingTables(actIJK.size(), cartDims,
|
||||
const auto map = Opm::ActiveIndexByColumns { actIJK.size(), cartDims,
|
||||
[&actIJK](const std::size_t i)
|
||||
{
|
||||
return actIJK[i];
|
||||
});
|
||||
}};
|
||||
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex( 0), 0);
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex( 1), 6);
|
||||
@ -256,8 +264,7 @@ BOOST_AUTO_TEST_CASE(Cube_3x3x3_Full)
|
||||
{
|
||||
const auto grid = Opm::EclipseGrid {{3, 3, 3}, coord_3x3x3(), zcorn_3x3x3() };
|
||||
|
||||
auto map = Opm::ActiveIndexByColumns{};
|
||||
buildColumnarActiveIndexMappingTables(grid, map);
|
||||
const auto map = Opm::buildColumnarActiveIndexMappingTables(grid);
|
||||
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex( 0), 0);
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex( 1), 9);
|
||||
@ -321,8 +328,7 @@ BOOST_AUTO_TEST_CASE(Cube_3x3x3_exclude_centre_cell)
|
||||
const auto actnum = actnum_3x3x3_exclude_centre_cell();
|
||||
const auto grid = Opm::EclipseGrid {{3, 3, 3}, coord_3x3x3(), zcorn_3x3x3(), actnum.data() };
|
||||
|
||||
auto map = Opm::ActiveIndexByColumns{};
|
||||
buildColumnarActiveIndexMappingTables(grid, map);
|
||||
const auto map = Opm::buildColumnarActiveIndexMappingTables(grid);
|
||||
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex( 0), 0);
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex( 1), 9);
|
||||
@ -385,8 +391,7 @@ BOOST_AUTO_TEST_CASE(Cube_3x3x3_exclude_centre_column)
|
||||
const auto actnum = actnum_3x3x3_exclude_centre_column();
|
||||
const auto grid = Opm::EclipseGrid {{3, 3, 3}, coord_3x3x3(), zcorn_3x3x3(), actnum.data() };
|
||||
|
||||
auto map = Opm::ActiveIndexByColumns{};
|
||||
buildColumnarActiveIndexMappingTables(grid, map);
|
||||
const auto map = Opm::buildColumnarActiveIndexMappingTables(grid);
|
||||
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex( 0), 0);
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex( 1), 9);
|
||||
@ -447,8 +452,7 @@ BOOST_AUTO_TEST_CASE(Cube_3x3x3_exclude_diagonals)
|
||||
const auto actnum = actnum_3x3x3_exclude_diagonals();
|
||||
const auto grid = Opm::EclipseGrid {{3, 3, 3}, coord_3x3x3(), zcorn_3x3x3(), actnum.data() };
|
||||
|
||||
auto map = Opm::ActiveIndexByColumns{};
|
||||
buildColumnarActiveIndexMappingTables(grid, map);
|
||||
const auto map = Opm::buildColumnarActiveIndexMappingTables(grid);
|
||||
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex( 0), 5);
|
||||
BOOST_CHECK_EQUAL(map.getColumnarActiveIndex( 1), 1);
|
||||
|
Loading…
Reference in New Issue
Block a user