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

Outsource common NSTEPS code to function #858

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 1 addition & 9 deletions src/Algorithms/A20/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(kwargs, :NSTEPS, compute_nsteps(δ, tspan))

# normalize system to canonical form
# x' = Ax, x in X, or
Expand Down
9 changes: 1 addition & 8 deletions src/Algorithms/ASB07/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(kwargs, :NSTEPS, compute_nsteps(δ, tspan))

# normalize system to canonical form
# x' = Ax, x in X, or
Expand Down
9 changes: 1 addition & 8 deletions src/Algorithms/BFFPSV18/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(kwargs, :NSTEPS, compute_nsteps(δ, tspan))

# normalize system to canonical form
# x' = Ax, x in X, or
Expand Down
9 changes: 1 addition & 8 deletions src/Algorithms/BOX/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(kwargs, :NSTEPS, compute_nsteps(δ, tspan))

# normalize system to canonical form
ivp_norm = _normalize(ivp)
Expand Down
10 changes: 1 addition & 9 deletions src/Algorithms/CARLIN/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 1 addition & 9 deletions src/Algorithms/GLGM06/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(kwargs, :NSTEPS, compute_nsteps(δ, tspan))

# normalize system to canonical form
# x' = Ax, x in X, or
Expand Down
9 changes: 1 addition & 8 deletions src/Algorithms/INT/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(kwargs, :NSTEPS, compute_nsteps(δ, tspan))

# normalize system to canonical form
ivp_norm = _normalize(ivp)
Expand Down
9 changes: 1 addition & 8 deletions src/Algorithms/LGG09/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(kwargs, :NSTEPS, compute_nsteps(δ, tspan))

# normalize system to canonical form
ivp_norm = _normalize(ivp)
Expand Down
9 changes: 1 addition & 8 deletions src/Algorithms/ORBIT/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(kwargs, :NSTEPS, compute_nsteps(δ, tspan))

U = inputset(ivp)

Expand Down
10 changes: 1 addition & 9 deletions src/Algorithms/VREP/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(kwargs, :NSTEPS, compute_nsteps(δ, tspan))

# normalize system to canonical form
# x' = Ax, x in X, or
Expand Down
7 changes: 7 additions & 0 deletions src/Continuous/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ function _get_T(tspan::TimeInterval; check_zero::Bool=true, check_positive::Bool
return T
end

function compute_nsteps(δ, tspan)
isempty(tspan) && return zero(δ)
# 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)
tend(Δt::TimeInterval) = sup(Δt)
tspan(Δt::TimeInterval) = Δt
Expand Down