Skip to content

Commit

Permalink
adding tests + removing prints.
Browse files Browse the repository at this point in the history
  • Loading branch information
weinbe58 committed Dec 23, 2023
1 parent db93c54 commit 3b2f499
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/hinit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ function euler_first_guess(solver::AbstractDPSolver{T}, hmax::T, posneg::T) wher
(abs(f0i)/sk)^2, (abs(yi)/sk)^2 # dnf, dny
end

println("euler_first_guess: dnf = $dnf, dny = $dny")

if (dnf <= 1.0e-10) || (dny <= 1.0e-10)
h = 1.0e-6
else
Expand Down Expand Up @@ -48,7 +46,6 @@ function hinit(
the increment for explicit euler is small
compared to the solution
=#
println("hinit: y = $(solver.y), k1 = $(solver.k1), k2 = $(solver.k2), k3 = $(solver.k3)")
h, dnf = euler_first_guess(solver, hmax, posneg)

###### Perform an explicit step
Expand Down
24 changes: 24 additions & 0 deletions test/errors.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Test
using DormandPrince:
DP5Solver,
DP8Solver,
Options,
LARGER_NMAX_NEEDED,
STEP_SIZE_BECOMES_TOO_SMALL

using DormandPrince. DP5: dopri5
using DormandPrince. DP8: dop853

@testset "Larger nmax needed" begin
solver = DP5Solver(
Expand All @@ -19,6 +21,17 @@ using DormandPrince. DP5: dopri5
h, report = dopri5(solver, 2/0.0001, 0.1, 0.0)
@test report.idid == LARGER_NMAX_NEEDED

solver = DP8Solver(
stiff_fcn,
0.0, # start at 0.0
[0.0001] # delta
; maximum_allowed_steps=1
)


h, report = dop853(solver, 2/0.0001, 0.1, 0.0)
@test report.idid == LARGER_NMAX_NEEDED

end

@testset "Step size becomes too small" begin
Expand All @@ -32,4 +45,15 @@ end

h, report = dopri5(solver, 2/0.0001, 0.1, 0.0)
@test report.idid == STEP_SIZE_BECOMES_TOO_SMALL

solver = DP8Solver(
stiff_fcn,
0.0,
[0.0001]
; uround=10000
)


h, report = dop853(solver, 2/0.0001, 0.1, 0.0)
@test report.idid == STEP_SIZE_BECOMES_TOO_SMALL
end
19 changes: 10 additions & 9 deletions test/stiff.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using Test
using DormandPrince: DP5Solver, integrate
using DormandPrince: DP5Solver, DP8Solver, integrate

function stiff_fcn(x, y, f)
f[1] = y[1]^2 - y[1]^3
end

@testset "Stiff ODE" begin

solver = DP5Solver(
stiff_fcn,
0.0, # start at 0.0
[0.0001] # initial value of delta
)

integrate(solver, 2/0.0001)

for SolverType in [DP5Solver, DP8Solver]
solver = SolverType(
stiff_fcn,
0.0,
[0.0001]
)

integrate(solver, 2/0.0001)
end
end

0 comments on commit 3b2f499

Please sign in to comment.