Commit 670041db authored by Praetorius, Simon's avatar Praetorius, Simon

removed some segfaults in traversal

parent f7657c89
...@@ -52,10 +52,10 @@ namespace Dune ...@@ -52,10 +52,10 @@ namespace Dune
struct EntityStackEntry struct EntityStackEntry
{ {
template <class It, class End> template <class Entity>
EntityStackEntry(It&& it, End&& end) explicit EntityStackEntry(Entity&& entity)
: it(std::forward<It>(it)) : it(entity.hbegin(entity.level()+1))
, end(std::forward<End>(end)) , end(entity.hend(entity.level()+1))
{} {}
typename HostEntity::HierarchicIterator it; typename HostEntity::HierarchicIterator it;
...@@ -149,8 +149,8 @@ namespace Dune ...@@ -149,8 +149,8 @@ namespace Dune
std::vector<HostEntity> dereference () const std::vector<HostEntity> dereference () const
{ {
std::vector<HostEntity> multiEntity; std::vector<HostEntity> multiEntity;
for (auto const& stack : entityStacks_) for (std::size_t i = 0; i < entityStacks_.size(); ++i)
multiEntity.push_back(*stack.top().it); multiEntity.push_back(dereference(i));
return multiEntity; return multiEntity;
} }
...@@ -187,16 +187,12 @@ namespace Dune ...@@ -187,16 +187,12 @@ namespace Dune
++macroIt; ++macroIt;
if (macroIt == macroEnd) if (macroIt == macroEnd)
return; return;
auto entity = *macroIt;
entityStack.emplace(entity.hbegin(0), entity.hend(0));
} }
// 3. go down in tree until leaf entity // 3. go down in tree until leaf entity
for (auto child = *entityStack.top().it; !entityTest(child); for (auto child = dereference(i); !entityTest(child);
child = *entityStack.top().it) { child = dereference(i)) {
int childLevel = child.level() + 1; entityStack.emplace(child);
entityStack.emplace(child.hbegin(childLevel), child.hend(childLevel));
} }
} }
...@@ -221,21 +217,19 @@ namespace Dune ...@@ -221,21 +217,19 @@ namespace Dune
if (macroIt == macroEnd) if (macroIt == macroEnd)
return; return;
// 1. push first entry to stack
auto entity = *macroIt;
entityStack.emplace(entity.hbegin(0), entity.hend(0));
// 2. go down in tree until leaf entity // 2. go down in tree until leaf entity
for (auto child = *entityStack.top().it; !entityTest(child); for (auto child = dereference(i); !entityTest(child);
child = *entityStack.top().it) { child = dereference(i)) {
int childLevel = child.level() + 1; entityStack.emplace(child);
entityStack.emplace(child.hbegin(childLevel), child.hend(childLevel));
} }
} }
HostEntity dereference (std::size_t i) const HostEntity dereference (std::size_t i) const
{ {
return *entityStacks_[i].top().it; if (entityStacks_[i].empty())
return *macroIterators_[i];
else
return *entityStacks_[i].top().it;
} }
bool entityTest(HostEntity const& entity) bool entityTest(HostEntity const& entity)
...@@ -253,8 +247,6 @@ namespace Dune ...@@ -253,8 +247,6 @@ namespace Dune
std::vector<EntityStack> entityStacks_; std::vector<EntityStack> entityStacks_;
std::vector<bool> incrementAllowed_; std::vector<bool> incrementAllowed_;
int level_ = -1; int level_ = -1;
double time1 = 0.0, time2 = 0.0, time3 = 0.0, time4 = 0.0;
}; };
} // end namespace Dune } // end namespace Dune
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <dune/multimesh/mmgridfactory.hh> #include <dune/multimesh/mmgridfactory.hh>
#include <dune/multimesh/utility/structuredgridfactory.hh> #include <dune/multimesh/utility/structuredgridfactory.hh>
#define GRID 3 #define GRID 1
using namespace Dune; using namespace Dune;
...@@ -27,7 +27,7 @@ void printGrid(Grid const& grid) ...@@ -27,7 +27,7 @@ void printGrid(Grid const& grid)
volatile std::size_t n = 0; volatile std::size_t n = 0;
Dune::Timer t; Dune::Timer t;
for (auto const& entities : elements(grid.leafGridView())) for (auto const& entities : elements(grid.leafGridView()))
n = std::max(std::size_t(n), std::size_t(grid.grid(0).leafIndexSet().index(entities[0]))); n += grid.grid(0).leafIndexSet().index(entities[0]);
std::cout << n << "\n"; std::cout << n << "\n";
std::cout << "time: " << t.elapsed() << "\n"; std::cout << "time: " << t.elapsed() << "\n";
} }
...@@ -38,7 +38,7 @@ void printGrid2(Grid const& grid) ...@@ -38,7 +38,7 @@ void printGrid2(Grid const& grid)
volatile std::size_t n = 0; volatile std::size_t n = 0;
Dune::Timer t; Dune::Timer t;
for (auto const& entity : elements(grid.leafGridView())) for (auto const& entity : elements(grid.leafGridView()))
n = std::max(std::size_t(n), std::size_t(grid.leafIndexSet().index(entity))); n += grid.leafIndexSet().index(entity);
std::cout << n << "\n"; std::cout << n << "\n";
std::cout << "time: " << t.elapsed() << "\n"; std::cout << "time: " << t.elapsed() << "\n";
} }
...@@ -55,10 +55,10 @@ int main(int argc, char** argv) ...@@ -55,10 +55,10 @@ int main(int argc, char** argv)
using HostGrid = YaspGrid<3, EquidistantOffsetCoordinates<double,3>>; using HostGrid = YaspGrid<3, EquidistantOffsetCoordinates<double,3>>;
MultiMesh<HostGrid> grid(2, lower_left, bbox, num_elements); MultiMesh<HostGrid> grid(2, lower_left, bbox, num_elements);
#elif GRID == 2 #elif GRID == 2
FieldVector<double,3> lower_left = {-1.5, -1.5, -1.5}; FieldVector<double,2> lower_left = {-1.5, -1.5};
FieldVector<double,3> bbox = {1.5, 1.5, 1.5}; FieldVector<double,2> bbox = {1.5, 1.5};
std::array<unsigned int,3> num_elements = {2, 2, 2}; std::array<unsigned int,2> num_elements = {2, 2};
using HostGrid = Dune::ALUGrid<3, 3, Dune::simplex, Dune::conforming>; using HostGrid = Dune::ALUGrid<2, 2, Dune::simplex, Dune::conforming>;
using Factory = StructuredGridFactoryWrapper<MultiMesh<HostGrid> >; using Factory = StructuredGridFactoryWrapper<MultiMesh<HostGrid> >;
GridFactory<MultiMesh<HostGrid> > gridFactory(2); GridFactory<MultiMesh<HostGrid> > gridFactory(2);
......
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