Skip to content

Commit 27044cb

Browse files
authored
Revise integrator interface (again) (#185)
* Implement the new integrator interface for Euler, ERK, IRK, and VPRK methods. * Implement the new integrator interface for splitting and composition integrators. * Revise integrator interface in SPARK methods. * Remove obsolete integrate_step! methods. * Revise integrator interface in HPI methods. * Revise integrator interface in DVI methods. * Revise integrator interface in DIRK methods. * Revise integrator interface in partitioned Runge-Kutta methods. * Revise integrator interface in CGVI methods. * Refactor Runge-Kutta methods for implicit ODEs. * Revise integrator interface in partitioned Runge-Kutta methods for implicit ODEs. * Refactor integrator interface and projection methods, and remove storage of previous solution in cache. * Start to refactor extrapolation interface towards unification with integrator interface. * Minor fix. * Add minor comment in docs. * Refactor integrator, remove solstep, and completely revise initial guess handling and extrapolation methods.
1 parent 044c769 commit 27044cb

File tree

82 files changed

+2590
-2814
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2590
-2814
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ CompactBasisFunctions = "0.2"
2929
Documenter = "0.25, 0.26, 0.27, 1"
3030
ForwardDiff = "0.10"
3131
GenericLinearAlgebra = "0.2, 0.3"
32-
GeometricBase = "0.10"
33-
GeometricEquations = "0.16, 0.17"
32+
GeometricBase = "0.10.11"
33+
GeometricEquations = "0.18"
3434
GeometricSolutions = "0.3"
3535
OffsetArrays = "1"
3636
Parameters = "0.12"

docs/src/developer/projections.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Projection Methods
2+
3+
Projection methods are implemented in such a way that they can be combined with almost any one-step method in GeometricIntegrators.
4+
5+
6+
7+
8+

src/Extrapolators.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ module Extrapolators
77
using GeometricEquations
88

99
import Base: Callable
10+
import GeometricBase: solutionstep!
1011

1112
export Extrapolation,
1213
EulerExtrapolation,
1314
MidpointExtrapolation,
1415
HermiteExtrapolation
15-
export extrapolate!
16+
export NoInitialGuess
17+
export extrapolate!, solutionstep!
1618

19+
include("extrapolation/vectorfields.jl")
1720
include("extrapolation/extrapolation.jl")
1821
include("extrapolation/aitken_neville.jl")
1922
include("extrapolation/euler.jl")

src/Integrators.jl

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ module Integrators
2929
import CompactBasisFunctions: nbasis
3030

3131
import GeometricBase: description, reference, tableau, order
32-
import GeometricBase: equations, nconstraints, parameters, timestep
33-
import GeometricBase: integrate, integrate!
32+
import GeometricBase: equations, initialguess, nconstraints, parameters, timestep
33+
import GeometricBase: integrate, integrate!, solutionstep!
3434
import GeometricBase: reset!
3535
import GeometricBase.Utils: @big, @define, compensated_summation
3636

@@ -97,14 +97,6 @@ module Integrators
9797
include("solutions/solution_step_constructors.jl")
9898

9999

100-
export InitialGuess, NoInitialGuess
101-
export initialguess!
102-
103-
include("initial_guess/initial_guess.jl")
104-
include("initial_guess/hermite.jl")
105-
include("initial_guess/midpoint.jl")
106-
107-
108100
export IntegratorCache, IntegratorConstructor
109101
export equation, timestep
110102

@@ -117,7 +109,7 @@ module Integrators
117109

118110

119111
export GeometricIntegrator
120-
export integrate, integrate!, integrate_step!
112+
export integrate, integrate!, solutionstep!
121113

122114
include("integrators/integrator.jl")
123115

src/SPARK.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@ module SPARK
2222
import ..Integrators: GeometricIntegrator, Newton
2323
import ..Integrators: HDAEMethod, IDAEMethod, LDAEMethod, PDAEMethod
2424
import ..Integrators: SolutionStepPDAE
25-
import ..Integrators: InitialGuess, Extrapolation, HermiteExtrapolation
26-
import ..Integrators: initialguess!, initial_guess!, integrate_step!, residual!
25+
import ..Integrators: StageVector
26+
import ..Integrators: Extrapolation, HermiteExtrapolation
27+
import ..Integrators: initial_guess!, integrate_step!, residual!, solutionstep!
2728
import ..Integrators: CacheDict, Cache, CacheType, IDAEIntegratorCache
2829
import ..Integrators: AbstractCoefficients,
2930
@CoefficientsRK, @HeaderCoefficientsRK
3031
import ..Integrators: create_internal_stage_vector,
3132
update!, update_vector_fields!, update_multiplier!,
32-
initialize!, initsolver, internal, nlsolution
33-
import ..Integrators: equation, equations, timestep, eachstage, nstages
33+
initialize!, initsolver, internal, nlsolution,
34+
internal_variables
35+
import ..Integrators: current, equation, equations, timestep, eachstage, nstages
36+
import ..Integrators: cache, caches, iguess, method, problem, solver
3437

3538

3639
export CoefficientsARK, CoefficientsPRK, CoefficientsMRK, CoefficientsIRK,

src/extrapolation/euler.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ end
3636

3737
function extrapolate!(t₀::TT, x₀::AbstractVector{DT},
3838
t₁::TT, x₁::AbstractVector{DT},
39-
v::Callable, params::OptionalParameters,
39+
problem::AbstractProblemODE,
4040
extrap::EulerExtrapolation) where {DT,TT}
41-
@assert size(x₀) == size(x₁)
41+
42+
@assert axes(x₀) == axes(x₁)
4243

4344
local F = collect(1:(extrap.s+1))
4445
local σ = (t₁ - t₀) ./ F
@@ -53,7 +54,7 @@ function extrapolate!(t₀::TT, x₀::AbstractVector{DT},
5354
for k in axes(pts,1)
5455
xᵢ[k] = pts[k,i]
5556
end
56-
v(vᵢ, tᵢ, xᵢ, params)
57+
initialguess(problem).v(vᵢ, tᵢ, xᵢ, parameters(problem))
5758
for k in axes(pts,1)
5859
pts[k,i] += σ[i] * vᵢ[k]
5960
end
@@ -65,9 +66,8 @@ function extrapolate!(t₀::TT, x₀::AbstractVector{DT},
6566
return x₁
6667
end
6768

68-
function extrapolate!(t₀, x₀::AbstractVector,
69-
t₁, x₁::AbstractVector,
70-
problem::AbstractProblemODE,
71-
extrap::EulerExtrapolation)
72-
extrapolate!(t₀, x₀, t₁, x₁, functions(problem).v, parameters(problem), extrap)
69+
function solutionstep!(sol, history, problem::Union{AbstractProblemODE, SODEProblem}, extrap::EulerExtrapolation)
70+
extrapolate!(history.t[1], history.q[1], sol.t, sol.q, problem, extrap)
71+
update_vectorfields!(sol, problem)
72+
return sol
7373
end

src/extrapolation/extrapolation.jl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,29 @@
22
const default_extrapolation_stages = 5
33

44
abstract type Extrapolation end
5+
# abstract type Extrapolation <: DeterministicMethod end
56

6-
function extrapolate! end
7+
8+
struct NoInitialGuess <: Extrapolation end
9+
10+
11+
# """
12+
13+
14+
# """
15+
# function extrapolate! end
16+
17+
18+
19+
# function extrapolate!(t₀, q₀, q̇₀, t₁, q₁, q̇₁, t₂, q₂, q̇₂, problem::AbstractProblemODE, extrap::Extrapolation; kwargs...)
20+
# solution = (
21+
# t = t₀, q = q₀, v = q̇₀,
22+
# )
23+
24+
# history = (
25+
# (t = t₁, q = q₁, v = q̇₁),
26+
# (t = t₂, q = q₂, v = q̇₂),
27+
# )
28+
29+
# solutionstep!(solution, history, problem, extrap; kwargs...)
30+
# end

src/extrapolation/hermite.jl

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -188,45 +188,40 @@ function extrapolate!(t₀::TT, x₀::AbstractArray{DT}, ẋ₀::AbstractArray{D
188188
return (xᵢ, ẋᵢ)
189189
end
190190

191+
function solutionstep!(sol, history, problem::Union{AbstractProblemODE, SODEProblem}, extrap::HermiteExtrapolation; nowarn = false)
192+
t₀, q₀, q̇₀ = history.t[2], history.q[2], history.v[2]
193+
t₁, q₁, q̇₁ = history.t[1], history.q[1], history.v[1]
194+
195+
if q₀ == q₁
196+
nowarn || @warn "Hermite Extrapolation: q's history[1] and history[2] are identical!"
197+
sol.q .= q₁
198+
sol.v .= q̇₁
199+
else
200+
extrapolate!(t₀, q₀, q̇₀, t₁, q₁, q̇₁, sol.t, sol.q, sol.v, extrap)
201+
end
191202

192-
function _vectorfield(t::TT, x::AbstractArray{DT}, v::Callable, params) where {DT,TT}
193-
= zero(x)
194-
v(ẋ, t, x, params)
195-
return
203+
return sol
196204
end
197205

198-
function extrapolate!(t₀::TT, x₀::AbstractArray{DT},
199-
t₁::TT, x₁::AbstractArray{DT},
200-
tᵢ::TT, xᵢ::AbstractArray{DT},
201-
v::Function, params::OptionalParameters,
202-
extrap::HermiteExtrapolation) where {DT,TT}
203-
ẋ₀ = _vectorfield(t₀, x₀, v, params)
204-
ẋ₁ = _vectorfield(t₁, x₁, v, params)
205-
extrapolate!(t₀, x₀, ẋ₀, t₁, x₁, ẋ₁, tᵢ, xᵢ, extrap)
206-
end
206+
function solutionstep!(sol, history, problem::Union{AbstractProblemPODE, AbstractProblemIODE}, extrap::HermiteExtrapolation; nowarn = false)
207+
t₀, q₀, v₀, p₀, f₀ = history.t[2], history.q[2], history.v[2], history.p[2], history.f[2]
208+
t₁, q₁, v₁, p₁, f₁ = history.t[1], history.q[1], history.v[1], history.p[1], history.f[1]
207209

208-
function extrapolate!(t₀::TT, x₀::AbstractArray{DT},
209-
t₁::TT, x₁::AbstractArray{DT},
210-
tᵢ::TT, xᵢ::AbstractArray{DT}, ẋᵢ::AbstractArray{DT},
211-
v::Function, params::OptionalParameters,
212-
extrap::HermiteExtrapolation) where {DT,TT}
213-
ẋ₀ = _vectorfield(t₀, x₀, v, params)
214-
ẋ₁ = _vectorfield(t₁, x₁, v, params)
215-
extrapolate!(t₀, x₀, ẋ₀, t₁, x₁, ẋ₁, tᵢ, xᵢ, ẋᵢ, extrap)
216-
end
210+
if q₀ == q₁
211+
nowarn || @warn "Hermite Extrapolation: q's history[1] and history[2] are identical!"
212+
sol.q .= q₁
213+
sol.v .= v₁
214+
else
215+
extrapolate!(t₀, q₀, v₀, t₁, q₁, v₁, sol.t, sol.q, sol.v, extrap)
216+
end
217217

218-
function extrapolate!(t₀::TT, x₀::AbstractArray{DT},
219-
t₁::TT, x₁::AbstractArray{DT},
220-
tᵢ::TT, xᵢ::AbstractArray{DT},
221-
problem::AbstractProblemODE,
222-
extrap::HermiteExtrapolation) where {DT,TT}
223-
extrapolate!(t₀, x₀, t₁, x₁, tᵢ, xᵢ, functions(problem).v, parameters(problem), extrap)
224-
end
218+
if p₀ == p₁
219+
nowarn || @warn "Hermite Extrapolation: p's history[1] and history[2] are identical!"
220+
sol.p .= p₁
221+
sol.f .= f₁
222+
else
223+
extrapolate!(t₀, p₀, f₀, t₁, p₁, f₁, sol.t, sol.p, sol.f, extrap)
224+
end
225225

226-
function extrapolate!(t₀::TT, x₀::AbstractArray{DT},
227-
t₁::TT, x₁::AbstractArray{DT},
228-
tᵢ::TT, xᵢ::AbstractArray{DT}, ẋᵢ::AbstractArray{DT},
229-
problem::AbstractProblemODE,
230-
extrap::HermiteExtrapolation) where {DT,TT}
231-
extrapolate!(t₀, x₀, t₁, x₁, tᵢ, xᵢ, ẋᵢ, functions(problem).v, parameters(problem), extrap)
226+
return sol
232227
end

0 commit comments

Comments
 (0)