diff --git a/AMDiS/src/Mesh.cc b/AMDiS/src/Mesh.cc index 9e421e01de9fab37477d0559583c61236275496b..80f053479ac1c4086697b44dbb99156720a2bec0 100644 --- a/AMDiS/src/Mesh.cc +++ b/AMDiS/src/Mesh.cc @@ -674,10 +674,22 @@ namespace AMDiS { mel_info->fillMacroInfo(mel); + // We have the care about not to visite a macro element twice. In this case the + // function would end up in an infinite loop. If a macro element is visited a + // second time, what can happen with periodic boundary conditions, the point is + // not within the mesh! + std::set<int> macrosVisited; + macrosVisited.insert(mel->getIndex()); + int k; while ((k = mel_info->worldToCoord(xy, &lambda)) >= 0) { if (mel->getNeighbour(k)) { mel = mel->getNeighbour(k); + mel = mel->getNeighbour(k); + if (macrosVisited.count(mel->getIndex())) + return false; + + macrosVisited.insert(mel->getIndex()); mel_info->fillMacroInfo(mel); continue; }