Skip to content

Commit

Permalink
New formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
YingboMa committed Oct 29, 2023
1 parent 45dfe62 commit 0d8ab97
Show file tree
Hide file tree
Showing 37 changed files with 538 additions and 538 deletions.
8 changes: 4 additions & 4 deletions docs/src/tutorials/domain_connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ The fluid medium setter for `HydralicPort` may be defined as `HydraulicFluid` wi

```@example domain
@connector function HydraulicFluid(;
density = 997,
bulk_modulus = 2.09e9,
viscosity = 0.0010016,
name)
density = 997,
bulk_modulus = 2.09e9,
viscosity = 0.0010016,
name)
pars = @parameters begin
ρ = density
β = bulk_modulus
Expand Down
16 changes: 8 additions & 8 deletions ext/MTKBifurcationKitExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import BifurcationKit

# When input is a NonlinearSystem.
function BifurcationKit.BifurcationProblem(nsys::NonlinearSystem,
u0_bif,
ps,
bif_par,
args...;
plot_var = nothing,
record_from_solution = BifurcationKit.record_sol_default,
jac = true,
kwargs...)
u0_bif,
ps,
bif_par,
args...;
plot_var = nothing,
record_from_solution = BifurcationKit.record_sol_default,
jac = true,
kwargs...)
# Creates F and J functions.
ofun = NonlinearFunction(nsys; jac = jac)
F = ofun.f
Expand Down
2 changes: 1 addition & 1 deletion ext/MTKDeepDiffsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function Base.getindex(ssdpm::SystemStructureDiffPrintMatrix, i::Integer, j::Int
end

function DeepDiffs.deepdiff(old::Union{MatchedSystemStructure, SystemStructure},
new::Union{MatchedSystemStructure, SystemStructure})
new::Union{MatchedSystemStructure, SystemStructure})
new_sspm = SystemStructurePrintMatrix(new)
old_sspm = SystemStructurePrintMatrix(old)
Base.print_matrix(stdout, SystemStructureDiffPrintMatrix(new_sspm, old_sspm))
Expand Down
26 changes: 13 additions & 13 deletions src/bipartite_graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ mutable struct BipartiteGraph{I <: Integer, M} <: Graphs.AbstractGraph{I}
metadata::M
end
function BipartiteGraph(ne::Integer, fadj::AbstractVector,
badj::Union{AbstractVector, Integer} = maximum(maximum, fadj);
metadata = nothing)
badj::Union{AbstractVector, Integer} = maximum(maximum, fadj);
metadata = nothing)
BipartiteGraph(ne, fadj, badj, metadata)
end
function BipartiteGraph(fadj::AbstractVector,
badj::Union{AbstractVector, Integer} = maximum(maximum, fadj);
metadata = nothing)
badj::Union{AbstractVector, Integer} = maximum(maximum, fadj);
metadata = nothing)
BipartiteGraph(mapreduce(length, +, fadj; init = 0), fadj, badj, metadata)
end

Expand Down Expand Up @@ -325,7 +325,7 @@ $(SIGNATURES)
Build an empty `BipartiteGraph` with `nsrcs` sources and `ndsts` destinations.
"""
function BipartiteGraph(nsrcs::T, ndsts::T, backedge::Val{B} = Val(true);
metadata = nothing) where {T, B}
metadata = nothing) where {T, B}
fadjlist = map(_ -> T[], 1:nsrcs)
badjlist = B ? map(_ -> T[], 1:ndsts) : ndsts
BipartiteGraph(0, fadjlist, badjlist, metadata)
Expand Down Expand Up @@ -359,11 +359,11 @@ end
has_𝑠vertex(g::BipartiteGraph, v::Integer) = v in 𝑠vertices(g)
has_𝑑vertex(g::BipartiteGraph, v::Integer) = v in 𝑑vertices(g)
function 𝑠neighbors(g::BipartiteGraph, i::Integer,
with_metadata::Val{M} = Val(false)) where {M}
with_metadata::Val{M} = Val(false)) where {M}
M ? zip(g.fadjlist[i], g.metadata[i]) : g.fadjlist[i]
end
function 𝑑neighbors(g::BipartiteGraph, j::Integer,
with_metadata::Val{M} = Val(false)) where {M}
with_metadata::Val{M} = Val(false)) where {M}
require_complete(g)
M ? zip(g.badjlist[j], (g.metadata[i][j] for i in g.badjlist[j])) : g.badjlist[j]
end
Expand All @@ -389,7 +389,7 @@ Try to construct an augmenting path in matching and if such a path is found,
update the matching accordingly.
"""
function construct_augmenting_path!(matching::Matching, g::BipartiteGraph, vsrc, dstfilter,
dcolor = falses(ndsts(g)), scolor = nothing)
dcolor = falses(ndsts(g)), scolor = nothing)
scolor === nothing || (scolor[vsrc] = true)

# if a `vdst` is unassigned and the edge `vsrc <=> vdst` exists
Expand Down Expand Up @@ -421,7 +421,7 @@ vertices, subject to the constraint that vertices for which `srcfilter` or `dstf
return `false` may not be matched.
"""
function maximal_matching(g::BipartiteGraph, srcfilter = vsrc -> true,
dstfilter = vdst -> true, ::Type{U} = Unassigned) where {U}
dstfilter = vdst -> true, ::Type{U} = Unassigned) where {U}
matching = Matching{U}(ndsts(g))
foreach(Iterators.filter(srcfilter, 𝑠vertices(g))) do vsrc
construct_augmenting_path!(matching, g, vsrc, dstfilter)
Expand Down Expand Up @@ -550,7 +550,7 @@ Base.length(it::BipartiteEdgeIter) = ne(it.g)
Base.eltype(it::BipartiteEdgeIter) = edgetype(it.g)

function Base.iterate(it::BipartiteEdgeIter{SRC, <:BipartiteGraph{T}},
state = (1, 1, SRC)) where {T}
state = (1, 1, SRC)) where {T}
@unpack g = it
neqs = nsrcs(g)
neqs == 0 && return nothing
Expand All @@ -572,7 +572,7 @@ function Base.iterate(it::BipartiteEdgeIter{SRC, <:BipartiteGraph{T}},
end

function Base.iterate(it::BipartiteEdgeIter{DST, <:BipartiteGraph{T}},
state = (1, 1, DST)) where {T}
state = (1, 1, DST)) where {T}
@unpack g = it
nvars = ndsts(g)
nvars == 0 && return nothing
Expand Down Expand Up @@ -644,7 +644,7 @@ mutable struct DiCMOBiGraph{Transposed, I, G <: BipartiteGraph{I}, M <: Matching
ne::Union{Missing, Int}
matching::M
function DiCMOBiGraph{Transposed}(g::G, ne::Union{Missing, Int},
m::M) where {Transposed, I, G <: BipartiteGraph{I}, M}
m::M) where {Transposed, I, G <: BipartiteGraph{I}, M}
new{Transposed, I, G, M}(g, ne, m)
end
end
Expand All @@ -671,7 +671,7 @@ struct CMONeighbors{Transposed, V}
g::DiCMOBiGraph{Transposed}
v::V
function CMONeighbors{Transposed}(g::DiCMOBiGraph{Transposed},
v::V) where {Transposed, V}
v::V) where {Transposed, V}
new{Transposed, V}(g, v)
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/inputoutput.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ f[1](x, inputs, p, t)
```
"""
function generate_control_function(sys::AbstractODESystem, inputs = unbound_inputs(sys),
disturbance_inputs = disturbances(sys);
implicit_dae = false,
simplify = false,
kwargs...)
disturbance_inputs = disturbances(sys);
implicit_dae = false,
simplify = false,
kwargs...)
isempty(inputs) && @warn("No unbound inputs were found in system.")

