diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 46e299ab..25b60e88 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -6563,6 +6563,21 @@ namespace netgen return defaultstring; } + + NgArray & Mesh :: GetRegionNamesCD (int codim) + { + switch (codim) + { + case 0: return materials; + case 1: return bcnames; + case 2: return cd2names; + case 3: return cd3names; + default: throw Exception("don't have regions of co-dimension "+ToString(codim)); + } + } + + + void Mesh :: SetUserData(const char * id, NgArray & data) { if(userdata_int.Used(id)) diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 74381b7f..372430ee 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -687,6 +687,9 @@ namespace netgen string * GetBCNamePtr (int bcnr) const { return (bcnr < bcnames.Size() && bcnames[bcnr]) ? bcnames[bcnr] : &default_bc; } + + NgArray & GetRegionNamesCD (int codim); + /// void ClearFaceDescriptors() { facedecoding.SetSize(0); } diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 9a90d3f1..01d2fcc9 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -321,35 +321,35 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) ; py::class_(m, "Element2D") - .def(py::init ([](int index, py::list vertices) + .def(py::init ([](int index, std::vector vertices) { Element2d * newel = nullptr; - if (py::len(vertices) == 3) + if (vertices.size() == 3) { newel = new Element2d(TRIG); for (int i = 0; i < 3; i++) - (*newel)[i] = py::extract(vertices[i])(); + (*newel)[i] = vertices[i]; newel->SetIndex(index); } - else if (py::len(vertices) == 4) + else if (vertices.size() == 4) { newel = new Element2d(QUAD); for (int i = 0; i < 4; i++) - (*newel)[i] = py::extract(vertices[i])(); + (*newel)[i] = vertices[i]; newel->SetIndex(index); } - else if (py::len(vertices) == 6) + else if (vertices.size() == 6) { newel = new Element2d(TRIG6); for(int i = 0; i<6; i++) - (*newel)[i] = py::extract(vertices[i])(); + (*newel)[i] = vertices[i]; newel->SetIndex(index); } - else if (py::len(vertices) == 8) + else if (vertices.size() == 8) { newel = new Element2d(QUAD8); for(int i = 0; i<8; i++) - (*newel)[i] = py::extract(vertices[i])(); + (*newel)[i] = vertices[i]; newel->SetIndex(index); } else @@ -801,6 +801,20 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) return self.Compress (); } ,py::call_guard()) + .def ("AddRegion", [] (Mesh & self, string name, int dim) -> int + { + auto & regionnames = self.GetRegionNamesCD(self.GetDimension()-dim); + regionnames.Append (new string(name)); + int idx = regionnames.Size(); + if (dim == 2) + { + FaceDescriptor fd; + fd.SetBCName(regionnames.Last()); + fd.SetBCProperty(idx); + self.AddFaceDescriptor(fd); + } + return idx; + }, py::arg("name"), py::arg("dim")) .def ("SetBCName", &Mesh::SetBCName) .def ("GetBCName", FunctionPointer([](Mesh & self, int bc)->string