-
-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
File src/DASSL.jl line 686 has the function:
# generate a function that computes approximate jacobian using forward
# finite differences
function numerical_jacobian(F,reltol,abstol,weights)
function numjac(t, y, dy, a)
ep = eps(one(t)) # this is the machine epsilon
h = 1/a # h ~ 1/a
wt = weights(y,reltol,abstol)
# delta for approximation of jacobian. I removed the
# sign(h_next*dy0) from the definition of delta because it was
# causing trouble when dy0==0 (which happens for ord==1)
edelta = diagm(0=>max.(abs.(y),abs.(h*dy),wt)*sqrt(ep))
b=dy-a*y
f(y1) = F(t,y1,a*y1+b)
n = length(y)
jac = Array{eltype(y)}(undef,n,n)
for i=1:n
jac[:,i]=(f(y+edelta[:,i])-f(y))/edelta[i,i]
end
jac
end
end
This (central) function should be improved:
-
In the for loop
f(y)
is called in every iteration, althoughy
does not change. This means that there aren-1
unnecessary calls of the right hand side function. The call off(y)
should be moved out of the for loop and the result stored in a vector. -
The statement
jac = Array{eltype(y)}(undef,n,n)
generates the Jacobian matrix whenever this function is called. So, when this function is called 100 times, then memory for 100 Jacobians are allocated. This should be improved: At the start of the simulation, memory for one Jacobian should be allocated that is then updated within this function.
Metadata
Metadata
Assignees
Labels
No labels