Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added High Order and Low Order RK methods #2304

Merged
merged 139 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
3917a26
Added High Order and Low Order RK methods
ParamThakkar123 Jul 30, 2024
e7b8f53
Changes
ParamThakkar123 Jul 30, 2024
2ad688f
Changes
ParamThakkar123 Jul 30, 2024
5d7759a
Update lib/OrdinaryDiffEqLowOrderRK/test/runtests.jl
ChrisRackauckas Jul 30, 2024
235027d
Fixes
ParamThakkar123 Jul 30, 2024
0e74476
Update test/runtests.jl
ParamThakkar123 Jul 30, 2024
38c83ea
Merge branch 'master' of https://github.com/ParamThakkar123/OrdinaryD…
ParamThakkar123 Jul 30, 2024
e852f01
OrdinaryDiffEqTsit5 added
ParamThakkar123 Jul 30, 2024
f21324d
added interpolants
ParamThakkar123 Jul 30, 2024
aa889f2
trivial_limiter!
ParamThakkar123 Jul 30, 2024
fa5c07a
trivial_limiter!
ParamThakkar123 Jul 30, 2024
54be923
trivial_limiter!
ParamThakkar123 Jul 30, 2024
05a8df5
explicit_rk_docstring
ParamThakkar123 Jul 30, 2024
9209566
changes
ParamThakkar123 Jul 30, 2024
1756924
changes
ParamThakkar123 Jul 30, 2024
4dd3814
changes
ParamThakkar123 Jul 30, 2024
135b5af
Fixes
ParamThakkar123 Jul 30, 2024
b71cb79
TruncatedStacktraces
ParamThakkar123 Jul 30, 2024
56e59f9
@cache
ParamThakkar123 Jul 30, 2024
e86154e
trivial_limiter!
ParamThakkar123 Jul 30, 2024
475e4ec
Update algorithms.jl
ChrisRackauckas Jul 30, 2024
3432c11
@fold
ParamThakkar123 Jul 31, 2024
8f70743
Update lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl
ChrisRackauckas Jul 31, 2024
e9dda02
DiffEqBase
ParamThakkar123 Jul 31, 2024
00e95a9
@OnDemandTableauExtract
ParamThakkar123 Jul 31, 2024
cd7dc0e
trivial_limiter!
ParamThakkar123 Jul 31, 2024
3075609
trivial_limiter!
ParamThakkar123 Jul 31, 2024
c8cc3cc
CompiledFloats
ParamThakkar123 Jul 31, 2024
85d27e3
DiffEqBase
ParamThakkar123 Jul 31, 2024
4b0f31b
@cache
ParamThakkar123 Jul 31, 2024
b898c57
CompiledFloats
ParamThakkar123 Jul 31, 2024
cbf6463
DP8ConstantCache
ParamThakkar123 Jul 31, 2024
b5854c6
DiffEqBase
ParamThakkar123 Jul 31, 2024
20c62f4
FunctionMap
ParamThakkar123 Jul 31, 2024
cd9d69c
FunctionMap
ParamThakkar123 Jul 31, 2024
04b47ea
FunctionMapConstantCache
ParamThakkar123 Jul 31, 2024
d5cd505
Fixes
ParamThakkar123 Jul 31, 2024
64c7100
Interpolants
ParamThakkar123 Jul 31, 2024
c5eccec
@tight_loop_macros
ParamThakkar123 Jul 31, 2024
7908b40
OrdinaryDiffEqFunctionMap
ParamThakkar123 Jul 31, 2024
642810e
FunctionMap
ParamThakkar123 Jul 31, 2024
0de6d31
fixes
ParamThakkar123 Jul 31, 2024
39c81df
OrdinaryDiffEqConstantCache
ParamThakkar123 Jul 31, 2024
f50c16b
OrdinaryDiffEqConstantCache
ParamThakkar123 Jul 31, 2024
561bc9e
solve.jl
ParamThakkar123 Aug 1, 2024
ec2ed26
Added Adams-Bashforth-Moulton methods
ParamThakkar123 Aug 2, 2024
822fd9e
imports
ParamThakkar123 Aug 2, 2024
19a48d9
Fixes
ParamThakkar123 Aug 2, 2024
a6c9c28
Fixes
ParamThakkar123 Aug 2, 2024
fd3f786
Fixes
ParamThakkar123 Aug 2, 2024
6463da2
Added Nordsieck solvers
ParamThakkar123 Aug 2, 2024
0ddeccc
Added Nordsieck solvers
ParamThakkar123 Aug 2, 2024
0117bf1
Setup traits to remove FunctionMap from internals
ChrisRackauckas Aug 2, 2024
905291d
Update lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl
ChrisRackauckas Aug 2, 2024
50ac81c
Added Rosenbrock solvers
ParamThakkar123 Aug 2, 2024
5691c0d
Fixes
ParamThakkar123 Aug 2, 2024
2ad25d1
Fixes and added Explicit RK solvers
ParamThakkar123 Aug 2, 2024
a4226ea
fixes
ParamThakkar123 Aug 2, 2024
972426f
Updates
ParamThakkar123 Aug 2, 2024
6173202
Update
ParamThakkar123 Aug 2, 2024
3f94372
Update src/OrdinaryDiffEq.jl
ChrisRackauckas Aug 2, 2024
f51491e
Update OrdinaryDiffEq.jl
ChrisRackauckas Aug 2, 2024
de8e503
Update lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl
ChrisRackauckas Aug 2, 2024
65e5459
Updates
ParamThakkar123 Aug 2, 2024
72cfebb
fixes
ParamThakkar123 Aug 2, 2024
2c022ad
OrdinaryDiffEqRosenbrockAlgorithm
ParamThakkar123 Aug 2, 2024
6529ee1
@ROS2
ParamThakkar123 Aug 2, 2024
26f4067
@capture
ParamThakkar123 Aug 2, 2024
2dc43ec
Merge remote-tracking branch 'origin/master'
ChrisRackauckas Aug 2, 2024
f8dbed2
a bunch of fixes
ChrisRackauckas Aug 3, 2024
3aaceb7
a few more imports
ChrisRackauckas Aug 3, 2024
85e9653
more imports
ChrisRackauckas Aug 3, 2024
efc9279
some more imports
ChrisRackauckas Aug 3, 2024
b61de14
add missing dep
ChrisRackauckas Aug 3, 2024
e610400
more
ChrisRackauckas Aug 3, 2024
02a3bda
more
ChrisRackauckas Aug 3, 2024
b35e28e
more
ChrisRackauckas Aug 3, 2024
09ee697
should be the last one
ChrisRackauckas Aug 3, 2024
e06f6e5
more imports
ChrisRackauckas Aug 3, 2024
00897fe
next tests...
ChrisRackauckas Aug 3, 2024
6731f9b
update
ParamThakkar123 Aug 3, 2024
cc07cf9
copyat_or_push!
ParamThakkar123 Aug 3, 2024
d5aad61
calculate_residuals
ParamThakkar123 Aug 3, 2024
032368d
Update
ParamThakkar123 Aug 3, 2024
2fb92d6
move around some interface functions
ChrisRackauckas Aug 3, 2024
57d61e0
constvalue
ParamThakkar123 Aug 3, 2024
19ffbaf
a few more
ChrisRackauckas Aug 3, 2024
c5de013
Merge branch 'master' of https://github.com/ParamThakkar123/OrdinaryD…
ChrisRackauckas Aug 3, 2024
a0821ff
Update src/solve.jl
ChrisRackauckas Aug 3, 2024
59e4a26
jacobian2W!
ParamThakkar123 Aug 3, 2024
3fcefb1
more
ChrisRackauckas Aug 3, 2024
dd78907
Merge branch 'master' of https://github.com/ParamThakkar123/OrdinaryD…
ChrisRackauckas Aug 3, 2024
6648d8a
another
ChrisRackauckas Aug 3, 2024
8df87e6
deps in ABM
ChrisRackauckas Aug 3, 2024
4752f18
import correctly
ChrisRackauckas Aug 3, 2024
4ff49d9
Fix ABM import
ChrisRackauckas Aug 3, 2024
dd497b8
RK4Cache
ParamThakkar123 Aug 3, 2024
2c5e729
Update src/solve.jl
ChrisRackauckas Aug 3, 2024
c722380
add missing imports
ChrisRackauckas Aug 3, 2024
e3e16ae
Merge branch 'master' of https://github.com/ParamThakkar123/OrdinaryD…
ChrisRackauckas Aug 3, 2024
ec264c0
@def
ParamThakkar123 Aug 3, 2024
f7e492f
some clean up
ChrisRackauckas Aug 3, 2024
2c85152
fix project toml
ChrisRackauckas Aug 3, 2024
947a76c
remove extra file
ChrisRackauckas Aug 3, 2024
eb425a1
Adapt
ParamThakkar123 Aug 3, 2024
ba7d043
AutoAlgSwitch
ParamThakkar123 Aug 3, 2024
f123e4f
trivial_limiter!
ParamThakkar123 Aug 3, 2024
13a4150
AutoAlgSwitch
ParamThakkar123 Aug 3, 2024
9db7b75
Static
ParamThakkar123 Aug 3, 2024
4e32260
ADTypes
ParamThakkar123 Aug 3, 2024
41349aa
ADTypes
ParamThakkar123 Aug 3, 2024
e25583f
Tsit5ConstantCache
ParamThakkar123 Aug 3, 2024
1b8afa4
full_cache
ParamThakkar123 Aug 3, 2024
10a9a1e
norm
ParamThakkar123 Aug 3, 2024
b1ca7d8
full_cache
ParamThakkar123 Aug 3, 2024
984bce7
Update lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl
ChrisRackauckas Aug 3, 2024
913b9ee
Update src/OrdinaryDiffEq.jl
ChrisRackauckas Aug 3, 2024
032ee4d
a few more missing bits
ChrisRackauckas Aug 3, 2024
1cf0be4
ODEIntegrator
ParamThakkar123 Aug 3, 2024
03093ac
perform_predict!
ParamThakkar123 Aug 3, 2024
0bb766e
full_cache
ParamThakkar123 Aug 3, 2024
439fad1
Fix prediction import
ChrisRackauckas Aug 3, 2024
b269441
add missing custom interpolations
ChrisRackauckas Aug 3, 2024
fc50277
DP8ConstantCache
ParamThakkar123 Aug 3, 2024
b1d993e
move high order interpolant
ChrisRackauckas Aug 3, 2024
b8a9bd3
a bit more
ChrisRackauckas Aug 3, 2024
7fb1037
getting close
ChrisRackauckas Aug 3, 2024
a69313a
some imports
ChrisRackauckas Aug 4, 2024
52d58bb
more
ChrisRackauckas Aug 4, 2024
19423ae
one more
ChrisRackauckas Aug 4, 2024
c4d48f1
missing cache piece
ChrisRackauckas Aug 4, 2024
b3f2f3a
add missing cache
ChrisRackauckas Aug 4, 2024
5d8b121
Update
ParamThakkar123 Aug 4, 2024
743eb97
Update
ParamThakkar123 Aug 4, 2024
9f452f2
Removed
ParamThakkar123 Aug 4, 2024
454389c
LinearAlgebra
ParamThakkar123 Aug 4, 2024
d125014
Revert "Merge remote-tracking branch 'origin/master'"
ChrisRackauckas Aug 4, 2024
b262540
Merge branch 'master' of https://github.com/ParamThakkar123/OrdinaryD…
ChrisRackauckas Aug 4, 2024
6073819
FiniteDiff
ParamThakkar123 Aug 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
FunctionWrappersWrappers = "77dc65aa-8811-40c2-897b-53d922fa7daf"
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down Expand Up @@ -60,7 +59,6 @@ FillArrays = "1.9"
FiniteDiff = "2"
ForwardDiff = "0.10.3"
FunctionWrappersWrappers = "0.1"
IfElse = "0.1"
InteractiveUtils = "1.9"
LineSearches = "7"
LinearAlgebra = "1.9"
Expand Down
25 changes: 25 additions & 0 deletions lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name = "OrdinaryDiffEqAdamsBashforthMoulton"
uuid = "89bda076-bce5-4f1c-845f-551c83cdda9a"
authors = ["ParamThakkar123 <[email protected]>"]
version = "1.0.0"

