-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
[WIP] Relaxation Runge-Kutta #2227
Closed
Closed
Changes from 21 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
fbf962d
just ideas for relaxation
Theozeud dc25f21
Update ideas_for_relaxation.jl
Theozeud 575826a
Update ideas_for_relaxation.jl
Theozeud cdb53c9
Update ideas_for_relaxation.jl
Theozeud 7e2b73a
Update ideas_for_relaxation.jl
Theozeud d0f8a22
try_implementation_tsit5_for_relaxation
Theozeud 229438f
progress relaxation
Theozeud 9384053
Merge branch 'SciML:master' into relaxation
Theozeud a796157
all implement but failed compilation
Theozeud eeda5a7
Merge branch 'relaxation' of https://github.com/Theozeud/OrdinaryDiff…
Theozeud b3617ad
compilation works but not tests
Theozeud 945b9d3
Merge branch 'SciML:master' into relaxation
Theozeud ef5238b
code change structure works
Theozeud cb94460
Merge branch 'relaxation' of https://github.com/Theozeud/OrdinaryDiff…
Theozeud 4323a68
fix mistakes
Theozeud 12e4a7a
improvement for regression
Theozeud e35d9fa
clean up
Theozeud 7fada13
Merge branch 'master' into relaxation_method
Theozeud 653436b
try test without relaxation
Theozeud 730d4e1
copy tist5 for non constant cache
Theozeud db28be6
fix tsit5_for_relaxation with non constant cache
Theozeud 2ffd004
first try of implementation of the relaxation step
Theozeud a180073
add notes on some thoughts
Theozeud 52f4461
add some tools
Theozeud b4d9c40
add some tools
Theozeud a01bc2a
bound_dt
Theozeud 3fd63fd
trying to use Roots.jl instead of OptimizationOptimJL.jl
Theozeud e926a61
test relaxation on oscillator
Theozeud 2789e9f
work at the beginning for harmonic oscillator but there is bug in lon…
Theozeud 89c10f3
add some problem for later
Theozeud 2c387d8
some change in the modif_step!
Theozeud 83bd06c
fix bug
Theozeud 8ff5be9
first test to compare relaxation with no relaxation
Theozeud 5138202
Create benchmark in time.ipynb
Theozeud c884132
Test FSAL-R
Theozeud fa0d5c3
add more examples
Theozeud 3287f82
Relaxation v2
Theozeud 1111c38
New way with PerformStepCallBack
Theozeud 44ea89d
new structure runs
Theozeud 9af57f8
Merge pull request #4 from Theozeud/relaxation_new_version
Theozeud 3d06894
all last modif
Theozeud f6557b4
Merge pull request #5 from Theozeud/relaxation_new_version
Theozeud ac1943d
almost all work well except R-FSAL which needs
Theozeud 5c9b8e6
find a way to make R-FSAL work
Theozeud 2b0fb0a
do each examples of the paper with different FSAL
Theozeud f208a53
small fix
Theozeud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -448,6 +448,44 @@ | |
Base.Experimental.silence!(Tsit5Cache) | ||
end | ||
|
||
@cache struct Tsit5Cache_for_relaxation{uType, rateType, uNoUnitsType, StageLimiter, StepLimiter, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could this just use the |
||
Thread} <: OrdinaryDiffEqMutableCache | ||
u::uType | ||
uprev::uType | ||
k1::rateType | ||
k2::rateType | ||
k3::rateType | ||
k4::rateType | ||
k5::rateType | ||
k6::rateType | ||
k7::rateType | ||
utilde::uType | ||
tmp::uType | ||
atmp::uNoUnitsType | ||
stage_limiter!::StageLimiter | ||
step_limiter!::StepLimiter | ||
thread::Thread | ||
end | ||
|
||
function alg_cache(alg::Tsit5_for_relaxation, u, rate_prototype, ::Type{uEltypeNoUnits}, | ||
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, | ||
dt, reltol, p, calck, | ||
::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} | ||
k1 = zero(rate_prototype) | ||
k2 = zero(rate_prototype) | ||
k3 = zero(rate_prototype) | ||
k4 = zero(rate_prototype) | ||
k5 = zero(rate_prototype) | ||
k6 = zero(rate_prototype) | ||
k7 = zero(rate_prototype) | ||
utilde = zero(u) | ||
atmp = similar(u, uEltypeNoUnits) | ||
recursivefill!(atmp, false) | ||
tmp = zero(u) | ||
Tsit5Cache_for_relaxation(u, uprev, k1, k2, k3, k4, k5, k6, k7, utilde, tmp, atmp, | ||
alg.stage_limiter!, alg.step_limiter!, alg.thread) | ||
end | ||
|
||
@cache struct RK46NLCache{uType, rateType, TabType, StageLimiter, StepLimiter, Thread} <: | ||
OrdinaryDiffEqMutableCache | ||
u::uType | ||
|
@@ -547,6 +585,13 @@ | |
Tsit5ConstantCache() | ||
end | ||
|
||
function alg_cache(alg::Tsit5_for_relaxation, u, rate_prototype, ::Type{uEltypeNoUnits}, | ||
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, | ||
dt, reltol, p, calck, | ||
::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} | ||
Tsit5ConstantCache_for_relaxation() | ||
end | ||
|
||
@cache struct DP5Cache{uType, rateType, uNoUnitsType, StageLimiter, StepLimiter, | ||
Thread} <: OrdinaryDiffEqMutableCache | ||
u::uType | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
function initialize!(integrator, ::Tsit5ConstantCache_for_relaxation) | ||
integrator.kshortsize = 7 | ||
integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) | ||
integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal | ||
integrator.stats.nf += 1 | ||
|
||
# Avoid undefined entries if k is an array of arrays | ||
integrator.fsallast = zero(integrator.fsalfirst) | ||
integrator.k[1] = integrator.fsalfirst | ||
@inbounds for i in 2:(integrator.kshortsize - 1) | ||
integrator.k[i] = zero(integrator.fsalfirst) | ||
end | ||
integrator.k[integrator.kshortsize] = integrator.fsallast | ||
end | ||
|
||
|
||
function perform_step!(integrator, cache::Tsit5ConstantCache_for_relaxation, repeat_step = false) | ||
|
||
# Variable to know if dt has changed during perform_step | ||
integrator.dt_has_changed = false | ||
|
||
# computations! will only contain the mathematical scheme | ||
# i.e the computations of the u(t+dt) | ||
# the result is store not in integrator.u but integrator.u_propose | ||
computations!(integrator, cache, repeat_step) | ||
|
||
# modif_step! enables to modify the step like when we want to perform a relaxation | ||
# for this we give a new struture that can be defined either by us for already known | ||
# modification we want to do or by a user (see below) | ||
modif_step!(integrator) | ||
|
||
# finalize_step! will do staff related to the solver like integrator.stats, register integrator.fsal | ||
# and register integrator.u | ||
finalize_step!(integrator, cache) | ||
end | ||
|
||
|
||
@muladd function computations!(integrator, ::Tsit5ConstantCache_for_relaxation, repeat_step = false) | ||
@unpack t, dt, uprev, u, f, p = integrator | ||
T = constvalue(recursive_unitless_bottom_eltype(u)) | ||
T2 = constvalue(typeof(one(t))) | ||
@OnDemandTableauExtract Tsit5ConstantCacheActual T T2 | ||
k1 = integrator.fsalfirst | ||
a = dt * a21 | ||
k2 = f(uprev + a * k1, p, t + c1 * dt) | ||
k3 = f(uprev + dt * (a31 * k1 + a32 * k2), p, t + c2 * dt) | ||
k4 = f(uprev + dt * (a41 * k1 + a42 * k2 + a43 * k3), p, t + c3 * dt) | ||
k5 = f(uprev + dt * (a51 * k1 + a52 * k2 + a53 * k3 + a54 * k4), p, t + c4 * dt) | ||
g6 = uprev + dt * (a61 * k1 + a62 * k2 + a63 * k3 + a64 * k4 + a65 * k5) | ||
k6 = f(g6, p, t + dt) | ||
u = uprev + dt * (a71 * k1 + a72 * k2 + a73 * k3 + a74 * k4 + a75 * k5 + a76 * k6) | ||
k7 = f(u, p, t + dt) | ||
integrator.k[1] = k1 | ||
integrator.k[2] = k2 | ||
integrator.k[3] = k3 | ||
integrator.k[4] = k4 | ||
integrator.k[5] = k5 | ||
integrator.k[6] = k6 | ||
integrator.k[7] = k7 | ||
integrator.u_propose = u | ||
|
||
if integrator.opts.adaptive | ||
utilde = dt * | ||
(btilde1 * integrator.k[1] + btilde2 * integrator.k[2] + btilde3 * integrator.k[3] + btilde4 * integrator.k[4] + btilde5 * integrator.k[5] + | ||
btilde6 * integrator.k[6] + btilde7 * integrator.k[7]) | ||
atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, | ||
integrator.opts.reltol, integrator.opts.internalnorm, t) | ||
integrator.EEst = integrator.opts.internalnorm(atmp, t) | ||
end | ||
end | ||
|
||
|
||
function modif_step!(integrator) | ||
|
||
# Perform the modifications | ||
if !(integrator.opts.modif isa Nothing) | ||
integrator.opts.modif(integrator) | ||
|
||
# Here we check the validity of chaging dt if it has changed | ||
# if it is valid integrator.changed_valid will be true, if not it will be false | ||
changed_valid = true | ||
if integrator.dt_has_changed | ||
# check dt in [dtmin, dtmax] | ||
# things related to tstops | ||
# surely other things | ||
if changed_valid | ||
integrator.u_propose = integrator.u_changed | ||
integrator.dt = integrator.dt_changed | ||
else | ||
# print error or warning | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
||
function finalize_step!(integrator, cache::Tsit5ConstantCache_for_relaxation) | ||
@unpack t, dt, uprev, u_propose, f, p = integrator | ||
integrator.u = u_propose | ||
integrator.fsallast = f(u_propose, p, t + dt) | ||
|
||
integrator.stats.nf += 7 | ||
end | ||
|
||
|
||
## Non Constant cache | ||
function initialize!(integrator, cache::Tsit5Cache_for_relaxation) | ||
integrator.kshortsize = 7 | ||
integrator.fsalfirst = cache.k1 | ||
integrator.fsallast = cache.k7 # setup pointers | ||
resize!(integrator.k, integrator.kshortsize) | ||
# Setup k pointers | ||
integrator.k[1] = cache.k1 | ||
integrator.k[2] = cache.k2 | ||
integrator.k[3] = cache.k3 | ||
integrator.k[4] = cache.k4 | ||
integrator.k[5] = cache.k5 | ||
integrator.k[6] = cache.k6 | ||
integrator.k[7] = cache.k7 | ||
integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # Pre-start fsal | ||
integrator.stats.nf += 1 | ||
return nothing | ||
end | ||
|
||
|
||
function perform_step!(integrator, cache::Tsit5Cache_for_relaxation, repeat_step = false) | ||
|
||
# Variable to know if dt has changed during perform_step | ||
integrator.dt_has_changed = false | ||
|
||
# computations! will only contain the mathematical scheme | ||
# i.e the computations of the u(t+dt) | ||
# the result is store not in integrator.u but integrator.u_propose | ||
computations!(integrator, cache, repeat_step) | ||
|
||
# modif_step! enables to modify the step like when we want to perform a relaxation | ||
# for this we give a new struture that can be defined either by us for already known | ||
# modification we want to do or by a user (see below) | ||
modif_step!(integrator) | ||
|
||
# finalize_step! will do staff related to the solver like integrator.stats, register integrator.fsal | ||
# and register integrator.u | ||
finalize_step!(integrator, cache) | ||
end | ||
|
||
@muladd function computations!(integrator, cache::Tsit5Cache_for_relaxation, repeat_step = false) | ||
@unpack t, dt, uprev, u_propose, f, p = integrator | ||
T = constvalue(recursive_unitless_bottom_eltype(u_propose)) | ||
T2 = constvalue(typeof(one(t))) | ||
@OnDemandTableauExtract Tsit5ConstantCacheActual T T2 | ||
@unpack k1, k2, k3, k4, k5, k6, k7, utilde, tmp, atmp, stage_limiter!, step_limiter!, thread = cache | ||
a = dt * a21 | ||
@.. broadcast=false thread=thread tmp=uprev + a * k1 | ||
stage_limiter!(tmp, f, p, t + c1 * dt) | ||
f(k2, tmp, p, t + c1 * dt) | ||
@.. broadcast=false thread=thread tmp=uprev + dt * (a31 * k1 + a32 * k2) | ||
stage_limiter!(tmp, f, p, t + c2 * dt) | ||
f(k3, tmp, p, t + c2 * dt) | ||
@.. broadcast=false thread=thread tmp=uprev + dt * (a41 * k1 + a42 * k2 + a43 * k3) | ||
stage_limiter!(tmp, f, p, t + c3 * dt) | ||
f(k4, tmp, p, t + c3 * dt) | ||
@.. broadcast=false thread=thread tmp=uprev + | ||
dt * (a51 * k1 + a52 * k2 + a53 * k3 + a54 * k4) | ||
stage_limiter!(tmp, f, p, t + c4 * dt) | ||
f(k5, tmp, p, t + c4 * dt) | ||
@.. broadcast=false thread=thread tmp=uprev + | ||
dt * (a61 * k1 + a62 * k2 + a63 * k3 + a64 * k4 + | ||
a65 * k5) | ||
stage_limiter!(tmp, f, p, t + dt) | ||
f(k6, tmp, p, t + dt) | ||
@.. broadcast=false thread=thread u_propose = uprev + | ||
dt * (a71 * k1 + a72 * k2 + a73 * k3 + a74 * k4 + | ||
a75 * k5 + a76 * k6) | ||
stage_limiter!(u_propose, integrator, p, t + dt) | ||
step_limiter!(u_propose, integrator, p, t + dt) | ||
|
||
f(k7, u_propose, p, t + dt) | ||
|
||
if integrator.opts.adaptive | ||
@.. broadcast=false thread=thread utilde=dt * (btilde1 * k1 + btilde2 * k2 + | ||
btilde3 * k3 + btilde4 * k4 + | ||
btilde5 * k5 + btilde6 * k6 + | ||
btilde7 * k7) | ||
calculate_residuals!(atmp, utilde, uprev, u_propose, integrator.opts.abstol, | ||
integrator.opts.reltol, integrator.opts.internalnorm, t, | ||
thread) | ||
integrator.EEst = integrator.opts.internalnorm(atmp, t) | ||
end | ||
return nothing | ||
end | ||
|
||
function finalize_step!(integrator, cache::Tsit5Cache_for_relaxation) | ||
@unpack t, dt, u_propose, u, f, p = integrator | ||
@unpack k7, stage_limiter!, step_limiter!, thread = cache | ||
@.. broadcast=false thread=thread u = u_propose | ||
stage_limiter!(u, integrator, p, t + dt) | ||
step_limiter!(u, integrator, p, t + dt) | ||
f(k7, u_propose, p, t + dt) | ||
integrator.stats.nf += 7 | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backwards compatibility with what?