3MAH / microgen

Microstructure generation
https://3mah.github.io
GNU General Public License v3.0
67 stars 8 forks source link

Periodic remeshing overhaul with periodicity checks and double mmg call, add example and doc entry #38

Closed ylgrst closed 7 months ago

ylgrst commented 7 months ago

Context

This pull request proposes a refactor of remesh.py, and adds an example as well as a new documentation entry regarding periodic remeshing. Some other refactoring has also been conducted on other modules, mainly to account for naming convention (snake_case) changes in mesh.py. It also moves is_periodic() from test_utils.py to Mesh class.

Description

The function remesh_keeping_periodicity_for_fem() now uses either a BoxMesh or a pyvista.UnstructuredGrid or a pyvista.PolyData as input, and outputs a pyvista.UnstructuredGrid. It also now calls mmg twice: once to prepare for remeshing by adding a -nofem parameter that ensures preservation of level sets, and another for the actual remeshing job.

An example has been added which compares a periodically meshed gyroid before and after periodic remeshing.

An entry has been added to documentation under Mesh section. New images generation has been added to generates_images.py.

is_periodic() was moved to Mesh as it seems more relevant now that both mesh_periodic() and remesh_keeping_periodicity_for_fem() check for mesh periodicity (output for the former, both input and output for the latter)

Additional details

For some reason, calling mmg only once could sometimes result in some nodes being displaced outside of the initial RVE, thus breaking mesh periodicity. A first run of mmg with the -nofem parameter seems to fix the issue.

Adding periodicity checks reassures the user on actual mesh periodicity, avoiding the need of manual checks. Also, an exception is now raised if something went wrong during remeshing that leads to a non periodic output.

Testing

Tests have been updated in test_remesh.py to reflect changes in input and output. test_is_periodic.py has also been changed to remove excessive use of unnecessary fixtures.