Domain refractor proposal: Optimize Mesh Creation Process with GMSH
Issue: Domain Refactoring Proposal – Optimize Mesh Creation Process with GMSH
Description
The current implementation of the domain library does not follow Python best practices. For example, CustomDomain
inherits from BuiltInModel
, even though it does not require any GMSH features.
We propose a refactoring of the domain submodule, to be introduced in the next major bvpy
release (i.e., bvpy 2.0
), to enhance coherence and maintainability.
Another inefficiency in bvpy
is the current mesh creation process, which writes the mesh to disk twice—first in .msh
format and then in .xdmf
format. This workflow is suboptimal, as disk operations are time-consuming.
We propose rewriting the AbstractDomain.generate
and AbstractDomain.convert_gmsh_to_fenics
methods to eliminate unnecessary file I/O. This can be achieved using in-memory data structures and tools such as fe.MeshEditor()
, which has already been employed in bvpy
in other contexts.[2]
Objectives of the Refactoring
- Ensure coherence and consistency with Python best practices.
-
Optimize the process by avoiding unnecessary file operations. Specifically, eliminate the need for
tempfile.TemporaryDirectory
. - Preserve domain attributes, such as GMSH physical groups, by storing them in a
MeshFunction
object to retain geometry labels. - Implement changes in a way that facilitates a future transition from FEniCS to FEniCSx with minimal modifications.