Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/model/nonlinmodeldae.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ function reset_warmstart!(model::NonLinModelDAE, transcription::OrthogonalColloc
model.a0 .= a0s
model.Z[1:nx] .= x0s
model.Z[(nx+1):(nx+na)] .= a0s
model.Z[(nx+na+1):(nx+na+nk̄)] .= 0 # state derivative ki warm-started at 0
model.Z[(nx+na+1):(nx+na+nk̄)] .= x0s
ā_Z = @views model.Z[(nx+na+nk̄+1):end]
repeat!(ā_Z, a0s, no)
return nothing
Expand Down
16 changes: 13 additions & 3 deletions test/1_test_sim_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,9 @@ end
p = [1.0]

transcription = OrthogonalCollocation(0, 4, roots=:gausslegendre)
xs_0 = [-0.5]
as_0 = [-1]
dae = NonLinModelDAE(fq!, h!, Ts, nu, nx, na, ny; p, transcription, as_0)
dae = NonLinModelDAE(fq!, h!, Ts, nu, nx, na, ny; p, transcription, xs_0, as_0)
u = [0.0]
d = Float64[]

Expand All @@ -565,17 +566,26 @@ end
@test evaloutput(dae) ≈ zeros(1) atol=1e-6

transcription = TrapezoidalCollocation()
dae2 = NonLinModelDAE(fq!, h!, Ts, nu, nx, na, ny; p, transcription)
dae2 = NonLinModelDAE(fq!, h!, Ts, nu, nx, na, ny; p, transcription, as_0, xs_0)
@test updatestate!(dae2, u) ≈ zeros(1) atol=1e-6
@test updatestate!(dae2, u, d) ≈ zeros(1) atol=1e-6
@test dae2.x0 ≈ zeros(1) atol=1e-6
@test dae2() ≈ zeros(1) atol=1e-6

x = initstate!(dae, [10])
@test dae.a0 ≈ as_0 atol=1e-6
@test dae.Z[2:2] ≈ as_0 atol=1e-6
@test dae.Z[1:1] ≈ xs_0 atol=1e-6
@test dae.Z[2:2] ≈ as_0 atol=1e-6
@test dae.Z[3:6] ≈ repeat(xs_0, 4) atol=1e-6
@test dae.Z[7:10] ≈ repeat(as_0, 4) atol=1e-6
@test evaloutput(dae) ≈ [0] atol=1e-6

x = initstate!(dae2, [10])
@test dae2.Z[1:1] ≈ xs_0 atol=1e-6
@test dae2.Z[2:2] ≈ as_0 atol=1e-6
@test dae2.Z[3:3] ≈ as_0 atol=1e-6
@test evaloutput(dae2) ≈ [0] atol=1e-6

@test_throws DimensionMismatch updatestate!(dae, zeros(2))
@test_throws DimensionMismatch updatestate!(dae, zeros(1), zeros(1))
@test_throws DimensionMismatch evaloutput(dae, zeros(1))
Expand Down
Loading