From 3353c6a479802f459e66f52477cb17e7238b6f13 Mon Sep 17 00:00:00 2001 From: schillic Date: Sun, 28 Jul 2024 13:21:58 +0200 Subject: [PATCH] outsource common NSTEPS code to function --- src/Algorithms/A20/post.jl | 10 +--------- src/Algorithms/ASB07/post.jl | 9 +-------- src/Algorithms/BFFPSV18/post.jl | 9 +-------- src/Algorithms/BOX/post.jl | 9 +-------- src/Algorithms/CARLIN/post.jl | 10 +--------- src/Algorithms/GLGM06/post.jl | 10 +--------- src/Algorithms/INT/post.jl | 9 +-------- src/Algorithms/LGG09/post.jl | 9 +-------- src/Algorithms/ORBIT/post.jl | 9 +-------- src/Algorithms/VREP/post.jl | 10 +--------- src/Continuous/solve.jl | 11 +++++++++++ 11 files changed, 21 insertions(+), 84 deletions(-) diff --git a/src/Algorithms/A20/post.jl b/src/Algorithms/A20/post.jl index 3582583efa..7ea31be7df 100644 --- a/src/Algorithms/A20/post.jl +++ b/src/Algorithms/A20/post.jl @@ -2,15 +2,7 @@ function post(alg::A20{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan; Δt0::TimeInterval=zeroI, kwargs...) where {N} @unpack δ, max_order = alg - # TODO move up to main solve function - if haskey(kwargs, :NSTEPS) - NSTEPS = kwargs[:NSTEPS] - T = NSTEPS * δ - else - # get time horizon from the time span imposing that it is of the form (0, T) - T = _get_T(tspan; check_zero=true, check_positive=true) - NSTEPS = ceil(Int, T / δ) - end + NSTEPS = _get_nsteps(kwargs, δ, tspan) # normalize system to canonical form # x' = Ax, x in X, or diff --git a/src/Algorithms/ASB07/post.jl b/src/Algorithms/ASB07/post.jl index 47328439c8..7c1dade143 100644 --- a/src/Algorithms/ASB07/post.jl +++ b/src/Algorithms/ASB07/post.jl @@ -2,14 +2,7 @@ function post(alg::ASB07{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan; Δt0::TimeInterval=zeroI, kwargs...) where {N} @unpack δ, approx_model, max_order, reduction_method, static, recursive, dim, ngens = alg - if haskey(kwargs, :NSTEPS) - NSTEPS = kwargs[:NSTEPS] - T = NSTEPS * δ - else - # get time horizon from the time span imposing that it is of the form (0, T) - T = _get_T(tspan; check_zero=true, check_positive=true) - NSTEPS = ceil(Int, T / δ) - end + NSTEPS = _get_nsteps(kwargs, δ, tspan) # normalize system to canonical form # x' = Ax, x in X, or diff --git a/src/Algorithms/BFFPSV18/post.jl b/src/Algorithms/BFFPSV18/post.jl index 9a54bc4d04..5521154389 100644 --- a/src/Algorithms/BFFPSV18/post.jl +++ b/src/Algorithms/BFFPSV18/post.jl @@ -3,14 +3,7 @@ function post(alg::BFFPSV18{N,ST}, ivp::IVP{<:AbstractContinuousSystem}, tspan; @unpack δ, approx_model, vars, block_indices, row_blocks, column_blocks = alg - if haskey(kwargs, :NSTEPS) - NSTEPS = kwargs[:NSTEPS] - T = NSTEPS * δ - else - # get time horizon from the time span imposing that it is of the form (0, T) - T = _get_T(tspan; check_zero=true, check_positive=true) - NSTEPS = ceil(Int, T / δ) - end + NSTEPS = _get_nsteps(kwargs, δ, tspan) # normalize system to canonical form # x' = Ax, x in X, or diff --git a/src/Algorithms/BOX/post.jl b/src/Algorithms/BOX/post.jl index 019aa65d39..6e140e3d20 100644 --- a/src/Algorithms/BOX/post.jl +++ b/src/Algorithms/BOX/post.jl @@ -2,14 +2,7 @@ function post(alg::BOX{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan; Δt0::TimeInterval=zeroI, kwargs...) where {N} @unpack δ, approx_model, static, dim, recursive = alg - if haskey(kwargs, :NSTEPS) - NSTEPS = kwargs[:NSTEPS] - T = NSTEPS * δ - else - # get time horizon from the time span imposing that it is of the form (0, T) - T = _get_T(tspan; check_zero=true, check_positive=true) - NSTEPS = ceil(Int, T / δ) - end + NSTEPS = _get_nsteps(kwargs, δ, tspan) # normalize system to canonical form ivp_norm = _normalize(ivp) diff --git a/src/Algorithms/CARLIN/post.jl b/src/Algorithms/CARLIN/post.jl index b5d6c9fb16..71b3901fc2 100644 --- a/src/Algorithms/CARLIN/post.jl +++ b/src/Algorithms/CARLIN/post.jl @@ -35,15 +35,7 @@ end function post(alg::CARLIN, ivp::IVP{<:AbstractContinuousSystem}, tspan; Δt0=interval(0), kwargs...) @unpack N, compress, δ, bloat, resets = alg - # for now we assume there are no resets - if haskey(kwargs, :NSTEPS) - NSTEPS = kwargs[:NSTEPS] - T = NSTEPS * δ - else - # get time horizon from the time span imposing that it is of the form (0, T) - T = _get_T(tspan; check_zero=true, check_positive=true) - NSTEPS = ceil(Int, T / δ) - end + T = _get_T(tspan; check_zero=true, check_positive=true) # extract initial states X0 = initial_state(ivp) diff --git a/src/Algorithms/GLGM06/post.jl b/src/Algorithms/GLGM06/post.jl index eaa041b377..1db209dc81 100644 --- a/src/Algorithms/GLGM06/post.jl +++ b/src/Algorithms/GLGM06/post.jl @@ -4,15 +4,7 @@ function post(alg::GLGM06{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan; @unpack δ, approx_model, max_order, static, dim, ngens, preallocate, reduction_method, disjointness_method = alg - # TODO move up to main solve function - if haskey(kwargs, :NSTEPS) - NSTEPS = kwargs[:NSTEPS] - T = NSTEPS * δ - else - # get time horizon from the time span imposing that it is of the form (0, T) - T = _get_T(tspan; check_zero=true, check_positive=true) - NSTEPS = ceil(Int, T / δ) - end + NSTEPS = _get_nsteps(kwargs, δ, tspan) # normalize system to canonical form # x' = Ax, x in X, or diff --git a/src/Algorithms/INT/post.jl b/src/Algorithms/INT/post.jl index d109c3066b..bb12ed6d96 100644 --- a/src/Algorithms/INT/post.jl +++ b/src/Algorithms/INT/post.jl @@ -7,14 +7,7 @@ function post(alg::INT{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan; @unpack δ, approx_model = alg - if haskey(kwargs, :NSTEPS) - NSTEPS = kwargs[:NSTEPS] - T = NSTEPS * δ - else - # get time horizon from the time span imposing that it is of the form (0, T) - T = _get_T(tspan; check_zero=true, check_positive=true) - NSTEPS = ceil(Int, T / δ) - end + NSTEPS = _get_nsteps(kwargs, δ, tspan) # normalize system to canonical form ivp_norm = _normalize(ivp) diff --git a/src/Algorithms/LGG09/post.jl b/src/Algorithms/LGG09/post.jl index dd49cff5dd..81b3826ab2 100644 --- a/src/Algorithms/LGG09/post.jl +++ b/src/Algorithms/LGG09/post.jl @@ -6,14 +6,7 @@ function post(alg::LGG09{N,AM,VN,TN}, ivp::IVP{<:AbstractContinuousSystem}, tspa @assert statedim(ivp) == dim(template) "the problems' dimension $(statedim(ivp)) " * "doesn't match the dimension of the template directions, $(dim(template))" - if haskey(kwargs, :NSTEPS) - NSTEPS = kwargs[:NSTEPS] - T = NSTEPS * δ - else - # get time horizon from the time span imposing that it is of the form (0, T) - T = _get_T(tspan; check_zero=true, check_positive=true) - NSTEPS = ceil(Int, T / δ) - end + NSTEPS = _get_nsteps(kwargs, δ, tspan) # normalize system to canonical form ivp_norm = _normalize(ivp) diff --git a/src/Algorithms/ORBIT/post.jl b/src/Algorithms/ORBIT/post.jl index 2320f5a56c..0900fbd995 100644 --- a/src/Algorithms/ORBIT/post.jl +++ b/src/Algorithms/ORBIT/post.jl @@ -2,14 +2,7 @@ function post(alg::ORBIT{N,VT,AM}, ivp::IVP{<:AbstractContinuousSystem}, tspan; Δt0::TimeInterval=zeroI, kwargs...) where {N,VT,AM} @unpack δ, approx_model = alg - if haskey(kwargs, :NSTEPS) - NSTEPS = kwargs[:NSTEPS] - T = NSTEPS * δ - else - # get time horizon from the time span imposing that it is of the form (0, T) - T = _get_T(tspan; check_zero=true, check_positive=true) - NSTEPS = ceil(Int, T / δ) - end + NSTEPS = _get_nsteps(kwargs, δ, tspan) U = inputset(ivp) diff --git a/src/Algorithms/VREP/post.jl b/src/Algorithms/VREP/post.jl index 01721ae06b..55b5b58518 100644 --- a/src/Algorithms/VREP/post.jl +++ b/src/Algorithms/VREP/post.jl @@ -7,15 +7,7 @@ function post(alg::VREP{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan; Δt0::TimeInterval=zeroI, kwargs...) where {N} @unpack δ, approx_model, static, dim = alg - # TODO move up to main solve function - if haskey(kwargs, :NSTEPS) - NSTEPS = kwargs[:NSTEPS] - T = NSTEPS * δ - else - # get time horizon from the time span imposing that it is of the form (0, T) - T = _get_T(tspan; check_zero=true, check_positive=true) - NSTEPS = ceil(Int, T / δ) - end + NSTEPS = _get_nsteps(kwargs, δ, tspan) # normalize system to canonical form # x' = Ax, x in X, or diff --git a/src/Continuous/solve.jl b/src/Continuous/solve.jl index fd3e86e644..d8507d3747 100644 --- a/src/Continuous/solve.jl +++ b/src/Continuous/solve.jl @@ -288,6 +288,17 @@ function _get_T(tspan::TimeInterval; check_zero::Bool=true, check_positive::Bool return T end +function _get_nsteps(kwargs, δ, tspan) + if haskey(kwargs, :NSTEPS) + NSTEPS = kwargs[:NSTEPS] + else + # get time horizon from the time span imposing that it is of the form (0, T) + T = _get_T(tspan; check_zero=true, check_positive=true) + NSTEPS = ceil(Int, T / δ) + end + return NSTEPS +end + tstart(Δt::TimeInterval) = inf(Δt) tend(Δt::TimeInterval) = sup(Δt) tspan(Δt::TimeInterval) = Δt