diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 5441b732..b38aeb88 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -6115,15 +6115,19 @@ namespace netgen int Mesh::IdentifyPeriodicBoundaries(const string &s1, const string &s2, - const Transformation<3> &mapping) + const Transformation<3> &mapping, + double pointTolerance) { auto nr = ident->GetMaxNr() + 1; ident->SetType(nr, Identifications::PERIODIC); double lami[4]; set identified_points; - Point3d pmin, pmax; - GetBox(pmin, pmax); - auto eps = 1e-8 * (pmax-pmin).Length(); + if(pointTolerance < 0.) + { + Point3d pmin, pmax; + GetBox(pmin, pmax); + pointTolerance = 1e-8 * (pmax-pmin).Length(); + } for(const auto& se : surfelements) { if(GetBCName(se.index-1) != s1) @@ -6138,14 +6142,18 @@ namespace netgen auto other_nr = GetElementOfPoint(mapped_pt, lami, true); int index = -1; auto other_el = VolumeElement(other_nr); - for(auto i : Range(4)) - if((mapped_pt - (*this)[other_el.PNums()[i]]).Length() < eps) + for(auto i : Range(other_el.PNums().Size())) + if((mapped_pt - (*this)[other_el.PNums()[i]]).Length() < pointTolerance) { index = i; break; } if(index == -1) - throw Exception("Did not find mapped point, are you sure your mesh is periodic?"); + { + cout << "point coordinates = " << pt << endl; + cout << "mapped coordinates = " << mapped_pt << endl; + throw Exception("Did not find mapped point with nr " + ToString(pi) + ", are you sure your mesh is periodic?"); + } auto other_pi = other_el.PNums()[index]; identified_points.insert(pi); ident->Add(pi, other_pi, nr); diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index f312a5da..28ad665b 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -712,7 +712,8 @@ namespace netgen int IdentifyPeriodicBoundaries(const string& s1, const string& s2, - const Transformation<3>& mapping); + const Transformation<3>& mapping, + double pointTolerance); // #ifdef NONE // /* diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index e5a8c5cc..542e7088 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -855,7 +855,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) py::arg("pid2"), py::arg("identnr"), py::arg("type")) - .def("IdentifyPeriodicBoundaries", &Mesh::IdentifyPeriodicBoundaries) + .def("IdentifyPeriodicBoundaries", &Mesh::IdentifyPeriodicBoundaries, + py::arg("face1"), py::arg("face2"), py::arg("mapping"), py::arg("point_tolerance") = -1.) .def("GetNrIdentifications", [](Mesh& self) { return self.GetIdentifications().GetMaxNr();