Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/semidiscretization/semidiscretization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,13 @@ function jacobian_fd(semi::AbstractSemidiscretization;
# use second order finite difference to estimate Jacobian matrix
for idx in eachindex(u0_ode)
# determine size of fluctuation
epsilon = sqrt(eps(typeof(u0_ode[idx])))
# This is the approach used by FiniteDiff.jl to compute the
# step size, which assures that the finite difference is accurate
# for very small and very large absolute values `u0_ode[idx]`.
# See https://github.com/trixi-framework/Trixi.jl/pull/2514#issuecomment-3190534904.
absstep = sqrt(eps(typeof(u0_ode[idx])))
relstep = absstep
epsilon = max(relstep * abs(u0_ode[idx]), absstep)

# plus fluctuation
u_ode[idx] = u0_ode[idx] + epsilon
Expand Down
Loading