From 3dbcab60368f1190ef8f79aefa66f0e3462d493b Mon Sep 17 00:00:00 2001 From: Marcelo Forets Date: Tue, 27 Aug 2024 18:14:26 -0300 Subject: [PATCH] refactor --- src/Algorithms/A20/post.jl | 2 +- src/Algorithms/ASB07/post.jl | 2 +- src/Algorithms/BFFPSV18/post.jl | 2 +- src/Algorithms/BOX/post.jl | 2 +- src/Algorithms/GLGM06/post.jl | 2 +- src/Algorithms/INT/post.jl | 2 +- src/Algorithms/LGG09/post.jl | 2 +- src/Algorithms/ORBIT/post.jl | 2 +- src/Algorithms/VREP/post.jl | 2 +- src/Continuous/solve.jl | 13 ++++--------- 10 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/Algorithms/A20/post.jl b/src/Algorithms/A20/post.jl index f8cbe3c29..84bf21974 100644 --- a/src/Algorithms/A20/post.jl +++ b/src/Algorithms/A20/post.jl @@ -2,7 +2,7 @@ function post(alg::A20{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan; Δt0::TimeInterval=zeroI, kwargs...) where {N} @unpack δ, max_order = alg - NSTEPS = _get_nsteps(kwargs, δ, tspan) + NSTEPS = get(kwargs, :NSTEPS, compute_nsteps(δ, 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 503b2cf4e..6f89a0f60 100644 --- a/src/Algorithms/ASB07/post.jl +++ b/src/Algorithms/ASB07/post.jl @@ -2,7 +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 - NSTEPS = _get_nsteps(kwargs, δ, tspan) + NSTEPS = get(kwargs, :NSTEPS, compute_nsteps(δ, 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 981061928..8d7c11725 100644 --- a/src/Algorithms/BFFPSV18/post.jl +++ b/src/Algorithms/BFFPSV18/post.jl @@ -3,7 +3,7 @@ function post(alg::BFFPSV18{N,ST}, ivp::IVP{<:AbstractContinuousSystem}, tspan; @unpack δ, approx_model, vars, block_indices, row_blocks, column_blocks = alg - NSTEPS = _get_nsteps(kwargs, δ, tspan) + NSTEPS = get(kwargs, :NSTEPS, compute_nsteps(δ, 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 f37ca7d6a..7b22e7939 100644 --- a/src/Algorithms/BOX/post.jl +++ b/src/Algorithms/BOX/post.jl @@ -2,7 +2,7 @@ function post(alg::BOX{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan; Δt0::TimeInterval=zeroI, kwargs...) where {N} @unpack δ, approx_model, static, dim, recursive = alg - NSTEPS = _get_nsteps(kwargs, δ, tspan) + NSTEPS = get(kwargs, :NSTEPS, compute_nsteps(δ, tspan)) # normalize system to canonical form ivp_norm = _normalize(ivp) diff --git a/src/Algorithms/GLGM06/post.jl b/src/Algorithms/GLGM06/post.jl index 11e25f108..3d49b499e 100644 --- a/src/Algorithms/GLGM06/post.jl +++ b/src/Algorithms/GLGM06/post.jl @@ -4,7 +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 - NSTEPS = _get_nsteps(kwargs, δ, tspan) + NSTEPS = get(kwargs, :NSTEPS, compute_nsteps(δ, 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 a355c67e7..bafaf9aca 100644 --- a/src/Algorithms/INT/post.jl +++ b/src/Algorithms/INT/post.jl @@ -7,7 +7,7 @@ function post(alg::INT{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan; @unpack δ, approx_model = alg - NSTEPS = _get_nsteps(kwargs, δ, tspan) + NSTEPS = get(kwargs, :NSTEPS, compute_nsteps(δ, 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 84c3f2810..e313b64c9 100644 --- a/src/Algorithms/LGG09/post.jl +++ b/src/Algorithms/LGG09/post.jl @@ -6,7 +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))" - NSTEPS = _get_nsteps(kwargs, δ, tspan) + NSTEPS = get(kwargs, :NSTEPS, compute_nsteps(δ, 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 254369648..d5e534820 100644 --- a/src/Algorithms/ORBIT/post.jl +++ b/src/Algorithms/ORBIT/post.jl @@ -2,7 +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 - NSTEPS = _get_nsteps(kwargs, δ, tspan) + NSTEPS = get(kwargs, :NSTEPS, compute_nsteps(δ, tspan)) U = inputset(ivp) diff --git a/src/Algorithms/VREP/post.jl b/src/Algorithms/VREP/post.jl index 49ab49c00..6846679ce 100644 --- a/src/Algorithms/VREP/post.jl +++ b/src/Algorithms/VREP/post.jl @@ -7,7 +7,7 @@ function post(alg::VREP{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan; Δt0::TimeInterval=zeroI, kwargs...) where {N} @unpack δ, approx_model, static, dim = alg - NSTEPS = _get_nsteps(kwargs, δ, tspan) + NSTEPS = get(kwargs, :NSTEPS, compute_nsteps(δ, 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 df3fb2e8d..acdca3179 100644 --- a/src/Continuous/solve.jl +++ b/src/Continuous/solve.jl @@ -288,15 +288,10 @@ 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 +function compute_nsteps(δ, tspan) + # 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) + return NSTEPS = ceil(Int, T / δ) end tstart(Δt::TimeInterval) = inf(Δt)