[deps]
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

[compat]
julia = "1.10"

[extras]
DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["DiffEqDevTools", "Random", "SafeTestsets", "Test"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module OrdinaryDiffEqAdamsBashforthMoulton

import OrdinaryDiffEq: OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, @cache, alg_cache,
initialize!, @unpack, perform_step!, alg_order, isstandard, OrdinaryDiffEqAlgorithm,
OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm,
constvalue, calculate_residuals, calculate_residuals!, trivial_limiter!
import OrdinaryDiffEq: BS3ConstantCache, BS3Cache, RK4ConstantCache, RK4Cache
import RecursiveArrayTools: recursivefill!
using MuladdMacro, FastBroadcast
import Static: False
import ADTypes: AutoForwardDiff

include("algorithms.jl")
include("alg_utils.jl")
include("adams_bashforth_moulton_caches.jl")
include("adams_utils.jl")
include("adams_bashforth_moulton_perform_step.jl")

export AB3, AB4, AB5, ABM32, ABM43, ABM54, VCAB3,
VCAB4, VCAB5, VCABM3, VCABM4, VCABM5, VCABM

end
Original file line number Diff line number Diff line change
Expand Up @@ -1019,120 +1019,3 @@ function alg_cache(alg::VCABM, u, rate_prototype, ::Type{uEltypeNoUnits},
max_order, atmp, tmp, ξ, ξ0, utilde, utildem1, utildem2, utildep1, atmpm1,
atmpm2, atmpp1, 1)
end

# IMEX Multistep methods

# CNAB2

@cache mutable struct CNAB2ConstantCache{rateType, N, uType, tType} <:
OrdinaryDiffEqConstantCache
k2::rateType
nlsolver::N
uprev3::uType
tprev2::tType
end

@cache mutable struct CNAB2Cache{uType, rateType, N, tType} <: OrdinaryDiffEqMutableCache
u::uType
uprev::uType
uprev2::uType
fsalfirst::rateType
k1::rateType
k2::rateType
du₁::rateType
nlsolver::N
uprev3::uType
tprev2::tType
end

function alg_cache(alg::CNAB2, u, rate_prototype, ::Type{uEltypeNoUnits},
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t,
dt, reltol, p, calck,
::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
γ, c = 1 // 2, 1
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(false))

k2 = rate_prototype
uprev3 = u
tprev2 = t

CNAB2ConstantCache(k2, nlsolver, uprev3, tprev2)
end

function alg_cache(alg::CNAB2, u, rate_prototype, ::Type{uEltypeNoUnits},
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t,
dt, reltol, p, calck,
::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
γ, c = 1 // 2, 1
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true))
fsalfirst = zero(rate_prototype)

