Skip to content
Snippets Groups Projects
Commit be38bf84 authored by Brian Groenke's avatar Brian Groenke
Browse files

Add isfinite check to CFL callback

parent 9e1f5c9b
No related branches found
No related tags found
1 merge request!36Fix CFL step limiter callback choking on autodiff types
struct CFLHeatState{A}
Δt::A
default_dt::Float64
end
function (fn::CryoGridCallbackFunction{<:CFLHeatState})(u,p,t)
function (fn::CryoGridCallbackFunction{CFLHeatState{<:AbstractArray}})(u,p,t)
let Δt = fn.state.Δt,
Δx = Δ(fn.setup.grid),
Ceff = getvar(:Ceff, fn.setup, u), # apparent heat capacity
kc = getvar(:kc, fn.setup, u); # thermal cond. at grid centers
@. Δt = adstrip(Δx^2 * Ceff / kc)
minimum(Δt)
Δt_min = minimum(Δt)
IfElse.ifelse(isfinite(Δt_min), Δt_min, fn.default_dt)
end
end
function CFLStepLimiter(setup::HeatOnlySetup; courant_number=1//2)
state = CFLHeatState(similar(Δ(setup.grid)))
function (fn::CryoGridCallbackFunction{CFLHeatState{Nothing}})(u,p,t)
let Δx = Δ(fn.setup.grid),
Ceff = getvar(:Ceff, fn.setup, u), # apparent heat capacity
kc = getvar(:kc, fn.setup, u); # thermal cond. at grid centers
Δt = adstrip(Δx^2 * Ceff / kc)
Δt_min = minimum(Δt)
IfElse.ifelse(isfinite(Δt_min), Δt_min, fn.default_dt)
end
end
function CFLStepLimiter(setup::HeatOnlySetup; courant_number=1//2, default_dt=60.0, iip=true)
state = iip ? CFLHeatState(similar(Δ(setup.grid)), default_dt) : CFLHeatState(nothing, default_dt)
fn = CryoGridCallbackFunction(setup, state)
StepsizeLimiter(fn; safety_factor=courant_number, max_step=true)
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment