Skip to content

Commit

Permalink
Merge pull request #183 from JuliaDynamics/hw/verboseinit
Browse files Browse the repository at this point in the history
don't error on verbose when u0 is empty
  • Loading branch information
hexaeder authored Nov 25, 2024
2 parents a1672e6 + 1465cab commit 953624a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion test/initialization_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 953624a

Please sign in to comment.