Skip to content

Commit

Permalink
adding tests for pseudotransient method
Browse files Browse the repository at this point in the history
  • Loading branch information
yonatanwesen committed Sep 19, 2023
1 parent d14c57e commit dc98dbc
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion test/basictests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ u0 = [1.0, 1.0]

precs = [
NonlinearSolve.DEFAULT_PRECS,
(args...) -> (Diagonal(rand!(similar(u0))), nothing)
(args...) -> (Diagonal(rand!(similar(u0))), nothing),
]

for prec in precs, linsolve in (nothing, KrylovJL_GMRES())
Expand Down Expand Up @@ -772,3 +772,44 @@ for options in list_of_options
sol = solve(probN, alg, abstol = 1e-10)
@test all(abs.(f(u, p)) .< 1e-10)
end

# --- PseudoTransient tests ---

function test_f!(du, u, p)
du[1] = 2 - 2u[1]
du[2] = u[1] - 4u[2]
return du
end

u0 = zeros(2)

probN = NonlinearProblem{true}(test_f!, u0)

sol = solve(probN, PseudoTransient())

@test sol.retcode == ReturnCode.Success
du = zeros(2)
test_f!(du, sol.u, 4.0)
@test du[0, 0] atol=1e-7

#oop
simple_test(u, p) = 0.9f0 .* u .- u
probN = NonlinearProblem{false}(simple_test, [1.0f0])
sol = solve(probN, PseudoTransient(alpha_initial = 1.0))

@test sol.retcode == ReturnCode.Success
@test abs(sol.u[1]) <= 1.0f-4

#test jacobian free PseudoTransient method
function f!(res, u, p)
@. res = u * u - p
end
u0 = [1.0, 1.0]
p = 2.0
probN = NonlinearProblem(f!, u0, p)

linsolve = LinearSolve.KrylovJL_GMRES()
sol = solve(probN,
PseudoTransient(alpha_initial = 10.0, linsolve = linsolve),
reltol = 1e-9)
@test sol.retcode == ReturnCode.Success

0 comments on commit dc98dbc

Please sign in to comment.