Skip to content

Commit aa126f7

Browse files
committed
format
1 parent f6b2579 commit aa126f7

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

Diff for: lib/SimpleImplicitDiscreteSolve/src/SimpleImplicitDiscreteSolve.jl

+16-13
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ function DiffEqBase.__init(prob::ImplicitDiscreteProblem, alg::SimpleIDSolve; dt
2424
sol, (sol.retcode != ReturnCode.Success)
2525
end
2626

27-
function DiffEqBase.solve(prob::ImplicitDiscreteProblem, alg::SimpleIDSolve;
28-
dt = 1,
29-
save_everystep = true,
30-
save_start = true,
31-
adaptive = false,
32-
dense = false,
33-
save_end = true,
34-
kwargs...)
35-
27+
function DiffEqBase.solve(prob::ImplicitDiscreteProblem, alg::SimpleIDSolve;
28+
dt = 1,
29+
save_everystep = true,
30+
save_start = true,
31+
adaptive = false,
32+
dense = false,
33+
save_end = true,
34+
kwargs...)
3635
@assert !adaptive
3736
@assert !dense
3837
(initsol, initfail) = DiffEqBase.__init(prob, alg; dt)
3938
if initfail
40-
sol = DiffEqBase.build_solution(prob, alg, prob.tspan[1], u0, k = nothing, stats = nothing, calculate_error = false)
39+
sol = DiffEqBase.build_solution(prob, alg, prob.tspan[1], u0, k = nothing,
40+
stats = nothing, calculate_error = false)
4141
return SciMLBase.solution_new_retcode(sol, ReturnCode.InitialFailure)
4242
end
4343

@@ -66,15 +66,17 @@ function DiffEqBase.solve(prob::ImplicitDiscreteProblem, alg::SimpleIDSolve;
6666
for i in 2:length(ts)
6767
uprev = u
6868
t = ts[i]
69-
nlf = isinplace(f) ? (out, u, p) -> f(out, u, uprev, p, t) : (u, p) -> f(u, uprev, p, t)
69+
nlf = isinplace(f) ? (out, u, p) -> f(out, u, uprev, p, t) :
70+
(u, p) -> f(u, uprev, p, t)
7071
nlprob = NonlinearProblem{isinplace(f)}(nlf, uprev, p)
7172
nlsol = solve(nlprob, SimpleNewtonRaphson())
7273
u = nlsol.u
7374
save_everystep && (us[i] = u)
7475
convfail = (nlsol.retcode != ReturnCode.Success)
7576

7677
if convfail
77-
sol = DiffEqBase.build_solution(prob, alg, ts[1:i], us[1:i], k = nothing, stats = nothing, calculate_error = false)
78+
sol = DiffEqBase.build_solution(prob, alg, ts[1:i], us[1:i], k = nothing,
79+
stats = nothing, calculate_error = false)
7880
sol = SciMLBase.solution_new_retcode(sol, ReturnCode.ConvergenceFailure)
7981
return sol
8082
end
@@ -86,7 +88,8 @@ function DiffEqBase.solve(prob::ImplicitDiscreteProblem, alg::SimpleIDSolve;
8688
calculate_error = false)
8789

8890
DiffEqBase.has_analytic(prob.f) &&
89-
DiffEqBase.calculate_solution_errors!(sol; timeseries_errors = true, dense_errors = false)
91+
DiffEqBase.calculate_solution_errors!(
92+
sol; timeseries_errors = true, dense_errors = false)
9093
sol
9194
end
9295

Diff for: lib/SimpleImplicitDiscreteSolve/test/runtests.jl

+17-17
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,39 @@ using OrdinaryDiffEqSDIRK
66
# Test implicit Euler using ImplicitDiscreteProblem
77
@testset "Implicit Euler" begin
88
function lotkavolterra(u, p, t)
9-
[1.5*u[1] - u[1]*u[2], -3.0*u[2] + u[1]*u[2]]
9+
[1.5 * u[1] - u[1] * u[2], -3.0 * u[2] + u[1] * u[2]]
1010
end
1111

1212
function f!(resid, u_next, u, p, t)
1313
lv = lotkavolterra(u_next, p, t)
14-
resid[1] = u_next[1] - u[1] - 0.01*lv[1]
15-
resid[2] = u_next[2] - u[2] - 0.01*lv[2]
14+
resid[1] = u_next[1] - u[1] - 0.01 * lv[1]
15+
resid[2] = u_next[2] - u[2] - 0.01 * lv[2]
1616
nothing
1717
end
18-
u0 = [1., 1.]
19-
tspan = (0., 0.5)
18+
u0 = [1.0, 1.0]
19+
tspan = (0.0, 0.5)
2020

2121
idprob = ImplicitDiscreteProblem(f!, u0, tspan, [])
2222
idsol = solve(idprob, SimpleIDSolve(), dt = 0.01)
2323

2424
oprob = ODEProblem(lotkavolterra, u0, tspan)
2525
osol = solve(oprob, ImplicitEuler())
2626

27-
@test isapprox(idsol[end-1], osol[end], atol = 0.1)
27+
@test isapprox(idsol[end - 1], osol[end], atol = 0.1)
2828

2929
### free-fall
3030
# y, dy
31-
function ff(u, p, t)
31+
function ff(u, p, t)
3232
[u[2], -9.8]
3333
end
3434

35-
function g!(resid, u_next, u, p, t)
36-
f = ff(u_next, p, t)
37-
resid[1] = u_next[1] - u[1] - 0.01*f[1]
38-
resid[2] = u_next[2] - u[2] - 0.01*f[2]
35+
function g!(resid, u_next, u, p, t)
36+
f = ff(u_next, p, t)
37+
resid[1] = u_next[1] - u[1] - 0.01 * f[1]
38+
resid[2] = u_next[2] - u[2] - 0.01 * f[2]
3939
nothing
4040
end
41-
u0 = [10., 0.]
41+
u0 = [10.0, 0.0]
4242
tspan = (0, 0.5)
4343

4444
idprob = ImplicitDiscreteProblem(g!, u0, tspan, [])
@@ -47,17 +47,17 @@ using OrdinaryDiffEqSDIRK
4747
oprob = ODEProblem(ff, u0, tspan)
4848
osol = solve(oprob, ImplicitEuler())
4949

50-
@test isapprox(idsol[end-1], osol[end], atol = 0.1)
50+
@test isapprox(idsol[end - 1], osol[end], atol = 0.1)
5151
end
5252

5353
@testset "Solver initializes" begin
54-
function periodic!(resid, u_next, u, p, t)
55-
resid[1] = u_next[1] - u[1] - sin(t*π/4)
56-
resid[2] = 16 - u_next[2]^2 - u_next[1]^2
54+
function periodic!(resid, u_next, u, p, t)
55+
resid[1] = u_next[1] - u[1] - sin(t * π / 4)
56+
resid[2] = 16 - u_next[2]^2 - u_next[1]^2
5757
end
5858

5959
tsteps = 15
60-
u0 = [1., 3.]
60+
u0 = [1.0, 3.0]
6161
idprob = ImplicitDiscreteProblem(periodic!, u0, (0, tsteps), [])
6262
initsol, initfail = DiffEqBase.__init(idprob, SimpleIDSolve())
6363
@test initsol.u[1]^2 + initsol.u[2]^2 16

0 commit comments

Comments
 (0)