Skip to content

Commit

Permalink
New formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
YingboMa committed Oct 29, 2023
1 parent d763352 commit eaf751c
Show file tree
Hide file tree
Showing 83 changed files with 3,019 additions and 3,017 deletions.
138 changes: 69 additions & 69 deletions src/alg_utils.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
## SciMLBase Trait Definitions

function SciMLBase.isautodifferentiable(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm,
FunctionMap})
FunctionMap})
true
end
function SciMLBase.allows_arbitrary_number_types(alg::Union{OrdinaryDiffEqAlgorithm,
DAEAlgorithm, FunctionMap})
DAEAlgorithm, FunctionMap})
true
end
function SciMLBase.allowscomplex(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm,
FunctionMap})
FunctionMap})
true
end
SciMLBase.isdiscrete(alg::FunctionMap) = true
function SciMLBase.forwarddiffs_model(alg::Union{OrdinaryDiffEqAdaptiveImplicitAlgorithm,
DAEAlgorithm,
OrdinaryDiffEqImplicitAlgorithm,
ExponentialAlgorithm})
DAEAlgorithm,
OrdinaryDiffEqImplicitAlgorithm,
ExponentialAlgorithm})
alg_autodiff(alg) isa AutoForwardDiff
end
SciMLBase.forwarddiffs_model_time(alg::RosenbrockAlgorithm) = true
Expand Down Expand Up @@ -104,7 +104,7 @@ issplit(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = false
issplit(alg::SplitAlgorithms) = true

function _composite_beta1_default(algs::Tuple{T1, T2}, current, ::Val{QT},
beta2) where {T1, T2, QT}
beta2) where {T1, T2, QT}
if current == 1
return QT(beta1_default(algs[1], beta2))
else
Expand All @@ -113,7 +113,7 @@ function _composite_beta1_default(algs::Tuple{T1, T2}, current, ::Val{QT},
end

@generated function _composite_beta1_default(algs::T, current, ::Val{QT},
beta2) where {T <: Tuple, QT}
beta2) where {T <: Tuple, QT}
expr = Expr(:block)
for i in 1:length(T.types)
push!(expr.args, quote
Expand All @@ -126,7 +126,7 @@ end
end

function _composite_beta2_default(algs::Tuple{T1, T2}, current,
::Val{QT}) where {T1, T2, QT}
::Val{QT}) where {T1, T2, QT}
if current == 1
return QT(beta2_default(algs[1]))
else
Expand All @@ -135,7 +135,7 @@ function _composite_beta2_default(algs::Tuple{T1, T2}, current,
end

@generated function _composite_beta2_default(algs::T, current,
::Val{QT}) where {T <: Tuple, QT}
::Val{QT}) where {T <: Tuple, QT}
expr = Expr(:block)
for i in 1:length(T.types)
push!(expr.args, quote
Expand Down Expand Up @@ -165,7 +165,7 @@ isimplicit(alg::CompositeAlgorithm) = any(isimplicit.(alg.algs))
isdtchangeable(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = true
isdtchangeable(alg::CompositeAlgorithm) = all(isdtchangeable.(alg.algs))
function isdtchangeable(alg::Union{LawsonEuler, NorsettEuler, LieEuler, MagnusGauss4,
CayleyEuler, ETDRK2, ETDRK3, ETDRK4, HochOst4, ETD2})
CayleyEuler, ETDRK2, ETDRK3, ETDRK4, HochOst4, ETD2})
false
end # due to caching

Expand Down Expand Up @@ -204,10 +204,10 @@ get_chunksize(alg::OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD}) where {CS, A
get_chunksize(alg::OrdinaryDiffEqImplicitAlgorithm{CS, AD}) where {CS, AD} = Val(CS)
get_chunksize(alg::DAEAlgorithm{CS, AD}) where {CS, AD} = Val(CS)
function get_chunksize(alg::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD},
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD}}) where {
CS,
AD,
}
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD}}) where {
CS,
AD,
}
Val(CS)
end

