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/common/dofmanager.hh>
13#include <dune/fem/space/finitevolume.hh>
14#include <dune/fem/space/mapper/parallel.hh>
15
16namespace Dune
17{
18
19 namespace Fem
20 {
21
22 // DefaultUniqueFacetOrientation
23 // -----------------------------
24
25 template< class GridPart >
26 struct DefaultUniqueFacetOrientation
27 {
28 typedef GridPart GridPartType;
29 typedef typename GridPartType::GridType GridType;
30 typedef DofManager< GridType > DofManagerType;
31
32 typedef typename GridPartType::template Codim< 0 >::EntityType EntityType;
33 typedef typename EntityType::Geometry::GlobalCoordinate GlobalCoordinateType;
34
35 //typedef FunctionSpace< double, int, GridPartType::dimensionworld, 1 > FunctionSpaceType;
36 // typedef FiniteVolumeSpace< FunctionSpaceType, GridPartType, 0, SimpleStorage > SpaceType;
37
38 //typedef ParallelDofMapper< GridPartType, typename SpaceType::BlockMapperType > ParallelMapperType;
39 //typedef typename ParallelMapperType :: GlobalKeyType GlobalKeyType;
40
41 static const int dimensionworld = GridPartType::dimensionworld;
42
43 explicit DefaultUniqueFacetOrientation ( const GridPartType &gridPart )
44 : gridPart_( gridPart ),
45 dofManager_( DofManagerType::instance( gridPart_.grid() ) ),
46 uniqueDirection_( M_PI ),
47 sequence_( -1 )
48 {
49 if constexpr ( dimensionworld > 1 )
50 uniqueDirection_[ 1 ] = M_LN2;
51 if constexpr ( dimensionworld > 2 )
52 uniqueDirection_[ 2 ] = M_E;
53 }
54
55 void update() const
56 {
57 if( sequence_ != dofManager_.sequence() )
58 {
59 orientations_.resize( gridPart().indexSet().size(0) );
60 const auto& indexSet = gridPart().indexSet();
61 for( const auto& entity : elements( gridPart(), Partitions::all ) )
62 {
63 unsigned int orientations = 0;
64 for( auto intersection : intersections( gridPart(), entity ) )
65 {
66 if( intersection.neighbor() )
67 {
68 // make sure that the normal is not orthogonal to the uniqueDirection_
69 assert( std::abs(intersection.centerUnitOuterNormal() * uniqueDirection_) > 0 );
70
71 if( (intersection.centerUnitOuterNormal() * uniqueDirection_) > 0 )
72 {
73 orientations |= (1 << intersection.indexInInside());
74 }
75 }
76 }
77 orientations_[ indexSet.index( entity ) ] = orientations;
78 }
79 sequence_ = dofManager_.sequence();
80 }
81 }
82
83 unsigned int operator() ( const EntityType &entity ) const
84 {
85 update();
86 return orientations_[ gridPart().indexSet().index( entity ) ];
87 }
88
89 /*
90 unsigned int orientations = 0;
91 for( auto intersection : intersections( gridPart(), entity ) )
92 {
93 if( intersection.neighbor() && (globallyUniqueIndex( entity ) < globallyUniqueIndex( intersection.outside() )) )
94 orientations |= (1 << intersection.indexInInside());
95 }
96 return orientations;
97 */
98
99 /*
100 template <class Entity>
101 GlobalKeyType globallyUniqueIndex( const Entity& entity ) const
102 {
103 retu
104 GlobalKeyType index = -1;
105 // parallelMapper_.mapEach( entity, [ &index ] ( auto local, auto global ) { assert( local == 0 ); index = global; } );
106 return gridPart().indexSet().index(entity);
107 return index;
108 }
109 */
110
111 const GridPartType &gridPart () const { return gridPart_; }
112
113 protected:
114 const GridPartType& gridPart_;
115 const DofManagerType& dofManager_;
116 GlobalCoordinateType uniqueDirection_;
117 mutable std::vector< unsigned int > orientations_;
118 //SpaceType space_; // works without this
119 // mutable ParallelMapperType parallelMapper_;
120 mutable int sequence_;
121 };
122
123
124
125 // CartesianUniqueFacetOrientation
126 // -------------------------------
127
128 template< class GridPart >
129 struct CartesianUniqueFacetOrientation
130 {
131 typedef GridPart GridPartType;
132 typedef typename GridPart::template Codim< 0 >::EntityType EntityType;
133
134 explicit CartesianUniqueFacetOrientation ( const GridPartType &gridPart )
135 : gridPart_( gridPart )
136 {}
137
138 unsigned int operator() ( const EntityType &entity ) const
139 {
140 return orientations( std::make_index_sequence< GridPartType::dimension >() );
141 }
142
143 const GridPartType &gridPart () const { return gridPart_; }
144
145 private:
146 template< std::size_t... i >
147 static constexpr unsigned int orientations ( std::index_sequence< i... > )
148 {
149 return Std::sum( (1u << 2*i)... );
150 }
151
152 const GridPartType &gridPart_;
153 };
154
155
156
157 // UniqueFacetOrientation
158 // ----------------------
159
160 template< class GP >
161 using UniqueFacetOrientation =
162 typename std::conditional< GridPartCapabilities::isCartesian< GP >::v,
163 CartesianUniqueFacetOrientation< GP>,
164 DefaultUniqueFacetOrientation< GP > >::type;
165
166 } // namespace Fem
167
168} // namespace Dune
169
170#endif // #ifndef DUNE_FEM_SPACE_COMMON_UNIQUEFACETORIENTATION_HH
constexpr All all
PartitionSet for all partitions.
Definition: partitionset.hh:295
Dune namespace
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Feb 16, 23:40, 2026)