Commit 0b61d119 authored by Ansgar Burchardt's avatar Ansgar Burchardt

Merge branch 'cherry-pick-67e5c5a7' into 'releases/2.5'

Merge branch 'do-not-force-grids-to-subclass-master' into 'master'

Do not force grids to subclass Entity or Geometry

The current implementation assumes that both the Entity and the Geometry of a grid are subclasses of Dune::Entity and Dune::Geometry. This requirement must have been introduced after 2.4.1 and is IMHO to much of restriction. After all these are just tests. With this MR we drop this additional restriction. Tested with opm-grid.

Closes #36 

Should be in the release.

See merge request !114

See merge request !129
parents 63340ecb b50e3159
......@@ -61,15 +61,14 @@ namespace CheckEntitySeed // don't blur namespace Dune
{ };
// Template specialization for Dune::Geometry
// Equals for Dune::Geometry
// ------------------------------------------
template< int mydim, int cdim, class GridImp, template< int, int, class > class GeometryImp >
struct Equals< Dune::Geometry< mydim, cdim, GridImp, GeometryImp > >
template<class Geometry>
struct GeometryEquals
{
typedef typename Dune::Geometry< mydim, cdim, GridImp, GeometryImp > Type;
static bool apply ( const Type &t1, const Type &t2, const double eps = 1e-10 )
static bool apply ( const Geometry &t1, const Geometry &t2, const double eps = 1e-10 )
{
//typedef typename Type::GlobalCoordinate GlobalCooridinate;
......@@ -175,7 +174,7 @@ namespace CheckEntitySeed // don't blur namespace Dune
// compare geometries
const double eps = 1e-10;
if( !Equals< Geometry >::apply( e1.geometry(), e2.geometry(), eps ) )
if( !GeometryEquals< Geometry >::apply( e1.geometry(), e2.geometry(), eps ) )
output << "Warning: Geometries do not conincide" << std::endl;
}
......
......@@ -18,6 +18,9 @@
namespace Dune
{
template<class Grid>
struct GeometryChecker;
/** \param geometry The local geometry to be tested
* \param type The type of the element that the local geometry is embedded in
* \param geoName Helper string that will appear in the error message
......@@ -46,35 +49,39 @@ namespace Dune
}
template <int codim>
template <class GI>
struct CheckSubEntityGeometry
{
template <int dim,class GI,template <int,int,class> class EI>
static void apply(const Entity<0,dim,GI,EI> &entity)
template <int codim>
struct Operation
{
std::integral_constant<
template <class Entity>
static void apply(const Entity &entity)
{
std::integral_constant<
bool, Dune::Capabilities::hasEntity<GI,codim>::v
> capVar;
check(capVar,entity);
}
template <class Entity>
static void check(const std::true_type&, const Entity &entity)
{
for (unsigned int i=0; i<entity.subEntities(codim); ++i)
check(capVar,entity);
}
template <class Entity>
static void check(const std::true_type&, const Entity &entity)
{
typedef typename Entity::template Codim< codim >::Entity SubE;
const SubE subEn = entity.template subEntity<codim>(i);
for (unsigned int i=0; i<entity.subEntities(codim); ++i)
{
typedef typename Entity::template Codim< codim >::Entity SubE;
const SubE subEn = entity.template subEntity<codim>(i);
typename SubE::Geometry subGeo = subEn.geometry();
typename SubE::Geometry subGeo = subEn.geometry();
if( subEn.type() != subGeo.type() )
std::cerr << "Error: Entity and geometry report different geometry types on codimension " << codim << "." << std::endl;
checkGeometry(subGeo);
if( subEn.type() != subGeo.type() )
std::cerr << "Error: Entity and geometry report different geometry types on codimension " << codim << "." << std::endl;
checkGeometry(subGeo);
}
}
}
template <class Entity>
static void check(const std::false_type&, const Entity &)
{}
template <class Entity>
static void check(const std::false_type&, const Entity &)
{}
};
};
template<typename GV>
......@@ -109,19 +116,29 @@ namespace Dune
}
}
template< class VT >
void checkGeometry ( const GridView< VT > &gridView )
template<class Grid>
struct GeometryChecker
{
typedef typename GridView< VT >::template Codim<0>::Iterator Iterator;
const Iterator end = gridView.template end<0>();
Iterator it = gridView.template begin<0>();
template<int codim>
using SubEntityGeometryChecker =
typename CheckSubEntityGeometry<Grid>::template Operation<codim>;
for( ; it != end; ++it )
template< class VT >
void checkGeometry ( const GridView< VT > &gridView )
{
ForLoop<CheckSubEntityGeometry,0,GridView<VT>::dimension>::apply(*it);
typedef typename GridView< VT >::template Codim<0>::Iterator Iterator;
const Iterator end = gridView.template end<0>();
Iterator it = gridView.template begin<0>();
for( ; it != end; ++it )
{
ForLoop<SubEntityGeometryChecker,0,GridView<VT>::dimension>
::apply(*it);
}
}
}
};
} // namespace Dune
......
......@@ -937,8 +937,9 @@ void gridcheck (Grid &g)
checkFatherLevel(cg);
// check geometries of macro level and leaf level
checkGeometry( g.levelGridView( 0 ) );
checkGeometry( g.leafGridView() );
Dune::GeometryChecker<Grid> checker;
checker.checkGeometry( g.levelGridView( 0 ) );
checker.checkGeometry( g.leafGridView() );
// check entity seeds
Dune::checkEntitySeed( g.leafGridView(), std::cerr );
......
......@@ -91,9 +91,11 @@ void test(const std::string& gridfile)
gridcheck( geogrid );
std::cerr << "Checking geometry... " << std::endl;
checkGeometry( geogrid.leafGridView() );
Dune::GeometryChecker< GeometryGridType > checker;
checker.checkGeometry( geogrid.leafGridView() );
for( int i = 0; i <= geogrid.maxLevel(); ++i )
checkGeometry( geogrid.levelGridView( i ) );
checker.checkGeometry( geogrid.levelGridView( i ) );
std::cerr << "Checking geometry in father..." << std::endl;
checkGeometryInFather( geogrid );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment