Mesh geometry import#3197
Draft
Luochenghuang wants to merge 2 commits intoNanoComp:masterfrom
Draft
Conversation
- Mesh class in geom.py: vertices + triangles, optional center, from_stl() and from_obj() classmethods with built-in parsers (binary/ASCII STL with vertex welding, OBJ with quad triangulation) - pymesh_to_mesh in typemap_utils.cpp: extracts vertices and triangles from Python, calls make_mesh_with_center from libctl - Mesh exported from meep.__init__ (requires manual addition to generated __init__.py until codegen is updated) Requires libctl with MESH support (Luochenghuang/libctl#mesh-geometry-import).
Two tests (~1s total): 1. Geometric convergence: mesh icosphere L2 error vs native Sphere decreases with subdivision (20 faces -> 5120 faces -> exact match) 2. Subpixel smoothing: eps_averaging=True produces intermediate epsilon values at mesh-air interfaces, confirming Kottke averaging works for mesh objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Python support for the new
MESHgeometric object type from Luochenghuang/libctl#mesh-geometry-import. This enables importing arbitrary triangulated 3D surfaces (e.g., from STL/OBJ files) directly into meep simulations.Depends on libctl with MESH support (NanoComp/libctl#74).
Closes #138.
Changes
python/geom.py—Meshclass and file parsers:Mesh(vertices, triangles, center=None, material=...)— triangulated surface geometryMesh.from_stl(filename, ...)— binary and ASCII STL import with vertex weldingMesh.from_obj(filename, ...)— Wavefront OBJ import with quad triangulationstructandre)python/typemap_utils.cpp— C++ binding:pymesh_to_mesh— extracts vertices and triangles from Python, callsmake_mesh_with_center"Mesh"case added topy_gobj_to_gobjdispatchUsage
Subpixel smoothing, epsilon grid queries, and all other meep features work automatically.
Test plan
5 integration tests in
python/tests/test_mesh.py:test_stl_importtest_point_in_meshtest_volumetest_eps_averagingtest_mesh_vs_block