Skip to content

Commit 0445429

Browse files
author
oscarddssmith
committed
still broken
1 parent 67d3a4e commit 0445429

File tree

1 file changed

+23
-54
lines changed

1 file changed

+23
-54
lines changed

src/derivative_utils.jl

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -736,45 +736,35 @@ end
736736
islin, isode = islinearfunction(integrator)
737737
!isdae && update_coefficients!(mass_matrix, uprev, p, t)
738738

739-
if cache.W isa WOperator
740-
W = cache.W
741-
if isnewton(nlsolver)
742-
# we will call `update_coefficients!` for u/p/t in NLNewton
743-
W = update_coefficients!(W; transform = W_transform, dtgamma)
744-
else
745-
W = update_coefficients!(W, uprev, p, t; transform = W_transform, dtgamma)
746-
end
747-
if W.J !== nothing && !(W.J isa AbstractSciMLOperator)
748-
J = islin ? (isode ? f.f : f.f1.f) : calc_J(integrator, cache, next_step)
749-
if !isdae
750-
integrator.stats.nw += 1
751-
W = jacobian2W(mass_matrix, dtgamma, J, W_transform)
752-
end
739+
if cache.W isa StaticWOperator
740+
integrator.stats.nw += 1
741+
J = calc_J(integrator, cache, next_step)
742+
W = StaticWOperator(W_transform ? J - mass_matrix * inv(dtgamma) : dtgamma * J - mass_matrix)
743+
elseif cache.W isa WOperator
744+
integrator.stats.nw += 1
745+
J = if islin
746+
isode ? f.f : f.f1.f
747+
elseif cache.W.J === nothing
748+
calc_J(integrator, cache, next_step)
749+
else
750+
J = update_coefficients(cache.W.J, uprev, p, t)
753751
end
754-
elseif cache.W isa AbstractSciMLOperator && !(cache.W isa StaticWOperator)
755-
J = update_coefficients(cache.J, uprev, p, t)
752+
W = WOperator{false}(mass_matrix, dtgamma, J, uprev, cache.W.jacvec; transform = W_transform)
753+
elseif cache.W isa AbstractSciMLOperator
756754
W = update_coefficients(cache.W, uprev, p, t; dtgamma, transform = W_transform)
757755
elseif islin
758-
J = isode ? f.f : f.f1.f # unwrap the Jacobian accordingly
756+
J = isode ? f.f : f.f1.f
759757
W = WOperator{false}(mass_matrix, dtgamma, J, uprev; transform = W_transform)
760758
else
761759
integrator.stats.nw += 1
762-
J = calc_J(integrator, cache, next_step)
760+
J = islin ? isode ? f.f : f.f1.f : calc_J(integrator, cache, next_step)
763761
if isdae
764762
W = J
765-
elseif J isa StaticArray &&
766-
integrator.alg isa OrdinaryDiffEqRosenbrockAdaptiveAlgorithm
767-
W = W_transform ? J - mass_matrix * inv(dtgamma) :
768-
dtgamma * J - mass_matrix
769763
else
770764
W_full = W_transform ? J - mass_matrix * inv(dtgamma) :
771765
dtgamma * J - mass_matrix
772-
len = StaticArrayInterface.known_length(typeof(W_full))
773766
W = if W_full isa Number
774767
W_full
775-
elseif len !== nothing &&
776-
integrator.alg isa OrdinaryDiffEqRosenbrockAdaptiveAlgorithm
777-
StaticWOperator(W_full)
778768
else
779769
DiffEqBase.default_factorize(W_full)
780770
end
@@ -859,10 +849,11 @@ function build_J_W(alg, u, uprev, p, t, dt, f::F, ::Type{uEltypeNoUnits},
859849
elseif f.jac_prototype isa AbstractSciMLOperator
860850
W = WOperator{IIP}(f, u, dt)
861851
J = W.J
852+
elseif islin
853+
J = isode ? f.f : f.f1.f # unwrap the Jacobian accordingly
854+
W = WOperator{IIP}(f.mass_matrix, dt, J, u)
862855
elseif IIP && f.jac_prototype !== nothing && concrete_jac(alg) === nothing &&
863-
(alg.linsolve === nothing ||
864-
alg.linsolve !== nothing &&
865-
LinearSolve.needs_concrete_A(alg.linsolve))
856+
(alg.linsolve === nothing || LinearSolve.needs_concrete_A(alg.linsolve))
866857

867858
# If factorization, then just use the jac_prototype
868859
J = similar(f.jac_prototype)
@@ -879,7 +870,6 @@ function build_J_W(alg, u, uprev, p, t, dt, f::F, ::Type{uEltypeNoUnits},
879870
autodiff = alg_autodiff(alg), tag = OrdinaryDiffEqTag())
880871
J = jacvec
881872
W = WOperator{IIP}(f.mass_matrix, dt, J, u, jacvec)
882-
883873
elseif alg.linsolve !== nothing && !LinearSolve.needs_concrete_A(alg.linsolve) ||
884874
concrete_jac(alg) !== nothing && concrete_jac(alg)
885875
# The linear solver does not need a concrete Jacobian, but the user has
@@ -899,31 +889,10 @@ function build_J_W(alg, u, uprev, p, t, dt, f::F, ::Type{uEltypeNoUnits},
899889
jacvec = JacVec(__f, copy(u), p, t;
900890
autodiff = alg_autodiff(alg), tag = OrdinaryDiffEqTag())
901891
W = WOperator{IIP}(f.mass_matrix, dt, J, u, jacvec)
902-
903-
elseif islin
904-
J = isode ? f.f : f.f1.f # unwrap the Jacobian accordingly
905-
W = WOperator{IIP}(f.mass_matrix, dt, J, u)
906-
elseif DiffEqBase.has_jac(f)
907-
J = islin ? (isode ? f.f : f.f1.f) : f.jac(uprev, p, t) # unwrap the Jacobian accordingly
908-
if J isa AbstractSciMLOperator
909-
W = WOperator{IIP}(f.mass_matrix, dt, J, u)
910-
else
911-
W = if alg isa DAEAlgorithm
912-
J
913-
elseif IIP
914-
similar(J)
915-
else
916-
len = StaticArrayInterface.known_length(typeof(J))
917-
if len !== nothing &&
918-
alg isa OrdinaryDiffEqRosenbrockAdaptiveAlgorithm
919-
StaticWOperator(J, false)
920-
else
921-
ArrayInterface.lu_instance(J)
922-
end
923-
end
924-
end
925892
else
926-
J = if f.jac_prototype === nothing
893+
J = if !IIP && DiffEqBase.has_jac(f)
894+
f.jac(uprev, p, t)
895+
elseif f.jac_prototype === nothing
927896
ArrayInterface.undefmatrix(u)
928897
else
929898
deepcopy(f.jac_prototype)

0 commit comments

Comments
 (0)