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 Intersection >
20 static int boundaryId ( const Intersection &intersection )
21 {
22 // for all grids that have the method, call it on the implementation
23 if constexpr ( requires{ intersection.impl().boundaryId(); })
24 {
25 return intersection.impl().boundaryId();
26 }
27 else // otherwise use fallback
28 {
29 // Cartesian grids use indexInInside + 1
30 if constexpr ( Dune::Capabilities::isCartesian< Grid > :: v )
31 {
32 return (intersection.boundary() ? (intersection.indexInInside()+1) : 0);
33 }
34 else // e.g. UGGrid
35 {
36 return intersection.boundarySegmentIndex();
37 }
38 }
39 }
40 };
41
42 // BoundaryIdProvider for general GridParts or GridViews
43 // -----------------------------------------------------
44
46 template< class GridView, class Intersection>
47 inline static int boundaryId ( const Intersection &intersection )
48 {
50 boundaryId( intersection );
51 }
52
54 template< class GridView, class Intersection>
55 inline static int boundaryId ( const GridView&, const Intersection &intersection )
56 {
58 boundaryId( intersection );
59 }
60
61
62 /* \brief BoundaryId inspection: project boundary ids to piecewise constant
63 function. Elements with more than one boundary segment will
64 contain the sum of all boundary ids.
65 */
66 template <class DiscreteFunction>
67 void projectBoundaryIds( DiscreteFunction& df )
68 {
69 if( df.space().order() != 0 ) // should be piecewise constant, and FV space
70 {
71 DUNE_THROW(InvalidStateException,"projectBoundaryIds: expect piecewise constant discrete function");
72 }
73
74 df.clear(); // reset all dofs
75
76 const auto& gridPart = df.space().gridPart();
77
78 typedef AddLocalContribution< DiscreteFunction > AddLocalContributionType;
79 AddLocalContributionType localDf( df );
80 for( const auto& element : df.space() )
81 {
82 int count = 0;
83 auto guard = bindGuard( localDf, element );
84 for( const auto& intersection : intersections( gridPart, element ) )
85 {
86 if( intersection.boundary() )
87 {
88 localDf[ 0 ] += boundaryId( gridPart, intersection );
89 count += 1;
90 }
91 }
92 if (count>0)
93 localDf[ 0 ] /= double(count);
94 }
95 }
96
97 } // namespace Fem
98
99} // namespace Dune
100
101#endif // #ifndef DUNE_FEM_MISC_BOUNDARYIDPROVIDER_HH
#define DUNE_THROW(E,...)
void projectBoundaryIds(DiscreteFunction &df)
Definition boundaryidprovider.hh:67
static int boundaryId(const Intersection &intersection)
this works for both, GridView and GridPart
Definition boundaryidprovider.hh:47
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:20