graintrace.taylor#
Uniaxial Taylor crystal-plasticity forward + calibration model (NEML2 v3).
A mixed-control NEML2 NonlinearSystem (cpfe_base/neml2_cpfe_calibration.i)
is wrapped by neml2.pyzag.NEML2PyzagModel and driven through
pyzag.nonlinear.solve_adjoint() for analytic parameter gradients.
- class graintrace.taylor.UniaxialTaylorModel(factory, axial_index=2, nchunk=5, rtol=1e-06, atol=1e-08, linesearch_iter=5)[source]#
Bases:
ModuleDifferentiable uniaxial Taylor forward via a NEML2 mixed-control eq_sys.
Wraps a
neml2.pyzag.NEML2PyzagModeland integrates the strain history withpyzag.nonlinear.solve_adjoint. Uniaxial loading is expressed with NEML2’sMixedControlSetup:controlselects the axial component as strain-controlled (prescribed = rate); the remaining components are stress-free, and a global constraint forcestarget_cauchy_stressto equal the grain-mean per-crystal stress.- Parameters:
- forward(orientations, strain, rate, initial_strains=None, return_state=False)[source]#
Integrate the uniaxial history and return the macro stress trajectory.
- Parameters:
orientations (Tensor) – (n_grains, 3) NEML2 MRP orientations.
strain (Tensor) – (ntime,) axial strain grid (mm/mm), typically starting at 0.
rate (float) – assumed strain rate (1/s);
t = strain / rate.initial_strains (Tensor | None) – optional (n_grains, 6) initial elastic strain.
return_state (bool) – also return per-grain elastic strain history.
- Returns:
xx, yy, zz, yz, xz, xy); if
return_state, also(ntime, n_grains, 6)elastic strain.- Return type:
macro cauchy stress
(ntime, 6)(SR2 Voigt
- class graintrace.taylor.TaylorModel(neml2_path, neml2_model_name='model_with_stress', axial_index=2, assumed_rate=0.0001, npoints=500, nchunk=5, equation_system='eq_sys', exclude_parameters=None, compile=False, device='cpu')[source]#
Bases:
BaseMaterialApproximationModelTaylor calibration model backed by the NEML2 v3 + pyzag adjoint engine.
Loads and preprocesses experimental data (per-stress-level CSVs).
Manages the six calibration parameters as NEML2/torch parameters.
Runs differentiable uniaxial stress-strain simulations for optimization.
- Parameters:
- DEFAULT_EXCLUDE_PARAMETERS = ['slip_rule_gamma0', 'slip_rule_n']#
- set_params(values)[source]#
Assign the six calibration parameters from a 1-D iterable.
- Return type:
None
- load_experiment_data(data_dir, strain_stress_file, full_field_strain_units=None, strain_stress_file_units=None, straintype='eFab', npoints=None, max_strain=None, max_stress=None, n_grains=None, seed=0)[source]#
Load experiment data (macroscopic stress-strain plus per-file CSVs).
- simulate(params, d=None, assumed_rate=None, experiment_data=None, return_state=False, initial_strains=None)[source]#
Run a differentiable uniaxial stress-strain simulation.
- Parameters:
params – optional 1-D tensor of the six calibration values. If given, they are assigned to the factory (no grad) before the solve; use this for plotting a specific parameter set. Pass
Noneto run with the factory’s current (possibly optimizer-owned) parameters so gradients flow (used during calibration).d (Tensor | None) – ignored (kept for API compatibility; the axial direction is set by
self.axial_index).assumed_rate (float | None) – strain rate; defaults to
self.assumed_rate.experiment_data – dict from
load_experiment_data().return_state (bool) – also return the per-grain elastic strain history.
initial_strains – optional (n_grains, 6) initial elastic strain.
- Returns:
stress_hist(npoints, 6), or(stress_hist, state_hist)wherestate_histis (npoints, n_grains, 6) elastic strain.