DUNE-FEM (unstable)

default.hh
1#ifndef DUNE_FEMPY_PY_DEFAULT_MARKING_HH
2#define DUNE_FEMPY_PY_DEFAULT_MARKING_HH
3
4#include <array>
5#include <memory>
6#include <dune/geometry/referenceelements.hh>
7#include <dune/fem/gridpart/common/gridpart.hh>
8#include <dune/fem/function/localfunction/const.hh>
9
10namespace Dune
11{
12 namespace Fem
13 {
14 namespace GridAdaptation
15 {
16 struct Marker
17 {
18 static const int refine = 1;
19 static const int keep = 0;
20 static const int coarsen = -1;
21 };
22
23 // Indicator is of type DiscreteFunction
24 template <class Grid, class Indicator>
25 static inline
26 std::pair< int, int >
27 mark( Grid& grid, Indicator& indicator,
28 const double refineTolerance, const double coarsenTolerance,
29 const int minLevel = 0,
30 int maxLevel = -1,
31 const double minVolume = -1.,
32 double maxVolume = -1.0,
33 const bool markNeighbors = false )
34 {
35 Dune::Fem::ConstLocalFunction<Indicator> localIndicator(indicator);
36 typename Indicator::RangeType value;
37
38 std::array< int, 2 > sumMarks = {{ 0,0 }};
39
40 int& refMarked = sumMarks[ 0 ];
41 int& crsMarked = sumMarks[ 1 ];
42
43 if ( maxLevel < 0 )
45
46 const bool useVolumeRefinement = minVolume > 0.0;
47 const bool useVolumeCoarsening = maxVolume > 0.0;
48 if ( ! useVolumeCoarsening )
49 {
50 // this will avoid volume check
52 }
53
54 const auto& gridPart = indicator.space().gridPart();
55
56 for (const auto &e : indicator.space())
57 {
58 if (!e.isLeaf()) continue;
59
60 const auto &gridEntity = Dune::Fem::gridEntity(e);
61 int marked = grid.getMark(gridEntity);
62 if (marked==1) continue;
63
64 localIndicator.bind(e);
65 const auto &center = Dune::referenceElement< typename Grid::ctype, Grid::dimension>( e.type() ).position(0,0);
66 localIndicator.evaluate(center,value);
67 double eta = std::abs(value[0]);
68 const int level = e.level();
69
70 // compute volume only if necessary
71 const double volume = (useVolumeRefinement || useVolumeCoarsening) ? e.geometry().volume() : 0.0;
72
73 // check that estimator is larger than tolerance
74 // check that level is smaller than minimal level
75 // check that volume of element is larger than minimal acceptable volume
76 if (eta>refineTolerance && level<maxLevel && volume>minVolume)
77 {
78 refMarked += grid.mark( Marker::refine, gridEntity);
79 if( markNeighbors )
80 {
81 const auto iEnd = gridPart.iend( e );
82 for( auto it = gridPart.ibegin( e ); it != iEnd; ++it )
83 {
84 const auto& intersection = *it;
85 if( intersection.neighbor() )
86 {
87 const auto& outside = intersection.outside();
88 const double outsideVol = (useVolumeRefinement) ? outside.geometry().volume() : 0.0;
89 if (outside.level()<maxLevel && outsideVol>minVolume )
90 refMarked += grid.mark( Marker::refine, Dune::Fem::gridEntity(outside) );
91 }
92 }
93
94 }
95 }
96 else if (eta<coarsenTolerance && level>minLevel && volume<maxVolume )
97 crsMarked += grid.mark( Marker::coarsen, gridEntity);
98 else
99 grid.mark(Marker::keep, gridEntity);
100 }
101
102 grid.comm().sum( sumMarks.data(), 2 );
103 return std::make_pair( refMarked, crsMarked );
104 } // end mark
105
106 } // end namespace GridAdaptation
107
108 } // end namespace Fem
109} // end namespace Dune
110#endif
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
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)