Expand All @@ -218,22 +218,22 @@ get_chunksize_int(alg::OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD}) where {C
get_chunksize_int(alg::OrdinaryDiffEqImplicitAlgorithm{CS, AD}) where {CS, AD} = CS
get_chunksize_int(alg::DAEAlgorithm{CS, AD}) where {CS, AD} = CS
function get_chunksize_int(alg::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD},
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD}}) where {
CS,
AD,
}
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD}}) where {
CS,
AD,
}
CS
end
# get_chunksize(alg::CompositeAlgorithm) = get_chunksize(alg.algs[alg.current_alg])

function DiffEqBase.prepare_alg(alg::Union{
OrdinaryDiffEqAdaptiveImplicitAlgorithm{0, AD,
FDT},
OrdinaryDiffEqImplicitAlgorithm{0, AD, FDT},
DAEAlgorithm{0, AD, FDT},
OrdinaryDiffEqExponentialAlgorithm{0, AD, FDT}},
u0::AbstractArray{T},
p, prob) where {AD, FDT, T}
OrdinaryDiffEqAdaptiveImplicitAlgorithm{0, AD,
FDT},
OrdinaryDiffEqImplicitAlgorithm{0, AD, FDT},
DAEAlgorithm{0, AD, FDT},
OrdinaryDiffEqExponentialAlgorithm{0, AD, FDT}},
u0::AbstractArray{T},
p, prob) where {AD, FDT, T}
if alg isa OrdinaryDiffEqExponentialAlgorithm
linsolve = nothing
elseif alg.linsolve === nothing
Expand Down Expand Up @@ -305,9 +305,9 @@ end

# Linear Exponential doesn't have any of the AD stuff
function DiffEqBase.prepare_alg(alg::Union{ETD2, SplitEuler, LinearExponential,
OrdinaryDiffEqLinearExponentialAlgorithm},
u0::AbstractArray,
p, prob)
OrdinaryDiffEqLinearExponentialAlgorithm},
u0::AbstractArray,
p, prob)
alg
end

Expand All @@ -329,10 +329,10 @@ _alg_autodiff(::OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD}) where {CS, AD}
_alg_autodiff(::DAEAlgorithm{CS, AD}) where {CS, AD} = Val{AD}()
_alg_autodiff(::OrdinaryDiffEqImplicitAlgorithm{CS, AD}) where {CS, AD} = Val{AD}()
function _alg_autodiff(::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD},
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD},
}) where {
CS, AD,
}
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD},
}) where {
CS, AD,
}
Val{AD}()
end

Expand All @@ -356,38 +356,38 @@ function get_current_alg_autodiff(alg::CompositeAlgorithm, cache)
end

function alg_difftype(alg::Union{
OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD, FDT, ST, CJ
},
OrdinaryDiffEqImplicitAlgorithm{CS, AD, FDT, ST, CJ},
OrdinaryDiffEqExponentialAlgorithm{CS, AD, FDT, ST, CJ},
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD, FDT, ST,
CJ},
DAEAlgorithm{CS, AD, FDT, ST, CJ}}) where {CS, AD, FDT, ST,
CJ}
OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD, FDT, ST, CJ
},
OrdinaryDiffEqImplicitAlgorithm{CS, AD, FDT, ST, CJ},
OrdinaryDiffEqExponentialAlgorithm{CS, AD, FDT, ST, CJ},
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD, FDT, ST,
CJ},
DAEAlgorithm{CS, AD, FDT, ST, CJ}}) where {CS, AD, FDT, ST,
CJ}
FDT
end

function standardtag(alg::Union{
OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD, FDT, ST, CJ
},
OrdinaryDiffEqImplicitAlgorithm{CS, AD, FDT, ST, CJ},
OrdinaryDiffEqExponentialAlgorithm{CS, AD, FDT, ST, CJ},
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD, FDT, ST,
CJ},
DAEAlgorithm{CS, AD, FDT, ST, CJ}}) where {CS, AD, FDT, ST,
CJ}
OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD, FDT, ST, CJ
},
OrdinaryDiffEqImplicitAlgorithm{CS, AD, FDT, ST, CJ},
OrdinaryDiffEqExponentialAlgorithm{CS, AD, FDT, ST, CJ},
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD, FDT, ST,
CJ},
DAEAlgorithm{CS, AD, FDT, ST, CJ}}) where {CS, AD, FDT, ST,
CJ}
ST
end

