Skip to content

Commit 2d4bf5d

Browse files
committed
Merge remote-tracking branch 'origin' into implicit_discrete_system
Merge master
2 parents af3995c + 0d9fde4 commit 2d4bf5d

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ DataInterpolations = "6.5"
3333
Distributions = "0.25"
3434
Documenter = "1"
3535
DynamicQuantities = "^0.11.2, 0.12, 1"
36+
FMI = "0.14"
37+
FMIZoo = "1"
3638
ModelingToolkit = "8.33, 9"
3739
ModelingToolkitStandardLibrary = "2.19"
3840
NonlinearSolve = "3, 4"

src/discretedomain.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ $(TYPEDEF)
9898
Represents a sample operator. A discrete-time signal is created by sampling a continuous-time signal.
9999
100100
# Constructors
101-
`Sample(clock::Union{TimeDomain, InferredTimeDomain} = InferredDiscrete)`
101+
`Sample(clock::Union{TimeDomain, InferredTimeDomain} = InferredDiscrete())`
102102
`Sample(dt::Real)`
103103
104104
`Sample(x::Num)`, with a single argument, is shorthand for `Sample()(x)`.
@@ -119,7 +119,7 @@ julia> Δ = Sample(0.01)
119119
"""
120120
struct Sample <: Operator
121121
clock::Any
122-
Sample(clock::Union{TimeDomain, InferredTimeDomain} = InferredDiscrete) = new(clock)
122+
Sample(clock::Union{TimeDomain, InferredTimeDomain} = InferredDiscrete()) = new(clock)
123123
end
124124

125125
function Sample(arg::Real)
@@ -203,7 +203,7 @@ struct ShiftIndex
203203
clock::Union{InferredTimeDomain, TimeDomain, IntegerSequence}
204204
steps::Int
205205
function ShiftIndex(
206-
clock::Union{TimeDomain, InferredTimeDomain, IntegerSequence} = Inferred, steps::Int = 0)
206+
clock::Union{TimeDomain, InferredTimeDomain, IntegerSequence} = Inferred(), steps::Int = 0)
207207
new(clock, steps)
208208
end
209209
ShiftIndex(dt::Real, steps::Int = 0) = new(Clock(dt), steps)
@@ -267,7 +267,7 @@ function input_timedomain(h::Hold, arg = nothing)
267267
if has_time_domain(arg)
268268
return get_time_domain(arg)
269269
end
270-
InferredDiscrete # the Hold accepts any discrete
270+
InferredDiscrete() # the Hold accepts any discrete
271271
end
272272
output_timedomain(::Hold, _ = nothing) = ContinuousClock()
273273

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ function NonlinearSystem(eqs; kwargs...)
219219
push!(new_ps, p)
220220
end
221221
else
222+
if symbolic_type(p) == ArraySymbolic() &&
223+
Symbolics.shape(unwrap(p)) != Symbolics.Unknown()
224+
for i in eachindex(p)
225+
delete!(new_ps, p[i])
226+
end
227+
end
222228
push!(new_ps, p)
223229
end
224230
end

test/nonlinearsystem.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using DiffEqBase, SparseArrays
44
using Test
55
using NonlinearSolve
66
using ForwardDiff
7+
using SymbolicIndexingInterface
78
using ModelingToolkit: value
89
using ModelingToolkit: get_default_or_guess, MTKParameters
910

@@ -380,3 +381,12 @@ end
380381
@test_throws ["single equation", "unknown"] IntervalNonlinearFunctionExpr(
381382
sys, (0.0, 1.0))
382383
end
384+
385+
@testset "Vector parameter used unscalarized and partially scalarized" begin
386+
@variables x y
387+
@parameters p[1:2] (f::Function)(..)
388+
389+
@mtkbuild sys = NonlinearSystem([x^2 - p[1]^2 ~ 0, y^2 ~ f(p)])
390+
@test !any(isequal(p[1]), parameters(sys))
391+
@test is_parameter(sys, p)
392+
end

test/scc_nonlinear_problem.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,12 @@ end
282282
sccprob = SCCNonlinearProblem(fullsys, u0, p)
283283
@test isequal(parameters(fullsys), parameters(sccprob.f.sys))
284284
end
285+
286+
@testset "Vector parameters in function arguments" begin
287+
@variables x y
288+
@parameters p[1:2] (f::Function)(..)
289+
290+
@mtkbuild sys = NonlinearSystem([x^2 - p[1]^2 ~ 0, y^2 ~ f(p)])
291+
prob = SCCNonlinearProblem(sys, [x => 1.0, y => 1.0], [p => ones(2), f => sum])
292+
@test_nowarn solve(prob, NewtonRaphson())
293+
end

0 commit comments

Comments
 (0)