Extended test for the reordering

This commit is contained in:
Markus Blatt 2018-06-12 13:18:07 +02:00
parent 190272e21d
commit 41e5779ae3

View File

@ -11,6 +11,21 @@
#include <boost/test/unit_test.hpp>
///! \brief check that all indices are represented in the new ordering.
void checkAllIndices(const std::vector<std::size_t>& ordering)
{
std::vector<int> counters(ordering.size(), 0);
for(auto index: ordering)
{
++counters[index];
}
for(auto count: counters)
{
BOOST_CHECK(count==1);
}
}
BOOST_AUTO_TEST_CASE(TestWelschPowell)
{
using Matrix = Dune::BCRSMatrix<Dune::FieldMatrix<double,1,1>>;
@ -46,8 +61,10 @@ BOOST_AUTO_TEST_CASE(TestWelschPowell)
}
matrix.compress();
auto colorsTuple = Opm::colorVerticesWelshPowell(Graph(matrix));
Graph graph(matrix);
auto colorsTuple = Opm::colorVerticesWelshPowell(graph);
const auto& colors = std::get<0>(colorsTuple);
const auto& verticesPerColor = std::get<2>(colorsTuple);
auto noColors = std::get<1>(colorsTuple);
auto firstCornerColor = colors[0];
BOOST_CHECK(noColors == 2);
@ -66,4 +83,19 @@ BOOST_AUTO_TEST_CASE(TestWelschPowell)
}
firstCornerColor=(firstCornerColor + 1) % 2;
}
auto newOrder = Opm::reorderVerticesPreserving(colors, noColors, verticesPerColor,
graph);
std::vector<std::size_t> colorIndex(noColors, 0);
std::partial_sum(verticesPerColor.begin(),
verticesPerColor.begin()+verticesPerColor.size()-1,
colorIndex.begin()+1);
for (auto vertex : graph)
{
BOOST_CHECK(colorIndex[colors[vertex]]++ == newOrder[vertex]);
}
checkAllIndices(newOrder);
newOrder = Opm::reorderVerticesSpheres(colors, noColors, verticesPerColor,
graph, 0);
checkAllIndices(newOrder);
}