1#ifndef DUNE_FEM_MARKING_MAXIMUM_HH
2#define DUNE_FEM_MARKING_MAXIMUM_HH
21 namespace GridAdaptation
46 template <
class Gr
id,
class Indicator>
50 const double theta,
int maxLevel = -1 )
54 typedef Dune::ReferenceElements< typename Grid::ctype, Grid::dimension > ReferenceElements;
56 typename Indicator::RangeType value;
58 double totalError( 0 ), maxError( 0 );
59 for (
const auto &e : indicator.space())
61 if (!e.isLeaf())
continue;
62 localIndicator.bind(e);
63 const auto ¢er = ReferenceElements::general( e.type() ).position(0,0);
64 localIndicator.evaluate(center,value);
67 maxError =
max( maxError, eta );
69 maxError = grid.
comm().max( maxError );
70 totalError = grid.
comm().sum( totalError );
78 double m = (a.first + b.
first) /
double( 2 );
79 while( (m > a.first) && (a.second > theta*totalError) )
84 for (
const auto &e : indicator.space())
86 if (!e.isLeaf())
continue;
87 localIndicator.bind(e);
88 const auto ¢er = ReferenceElements::general( e.type() ).position(0,0);
89 localIndicator.evaluate(center,value);
90 double eta = value[0];
102 if( c.
second < theta*totalError )
106 m = (a.first + b.
first) /
double( 2 );
116 for (
const auto &e : indicator.space())
118 if (!e.isLeaf())
continue;
119 localIndicator.bind(e);
120 const auto ¢er = ReferenceElements::general( e.type() ).position(0,0);
121 localIndicator.evaluate(center,value);
122 double eta = value[0];
126 m = grid.
comm().max( m );
133 for (
const auto &e : indicator.space())
135 if (!e.isLeaf())
continue;
137 localIndicator.bind(e);
138 const auto ¢er = ReferenceElements::general( e.type() ).position(0,0);
139 localIndicator.evaluate(center,value);
140 double eta = value[0];
166 template <
class Gr
id,
class Indicator>
168 computeSumAndMaxGridWalk(
Grid& grid,
const Indicator& indicator,
171 typedef Dune::ReferenceElements< typename Grid::ctype, Grid::dimension > ReferenceElements;
173 typename Indicator::RangeType value;
174 double maxIndicator = 0;
175 double sumIndicator = 0;
176 for (
const auto &e : indicator.space())
178 if (!e.isLeaf())
continue;
179 localIndicator.bind(e);
180 const auto ¢er = ReferenceElements::general( e.type() ).position(0,0);
181 localIndicator.evaluate(center,value);
182 double eta = value[0];
183 maxIndicator =
std::max(maxIndicator,eta);
188 maxIndicator = indicator.space().gridPart().comm().max( maxIndicator );
189 sumIndicator = indicator.space().gridPart().comm().sum( sumIndicator );
191 for (
const auto &e : indicator.space())
193 if (!e.isLeaf())
continue;
194 localIndicator.bind(e);
195 const auto ¢er = ReferenceElements::general( e.type() ).position(0,0);
196 localIndicator.evaluate(center,value);
197 double eta = value[0];
198 int index = int(eta/maxIndicator*1./nu);
201 buckets[
index] += eta;
205 indicator.space().gridPart().comm().sum( buckets.
data(), buckets.
size() );
210 template <
class Gr
id,
class Indicator>
212 computeSumAndMax( Grid& grid,
const Indicator& indicator,
215 return computeSumAndMaxGridWalk( grid, indicator, nu, buckets );
218 template <
class Gr
id,
class Imp>
224 if( indicator.
space().order() > 0 )
225 return computeSumAndMaxGridWalk( grid, indicator, nu, buckets );
227 double maxIndicator = 0;
228 double sumIndicator = 0;
231 for (
const auto &d :
Dune::Fem::
dofs(indicator) )
233 maxIndicator =
std::max(maxIndicator,d);
238 maxIndicator = indicator.
space().gridPart().comm().max( maxIndicator );
239 sumIndicator = indicator.
space().gridPart().comm().sum( sumIndicator );
244 for (
const auto &d :
Dune::Fem::
dofs(indicator) )
246 int index = int(d/maxIndicator*1./nu);
252 indicator.
space().gridPart().comm().sum( buckets.
data(), buckets.
size() );
258 template <
class Gr
id,
class Indicator>
262 const double tolerance,
int maxLevel = -1,
270 typedef Dune::ReferenceElements< typename Grid::ctype, Grid::dimension > ReferenceElements;
272 typename Indicator::RangeType value;
278 auto sumMax = detail::computeSumAndMax( grid, indicator, nu, buckets );
279 double sumIndicator = sumMax.first;
280 double maxIndicator = sumMax.second;
287 index >= 0 && sum < (1-tolerance)*(1-tolerance)*sumIndicator;
290 sum += buckets[
index];
298 const double gammaMaxIndicator = gamma*maxIndicator ;
299 for (
const auto &e : indicator.space())
301 if (!e.isLeaf())
continue;
303 localIndicator.bind(e);
304 const auto ¢er = ReferenceElements::general( e.type() ).position(0,0);
305 localIndicator.evaluate(center,value);
306 double eta = value[0];
307 if (eta > gammaMaxIndicator )
320 assert( sum >= (1-tolerance)*(1-tolerance)*sumIndicator);
std::ptrdiff_t index() const
Dune::Fem::Double abs(const Dune::Fem::Double &a)
Definition double.hh:942
const GridEntityAccess< Entity >::GridEntityType & gridEntity(const Entity &entity)
Definition gridpart.hh:510
IteratorRange< typename DF::DofIteratorType > dofs(DF &df)
Iterates over all DOFs.
Definition rangegenerators.hh:76
typename Impl::ConstLocalFunction< GridFunction >::Type ConstLocalFunction
Definition const.hh:626
static double max(const Double &v, const double p)
Definition double.hh:398
static std::pair< int, int > layeredDoerflerMarking(Grid &grid, const Indicator &indicator, const double tolerance, int maxLevel=-1, double nu=0.05)
Definition doerfler.hh:261
static std::pair< int, int > doerflerMarking(Grid &grid, const Indicator &indicator, const double theta, int maxLevel=-1)
doerflerMarking
Definition doerfler.hh:49
bool mark(int refCount, const typename Codim< 0 >::Entity &e)
const Communication & comm() const
Definition common/discretefunction.hh:86
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition common/discretefunction.hh:214
static const int keep
Definition marking/default.hh:19
static const int refine
Definition marking/default.hh:18