1#ifndef DUNE_FEMPY_PY_DEFAULT_MARKING_HH
2#define DUNE_FEMPY_PY_DEFAULT_MARKING_HH
6#include <dune/geometry/referenceelements.hh>
7#include <dune/fem/gridpart/common/gridpart.hh>
8#include <dune/fem/function/localfunction/const.hh>
14 namespace GridAdaptation
18 static const int refine = 1;
19 static const int keep = 0;
20 static const int coarsen = -1;
24 template <
class Gr
id,
class Indicator>
27 mark( Grid& grid, Indicator& indicator,
28 const double refineTolerance,
const double coarsenTolerance,
29 const int minLevel = 0,
31 const double minVolume = -1.,
32 double maxVolume = -1.0,
33 const bool markNeighbors =
false )
35 Dune::Fem::ConstLocalFunction<Indicator> localIndicator(indicator);
36 typename Indicator::RangeType value;
38 std::array< int, 2 > sumMarks = {{ 0,0 }};
40 int& refMarked = sumMarks[ 0 ];
41 int& crsMarked = sumMarks[ 1 ];
46 const bool useVolumeRefinement = minVolume > 0.0;
47 const bool useVolumeCoarsening = maxVolume > 0.0;
48 if ( ! useVolumeCoarsening )
54 const auto& gridPart = indicator.space().gridPart();
56 for (
const auto &e : indicator.space())
58 if (!e.isLeaf())
continue;
60 const auto &gridEntity = Dune::Fem::gridEntity(e);
61 int marked = grid.getMark(gridEntity);
62 if (marked==1)
continue;
64 localIndicator.bind(e);
65 const auto ¢er = 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();
71 const double volume = (useVolumeRefinement || useVolumeCoarsening) ? e.geometry().volume() : 0.0;
76 if (eta>refineTolerance && level<maxLevel && volume>minVolume)
78 refMarked += grid.mark( Marker::refine, gridEntity);
81 const auto iEnd = gridPart.iend( e );
82 for(
auto it = gridPart.ibegin( e ); it != iEnd; ++it )
84 const auto& intersection = *it;
85 if( intersection.neighbor() )
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) );
96 else if (eta<coarsenTolerance && level>minLevel && volume<maxVolume )
97 crsMarked += grid.mark( Marker::coarsen, gridEntity);
99 grid.mark(Marker::keep, gridEntity);
102 grid.comm().sum( sumMarks.data(), 2 );
103 return std::make_pair( refMarked, crsMarked );
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
Dune namespace.
Definition: alignedallocator.hh:13