Skip to content

Commit 953624a

Browse files
authored
Merge pull request #183 from JuliaDynamics/hw/verboseinit
don't error on verbose when u0 is empty
2 parents a1672e6 + 1465cab commit 953624a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/initialization.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,17 @@ function initialize_component!(cf; verbose=true, kwargs...)
199199
@warn "Initialization for componend stalled with residual $(res)"
200200
elseif !SciMLBase.successful_retcode(sol.retcode)
201201
throw(ArgumentError("Initialization failed. Solver returned $(sol.retcode)"))
202+
else
203+
verbose && @info "Initialization successful with residual $(LinearAlgebra.norm(sol.resid))"
202204
end
203205
set_init!.(Ref(cf), SII.variable_symbols(sol), sol.u)
204206
resid = sol.resid
205207
else
206208
resid = init_residual(cf; recalc=true)
209+
verbose && @info "No free variables! Residual $(LinearAlgebra.norm(resid))"
207210
end
208211

209212
set_metadata!(cf, :init_residual, resid)
210-
211-
verbose && @info "Initialization successful with residual $(LinearAlgebra.norm(sol.resid))"
212213
cf
213214
end
214215

test/initialization_test.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ end
6565
@test vf.symmetadata[:i_r][:default] == 1
6666
@test vf.symmetadata[:i_i][:default] == 0.1
6767

68-
NetworkDynamics.initialize_component!(vf)
68+
NetworkDynamics.initialize_component!(vf; verbose=true)
6969
@test NetworkDynamics.init_residual(vf) < 1e-8
7070
@test init_residual(vf) init_residual(vf; recalc=true)
71+
72+
# make empty problem
73+
set_default!(vf, :Pm, get_init(vf, :Pm))
74+
set_default!(vf, , get_init(vf, ))
75+
set_default!(vf, , get_init(vf, ))
76+
77+
NetworkDynamics.initialize_component!(vf; verbose=true)
7178
end

0 commit comments

Comments
 (0)