forked from SciML/RecursiveArrayTools.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathodesolve.jl
More file actions
75 lines (67 loc) · 1.87 KB
/
odesolve.jl
File metadata and controls
75 lines (67 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using OrdinaryDiffEq, NLsolve, RecursiveArrayTools, Test, ArrayInterface, StaticArrays
function lorenz(du, u, p, t)
du[1] = 10.0 * (u[2] - u[1])
du[2] = u[1] * (28.0 - u[3]) - u[2]
return du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
u0 = AP[[1.0, 0.0], [0.0]]
@test ArrayInterface.zeromatrix(u0) isa Matrix
tspan = (0.0, 100.0)
prob = ODEProblem(lorenz, u0, tspan)
sol = solve(prob, Tsit5())
sol = solve(prob, AutoTsit5(Rosenbrock23(autodiff = false)))
sol = solve(prob, AutoTsit5(Rosenbrock23()))
@test all(Array(sol) .== sol)
function mymodel(F, vars)
for i in 1:2
x = vars.x[i]
F.x[i][1, 1] = (x[1, 1] + 3) * (x[1, 2]^3 - 7) + 18.0
F.x[i][1, 2] = sin(x[1, 2] * exp(x[1, 1]) - 1)
F.x[i][2, 1] = (x[2, 1] + 3) * (x[2, 2]^3 - 7) + 19.0
F.x[i][2, 2] = sin(x[2, 2] * exp(x[2, 1]) - 3)
end
return
end
# To show that the function works
F = AP[[0.0 0.0; 0.0 0.0], [0.0 0.0; 0.0 0.0]]
u0 = AP[[0.1 1.2; 0.1 1.2], [0.1 1.2; 0.1 1.2]]
result = mymodel(F, u0)
nlsolve(mymodel, u0)
# Nested ArrayPartition solves
function dyn(u, p, t)
return ArrayPartition(
AP[zeros(1), [0.0]],
AP[zeros(1), [0.0]]
)
end
@test solve(
ODEProblem(
dyn,
ArrayPartition(
AP[zeros(1), [-1.0]],
AP[zeros(1), [0.75]]
),
(0.0, 1.0)
),
AutoTsit5(Rodas5())
).retcode == ReturnCode.Success
@test_broken solve(
ODEProblem(
dyn,
ArrayPartition(
AP[zeros(1), [-1.0]],
AP[zeros(1), [0.75]]
),
(0.0, 1.0)
),
Rodas5()
).retcode == ReturnCode.Success
function rhs!(duu::VectorOfArray, uu::VectorOfArray, p, t)
du = parent(duu)
u = parent(uu)
return du .= u
end
u = fill(SVector{2}(ones(2)), 2, 3)
ode = ODEProblem(rhs!, VectorOfArray(u), (0.0, 1.0))
sol = solve(ode, Tsit5())
@test SciMLBase.successful_retcode(sol)