Dune Core Modules (2.8.0)

gridinfo.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_GRID_UTILITY_GRIDINFO_HH
5#define DUNE_GRID_UTILITY_GRIDINFO_HH
6
7#include <algorithm>
8#include <cstddef>
9#include <functional>
10#include <limits>
11#include <map>
12#include <ostream>
13#include <string>
14#include <vector>
15
19#include <dune/common/hybridutilities.hh>
20
21#include <dune/geometry/multilineargeometry.hh>
22#include <dune/geometry/referenceelements.hh>
23#include <dune/geometry/type.hh>
24
26
27namespace Dune {
28
30 template<class ctype>
31 struct EntityInfo {
33 std::size_t count;
35
40 ctype volumeMin;
42
47 ctype volumeMax;
48
50
54 ctype volumeSum;
55
57
63 count(0), volumeMin(std::numeric_limits<ctype>::infinity()),
64 volumeMax(-std::numeric_limits<ctype>::infinity()), volumeSum(0)
65 { }
66 };
67
69
76 public std::binary_function<GeometryType, GeometryType, bool>
77 {
79 inline bool operator()(const GeometryType &a, const GeometryType &b) const
80 {
81 return a.dim() < b.dim() ||
82 (a.dim() == b.dim() && (a.isNone() < b.isNone() ||
83 (a.isNone() == b.isNone() && (a.id() >> 1) < (b.id() >> 1))));
84 // topologyId is set to 0 for None, so no harm im comparing them even if
85 // isNone()==true
86 }
87 };
88
90
95 template<class ctype>
96 struct GridViewInfo :
97 public std::map<GeometryType, EntityInfo<ctype>, GridViewInfoGTCompare>
98 {
100 std::string gridName;
102 std::string gridViewName;
104
108 std::string partitionName;
109
111
124 void print(std::ostream &stream, std::string prefix) const {
125 if(!gridName.empty()) {
126 stream << prefix << gridName << ":\n";
127 prefix += " ";
128 }
129 if(!gridViewName.empty()) {
130 stream << prefix << gridViewName << ":\n";
131 prefix += " ";
132 }
133 if(!partitionName.empty()) {
134 stream << prefix << partitionName << ":\n";
135 prefix += " ";
136 }
137
138 typedef typename GridViewInfo::const_iterator Iterator;
139 std::size_t dim = ~0;
140 const Iterator &end = this->end();
141 for(Iterator it = this->begin(); it != end; ++it) {
142 if(it->first.dim() != dim) {
143 dim = it->first.dim();
144 stream << prefix << "Dim = " << dim << ":\n";
145 }
146 stream << prefix << " " << it->first << ": Count = "
147 << it->second.count << ", Volume range = "
148 << "(" << it->second.volumeMin << ".."
149 << it->second.volumeMax << "), Total volume = "
150 << it->second.volumeSum << "\n";
151 }
152 }
153 };
154
156
161 template<class ctype>
162 std::ostream &operator<<(std::ostream &stream,
163 const GridViewInfo<ctype> &info)
164 {
165 info.print(stream, "");
166 return stream;
167 }
168
169#ifndef DOXYGEN
171 template<int codim>
172 struct FillGridInfoOperation {
173 template<class Entity, class Mapper, class Visited, class RefElem>
174 static void apply(const Entity &e, const Mapper &mapper, Visited &visited,
175 const typename Entity::Geometry &geo,
176 RefElem refelem,
178 {
179 typedef typename Entity::Geometry::ctype ctype;
180 static const std::size_t dimw = Entity::Geometry::coorddimension;
181 static const std::size_t dim = Entity::dimension;
182 std::vector<FieldVector<ctype, dimw> > coords;
183 for(int i = 0; i < refelem.size(codim); ++i) {
184 int index = mapper.map(e, i, codim);
185 if(visited[index])
186 continue;
187 visited[index] = true;
188
189 GeometryType gt = refelem.type(i, codim);
190 coords.clear();
191 coords.resize( refelem.size(i, codim, dim) );
192 for(std::size_t corner = 0; corner < coords.size(); ++corner)
193 coords[ corner ] = geo.corner( refelem.subEntity( i, codim, corner, dim ) );
194 MultiLinearGeometry<ctype, dim-codim, dimw> mygeo(gt, coords);
195
196 ctype volume = mygeo.volume();
197 EntityInfo<ctype> &ei = gridViewInfo[mygeo.type()];
198 ei.volumeMin = std::min(ei.volumeMin, volume);
199 ei.volumeMax = std::max(ei.volumeMax, volume);
200 ei.volumeSum += volume;
201 }
202 }
203 };
204#endif // !DOXYGEN
205
207
211 template<class GV>
212 void fillGridViewInfoSerial(const GV &gv,
214 {
215 typedef typename GV::ctype ctype;
216 static const std::size_t dim = GV::dimension;
217 typedef typename GV::template Codim<0>::Iterator EIterator;
218 typedef typename GV::template Codim<0>::Geometry EGeometry;
219 typedef typename GV::IndexSet IndexSet;
220
221 typedef typename GridViewInfo<ctype>::iterator InfoIterator;
222
223 typedef ReferenceElements<ctype, dim> RefElems;
224
226 mapper(gv,
227 [](GeometryType gt, int) { return gt.dim() < GV::dimension; }
228 );
229 std::vector<bool> visited(mapper.size(), false);
230
231 gridViewInfo.gridName = className<typename GV::Grid>();
232 gridViewInfo.gridViewName = className<GV>();
233 gridViewInfo.partitionName = "";
234 gridViewInfo.clear();
235
236 const EIterator &eend = gv.template end<0>();
237 for(EIterator eit = gv.template begin<0>(); eit != eend; ++eit) {
238 ctype volume = eit->geometry().volume();
239 EntityInfo<ctype> &ei = gridViewInfo[eit->type()];
240 ei.volumeMin = std::min(ei.volumeMin, volume);
241 ei.volumeMax = std::max(ei.volumeMax, volume);
242 ei.volumeSum += volume;
243
244 if(!eit->type().isNone()) {
245 const EGeometry &geo = eit->geometry();
246 Hybrid::forEach(std::make_index_sequence< dim >{},
247 [ & ](auto i){ FillGridInfoOperation< i+1 >::apply(*eit, mapper, visited, geo, RefElems::general(eit->type()), gridViewInfo); } );
248 }
249 }
250
252 if(gridViewInfo.count(gt) > 0) {
253 for(std::size_t codim = 0; codim < dim; ++codim)
254 {
255 gt = GeometryTypes::none(dim-codim);
256 EntityInfo<ctype> & ei = gridViewInfo[gt];
257 ei.volumeMin = ei.volumeMax = ei.volumeSum =
258 std::numeric_limits<ctype>::quiet_NaN();
259 }
261 EntityInfo<ctype> & ei = gridViewInfo[gt];
262 ei.volumeMin = ei.volumeMax = ei.volumeSum = 0;
263 }
264
265 const InfoIterator &end = gridViewInfo.end();
266 const IndexSet &is = gv.indexSet();
267 for(InfoIterator it = gridViewInfo.begin(); it != end; ++it) {
268 it->second.count = is.size(it->first);
269 if(it->second.count == 0)
270 DUNE_THROW(Exception, "Found Entities of geomentry type " <<
271 it->first << " while iterating through the grid, but "
272 "indexSet.size() == 0 for that geometry type");
273 }
274
275 }
276
277} // namespace Dune
278
279
280#endif // DUNE_GRID_UTILITY_GRIDINFO_HH
Wrapper class for entities.
Definition: entity.hh:64
GridImp::template Codim< cd >::Geometry Geometry
The corresponding geometry type.
Definition: entity.hh:98
@ dimension
Know the grid dimension.
Definition: entity.hh:109
Base class for Dune-Exceptions.
Definition: exceptions.hh:94
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:369
constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:374
constexpr bool isNone() const
Return true if entity is a singular of any dimension.
Definition: type.hh:364
Index Set Interface base class.
Definition: indexidset.hh:76
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:221
Mapper interface.
Definition: mapper.hh:108
auto size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mapper.hh:150
generic geometry implementation based on corner coordinates
Definition: multilineargeometry.hh:179
Volume volume() const
obtain the volume of the mapping's image
Definition: multilineargeometry.hh:355
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:127
A free function to provide the demangled class name of a given object or type as a string.
A few common exception classes.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:156
constexpr GeometryType none(unsigned int dim)
Returns a GeometryType representing a singular of dimension dim.
Definition: type.hh:479
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:266
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:87
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
Mapper for multiple codim and multiple geometry types.
Dune namespace.
Definition: alignedallocator.hh:11
void fillGridViewInfoSerial(const GV &gv, GridViewInfo< typename GV::ctype > &gridViewInfo)
fill a GridViewInfo structure from a serial grid
Definition: gridinfo.hh:212
STL namespace.
Static tag representing a codimension.
Definition: dimension.hh:22
Structure to hold statistical information about one type of entity.
Definition: gridinfo.hh:31
ctype volumeMin
minimum volume of all entities in the set.
Definition: gridinfo.hh:40
ctype volumeMax
maximum volume of all entities in the set.
Definition: gridinfo.hh:47
ctype volumeSum
sum of volumes of all entities in the set.
Definition: gridinfo.hh:54
std::size_t count
number of entities in the set
Definition: gridinfo.hh:33
EntityInfo()
initialize the structure
Definition: gridinfo.hh:62
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:168
Comparison object to sort GeometryType by majorly dimension.
Definition: gridinfo.hh:77
bool operator()(const GeometryType &a, const GeometryType &b) const
compare two GeometryTypes
Definition: gridinfo.hh:79
structure to hold information about a certain GridView.
Definition: gridinfo.hh:98
std::ostream & operator<<(std::ostream &stream, const GridViewInfo< ctype > &info)
write a GridViewInfo object
Definition: gridinfo.hh:162
std::string gridViewName
name of the class of the GridView this information was extracted from
Definition: gridinfo.hh:102
std::string partitionName
name of the partition this information was extracted from
Definition: gridinfo.hh:108
std::string gridName
name of the grid class this information was extracted from
Definition: gridinfo.hh:100
void print(std::ostream &stream, std::string prefix) const
print the information contained in this object
Definition: gridinfo.hh:124
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)