LCOV - code coverage report
Current view: top level - src - options.jl (source / functions) Hit Total Coverage
Test: on branch nothing Lines: 10 11 90.9 %
Date: 2025-02-26 15:13:49 Functions: 0 0 -

          Line data    Source code
       1             : """
       2             :     opts = options([T=Float64]
       3             :                    [;rtol=1e-3, atol=1e-8, h0=0.0, hmax=Inf, maxsteps=0])
       4             : 
       5             : created by [`options`](@ref): stores [`Solver`](@ref) options.
       6             : 
       7             : See also [`options`](@ref), [`Solver`](@ref)
       8             : """
       9             : SolverOptions{T} = @NamedTuple begin
      10             :     rtol::T
      11             :     atol::T
      12             :     h0::T
      13             :     hmax::T
      14             :     maxsteps::Int
      15             : end
      16             : 
      17         150 : function options(T=Float64;
      18             :                  rtol=T(1e-3), atol=T(1e-8), h0=T(0.0), hmax=T(Inf), maxsteps::Int=0)
      19          60 :     @assert rtol > 0 "relative tolerance must be positive"
      20          60 :     @assert atol > 0 "absolute tolerance must be positive"
      21          60 :     @assert h0 >= 0 "initial step size h0 must be nonnegative"
      22          60 :     @assert hmax > 0  "maximum step size h0 must be positive"
      23          60 :     @assert maxsteps >= 0 "maximum number of steps must be positive"
      24             : 
      25          60 :     (;rtol=T(rtol), atol=T(atol), h0=T(h0), hmax=T(hmax), maxsteps=maxsteps)
      26             : end
      27             : 
      28           0 : options(::T;
      29             :         rtol=T(1e-3), atol=T(1e-8),
      30             :         h0=T(0.0), hmax=T(Inf), maxsteps::Int=0) where {T<:Real} =
      31             :     options(T; rtol, atol, h0, hmax, maxsteps)
      32             : 
      33             : # convert to type x or typeof(x)
      34          29 : options(x, opts::SolverOptions{T}) where {T} = options(x; opts...)
      35             : 
      36             : """
      37             :     opts = options([T=Float64]
      38             :                    [;rtol=1e-3, atol=1e-8, h0=0.0, hmax=Inf, maxsteps=0])
      39             : 
      40             : `T` determines the type of scalars. You can alternatively provide a scalar
      41             : `x :: T` for `T<:Real`, e.g.,
      42             : 
      43             :     opts = options(1.0[; ...])
      44             : 
      45             : Use
      46             : 
      47             :    opts = options(Float32, opts)
      48             :    opts = options(1.0f0, opts)
      49             : 
      50             : to copy-convert `opts` using a specified type.
      51             : 
      52             : - Relative tolerance `rtol`
      53             : - Absdolute tolerance `atol`
      54             : - Initial step size `h0` is determined automatically if `h0 == 0`
      55             : - Maximum step size `hmax`
      56             : - Maximum number of steps `maxsteps` uses built-in default if `maxsteps == 0`
      57             : 
      58             : !!! note
      59             :     The **maximum step size** is *unbounded* for `hmax=Inf`. You may always
      60             :     want to adapt this to your data set!
      61             : 
      62             : See also [`Solver`](@ref), [`SolverOptions`](@ref), [`update!`](@ref)
      63             : [`set!`](@ref)
      64             : """ options
      65             : 
      66             : """
      67             :     opts = update(opts; kwargs...)
      68             : 
      69             : Update [`SolverOptions`](@ref) for given `kwargs` and return a new
      70             : set of modified options.
      71             : 
      72             : The keyword arguments are as definef for [`options`](@ref).
      73             : 
      74             : See also [`options`](@ref)
      75             : """
      76           4 : function update(opts::SolverOptions{T};
      77             :                 rtol=nothing, atol=nothing,
      78             :                 h0=nothing, hmax=nothing, maxsteps=nothing) where {T}
      79           2 :     options(rtol= something(rtol, opts.rtol),
      80             :             atol= something(atol, opts.atol),
      81             :             h0= something(h0, opts.h0),
      82             :             hmax= something(hmax, opts.hmax),
      83             :             maxsteps= something(maxsteps, opts.maxsteps))
      84             : end

Generated by: LCOV version 1.16