Skip to content

Commit a797008

Browse files
refactor: format
1 parent 3a54d9e commit a797008

File tree

6 files changed

+150
-133
lines changed

6 files changed

+150
-133
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -841,35 +841,35 @@ function SciMLBase.BVProblem{iip, specialize}(sys::AbstractODESystem, u0map = []
841841
eval_expression = false,
842842
eval_module = @__MODULE__,
843843
kwargs...) where {iip, specialize}
844-
845844
if !iscomplete(sys)
846845
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating an `BVProblem`")
847846
end
848847
!isnothing(callback) && error("BVP solvers do not support callbacks.")
849848

850-
has_alg_eqs(sys) && error("The BVProblem constructor currently does not support ODESystems with algebraic equations.") # Remove this when the BVDAE solvers get updated, the codegen should work when it does.
849+
has_alg_eqs(sys) &&
850+
error("The BVProblem constructor currently does not support ODESystems with algebraic equations.") # Remove this when the BVDAE solvers get updated, the codegen should work when it does.
851851

852852
sts = unknowns(sys)
853853
ps = parameters(sys)
854854
constraintsys = get_constraintsystem(sys)
855855

856856
if !isnothing(constraintsys)
857-
(length(constraints(constraintsys)) + length(u0map) > length(sts)) &&
858-
@warn "The BVProblem is overdetermined. The total number of conditions (# constraints + # fixed initial values given by u0map) exceeds the total number of states. The BVP solvers will default to doing a nonlinear least-squares optimization."
857+
(length(constraints(constraintsys)) + length(u0map) > length(sts)) &&
858+
@warn "The BVProblem is overdetermined. The total number of conditions (# constraints + # fixed initial values given by u0map) exceeds the total number of states. The BVP solvers will default to doing a nonlinear least-squares optimization."
859859
end
860860

861861
# ODESystems without algebraic equations should use both fixed values + guesses
862862
# for initialization.
863-
_u0map = has_alg_eqs(sys) ? u0map : merge(Dict(u0map), Dict(guesses))
863+
_u0map = has_alg_eqs(sys) ? u0map : merge(Dict(u0map), Dict(guesses))
864864
f, u0, p = process_SciMLProblem(ODEFunction{iip, specialize}, sys, _u0map, parammap;
865865
t = tspan !== nothing ? tspan[1] : tspan, guesses,
866866
check_length, warn_initialize_determined, eval_expression, eval_module, kwargs...)
867867

868868
stidxmap = Dict([v => i for (i, v) in enumerate(sts)])
869-
u0_idxs = has_alg_eqs(sys) ? collect(1:length(sts)) : [stidxmap[k] for (k,v) in u0map]
869+
u0_idxs = has_alg_eqs(sys) ? collect(1:length(sts)) : [stidxmap[k] for (k, v) in u0map]
870870

871871
fns = generate_function_bc(sys, u0, u0_idxs, tspan)
872-
bc_oop, bc_iip = eval_or_rgf.(fns; eval_expression, eval_module)
872+
bc_oop, bc_iip = eval_or_rgf.(fns; eval_expression, eval_module)
873873
bc(sol, p, t) = bc_oop(sol, p, t)
874874
bc(resid, u, p, t) = bc_iip(resid, u, p, t)
875875