k1 = zero(rate_prototype)
k2 = zero(rate_prototype)
du₁ = zero(rate_prototype)
uprev3 = zero(u)
tprev2 = t

CNAB2Cache(u, uprev, uprev2, fsalfirst, k1, k2, du₁, nlsolver, uprev3, tprev2)
end

# CNLF2

@cache mutable struct CNLF2ConstantCache{rateType, N, uType, tType} <:
OrdinaryDiffEqConstantCache
k2::rateType
nlsolver::N
uprev2::uType
uprev3::uType
tprev2::tType
end

@cache mutable struct CNLF2Cache{uType, rateType, N, tType} <: OrdinaryDiffEqMutableCache
u::uType
uprev::uType
uprev2::uType
fsalfirst::rateType
k1::rateType
k2::rateType
du₁::rateType
nlsolver::N
uprev3::uType
tprev2::tType
end

function alg_cache(alg::CNLF2, u, rate_prototype, ::Type{uEltypeNoUnits},
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t,
dt, reltol, p, calck,
::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
γ, c = 1 // 1, 1
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(false))

k2 = rate_prototype
uprev2 = u
uprev3 = u
tprev2 = t

CNLF2ConstantCache(k2, nlsolver, uprev2, uprev3, tprev2)
end

function alg_cache(alg::CNLF2, u, rate_prototype, ::Type{uEltypeNoUnits},
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t,
dt, reltol, p, calck,
::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
γ, c = 1 // 1, 1
nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits,
uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true))
fsalfirst = zero(rate_prototype)

