graintrace.construct_nf_mesh#

NF HEDM reconstruction: segment .mic layers and build a hex mesh.

class graintrace.construct_nf_mesh.NearFieldMeshBuilder(*, input_folder, save_dir, exp_file_token='layer', angle_convention='bunge', angle_type='radians', symmetry='432', prefix='reconstructed', write_intermediate=True, write_vtk=True, default_mesh_filename='mesh.e', default_mapped_orientations_filename='orientations')[source]#

Bases: object

Reconstruct a high-resolution 3D mesh from near-field (NF) HEDM .mic layers.

Reads a folder of per-layer orientation maps, segments them into grains on a voxel grid, and generates a conformal hexahedral Exodus mesh via CUBIT/SCULPT, plus per-element MRP orientations for CPFE. See examples/demonstrate_cpfe_nfff.py and the /nf-reconstruction skill. (NF reconstruction uses multiprocessing, so call it under an if __name__ == "__main__": guard.)

Parameters:
  • input_folder (PathLike)

  • save_dir (PathLike)

  • exp_file_token (str)

  • angle_convention (str)

  • angle_type (str)

  • symmetry (str)

  • prefix (str)

  • write_intermediate (bool)

  • write_vtk (bool)

  • default_mesh_filename (str)

  • default_mapped_orientations_filename (str)

DEFAULT_SEGMENTATION: Dict[str, Any] = {'batch_norm': 1000, 'connectivity': 26, 'grain_threshold': 100, 'grain_threshold_final': 1000, 'misorientation_tol': 0.08726646259971647, 'stop_count': 500}#
DEFAULT_SCULPT_OPTIONS: Sequence[str] = ('--adapt', '-A', '7', '-df', '1', '-S', '2', '-CS', '4', '--void_mat', '0')#
REQUIRED_SCULPT_KEYS = ('psculpt', 'epu', 'nprocs')#
reconstruct(*, dz=5.0, nx=300, ny=900, segmentation=None)[source]#

Reconstruct a segmented NF voxel grid from .mic/.csv layers.

Converts the layer files to a pointcloud, rasterizes it onto a fixed voxel grid, segments it into grains via flood-fill, infills, and removes small segments.

Parameters:
  • dz (float) – Layer thickness in micrometers (z spacing between stacked layers).

  • nx (int) – In-plane grid resolution along x.

  • ny (int) – In-plane grid resolution along y.

  • segmentation (Dict[str, Any] | None) – Flat segmentation config dict (misorientation_tol in radians, connectivity, batch_norm, grain_threshold, stop_count, grain_threshold_final); None uses the class defaults.

Returns:

Path to the written merged_segmented_fixed_grid.npy.

Return type:

Path

mesh(*, sculpt_config, sculpt_options=None, merged_grid=None, spn_path=None, orientations_path=None, mesh_path=None, mapped_orientations_path=None)[source]#

Generate an Exodus mesh via SCULPT from the merged voxel grid.

Uses merged_grid if given, else save_dir/merged_segmented_fixed_grid.npy. Writes the SCULPT .spn/orientations inputs, runs SCULPT, and maps per-element MRP orientations.

Parameters:
  • sculpt_config (Dict[str, Any]) – SCULPT configuration dict (required keys psculpt, epu, nprocs; optional launcher, environment).

  • sculpt_options (Sequence[str] | None) – SCULPT CLI flags as a sequence of strings; None uses DEFAULT_SCULPT_OPTIONS.

  • merged_grid (str | Path | None) – Path to the merged segmented grid .npy; None uses save_dir/merged_segmented_fixed_grid.npy.

  • spn_path (str | Path | None) – Override for the SCULPT .spn voxel input path.

  • orientations_path (str | Path | None) – Override for the SCULPT per-voxel orientations input path.

  • mesh_path (str | Path | None) – Override for the output Exodus mesh path; None uses the configured default.

  • mapped_orientations_path (str | Path | None) – Override for the mapped per-element orientation output basename (“.csv” is appended).

Returns:

Path to the written Exodus mesh.

Return type:

Path