From 61c813aefe00b429ddd4907f9d71bd0cdd455047 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Mon, 14 Sep 2026 23:27:23 -0400 Subject: [PATCH] =?UTF-8?q?debug:=20also=20warm-start=20`k=CC=84`=20for=20?= =?UTF-8?q?`OrthogonalCollocation`=20The=20PR=20#445=20skipped=20the=20war?= =?UTF-8?q?m-starting=20of=20the=20`k=CC=84`=20vector=20in=20the=20decisio?= =?UTF-8?q?n=20variable=20because=20I=20though=20that=20it=20was=20state?= =?UTF-8?q?=20DERIVATIVE,=20thus=20different=20units=20than=20the=20states?= =?UTF-8?q?.=20But=20I=20was=20wrong,=20the=20`k=CC=84`=20is=20the=20state?= =?UTF-8?q?=20at=20the=20collocation=20points.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are no reasons to not warm-start this vector anymore. --- src/model/nonlinmodeldae.jl | 2 +- test/1_test_sim_model.jl | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/model/nonlinmodeldae.jl b/src/model/nonlinmodeldae.jl index 5036b8b8a..9d619767d 100644 --- a/src/model/nonlinmodeldae.jl +++ b/src/model/nonlinmodeldae.jl @@ -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 diff --git a/test/1_test_sim_model.jl b/test/1_test_sim_model.jl index c31b827d0..26dae5bda 100644 --- a/test/1_test_sim_model.jl +++ b/test/1_test_sim_model.jl @@ -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[] @@ -565,7 +566,7 @@ 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 @@ -573,9 +574,18 @@ end 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))