k1 = zero(rate_prototype)
k2 = zero(rate_prototype)
du₁ = zero(rate_prototype)
uprev2 = zero(u)
uprev3 = zero(u)
tprev2 = t

CNLF2Cache(u, uprev, uprev2, fsalfirst, k1, k2, du₁, nlsolver, uprev3, tprev2)
end
Original file line number Diff line number Diff line change
Expand Up @@ -1540,209 +1540,3 @@ end
return nothing
end # inbounds
end

# CNAB2

function initialize!(integrator, cache::CNAB2ConstantCache)
integrator.kshortsize = 2
integrator.k = typeof(integrator.k)(undef, integrator.kshortsize)
integrator.fsalfirst = integrator.f.f1(integrator.uprev, integrator.p, integrator.t) +
integrator.f.f2(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal
integrator.stats.nf += 1
integrator.stats.nf2 += 1

# Avoid undefined entries if k is an array of arrays
integrator.fsallast = zero(integrator.fsalfirst)
integrator.k[1] = integrator.fsalfirst
integrator.k[2] = integrator.fsallast
end

function perform_step!(integrator, cache::CNAB2ConstantCache, repeat_step = false)
@unpack t, dt, uprev, u, f, p = integrator
@unpack k2, nlsolver = cache
cnt = integrator.iter
f1 = integrator.f.f1
f2 = integrator.f.f2
du₁ = f1(uprev, p, t)
integrator.stats.nf += 1
k1 = integrator.fsalfirst - du₁
# Explicit part
if cnt == 1
tmp = uprev + dt * k1
else
tmp = uprev + dt * (3 // 2 * k1 - 1 // 2 * k2)
end
nlsolver.tmp = tmp
# Implicit part
# precalculations
γ = 1 // 2
γdt = γ * dt

# initial guess
zprev = dt * du₁
nlsolver.z = z = zprev # Constant extrapolation

nlsolver.tmp += γ * zprev
markfirststage!(nlsolver)
z = nlsolve!(nlsolver, integrator, cache, repeat_step)
nlsolvefail(nlsolver) && return
u = nlsolver.tmp + 1 // 2 * z

cache.k2 = k1
integrator.fsallast = f1(u, p, t + dt) + f2(u, p, t + dt)
integrator.stats.nf += 1
integrator.stats.nf2 += 1
integrator.k[1] = integrator.fsalfirst
integrator.k[2] = integrator.fsallast
integrator.u = u
end

function initialize!(integrator, cache::CNAB2Cache)
integrator.kshortsize = 2
integrator.fsalfirst = cache.fsalfirst
integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst)
resize!(integrator.k, integrator.kshortsize)
integrator.k[1] = integrator.fsalfirst
integrator.k[2] = integrator.fsallast
integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t)
integrator.stats.nf += 1
end

