upxo.ggrowth.mcgs_v2 module
mcgs_v2 – Monte-Carlo grain-growth driver configured from plain Python values (no Excel input dashboard), for 2D and 3D.
Independent of upxo.ggrowth.mcgs.mcgs (the Excel-dashboard driver).
Supersedes upxo.ggrowth.mcgsV1_1, which now re-exports this module’s
mcgs_v2 and MCGSConfig under the old names.
Usage
3D (default, dim=3):
cfg = MCGSConfig(xmin=0, xmax=49, xinc=1, ymin=0, ymax=49, yinc=1,
zmin=0, zmax=49, zinc=1, Q=32, mcalg='300a',
mcsteps=60, save_interval=10, consider_boltzmann=False)
pxt = mcgs_v2(cfg); pxt.simulate()
2D (dim=2; z-axis fields are optional and ignored):
cfg = MCGSConfig(dim=2, xmin=0, xmax=199, xinc=1, ymin=0, ymax=199,
yinc=1, Q=32, mcalg='200', mcsteps=100,
save_interval=10, consider_boltzmann=False)
pxt = mcgs_v2(cfg); pxt.simulate()
pxt.detect_grains()
After simulate(): pxt.m is the sorted list of saved temporal slices,
pxt.gs[t].s the state array of slice t – shape (ny, nx) in 2D,
(nz, ny, nx) in 3D – and pxt.fully_annealed the dict returned by the
algorithm.
Algorithms
2D: ‘200’ (unweighted Potts), ‘201’ (second-order-neighbour weighted, uses
rsfso), ‘202’ (dominant-neighbour variant).
3D: ‘300a’, ‘300b’.
Note on ‘201’: alg201.py ranks the neighbour states by count but then indexes the value-sorted state list with the random draw instead of the ranking, so the candidate is always among the lowest-numbered neighbouring states. The structure coarsens to a single crystal within a few tens of steps. It is run here exactly as implemented there.
State-dependent Boltzmann acceptance
q_unrelated: one temperature factor shared by every state.
q_related: Q independent per-state temperature factors.
In both cases P_q = exp(-kbf_q * a_q), a_q ~ Uniform(0, 1).
- class upxo.ggrowth.mcgs_v2.MCGSConfig(xmin: float, xmax: float, xinc: float, ymin: float, ymax: float, yinc: float, Q: int, mcalg: str, mcsteps: int, save_interval: int, consider_boltzmann: bool, zmin: float = 0.0, zmax: float = 0.0, zinc: float = 1.0, dim: int = 3, boltzmann_mode: str = 'q_unrelated', boltzmann_temp_factor: float | None = None, boltzmann_temp_factors: Sequence[float] | None = None, rsfso: int = 2, print_interval: int = 10, rng_seed: int | None = None)[source]
Bases:
objectEverything mcgs_v2 needs, in plain Python values.
dimdefaults to 3. Fordim=2the z-axis fields may be omitted and are ignored.boltzmann_temp_factor is used when boltzmann_mode == ‘q_unrelated’. boltzmann_temp_factors (length Q) is used when ‘q_related’. rsfso is only used by 2D algorithm ‘201’.
- class upxo.ggrowth.mcgs_v2.mcgs_v2(config: MCGSConfig, verbose=True)[source]
Bases:
objectMonte-Carlo grain-growth driver for 2D (dim=2) and 3D (dim=3).
- simulate(verbose=None)[source]
Run the simulation and populate self.gs (temporal slice index -> grain-structure object) and self.m (sorted saved slice indices).
- detect_grains(mcsteps=None, kernel_order=2, library='scikit-image', connectivity=8, store_state_ng=True, process_individual_states=False, delta=0, lfiDtype=<class 'numpy.int32'>, verbose=False)[source]
Label grains on 2D temporal slices (fills .lgi, .n, .gid, …).
mcsteps: int or iterable of saved slice indices; default all. 3D labelling is not done here.