version 3.10-dev
markelements.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_ADAPTIVE_MARKELEMENTS_HH
13#define DUMUX_ADAPTIVE_MARKELEMENTS_HH
14
15#include <dune/grid/common/rangegenerators.hh>
16
17namespace Dumux {
18
27template<class Grid, class Indicator>
28bool markElements(Grid& grid, const Indicator& indicator, bool verbose = true)
29{
30 // mark elements according to indicator
31 std::size_t refine = 0;
32 std::size_t coarsen = 0;
33 for (const auto& element : elements(grid.leafGridView(), Dune::Partitions::interior))
34 {
35 const auto mark = indicator(element);
36 if (mark > 0)
37 {
38 grid.mark(1, element);
39 ++refine;
40 }
41 else if (mark < 0)
42 {
43 grid.mark(-1, element);
44 ++coarsen;
45 }
46 }
47
48 // abort if nothing in grid is marked
49 const std::size_t sumRefine = grid.comm().sum(refine);
50 const std::size_t sumCoarsen = grid.comm().sum(coarsen);
51
52 if (grid.comm().rank() == 0 && verbose)
53 std::cout << sumRefine << " cells have been marked to be refined, "
54 << sumCoarsen << " to be coarsened." << std::endl;
55
56 // return whether or not anything has been marked
57 return sumRefine != 0 || sumCoarsen != 0;
58}
59
60} //end namespace Dumux
61
62#endif
bool markElements(Grid &grid, const Indicator &indicator, bool verbose=true)
A function to mark element for refinement or coarsening.
Definition: markelements.hh:28
Definition: adapt.hh:17