function perform_step!(integrator, cache::CNAB2Cache, repeat_step = false)
@unpack t, dt, uprev, u, f, p = integrator
@unpack k1, k2, du₁, nlsolver = cache
@unpack z, tmp = nlsolver
@unpack f1 = f
cnt = integrator.iter

f1(du₁, uprev, p, t)
integrator.stats.nf += 1
@.. broadcast=false k1=integrator.fsalfirst - du₁
# Explicit part
if cnt == 1
@.. broadcast=false tmp=uprev + dt * k1
else
@.. broadcast=false tmp=uprev + dt * (3 // 2 * k1 - 1 // 2 * k2)
end
# Implicit part
# precalculations
γ = 1 // 2
γdt = γ * dt

# initial guess
@.. broadcast=false z=dt * du₁
@.. broadcast=false tmp+=γ * z
markfirststage!(nlsolver)
z = nlsolve!(nlsolver, integrator, cache, repeat_step)
nlsolvefail(nlsolver) && return
@.. broadcast=false u=tmp + 1 // 2 * z

cache.k2 .= k1
f(integrator.fsallast, u, p, t + dt)
integrator.stats.nf += 1
end

# CNLF2

function initialize!(integrator, cache::CNLF2ConstantCache)
integrator.kshortsize = 2
integrator.k = typeof(integrator.k)(undef, integrator.kshortsize)
integrator.fsalfirst = integrator.f.f1(integrator.uprev, integrator.p, integrator.t) +
integrator.f.f2(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal
integrator.stats.nf += 1
integrator.stats.nf2 += 1

# Avoid undefined entries if k is an array of arrays
integrator.fsallast = zero(integrator.fsalfirst)
integrator.k[1] = integrator.fsalfirst
integrator.k[2] = integrator.fsallast
end

function perform_step!(integrator, cache::CNLF2ConstantCache, repeat_step = false)
@unpack t, dt, uprev, u, f, p = integrator
@unpack k2, uprev2, nlsolver = cache
cnt = integrator.iter
f1 = integrator.f.f1
f2 = integrator.f.f2
du₁ = f1(uprev, p, t)
integrator.stats.nf += 1
# Explicit part
if cnt == 1
tmp = uprev + dt * (integrator.fsalfirst - du₁)
else
tmp = uprev2 + 2 // 1 * dt * (integrator.fsalfirst - du₁)
end
# Implicit part
# precalculations
γ = 1 // 1
if cnt != 1
tmp += γ * dt * k2
end
γdt = γ * dt
nlsolver.tmp = tmp

# initial guess
zprev = dt * du₁
nlsolver.z = z = zprev # Constant extrapolation

markfirststage!(nlsolver)
z = nlsolve!(nlsolver, integrator, cache, repeat_step)
nlsolvefail(nlsolver) && return
u = nlsolver.tmp + γ * z

cache.uprev2 = uprev
cache.k2 = du₁
integrator.fsallast = f1(u, p, t + dt) + f2(u, p, t + dt)
integrator.stats.nf += 1
integrator.stats.nf2 += 1
integrator.k[1] = integrator.fsalfirst
integrator.k[2] = integrator.fsallast
integrator.u = u
end

function initialize!(integrator, cache::CNLF2Cache)
integrator.kshortsize = 2
integrator.fsalfirst = cache.fsalfirst
integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst)
resize!(integrator.k, integrator.kshortsize)
integrator.k[1] = integrator.fsalfirst
integrator.k[2] = integrator.fsallast
integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t)
integrator.stats.nf += 1
end

function perform_step!(integrator, cache::CNLF2Cache, repeat_step = false)
@unpack t, dt, uprev, u, f, p = integrator
@unpack uprev2, k2, du₁, nlsolver = cache
@unpack z, tmp = nlsolver
@unpack f1 = f
cnt = integrator.iter

f1(du₁, uprev, p, t)
integrator.stats.nf += 1
# Explicit part
if cnt == 1
@.. broadcast=false tmp=uprev + dt * (integrator.fsalfirst - du₁)
else
@.. broadcast=false tmp=uprev2 + 2 // 1 * dt * (integrator.fsalfirst - du₁)
end
# Implicit part
# precalculations
γ = 1 // 1
if cnt != 1
@.. broadcast=false tmp+=γ * dt * k2
end
γdt = γ * dt

# initial guess
@.. broadcast=false z=dt * du₁
markfirststage!(nlsolver)
z = nlsolve!(nlsolver, integrator, cache, repeat_step)
nlsolvefail(nlsolver) && return
@.. broadcast=false u=tmp + γ * z

cache.uprev2 .= uprev
cache.k2 .= du₁
f(integrator.fsallast, u, p, t + dt)
integrator.stats.nf += 1
end
Loading
Loading