"""Equation-only diagnostics of the published growth update. NOT a Fortran/UMAT/Abaqus run.
Fixed orthonormal growth axes, sum(alpha)=1. q=Omega*c is dimensionless.
No mechanics, plasticity, contact, hybrid element or solver iteration is modeled.
"""
import math,json,pathlib
out=[]
for qmax in [0.1,3.9]:
 for n in [10,100,1000]:
  dq=qmax/n; logj=0.;q=0.
  for k in range(n):
   qnew=(k+1)*dq;logj+=dq/(1+qnew);q=qnew
  j=math.exp(logj); expected=1+qmax
  growlog=logj
  for k in range(n):
   qnew=qmax-(k+1)*dq;logj+=-dq/(1+qnew)
  closed=math.exp(logj)
  exact_log=sum(math.log((1+(k+1)*dq)/(1+k*dq)) for k in range(n))
  out.append({'qmax':qmax,'steps_per_leg':n,'growth_expected_J':expected,'original_update_J':j,'growth_relative_error_percent':100*(j/expected-1),'closed_cycle_expected_J':1.,'original_update_closed_cycle_J':closed,'closed_cycle_residual_percent':100*(closed-1),'endpoint_log_ratio_update_J':math.exp(exact_log)})
assert all(abs(x['endpoint_log_ratio_update_J']/x['growth_expected_J']-1)<1e-12 for x in out)
assert abs(out[2]['growth_relative_error_percent'])<abs(out[0]['growth_relative_error_percent'])
r={'evidence_type':'Python scalar equation reproduction only; no original Fortran execution or physical validation','assumptions':['fixed orthonormal growth axes','sum(alpha)=1','q is prescribed, constant rate in each leg','no zero-DSTRAN return branch modeled','no material properties or experimental data used'],'results':out}
pathlib.Path(__file__).with_name('equation_diagnostics.json').write_text(json.dumps(r,indent=2));print(json.dumps(r,indent=2))
