Skip to content

Commit

Permalink
outsource common NSTEPS code to function
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jul 28, 2024
1 parent 3d9acf3 commit 0e3e3d0
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 84 deletions.
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_NSTEPS(kwargs, δ, 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_NSTEPS(kwargs, δ, 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_NSTEPS(kwargs, δ, 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_NSTEPS(kwargs, δ, 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_NSTEPS(kwargs, δ, 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_NSTEPS(kwargs, δ, 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_NSTEPS(kwargs, δ, 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_NSTEPS(kwargs, δ, 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_NSTEPS(kwargs, δ, tspan)

# normalize system to canonical form
# x' = Ax, x in X, or
Expand Down
11 changes: 11 additions & 0 deletions src/Continuous/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0e3e3d0

Please sign in to comment.