Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Apr 15, 2024
1 parent 35587b2 commit 4c595d2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/src/Ribasim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ using OrdinaryDiffEq: OrdinaryDiffEq, OrdinaryDiffEqRosenbrockAdaptiveAlgorithm
using PreallocationTools: DiffCache, get_tmp
using SciMLBase:
init,
check_error!,
solve!,
step!,
SciMLBase,
ReturnCode,
successful_retcode,
CallbackSet,
ODEFunction,
Expand Down
7 changes: 3 additions & 4 deletions core/src/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,21 @@ function main(ARGS::Vector{String})::Cint
config = Config(arg)
mkpath(results_path(config, "."))
open(results_path(config, "ribasim.log"), "w") do io
logger =
Ribasim.setup_logger(; verbosity = config.logging.verbosity, stream = io)
logger = setup_logger(; verbosity = config.logging.verbosity, stream = io)
with_logger(logger) do
cli = (; ribasim_version = string(pkgversion(Ribasim)))
(; starttime, endtime) = config
if config.ribasim_version != cli.ribasim_version
@warn "The Ribasim version in the TOML config file does not match the used Ribasim CLI version." config.ribasim_version cli.ribasim_version
end
@info "Starting a Ribasim simulation." cli.ribasim_version starttime endtime
model = Ribasim.run(config)
model = run(config)
if successful_retcode(model)
@info "The model finished successfully"
return 0
end

t = Ribasim.datetime_since(model.integrator.t, starttime)
t = datetime_since(model.integrator.t, starttime)
retcode = model.integrator.sol.retcode
@error "The model exited at model time $t with return code $retcode.\nSee https://docs.sciml.ai/DiffEqDocs/stable/basics/solution/#retcodes"
return 1
Expand Down
9 changes: 7 additions & 2 deletions core/src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function SciMLBase.step!(model::Model, dt::Float64)::Model
if ntimes > 0 && round(ntimes) ntimes
update_allocation!(integrator)
end
step!(integrator, dt; stop_at_tdt = true)
step!(integrator, dt, true)
return model
end

Expand All @@ -222,9 +222,14 @@ function SciMLBase.solve!(model::Model)::Model
for _ in TimeChoiceIterator(integrator, times)
update_allocation!(integrator)
end

# https://github.com/SciML/SciMLBase.jl/issues/669
if integrator.sol.retcode != ReturnCode.Default
return integrator.sol
end
integrator.sol = SciMLBase.solution_new_retcode(integrator.sol, ReturnCode.Success)
else
solve!(integrator)
end
check_error!(integrator)
return model
end

0 comments on commit 4c595d2

Please sign in to comment.