DUNE PDELab (git)

gridinfo.hh
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5
6#ifndef DUNE_GRID_UTILITY_GRIDINFO_HH
7#define DUNE_GRID_UTILITY_GRIDINFO_HH
8
9#include <algorithm>
10#include <cstddef>
11#include <functional>
12#include <limits>
13#include <map>
14#include <ostream>
15#include <string>
16#include <vector>
17
21#include <dune/common/hybridutilities.hh>
22
23#include <dune/geometry/multilineargeometry.hh>
24#include <dune/geometry/referenceelements.hh>
25#include <dune/geometry/type.hh>
26
28
29namespace Dune {
30
32 template<class ctype>
33 struct EntityInfo {
35 std::size_t count;
37
42 ctype volumeMin;
44
49 ctype volumeMax;
50
52
56 ctype volumeSum;
57
59
65 count(0), volumeMin(std::numeric_limits<ctype>::infinity()),
66 volumeMax(-std::numeric_limits<ctype>::infinity()), volumeSum(0)
67 { }
68 };
69
71
78 public std::binary_function<GeometryType, GeometryType, bool>
79 {
81 inline bool operator()(const GeometryType &a, const GeometryType &b) const
82 {
83 return a.dim() < b.dim() ||
84 (a.dim() == b.dim() && (a.isNone() < b.isNone() ||
85 (a.isNone() == b.isNone() && (a.id() >> 1) < (b.id() >> 1))));
86 // topologyId is set to 0 for None, so no harm im comparing them even if
87 // isNone()==true
88 }
89 };
90
92
97 template<class ctype>
98 struct GridViewInfo :
99 public std::map<GeometryType, EntityInfo<ctype>, GridViewInfoGTCompare>
100 {
102 std::string gridName;
104 std::string gridViewName;
106
110 std::string partitionName;
111
113
126 void print(std::ostream &stream, std::string prefix) const {
127 if(!gridName.empty()) {
128 stream << prefix << gridName << ":\n";
129 prefix += " ";
130 }
131 if(!gridViewName.empty()) {
132 stream << prefix << gridViewName << ":\n";
133 prefix += " ";
134 }
135 if(!partitionName.empty()) {
136 stream << prefix << partitionName << ":\n";
137 prefix += " ";
138 }
139
140 typedef typename GridViewInfo::const_iterator Iterator;
141 std::size_t dim = ~0;
142 const Iterator &end = this->end();
143 for(Iterator it = this->begin(); it != end; ++it) {
144 if(it->first.dim() != dim) {
145 dim = it->first.dim();
146 stream << prefix << "Dim = " << dim << ":\n";
147 }
148 stream << prefix << " " << it->first << ": Count = "
149 << it->second.count << ", Volume range = "
150 << "(" << it->second.volumeMin << ".."
151 << it->second.volumeMax << "), Total volume = "
152 << it->second.volumeSum << "\n";
153 }
154 }
155 };
156
158
163 template<class ctype>
164 std::ostream &operator<<(std::ostream &stream,
165 const GridViewInfo<ctype> &info)
166 {
167 info.print(stream, "");
168 return stream;
169 }
170
171#ifndef DOXYGEN
173 template<int codim>
174 struct FillGridInfoOperation {
175 template<class Entity, class Mapper, class Visited, class RefElem>
176 static void apply(const Entity &e, const Mapper &mapper, Visited &visited,
177 const typename Entity::Geometry &geo,
178 RefElem refelem,
180 {
181 typedef typename Entity::Geometry::ctype ctype;
182 static const std::size_t dimw = Entity::Geometry::coorddimension;
183 static const std::size_t dim = Entity::dimension;
184 std::vector<FieldVector<ctype, dimw> > coords;
185 for(int i = 0; i < refelem.size(codim); ++i) {
186 int index = mapper.map(e, i, codim);
187 if(visited[index])
188 continue;
189 visited[index] = true;
190
191 GeometryType gt = refelem.type(i, codim);
192 coords.clear();
193 coords.resize( refelem.size(i, codim, dim) );
194 for(std::size_t corner = 0; corner < coords.size(); ++corner)
195 coords[ corner ] = geo.corner( refelem.subEntity( i, codim, corner, dim ) );
196 MultiLinearGeometry<ctype, dim-codim, dimw> mygeo(gt, coords);
197
198 ctype volume = mygeo.volume();
199 EntityInfo<ctype> &ei = gridViewInfo[mygeo.type()];
200 ei.volumeMin = std::min(ei.volumeMin, volume);
201 ei.volumeMax = std::max(ei.volumeMax, volume);
202 ei.volumeSum += volume;
203 }
204 }
205 };
206#endif // !DOXYGEN
207
209
213 template<class GV>
214 void fillGridViewInfoSerial(const GV &gv,
216 {
217 typedef typename GV::ctype ctype;
218 static const std::size_t dim = GV::dimension;
219 typedef typename GV::template Codim<0>::Iterator EIterator;
220 typedef typename GV::template Codim<0>::Geometry EGeometry;
221 typedef typename GV::IndexSet IndexSet;
222
223 typedef typename GridViewInfo<ctype>::iterator InfoIterator;
224
225 typedef ReferenceElements<ctype, dim> RefElems;
226
228 mapper(gv,
229 [](GeometryType gt, int) { return gt.dim() < GV::dimension; }
230 );
231 std::vector<bool> visited(mapper.size(), false);
232
233 gridViewInfo.gridName = className<typename GV::Grid>();
234 gridViewInfo.gridViewName = className<GV>();
235 gridViewInfo.partitionName = "";
236 gridViewInfo.clear();
237
238 const EIterator &eend = gv.template end<0>();
239 for(EIterator eit = gv.template begin<0>(); eit != eend; ++eit) {
240 ctype volume = eit->geometry().volume();
241 EntityInfo<ctype> &ei = gridViewInfo[eit->type()];
242 ei.volumeMin = std::min(ei.volumeMin, volume);
243 ei.volumeMax = std::max(ei.volumeMax, volume);
244 ei.volumeSum += volume;
245
246 if(!eit->type().isNone()) {
247 const EGeometry &geo = eit->geometry();
248 Hybrid::forEach(std::make_index_sequence< dim >{},
249 [ & ](auto i){ FillGridInfoOperation< i+1 >::apply(*eit, mapper, visited, geo, RefElems::general(eit->type()), gridViewInfo); } );
250 }
251 }
252
254 if(gridViewInfo.count(gt) > 0) {
255 for(std::size_t codim = 0; codim < dim; ++codim)
256 {
257 gt = GeometryTypes::none(dim-codim);
258 EntityInfo<ctype> & ei = gridViewInfo[gt];
259 ei.volumeMin = ei.volumeMax = ei.volumeSum =
260 std::numeric_limits<ctype>::quiet_NaN();
261 }
263 EntityInfo<ctype> & ei = gridViewInfo[gt];
264 ei.volumeMin = ei.volumeMax = ei.volumeSum = 0;
265 }
266
267 const InfoIterator &end = gridViewInfo.end();
268 const IndexSet &is = gv.indexSet();
269 for(InfoIterator it = gridViewInfo.begin(); it != end; ++it) {
270 it->second.count = is.size(it->first);
271 if(it->second.count == 0)
272 DUNE_THROW(Exception, "Found Entities of geomentry type " <<
273 it->first << " while iterating through the grid, but "
274 "indexSet.size() == 0 for that geometry type");
275 }
276
277 }
278
279} // namespace Dune
280
281
282#endif // DUNE_GRID_UTILITY_GRIDINFO_HH
Wrapper class for entities.
Definition: entity.hh:66
GridImp::template Codim< cd >::Geometry Geometry
The corresponding geometry type.
Definition: entity.hh:100
static constexpr int dimension
Know the grid dimension.
Definition: entity.hh:109
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:360
constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:365
constexpr bool isNone() const
Return true if entity is a singular of any dimension.
Definition: type.hh:355
Index Set Interface base class.
Definition: indexidset.hh:78
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:223
Mapper interface.
Definition: mapper.hh:110
auto size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mapper.hh:152
generic geometry implementation based on corner coordinates
Definition: multilineargeometry.hh:181
Volume volume() const
obtain the volume of the mapping's image
Definition: multilineargeometry.hh:363
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:129
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:218
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
constexpr GeometryType none(unsigned int dim)
Returns a GeometryType representing a singular of dimension dim.
Definition: type.hh:471
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
constexpr auto min
Function object that returns the smaller of the given values.
Definition: hybridutilities.hh:506
Mapper for multiple codim and multiple geometry types.
Dune namespace.
Definition: alignedallocator.hh:13
void fillGridViewInfoSerial(const GV &gv, GridViewInfo< typename GV::ctype > &gridViewInfo)
fill a GridViewInfo structure from a serial grid
Definition: gridinfo.hh:214
STL namespace.
Static tag representing a codimension.
Definition: dimension.hh:24
Structure to hold statistical information about one type of entity.
Definition: gridinfo.hh:33
ctype volumeMin
minimum volume of all entities in the set.
Definition: gridinfo.hh:42
ctype volumeMax
maximum volume of all entities in the set.
Definition: gridinfo.hh:49
ctype volumeSum
sum of volumes of all entities in the set.
Definition: gridinfo.hh:56
std::size_t count
number of entities in the set
Definition: gridinfo.hh:35
EntityInfo()
initialize the structure
Definition: gridinfo.hh:64
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:128
Comparison object to sort GeometryType by majorly dimension.
Definition: gridinfo.hh:79
bool operator()(const GeometryType &a, const GeometryType &b) const
compare two GeometryTypes
Definition: gridinfo.hh:81
structure to hold information about a certain GridView.
Definition: gridinfo.hh:100
std::ostream & operator<<(std::ostream &stream, const GridViewInfo< ctype > &info)
write a GridViewInfo object
Definition: gridinfo.hh:164
std::string gridViewName
name of the class of the GridView this information was extracted from
Definition: gridinfo.hh:104
std::string partitionName
name of the partition this information was extracted from
Definition: gridinfo.hh:110
std::string gridName
name of the grid class this information was extracted from
Definition: gridinfo.hh:102
void print(std::ostream &stream, std::string prefix) const
print the information contained in this object
Definition: gridinfo.hh:126
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 (Nov 24, 23:30, 2024)