From e4c1648520a8328f2d05e04ea957a75b2b4f6159 Mon Sep 17 00:00:00 2001 From: ksugahar Date: Sun, 11 Jan 2026 09:35:17 +0900 Subject: [PATCH] Add Element2d.SetGeomInfo() Python API for external mesh curving This adds a SetGeomInfo method to Element2d that allows setting the UV parametric coordinates (geominfo) for surface element vertices. This is essential for high-order curving of externally imported meshes (e.g., from Gmsh, Cubit, or other mesh generators). When meshes are imported without geometry, the geominfo is not set automatically, which prevents mesh.Curve(order) from working correctly. Usage: ```python for el in mesh.Elements2D(): for i in range(len(el.vertices)): # Get UV coordinates from geometry u, v = compute_uv_for_vertex(el.vertices[i]) el.SetGeomInfo(i, u, v) mesh.Curve(order) ``` Parameters: - vertex_index: 0-based index of the vertex within the element - u, v: Surface parametric coordinates - trignum: Triangle number for STL meshing (default: 0) Feature request: https://forum.ngsolve.org/t/feature-request-python-api-for-high-order-curving-of-externally-imported-meshes/3810 Co-Authored-By: Claude Opus 4.5 --- libsrc/meshing/python_mesh.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index b6adbee9..202aabfc 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -469,6 +469,21 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) li.append(py::make_tuple(pgi.trignum, pgi.u, pgi.v)); return li; }) + .def("SetGeomInfo", [](Element2d& self, int vertex_index, double u, double v, int trignum) + { + int np = self.GetNP(); + if (vertex_index < 0 || vertex_index >= np) + throw NgException("vertex_index out of range [0, " + std::to_string(np-1) + "]"); + auto& gi = self.GeomInfoPi(vertex_index + 1); + gi.u = u; + gi.v = v; + gi.trignum = trignum; + }, py::arg("vertex_index"), py::arg("u"), py::arg("v"), py::arg("trignum")=0, + "Set geometry info (UV parameters) for a vertex of this surface element. " + "This is useful for external meshes where geominfo is not automatically set. " + "Parameters: vertex_index (0-based index), u/v (surface parametric coordinates), " + "trignum (triangle number for STL meshing, default: 0)" + ) .def_property_readonly("vertices", FunctionPointer([](const Element2d & self) -> py::list {