function concrete_jac(alg::Union{
OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD, FDT, ST, CJ
},
OrdinaryDiffEqImplicitAlgorithm{CS, AD, FDT, ST, CJ},
OrdinaryDiffEqExponentialAlgorithm{CS, AD, FDT, ST, CJ},
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD, FDT, ST,
CJ},
DAEAlgorithm{CS, AD, FDT, ST, CJ}}) where {CS, AD, FDT, ST,
CJ}
OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD, FDT, ST, CJ
},
OrdinaryDiffEqImplicitAlgorithm{CS, AD, FDT, ST, CJ},
OrdinaryDiffEqExponentialAlgorithm{CS, AD, FDT, ST, CJ},
OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD, FDT, ST,
CJ},
DAEAlgorithm{CS, AD, FDT, ST, CJ}}) where {CS, AD, FDT, ST,
CJ}
CJ
end

Expand Down Expand Up @@ -425,11 +425,11 @@ get_current_alg_order(alg::FBDF, cache) = cache.order
get_current_adaptive_order(alg::QNDF, cache) = cache.order
get_current_adaptive_order(alg::FBDF, cache) = cache.order
function get_current_adaptive_order(alg::OrdinaryDiffEqExtrapolationVarOrderVarStepAlgorithm,
cache)
cache)
cache.cur_order
end
function get_current_alg_order(alg::OrdinaryDiffEqExtrapolationVarOrderVarStepAlgorithm,
cache)
cache)
cache.cur_order
end
get_current_alg_order(alg::ExtrapolationMidpointDeuflhard, cache) = 2(cache.n_curr + 1)
Expand All @@ -449,7 +449,7 @@ end

#alg_adaptive_order(alg::OrdinaryDiffEqAdaptiveAlgorithm) = error("Algorithm is adaptive with no order")
function get_current_adaptive_order(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm},
cache)
cache)
alg_adaptive_order(alg)
end
function get_current_adaptive_order(alg::CompositeAlgorithm, cache)
Expand Down Expand Up @@ -781,12 +781,12 @@ function default_controller(alg, cache, qoldinit, _beta1 = nothing, _beta2 = not
end

function default_controller(alg::Union{ExtrapolationMidpointDeuflhard,
ImplicitDeuflhardExtrapolation,
ExtrapolationMidpointHairerWanner,
ImplicitHairerWannerExtrapolation,
ImplicitEulerExtrapolation,
ImplicitEulerBarycentricExtrapolation}, cache,
qoldinit, _beta1 = nothing, _beta2 = nothing)
ImplicitDeuflhardExtrapolation,
ExtrapolationMidpointHairerWanner,
ImplicitHairerWannerExtrapolation,
ImplicitEulerExtrapolation,
ImplicitEulerBarycentricExtrapolation}, cache,
qoldinit, _beta1 = nothing, _beta2 = nothing)
QT = typeof(qoldinit)
beta1, beta2 = _digest_beta1_beta2(alg, cache, Val(QT), _beta1, _beta2)
return ExtrapolationController(beta1)
Expand Down Expand Up @@ -1058,9 +1058,9 @@ isWmethod(alg::RosenbrockW6S4OS) = true

isesdirk(alg::TRBDF2) = true
function isesdirk(alg::Union{KenCarp3, KenCarp4, KenCarp5, KenCarp58,
Kvaerno3, Kvaerno4, Kvaerno5, ESDIRK437L2SA,
ESDIRK54I8L2SA, ESDIRK436L2SA2, ESDIRK547L2SA2,
ESDIRK659L2SA, CFNLIRK3})
Kvaerno3, Kvaerno4, Kvaerno5, ESDIRK437L2SA,
ESDIRK54I8L2SA, ESDIRK436L2SA2, ESDIRK547L2SA2,
ESDIRK659L2SA, CFNLIRK3})
true
end
isesdirk(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = false
Expand Down
Loading

0 comments on commit eaf751c

Please sign in to comment.