Skip to content

Commit b6c67ba

Browse files
refactor: format
1 parent cc669c8 commit b6c67ba

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

Diff for: src/ModelingToolkit.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ export structural_simplify, expand_connections, linearize, linearization_functio
303303
LinearizationProblem
304304
export solve
305305

306-
export calculate_jacobian, generate_jacobian, generate_function, generate_custom_function, generate_W
306+
export calculate_jacobian, generate_jacobian, generate_function, generate_custom_function,
307+
generate_W
307308
export calculate_control_jacobian, generate_control_jacobian
308309
export calculate_tgrad, generate_tgrad
309310
export calculate_gradient, generate_gradient

Diff for: src/systems/diffeqs/abstractodesystem.jl

+7-6
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,17 @@ function assert_jac_length_header(sys)
149149
end
150150
end
151151

152-
function generate_W(sys::AbstractODESystem, γ = 1., dvs = unknowns(sys),
153-
ps = parameters(sys; initial_parameters = true);
152+
function generate_W(sys::AbstractODESystem, γ = 1.0, dvs = unknowns(sys),
153+
ps = parameters(sys; initial_parameters = true);
154154
simplify = false, sparse = false, kwargs...)
155155
@variables ˍ₋gamma
156156
M = calculate_massmatrix(sys; simplify)
157157
sparse && (M = SparseArrays.sparse(M))
158158
J = calculate_jacobian(sys; simplify, sparse, dvs)
159-
W = ˍ₋gamma*M + J
159+
W = ˍ₋gamma * M + J
160160

161161
p = reorder_parameters(sys, ps)
162-
return build_function_wrapper(sys, W,
162+
return build_function_wrapper(sys, W,
163163
dvs,
164164
p...,
165165
ˍ₋gamma,
@@ -304,11 +304,12 @@ function jacobian_dae_sparsity(sys::AbstractODESystem)
304304
J1 + J2
305305
end
306306

307-
function W_sparsity(sys::AbstractODESystem)
307+
function W_sparsity(sys::AbstractODESystem)
308308
jac_sparsity = jacobian_sparsity(sys)
309309
(n, n) = size(jac_sparsity)
310310
M = calculate_massmatrix(sys)
311-
M_sparsity = M isa UniformScaling ? sparse(I(n)) : SparseMatrixCSC{Bool, Int64}((!iszero).(M))
311+
M_sparsity = M isa UniformScaling ? sparse(I(n)) :
312+
SparseMatrixCSC{Bool, Int64}((!iszero).(M))
312313
jac_sparsity .| M_sparsity
313314
end
314315

Diff for: test/jacobiansparsity.jl

+6-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ f = DiffEqBase.ODEFunction(sys, u0 = nothing, sparse = true, jac = false)
7474
# test when u0 is not Float64
7575
u0 = similar(init_brusselator_2d(xyd_brusselator), Float32)
7676
prob_ode_brusselator_2d = ODEProblem(brusselator_2d_loop,
77-
u0, (0.0, 11.5), p)
77+
u0, (0.0, 11.5), p)
7878
sys = complete(modelingtoolkitize(prob_ode_brusselator_2d))
7979

8080
prob = ODEProblem(sys, u0, (0, 11.5), sparse = true, jac = false)
@@ -94,7 +94,8 @@ prob = ODEProblem(sys, u0, (0, 11.5), sparse = true, jac = true)
9494
@mtkbuild pend = ODESystem(eqs, t)
9595

9696
u0 = [x => 1, y => 0]
97-
prob = ODEProblem(pend, u0, (0, 11.5), [g => 1], guesses ==> 1], sparse = true, jac = true)
97+
prob = ODEProblem(
98+
pend, u0, (0, 11.5), [g => 1], guesses ==> 1], sparse = true, jac = true)
9899
jac, jac! = generate_jacobian(pend; expression = Val{false}, sparse = true)
99100
jac_prototype = ModelingToolkit.jacobian_sparsity(pend)
100101
W_prototype = ModelingToolkit.W_sparsity(pend)
@@ -109,8 +110,9 @@ prob = ODEProblem(sys, u0, (0, 11.5), sparse = true, jac = true)
109110
@test_throws AssertionError jac!(similar(jac_prototype, Float64), u, p, t)
110111

111112
W, W! = generate_W(pend; expression = Val{false}, sparse = true)
112-
γ = .1
113+
γ = 0.1
113114
M = sparse(calculate_massmatrix(pend))
114115
@test_throws AssertionError W!(similar(jac_prototype, Float64), u, p, γ, t)
115-
@test W!(similar(W_prototype, Float64), u, p, γ, t) == 0.1 * M + jac!(similar(W_prototype, Float64), u, p, t)
116+
@test W!(similar(W_prototype, Float64), u, p, γ, t) ==
117+
0.1 * M + jac!(similar(W_prototype, Float64), u, p, t)
116118
end

0 commit comments

Comments
 (0)