Skip to content

Conversation

@ksugahar
Copy link

Summary

Add a SetGeomInfo method to Element2d that allows setting the UV parametric coordinates (geominfo) for surface element vertices.

Motivation

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

from netgen.meshing import *

# After importing mesh and setting up geometry
for el in mesh.Elements2D():
    for i in range(len(el.vertices)):
        # Get UV coordinates from geometry for this vertex
        u, v = compute_uv_for_vertex(el.vertices[i])
        el.SetGeomInfo(i, u, v)

# Now curving works correctly
mesh.Curve(order)

API

Element2d.SetGeomInfo(vertex_index, u, v, trignum=0)

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)

Related

🤖 Generated with Claude Code

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 <noreply@anthropic.com>
@ksugahar
Copy link
Author

Successful Workflow Report: 3D High-Order Elements with SetGeomInfo API

I've been using this PR to enable high-order curving for externally imported meshes from Coreform Cubit. The results are excellent!

Workflow

  1. OCC: Create geometry and name faces (name_occ_faces())
  2. OCC: Export to STEP (face names preserved)
  3. Cubit: Import STEP, generate mesh
  4. Export: Use name-based face mapping to Netgen mesh
  5. SetGeomInfo: Compute UV parameters analytically and call el.SetGeomInfo(i, u, v)
  6. mesh.Curve(order): High-order curving now works correctly!

Accuracy Results

Geometry Curve(2) Error Curve(3) Error
Complex (Boolean ops) 0.0021% 0.0004%
Cylinder 0.0027% 0.0006%
Sphere 0.0027% 0.0004%
Torus 0.0010% 0.0003%

This achieves Netgen-native accuracy for externally imported meshes!

Published Library

The workflow is implemented in my Python library:

Key Functions

# Set UV for analytic surfaces
set_cylinder_geominfo(ngmesh, radius, height, center, axis)
set_sphere_geominfo(ngmesh, radius, center)
set_torus_geominfo(ngmesh, major_radius, minor_radius, center, axis)
set_cone_geominfo(ngmesh, base_radius, height, center, axis)

Why This Matters

  • Cubit users can now use NGSolve's high-order elements with correct curving
  • Hex meshes from Cubit work correctly with mesh.Curve()
  • Complex geometries (Boolean operations) achieve the same accuracy as Netgen-native meshing

Thank you for implementing this API! It's exactly what was needed for external mesh curving.

@ksugahar
Copy link
Author

Binary Release Available

I've published a pre-built Windows binary with this PR applied:

Download: NGSolve 6.2.2601 + SetGeomInfo API

This allows users to test the SetGeomInfo API without building from source.

Installation

  1. Download and extract ngsolve-6.2.2601-setgeominfo-win64.zip
  2. Add to Python path:
import sys
sys.path.insert(0, "path/to/extracted/Lib/site-packages")
import ngsolve

The binary includes the Periodic BC fix (upstream commit 2581a74) and PR #232.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant