Skip to content

Commit 413f40b

Browse files
committed
don't allocate for inexact jacobian. just modifiy J
1 parent 3565824 commit 413f40b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/pseudotransient.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,17 @@ end
114114
function perform_step!(cache::PseudoTransientCache{true})
115115
@unpack u, u_prev, fu1, f, p, alg, J, linsolve, du, alpha, tc_storage = cache
116116
jacobian!!(J, cache)
117-
J_new = J - (1 / alpha) * I
117+
if J isa SciMLBase.AbstractSciMLOperator
118+
J = J - (1 / alpha) * I
119+
else
120+
J .= J - (1 / alpha) * I
121+
end
122+
#J_new = J - (1 / alpha) * I
118123

119124
termination_condition = cache.termination_condition(tc_storage)
120125

121126
# u = u - J \ fu
122-
linres = dolinsolve(alg.precs, linsolve; A = J_new, b = _vec(fu1), linu = _vec(du),
127+
linres = dolinsolve(alg.precs, linsolve; A = J, b = _vec(fu1), linu = _vec(du),
123128
p, reltol = cache.abstol)
124129
cache.linsolve = linres.cache
125130
@. u = u - du
@@ -147,11 +152,13 @@ function perform_step!(cache::PseudoTransientCache{false})
147152
termination_condition = cache.termination_condition(tc_storage)
148153

149154
cache.J = jacobian!!(cache.J, cache)
155+
156+
cache.J = cache.J - (1 / alpha) * I
150157
# u = u - J \ fu
151158
if linsolve === nothing
152-
cache.du = fu1 / (cache.J - (1 / alpha) * I)
159+
cache.du = fu1 / (cache.J)
153160
else
154-
linres = dolinsolve(alg.precs, linsolve; A = cache.J - (1 / alpha) * I,
161+
linres = dolinsolve(alg.precs, linsolve; A = cache.J,
155162
b = _vec(fu1),
156163
linu = _vec(cache.du), p, reltol = cache.abstol)
157164
cache.linsolve = linres.cache

0 commit comments

Comments
 (0)