@@ -686,7 +686,31 @@ function find_steady_state!(s::KPS4; prn=false, delta = 0.01, stiffness_factor=0
686686 end
687687 if prn println (" \n Started function test_nlsolve..." ) end
688688 X00 = zeros (SimFloat, 2 * (s. set. segments+ KITE_PARTICLES- 1 )+ 2 )
689- results = nlsolve (test_initial_condition!, X00, autoscale= true , xtol= 4e-7 , ftol= 4e-7 , iterations= s. set. max_iter)
689+ # Provide explicit Jacobian using central finite differences to work around
690+ # NLSolversBase >= 7.10 producing subnormal Jacobian entries via DifferentiationInterface,
691+ # which cause NaN in NLsolve autoscale (subnormal column norms squared underflow to zero).
692+ n_vars = length (X00)
693+ _F1 = zeros (SimFloat, n_vars)
694+ _F2 = zeros (SimFloat, n_vars)
695+ _xp = zeros (SimFloat, n_vars)
696+ _xm = zeros (SimFloat, n_vars)
697+ function jac! (J, x)
698+ h_factor = cbrt (eps (SimFloat))
699+ for j in 1 : n_vars
700+ copyto! (_xp, x)
701+ copyto! (_xm, x)
702+ h = max (abs (x[j]), one (SimFloat)) * h_factor
703+ _xp[j] += h
704+ _xm[j] -= h
705+ test_initial_condition! (_F1, _xp)
706+ test_initial_condition! (_F2, _xm)
707+ @views J[:, j] .= (_F1 .- _F2) ./ (2 h)
708+ end
709+ # Flush near-zero entries whose squares would underflow, preventing NaN in autoscale
710+ threshold = sqrt (floatmin (SimFloat))
711+ @. J = ifelse (abs (J) < threshold, zero (SimFloat), J)
712+ end
713+ results = nlsolve (test_initial_condition!, jac!, X00, autoscale= true , xtol= 4e-7 , ftol= 4e-7 , iterations= s. set. max_iter)
690714 if prn println (" \n result: $results " ) end
691715 y0, yd0 = init (s, results. zero; upwind_dir)
692716 set_v_wind_ground! (s, calc_height (s), s. set. v_wind; upwind_dir)
0 commit comments