graintrace.material_calibration#

Crystal-plasticity material parameter calibration (NEML2 v3 + pyzag adjoint).

class graintrace.material_calibration.MaterialCalibration(model_class, model_args, data_args, apply_elastic_correction=False, correction_method='with_experiment_average', strain_window=None, save_dir='calibration_results')[source]#

Bases: object

Parameter calibration on the NEML2 v3 + pyzag adjoint engine (LBFGS with analytic gradients, RangeRescale reparametrization, optional plotting).

DEFAULT_PARAM_RANGES = {'elastic_tensor_E': (10000.0, 500000.0), 'elastic_tensor_G': (1000.0, 300000.0), 'elastic_tensor_nu': (-0.5, 0.5), 'slip_strength_constant_strength': (1.0, 2000.0), 'voce_hardening_initial_slope': (0.001, 50000.0), 'voce_hardening_saturated_hardening': (1.0, 2000.0)}#
objective(params=None, default_err=1000000.0)[source]#

L2 norm of (model axial stress - experimental stress). If params is given, evaluate at those values; otherwise at the current factory parameters. Kept for API compatibility / diagnostics.

Parameters:
Return type:

float

calibrate(method='lbfgs', maxiter=50, lr=0.1, max_iter_per_step=20, line_search_fn=None, param_ranges=None, plateau_rtol=0.001, plateau_window=3, autosave=True, full_field_weight=0.0, full_field_components=None, n_quantiles=64)[source]#

Calibrate the six parameters with analytic-adjoint gradients + LBFGS. method is accepted for backward compatibility only.

full_field_weight (default 0.0) adds a distribution-matched per-grain elastic-strain term to the macroscopic-stress loss, i.e. loss = mean((sigma_model - sigma_exp)^2) + full_field_weight * fullfield_strain_loss. When 0.0 the objective is macroscopic-stress-only (unchanged behavior). full_field_components selects strain tensor components (default all 6); n_quantiles sets the quantile resolution of the distribution match.

Parameters:
  • method (str)

  • maxiter (int)

  • lr (float)

  • max_iter_per_step (int)

  • line_search_fn (str | None)

  • plateau_rtol (float)

  • plateau_window (int)

  • autosave (bool)

  • full_field_weight (float)

  • full_field_components (List[int] | None)

  • n_quantiles (int)

Return type:

Tensor

plot_stress_strain(include_model=False, optimized=True, include_experiment_overlay=True)[source]#

Plot stress-strain data.

plot_texture(direction=None, crystal_symmetry='432')[source]#

Plot experimental pole figures (neml2.texture).

Parameters:
Return type:

None

plot_strain_histogram(strain_index=None, include_initial_strain=False)[source]#

Plot elastic strain histograms (model vs experiment) at matching stress levels.

Parameters:
  • strain_index (int | None)

  • include_initial_strain (bool)

Return type:

None

save(filepath)[source]#

Save the optimized material parameters to a JSON file.

Parameters:

filepath (str)

load(filepath)[source]#

Load previously saved optimized material parameters from a JSON file.

Parameters:

filepath (str)