Skip to content
Snippets Groups Projects
Commit 9fe4f696 authored by Robert K's avatar Robert K
Browse files

[bugfix][MCMGMapper] added contains == subIndex for blocksize > 1.

parent 34d32f2f
No related branches found
No related tags found
1 merge request!351fix bug a bug in the MCMGMapper contains method for blocksize > 1
Pipeline #22561 passed
dune_add_test(SOURCES scsgmappertest.cc)
dune_add_test(SOURCES mcmgmappertest.cc
CMAKE_GUARD dune-uggrid_FOUND)
dune_add_test(SOURCES mcmgmappertest.cc)
......@@ -12,8 +12,12 @@
#include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/common/mcmgmapper.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/grid/utility/structuredgridfactory.hh>
#if HAVE_DUNE_UGGRID
#include <dune/grid/uggrid.hh>
#include "../../../../doc/grids/gridfactory/hybridtestgrids.hh"
#endif
using namespace Dune;
......@@ -37,6 +41,7 @@ struct MCMGElementEdgeLayout
}
};
/*!
* \brief Check whether the index created for element data is unique,
* consecutive and starting from zero.
......@@ -75,16 +80,26 @@ void checkVertexDataMapper(const Mapper& mapper, const GridView& gridView)
{
const size_t dim = GridView::dimension;
size_t min = 1;
size_t max = 0;
std::set<int> indices;
typedef typename Mapper::Index Index;
Index min = 1;
Index max = 0;
std::set< Index > indices;
for (const auto& element : elements(gridView))
{
size_t numVertices = element.subEntities(dim);
for (size_t curVertex = 0; curVertex < numVertices; ++curVertex)
{
size_t index = mapper.subIndex(element, curVertex, dim);
Index testIdx = Index(-1);
bool contains = mapper.contains(element, curVertex, dim, testIdx );
Index index = mapper.subIndex(element, curVertex, dim);
if( contains && (index != testIdx) )
{
DUNE_THROW(GridError, "subIndex and contains do not return the same index!");
}
min = std::min(min, index);
max = std::max(max, index);
indices.insert(index);
......@@ -160,6 +175,15 @@ void checkMixedDataMapper(const Mapper& mapper, const GridView& gridView)
max = std::max(max, *(block.end())-1);
for (Index i : block)
indices.insert(i);
Index testIdx = Index(-1);
const bool contains = mapper.contains(element, curEdge, dim-1, testIdx );
const Index index = mapper.subIndex(element, curEdge, dim-1);
if( contains && (index != testIdx) )
{
DUNE_THROW(GridError, "subIndex and contains do not return the same index!");
}
}
}
......@@ -199,6 +223,7 @@ void checkGrid(const Grid& grid)
leafMCMGMapper(grid, MCMGElementLayout<dim>());
checkElementDataMapper(leafMCMGMapper, grid.leafGridView());
}
DUNE_NO_DEPRECATED_END
{
LeafMultipleCodimMultipleGeomTypeMapper<Grid>
......@@ -325,6 +350,7 @@ try
// Check grids with more than one element type.
// So far only UGGrid does this, so we use it to test the mappers.
#if HAVE_DUNE_UGGRID
// Do the test for a 2d UGGrid
{
typedef UGGrid<2> Grid;
......@@ -350,6 +376,31 @@ try
checkGrid(*grid);
}
#endif
// Do the test for a 2d YaspGrid
{
Dune::FieldVector< double, 2 > lower( 0 );
Dune::FieldVector< double, 2 > upper( 1 );
std::array<unsigned int,2 > elements = {{ 4 ,4 }};
typedef Dune::YaspGrid<2> Grid;
auto grid = Dune::StructuredGridFactory< Grid >::createCubeGrid( lower, upper, elements );
// create hybrid grid
checkGrid(*grid);
}
// Do the test for a 3d YaspGrid
{
Dune::FieldVector< double, 3 > lower( 0 );
Dune::FieldVector< double, 3 > upper( 1 );
std::array<unsigned int,3 > elements = {{ 4 ,4, 4 }};
typedef Dune::YaspGrid<3> Grid;
auto grid = Dune::StructuredGridFactory< Grid >::createCubeGrid( lower, upper, elements );
// create hybrid grid
checkGrid(*grid);
}
return EXIT_SUCCESS;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment