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

boundary-element-iterator iterates correctly over entites

parent 16b2f8b8
Pipeline #206 skipped
......@@ -2,17 +2,18 @@
namespace AMDiS
{
template <MeshView>
template <class MeshView>
class BoundaryFacetIterator;
// An Iterator over all elements and when element hasBoundaryIntersections
template <MeshView>
template <class MeshView>
class BoundaryElementIterator
{
friend template <class> class BoundaryFacetIterator;
friend class BoundaryFacetIterator<MeshView>;
using Element = typename MeshView::Codim<0>::Entity;
using ElementIterator = typename MeshView::Codim<1>::Iterator;
using Self = BoundaryElementIterator;
using Element = typename MeshView::template Codim<0>::Entity;
using ElementIterator = typename MeshView::template Codim<0>::Iterator;
class Iterator
{
......@@ -25,10 +26,11 @@ namespace AMDiS
Iterator(Iterator const&) = default;
Iterator& operator=(Iterator const&) = default;
// iterate to next element that has boundary intersections
Iterator& operator++()
{
++elementIt;
while (!elementIt->hasBoundaryIntersections() && elementIt != endIt)
while (elementIt != endIt && !elementIt->hasBoundaryIntersections())
++elementIt;
return *this;
}
......@@ -40,22 +42,22 @@ namespace AMDiS
return tmp;
}
Element& operator*() const
Element const& operator*() const
{
return *elementIt;
}
Element* operator->() const
Element const* operator->() const
{
return &(*elementIt);
}
bool operator==(Iterator const& that)
bool operator==(Iterator const& that) const
{
return elementIt == that.elementIt;
}
bool operator!=(Iterator const& that)
bool operator!=(Iterator const& that) const
{
return !(*this == that);
}
......@@ -67,14 +69,14 @@ namespace AMDiS
public:
/// Constructor.
BoundaryElementIterator(MeshView& meshView)
BoundaryElementIterator(MeshView const& meshView)
: meshView(meshView)
{}
Iterator begin() {
auto elementIt = elements(meshView).begin();
auto endIt = elements(meshView).end();
while (!elementIt->hasBoundaryIntersections() && elementIt != endIt)
while (elementIt != endIt && !elementIt->hasBoundaryIntersections())
++elementIt;
return {elementIt, endIt};
......@@ -85,13 +87,13 @@ namespace AMDiS
}
private:
MeshView& meshView;
MeshView const& meshView;
};
/// Generator function for the boundary-element iterator
template <class MeshView>
BoundaryElementIterator<MeshView> boundary_elements(MeshView& meshView)
BoundaryElementIterator<MeshView> boundary_elements(MeshView const& meshView)
{
return {meshView};
}
......@@ -100,11 +102,11 @@ namespace AMDiS
// An Iterator over all elements and when element hasBoundaryIntersections, then
// iterate over all boundary-intersections with given Index, oder for thos with
// predicate returns true
template <MeshView>
template <class MeshView>
class BoundaryFacetIterator
{
using Element = typename MeshView::Codim<0>::Entity;
using Facet = typename MeshView::Codim<1>::Entity;
using Element = typename MeshView::template Codim<0>::Entity;
using Facet = typename MeshView::template Codim<1>::Entity;
using ElementIterator = typename BoundaryElementIterator<MeshView>::Iterator;
using FacetIterator = typename MeshView::IntersectionIterator;
......@@ -112,7 +114,7 @@ namespace AMDiS
class Iterator
{
public:
Iterator(MeshView& meshView,
Iterator(MeshView const& meshView,
ElementIterator elementIt,
FacetIterator facetIt,
ElementIterator endIt)
......@@ -125,15 +127,20 @@ namespace AMDiS
Iterator(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++()
{
++facetIt;
do {
auto facetEndIt = intersections(meshView, *elementIt).end();
while (!facetIt->boundary() && facetIt != facetEndIt)
while (facetIt != facetEndIt && !facetIt->boundary())
++facetIt;
if (facetIt == facetEndIt)
++elementIt;
if (facetIt != facetEndIt)
break;
++elementIt;
facetIt = intersections(meshView, *elementIt).begin();
} while (elementIt != endIt);
return *this;
......@@ -146,36 +153,37 @@ namespace AMDiS
return tmp;
}
Facet& operator*() const
// returns Dune::Intersection
auto const& operator*() const
{
return *facetIt;
}
Facet* operator->() const
auto const* operator->() const
{
return &(*facetIt);
}
bool operator==(Iterator const& that)
bool operator==(Iterator const& that) const
{
return elementIt == that.elementIt && (elementIt == endIt || facetIt == that.facetIt);
}
bool operator!=(Iterator const& that)
bool operator!=(Iterator const& that) const
{
return !(*this == that);
}
private:
MeshView& meshView;
MeshView const& meshView;
ElementIterator elementIt;
ElementIterator endIt;
FacetIterator facetIt;
ElementIterator endIt;
};
public:
/// Constructor.
BoundaryFacetIterator(MeshView& meshView)
BoundaryFacetIterator(MeshView const& meshView)
: meshView(meshView)
{}
......@@ -183,29 +191,28 @@ namespace AMDiS
auto elementIt = boundary_elements(meshView).begin();
auto endElementIt = boundary_elements(meshView).end();
auto facetIt = intersections(meshView, *elementIt).begin();
auto endFacetIt = intersections(meshView, *elementIt).end();
while (!facetIt->boundary() && facetIt != facetEndIt)
while (!facetIt->boundary())
++facetIt;
return {elementIt, facetIt, endElementIt};
return {meshView, elementIt, facetIt, endElementIt};
}
Iterator end() {
auto elementIt = boundary_elements(meshView).begin();
auto endElementIt = boundary_elements(meshView).end();
auto facetIt = intersections(meshView, *elementIt).begin(); // TODO: what is the correct end_facet_iterator
return {endElementIt, facetIt, endElementIt};
auto facetIt = intersections(meshView, *elementIt).begin();
return {meshView, endElementIt, facetIt, endElementIt};
}
private:
MeshView& meshView;
MeshView const& meshView;
};
/// Generator function for the boundary-element iterator
template <class MeshView>
BoundaryFacetIterator<MeshView> boundary_facets(MeshView& meshView)
BoundaryFacetIterator<MeshView> boundary_facets(MeshView const& meshView)
{
return {meshView};
}
......
......@@ -13,13 +13,18 @@ namespace AMDiS
template <class Mesh, int deg>
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>
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>
......
Markdown is supported
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