Commit a4faf367 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

boundary-element-iterator iterates correctly over entites

parent 16b2f8b8
...@@ -2,17 +2,18 @@ ...@@ -2,17 +2,18 @@
namespace AMDiS namespace AMDiS
{ {
template <MeshView> template <class MeshView>
class BoundaryFacetIterator; class BoundaryFacetIterator;
// An Iterator over all elements and when element hasBoundaryIntersections // An Iterator over all elements and when element hasBoundaryIntersections
template <MeshView> template <class MeshView>
class BoundaryElementIterator class BoundaryElementIterator
{ {
friend template <class> class BoundaryFacetIterator; friend class BoundaryFacetIterator<MeshView>;
using Element = typename MeshView::Codim<0>::Entity; using Self = BoundaryElementIterator;
using ElementIterator = typename MeshView::Codim<1>::Iterator; using Element = typename MeshView::template Codim<0>::Entity;
using ElementIterator = typename MeshView::template Codim<0>::Iterator;
class Iterator class Iterator
{ {
...@@ -25,10 +26,11 @@ namespace AMDiS ...@@ -25,10 +26,11 @@ namespace AMDiS
Iterator(Iterator const&) = default; Iterator(Iterator const&) = default;
Iterator& operator=(Iterator const&) = default; Iterator& operator=(Iterator const&) = default;
// iterate to next element that has boundary intersections
Iterator& operator++() Iterator& operator++()
{ {
++elementIt; ++elementIt;
while (!elementIt->hasBoundaryIntersections() && elementIt != endIt) while (elementIt != endIt && !elementIt->hasBoundaryIntersections())
++elementIt; ++elementIt;
return *this; return *this;
} }
...@@ -40,22 +42,22 @@ namespace AMDiS ...@@ -40,22 +42,22 @@ namespace AMDiS
return tmp; return tmp;
} }
Element& operator*() const Element const& operator*() const
{ {
return *elementIt; return *elementIt;
} }
Element* operator->() const Element const* operator->() const
{ {
return &(*elementIt); return &(*elementIt);
} }
bool operator==(Iterator const& that) bool operator==(Iterator const& that) const
{ {
return elementIt == that.elementIt; return elementIt == that.elementIt;
} }
bool operator!=(Iterator const& that) bool operator!=(Iterator const& that) const
{ {
return !(*this == that); return !(*this == that);
} }
...@@ -67,14 +69,14 @@ namespace AMDiS ...@@ -67,14 +69,14 @@ namespace AMDiS
public: public:
/// Constructor. /// Constructor.
BoundaryElementIterator(MeshView& meshView) BoundaryElementIterator(MeshView const& meshView)
: meshView(meshView) : meshView(meshView)
{} {}
Iterator begin() { Iterator begin() {
auto elementIt = elements(meshView).begin(); auto elementIt = elements(meshView).begin();
auto endIt = elements(meshView).end(); auto endIt = elements(meshView).end();
while (!elementIt->hasBoundaryIntersections() && elementIt != endIt) while (elementIt != endIt && !elementIt->hasBoundaryIntersections())
++elementIt; ++elementIt;
return {elementIt, endIt}; return {elementIt, endIt};
...@@ -85,13 +87,13 @@ namespace AMDiS ...@@ -85,13 +87,13 @@ namespace AMDiS
} }
private: private:
MeshView& meshView; MeshView const& meshView;
}; };
/// Generator function for the boundary-element iterator /// Generator function for the boundary-element iterator
template <class MeshView> template <class MeshView>
BoundaryElementIterator<MeshView> boundary_elements(MeshView& meshView) BoundaryElementIterator<MeshView> boundary_elements(MeshView const& meshView)
{ {
return {meshView}; return {meshView};
} }
...@@ -100,11 +102,11 @@ namespace AMDiS ...@@ -100,11 +102,11 @@ namespace AMDiS
// An Iterator over all elements and when element hasBoundaryIntersections, then // An Iterator over all elements and when element hasBoundaryIntersections, then
// iterate over all boundary-intersections with given Index, oder for thos with // iterate over all boundary-intersections with given Index, oder for thos with
// predicate returns true // predicate returns true
template <MeshView> template <class MeshView>
class BoundaryFacetIterator class BoundaryFacetIterator
{ {
using Element = typename MeshView::Codim<0>::Entity; using Element = typename MeshView::template Codim<0>::Entity;
using Facet = typename MeshView::Codim<1>::Entity; using Facet = typename MeshView::template Codim<1>::Entity;
using ElementIterator = typename BoundaryElementIterator<MeshView>::Iterator; using ElementIterator = typename BoundaryElementIterator<MeshView>::Iterator;
using FacetIterator = typename MeshView::IntersectionIterator; using FacetIterator = typename MeshView::IntersectionIterator;
...@@ -112,7 +114,7 @@ namespace AMDiS ...@@ -112,7 +114,7 @@ namespace AMDiS
class Iterator class Iterator
{ {
public: public:
Iterator(MeshView& meshView, Iterator(MeshView const& meshView,
ElementIterator elementIt, ElementIterator elementIt,
FacetIterator facetIt, FacetIterator facetIt,
ElementIterator endIt) ElementIterator endIt)
...@@ -125,15 +127,20 @@ namespace AMDiS ...@@ -125,15 +127,20 @@ namespace AMDiS
Iterator(Iterator const&) = default; Iterator(Iterator const&) = default;
Iterator& operator=(Iterator const&) = default; Iterator& operator=(Iterator const&) = default;
// iterate to next boundary face within current element or to the first
// boundary face in the next boundary element
Iterator& operator++() Iterator& operator++()
{ {
++facetIt; ++facetIt;
do { do {
auto facetEndIt = intersections(meshView, *elementIt).end(); auto facetEndIt = intersections(meshView, *elementIt).end();
while (!facetIt->boundary() && facetIt != facetEndIt) while (facetIt != facetEndIt && !facetIt->boundary())
++facetIt; ++facetIt;
if (facetIt == facetEndIt) if (facetIt != facetEndIt)
++elementIt; break;
++elementIt;
facetIt = intersections(meshView, *elementIt).begin();
} while (elementIt != endIt); } while (elementIt != endIt);
return *this; return *this;
...@@ -146,36 +153,37 @@ namespace AMDiS ...@@ -146,36 +153,37 @@ namespace AMDiS
return tmp; return tmp;
} }
Facet& operator*() const // returns Dune::Intersection
auto const& operator*() const
{ {
return *facetIt; return *facetIt;
} }
Facet* operator->() const auto const* operator->() const
{ {
return &(*facetIt); return &(*facetIt);
} }
bool operator==(Iterator const& that) bool operator==(Iterator const& that) const
{ {
return elementIt == that.elementIt && (elementIt == endIt || facetIt == that.facetIt); return elementIt == that.elementIt && (elementIt == endIt || facetIt == that.facetIt);
} }
bool operator!=(Iterator const& that) bool operator!=(Iterator const& that) const
{ {
return !(*this == that); return !(*this == that);
} }
private: private:
MeshView& meshView; MeshView const& meshView;
ElementIterator elementIt; ElementIterator elementIt;
ElementIterator endIt;
FacetIterator facetIt; FacetIterator facetIt;
ElementIterator endIt;
}; };
public: public:
/// Constructor. /// Constructor.
BoundaryFacetIterator(MeshView& meshView) BoundaryFacetIterator(MeshView const& meshView)
: meshView(meshView) : meshView(meshView)
{} {}
...@@ -183,29 +191,28 @@ namespace AMDiS ...@@ -183,29 +191,28 @@ namespace AMDiS
auto elementIt = boundary_elements(meshView).begin(); auto elementIt = boundary_elements(meshView).begin();
auto endElementIt = boundary_elements(meshView).end(); auto endElementIt = boundary_elements(meshView).end();
auto facetIt = intersections(meshView, *elementIt).begin(); auto facetIt = intersections(meshView, *elementIt).begin();
auto endFacetIt = intersections(meshView, *elementIt).end();
while (!facetIt->boundary() && facetIt != facetEndIt) while (!facetIt->boundary())
++facetIt; ++facetIt;
return {elementIt, facetIt, endElementIt}; return {meshView, elementIt, facetIt, endElementIt};
} }
Iterator end() { Iterator end() {
auto elementIt = boundary_elements(meshView).begin(); auto elementIt = boundary_elements(meshView).begin();
auto endElementIt = boundary_elements(meshView).end(); auto endElementIt = boundary_elements(meshView).end();
auto facetIt = intersections(meshView, *elementIt).begin(); // TODO: what is the correct end_facet_iterator auto facetIt = intersections(meshView, *elementIt).begin();
return {endElementIt, facetIt, endElementIt}; return {meshView, endElementIt, facetIt, endElementIt};
} }
private: private:
MeshView& meshView; MeshView const& meshView;
}; };
/// Generator function for the boundary-element iterator /// Generator function for the boundary-element iterator
template <class MeshView> template <class MeshView>
BoundaryFacetIterator<MeshView> boundary_facets(MeshView& meshView) BoundaryFacetIterator<MeshView> boundary_facets(MeshView const& meshView)
{ {
return {meshView}; return {meshView};
} }
......
...@@ -13,13 +13,18 @@ namespace AMDiS ...@@ -13,13 +13,18 @@ namespace AMDiS
template <class Mesh, int deg> template <class Mesh, int deg>
struct DefaultFeSpaceFactory struct DefaultFeSpaceFactory
{ {
using type = Dune::Functions::PQkNodalBasis<typename Mesh::LeafGridView, deg>; using GV = typename Mesh::LeafGridView;
using ST = typename GV::IndexSet::IndexType;
using type = Dune::Functions::PQkNodalBasis<GV, deg>;
}; };
template <class Mesh> template <class Mesh>
struct DefaultFeSpaceFactory<Mesh, 1> struct DefaultFeSpaceFactory<Mesh, 1>
{ {
using type = Dune::Functions::PQ1NodalBasis<typename Mesh::LeafGridView>; using GV = typename Mesh::LeafGridView;
using ST = typename GV::IndexSet::IndexType;
using type = Dune::Functions::PQ1NodalBasis<GV>;
}; };
template <class Mesh, int deg> template <class Mesh, int deg>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment