Replace Shewchuk Triangle with fortfem's MIT-licensed Triangle-compatible mesher#27
Draft
krystophny wants to merge 1 commit into
Draft
Replace Shewchuk Triangle with fortfem's MIT-licensed Triangle-compatible mesher#27krystophny wants to merge 1 commit into
krystophny wants to merge 1 commit into
Conversation
Triangle forbids distribution as part of a commercial system without arrangement with the author, which conflicts with MEPHIT's MIT license. fortfem's clean-room triangle_compat module reproduces Triangle's behavior for the flags MEPHIT uses (BejnpqYz): on the TCFP annulus geometry of write_FreeFem_mesh, the generated outer.msh has byte-identical vertices and segments and the same triangles up to enumeration order; on the AUG annulus the file is byte-identical. The mesher is now called directly from Fortran (mephit_triangulate), so the C wrapper around triangulate() goes away along with the Triangle fetch-and-patch machinery. fortfem is fetched via FetchContent with FORTFEM_TRIANGLE_COMPAT_ONLY=ON, which builds only the dependency-free mesher library. Resolves #25
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.
Replaces Shewchuk's Triangle with the clean-room, MIT-licensed Triangle-compatible mesher from fortfem (lazy-fortran/fortfem#56). Triangle's license forbids distribution as part of a commercial system without arrangement with the author; Debian classifies it as non-free. That restriction conflicts with MEPHIT's MIT grant.
Resolves #25
Changes
src/mephit_triangulate.f90: new Fortran module calling fortfem'striangulate_compat(equivalent to Triangle flagspq20Yz) and writingouter.mshin the same format as the old C writer, including C%.16efloat rendering.src/mephit_mesh.F90:write_FreeFem_meshcalls the Fortran routine; the C interface block is gone.src/mephit_fem.c,src/mephit_fem.h:FEM_triangulate_externaland thetriangle.hinclude removed. No caller of Triangle remains.cmake/SetupFortfem.cmakereplacescmake/SetupTriangle.cmakeandcmake/setup_triangle.sh: FetchContent of fortfem withFORTFEM_TRIANGLE_COMPAT_ONLY=ON, which builds only the dependency-free mesher libraryfortfem_triangle_compat(no fortplot, no extra SuiteSparse/BLAS requirements).README.md: Triangle removed from the prerequisites.Notes
SetupFortfem.cmakepins thetriangle-compatbranch. Once Triangle-compatible meshing mode and CMake build lazy-fortran/fortfem#56 is merged and tagged, retargetGIT_TAGto that release.CMakeLists.txt; whichever merges second needs a trivial conflict resolution. This PR is based onmainand independent of Drop GSL dependency #26.triangulate_compatkeeps all state in a local derived-type instance, no module-level state (the old Triangle library used globals).Verification
Mesher parity against Triangle on six MEPHIT-derived cases
Golden meshes generated with the original Triangle binary (
triangle -BejnpqYz, the flags fromFEM_triangulate_external) on six PSLG cases derived from MEPHIT data: TCFP LCFS fromdata/g000001.0001_TCFP, the exactwrite_FreeFem_meshTCFP annulus (256-point LCFS + 32-point outer ellipse + hole seed), the AUG convex wall fromdata/convexwall_asdex.dat, and D-shape/annulus variants at 400 and 1000 vertices. fortfem'striangle_compat_clioutput compared against these:Vertex coordinates are bit-exact doubles in identical order in all six cases. Triangle connectivity is identical; in cases 3 to 6 also row by row, in cases 1 and 2 up to enumeration order (see below).
End-to-end: old MEPHIT path vs new MEPHIT path
Before (unmodified
FEM_triangulate_externalfromsrc/mephit_fem.clinked against Debian-patched Triangle 1.6) and after (mephit_triangulatelinked againstfortfem_triangle_compat), driven by the same harness on thewrite_FreeFem_meshboundary geometry, comparing the generatedouter.msh:TCFP annulus (256+32 boundary points, hole at (170, 0)):
AUG annulus (400+50 boundary points, hole at (165, 0)):
The only deviation anywhere is the enumeration order of triangles in the TCFP case: same vertices (bit-exact, same indices), same triangles (same vertex triples, same orientation), different row order. Triangle's row order is an artifact of its internal memory-pool traversal.
outer.mshis read by FreeFem (readmeshinmaxwell_daemon.edp/extmesh.edp) and merged with the core plasma mesh; FreeFem renumbers elements on mesh addition, so triangle enumeration order does not enter the results.Build
Full build from clean configure with this branch, gfortran 15.2 on macOS (fortfem fetched from GitHub by
SetupFortfem.cmake):Before this change, the same configure required fetching the non-free Triangle source from salsa.debian.org and building
libtriangle.so.The fortfem side is covered by
test_triangle_compat_goldenandtest_triangle_compat_oraclein lazy-fortran/fortfem#56 (both pass under ctest).