From 1465cab8ebd1689f439b0752180bbe420d2f1293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20W=C3=BCrfel?= Date: Mon, 25 Nov 2024 14:25:59 +0100 Subject: [PATCH] don't error on verbose when u0 is empty --- src/initialization.jl | 5 +++-- test/initialization_test.jl | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/initialization.jl b/src/initialization.jl index 3cfb99aa..ae9a5739 100644 --- a/src/initialization.jl +++ b/src/initialization.jl @@ -199,16 +199,17 @@ function initialize_component!(cf; verbose=true, kwargs...) @warn "Initialization for componend stalled with residual $(res)" elseif !SciMLBase.successful_retcode(sol.retcode) throw(ArgumentError("Initialization failed. Solver returned $(sol.retcode)")) + else + verbose && @info "Initialization successful with residual $(LinearAlgebra.norm(sol.resid))" end set_init!.(Ref(cf), SII.variable_symbols(sol), sol.u) resid = sol.resid else resid = init_residual(cf; recalc=true) + verbose && @info "No free variables! Residual $(LinearAlgebra.norm(resid))" end set_metadata!(cf, :init_residual, resid) - - verbose && @info "Initialization successful with residual $(LinearAlgebra.norm(sol.resid))" cf end diff --git a/test/initialization_test.jl b/test/initialization_test.jl index e1041841..04a20124 100644 --- a/test/initialization_test.jl +++ b/test/initialization_test.jl @@ -65,7 +65,14 @@ end @test vf.symmetadata[:i_r][:default] == 1 @test vf.symmetadata[:i_i][:default] == 0.1 - NetworkDynamics.initialize_component!(vf) + NetworkDynamics.initialize_component!(vf; verbose=true) @test NetworkDynamics.init_residual(vf) < 1e-8 @test init_residual(vf) ≈ init_residual(vf; recalc=true) + + # make empty problem + set_default!(vf, :Pm, get_init(vf, :Pm)) + set_default!(vf, :θ, get_init(vf, :θ)) + set_default!(vf, :ω, get_init(vf, :ω)) + + NetworkDynamics.initialize_component!(vf; verbose=true) end