Skip to content

ClimFlows/CFTimeSchemes.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CFTimeSchemes

Dev Build Status Coverage Ask DeepWiki

AD-friendly, fixed time-step RK and ARK schemes.

Installation

CFTimesSchemes is registered in the ClimFlows registry. Follow instructions there, then:

] add CFTimeSchemes

Example

using CFTimeSchemes: void, RungeKutta4, IVPSolver, advance!
import CFTimeSchemes: tendencies!
using UnicodePlots

struct Model{A}
    z::A
end
tendencies!(dstate, _, m::Model, state, _) = (@. dstate = state*m.z), nothing

function make_model(Scheme)
    x, y = range(-3, 1, 101), range(-4, 4, 201)
    model = Model([xx+yy*1im for xx in x, yy in y])
    z0 = one.(model.z) # complex 1
    scheme = Scheme(model)
    return model, scheme, z0
end

function stability_region(Scheme)
    model, scheme, z0 = make_model(Scheme)
    # non-mutating solver
    solver = IVPSolver(scheme, 1.0)
    z1, t = advance!(void, solver, z0, 0.0, 100)
    @info Scheme
    display(heatmap(@. min(1.0, abs(z1))))

    # mutating solver
    solver = IVPSolver(scheme, 1.0, z0, nothing)
    z1, t = advance!(z1, solver, z0, 0.0, 100) # compile
    @time z1, t = advance!(z1, solver, z0, 0.0, 100) # should not allocate
    return
end

stability_region(RungeKutta4)

Change Log

Version 0.3

  • new API:
    • tendencies! now has variants for implicit and implicit-explicit (IMEX) schemes
    • tendencies! now returns scratch. This enables default implementations for model_dstate and scratch_space.
    • update! now takes model as an argument and can be customized for user model types.

About

AD-friendly, fixed time-step RK and ARK schemes

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages