Skip to content

Commit 10f8547

Browse files
author
oscarddssmith
committed
fix out of place WOperator
1 parent 17bd407 commit 10f8547

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

src/derivative_utils.jl

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,12 @@ function calc_J(integrator, cache, next_step::Bool = false)
9090
J = jacobian(uf, uprev, integrator)
9191
end
9292

93-
integrator.stats.njacs += 1
94-
9593
if alg isa CompositeAlgorithm
9694
integrator.eigen_est = constvalue(opnorm(J, Inf))
9795
end
9896
end
9997

98+
integrator.stats.njacs += 1
10099
J
101100
end
102101

@@ -144,12 +143,11 @@ function calc_J!(J, integrator, cache, next_step::Bool = false)
144143
end
145144
end
146145

147-
integrator.stats.njacs += 1
148-
149146
if alg isa CompositeAlgorithm
150147
integrator.eigen_est = constvalue(opnorm(J, Inf))
151148
end
152149

150+
integrator.stats.njacs += 1
153151
return nothing
154152
end
155153

@@ -604,21 +602,21 @@ function jacobian2W!(W::Matrix, mass_matrix, dtgamma::Number, J::Matrix,
604602
return nothing
605603
end
606604

607-
function jacobian2W(mass_matrix::MT, dtgamma::Number, J::AbstractMatrix,
608-
W_transform::Bool)::Nothing where {MT}
605+
function jacobian2W(mass_matrix, dtgamma::Number, J::AbstractMatrix,
606+
W_transform::Bool)
609607
# check size and dimension
610608
mass_matrix isa UniformScaling ||
611609
@boundscheck axes(mass_matrix) == axes(J) || _throwJMerror(J, mass_matrix)
612610
@inbounds if W_transform
613611
invdtgamma = inv(dtgamma)
614-
if MT <: UniformScaling
612+
if mass_matrix isa UniformScaling
615613
λ = -mass_matrix.λ
616614
W = J +* invdtgamma) * I
617615
else
618616
W = muladd(-mass_matrix, invdtgamma, J)
619617
end
620618
else
621-
if MT <: UniformScaling
619+
if mass_matrix isa UniformScaling
622620
λ = -mass_matrix.λ
623621
W = dtgamma * J + λ * I
624622
else
@@ -742,15 +740,16 @@ end
742740
W = cache.W
743741
if isnewton(nlsolver)
744742
# we will call `update_coefficients!` for u/p/t in NLNewton
745-
update_coefficients!(W; transform = W_transform, dtgamma)
743+
W = update_coefficients(W; transform = W_transform, dtgamma)
746744
else
747-
update_coefficients!(W, uprev, p, t; transform = W_transform, dtgamma)
745+
W = update_coefficients(W, uprev, p, t; transform = W_transform, dtgamma)
748746
end
749-
if W.J !== nothing && !(W.J isa AbstractSciMLOperator)
750-
islin, isode = islinearfunction(integrator)
747+
if W.J !== nothing
751748
J = islin ? (isode ? f.f : f.f1.f) : calc_J(integrator, cache, next_step)
752-
!isdae &&
753-
jacobian2W!(W._concrete_form, mass_matrix, dtgamma, J, W_transform)
749+
if !isdae
750+
integrator.stats.nw += 1
751+
W = jacobian2W(mass_matrix, dtgamma, J, W_transform)
752+
end
754753
end
755754
elseif cache.W isa AbstractSciMLOperator && !(cache.W isa StaticWOperator)
756755
J = update_coefficients(cache.J, uprev, p, t)
@@ -760,11 +759,9 @@ end
760759
W = WOperator{false}(mass_matrix, dtgamma, J, uprev; transform = W_transform)
761760
elseif DiffEqBase.has_jac(f)
762761
J = f.jac(uprev, p, t)
762+
integrator.stats.njacs += 1
763763
if J isa StaticArray &&
764-
integrator.alg isa
765-
Union{
766-
Rosenbrock23, Rodas23W, Rodas3P, Rodas4, Rodas4P, Rodas4P2,
767-
Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr}
764+
integrator.alg isa OrdinaryDiffEqRosenbrockAdaptiveAlgorithm
768765
W = W_transform ? J - mass_matrix * inv(dtgamma) :
769766
dtgamma * J - mass_matrix
770767
else
@@ -788,9 +785,7 @@ end
788785
W = if W_full isa Number
789786
W_full
790787
elseif len !== nothing &&
791-
integrator.alg isa
792-
Union{Rosenbrock23, Rodas23W, Rodas3P, Rodas4, Rodas4P,
793-
Rodas4P2, Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr}
788+
integrator.alg isa OrdinaryDiffEqRosenbrockAdaptiveAlgorithm
794789
StaticWOperator(W_full)
795790
else
796791
DiffEqBase.default_factorize(W_full)

0 commit comments

Comments
 (0)