Skip to content
Snippets Groups Projects
Commit 633a40c1 authored by Jonathan Youett's avatar Jonathan Youett
Browse files

Cleanup using range-based for-loops

parent ce2ed688
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
template <class GridView> template <class GridView>
void writeBoundary(const BoundaryPatch<GridView>& surface, const std::string& filename) void writeBoundary(const BoundaryPatch<GridView>& surface, const std::string& filename)
{ {
typedef typename GridView::ctype field_type;
enum {dim = GridView::dimension}; enum {dim = GridView::dimension};
const GridView& gv = surface.gridView(); const GridView& gv = surface.gridView();
...@@ -58,17 +59,12 @@ void writeBoundary(const BoundaryPatch<GridView>& surface, const std::string& fi ...@@ -58,17 +59,12 @@ void writeBoundary(const BoundaryPatch<GridView>& surface, const std::string& fi
fprintf(fp, "\nVertices %lu\n", surfVertices.count()); fprintf(fp, "\nVertices %lu\n", surfVertices.count());
typedef typename GridView::template Codim<dim>::Iterator VertexIterator; Dune::BlockVector<Dune::FieldVector<field_type, dim> > coords(gv.size(dim));
VertexIterator vIt = gv.template begin<dim>();
VertexIterator vEndIt = gv.template end<dim>();
Dune::BlockVector<Dune::FieldVector<double, dim> > coords(gv.size(dim));
// resort the relevant coordinates so they appear ordered by their entities' indices // resort the relevant coordinates so they appear ordered by their entities' indices
for (; vIt!=vEndIt; ++vIt) for (const auto& v : vertices(gv))
if (surfVertices[indexSet.index(*vIt)][0]) if (surfVertices[indexSet.index(v)][0])
coords[indexSet.index(*vIt)] = vIt->geometry().corner(0); coords[indexSet.index(v)] = v.geometry().corner(0);
// write coordinates // write coordinates
for (size_t i=0; i<coords.size(); i++) for (size_t i=0; i<coords.size(); i++)
...@@ -94,13 +90,11 @@ void writeBoundary(const BoundaryPatch<GridView>& surface, const std::string& fi ...@@ -94,13 +90,11 @@ void writeBoundary(const BoundaryPatch<GridView>& surface, const std::string& fi
// quadrilaterals need to be transformed to two triangles because // quadrilaterals need to be transformed to two triangles because
// Amira doesn't know quadrilateral surface :-((( // Amira doesn't know quadrilateral surface :-(((
int numFaces = 0; 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: case 3:
numFaces++; numFaces++;
break; break;
...@@ -116,25 +110,24 @@ void writeBoundary(const BoundaryPatch<GridView>& surface, const std::string& fi ...@@ -116,25 +110,24 @@ void writeBoundary(const BoundaryPatch<GridView>& surface, const std::string& fi
fprintf(fp, "Triangles %d\n", numFaces); fprintf(fp, "Triangles %d\n", numFaces);
// loop over all elements // 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 = const auto& refElement = Dune::ReferenceElements<field_type, dim>::general(inside.type());
Dune::ReferenceElements<double, dim>::general(it->inside()->type());
int n = refElement.size(it->indexInInside(), 1, dim); int n = refElement.size(it.indexInInside(), 1, dim);
fprintf(fp, " %d %d %d\n", fprintf(fp, " %d %d %d\n",
globalToLocal[indexSet.subIndex(*it->inside(), refElement.subEntity(it->indexInInside(), 1, 0, dim), dim)] + 1, globalToLocal[indexSet.subIndex(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(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, 2, dim), dim)] + 1);
if (n==4) if (n==4)
fprintf(fp, " %d %d %d\n", fprintf(fp, " %d %d %d\n",
globalToLocal[indexSet.subIndex(*it->inside(), refElement.subEntity(it->indexInInside(), 1, 2, dim), dim)] + 1, globalToLocal[indexSet.subIndex(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(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, 0, dim), dim)] + 1);
} }
...@@ -212,11 +205,8 @@ void writeLineSet(const BoundaryPatch<GridView>& surface, const std::string& fil ...@@ -212,11 +205,8 @@ void writeLineSet(const BoundaryPatch<GridView>& surface, const std::string& fil
fgrid<<"\n"; fgrid<<"\n";
fgrid<<"@2 \n"; fgrid<<"@2 \n";
typename BoundaryPatch<GridView>::iterator it = surface.begin(); for (const auto& it : surface) {
typename BoundaryPatch<GridView>::iterator itEnd = surface.end(); auto geom = it.geometry();
for (; it != itEnd; ++it) {
auto geom = it->geometry();
for (int i = 0; i <2; ++i) for (int i = 0; i <2; ++i)
fgrid << geom.corner(i) <<" "<<0<<"\n"; fgrid << geom.corner(i) <<" "<<0<<"\n";
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment