upxo.meshing.conformal_mesher2d module
- class upxo.meshing.conformal_mesher2d.confMesh2d(gtess=None)[source]
Bases:
objectAn orchastrator class capable of multiple 2D conformal mehsing pipelines.
Usage
from upxo.meshing.conformal_mesher2d import confMesh2d as cm2d
- ValidElTypesOptions = ('triangle', 'quad')
- gtess
- classmethod from_geometric_pxtal(gsgen_method='shapely_pxtal_load', pxtal=None, xbound=None, ybound=None)[source]
Class method to mesh geometrified grain struture
- femesh_pygmsh(elementShape='tri', elementOrder=1, meshingAlgorithmID=4, elsize_global=[1.0], intermediateFilename='femesh', intermediateFileformat='vtk')[source]
Femesh pygmsh.
- set_fids(geomObject)[source]
Assign each cell feature, a unique ID (fid) starting from 1.
- Parameters:
geomObject (list of shapely geometries Geometries that will be used to form feature IDs.)
Example
gsConfMesh.set_fids(gsConfMesh.gtess.L0.pxtal.geoms)
- assess_quality(qualityMeasures=['aspect_ratio', 'skew', 'min_angle', 'area'])[source]
Assess quality.
- see_mesh_quality(mqm_data, mqm_dataframe, data_to_vis='mesh > quality > field', qualityMeasures=['aspect_ratio', 'skew', 'min_angle', 'area'])[source]
See mesh quality.
- plot_elements_geometric_grain(grain_name, **kwargs)[source]
Visualise elements geometric grain using Matplotlib or PyVista.
- plot_elements_by_elIDs(element_ids, **kwargs)[source]
Visualise elements by elIDs using Matplotlib or PyVista.
- plot_elements_geometric_grains(**kwargs)[source]
Visualise elements geometric grains using Matplotlib or PyVista.
- collect_gb_elements_for_grains(grain_ids=None, grain_names=None, prefix='grain')[source]
Orchestrator to extract GB elements for multiple grains using extract_gb_elements_for_grain. Accepts either grain_ids or grain_names. If grain_ids are provided, uses prefix + ‘.’ + str(grainid) to form grain names.
- resolve_eltypes(grain_name, grainElements, grainCoordinates, eltypes=None)[source]
Resolve eltypes.
- build_element_ids_by_band(grain_name, bands, eltypes, grainElements, nearest_dist_by_type)[source]
Build and return element ids by band.
- pick_contrasting_colours_from_cmap(n_colours, cmap_name='nipy_spectral')[source]
Pick contrasting colours from cmap.
- resolve_band_colours(bands, band_colours=None, auto_cmap='nipy_spectral')[source]
Resolve band colours.
- plot_band_elements(element_ids_by_band, bands, plot_eltype, gbcoords, gblines_by_grain=None, colours_to_use=None, title='Selected elements by band', band_facecolors=False)[source]
Visualise band elements using Matplotlib or PyVista.
- select_elements_in_bands(grain_name, bands, gbnodeCoords, grainCoordinates, grainElements, eltypes=None, plot_eltype='quad', gblines_by_grain=None, plot=True, band_colours=None, auto_cmap='nipy_spectral', band_facecolors=False)[source]
Select elements in bands.
- fids
- pxtal_mesh
- grid
- mesherTool
- elementShape
- elementOrder
- meshingAlgorithmID
- filtered_cells
- filtered_mesh
- nodes
- elConn
- meshCellFeatTypes
- lineFeatLocation
- GBlines
- availableFeatures
- availableElTypes
- availableElTypeID
- elsets_eltype
- elsets
- elID_ranges
- class upxo.meshing.conformal_mesher2d.confMesh2dGMSH[source]
Bases:
objectConformal 2D mesher using the raw gmsh API (no pygmsh dependency).
Designed to work directly with a dict of Shapely polygons (flat_cells) and an optional grain-id mapping (gid_map). This class duplicates analytical / post-processing methods from confMesh2d so that pygmsh can be phased out without breaking existing workflows.
Usage
from upxo.meshing.conformal_mesher2d import confMesh2dGMSH as cm2dg
Typical workflow
m = confMesh2dGMSH() m.femesh_gmsh(flat_cells, gid_map,
mesh_size_gb=0.75, mesh_size_bulk=4.5, mesh_algo=8, mesh_order=1, recombine_to_quads=True)
m.form_elsets_gmsh() m.build_boundary_nsets() m.build_grain_nsets() m.build_gb_nset()
- ValidElTypesOptions = ('triangle', 'quad')
- gtess
- fids
- gid_map
- point_registry
- surface_tags
- physical_surface_tags
- mesherTool
- elementShape
- elementOrder
- meshingAlgorithmID
- recombine_to_quads
- nodes
- elConn
- GBlines
- availableFeatures
- availableElTypes
- availableElTypeID
- elsets_eltype
- elsets
- elID_ranges
- nsets
- grid
- femesh_gmsh(flat_cells, gid_map=None, mesh_size_gb=1.0, mesh_size_bulk=4.0, mesh_algo=6, mesh_order=1, recombine_to_quads=False, out_dir=None, basename='gs_mesh', formats=None)[source]
Full gmsh meshing pipeline.
- Parameters:
flat_cells (dict) – {flat_id: shapely.geometry.Polygon} — grain geometries.
gid_map (dict, optional) – {flat_id: original_grain_id}. If None, flat_id is used as-is.
mesh_size_gb (float) – Target element size on grain boundaries.
mesh_size_bulk (float) – Target element size in grain interiors.
mesh_algo (int) – gmsh mesh algorithm ID (e.g. 6=Frontal, 8=Frontal-Delaunay quads).
mesh_order (int) – Element order (1=linear, 2=quadratic).
recombine_to_quads (bool) – Whether to recombine triangles into quads after meshing.
out_dir (str or None) – Directory to write exported mesh files. No export when None.
basename (str) – Filename stem for exported files (extension appended per format).
formats (list of str or None) – File format extensions to export, e.g.
['msh', 'inp', 'vtk'].
- form_elsets_gmsh(flat_cells, prefix='grain.')[source]
Build per-grain element sets from flat_cells polygons.
- build_boundary_nsets(tol=1e-06)[source]
Build node sets for domain boundaries and corners.
- Populates self.nsets with keys:
‘LEFT’, ‘RIGHT’, ‘BOTTOM’, ‘TOP’, ‘BOTTOM_LEFT’, ‘BOTTOM_RIGHT’, ‘TOP_LEFT’, ‘TOP_RIGHT’
using node coordinates from self.nodes.
- build_grain_nsets()[source]
Build per-grain node sets from self.elsets_eltype. Populates self.nsets with keys matching elset names (e.g. ‘grain.1’).
- build_gb_nset()[source]
Build a node set containing all grain-boundary nodes. Populates self.nsets[‘GB’].
- collect_gb_elements_for_grains(grain_ids=None, grain_names=None, prefix='grain')[source]
Collect gb elements for grains.
- resolve_eltypes(grain_name, grainElements, grainCoordinates, eltypes=None)[source]
Resolve eltypes.
- build_element_ids_by_band(grain_name, bands, eltypes, grainElements, nearest_dist_by_type)[source]
Build and return element ids by band.
- pick_contrasting_colours_from_cmap(n_colours, cmap_name='nipy_spectral')[source]
Pick contrasting colours from cmap.
- resolve_band_colours(bands, band_colours=None, auto_cmap='nipy_spectral')[source]
Resolve band colours.
- plot_elements_geometric_grain(grain_name, **kwargs)[source]
Visualise elements geometric grain using Matplotlib or PyVista.
- plot_elements_by_elIDs(element_ids, **kwargs)[source]
Visualise elements by elIDs using Matplotlib or PyVista.
- plot_elements_geometric_grains(**kwargs)[source]
Visualise elements geometric grains using Matplotlib or PyVista.