Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of short ministeps and improved printing #66

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Jutul"
uuid = "2b460a1a-8a2b-45b2-b125-b5c536396eb9"
authors = ["Olav Møyner <olav.moyner@gmail.com>"]
version = "0.2.28"
version = "0.2.29"

[deps]
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
Expand Down
8 changes: 4 additions & 4 deletions src/simulator/simulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ function solve_timestep!(sim, dT, forces, max_its, config; dt = dT, reports = no
break
else
# Pick another for the next step...
dt = pick_timestep(sim, config, dt, dT, forces, reports, ministep_reports, step_index = step_no, new_step = false)
dt = pick_timestep(sim, config, dt, dT, forces, reports, ministep_reports, step_index = step_no, new_step = false, remaining_time = dT - t_local)
end
else
dt_old = dt
Expand Down Expand Up @@ -532,7 +532,7 @@ function initial_setup!(sim, config, timesteps; restart = nothing, parameters =
end
# Set up storage
reports = []
states = Vector{JUTUL_OUTPUT_TYPE}()
states = Vector{Dict{Symbol, Any}}()
pth = config[:output_path]
initialize_io(pth)
has_restart = !(isnothing(restart) || restart === 0 || restart === 1 || restart == false)
Expand Down Expand Up @@ -669,8 +669,8 @@ function apply_nonlinear_strategy!(sim, dt, forces, it, max_iter, cfg, e, step_r
report = step_reports[end]
w0 = relaxation
relaxation = select_nonlinear_relaxation(sim, cfg[:relaxation], step_reports, relaxation)
if cfg[:info_level] > 1 && relaxation != w0
jutul_message("Relaxation", "Changed from $w0 to $relaxation at iteration $it.", color = :yellow)
if cfg[:info_level] > 2 && relaxation != w0
jutul_message("Relaxation", "Changed from $w0 to $relaxation at iteration $it.", color = :green)
end
failure = false
max_res = cfg[:max_residual]
Expand Down
9 changes: 7 additions & 2 deletions src/simulator/timesteps.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function pick_timestep(sim, config, dt_prev, dT, forces, reports, current_reports; step_index = NaN, new_step = false)
function pick_timestep(sim, config, dt_prev, dT, forces, reports, current_reports; step_index = NaN, new_step = false, remaining_time = dT)
# Try to do the full step, unless one of our selectors/limits tells us otherwise.
# No need to limit to whatever remains of the interval since that is fixed on the outside.
dt = dT
Expand All @@ -23,6 +23,12 @@ function pick_timestep(sim, config, dt_prev, dT, forces, reports, current_report
for sel in selectors
dt = valid_timestep(sel, dt)
end
# If we are not going to reach the end anyway, we split the remaining part
# into two to avoid a long step and a very short step.
half_remain = remaining_time/2.0
if dt > half_remain && dt < remaining_time
dt = half_remain
end
dt = min(dt, config[:max_timestep])
if config[:info_level] > 1
ratio = dt/dt_prev
Expand All @@ -37,7 +43,6 @@ function pick_timestep(sim, config, dt_prev, dT, forces, reports, current_report
else
t_sym = "🔄"
end
# @info "Selected new sub-timestep $(get_tstr(dt)) from previous $(get_tstr(dt_prev)) $t_sym"
jutul_message("Next mini-step", "Δt = $(get_tstr(dt)) from previous $(get_tstr(dt_prev)) $t_sym", color = :default)
end
return dt
Expand Down
Loading