Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacsas committed Dec 30, 2023
1 parent 4792076 commit 55d95ae
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 105 in src/parameters.jl

View check run for this annotation

Codecov / codecov/patch

src/parameters.jl#L105

Added line #L105 was not covered by tests
split_ps = SArray{Tuple{size(parrs)...}}(parrs)
end
if length(split_ps) == 1 #Tuple not needed, only 1 type
Expand Down
12 changes: 8 additions & 4 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.(nameof(sys), :₊, getname.(variable_symbols(sys)))) == 1
count(isequal(sym), Symbol.(nameof(sys), :₊, getname.(variable_symbols(sys)))) ==
1
end

function SymbolicIndexingInterface.variable_index(sys::AbstractSystem, sym)
Expand All @@ -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.(nameof(sys), :₊, getname.(variable_symbols(sys))))
return findfirst(isequal(sym),

Check warning on line 217 in src/systems/abstractsystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/abstractsystem.jl#L217

Added line #L217 was not covered by tests
Symbol.(nameof(sys), :₊, getname.(variable_symbols(sys))))
end
return nothing
end
Expand All @@ -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.(nameof(sys), :₊, getname.(parameter_symbols(sys)))) == 1
count(isequal(sym),
Symbol.(nameof(sys), :₊, getname.(parameter_symbols(sys)))) == 1
end

function SymbolicIndexingInterface.parameter_index(sys::AbstractSystem, sym)
Expand All @@ -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.(nameof(sys), :₊, getname.(parameter_symbols(sys))))
return findfirst(isequal(sym),

Check warning on line 261 in src/systems/abstractsystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/abstractsystem.jl#L261

Added line #L261 was not covered by tests
Symbol.(nameof(sys), :₊, getname.(parameter_symbols(sys))))
end
return nothing
end
Expand Down
5 changes: 4 additions & 1 deletion src/systems/diffeqs/abstractodesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check warning on line 915 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L915

Added line #L915 was not covered by tests
u0map::StaticArray,
args...;
kwargs...)
ODEProblem{false, SciMLBase.FullSpecialize}(sys, u0map, args...; kwargs...)
end

Expand Down
2 changes: 1 addition & 1 deletion test/inversemodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 17 additions & 15 deletions test/symbolic_indexing_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand All @@ -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)

Expand All @@ -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) == []
Expand Down

0 comments on commit 55d95ae

Please sign in to comment.