Dune Core Modules (2.9.0)

checkbndsegiterator.hh
1#ifndef DUNE_SPGRID_CHECKBNDSEGITERATOR_HH
2#define DUNE_SPGRID_CHECKBNDSEGITERATOR_HH
3
4//- C++ includes
5#include <algorithm>
6#include <cassert>
7#include <iostream>
8#include <vector>
9
10//- dune-common includes
11#include <dune/common/array.hh>
13
14//- dune-grid includes
15#include <dune/grid/common/exceptions.hh>
16#include <dune/grid/common/gridview.hh>
17
18
19namespace Dune
20{
21
22 template< class VT >
23 void checkBoundarySegmentIterator ( const Dune::GridView< VT > &gridView )
24 {
25 // get grid view types
26 typedef Dune::GridView< VT > GridView;
27 typedef typename GridView::IntersectionIterator IntersectionIterator;
28 typedef typename IntersectionIterator::Intersection Intersection;
29 typedef typename Intersection::EntityPointer EntityPointer;
30 typedef typename EntityPointer::Entity Entity;
31
32 // boundary segment iterator to be tested
33 typedef typename GridView::Implementation::BoundarySegmentIterator BoundarySegmentIterator;
34
35 // get index set
36 typedef typename GridView::IndexSet IndexSet;
37 const IndexSet &indexSet = gridView.indexSet();
38
39 // storage for all intersections in grid view
40 static const int numFaces = 2*GridView::dimension;
41 typedef Dune::array< int, numFaces > Data;
42 std::vector< Data > boundaryFace( indexSet.size( 0 ) );
43 for( typename std::vector< Data >::iterator vit = boundaryFace.begin(); vit != boundaryFace.end(); ++vit )
44 vit->fill( 0 );
45
46 // visit all boundary intersections
47 int bndIntersections = 0;
48 typedef typename GridView::template Codim< 0 >::Iterator Iterator;
49 const Iterator end = gridView.template end< 0 >();
50 for( Iterator it = gridView.template begin< 0 >(); it != end; ++it )
51 {
52 // get entity
53 const Entity &entity = *it;
54 if( !entity.hasBoundaryIntersections() )
55 continue;
56
57 // visit boundary intersections
58 const typename IndexSet::IndexType index = indexSet.index( entity );
59 const IntersectionIterator iend = gridView.iend( entity );
60 for( IntersectionIterator iit = gridView.ibegin( entity ); iit != iend; ++iit )
61 {
62 const Intersection &intersection = *iit;
63 if( intersection.boundary() )
64 {
65 boundaryFace[ index ][ intersection.indexInInside() ] = 1;
66 bndIntersections++;
67 }
68 }
69 }
70 std::cerr << "Found " << bndIntersections << " boundary intersections" << std::endl;
71
72 // now iterate over all boundary segments
73 int bndSegments = 0;
74 const BoundarySegmentIterator bend = gridView.impl().boundarySegmentEnd();
75 for( BoundarySegmentIterator bit = gridView.impl().boundarySegmentBegin(); bit != bend; ++bit )
76 {
77 // dereference boundary segment iterator
78 const Intersection &boundarySegment = *bit;
79 ++bndSegments;
80
81 // assert boundary segment is on boundary
82 if( !boundarySegment.boundary() )
83 DUNE_THROW( GridError, "Boundary segment not on boundary" );
84
85 // get index in inside
86 const int indexInInside = boundarySegment.indexInInside();
87
88 // get inside entity
89 EntityPointer insidePtr = boundarySegment.inside();
90 const Entity &inside = *insidePtr;
91
92 // find boundary segment in inside intersections
93 const IntersectionIterator iend = gridView.iend( inside );
94 for( IntersectionIterator iit = gridView.ibegin( inside ); iit != iend; ++iit )
95 {
96 const Intersection &intersection = *iit;
97
98 // equality check should be symmetrical
99 if( intersection.impl().equals( boundarySegment.impl() ) != boundarySegment.impl().equals( intersection.impl() ) )
100 DUNE_THROW( GridError, "Comparison of intersection and boundary segment failed" );
101
102 // equality check should be symmetrical
103 if( intersection.impl().equals( boundarySegment.impl() ) )
104 {
105 // assert that index in inside conincides
106 if( intersection.indexInInside() != indexInInside )
107 DUNE_THROW( GridError, "Index in inside of boundary segment and intersection in inside entity do not conincide" );
108
109 // assert boundary segment is not found twice
110 if( (boundaryFace[ indexSet.index( inside ) ][ indexInInside ] -= 1) < 0 )
111 DUNE_THROW( GridError, "Boundary segment found twice in inside entity" );
112 }
113 }
114 }
115 std::cerr << "Found " << bndSegments << " boundary segments" << std::endl;
116
117 // check we found all boundary intersections
118 for( typename std::vector< Data >::iterator vit = boundaryFace.begin(); vit != boundaryFace.end(); ++vit )
119 {
120 for( size_t face = 0; face < vit->size(); ++face )
121 if( (*vit)[ face ] != 0 )
122 DUNE_THROW( GridError, "Not all boundary intersections were found" );
123 }
124 }
125
126}
127
128#endif // #ifndef DUNE_SPGRID_CHECKBNDSEGITERATOR_HH
Grid view abstract base class.
Definition: gridview.hh:66
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:92
Dune::Intersection< GridImp, IntersectionImp > Intersection
Type of Intersection this IntersectionIterator points to.
Definition: intersectioniterator.hh:111
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
const IndexSet & indexSet() const
obtain the index set
Definition: gridview.hh:191
Implementation & impl()
access to the underlying implementation
Definition: gridview.hh:313
Traits::IntersectionIterator IntersectionIterator
type of the intersection iterator
Definition: gridview.hh:92
IntersectionIterator ibegin(const typename Codim< 0 > ::Entity &entity) const
obtain begin intersection iterator with respect to this view
Definition: gridview.hh:267
Traits::IndexSet IndexSet
type of the index set
Definition: gridview.hh:86
static constexpr int dimension
The dimension of the grid.
Definition: gridview.hh:148
IntersectionIterator iend(const typename Codim< 0 > ::Entity &entity) const
obtain end intersection iterator with respect to this view
Definition: gridview.hh:274
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)