/usr/include/dune/grid/test/checkgridfactory.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 | #ifndef DUNE_GRID_TEST_CHECKGRIDFACTORY_HH
#define DUNE_GRID_TEST_CHECKGRIDFACTORY_HH
#include <algorithm>
#include <memory>
#include <vector>
#include <dune/common/exceptions.hh>
#include <dune/common/fvector.hh>
#include <dune/geometry/referenceelements.hh>
#include <dune/grid/common/gridfactory.hh>
namespace Dune
{
// checkGridFactory
// ----------------
template< class Grid, class Mesh, class Projection >
void checkGridFactory ( const Mesh &mesh, Projection &&projection )
{
GridFactory< Grid > factory;
// create grid from mesh
typedef FieldVector< typename Grid::ctype, Grid::dimensionworld > Vertex;
mesh.addToGridFactory( factory, projection );
std::unique_ptr< Grid > gridptr( factory.createGrid() );
Grid &grid = *gridptr;
// check insertion indices
// check vertex insertion index
for( const auto vertex : vertices( grid.leafGridView() ) )
{
std::size_t idx = factory.insertionIndex( vertex );
Vertex v = projection( mesh.vertices[ idx ] );
if( (v - vertex.geometry().center() ).two_norm() > 1e-8 )
DUNE_THROW( GridError, "GridFactory error, Vertex insertion Index wrong!" );
}
// check element insertion index
std::vector< unsigned int > indices;
for( const auto element : elements( grid.leafGridView() ) )
{
std::size_t idx = factory.insertionIndex( element );
unsigned int numSubEntitites = element.subEntities( Grid::dimension );
if( numSubEntitites != mesh.elements[ idx ].second.size() )
DUNE_THROW( GridError, "GridFactory error, wrong number of subEntities inserted!" );
indices.clear();
for( unsigned int i = 0; i < numSubEntitites; ++i )
indices.push_back( factory.insertionIndex( element.template subEntity< Grid::dimension >( i ) ) );
if( !std::is_permutation( indices.begin(), indices.end(), mesh.elements[ idx ].second.begin() ) )
DUNE_THROW( GridError, "GridFactory error, Element insertion index wrong!" );
}
// check boundary segment index
typedef std::pair< unsigned int, std::vector< unsigned int > > BoundarySegementPair;
std::vector< BoundarySegementPair > bndInsIndex;
for( const auto &entity : elements( grid.leafGridView() ) )
{
const ReferenceElement< typename Grid::ctype, Grid::dimension > &refelement
= ReferenceElements< typename Grid::ctype, Grid::dimension >::general( entity.type() );
for( const auto &intersection : intersections( grid.leafGridView(), entity ) )
if( factory.wasInserted( intersection ) )
{
auto geometry = intersection.geometry();
std::vector< unsigned int > vertices;
const int numSubEntitites = refelement.size( intersection.indexInInside(), 1, Grid::dimension );
for( int i = 0; i < numSubEntitites; ++i )
vertices.push_back(
factory.insertionIndex(
entity.template subEntity< Grid::dimension >( refelement.subEntity( intersection.indexInInside(), 1, i, Grid::dimension ) )
) );
bndInsIndex.emplace_back( factory.insertionIndex( intersection ), vertices );
}
}
auto compare = [] ( const BoundarySegementPair &v, const BoundarySegementPair &w ) { return v.first == w.first; };
bndInsIndex.resize( std::distance( bndInsIndex.begin(), std::unique( bndInsIndex.begin(), bndInsIndex.end(), compare ) ) );
if( bndInsIndex.size() != mesh.boundaries.size() )
DUNE_THROW( GridError, "GridFactory error, wrong number of boundary segments inserted." );
for( const BoundarySegementPair &pair : bndInsIndex )
if( !std::is_permutation( pair.second.begin(), pair.second.end(), mesh.boundaries[ pair.first ].begin() ) )
DUNE_THROW( GridError, "GridFactory error, insertion index for boundary segment wrong." );
}
template< class Grid, class Mesh >
void checkGridFactory ( const Mesh &mesh )
{
checkGridFactory< Grid >( mesh, [] ( const typename Mesh::Vertex &v ) { return v; } );
}
} // namespace Dune
#endif // #ifndef DUNE_GRID_TEST_CHECKGRIDFACTORY_HH
|