dune-fem 2.12-git
Loading...
Searching...
No Matches
boundaryidprovider.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_MISC_BOUNDARYIDPROVIDER_HH
2#define DUNE_FEM_MISC_BOUNDARYIDPROVIDER_HH
3
6
7#include <dune/grid/common/capabilities.hh>
8
10
11namespace Dune
12{
13 namespace Fem
14 {
15
16 template< class Grid >
18 {
19 template <class T, class = int>
21
22 template <class T>
23 struct hasBoundaryId<T, decltype(std::declval<T>().impl().boundaryId())> : std::true_type {};
24
25 template< class Intersection >
26 static int boundaryId ( const Intersection &intersection )
27 {
28 static constexpr bool hasBndId = hasBoundaryId< Intersection >::value;
29
30 // for all grids that have the method, call it on the implementation
31 if constexpr ( hasBndId )
32 {
33 return intersection.impl().boundaryId();
34 }
35 else // otherwise use fallback
36 {
37 // Cartesian grids use indexInInside + 1
38 if constexpr ( Dune::Capabilities::isCartesian< Grid > :: v )
39 {
40 return (intersection.boundary() ? (intersection.indexInInside()+1) : 0);
41 }
42 else // e.g. UGGrid
43 {
44 return intersection.boundarySegmentIndex();
45 }
46 }
47 }
48 };
49
50 // BoundaryIdProvider for general GridParts or GridViews
51 // -----------------------------------------------------
52
54 template< class GridView, class Intersection>
55 inline static int boundaryId ( const Intersection &intersection )
56 {
58 boundaryId( intersection );
59 }
60
62 template< class GridView, class Intersection>
63 inline static int boundaryId ( const GridView&, const Intersection &intersection )
64 {
66 boundaryId( intersection );
67 }
68
69
70 /* \brief BoundaryId inspection: project boundary ids to piecewise constant
71 function. Elements with more than one boundary segment will
72 contain the sum of all boundary ids.
73 */
74 template <class DiscreteFunction>
75 void projectBoundaryIds( DiscreteFunction& df )
76 {
77 if( df.space().order() != 0 ) // should be piecewise constant, and FV space
78 {
79 DUNE_THROW(InvalidStateException,"projectBoundaryIds: expect piecewise constant discrete function");
80 }
81
82 df.clear(); // reset all dofs
83
84 const auto& gridPart = df.space().gridPart();
85
86 typedef AddLocalContribution< DiscreteFunction > AddLocalContributionType;
87 AddLocalContributionType localDf( df );
88 for( const auto& element : df.space() )
89 {
90 int count = 0;
91 auto guard = bindGuard( localDf, element );
92 for( const auto& intersection : intersections( gridPart, element ) )
93 {
94 if( intersection.boundary() )
95 {
96 localDf[ 0 ] += boundaryId( gridPart, intersection );
97 count += 1;
98 }
99 }
100 if (count>0)
101 localDf[ 0 ] /= double(count);
102 }
103 }
104
105 } // namespace Fem
106
107} // namespace Dune
108
109#endif // #ifndef DUNE_FEM_MISC_BOUNDARYIDPROVIDER_HH
#define DUNE_THROW(E,...)
STL namespace.
void projectBoundaryIds(DiscreteFunction &df)
Definition boundaryidprovider.hh:75
static int boundaryId(const Intersection &intersection)
this works for both, GridView and GridPart
Definition boundaryidprovider.hh:55
static auto bindGuard(Object &object, Args &&... args) -> std::enable_if_t< isBindable< Object, Args... >::value, BindGuard< Object > >
Definition bindguard.hh:67
bool boundary() const
int indexInInside() const
size_t boundarySegmentIndex() const
Implementation & impl()
Definition common/localcontribution.hh:14
Definition boundaryidprovider.hh:18
static int boundaryId(const Intersection &intersection)
Definition boundaryidprovider.hh:26
Definition boundaryidprovider.hh:20