upxo.meshing.gsmesh2d module

gsmesh2d.py — 2D grain-structure FE meshing orchestrator.

Dispatches to conformal or non-conformal meshing backends. Non-conformal support is a placeholder for future implementation.

Public API

mesh_gs : Orchestrate meshing; returns a unified result dict. visualize_gs_mesh: Visualize a mesh_gs result dict.

Shared helpers

_flatten_cells : Expand MultiPolygons → individual Polygons (shared by all backends).

upxo.meshing.gsmesh2d.mesh_gs(cells: dict, method: str = 'conformal', mesh_size_gb: float = 0.75, mesh_size_bulk: float = 4.5, mesh_order: int = 1, mesh_algo: int = 8, recombine_to_quads: bool = True, dist_min: float = 0.5, dist_max: float = 5.0, out_dir: str | None = None, basename: str = 'gs_mesh', formats: list | None = None, verbose: bool = False) dict[source]

Orchestrate FE meshing for a dict of Shapely grain polygons.

Parameters:
  • cells ({gid: Shapely Polygon or MultiPolygon})

  • method ('conformal' (default). 'non_conformal' reserved for future use.)

  • mesh_size_gb (Target element size on grain boundaries.)

  • mesh_size_bulk (Target element size in grain interiors.)

  • mesh_order (Element order (1 = linear, 2 = quadratic).)

  • mesh_algo (Gmsh algorithm ID (6=Frontal, 8=Frontal-Delaunay quads).)

  • recombine_to_quads (Recombine triangles into quads after generation.)

  • dist_min (Distance field DistMin (passed through; currently stored in result).)

  • dist_max (Distance field DistMax (passed through; currently stored in result).)

  • out_dir (Directory for exported files. No export when None.)

  • basename (Filename stem (extension appended per format).)

  • formats (List of format extensions, e.g. ['msh', 'inp', 'vtk'].)

  • verbose (Print progress messages.)

Returns:

method str — meshing method used. mesher confMesh2dGMSH instance with populated nodes / elConn. flat_cells {flat_id: Polygon} gid_map {flat_id: original_gid} n_nodes int n_tri int n_quad int elapsed float — total wall-clock seconds. exported list[str] — paths of files written.

Return type:

dict

upxo.meshing.gsmesh2d.visualize_gs_mesh(result: dict, figsize: tuple = (12, 9), dpi: int = 150, tri_edgecolor: str = 'steelblue', tri_linewidth: float = 0.2, tri_alpha: float = 0.7, quad_edgecolor: str = 'darkorange', quad_linewidth: float = 0.2, quad_alpha: float = 0.7, show_axis: bool = True, show_stats: bool = True, lw_gb: float = 0.6, color_gb: str = 'k') tuple[source]

Visualize a mesh_gs result dict using see_femesh + grain boundary overlay.

Parameters:
  • result (dict returned by mesh_gs.)

  • figsize (Figure size in inches.)

  • dpi (Figure DPI.)

  • tri_* (Styling for triangle elements.)

  • quad_* (Styling for quad elements.)

  • show_axis (Show axis ticks.)

  • show_stats (Show element count statistics in the figure.)

  • lw_gb (Linewidth for grain boundary overlay.)

  • color_gb (Colour for grain boundary overlay.)

Return type:

(fig, ax)