/usr/include/dune/grid/test/checkentityseed.hh is in libdune-grid-dev 2.5.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_GRID_CHECK_ENTITYSEED_HH
#define DUNE_GRID_CHECK_ENTITYSEED_HH
//- C++ includes
#include <cassert>
#include <ostream>
//- dune-common includes
#include <dune/common/forloop.hh>
//- dune-grid includes
#include <dune/grid/common/capabilities.hh>
#include <dune/grid/common/geometry.hh>
#include <dune/grid/common/gridview.hh>
/**
@file
@author Christoph Gersbacher
@brief Provides a check for EntitySeeds of all codimensions.
*/
namespace CheckEntitySeed // don't blur namespace Dune
{
// Capability hasEntitySeed
// ------------------------
// allow for switching off the tests below by overloading this capability
template< class Grid, int codim >
struct hasEntitySeed
{
static const bool v = Dune::Capabilities::hasEntity< Grid, codim >::v;
};
// Equals
// ------
template< class T >
struct Equals
{
typedef T Type;
static bool apply ( const T &t1, const T &t2 )
{
return ( t1 == t2 );
}
};
// Template specialization for const
// ---------------------------------
template< class T >
struct Equals< const T >
: public Equals< T >
{ };
// Equals for Dune::Geometry
// ------------------------------------------
template<class Geometry>
struct GeometryEquals
{
static bool apply ( const Geometry &t1, const Geometry &t2, const double eps = 1e-10 )
{
//typedef typename Type::GlobalCoordinate GlobalCooridinate;
// check geometry type
if( t1.type() != t2.type() )
return false;
// compare corners
assert( t1.corners() == t2.corners() );
const int corners = t1.corners();
for( int i = 0; i < corners; ++i )
{
if( (t1.corner( i ) - t2.corner( i )).two_norm() > eps )
return false;
}
return true;
}
};
// Check
// -----
template< int codim, class GridView,
bool check = hasEntitySeed< typename GridView::Grid, codim >::v
>
class Check;
// Template specialization for hasEntitySeed< Grid, codim >::v = false
// -------------------------------------------------------------------
template< int codim, class GridView >
class Check< codim, GridView, false >
{
public:
static void apply ( const GridView &, std::ostream & )
{ };
};
// Template specialization for hasEntitySeed< Grid, codim >::v = true
// ------------------------------------------------------------------
template< int codim, class GridView >
class Check< codim, GridView, true >
{
public:
// iterator type
typedef typename GridView::template Codim< codim >::Iterator Iterator;
// entity type
typedef typename GridView::template Codim< codim >::Entity Entity;
// geometry type
typedef typename Entity::Geometry Geometry;
// grid type
typedef typename GridView::Grid Grid;
// type of entity seed (not available on GridView)
typedef typename Grid::template Codim< codim >::EntitySeed EntitySeed;
// Check whether EntitySeed reports the correct codimension
static_assert(EntitySeed::codimension==codim, "Codimension exported by EntitySeed is incorrect!");
static void apply ( const GridView &gridView, std::ostream &output )
{
// get grid, as method entity() is missing on GridViews
const Grid &grid = gridView.grid();
const Iterator end = gridView.template end< codim >();
for( Iterator it = gridView.template begin< codim >(); it != end; ++it )
{
// get entity
const Entity &entity = *it;
EntitySeed seed = entity.seed();
// get entity from seed
Entity entity2 = grid.entity( seed );
compare( entity, *it, output );
// test default constructor
EntitySeed seed2;
assert(! seed2.isValid());
// create copy of seed and compare again
seed2 = seed;
assert( seed2.isValid());
// we might like to check the assignment operator as well
compare( entity2, grid.entity( seed2 ), output );
}
}
private:
// compare two entities for equality
static void compare ( const Entity &e1, const Entity &e2, std::ostream &output )
{
// compare entities
if( !Equals< Entity >::apply( e1, e2 ) )
output << "Warning: Entities do not conincide" << std::endl;
// compare geometries
const double eps = 1e-10;
if( !GeometryEquals< Geometry >::apply( e1.geometry(), e2.geometry(), eps ) )
output << "Warning: Geometries do not conincide" << std::endl;
}
};
// IfHasEntitySeed
// ---------------
template< int codim >
struct IfHasEntitySeed
{
template< class GridView >
static void apply ( const GridView &gridView, std::ostream &output )
{
Check< codim, GridView >::apply( gridView, output );
}
};
} // namespace CheckEntitySeed
namespace Dune
{
/** \brief Check for EntitySeeds for all codimensions available in a grid implementation
\param gridView Grid view for which EntitySeeds will be tested
*/
template< class VT >
void checkEntitySeed ( const GridView< VT > &gridView, std::ostream &output = std::cerr )
{
const int dimension = GridView< VT >::dimension;
ForLoop< CheckEntitySeed::IfHasEntitySeed, 0, dimension >::apply( gridView, output );
}
} // namespace Dune
#endif // #ifndef DUNE_GRID_CHECK_ENTITYSEED_HH
|