Skip to content

Commit

Permalink
Fix CGEuler not respecting dtmax and dtmin
Browse files Browse the repository at this point in the history
  • Loading branch information
bgroenks96 committed Dec 26, 2024
1 parent 4b65f40 commit b1002b9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CryoGrid"
uuid = "a535b82e-5f3d-4d97-8b0b-d6483f5bebd5"
authors = ["Brian Groenke <[email protected]>", "Jan Nitzbon <[email protected]>", "Moritz Langer <[email protected]>"]
version = "0.23.1"
version = "0.23.2"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
2 changes: 1 addition & 1 deletion examples/heat_sfcc_samoylov_implicitT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tile = Tile(strat, modelgrid, forcings, ssinit);
tspan = (DateTime(2000,10,1), DateTime(2002,10,1))
u0, du0 = initialcondition!(tile, tspan);
prob = CryoGridProblem(tile, u0, tspan, saveat=24*3600, savevars=(:T,:θw,:∂H∂T), step_limiter=nothing)
integrator = init(prob, ImplicitEuler(autodiff=false))
integrator = init(prob, ImplicitEuler())
# test one step
@time step!(integrator)
last_t = integrator.t
Expand Down
13 changes: 11 additions & 2 deletions src/Solvers/LiteImplicit/cglite_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ struct LiteImplicitEulerCache{Tu,TA} <: SciMLBase.DECache
D::TA
end

function DiffEqBase.__init(prob::CryoGridProblem, alg::LiteImplicitEuler, args...; dt=24*3600.0, saveat=dt, kwargs...)
function DiffEqBase.__init(
prob::CryoGridProblem,
alg::LiteImplicitEuler,
args...;
dt=24*3600.0,
dtmax=dt,
dtmin=1.0,
saveat=dt,
kwargs...
)
tile = Tile(prob.f)
grid = tile.grid
u0 = copy(prob.u0)
Expand Down Expand Up @@ -54,6 +63,6 @@ function DiffEqBase.__init(prob::CryoGridProblem, alg::LiteImplicitEuler, args..
similar(u0, eltype(u0), length(prob.u0.H)),
)
p = isnothing(prob.p) ? prob.p : collect(prob.p)
opts = CryoGridIntegratorOptions(; dtmax=dt, saveat=CryoGrid.expandtstep(saveat, prob.tspan), kwargs...)
opts = CryoGridIntegratorOptions(; saveat=CryoGrid.expandtstep(saveat, prob.tspan), dtmax, dtmin, kwargs...)
return CryoGridIntegrator(alg, cache, opts, sol, copy(u0), p, t0, convert(eltype(prob.tspan), dt), 1, 1)
end
2 changes: 1 addition & 1 deletion src/Solvers/basic_solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ function perform_step!(integrator::CryoGridIntegrator{CGEuler})
# set next dt
# compute maximum timestep
dtmax = CryoGrid.timestep(tile, du, u, p, t₀)
integrator.dt = dtmax
integrator.dt = max(min(dtmax, integrator.opts.dtmax), integrator.opts.dtmin)
return nothing
end
2 changes: 1 addition & 1 deletion src/Solvers/integrator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function DiffEqBase.sensitivity_solution(sol::CryoGridSolution, u, t)
end

Base.@kwdef mutable struct CryoGridIntegratorOptions{Tt,Tsaveat,Ttstops}
dtmax::Tt = 24*3600.0
dtmax::Tt = 3600.0
dtmin::Tt = one(typeof(dtmax))
saveat::Tsaveat = typeof(dtmax)[]
tstops::Ttstops = SortedSet{typeof(dtmin)}()
Expand Down
7 changes: 5 additions & 2 deletions src/problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Constructor for `CryoGridProblem` that automatically generates all necessary cal
function CryoGridProblem(
tile::Tile,
u0::ComponentVector,
tspan::NTuple{2,Float64};
tspan::NTuple{2,Float64},
p::Union{Nothing,AbstractVector}=nothing;
diagnostic_stepsize=3600.0,
saveat=3600.0,
savevars=(),
Expand All @@ -68,7 +69,7 @@ function CryoGridProblem(
# strip all "fixed" parameters
tile = stripparams(FixedParam, tile)
# retrieve variable parameters
p = length(ModelParameters.params(tile)) > 0 ? parameters(tile) : nothing
tilepara = length(ModelParameters.params(tile)) > 0 ? parameters(tile) : nothing
du0 = zero(u0)
# remove units
tile = stripunits(tile)
Expand All @@ -95,6 +96,8 @@ function CryoGridProblem(
tile.data.outputs = savevals
# build mass matrix
mass_matrix = Numerics.build_mass_matrix(tile.state)
# get params
p = isnothing(p) && !isnothing(tilepara) ? ustrip.(vec(tilepara)) : p
func = odefunction(tile, u0, p, tspan; mass_matrix, specialization, function_kwargs...)
return CryoGridProblem{true}(func, u0, tspan, p, callbacks, saveat, getsavestate, isoutofdomain, prob_kwargs)
end
Expand Down

2 comments on commit b1002b9

@bgroenks96
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/122029

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.23.2 -m "<description of version>" b1002b95b9e455871c10c89aa5e4af9ac5659b8b
git push origin v0.23.2

Also, note the warning: Version 0.23.2 skips over 0.23.1
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

Please sign in to comment.