KASKADE 7 development version
errorest.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2013-2015 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef ERROREST_HH
14#define ERROREST_HH
15
16#include <vector>
17
18#include <boost/fusion/include/for_each.hpp>
19#include <boost/utility.hpp>
20#include <boost/multi_array.hpp>
21
22#include "grid/common/rangegenerators.hh"
23
24namespace Kaskade
25{
31 {
32 public:
42 std::vector<double> threshold(boost::multi_array<double,2> const& normalizedErrors) const;
43
44 private:
45 virtual double computeThreshold(std::vector<double>& normalizedErrors, double totalError, int j) const = 0;
46 };
47
52 template <class GridManager, class GridView>
53 void markAndRefine(GridManager& gridManager, GridView const& gridView, boost::multi_array<double,2> const& normalizedErrors,
54 std::vector<double> const& threshold)
55 {
56 for (auto const& cell: Dune::elements(gridView))
57 {
58 auto idx = gridView.indexSet().index(cell);
59 for (int j=0; j<threshold.size(); ++j)
60 if (normalizedErrors[idx][j] >= threshold[j])
61 {
62 gridManager.mark(1,cell);
63 break;
64 }
65 }
66 gridManager.adaptAtOnce();
67 }
68
81 {
82 public:
83 FixedFractionCriterion(double fraction = 0.2);
84
85 private:
86 double fraction;
87 virtual double computeThreshold(std::vector<double>& normalizedErrors, double totalError, int j) const;
88 };
89
99 {
100 public:
101 BulkCriterion(double fraction = 0.2);
102
103 private:
104 double fraction;
105 virtual double computeThreshold(std::vector<double>& normalizedErrors, double totalError, int j) const;
106 };
107
115 {
116 public:
117 MaxValueCriterion(double fraction = 0.2);
118
119 private:
120 double fraction;
121 virtual double computeThreshold(std::vector<double>& normalizedErrors, double totalError, int j) const;
122 };
123
135 {
136 public:
137 BabuskaRheinboldtCriterion(std::vector<int> const& order);
138
139 private:
140 std::vector<int> order;
141 virtual double computeThreshold(std::vector<double>& normalizedErrors, double totalError, int j) const;
142 };
143
144 //---------------------------------------------------------------------------------------------
145
146 namespace ErrorestDetail
147 {
154 template <class GroupByCell>
156 {
157 GroupedSummationCollector(GroupByCell const& group_):
158 group(group_)
159 {}
160
161 template <class Cell>
162 int integrationOrder(Cell const& , int shapeFunctionOrder) const
163 {
164 return shapeFunctionOrder;
165 }
166
167 // need to define this because boost::multi_array does not perform assignment if the arrays have
168 // different shape.
170 {
171 auto shape = c.sums.shape();
172
173 sums.resize(boost::extents[shape[0]][shape[1]]);
174 sums = c.sums;
175 group = c.group;
176
177 return *this;
178 }
179
180 template <class Cell, class Index, class LocalPosition, class Sequence>
181 void operator()(Cell const& /* cell */, Index idx,
182 LocalPosition const& /* xi */, double weight,
183 Sequence const& x)
184 {
185 if (sums.num_elements()==0)
186 sums.resize(boost::extents[group.nGroups][boost::fusion::size(x)]);
187 int i = 0; // for_each needs constant functor...
188 boost::fusion::for_each(x,Add(sums,group[idx],i,weight));
189 }
190
192 {
193 auto shape = c.sums.shape();
194 auto myshape = sums.shape();
195
196 if(c.sums.num_elements()==0) // no data in collector c
197 return;
198
199 if (sums.num_elements()==0 || myshape[0]!=shape[0] || myshape[1]!=shape[1]) // I'm not yet initialized
200 {
201 sums.resize(boost::extents[shape[0]][shape[1]]);
202 sums = c.sums; // -> do a simple copy
203 }
204 else
205 for (size_t i=0; i<shape[0]; ++i) // otherwise add up
206 for (size_t j=0; j<shape[1]; ++j)
207 sums[i][j] += c.sums[i][j];
208 }
209
210 boost::multi_array<double,2> sums;
211
212 private:
213 GroupByCell group;
214
215 struct Add
216 {
217 Add(boost::multi_array<double,2>& sums_, int idx_, int& i_, double w_):
218 sums(sums_), idx(idx_), i(i_) , w(w_)
219 {}
220
221 template <class T>
222 void operator()(T const& t) const { sums[idx][i++] += w*t; }
223
224 private:
225 boost::multi_array<double,2>& sums;
226 int idx;
227 int& i;
228 double w;
229 };
230 };
231
232 }
233}
234
235#endif
Babuska-Rheinboldt refinement criterion. Determines the refinement thresholds such that all cells wit...
Definition: errorest.hh:135
BabuskaRheinboldtCriterion(std::vector< int > const &order)
Bulk refinement criterion. Determines the refinement thresholds such that approximately the specified...
Definition: errorest.hh:99
BulkCriterion(double fraction=0.2)
Fixed fraction refinement criterion. Determines the refinement thresholds such that at least the spec...
Definition: errorest.hh:81
FixedFractionCriterion(double fraction=0.2)
bool adaptAtOnce()
DEPRECATED Performs grid refinement without prolongating registered FE functions.
Definition: gridmanager.hh:390
bool mark(int refCount, typename Grid::template Codim< 0 >::Entity const &cell)
Marks the given cell for refinement or coarsening.
Definition: gridmanager.hh:330
Class that takes care of the transfer of data (of each FunctionSpaceElement) after modification of th...
Definition: gridmanager.hh:680
Max value refinement criterion. Determines the refinement thresholds such that all cells with an erro...
Definition: errorest.hh:115
MaxValueCriterion(double fraction=0.2)
Base class for refinement criteria.
Definition: errorest.hh:31
std::vector< double > threshold(boost::multi_array< double, 2 > const &normalizedErrors) const
Computes the thresholds for refinement.
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
Definition: gridBasics.hh:35
void markAndRefine(GridManager &gridManager, GridView const &gridView, boost::multi_array< double, 2 > const &normalizedErrors, std::vector< double > const &threshold)
Refines the grid according to the normalized errors and the given thresholds.
Definition: errorest.hh:53
A Collector coalescing the information of multi-variable functions on cell groups.
Definition: errorest.hh:156
void join(GroupedSummationCollector< GroupByCell > const &c)
Definition: errorest.hh:191
GroupedSummationCollector(GroupByCell const &group_)
Definition: errorest.hh:157
boost::multi_array< double, 2 > sums
Definition: errorest.hh:210
int integrationOrder(Cell const &, int shapeFunctionOrder) const
Definition: errorest.hh:162
void operator()(Cell const &, Index idx, LocalPosition const &, double weight, Sequence const &x)
Definition: errorest.hh:181
GroupedSummationCollector< GroupByCell > & operator=(GroupedSummationCollector< GroupByCell > const &c)
Definition: errorest.hh:169