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, return_orientation=False)[source]#
Integrate the uniaxial history and return the macro stress trajectory.
- Parameters:
orientations (Tensor) – (n_grains, 3) NEML2 v3 MRP orientations (
tan(theta/4)*axis).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.
return_orientation (bool) – also return the per-grain crystal orientation history (the model’s
orientationstate, which evolves with plastic spin).
- Returns:
macro_stressalone when neither flag is set, otherwise a tuple in the fixed order(macro_stress[, elastic_strain][, orientation]):macro_stress:(ntime, 6)macro Cauchy stress (SR2 Voigt: xx, yy, zz, yz, xz, xy).elastic_strain(ifreturn_state):(ntime, n_grains, 6).orientation(ifreturn_orientation):(ntime, n_grains, 3)neml2 v3 MRP, in the same convention and frame as the inputorientations(no conversion is applied); step 0 equals the input.
- 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', slip_systems=None)[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.
slip_systems(constructor kwarg, defaultNone= useneml2_pathas written, which for the shippedneml2_cpfe_calibration.iis FCC<110>{111}) selects the crystal slip: a preset name fromgraintrace.slip_systems.SLIP_SYSTEM_PRESETS("fcc","bcc","bcc_112","bcc_110_112","bcc_110_112_123"), aSlipSystems, or (direction, plane) Miller families. The deck’s# @SLIPlines are rewritten into a temporary copy, which is what gets loaded. Use the same value asCPFESimulation(slip_systems=...)so calibration and CPFE agree.- 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, angle_identifier=('Eul0', 'Eul1', 'Eul2'), angle_convention='bunge', angle_type='auto')[source]#
Load the per-stress-level FF grain tables and the macro stress-strain curve.
Grain orientations come from the Euler columns (
angle_identifier) viaeuler_to_mrp(), i.e. the neml2 MRP of the activeRthe Taylor model expects. Only when a table has no Euler columns are theO11..O33columns used, and they must hold the activeR(MIDAS Grains.csvO; seeload_orientation_matrices()).- Parameters:
data_dir (str) – folder of per-stress-level CSVs named
<stress>.csv.strain_stress_file (str) – macro
strain,stressCSV.full_field_strain_units (str | None) –
Noneor"microstrain"(grain strains).strain_stress_file_units (str | None) –
Noneor"microstrain"(macro strain).straintype (str) – full-field strain column prefix (
"eKen"or"eFab").npoints (int | None) – resampled macro-curve points (defaults to the model’s).
max_strain (float | None) – cap the macro curve at this strain.
max_stress (float | None) – cap the macro curve at this stress (if no
max_strain).n_grains (int | None) – subsample this many grains per file (
None= all).seed (int) – RNG seed for the subsampling.
angle_identifier – the three Euler columns (standard Bunge triplet).
angle_convention (str) –
"bunge","kocks"or"roe".angle_type (str) –
"degrees","radians"or"auto"(any|value| > 2*pimeans degrees, MIDAS style), per file.
- Returns:
dict with
files,stress_levels,strain_stress,exp_strain,exp_texture(neml2 MRP per file),exp_weights,avg_exp_strain,avg_axial_strain,use_weightsandcutoff_strain.
- simulate(params, d=None, assumed_rate=None, experiment_data=None, return_state=False, initial_strains=None, return_orientation=False)[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.
return_orientation (bool) – also return the per-grain orientation history.
- Returns:
stress_hist(npoints, 6) alone when neither flag is set, otherwise a tuple in the fixed order(stress_hist[, state_hist][, ori_hist]):state_histis (npoints, n_grains, 6) elastic strain (ifreturn_state);ori_histis (npoints, n_grains, 3) neml2 v3 MRP orientations (ifreturn_orientation), in the same convention asexperiment_data["exp_texture"][0](no conversion), withori_hist[0]equal to the input texture.