From 210f6194bfafa377e75534edac347088102faba1 Mon Sep 17 00:00:00 2001
From: Bernd Flemisch <bernd@iws.uni-stuttgart.de>
Date: Fri, 16 Oct 2015 11:07:16 +0200
Subject: [PATCH] [range-for] adapt remaining intersection loops in
 LocalResiduals

In the LocalResiduals, there are several protected functions taking
an IntersectionIterator,
    void eval...(const IntersectionIterator &isIt,

In order to be callable with an (address of an) intersection, the
explicit requirement on the type IntersectionIterator has been
relaxed:
    template<class InetrsectionIterator>
    void eval...(const IntersectionIterator &isIt,

In a future steps these functions will be deprecated and replaced by
equivalents that take intersection objects.

Discussed with and approved by Christoph.
---
 dumux/freeflow/stokes/stokeslocalresidual.hh  | 16 +++++-----
 dumux/implicit/box/boxlocalresidual.hh        | 15 +++++-----
 .../implicit/cellcentered/cclocalresidual.hh  | 29 +++++++++----------
 dumux/implicit/mpnc/mpnclocalresidual.hh      |  2 +-
 .../stokesnccouplinglocalresidual.hh          | 24 +++++++--------
 .../stokesncnicouplinglocalresidual.hh        | 24 +++++++--------
 6 files changed, 51 insertions(+), 59 deletions(-)

diff --git a/dumux/freeflow/stokes/stokeslocalresidual.hh b/dumux/freeflow/stokes/stokeslocalresidual.hh
index f461f00028..e47482ac97 100644
--- a/dumux/freeflow/stokes/stokeslocalresidual.hh
+++ b/dumux/freeflow/stokes/stokeslocalresidual.hh
@@ -77,8 +77,6 @@ protected:
     typedef typename GET_PROP_TYPE(TypeTag, VolumeVariables) VolumeVariables;
     typedef typename GET_PROP_TYPE(TypeTag, FluxVariables) FluxVariables;
     typedef typename GET_PROP_TYPE(TypeTag, ElementVolumeVariables) ElementVolumeVariables;
-
-    typedef typename GridView::IntersectionIterator IntersectionIterator;
     typedef typename GET_PROP_TYPE(TypeTag, BoundaryTypes) BoundaryTypes;
 
     static const bool enableUnsymmetrizedVelocityGradient = GET_PROP_VALUE(TypeTag, EnableUnsymmetrizedVelocityGradient);
@@ -354,16 +352,14 @@ protected:
             // evaluate boundary conditions for the intersections of
             // the current element
             const BoundaryTypes &bcTypes = this->bcTypes_(scvIdx);
-            IntersectionIterator isIt = this->gridView_().ibegin(this->element_());
-            const IntersectionIterator &isEndIt = this->gridView_().iend(this->element_());
-            for (; isIt != isEndIt; ++isIt)
+            for (const auto& intersection : Dune::intersections(this->gridView_(), this->element_()))
             {
                 // handle only intersections on the boundary
-                if (!isIt->boundary())
+                if (!intersection.boundary())
                     continue;
 
                 // assemble the boundary for all vertices of the current face
-                const int fIdx = isIt->indexInInside();
+                const int fIdx = intersection.indexInInside();
                 const int numFaceVertices = refElement.size(fIdx, 1, dim);
 
                 // loop over the single vertices on the current face
@@ -410,8 +406,8 @@ protected:
                     }
 
                     // evaluate fluxes at a single boundary segment
-                    asImp_()->evalNeumannSegment_(isIt, scvIdx, boundaryFaceIdx, boundaryVars);
-                    asImp_()->evalOutflowSegment_(isIt, scvIdx, boundaryFaceIdx, boundaryVars);
+                    asImp_()->evalNeumannSegment_(&intersection, scvIdx, boundaryFaceIdx, boundaryVars);
+                    asImp_()->evalOutflowSegment_(&intersection, scvIdx, boundaryFaceIdx, boundaryVars);
 
                     // count the number of outer faces to determine, if we are on
                     // a corner point and if an interpolation should be done
@@ -442,6 +438,7 @@ protected:
      * \brief Evaluate and add Neumann boundary conditions for a single sub-control
      *        volume face to the local residual.
      */
+    template <class IntersectionIterator>
     void evalNeumannSegment_(const IntersectionIterator &isIt,
                              const int scvIdx,
                              const int boundaryFaceIdx,
@@ -506,6 +503,7 @@ protected:
     /*!
      * \brief Evaluate outflow boundary conditions for a single SCV face on the boundary.
      */
+    template <class IntersectionIterator>
     void evalOutflowSegment_(const IntersectionIterator &isIt,
                              const int scvIdx,
                              const int boundaryFaceIdx,
diff --git a/dumux/implicit/box/boxlocalresidual.hh b/dumux/implicit/box/boxlocalresidual.hh
index 8a838534a9..7ed39c9365 100644
--- a/dumux/implicit/box/boxlocalresidual.hh
+++ b/dumux/implicit/box/boxlocalresidual.hh
@@ -55,7 +55,6 @@ class BoxLocalResidual : public ImplicitLocalResidual<TypeTag>
     };
 
     typedef typename GridView::template Codim<0>::Entity Element;
-    typedef typename GridView::IntersectionIterator IntersectionIterator;
 
     typedef typename GridView::Grid::ctype CoordScalar;
     typedef typename Dune::ReferenceElements<CoordScalar, dim> ReferenceElements;
@@ -114,15 +113,13 @@ protected:
         Dune::GeometryType geoType = this->element_().geometry().type();
         const ReferenceElement &refElement = ReferenceElements::general(geoType);
 
-        IntersectionIterator isIt = this->gridView_().ibegin(this->element_());
-        const IntersectionIterator &isEndIt = this->gridView_().iend(this->element_());
-        for (; isIt != isEndIt; ++isIt)
+        for (const auto& intersection : Dune::intersections(this->gridView_(), this->element_()))
         {
             // handle only faces on the boundary
-            if (isIt->boundary()) {
+            if (intersection.boundary()) {
                 // Assemble the boundary for all vertices of the current
                 // face
-                int fIdx = isIt->indexInInside();
+                int fIdx = intersection.indexInInside();
                 int numFaceVerts = refElement.size(fIdx, 1, dim);
                 for (int faceVertexIdx = 0;
                     faceVertexIdx < numFaceVerts;
@@ -138,11 +135,11 @@ protected:
 
                     // add the residual of all vertices of the boundary
                     // segment
-                    this->asImp_().evalNeumannSegment_(isIt,
+                    this->asImp_().evalNeumannSegment_(&intersection,
                                                        scvIdx,
                                                        boundaryFaceIdx);
                     // evaluate the outflow conditions at the boundary face
-                    this->asImp_().evalOutflowSegment_(isIt,
+                    this->asImp_().evalOutflowSegment_(&intersection,
                                                        scvIdx,
                                                        boundaryFaceIdx);
                 }
@@ -154,6 +151,7 @@ protected:
      * \brief Add Neumann boundary conditions for a single sub-control
      *        volume face to the local residual.
      */
+    template <class IntersectionIterator>
     void evalNeumannSegment_(const IntersectionIterator &isIt,
                              const int scvIdx,
                              const int boundaryFaceIdx)
@@ -194,6 +192,7 @@ protected:
     * \param scvIdx The index of the considered face of the sub-control volume
     * \param boundaryFaceIdx The index of the considered boundary face of the sub control volume
     */
+    template <class IntersectionIterator>
     void evalOutflowSegment_(const IntersectionIterator &isIt,
                             const int scvIdx,
                             const int boundaryFaceIdx)
diff --git a/dumux/implicit/cellcentered/cclocalresidual.hh b/dumux/implicit/cellcentered/cclocalresidual.hh
index e6cc8084be..e0841d7cce 100644
--- a/dumux/implicit/cellcentered/cclocalresidual.hh
+++ b/dumux/implicit/cellcentered/cclocalresidual.hh
@@ -52,7 +52,6 @@ class CCLocalResidual : public ImplicitLocalResidual<TypeTag>
     };
 
     typedef typename GridView::template Codim<0>::Entity Element;
-    typedef typename GridView::IntersectionIterator IntersectionIterator;
     typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) PrimaryVariables;
     typedef typename GET_PROP_TYPE(TypeTag, BoundaryTypes) BoundaryTypes;
     typedef typename GET_PROP_TYPE(TypeTag, FVElementGeometry) FVElementGeometry;
@@ -73,28 +72,26 @@ protected:
      */
     void evalBoundaryFluxes_()
     {
-        IntersectionIterator isIt = this->gridView_().ibegin(this->element_());
-        const IntersectionIterator &isEndIt = this->gridView_().iend(this->element_());
-        for (; isIt != isEndIt; ++isIt)
+        for (const auto& intersection : Dune::intersections(this->gridView_(), this->element_()))
         {
             // handle only faces on the boundary
-            if (!isIt->boundary())
+            if (!intersection.boundary())
                 continue;
 
             BoundaryTypes bcTypes;
-            this->problem_().boundaryTypes(bcTypes, *isIt);
+            this->problem_().boundaryTypes(bcTypes, intersection);
 
             // evaluate the Neumann conditions at the boundary face
             if (bcTypes.hasNeumann())
-                this->asImp_().evalNeumannSegment_(isIt, bcTypes);
+                this->asImp_().evalNeumannSegment_(&intersection, bcTypes);
 
             // evaluate the outflow conditions at the boundary face
             if (bcTypes.hasOutflow())
-                this->asImp_().evalOutflowSegment_(isIt, bcTypes);
+                this->asImp_().evalOutflowSegment_(&intersection, bcTypes);
 
             // evaluate the pure Dirichlet conditions at the boundary face
             if (bcTypes.hasDirichlet() && !bcTypes.hasNeumann())
-                this->asImp_().evalDirichletSegment_(isIt, bcTypes);
+                this->asImp_().evalDirichletSegment_(&intersection, bcTypes);
         }
     }
 
@@ -104,25 +101,24 @@ protected:
      */
     void evalDirichlet_()
     {
-        IntersectionIterator isIt = this->gridView_().ibegin(this->element_());
-        const IntersectionIterator &isEndIt = this->gridView_().iend(this->element_());
-        for (; isIt != isEndIt; ++isIt)
+        for (const auto& intersection : Dune::intersections(this->gridView_(), this->element_()))
         {
             // handle only faces on the boundary
-            if (!isIt->boundary())
+            if (!intersection.boundary())
                 continue;
 
             BoundaryTypes bcTypes;
-            this->problem_().boundaryTypes(bcTypes, *isIt);
+            this->problem_().boundaryTypes(bcTypes, intersection);
 
             if (bcTypes.hasDirichlet() && bcTypes.hasNeumann())
-                this->asImp_().evalDirichletSegmentMixed_(isIt, bcTypes);
+                this->asImp_().evalDirichletSegmentMixed_(&intersection, bcTypes);
         }
     }
 
     /*!
      * \brief Add Neumann boundary conditions for a single intersection
      */
+    template <class IntersectionIterator>
     void evalNeumannSegment_(const IntersectionIterator &isIt,
                              const BoundaryTypes &bcTypes)
     {
@@ -152,6 +148,7 @@ protected:
     /*!
      * \brief Add outflow boundary conditions for a single intersection
      */
+    template <class IntersectionIterator>
     void evalOutflowSegment_(const IntersectionIterator &isIt,
                              const BoundaryTypes &bcTypes)
     {
@@ -211,6 +208,7 @@ protected:
      * \brief Treat Dirichlet boundary conditions in a weak sense for a single
      *        intersection that only has Dirichlet boundary conditions
      */
+    template <class IntersectionIterator>
     void evalDirichletSegment_(const IntersectionIterator &isIt,
                                    const BoundaryTypes &bcTypes)
     {
@@ -236,6 +234,7 @@ protected:
      * \brief Treat Dirichlet boundary conditions in a strong sense for a
      *        single intersection that has mixed D/N boundary conditions
      */
+    template <class IntersectionIterator>
     void evalDirichletSegmentMixed_(const IntersectionIterator &isIt,
                                     const BoundaryTypes &bcTypes)
     {
diff --git a/dumux/implicit/mpnc/mpnclocalresidual.hh b/dumux/implicit/mpnc/mpnclocalresidual.hh
index 92b2595cf6..ac9afb3406 100644
--- a/dumux/implicit/mpnc/mpnclocalresidual.hh
+++ b/dumux/implicit/mpnc/mpnclocalresidual.hh
@@ -61,7 +61,6 @@ protected:
     enum {phase0NcpIdx = Indices::phase0NcpIdx};
 
     typedef typename GridView::template Codim<0>::Entity Element;
-    typedef typename GridView::IntersectionIterator IntersectionIterator;
     typedef typename GET_PROP_TYPE(TypeTag, FVElementGeometry) FVElementGeometry;
     typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) PrimaryVariables;
     typedef typename GET_PROP_TYPE(TypeTag, VolumeVariables) VolumeVariables;
@@ -277,6 +276,7 @@ public:
      * 		\param isIt
      * 		\param bcTypes
      */
+    template <class IntersectionIterator>
     void evalDirichletSegment_(const IntersectionIterator &isIt,
                                const BoundaryTypes &bcTypes)
     {
diff --git a/dumux/multidomain/couplinglocalresiduals/stokesnccouplinglocalresidual.hh b/dumux/multidomain/couplinglocalresiduals/stokesnccouplinglocalresidual.hh
index 7ea9d3feac..e5d9d4511b 100644
--- a/dumux/multidomain/couplinglocalresiduals/stokesnccouplinglocalresidual.hh
+++ b/dumux/multidomain/couplinglocalresiduals/stokesnccouplinglocalresidual.hh
@@ -91,8 +91,6 @@ protected:
 
     typedef typename GET_PROP_TYPE(TypeTag, VolumeVariables) VolumeVariables;
     typedef typename GET_PROP_TYPE(TypeTag, FluxVariables) FluxVariables;
-
-    typedef typename GridView::IntersectionIterator IntersectionIterator;
     typedef typename GET_PROP_TYPE(TypeTag, BoundaryTypes) BoundaryTypes;
 
     static const bool useMoles = GET_PROP_VALUE(TypeTag, UseMoles);
@@ -120,16 +118,14 @@ public:
             // evaluate boundary conditions for the intersections of
             // the current element
             const BoundaryTypes &bcTypes = this->bcTypes_(idx);
-            IntersectionIterator isIt = this->gridView_().ibegin(this->element_());
-            const IntersectionIterator &endIt = this->gridView_().iend(this->element_());
-            for (; isIt != endIt; ++isIt)
+            for (const auto& intersection : Dune::intersections(this->gridView_(), this->element_()))
             {
                 // handle only intersections on the boundary
-                if (!isIt->boundary())
+                if (!intersection.boundary())
                     continue;
 
                 // assemble the boundary for all vertices of the current face
-                const int fIdx = isIt->indexInInside();
+                const int fIdx = intersection.indexInInside();
                 const int numFaceVertices = refElement.size(fIdx, 1, dim);
 
                 // loop over the single vertices on the current face
@@ -175,13 +171,13 @@ public:
                     }
 
                     // evaluate fluxes at a single boundary segment
-                    asImp_()->evalNeumannSegment_(isIt, idx, boundaryFaceIdx, boundaryVars);
-                    asImp_()->evalOutflowSegment_(isIt, idx, boundaryFaceIdx, boundaryVars);
+                    asImp_()->evalNeumannSegment_(&intersection, idx, boundaryFaceIdx, boundaryVars);
+                    asImp_()->evalOutflowSegment_(&intersection, idx, boundaryFaceIdx, boundaryVars);
 
                     //for the corner points, the boundary flux across the vertical non-coupling boundary faces
                     //has to be calculated to fulfill the mass balance
                     //convert suddomain intersection into multidomain intersection and check whether it is an outer boundary
-                    if(!GridView::Grid::multiDomainIntersection(*isIt).neighbor()
+                    if(!GridView::Grid::multiDomainIntersection(intersection).neighbor()
                            && this->boundaryHasMortarCoupling_(this->bcTypes_(idx)))
                     {
                        const GlobalPosition& globalPos = this->fvGeometry_().subContVol[idx].global;
@@ -214,8 +210,8 @@ public:
                     // Beavers-Joseph condition at the coupling boundary/interface
                     if(boundaryHasCoupling_(bcTypes) || boundaryHasMortarCoupling_(bcTypes))
                     {
-                        evalBeaversJoseph_(isIt, idx, boundaryFaceIdx, boundaryVars);
-                        asImp_()->evalCouplingVertex_(isIt, idx, boundaryFaceIdx, boundaryVars);
+                        evalBeaversJoseph_(&intersection, idx, boundaryFaceIdx, boundaryVars);
+                        asImp_()->evalCouplingVertex_(&intersection, idx, boundaryFaceIdx, boundaryVars);
                     }
 
                     // count the number of outer faces to determine, if we are on
@@ -261,6 +257,7 @@ protected:
      * \brief Evaluate one part of the Dirichlet-like coupling conditions for a single
      *        sub-control volume face; rest is done in the local coupling operator
      */
+    template <class IntersectionIterator>
     void evalCouplingVertex_(const IntersectionIterator &isIt,
                              const int scvIdx,
                              const int boundaryFaceIdx,
@@ -304,6 +301,7 @@ protected:
         }
     }
 
+    template <class IntersectionIterator>
     void evalBeaversJoseph_(const IntersectionIterator &isIt,
                             const int scvIdx,
                             const int boundaryFaceIdx,
@@ -344,7 +342,7 @@ protected:
             //set NEUMANN flux (set equal to pressure in problem)
 //             PrimaryVariables priVars(0.0);
 //             this->problem_().neumann(priVars, this->element_(), this->fvGeometry_(),
-//                             *isIt, scvIdx, boundaryFaceIdx);
+//                             intersection, scvIdx, boundaryFaceIdx);
 //             for (int dimIdx=0; dimIdx < dim; ++dimIdx)
 //                 this->residual_[scvIdx][dimIdx] += priVars[dimIdx]*
 //                                                    boundaryFaceArea;
diff --git a/dumux/multidomain/couplinglocalresiduals/stokesncnicouplinglocalresidual.hh b/dumux/multidomain/couplinglocalresiduals/stokesncnicouplinglocalresidual.hh
index 4a419f77d0..2a68740f67 100644
--- a/dumux/multidomain/couplinglocalresiduals/stokesncnicouplinglocalresidual.hh
+++ b/dumux/multidomain/couplinglocalresiduals/stokesncnicouplinglocalresidual.hh
@@ -92,8 +92,6 @@ namespace Dumux
 
         typedef typename GET_PROP_TYPE(TypeTag, VolumeVariables) VolumeVariables;
         typedef typename GET_PROP_TYPE(TypeTag, FluxVariables) FluxVariables;
-
-        typedef typename GridView::IntersectionIterator IntersectionIterator;
         typedef typename GET_PROP_TYPE(TypeTag, BoundaryTypes) BoundaryTypes;
 
         static const bool useMoles = GET_PROP_VALUE(TypeTag, UseMoles);
@@ -121,16 +119,14 @@ namespace Dumux
                 // evaluate boundary conditions for the intersections of
                 // the current element
                 const BoundaryTypes &bcTypes = this->bcTypes_(idx);
-                IntersectionIterator isIt = this->gridView_().ibegin(this->element_());
-                const IntersectionIterator &endIt = this->gridView_().iend(this->element_());
-                for (; isIt != endIt; ++isIt)
+                for (const auto& intersection : Dune::intersections(this->gridView_(), this->element_()))
                 {
                     // handle only intersections on the boundary
-                    if (!isIt->boundary())
+                    if (!intersection.boundary())
                         continue;
 
                     // assemble the boundary for all vertices of the current face
-                    const int fIdx = isIt->indexInInside();
+                    const int fIdx = intersection.indexInInside();
                     const int numFaceVertices = refElement.size(fIdx, 1, dim);
 
                     // loop over the single vertices on the current face
@@ -176,13 +172,13 @@ namespace Dumux
                         }
 
                         // evaluate fluxes at a single boundary segment
-                        asImp_()->evalNeumannSegment_(isIt, idx, boundaryFaceIdx, boundaryVars);
-                        asImp_()->evalOutflowSegment_(isIt, idx, boundaryFaceIdx, boundaryVars);
+                        asImp_()->evalNeumannSegment_(&intersection, idx, boundaryFaceIdx, boundaryVars);
+                        asImp_()->evalOutflowSegment_(&intersection, idx, boundaryFaceIdx, boundaryVars);
 
                         //for the corner points, the boundary flux across the vertical non-coupling boundary faces
                         //has to be calculated to fulfill the mass balance
                         //convert suddomain intersection into multidomain intersection and check whether it is an outer boundary
-                        if(!GridView::Grid::multiDomainIntersection(*isIt).neighbor()
+                        if(!GridView::Grid::multiDomainIntersection(intersection).neighbor()
                            && (this->boundaryHasMortarCoupling_(this->bcTypes_(idx)) || this->momentumBalanceHasNeumann_(this->bcTypes_(idx))))
                         {
                             const GlobalPosition& globalPos = this->fvGeometry_().subContVol[idx].global;
@@ -217,11 +213,11 @@ namespace Dumux
                         // Beavers-Joseph condition at the coupling boundary/interface
                         if(boundaryHasCoupling_(bcTypes))
                         {
-                            evalBeaversJoseph_(isIt, idx, boundaryFaceIdx, boundaryVars);
+                            evalBeaversJoseph_(&intersection, idx, boundaryFaceIdx, boundaryVars);
                         }
                         if(boundaryHasCoupling_(bcTypes) || boundaryHasMortarCoupling_(bcTypes))
                         {
-                            asImp_()->evalCouplingVertex_(isIt, idx, boundaryFaceIdx, boundaryVars);
+                            asImp_()->evalCouplingVertex_(&intersection, idx, boundaryFaceIdx, boundaryVars);
                         }
                         // count the number of outer faces to determine, if we are on
                         // a corner point and if an interpolation should be done
@@ -266,6 +262,7 @@ namespace Dumux
          * \brief Evaluate one part of the Dirichlet-like coupling conditions for a single
          *        sub-control volume face; rest is done in the local coupling operator
          */
+        template <class IntersectionIterator>
         void evalCouplingVertex_(const IntersectionIterator &isIt,
                                  const int scvIdx,
                                  const int boundaryFaceIdx,
@@ -315,6 +312,7 @@ namespace Dumux
             }
         }
 
+        template <class IntersectionIterator>
         void evalBeaversJoseph_(const IntersectionIterator &isIt,
                                 const int scvIdx,
                                 const int boundaryFaceIdx,
@@ -355,7 +353,7 @@ namespace Dumux
                 //set NEUMANN flux (set equal to pressure in problem)
 //                 PrimaryVariables priVars(0.0);
 //                 this->problem_().neumann(priVars, this->element_(), this->fvGeometry_(),
-//                                     *isIt, scvIdx, boundaryFaceIdx);
+//                                     intersection, scvIdx, boundaryFaceIdx);
 //                 for (int dimIdx=0; dimIdx < dim; ++dimIdx)
 //                     this->residual_[scvIdx][dimIdx] += priVars[dimIdx]*
 //                                                     boundaryFaceArea;
-- 
GitLab