Skip to content

Commit

Permalink
Add AliasSpecifiers for more problem types
Browse files Browse the repository at this point in the history
  • Loading branch information
jClugstor committed Dec 11, 2024
1 parent 081910e commit dcd70ef
Show file tree
Hide file tree
Showing 15 changed files with 366 additions and 22 deletions.
34 changes: 34 additions & 0 deletions src/problems/analytical_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,37 @@ function AnalyticalProblem(f, u0, tspan, p = NullParameters(); kwargs...)
end

export AnalyticalProblem, AbstractAnalyticalProblem

struct AnalyticalAliasSpecifier <: AbstractAliasSpecifier
alias_p::Union{Bool, Nothing}
alias_f::Union{Bool, Nothing}
alias_u0::Union{Bool, Nothing}
alias_du0::Union{Bool, Nothing}
alias_tstops::Union{Bool, Nothing}
end

@doc doc"""
Holds information on what variables to alias
when solving an AnalyticalProblem. Conforms to the AbstractAliasSpecifier interface.
AnalyticalAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
### Keywords
* `alias_p::Union{Bool, Nothing}`
* `alias_f::Union{Bool, Nothing}`
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false .
* `alias_du0::Union{Bool, Nothing}`: alias the du0 array for DAEs. Defaults to false.
* `alias_tstops::Union{Bool, Nothing}`: alias the tstops array
* `alias::Union{Bool, Nothing}`: sets all fields of the `AnalyticalAliasSpecifier` to `alias`
"""
function AnalyticalAliasSpecifier(; alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
if alias == true
AnalyticalAliasSpecifier(true, true, true, true, true)
elseif alias == false
AnalyticalAliasSpecifier(false, false, false, false, false)
elseif isnothing(alias)
AnalyticalAliasSpecifier(alias_p, alias_f, alias_u0, alias_du0, alias_tstops)
end
end
36 changes: 36 additions & 0 deletions src/problems/bvp_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,39 @@ function TwoPointSecondOrderBVProblem(
u0 = [initialGuess(i) for i in tspan]
return TwoPointSecondOrderBVProblem(f, bc, u0, (tspan[1], tspan[end]), p; kwargs...)
end


struct BVPAliasSpecifier <: AbstractAliasSpecifier
alias_p::Union{Bool, Nothing}
alias_f::Union{Bool, Nothing}
alias_u0::Union{Bool, Nothing}
alias_du0::Union{Bool, Nothing}
alias_tstops::Union{Bool, Nothing}
end


@doc doc"""
Holds information on what variables to alias
when solving an BVP. Conforms to the AbstractAliasSpecifier interface.
BVPAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
### Keywords
* `alias_p::Union{Bool, Nothing}`
* `alias_f::Union{Bool, Nothing}`
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false .
* `alias_du0::Union{Bool, Nothing}`: alias the du0 array for DAEs. Defaults to false.
* `alias_tstops::Union{Bool, Nothing}`: alias the tstops array
* `alias::Union{Bool, Nothing}`: sets all fields of the `BVPAliasSpecifier` to `alias`
"""
function BVPAliasSpecifier(; alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
if alias == true
BVPAliasSpecifier(true, true, true, true, true)
elseif alias == false
BVPAliasSpecifier(false, false, false, false, false)
elseif isnothing(alias)
BVPAliasSpecifier(alias_p, alias_f, alias_u0, alias_du0, alias_tstops)
end
end
36 changes: 36 additions & 0 deletions src/problems/dae_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,39 @@ function ConstructionBase.constructorof(::Type{P}) where {P <: DAEProblem}
return DAEProblem{iip}(f, du0, u0, tspan, p; differential_vars = dv, kw...)
end
end


struct DAEAliasSpecifier
alias_p::Union{Bool, Nothing}
alias_f::Union{Bool, Nothing}
alias_u0::Union{Bool, Nothing}
alias_du0::Union{Bool, Nothing}
alias_tstops::Union{Bool, Nothing}
end


@doc doc"""
Holds information on what variables to alias
when solving a DAE. Conforms to the AbstractAliasSpecifier interface.
DAEAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
### Keywords
* `alias_p::Union{Bool, Nothing}`
* `alias_f::Union{Bool, Nothing}`
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false.
* `alias_du0::Union{Bool, Nothing}`: alias the du0 array for DAEs. Defaults to false.
* `alias_tstops::Union{Bool, Nothing}`: alias the tstops array
* `alias::Union{Bool, Nothing}`: sets all fields of the `DAEAliasSpecifier` to `alias`
"""
function DAEAliasSpecifier(; alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
if alias == true
DAEAliasSpecifier(true, true, true, true, true)
elseif alias == false
DAEAliasSpecifier(false, false, false, false, false)
elseif isnothing(alias)
DAEAliasSpecifier(alias_p, alias_f, alias_u0, alias_du0, alias_tstops)
end
end
34 changes: 34 additions & 0 deletions src/problems/dde_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,37 @@ function SecondOrderDDEProblem(f::DynamicalDDEFunction, args...; kwargs...)
kwargs...)
end
end

struct DDEAliasSpecifier
alias_p
alias_f
alias_u0
alias_tstops
end


@doc doc"""
Holds information on what variables to alias
when solving a DDE. Conforms to the AbstractAliasSpecifier interface.
DDEAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
### Keywords
* `alias_p::Union{Bool, Nothing}`
* `alias_f::Union{Bool, Nothing}`
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false .
* `alias_du0::Union{Bool, Nothing}`: alias the du0 array for DAEs. Defaults to false.
* `alias_tstops::Union{Bool, Nothing}`: alias the tstops array
* `alias::Union{Bool, Nothing}`: sets all fields of the `DDEAliasSpecifier` to `alias`
"""
function DDEAliasSpecifier(; alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
if alias == true
DDEAliasSpecifier(true, true, true, true, true)
elseif alias == false
DDEAliasSpecifier(false, false, false, false, false)
elseif isnothing(alias)
DDEAliasSpecifier(alias_p, alias_f, alias_u0, alias_du0, alias_tstops)
end
end
31 changes: 31 additions & 0 deletions src/problems/discrete_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,34 @@ function DiscreteProblem(u0::Union{AbstractArray, Number}, tspan::Tuple,
end
DiscreteProblem(f, u0, tspan, p; kwargs...)
end

struct DiscreteAliasSpecifier
alias_p::Union{Bool, Nothing}
alias_f::Union{Bool, Nothing}
alias_u0::Union{Bool, Nothing}
end


@doc doc"""
Holds information on what variables to alias
when solving a DiscreteProblem. Conforms to the AbstractAliasSpecifier interface.
DiscreteAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias = nothing)
### Keywords
* `alias_p::Union{Bool, Nothing}`
* `alias_f::Union{Bool, Nothing}`
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false .
* `alias::Union{Bool, Nothing}`: sets all fields of the `DiscreteAliasSpecifier` to `alias`
"""
function DiscreteAliasSpecifier(; alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
alias_du0 = nothing, alias = nothing)
if alias == true
DiscreteAliasSpecifier(true, true, true, true, true)
elseif alias == false
DiscreteAliasAliasSpecifier(false, false, false, false, false)
elseif isnothing(alias)
DiscreteAliasSpecifier(alias_p, alias_f, alias_u0)
end
end
31 changes: 31 additions & 0 deletions src/problems/implicit_discrete_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,34 @@ function ImplicitDiscreteProblem(f, u0, tspan, p = NullParameters();
iip = isinplace(f, 6)
ImplicitDiscreteProblem(ImplicitDiscreteFunction{iip}(f), u0, tspan, p; kwargs...)
end


struct ImplicitDiscreteAliasSpecifier
alias_p::Union{Bool,Nothing}
alias_f::Union{Bool, Nothing}
alias_u0::Union{Bool, Nothing}
end

@doc doc"""
Holds information on what variables to alias
when solving an ODE. Conforms to the AbstractAliasSpecifier interface.
DiscreteAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias = nothing)
### Keywords
* `alias_p::Union{Bool, Nothing}`
* `alias_f::Union{Bool, Nothing}`
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false .
* `alias::Union{Bool, Nothing}`: sets all fields of the `ImplicitDiscreteAliasSpecifier` to `alias`
"""
function ImplicitDiscreteAliasSpecifier(; alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
alias_du0 = nothing, alias = nothing)
if alias == true
ImplicitDiscreteAliasSpecifier(true, true, true, true, true)
elseif alias == false
ImplicitDiscreteAliasAliasSpecifier(false, false, false, false, false)
elseif isnothing(alias)
ImplicitDiscreteAliasSpecifier(alias_p, alias_f, alias_u0)
end
end
12 changes: 12 additions & 0 deletions src/problems/integral_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ struct IntegralAliasSpecifier <: AbstractAliasSpecifier
alias_f
end

@doc doc"""
Holds information on what variables to alias
when solving an IntegralProblem. Conforms to the AbstractAliasSpecifier interface.
IntegralAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias = nothing)
### Keywords
* `alias_p::Union{Bool, Nothing}`
* `alias_f::Union{Bool, Nothing}`
* `alias::Union{Bool, Nothing}`: sets all fields of the `IntegralAliasSpecifier` to `alias`
"""
function IntegralAliasSpecifier(alias_p = nothing, alias_f = nothing, alias = nothing)
if alias == true
IntegralAliasSpecifier(true, true)
Expand Down
13 changes: 7 additions & 6 deletions src/problems/linear_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ struct LinearAliasSpecifier <: AbstractAliasSpecifier
end

@doc doc"""
Holds information on what variables to alias when solving a `LinearProblem`
Holds information on what variables to alias
when solving a LinearProblem. Conforms to the AbstractAliasSpecifier interface.
### Keywords
* `alias_p::Bool`
* `alias_f::Bool`
* `alias_A::Bool`: alias the `A` array.
* `alias_b::Bool`: alias the `b` array.
* `alias::Bool`: sets all fields of the `LinearAliasSpecifier` to `alias`.
* `alias_p::Union{Bool, Nothing}`
* `alias_f::Union{Bool, Nothing}`
* `alias_A::Union{Bool, Nothing}`: alias the `A` array.
* `alias_b::Union{Bool, Nothing}`: alias the `b` array.
* `alias::Union{Bool, Nothing}`: sets all fields of the `LinearAliasSpecifier` to `alias`.
Creates a `LinearAliasSpecifier` where `alias_A` and `alias_b` default to `nothing`.
When `alias_A` or `alias_b` is nothing, the default value of the solver is used.
Expand Down
13 changes: 7 additions & 6 deletions src/problems/nonlinear_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,16 @@ struct NonlinearAliasSpecifier <: AbstractAliasSpecifier
end

@doc doc"""
Holds information on what variables to alias when solving a `NonlinearProblem`.
Holds information on what variables to alias when solving a `NonlinearProblem`.
Conforms to the AbstractAliasSpecifier interface.
### Keywords
* `alias_p::Bool`
* `alias_f::Bool`
* `alias_A::Bool`: alias the `A` array.
* `alias_b::Bool`: alias the `b` array.
* `alias::Bool`: sets all fields of the `LinearAliasSpecifier` to `alias`.
* `alias_p::Union{Bool, Nothing}`
* `alias_f::Union{Bool, Nothing}`
* `alias_A::Union{Bool, Nothing}`: alias the `A` array.
* `alias_b::Union{Bool, Nothing}`: alias the `b` array.
* `alias::Union{Bool, Nothing}`: sets all fields of the `NonlinearAliasSpecifier` to `alias`.
"""
function NonlinearAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias = nothing)
if isnothing(alias)
Expand Down
12 changes: 6 additions & 6 deletions src/problems/ode_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,12 @@ when solving an ODE. Conforms to the AbstractAliasSpecifier interface.
ODEAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = false, alias_du0 = false, alias_tstops = false, alias = nothing)
### Keywords
* `alias_p::Bool`
* `alias_f::Bool`
* `alias_u0::Bool`: alias the u0 array. Defaults to false .
* `alias_du0::Bool`: alias the du0 array for DAEs. Defaults to false.
* `alias_tstops::Bool`: alias the tstops array
* `alias::Bool`: sets all fields of the `ODEAliasSpecifier` to `alias`
* `alias_p::Union{Bool, Nothing}`
* `alias_f::Union{Bool, Nothing}`
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false .
* `alias_du0::Union{Bool, Nothing}`: alias the du0 array for DAEs. Defaults to false.
* `alias_tstops::Union{Bool, Nothing}`: alias the tstops array
* `alias::Union{Bool, Nothing}`: sets all fields of the `ODEAliasSpecifier` to `alias`
"""
function ODEAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
Expand Down
18 changes: 16 additions & 2 deletions src/problems/optimization_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,25 @@ struct OptimizationAliasSpecifier <: AbstractAliasSpecifier
alias_u0
end


@doc doc"""
Holds information on what variables to alias
when solving an OptimizationProblem. Conforms to the AbstractAliasSpecifier interface.
OptimizationAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = false, alias = nothing)
### Keywords
* `alias_p::Union{Bool, Nothing}`
* `alias_f::Union{Bool, Nothing}`
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false .
* `alias::Union{Bool, Nothing}`: sets all fields of the `OptimizationAliasSpecifier` to `alias`
"""
function OptimizationAliasSpecifier(; alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias = nothing)
if alias == true
OptimizationAliasSpecifier(true, true, true, true, true)
OptimizationAliasSpecifier(true, true, true)
elseif alias == false
OptimizationAliasSpecifier(false, false, false, false, false)
OptimizationAliasSpecifier(false, false, false)
elseif isnothing(alias)
OptimizationAliasSpecifier(alias_p, alias_f, alias_u0, alias_tstops)
end
Expand Down
30 changes: 30 additions & 0 deletions src/problems/rode_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,34 @@ end
struct RODEAliasSpecifier <: AbstractAliasSpecifier
alias_p
alias_f
alias_u0
alias_du0
alias_tstops
end


@doc doc"""
Holds information on what variables to alias
when solving an RODEProblem. Conforms to the AbstractAliasSpecifier interface.
ODEAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = false, alias_du0 = false, alias_tstops = false, alias = nothing)
### Keywords
* `alias_p::Union{Bool, Nothing}`
* `alias_f::Union{Bool, Nothing}`
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false .
* `alias_du0::Union{Bool, Nothing}`: alias the du0 array for DAEs. Defaults to false.
* `alias_tstops::Union{Bool, Nothing}`: alias the tstops array
* `alias::Union{Bool, Nothing}`: sets all fields of the `RODEAliasSpecifier` to `alias`
"""
function RODEAliasSpecifier(; alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
if alias == true
RODEAliasSpecifier(true, true, true, true, true)
elseif alias == false
RODEAliasSpecifier(false, false, false, false, false)
elseif isnothing(alias)
RODEAliasSpecifier(alias_p, alias_f, alias_u0, alias_du0, alias_tstops)
end
end
Loading

0 comments on commit dcd70ef

Please sign in to comment.