Skip to content

Commit 9223d9a

Browse files
committed
add files
1 parent 3b42608 commit 9223d9a

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

test/ctdirect/problems/beam2.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Beam example from bocop
2+
# beam2: coordinate wise dynamics
3+
4+
function beam2()
5+
beam2 = @def begin
6+
t [0, 1], time
7+
x R², state
8+
u R, control
9+
x(0) == [0, 1]
10+
x(1) == [0, -1]
11+
(x₁)(t) == x₂(t)
12+
(x₂)(t) == u(t)
13+
0 x₁(t) 0.1
14+
-10 u(t) 10
15+
(u(t)^2) min
16+
end
17+
18+
return ((ocp=beam2, obj=8.898598, name="beam2", init=nothing))
19+
end

test/ctdirect/suite/test_exa.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# beam2
2+
if !isdefined(Main, :beam2)
3+
include("../problems/beam2.jl")
4+
end
5+
6+
display = false # during optim solves
7+
8+
# Test on CPU
9+
10+
println("testing: ExaModels (CPU)")
11+
12+
@testset verbose = true showtiming = true ":examodel :cpu :trapeze" begin
13+
prob = beam2()
14+
sol = solve(prob.ocp, :madnlp, :exa; disc_method = :trapeze, display = display)
15+
@test sol.objective prob.obj rtol = 1e-2
16+
end
17+
18+
@testset verbose = true showtiming = true ":examodel :cpu :euler :init" begin
19+
prob = beam2()
20+
sol = solve(prob.ocp, :madnlp, :exa; disc_method = :euler, display = display, init=(control=6.66,), max_iter = 0)
21+
@test control(sol)(0.5) == 6.66
22+
end

0 commit comments

Comments
 (0)