DUNE-FEM (unstable)

uniquefacetorientation.hh
1#ifndef DUNE_FEM_SPACE_COMMON_UNIQUEFACETORIENTATION_HH
2#define DUNE_FEM_SPACE_COMMON_UNIQUEFACETORIENTATION_HH
3
4#include <type_traits>
5#include <utility>
6
7#include <dune/grid/common/rangegenerators.hh>
8
9#include <dune/fem/common/utility.hh>
10#include <dune/fem/gridpart/common/capabilities.hh>
11#include <dune/fem/space/common/functionspace.hh>
12#include <dune/fem/space/finitevolume.hh>
13#include <dune/fem/space/mapper/parallel.hh>
14
15namespace Dune
16{
17
18 namespace Fem
19 {
20
21 // DefaultUniqueFacetOrientation
22 // -----------------------------
23
24 template< class GridPart >
25 struct DefaultUniqueFacetOrientation
26 {
27 typedef GridPart GridPartType;
28 typedef typename GridPartType::template Codim< 0 >::EntityType EntityType;
29
30 typedef FunctionSpace< double, int, GridPartType::dimensionworld, 1 > FunctionSpaceType;
31 typedef FiniteVolumeSpace< FunctionSpaceType, GridPartType, 0, SimpleStorage > SpaceType;
32
33 typedef ParallelDofMapper< GridPartType, typename SpaceType::BlockMapperType > ParallelMapperType;
34 typedef typename ParallelMapperType :: GlobalKeyType GlobalKeyType;
35
36 explicit DefaultUniqueFacetOrientation ( const GridPartType &gridPart )
37 : gridPart_( gridPart ),
38 space_( const_cast< GridPartType& > (gridPart_) ),
39 parallelMapper_( gridPart_, space_.blockMapper(), space_.communicationInterface() ),
40 sequence_( -1 )
41 {
42 }
43
44 unsigned int operator() ( const EntityType &entity ) const
45 {
46 if( sequence_ != space_.sequence() )
47 {
48 parallelMapper_.update();
49 sequence_ = space_.sequence();
50 }
51
52 unsigned int orientations = 0;
53 for( auto intersection : intersections( gridPart(), entity ) )
54 {
55 if( intersection.neighbor() && (globallyUniqueIndex( entity ) < globallyUniqueIndex( intersection.outside() )) )
56 orientations |= (1 << intersection.indexInInside());
57 }
58 return orientations;
59 }
60
61 template <class Entity>
62 GlobalKeyType globallyUniqueIndex( const Entity& entity ) const
63 {
64 GlobalKeyType index = -1;
65 parallelMapper_.mapEach( entity, [ &index ] ( auto local, auto global ) { assert( local == 0 ); index = global; } );
66 return index;
67 }
68
69 const GridPartType &gridPart () const { return gridPart_; }
70
71 protected:
72 const GridPartType& gridPart_;
73 SpaceType space_;
74 mutable ParallelMapperType parallelMapper_;
75 mutable int sequence_;
76 };
77
78
79
80 // CartesianUniqueFacetOrientation
81 // -------------------------------
82
83 template< class GridPart >
84 struct CartesianUniqueFacetOrientation
85 {
86 typedef GridPart GridPartType;
87 typedef typename GridPart::template Codim< 0 >::EntityType EntityType;
88
89 explicit CartesianUniqueFacetOrientation ( const GridPartType &gridPart )
90 : gridPart_( gridPart )
91 {}
92
93 unsigned int operator() ( const EntityType &entity ) const
94 {
95 return orientations( std::make_index_sequence< GridPartType::dimension >() );
96 }
97
98 const GridPartType &gridPart () const { return gridPart_; }
99
100 private:
101 template< std::size_t... i >
102 static constexpr unsigned int orientations ( std::index_sequence< i... > )
103 {
104 return Std::sum( (1u << 2*i)... );
105 }
106
107 const GridPartType &gridPart_;
108 };
109
110
111
112 // UniqueFacetOrientation
113 // ----------------------
114
115 template< class GridPart >
116 using UniqueFacetOrientation =
117 typename std::conditional< GridPartCapabilities::isCartesian< GridPart >::v,
118 CartesianUniqueFacetOrientation< GridPart>,
119 DefaultUniqueFacetOrientation< GridPart > >::type;
120
121 } // namespace Fem
122
123} // namespace Dune
124
125#endif // #ifndef DUNE_FEM_SPACE_COMMON_UNIQUEFACETORIENTATION_HH
A vector valued function space.
Definition: functionspace.hh:60
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)