diff --git a/ext/MTKBifurcationKitExt.jl b/ext/MTKBifurcationKitExt.jl index 34a22d8a51..fbaf8e44a8 100644 --- a/ext/MTKBifurcationKitExt.jl +++ b/ext/MTKBifurcationKitExt.jl @@ -34,11 +34,11 @@ struct ObservableRecordFromSolution{S, T} param_end_idxs = state_end_idxs + length(parameters(nsys)) bif_par_idx = state_end_idxs + bif_idx - # Gets the (base) substitution values for states. + # Gets the (base) substitution values for states. subs_vals_states = Pair.(states(nsys), u0_vals) - # Gets the (base) substitution values for parameters. + # Gets the (base) substitution values for parameters. subs_vals_params = Pair.(parameters(nsys), p_vals) - # Gets the (base) substitution values for observables. + # Gets the (base) substitution values for observables. subs_vals_obs = [obs.lhs => substitute(obs.rhs, [subs_vals_states; subs_vals_params]) for obs in observed(nsys)] # Sometimes observables depend on other observables, hence we make a second update to this vector. @@ -136,7 +136,7 @@ function BifurcationKit.BifurcationProblem(osys::ODESystem, args...; kwargs...) nsys = NonlinearSystem([0 ~ eq.rhs for eq in equations(osys)], states(osys), parameters(osys); - name = osys.name) + name = nameof(osys)) return BifurcationKit.BifurcationProblem(nsys, args...; kwargs...) end diff --git a/src/parameters.jl b/src/parameters.jl index ec2b8a8845..19c225b877 100644 --- a/src/parameters.jl +++ b/src/parameters.jl @@ -102,7 +102,7 @@ function split_parameters_by_type(ps) split_ps = tighten_types.(Base.Fix1(getindex, ps).(split_idxs)) if ps isa StaticArray - parrs = map(x-> SArray{Tuple{size(x)...}}(x), split_ps) + parrs = map(x -> SArray{Tuple{size(x)...}}(x), split_ps) split_ps = SArray{Tuple{size(parrs)...}}(parrs) end if length(split_ps) == 1 #Tuple not needed, only 1 type diff --git a/src/systems/abstractsystem.jl b/src/systems/abstractsystem.jl index 7406a5746f..2c9f1884fa 100644 --- a/src/systems/abstractsystem.jl +++ b/src/systems/abstractsystem.jl @@ -194,7 +194,8 @@ end function SymbolicIndexingInterface.is_variable(sys::AbstractSystem, sym::Symbol) return any(isequal(sym), getname.(variable_symbols(sys))) || count('₊', string(sym)) == 1 && - count(isequal(sym), Symbol.(sys.name, :₊, getname.(variable_symbols(sys)))) == 1 + count(isequal(sym), Symbol.(nameof(sys), :₊, getname.(variable_symbols(sys)))) == + 1 end function SymbolicIndexingInterface.variable_index(sys::AbstractSystem, sym) @@ -213,7 +214,8 @@ function SymbolicIndexingInterface.variable_index(sys::AbstractSystem, sym::Symb if idx !== nothing return idx elseif count('₊', string(sym)) == 1 - return findfirst(isequal(sym), Symbol.(sys.name, :₊, getname.(variable_symbols(sys)))) + return findfirst(isequal(sym), + Symbol.(nameof(sys), :₊, getname.(variable_symbols(sys)))) end return nothing end @@ -236,7 +238,8 @@ end function SymbolicIndexingInterface.is_parameter(sys::AbstractSystem, sym::Symbol) return any(isequal(sym), getname.(parameter_symbols(sys))) || count('₊', string(sym)) == 1 && - count(isequal(sym), Symbol.(sys.name, :₊, getname.(parameter_symbols(sys)))) == 1 + count(isequal(sym), + Symbol.(nameof(sys), :₊, getname.(parameter_symbols(sys)))) == 1 end function SymbolicIndexingInterface.parameter_index(sys::AbstractSystem, sym) @@ -255,7 +258,8 @@ function SymbolicIndexingInterface.parameter_index(sys::AbstractSystem, sym::Sym if idx !== nothing return idx elseif count('₊', string(sym)) == 1 - return findfirst(isequal(sym), Symbol.(sys.name, :₊, getname.(parameter_symbols(sys)))) + return findfirst(isequal(sym), + Symbol.(nameof(sys), :₊, getname.(parameter_symbols(sys)))) end return nothing end @@ -656,7 +660,7 @@ function states(sys::AbstractSystem) end isempty(nonunique_states) && return nonunique_states # `Vector{Any}` is incompatible with the `SymbolicIndexingInterface`, which uses - # `elsymtype = symbolic_type(eltype(_arg))` + # `elsymtype = symbolic_type(eltype(_arg))` # which inappropriately returns `NotSymbolic()` if nonunique_states isa Vector{Any} nonunique_states = _nonum.(nonunique_states) diff --git a/src/systems/diffeqs/abstractodesystem.jl b/src/systems/diffeqs/abstractodesystem.jl index d9ca7b6552..88a1ed9bb3 100644 --- a/src/systems/diffeqs/abstractodesystem.jl +++ b/src/systems/diffeqs/abstractodesystem.jl @@ -912,7 +912,10 @@ function DiffEqBase.ODEProblem(sys::AbstractODESystem, args...; kwargs...) ODEProblem{true}(sys, args...; kwargs...) end -function DiffEqBase.ODEProblem(sys::AbstractODESystem, u0map::StaticArray, args...; kwargs...) +function DiffEqBase.ODEProblem(sys::AbstractODESystem, + u0map::StaticArray, + args...; + kwargs...) ODEProblem{false, SciMLBase.FullSpecialize}(sys, u0map, args...; kwargs...) end diff --git a/src/variables.jl b/src/variables.jl index 8e30521ec9..964eaa7859 100644 --- a/src/variables.jl +++ b/src/variables.jl @@ -84,8 +84,6 @@ function varmap_to_vars(varmap, varlist; defaults = Dict(), check = true, container_type = Array end - @show container_type - vals = if eltype(varmap) <: Pair # `varmap` is a dict or an array of pairs varmap = todict(varmap) _varmap_to_vars(varmap, varlist; defaults = defaults, check = check, diff --git a/test/inversemodel.jl b/test/inversemodel.jl index 0d18e899aa..9fcbcc158a 100644 --- a/test/inversemodel.jl +++ b/test/inversemodel.jl @@ -145,7 +145,7 @@ sol = solve(prob, Rodas5P()) # plot(sol, idxs=[model.tank.xc, model.tank.xT, model.controller.ctr_output.u], layout=3, sp=[1 2 3]) # hline!([prob[cm.ref.k]], label="ref", sp=1) -@test sol(tspan[2], idxs = cm.tank.xc)≈ getp(prob, cm.ref.k)(prob) atol=1e-2 # Test that the inverse model led to the correct reference +@test sol(tspan[2], idxs = cm.tank.xc)≈getp(prob, cm.ref.k)(prob) atol=1e-2 # Test that the inverse model led to the correct reference Sf, simplified_sys = Blocks.get_sensitivity_function(model, :y) # This should work without providing an operating opint containing a dummy derivative x, p = ModelingToolkit.get_u0_p(simplified_sys, op) diff --git a/test/symbolic_indexing_interface.jl b/test/symbolic_indexing_interface.jl index 2acb04c986..3d0ab8f7c1 100644 --- a/test/symbolic_indexing_interface.jl +++ b/test/symbolic_indexing_interface.jl @@ -8,11 +8,13 @@ eqs = [D(x) ~ a * y + t, D(y) ~ b * t] @test all(is_variable.((odesys,), [x, y, 1, 2, :x, :y])) @test all(.!is_variable.((odesys,), [a, b, t, 3, 0, :a, :b])) -@test variable_index.((odesys,), [x, y, a, b, t, 1, 2, :x, :y, :a, :b]) == [1, 2, nothing, nothing, nothing, 1, 2, 1, 2, nothing, nothing] +@test variable_index.((odesys,), [x, y, a, b, t, 1, 2, :x, :y, :a, :b]) == + [1, 2, nothing, nothing, nothing, 1, 2, 1, 2, nothing, nothing] @test isequal(variable_symbols(odesys), [x, y]) @test all(is_parameter.((odesys,), [a, b, 1, 2, :a, :b])) @test all(.!is_parameter.((odesys,), [x, y, t, 3, 0, :x, :y])) -@test parameter_index.((odesys,), [x, y, a, b, t, 1, 2, :x, :y, :a, :b]) == [nothing, nothing, 1, 2, nothing, 1, 2, nothing, nothing, 1, 2] +@test parameter_index.((odesys,), [x, y, a, b, t, 1, 2, :x, :y, :a, :b]) == + [nothing, nothing, 1, 2, nothing, 1, 2, nothing, nothing, 1, 2] @test isequal(parameter_symbols(odesys), [a, b]) @test all(is_independent_variable.((odesys,), [t, :t])) @test all(.!is_independent_variable.((odesys,), [x, y, a, :x, :y, :a])) @@ -23,10 +25,10 @@ eqs = [D(x) ~ a * y + t, D(y) ~ b * t] @variables x y z @parameters σ ρ β -eqs = [0 ~ σ*(y-x), - 0 ~ x*(ρ-z)-y, - 0 ~ x*y - β*z] -@named ns = NonlinearSystem(eqs, [x,y,z],[σ,ρ,β]) +eqs = [0 ~ σ * (y - x), + 0 ~ x * (ρ - z) - y, + 0 ~ x * y - β * z] +@named ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β]) @test !is_time_dependent(ns) @@ -37,20 +39,20 @@ Dtt = Differential(t)^2 Dt = Differential(t) #2D PDE -C=1 -eq = Dtt(u(t,x)) ~ C^2*Dxx(u(t,x)) +C = 1 +eq = Dtt(u(t, x)) ~ C^2 * Dxx(u(t, x)) # Initial and boundary conditions -bcs = [u(t,0) ~ 0.,# for all t > 0 - u(t,1) ~ 0.,# for all t > 0 - u(0,x) ~ x*(1. - x), #for all 0 < x < 1 - Dt(u(0,x)) ~ 0. ] #for all 0 < x < 1] +bcs = [u(t, 0) ~ 0.0,# for all t > 0 + u(t, 1) ~ 0.0,# for all t > 0 + u(0, x) ~ x * (1.0 - x), #for all 0 < x < 1 + Dt(u(0, x)) ~ 0.0] #for all 0 < x < 1] # Space and time domains -domains = [t ∈ (0.0,1.0), - x ∈ (0.0,1.0)] +domains = [t ∈ (0.0, 1.0), + x ∈ (0.0, 1.0)] -@named pde_system = PDESystem(eq,bcs,domains,[t,x],[u]) +@named pde_system = PDESystem(eq, bcs, domains, [t, x], [u]) @test pde_system.ps == SciMLBase.NullParameters() @test parameter_symbols(pde_system) == []