idaholab / moose

Multiphysics Object Oriented Simulation Environment
https://www.mooseframework.org
GNU Lesser General Public License v2.1
1.71k stars 1.04k forks source link

Speed up return mapping for AD models #26815

Open dschwen opened 7 months ago

dschwen commented 7 months ago

Reason

Following a brilliant idea from @hugary1995 , we should look into performing return mapping for AD models without dual numbers to obtain a converged solution, and then just do a single iteration with dual numbers to recover all derivatives. This must work, because the derivatives must be independent of the initial guess of the Newton iterations.

Design

TBD, but I suppose we'll have to template the residual and derivative functions in single variable return mapping (or rather overload them and redirect to a template where we want to implement this behavior). After converging teh internalSolve with non_ad_scalar we can simply do a

  computeResidualAndDerivativeHelper(effective_trial_stress, non_ad_scalar);
  ADReal scalar = non_ad_scalar - _residual / _derivative;

Impact

Improved return mapping performance.

dschwen commented 7 months ago

Example:

I31 (0.000653639,{(0,0.00294146), (1,0.0109777), (2,-0.00577175), (3,-0.00294146), (4,0.00294146), (5,-0.00154653), (6,-0.0109777), (7,-0.00294146), (8,-0...
I32 (0.000653656,{(0,0.00294154), (1,0.010978), (2,-0.00577189), (3,-0.00294154), (4,0.00294154), (5,-0.00154657), (6,-0.010978), (7,-0.00294154), (8,-0.0...
I33 (0.000653668,{(0,0.00294159), (1,0.0109782), (2,-0.00577201), (3,-0.00294159), (4,0.00294159), (5,-0.0015466), (6,-0.0109782), (7,-0.00294159), (8,-0....
I34 (0.000653676,{(0,0.00294164), (1,0.0109784), (2,-0.0057721), (3,-0.00294164), (4,0.00294164), (5,-0.00154663), (6,-0.0109784), (7,-0.00294164), (8,-0....
I35 (0.000653682,{(0,0.00294168), (1,0.0109785), (2,-0.00577218), (3,-0.00294168), (4,0.00294168), (5,-0.00154665), (6,-0.0109785), (7,-0.00294168), (8,-0...
I36 (0.000653684,{(0,0.00294172), (1,0.0109786), (2,-0.00577225), (3,-0.00294172), (4,0.00294172), (5,-0.00154667), (6,-0.0109786), (7,-0.00294172), (8,-0...
I37 (0.000653685,{(0,0.00294173), (1,0.0109787), (2,-0.00577228), (3,-0.00294173), (4,0.00294173), (5,-0.00154668), (6,-0.0109787), (7,-0.00294173), (8,-0...
I38 (0.000653685,{(0,0.00294173), (1,0.0109787), (2,-0.00577228), (3,-0.00294173), (4,0.00294173), (5,-0.00154668), (6,-0.0109787), (7,-0.00294173), (8,-0...
I39 (0.000653685,{(0,0.00294173), (1,0.0109787), (2,-0.00577228), (3,-0.00294173), (4,0.00294173), (5,-0.00154668), (6,-0.0109787), (7,-0.00294173), (8,-0...
ZD 0.000653685
RD (0.000653685,{(0,0.00294173), (1,0.0109787), (2,-0.00577228), (3,-0.00294173), (4,0.00294173), (5,-0.00154668), (6,-0.0109787), (7,-0.00294173), (8,-0...

I31-I39 are the final iterations of an internal Newton solve (power law creep test). ZD is the derivative zeroed out, and RD is the derivative recovered using the two lines in the issue description.

lindsayad commented 7 months ago

Sounds like you've decided to leverage ADReal::do_derivatives instead. That should make the development easier