From 633a40c1c0b38f3e11a3fcbb97fbd22d68fd92a0 Mon Sep 17 00:00:00 2001 From: Jonathan Youett <youett@math.fu-berlin.de> Date: Mon, 5 Oct 2015 11:57:59 +0200 Subject: [PATCH] Cleanup using range-based for-loops --- dune/fufem/boundarywriter.hh | 50 +++++++++++++++--------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/dune/fufem/boundarywriter.hh b/dune/fufem/boundarywriter.hh index d04e25d6..1e7a954f 100644 --- a/dune/fufem/boundarywriter.hh +++ b/dune/fufem/boundarywriter.hh @@ -11,6 +11,7 @@ template <class GridView> void writeBoundary(const BoundaryPatch<GridView>& surface, const std::string& filename) { + typedef typename GridView::ctype field_type; enum {dim = GridView::dimension}; const GridView& gv = surface.gridView(); @@ -58,17 +59,12 @@ void writeBoundary(const BoundaryPatch<GridView>& surface, const std::string& fi fprintf(fp, "\nVertices %lu\n", surfVertices.count()); - typedef typename GridView::template Codim<dim>::Iterator VertexIterator; - - VertexIterator vIt = gv.template begin<dim>(); - VertexIterator vEndIt = gv.template end<dim>(); - - Dune::BlockVector<Dune::FieldVector<double, dim> > coords(gv.size(dim)); + Dune::BlockVector<Dune::FieldVector<field_type, dim> > coords(gv.size(dim)); // resort the relevant coordinates so they appear ordered by their entities' indices - for (; vIt!=vEndIt; ++vIt) - if (surfVertices[indexSet.index(*vIt)][0]) - coords[indexSet.index(*vIt)] = vIt->geometry().corner(0); + for (const auto& v : vertices(gv)) + if (surfVertices[indexSet.index(v)][0]) + coords[indexSet.index(v)] = v.geometry().corner(0); // write coordinates for (size_t i=0; i<coords.size(); i++) @@ -94,13 +90,11 @@ void writeBoundary(const BoundaryPatch<GridView>& surface, const std::string& fi // quadrilaterals need to be transformed to two triangles because // Amira doesn't know quadrilateral surface :-((( int numFaces = 0; - // loop over all elements - typename BoundaryPatch<GridView>::iterator it = surface.begin(); - typename BoundaryPatch<GridView>::iterator endIt = surface.end(); - for (; it!=endIt; ++it) { + // loop over all elements + for (const auto it : surface) { - switch (it->geometry().corners()) { + switch (it.geometry().corners()) { case 3: numFaces++; break; @@ -116,25 +110,24 @@ void writeBoundary(const BoundaryPatch<GridView>& surface, const std::string& fi fprintf(fp, "Triangles %d\n", numFaces); // loop over all elements - it = surface.begin(); + for (const auto it : surface) { - for (; it!=endIt; ++it) { + const auto& inside = it.inside(); - const Dune::ReferenceElement<double,dim>& refElement = - Dune::ReferenceElements<double, dim>::general(it->inside()->type()); + const auto& refElement = Dune::ReferenceElements<field_type, dim>::general(inside.type()); - int n = refElement.size(it->indexInInside(), 1, dim); + int n = refElement.size(it.indexInInside(), 1, dim); fprintf(fp, " %d %d %d\n", - globalToLocal[indexSet.subIndex(*it->inside(), refElement.subEntity(it->indexInInside(), 1, 0, dim), dim)] + 1, - globalToLocal[indexSet.subIndex(*it->inside(), refElement.subEntity(it->indexInInside(), 1, 1, dim), dim)] + 1, - globalToLocal[indexSet.subIndex(*it->inside(), refElement.subEntity(it->indexInInside(), 1, 2, dim), dim)] + 1); + globalToLocal[indexSet.subIndex(inside, refElement.subEntity(it.indexInInside(), 1, 0, dim), dim)] + 1, + globalToLocal[indexSet.subIndex(inside, refElement.subEntity(it.indexInInside(), 1, 1, dim), dim)] + 1, + globalToLocal[indexSet.subIndex(inside, refElement.subEntity(it.indexInInside(), 1, 2, dim), dim)] + 1); if (n==4) fprintf(fp, " %d %d %d\n", - globalToLocal[indexSet.subIndex(*it->inside(), refElement.subEntity(it->indexInInside(), 1, 2, dim), dim)] + 1, - globalToLocal[indexSet.subIndex(*it->inside(), refElement.subEntity(it->indexInInside(), 1, 3, dim), dim)] + 1, - globalToLocal[indexSet.subIndex(*it->inside(), refElement.subEntity(it->indexInInside(), 1, 0, dim), dim)] + 1); + globalToLocal[indexSet.subIndex(inside, refElement.subEntity(it.indexInInside(), 1, 2, dim), dim)] + 1, + globalToLocal[indexSet.subIndex(inside, refElement.subEntity(it.indexInInside(), 1, 3, dim), dim)] + 1, + globalToLocal[indexSet.subIndex(inside, refElement.subEntity(it.indexInInside(), 1, 0, dim), dim)] + 1); } @@ -212,11 +205,8 @@ void writeLineSet(const BoundaryPatch<GridView>& surface, const std::string& fil fgrid<<"\n"; fgrid<<"@2 \n"; - typename BoundaryPatch<GridView>::iterator it = surface.begin(); - typename BoundaryPatch<GridView>::iterator itEnd = surface.end(); - - for (; it != itEnd; ++it) { - auto geom = it->geometry(); + for (const auto& it : surface) { + auto geom = it.geometry(); for (int i = 0; i <2; ++i) fgrid << geom.corner(i) <<" "<<0<<"\n"; } -- GitLab