Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
errorfractionmarking.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef ERROR_FRACTION_MARKING_HH
5#define ERROR_FRACTION_MARKING_HH
6
7#include <vector>
8
10
14
16
31template <class GridType>
33{
34 private:
35
37 enum {dim = GridType::dimension};
38
40 struct AllCodimLayout {
41 bool operator() ([[maybe_unused]] Dune::GeometryType gt, int) const {
42 return true;
43 }
44 };
45
46 public:
47 static void mark(RefinementIndicator<GridType>& refinementIndicator,
48 GridType& grid,
49 double fraction);
50
61 static void mark(const std::vector<RefinementIndicator<GridType>* >& refinementIndicator,
62 const std::vector<GridType*>& grids,
63 double fraction);
64
65};
66
67template <class GridType>
69mark(RefinementIndicator<GridType>& refinementIndicator,
70 GridType& grid,
71 double fraction)
72{
73 std::vector<RefinementIndicator<GridType>* > refinementIndicatorInVector(1);
74 refinementIndicatorInVector[0] = &refinementIndicator;
75
76 std::vector<GridType*> gridInVector(1);
77 gridInVector[0] = &grid;
78
79 mark(refinementIndicatorInVector, gridInVector, fraction);
80}
81
82template <class GridType>
84mark(const std::vector<RefinementIndicator<GridType>*>& refinementIndicators,
85 const std::vector<GridType*>& grids,
86 double fraction)
87{
90
91 if (grids.size() != refinementIndicators.size())
92 DUNE_THROW(Dune::Exception, "The number of grids must match the number of error sets");
93
94 // /////////////////////////////////////////////////////////////////
95 // Create a map which stores the error for all elements of
96 // all grids and which can be traversed in sorted order.
97 // /////////////////////////////////////////////////////////////////
98 ErrorMap errorMap;
99
100 std::vector<Dune::BitSetVector<1> > refineIndex(grids.size());
101
102 // we need to sum the error indicators up
103 double totalError = 0.0;
104
105 for (size_t i=0; i<grids.size(); ++i)
106 {
107 // mapper that maps all entities to indices
108 AllCodimMapper mapper(*grids[i], AllCodimLayout());
109
110 // initialize bitfield
111 refineIndex[i].resize(mapper.size(), false);
112
113 // abuse bitfield for processed flags
114 Dune::BitSetVector<1>& entityProcessed = refineIndex[i];
115
116 for (const auto& e : elements(grids[i]->leafGridView()))
117 {
118 // Get set of shape functions
119 auto refElement
120 = Dune::ReferenceElements<double, dim>::general(e.type());
121
122 // Compute the indicator of any subentity of this element
123 for (int codim=0; codim<=dim; ++codim)
124 {
125 for (int entity=0; entity<refElement.size(codim); ++entity)
126 {
127 int entityIndex = mapper.subIndex(e, entity, codim);
128 if (not(entityProcessed[entityIndex][0]))
129 {
130 // map error indicator values to entity index and sum them up
131 double errorIndicator = (*refinementIndicators[i]).value(e, codim, entity);
132 totalError += errorIndicator;
133 errorMap.insert(std::pair<double, std::pair<int,int> >(errorIndicator, std::pair<int,int>(i, entityIndex)));
134 entityProcessed[entityIndex][0] = true;
135 }
136 }
137 }
138 }
139
140 // reset bitfields
141 entityProcessed.unsetAll();
142 }
143
144 // mark indicators by value fraction
145 {
146 double refinedError = 0.0;
147 for (const auto& e : errorMap)
148 {
149 refineIndex[e.second.first][e.second.second][0] = true;
150 refinedError += e.first;
151 if (refinedError >= totalError*fraction)
152 break;
153 }
154 }
155
156 for (size_t i=0; i<grids.size(); ++i)
157 {
158 AllCodimMapper mapper(*grids[i], AllCodimLayout());
159
160 for (const auto& e : elements(grids[i]->leafGridView()))
161 {
162 // Get set of shape functions
163 auto refElement
164 = Dune::ReferenceElements<double, dim>::general(e.type());
165
166 // Determine if the element is marked to refinement by any of its subentities
167 bool refineElement = false;
168 for (int codim=0; (codim<=dim) and not(refineElement); ++codim)
169 {
170 for (int entity=0; (entity<refElement.size(codim)) and not(refineElement); ++entity)
171 {
172 int entityIndex = mapper.subIndex(e, entity, codim);
173 if (refineIndex[i][entityIndex][0])
174 refineElement = true;
175 }
176 }
177 if (refineElement)
178 grids[i]->mark(1,e);
179 }
180 }
181}
182#endif
183
size_type dim() const
virtual void operator()()=0
#define DUNE_THROW(E,...)
This marking strategy marks local indicators providing a given fraction of the global error in descen...
Definition errorfractionmarking.hh:33
static void mark(RefinementIndicator< GridType > &refinementIndicator, GridType &grid, double fraction)
Definition errorfractionmarking.hh:69
Holds refinement indicators for a hierarchical grid.
Definition refinementindicator.hh:22
T resize(T... args)
T size(T... args)