Skip to content

Commit f5d037e

Browse files
refactor: remove denominators in NonlinearSystem
1 parent 148d3dd commit f5d037e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,13 @@ function calculate_jacobian(sys::NonlinearSystem; sparse = false, simplify = fal
277277

278278
if sparse
279279
jac = sparsejacobian(rhs, vals, simplify = simplify)
280+
(Is, Js, Vs) = findnz(jac)
281+
for (i, j) in zip(Is, Js)
282+
jac[i, j] = remove_denominators(jac[i, j])
283+
end
280284
else
281285
jac = jacobian(rhs, vals, simplify = simplify)
286+
jac = remove_denominators.(jac)
282287
end
283288
get_jac(sys)[] = jac, (sparse, simplify)
284289
return jac
@@ -318,7 +323,8 @@ function generate_function(
318323
sys::NonlinearSystem, dvs = unknowns(sys), ps = parameters(
319324
sys; initial_parameters = true);
320325
scalar = false, kwargs...)
321-
rhss = [deq.rhs for deq in equations(sys)]
326+
rhss = [deq.rhs for deq in full_equations(sys; allow_singular = true)]
327+
rhss = remove_denominators.(rhss)
322328
dvs′ = value.(dvs)
323329
if scalar
324330
rhss = only(rhss)

0 commit comments

Comments
 (0)