src/systems/diffeqs/odesystem.jl

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ struct ODESystem <: AbstractODESystem
193193
"""
194194
parent::Any
195195

196-
function ODESystem(tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, constraints, tgrad,
196+
function ODESystem(
197+
tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, constraints, tgrad,
197198
jac, ctrl_jac, Wfact, Wfact_t, name, description, systems, defaults, guesses,
198199
torn_matching, initializesystem, initialization_eqs, schedule,
199200
connector_type, preface, cevents,
@@ -214,7 +215,8 @@ struct ODESystem <: AbstractODESystem
214215
u = __get_unit_type(dvs, ps, iv)
215216
check_units(u, deqs)
216217
end
217-
new(tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, constraints, tgrad, jac,
218+
new(tag, deqs, iv, dvs, ps, tspan, var_to_name,
219+
ctrls, observed, constraints, tgrad, jac,
218220
ctrl_jac, Wfact, Wfact_t, name, description, systems, defaults, guesses, torn_matching,
219221
initializesystem, initialization_eqs, schedule, connector_type, preface,
220222
cevents, devents, parameter_dependencies, assertions, metadata,
@@ -300,16 +302,16 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
300302
if is_dde === nothing
301303
is_dde = _check_if_dde(deqs, iv′, systems)
302304
end
303-
305+
304306
if !isempty(systems) && !isnothing(constraintsystem)
305307
conssystems = ConstraintsSystem[]
306308
for sys in systems
307309
cons = get_constraintsystem(sys)
308-
cons !== nothing && push!(conssystems, cons)
310+
cons !== nothing && push!(conssystems, cons)
309311
end
310312
@show conssystems
311313
@set! constraintsystem.systems = conssystems
312-
end
314+
end
313315

314316
assertions = Dict{BasicSymbolic, Any}(unwrap(k) => v for (k, v) in assertions)
315317

@@ -359,9 +361,9 @@ function ODESystem(eqs, iv; constraints = Equation[], kwargs...)
359361
if !isempty(constraints)
360362
constraintsystem = process_constraint_system(constraints, allunknowns, new_ps, iv)
361363
for st in get_unknowns(constraintsystem)
362-
iscall(st) ?
363-
!in(operation(st)(iv), allunknowns) && push!(consvars, st) :
364-
!in(st, allunknowns) && push!(consvars, st)
364+
iscall(st) ?
365+
!in(operation(st)(iv), allunknowns) && push!(consvars, st) :
366+
!in(st, allunknowns) && push!(consvars, st)
365367
end
366368
for p in parameters(constraintsystem)
367369
!in(p, new_ps) && push!(new_ps, p)
@@ -712,7 +714,8 @@ end
712714
# Validate that all the variables in the BVP constraints are well-formed states or parameters.
713715
# - Callable/delay variables (e.g. of the form x(0.6) should be unknowns of the system (and have one arg, etc.)
714716
# - Callable/delay parameters should be parameters of the system (and have one arg, etc.)
715-
function process_constraint_system(constraints::Vector{Equation}, sts, ps, iv; consname = :cons)
717+
function process_constraint_system(
718+
constraints::Vector{Equation}, sts, ps, iv; consname = :cons)
716719
isempty(constraints) && return nothing
717720

718721
constraintsts = OrderedSet()
@@ -725,22 +728,26 @@ function process_constraint_system(constraints::Vector{Equation}, sts, ps, iv; c
725728
# Validate the states.
726729
for var in constraintsts
727730
if !iscall(var)
728-
occursin(iv, var) && (var sts || throw(ArgumentError("Time-dependent variable $var is not an unknown of the system.")))
731+
occursin(iv, var) && (var sts ||
732+
throw(ArgumentError("Time-dependent variable $var is not an unknown of the system.")))
729733
elseif length(arguments(var)) > 1
730734
throw(ArgumentError("Too many arguments for variable $var."))
731735
elseif length(arguments(var)) == 1
732736
arg = only(arguments(var))
733-
operation(var)(iv) sts ||
737+
operation(var)(iv) sts ||
734738
throw(ArgumentError("Variable $var is not a variable of the ODESystem. Called variables must be variables of the ODESystem."))
735739

736-
isequal(arg, iv) || isparameter(arg) || arg isa Integer || arg isa AbstractFloat ||
740+
isequal(arg, iv) || isparameter(arg) || arg isa Integer ||
741+
arg isa AbstractFloat ||
737742
throw(ArgumentError("Invalid argument specified for variable $var. The argument of the variable should be either $iv, a parameter, or a value specifying the time that the constraint holds."))
738743

739744
isparameter(arg) && push!(constraintps, arg)
740745
else
741-
var sts && @warn "Variable $var has no argument. It will be interpreted as $var($iv), and the constraint will apply to the entire interval."
746+
var sts &&
747+
@warn "Variable $var has no argument. It will be interpreted as $var($iv), and the constraint will apply to the entire interval."
742748
end
743749
end
744750

745-
ConstraintsSystem(constraints, collect(constraintsts), collect(constraintps); name = consname)
751+
ConstraintsSystem(
752+
constraints, collect(constraintsts), collect(constraintps); name = consname)
746753
end

src/systems/problem_utils.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,8 @@ function check_inputmap_keys(sys, u0map, pmap)
872872
push!(badparamkeys, k)
873873
end
874874
end
875-
(isempty(badvarkeys) && isempty(badparamkeys)) || throw(InvalidKeyError(collect(badvarkeys), collect(badparamkeys)))
875+
(isempty(badvarkeys) && isempty(badparamkeys)) ||
876+
throw(InvalidKeyError(collect(badvarkeys), collect(badparamkeys)))
876877
end
877878

878879
const BAD_KEY_MESSAGE = """
@@ -885,14 +886,12 @@ struct InvalidKeyError <: Exception
885886
params::Any
886887
end
887888

888-
function Base.showerror(io::IO, e::InvalidKeyError)
889+
function Base.showerror(io::IO, e::InvalidKeyError)
889890
println(io, BAD_KEY_MESSAGE)
890891
println(io, "u0map: $(join(e.vars, ", "))")
891892
println(io, "pmap: $(join(e.params, ", "))")
892893
end
893894

894-
895-
896895
##############
897896
# Legacy functions for backward compatibility
898897
##############

0 commit comments

Comments
 (0)