if disturbance_inputs !== nothing
Expand Down
10 changes: 5 additions & 5 deletions src/structural_transformation/bareiss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ else
end

function bareiss_update!(zero!, M::StridedMatrix, k, swapto, pivot,
prev_pivot::Base.BitInteger)
prev_pivot::Base.BitInteger)
flag = zero(prev_pivot)
prev_pivot = Base.MultiplicativeInverses.SignedMultiplicativeInverse(prev_pivot)
@inbounds for i in (k + 1):size(M, 2)
Expand Down Expand Up @@ -149,7 +149,7 @@ end
end

function bareiss_update_virtual_colswap!(zero!, M::AbstractMatrix, k, swapto, pivot,
prev_pivot)
prev_pivot)
if prev_pivot isa Base.BitInteger
prev_pivot = Base.MultiplicativeInverses.SignedMultiplicativeInverse(prev_pivot)
end
Expand Down Expand Up @@ -189,7 +189,7 @@ bareiss_colswap (the default) swaps the columns and rows normally.
bareiss_virtcolswap pretends to swap the columns which can be faster for sparse matrices.
"""
function bareiss!(M::AbstractMatrix{T}, swap_strategy = bareiss_colswap;
find_pivot = find_pivot_any, column_pivots = nothing) where {T}
find_pivot = find_pivot_any, column_pivots = nothing) where {T}
swapcols!, swaprows!, update!, zero! = swap_strategy
prev = one(eltype(M))
n = size(M, 1)
Expand Down Expand Up @@ -252,7 +252,7 @@ end
###
### https://github.com/Nemocas/AbstractAlgebra.jl/blob/4803548c7a945f3f7bd8c63f8bb7c79fac92b11a/LICENSE.md
function reduce_echelon!(A::AbstractMatrix{T}, rank, d,
pivots_cache = zeros(Int, size(A, 2))) where {T}
pivots_cache = zeros(Int, size(A, 2))) where {T}
m, n = size(A)
isreduced = true
@inbounds for i in 1:rank
Expand Down Expand Up @@ -318,7 +318,7 @@ function reduce_echelon!(A::AbstractMatrix{T}, rank, d,
end

function reduced_echelon_nullspace(rank, A::AbstractMatrix{T},
pivots_cache = zeros(Int, size(A, 2))) where {T}
pivots_cache = zeros(Int, size(A, 2))) where {T}
n = size(A, 2)
nullity = n - rank
U = zeros(T, n, nullity)
Expand Down
12 changes: 6 additions & 6 deletions src/structural_transformation/bipartite_tearing/modia_tearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function try_assign_eq!(ict::IncrementalCycleTracker, vj::Integer, eq::Integer)
end

function try_assign_eq!(ict::IncrementalCycleTracker, vars, v_active, eq::Integer,
condition::F = _ -> true) where {F}
condition::F = _ -> true) where {F}
G = ict.graph
for vj in vars
(vj in v_active && G.matching[vj] === unassigned && condition(vj)) || continue
Expand All @@ -20,7 +20,7 @@ function try_assign_eq!(ict::IncrementalCycleTracker, vars, v_active, eq::Intege
end

function tearEquations!(ict::IncrementalCycleTracker, Gsolvable, es::Vector{Int},
v_active::BitSet, isder′::F) where {F}
v_active::BitSet, isder′::F) where {F}
check_der = isder′ !== nothing
if check_der
has_der = Ref(false)
Expand Down Expand Up @@ -54,7 +54,7 @@ function tearEquations!(ict::IncrementalCycleTracker, Gsolvable, es::Vector{Int}
end

function tear_graph_block_modia!(var_eq_matching, ict, solvable_graph, eqs, vars,
isder::F) where {F}
isder::F) where {F}
tearEquations!(ict, solvable_graph.fadjlist, eqs, vars, isder)
for var in vars
var_eq_matching[var] = ict.graph.matching[var]
Expand All @@ -63,9 +63,9 @@ function tear_graph_block_modia!(var_eq_matching, ict, solvable_graph, eqs, vars
end

function tear_graph_modia(structure::SystemStructure, isder::F = nothing,
::Type{U} = Unassigned;
varfilter::F2 = v -> true,
eqfilter::F3 = eq -> true) where {F, U, F2, F3}
::Type{U} = Unassigned;
varfilter::F2 = v -> true,
eqfilter::F3 = eq -> true) where {F, U, F2, F3}
# It would be possible here to simply iterate over all variables and attempt to
# use tearEquations! to produce a matching that greedily selects the minimal
# number of torn variables. However, we can do this process faster if we first
Expand Down
46 changes: 23 additions & 23 deletions src/structural_transformation/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using ModelingToolkit: isdifferenceeq, process_events, get_preprocess_constants
const MAX_INLINE_NLSOLVE_SIZE = 8

function torn_system_with_nlsolve_jacobian_sparsity(state, var_eq_matching, var_sccs,
nlsolve_scc_idxs, eqs_idxs, states_idxs)
nlsolve_scc_idxs, eqs_idxs, states_idxs)
graph = state.structure.graph

# The sparsity pattern of `nlsolve(f, u, p)` w.r.t `p` is difficult to
Expand Down Expand Up @@ -97,7 +97,7 @@ function torn_system_with_nlsolve_jacobian_sparsity(state, var_eq_matching, var_
end

function gen_nlsolve!(is_not_prepended_assignment, eqs, vars, u0map::AbstractDict,
assignments, (deps, invdeps), var2assignment; checkbounds = true)
assignments, (deps, invdeps), var2assignment; checkbounds = true)
isempty(vars) && throw(ArgumentError("vars may not be empty"))
length(eqs) == length(vars) ||
throw(ArgumentError("vars must be of the same length as the number of equations to find the roots of"))
Expand Down Expand Up @@ -226,11 +226,11 @@ function gen_nlsolve!(is_not_prepended_assignment, eqs, vars, u0map::AbstractDic
end

function build_torn_function(sys;
expression = false,
jacobian_sparsity = true,
checkbounds = false,
max_inlining_size = nothing,
kw...)
expression = false,
jacobian_sparsity = true,
checkbounds = false,
max_inlining_size = nothing,
kw...)
max_inlining_size = something(max_inlining_size, MAX_INLINE_NLSOLVE_SIZE)
rhss = []
eqs = equations(sys)
Expand Down Expand Up @@ -382,14 +382,14 @@ function find_solve_sequence(sccs, vars)
end

function build_observed_function(state, ts, var_eq_matching, var_sccs,
is_solver_state_idxs,
assignments,
deps,
sol_states,
var2assignment;
expression = false,
output_type = Array,
checkbounds = true)
is_solver_state_idxs,
assignments,
deps,
sol_states,
var2assignment;
expression = false,
output_type = Array,
checkbounds = true)
is_not_prepended_assignment = trues(length(assignments))
if (isscalar = !(ts isa AbstractVector))
ts = [ts]
Expand Down Expand Up @@ -524,14 +524,14 @@ struct ODAEProblem{iip} end
ODAEProblem(args...; kw...) = ODAEProblem{true}(args...; kw...)

function ODAEProblem{iip}(sys,
u0map,
tspan,
parammap = DiffEqBase.NullParameters();
callback = nothing,
use_union = true,
tofloat = true,
check = true,
kwargs...) where {iip}
u0map,
tspan,
parammap = DiffEqBase.NullParameters();
callback = nothing,
use_union = true,
tofloat = true,
check = true,
kwargs...) where {iip}
eqs = equations(sys)
check && ModelingToolkit.check_operator_variables(eqs, Differential)
fun, dvs = build_torn_function(sys; kwargs...)
Expand Down
6 changes: 3 additions & 3 deletions src/structural_transformation/partial_state_selection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function ascend_dg_all(xs, dg, level, maxlevel)
end

function pss_graph_modia!(structure::SystemStructure, maximal_top_matching, varlevel,
inv_varlevel, inv_eqlevel)
inv_varlevel, inv_eqlevel)
@unpack eq_to_diff, var_to_diff, graph, solvable_graph = structure

# var_eq_matching is a maximal matching on the top-differentiated variables.
Expand Down Expand Up @@ -168,15 +168,15 @@ function partial_state_selection_graph!(structure::SystemStructure, var_eq_match
end

function dummy_derivative_graph!(state::TransformationState, jac = nothing;
state_priority = nothing, log = Val(false), kwargs...)
state_priority = nothing, log = Val(false), kwargs...)
state.structure.solvable_graph === nothing && find_solvables!(state; kwargs...)
complete!(state.structure)
var_eq_matching = complete(pantelides!(state))
dummy_derivative_graph!(state.structure, var_eq_matching, jac, state_priority, log)
end

function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, jac = nothing,
state_priority = nothing, ::Val{log} = Val(false)) where {log}
state_priority = nothing, ::Val{log} = Val(false)) where {log}
@unpack eq_to_diff, var_to_diff, graph = structure
diff_to_eq = invview(eq_to_diff)
diff_to_var = invview(var_to_diff)
Expand Down
10 changes: 5 additions & 5 deletions src/structural_transformation/symbolics_tearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function solve_equation(eq, var, simplify)
end

function substitute_vars!(structure, subs, cache = Int[], callback! = nothing;
exclude = ())
exclude = ())
@unpack graph, solvable_graph = structure
for su in subs
su === nothing && continue
Expand All @@ -163,7 +163,7 @@ function substitute_vars!(structure, subs, cache = Int[], callback! = nothing;
end

function to_mass_matrix_form(neweqs, ieq, graph, fullvars, isdervar::F,
var_to_diff) where {F}
var_to_diff) where {F}
eq = neweqs[ieq]
if !(eq.lhs isa Number && eq.lhs == 0)
eq = 0 ~ eq.rhs - eq.lhs
Expand Down Expand Up @@ -218,7 +218,7 @@ end
=#

function tearing_reassemble(state::TearingState, var_eq_matching;
simplify = false, mm = nothing)
simplify = false, mm = nothing)
@unpack fullvars, sys, structure = state
@unpack solvable_graph, var_to_diff, eq_to_diff, graph = structure

Expand Down Expand Up @@ -584,7 +584,7 @@ new residual equations after tearing. End users are encouraged to call [`structu
instead, which calls this function internally.
"""
function tearing(sys::AbstractSystem, state = TearingState(sys); mm = nothing,
simplify = false, kwargs...)
simplify = false, kwargs...)
var_eq_matching = tearing(state)
invalidate_cache!(tearing_reassemble(state, var_eq_matching; mm, simplify))
end
Expand All @@ -608,7 +608,7 @@ Perform index reduction and use the dummy derivative technique to ensure that
the system is balanced.
"""
function dummy_derivative(sys, state = TearingState(sys); simplify = false,
mm = nothing, kwargs...)
mm = nothing, kwargs...)
jac = let state = state
(eqs, vars) -> begin
symeqs = EquationsView(state)[eqs]
Expand Down
Loading

0 comments on commit 0d8ab97

Please sign in to comment.