diff --git a/opm/models/discretization/common/fvbaseboundarycontext.hh b/opm/models/discretization/common/fvbaseboundarycontext.hh index 7661508d3..9cce40d96 100644 --- a/opm/models/discretization/common/fvbaseboundarycontext.hh +++ b/opm/models/discretization/common/fvbaseboundarycontext.hh @@ -77,8 +77,15 @@ public: void increment() { const auto& iend = gridView().iend(element()); - while (intersectionIt_ != iend && !intersectionIt_->boundary()) - ++ intersectionIt_; + + if(intersectionIt_ == iend) + return; + + ++intersectionIt_; + // iterate to the next boundary intersection + while (intersectionIt_ != iend && !intersectionIt_->boundary()) { + ++intersectionIt_; + } } /*! @@ -245,7 +252,7 @@ public: * * \param boundaryFaceIdx The local index of the boundary segment */ - const Intersection& intersection(unsigned boundaryFaceIdx OPM_UNUSED) const + const Intersection intersection(unsigned boundaryFaceIdx OPM_UNUSED) const { return *intersectionIt_; } /*! diff --git a/opm/models/discretization/common/fvbaselocalresidual.hh b/opm/models/discretization/common/fvbaselocalresidual.hh index d8d0ccb61..cad090709 100644 --- a/opm/models/discretization/common/fvbaselocalresidual.hh +++ b/opm/models/discretization/common/fvbaselocalresidual.hh @@ -425,6 +425,9 @@ protected: return; BoundaryContext boundaryCtx(elemCtx); + // move the iterator to the first boundary + if(!boundaryCtx.intersection(0).boundary()) + boundaryCtx.increment(); // evaluate the boundary for all boundary faces of the current context size_t numBoundaryFaces = boundaryCtx.numBoundaryFaces(/*timeIdx=*/0);