dune-grid  2.2.1
geometrygrid/intersection.hh
Go to the documentation of this file.
1 #ifndef DUNE_GEOGRID_INTERSECTION_HH
2 #define DUNE_GEOGRID_INTERSECTION_HH
3 
7 
8 namespace Dune
9 {
10 
11  namespace GeoGrid
12  {
13 
14  // Internal Forward Declarations
15  // -----------------------------
16 
17  template< class Grid >
18  class LeafIntersection;
19 
20  template< class Grid >
21  class LevelIntersection;
22 
23 
24 
25  // Intersection
26  // ------------
27 
28  template< class Grid, class HostIntersection >
30  {
31  typedef typename HostIntersection::Geometry HostGeometry;
32  typedef typename HostIntersection::LocalGeometry HostLocalGeometry;
33 
34  typedef typename remove_const< Grid >::type::Traits Traits;
35 
36  public:
37  typedef typename Traits::ctype ctype;
38 
39  static const int dimension = Traits::dimension;
41 
42  typedef typename Traits::template Codim< 0 >::Entity Entity;
43  typedef typename Traits::template Codim< 0 >::EntityPointer EntityPointer;
44  typedef typename Traits::template Codim< 1 >::Geometry Geometry;
45  typedef typename Traits::template Codim< 1 >::LocalGeometry LocalGeometry;
46 
47  typedef typename Traits::template Codim< 0 >::Geometry ElementGeometry;
48 
49  private:
51 
52  typedef typename Traits::template Codim< 0 >::EntityPointerImpl EntityPointerImpl;
53 
54  typedef typename Traits::template Codim< 1 >::GeometryImpl GeometryImpl;
55  typedef typename Traits::template Codim< 0 >::GeometryImpl ElementGeometryImpl;
56 
57  public:
58  explicit Intersection ( const ElementGeometry &insideGeo )
59  : insideGeo_( Grid::getRealImplementation( insideGeo ) ),
60  hostIntersection_( 0 ),
61  geo_( grid() )
62  {}
63 
64  Intersection ( const Intersection &other )
65  : insideGeo_( other.insideGeo_ ),
66  hostIntersection_( 0 ),
67  geo_( grid() )
68  {}
69 
70  const Intersection &operator= ( const Intersection &other )
71  {
72  insideGeo_ = other.insideGeo_;
73  invalidate();
74  return *this;
75  }
76 
77  operator bool () const { return bool( hostIntersection_ ); }
78 
80  {
81  return EntityPointerImpl( insideGeo_, hostIntersection().inside() );
82  }
83 
85  {
86  return EntityPointerImpl( grid(), hostIntersection().outside() );
87  }
88 
89  bool boundary () const { return hostIntersection().boundary(); }
90 
91  bool conforming () const { return hostIntersection().conforming(); }
92 
93  bool neighbor () const { return hostIntersection().neighbor(); }
94 
95  int boundaryId () const { return hostIntersection().boundaryId(); }
96 
97  size_t boundarySegmentIndex () const
98  {
99  return hostIntersection().boundarySegmentIndex();
100  }
101 
103  {
104  return hostIntersection().geometryInInside();
105  }
106 
108  {
109  return hostIntersection().geometryInOutside();
110  }
111 
113  {
114  if( !geo_ )
115  {
116  CoordVector coords( insideGeo_, geometryInInside() );
117  geo_ = GeometryImpl( grid(), type(), coords );
118  }
119  return Geometry( geo_ );
120  }
121 
122  GeometryType type () const { return hostIntersection().type(); }
123 
124  unsigned int topologyId () const DUNE_DEPRECATED
125  {
126  return type().id();
127  }
128 
129  int indexInInside () const
130  {
131  return hostIntersection().indexInInside();
132  }
133 
134  int indexInOutside () const
135  {
136  return hostIntersection().indexInOutside();
137  }
138 
139  FieldVector< ctype, dimensionworld >
140  integrationOuterNormal ( const FieldVector< ctype, dimension-1 > &local ) const
141  {
142  const GenericReferenceElement< ctype, dimension > &refElement
143  = GenericReferenceElements< ctype, dimension>::general( insideGeo_.type() );
144 
145  FieldVector< ctype, dimension > x( geometryInInside().global( local ) );
146  const typename ElementGeometryImpl::JacobianInverseTransposed &jit = insideGeo_.jacobianInverseTransposed( x );
147  const FieldVector< ctype, dimension > &refNormal = refElement.volumeOuterNormal( indexInInside() );
148 
149  FieldVector< ctype, dimensionworld > normal;
150  jit.mv( refNormal, normal );
151  normal *= ctype( 1 ) / jit.det();
152  //normal *= insideGeo_.integrationElement( x );
153  return normal;
154  }
155 
156  FieldVector< ctype, dimensionworld >
157  outerNormal ( const FieldVector< ctype, dimension-1 > &local ) const
158  {
159  const GenericReferenceElement< ctype, dimension > &refElement
160  = GenericReferenceElements< ctype, dimension>::general( insideGeo_.type() );
161 
162  FieldVector< ctype, dimension > x( geometryInInside().global( local ) );
163  const typename ElementGeometryImpl::JacobianInverseTransposed &jit = insideGeo_.jacobianInverseTransposed( x );
164  const FieldVector< ctype, dimension > &refNormal = refElement.volumeOuterNormal( indexInInside() );
165 
166  FieldVector< ctype, dimensionworld > normal;
167  jit.mv( refNormal, normal );
168  return normal;
169  }
170 
171  FieldVector< ctype, dimensionworld >
172  unitOuterNormal ( const FieldVector< ctype, dimension-1 > &local ) const
173  {
174  FieldVector< ctype, dimensionworld > normal = outerNormal( local );
175  normal *= (ctype( 1 ) / normal.two_norm());
176  return normal;
177  }
178 
179  FieldVector< ctype, dimensionworld > centerUnitOuterNormal () const
180  {
181  const GenericReferenceElement< ctype, dimension-1 > &refFace
182  = GenericReferenceElements< ctype, dimension-1 >::general( type() );
183  return unitOuterNormal( refFace.position( 0, 0 ) );
184  }
185 
186  const HostIntersection &hostIntersection () const
187  {
188  assert( *this );
189  return *hostIntersection_;
190  }
191 
192  const Grid &grid () const { return insideGeo_.grid(); }
193 
194  void invalidate ()
195  {
196  hostIntersection_ = 0;
197  geo_ = GeometryImpl( grid() );
198  }
199 
200  void initialize ( const HostIntersection &hostIntersection )
201  {
202  assert( !(*this) );
203  hostIntersection_ = &hostIntersection;
204  }
205 
206  private:
207  ElementGeometryImpl insideGeo_;
208  const HostIntersection *hostIntersection_;
209  mutable GeometryImpl geo_;
210  };
211 
212 
213 
214  // LeafIntersection
215  // ----------------
216 
217  template< class HostGrid, class CoordFunction, class Allocator >
218  class LeafIntersection< const GeometryGrid< HostGrid, CoordFunction, Allocator > >
219  : public Intersection
220  < const GeometryGrid< HostGrid, CoordFunction, Allocator >,
221  typename HostGrid::Traits::LeafIntersection >
222  {
224  typedef typename HostGrid::Traits::LeafIntersection HostIntersection;
225 
227 
228  public:
230 
231  explicit LeafIntersection ( const ElementGeometry &insideGeo )
232  : Base( insideGeo )
233  {}
234  };
235 
236 
237 
238  // LevelIntersection
239  // -----------------
240 
241  template< class HostGrid, class CoordFunction, class Allocator >
242  class LevelIntersection< const GeometryGrid< HostGrid, CoordFunction, Allocator > >
243  : public Intersection
244  < const GeometryGrid< HostGrid, CoordFunction, Allocator >,
245  typename HostGrid::Traits::LevelIntersection >
246  {
248  typedef typename HostGrid::Traits::LevelIntersection HostIntersection;
249 
251 
252  public:
254 
255  explicit LevelIntersection ( const ElementGeometry &insideGeo )
256  : Base( insideGeo )
257  {}
258  };
259 
260  } // namespace GeoGrid
261 
262 } // namespace Dune
263 
264 #endif // #ifndef DUNE_GEOGRID_INTERSECTION_HH