4 #ifndef DUNE_GRID_UTILITY_GRIDINFO_HH
5 #define DUNE_GRID_UTILITY_GRIDINFO_HH
16 #include <dune/common/classname.hh>
17 #include <dune/common/exceptions.hh>
18 #include <dune/common/fvector.hh>
19 #include <dune/common/hybridutilities.hh>
20 #include <dune/common/std/utility.hh>
22 #include <dune/geometry/multilineargeometry.hh>
23 #include <dune/geometry/referenceelements.hh>
24 #include <dune/geometry/type.hh>
77 public std::binary_function<GeometryType, GeometryType, bool>
82 return a.dim() < b.dim() ||
83 (a.dim() == b.dim() && (a.isNone() < b.isNone() ||
84 (a.isNone() == b.isNone() && (a.id() >> 1) < (b.id() >> 1))));
98 public std::map<GeometryType, EntityInfo<ctype>, GridViewInfoGTCompare>
125 void print(std::ostream &stream, std::string prefix)
const {
127 stream << prefix <<
gridName <<
":\n";
139 typedef typename GridViewInfo::const_iterator Iterator;
140 std::size_t dim = ~0;
141 const Iterator &end = this->end();
142 for(Iterator it = this->begin(); it != end; ++it) {
143 if(it->first.dim() != dim) {
144 dim = it->first.dim();
145 stream << prefix <<
"Dim = " << dim <<
":\n";
147 stream << prefix <<
" " << it->first <<
": Count = "
148 << it->second.count <<
", Volume range = "
149 <<
"(" << it->second.volumeMin <<
".."
150 << it->second.volumeMax <<
"), Total volume = "
151 << it->second.volumeSum <<
"\n";
162 template<
class ctype>
166 info.
print(stream,
"");
173 struct FillGridInfoOperation {
174 template<
class Entity,
class Mapper,
class Visited,
class RefElem>
175 static void apply(
const Entity &e,
const Mapper &mapper, Visited &visited,
180 typedef typename Entity::Geometry::ctype ctype;
181 static const std::size_t dimw = Entity::Geometry::coorddimension;
183 std::vector<FieldVector<ctype, dimw> > coords;
184 for(
int i = 0; i < refelem.size(codim); ++i) {
185 int index = mapper.map(e, i, codim);
188 visited[index] =
true;
192 coords.resize( refelem.size(i, codim, dim) );
193 for(std::size_t corner = 0; corner < coords.size(); ++corner)
194 coords[ corner ] = geo.corner( refelem.subEntity( i, codim, corner, dim ) );
195 MultiLinearGeometry<ctype, dim-codim, dimw> mygeo(gt, coords);
197 ctype volume = mygeo.volume();
206 template<
int dimgr
id>
207 struct MCMGNonElementLayout {
208 bool contains(
GeometryType gt)
const {
return gt.dim() < dimgrid; }
221 typedef typename GV::ctype ctype;
222 static const std::size_t dim = GV::dimension;
223 typedef typename GV::template Codim<0>::Iterator EIterator;
224 typedef typename GV::template Codim<0>::Geometry EGeometry;
225 typedef typename GV::IndexSet
IndexSet;
229 typedef ReferenceElements<ctype, dim> RefElems;
232 std::vector<bool> visited(mapper.
size(),
false);
234 gridViewInfo.
gridName = className<typename GV::Grid>();
237 gridViewInfo.clear();
239 const EIterator &eend = gv.template end<0>();
240 for(EIterator eit = gv.template begin<0>(); eit != eend; ++eit) {
241 ctype volume = eit->geometry().volume();
247 if(!eit->type().isNone()) {
248 const EGeometry &geo = eit->geometry();
249 Hybrid::forEach(Std::make_index_sequence< dim >{},
250 [ & ](
auto i){ FillGridInfoOperation< i+1 >::apply(*eit, mapper, visited, geo, RefElems::general(eit->type()), gridViewInfo); } );
256 if(gridViewInfo.count(gt) > 0) {
257 for(std::size_t codim = 0; codim < dim; ++codim) {
258 gt.makeNone(dim-codim);
261 std::numeric_limits<ctype>::quiet_NaN();
268 const InfoIterator &end = gridViewInfo.end();
270 for(InfoIterator it = gridViewInfo.begin(); it != end; ++it) {
271 it->second.count = is.
size(it->first);
272 if(it->second.count == 0)
273 DUNE_THROW(Exception,
"Found Entities of geomentry type " <<
274 it->first <<
" while iterating through the grid, but "
275 "indexSet.size() == 0 for that geometry type");
283 #endif // DUNE_GRID_UTILITY_GRIDINFO_HH