Skip to content

Commit 6482c4d

Browse files
YingboMashashi
andcommitted
add connection_type for other systems, too
Co-authored-by: "Shashi Gowda" <gowda@mit.edu>
1 parent ff2a250 commit 6482c4d

File tree

6 files changed

+44
-13
lines changed

6 files changed

+44
-13
lines changed

examples/electrical_components.jl

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ using ModelingToolkit, OrdinaryDiffEq
88
ODESystem(Equation[], t, [v, i], [], name=name, defaults=[v=>1.0, i=>1.0])
99
end
1010

11-
# level-1
1211
function ModelingToolkit.connect(::Type{Pin}, ps...)
1312
eqs = [
1413
0 ~ sum(p->p.i, ps) # KCL

src/systems/diffeqs/sdesystem.jl

+8-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ struct SDESystem <: AbstractODESystem
7171
parameters are not supplied in `ODEProblem`.
7272
"""
7373
defaults::Dict
74+
"""
75+
type: type of the system
76+
"""
77+
connection_type::Any
7478
end
7579

7680
function SDESystem(deqs::AbstractVector{<:Equation}, neqs, iv, dvs, ps;
@@ -79,7 +83,9 @@ function SDESystem(deqs::AbstractVector{<:Equation}, neqs, iv, dvs, ps;
7983
default_u0=Dict(),
8084
default_p=Dict(),
8185
defaults=_merge(Dict(default_u0), Dict(default_p)),
82-
name = gensym(:SDESystem))
86+
name = gensym(:SDESystem)
87+
connection_type=nothing,
88+
)
8389
iv′ = value(iv)
8490
dvs′ = value.(dvs)
8591
ps′ = value.(ps)
@@ -94,7 +100,7 @@ function SDESystem(deqs::AbstractVector{<:Equation}, neqs, iv, dvs, ps;
94100
jac = RefValue{Any}(Matrix{Num}(undef, 0, 0))
95101
Wfact = RefValue(Matrix{Num}(undef, 0, 0))
96102
Wfact_t = RefValue(Matrix{Num}(undef, 0, 0))
97-
SDESystem(deqs, neqs, iv′, dvs′, ps′, observed, tgrad, jac, Wfact, Wfact_t, name, systems, defaults)
103+
SDESystem(deqs, neqs, iv′, dvs′, ps′, observed, tgrad, jac, Wfact, Wfact_t, name, systems, defaults, connection_type)
98104
end
99105

100106
function generate_diffusion_function(sys::SDESystem, dvs = states(sys), ps = parameters(sys); kwargs...)

src/systems/jumps/jumpsystem.jl

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractSystem
4747
parameters are not supplied in `ODEProblem`.
4848
"""
4949
defaults::Dict
50+
"""
51+
type: type of the system
52+
"""
53+
connection_type::Any
5054
end
5155

5256
function JumpSystem(eqs, iv, states, ps;
@@ -55,7 +59,9 @@ function JumpSystem(eqs, iv, states, ps;
5559
default_u0=Dict(),
5660
default_p=Dict(),
5761
defaults=_merge(Dict(default_u0), Dict(default_p)),
58-
name = gensym(:JumpSystem))
62+
name = gensym(:JumpSystem)
63+
connection_type=nothing,
64+
)
5965

6066
ap = ArrayPartition(MassActionJump[], ConstantRateJump[], VariableRateJump[])
6167
for eq in eqs
@@ -75,7 +81,7 @@ function JumpSystem(eqs, iv, states, ps;
7581
defaults = todict(defaults)
7682
defaults = Dict(value(k) => value(v) for (k, v) in pairs(defaults))
7783

78-
JumpSystem{typeof(ap)}(ap, value(iv), value.(states), value.(ps), observed, name, systems, defaults)
84+
JumpSystem{typeof(ap)}(ap, value(iv), value.(states), value.(ps), observed, name, systems, defaults, connection_type)
7985
end
8086

8187
function generate_rate_function(js, rate)

src/systems/nonlinear/nonlinearsystem.jl

+10-4
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,27 @@ struct NonlinearSystem <: AbstractSystem
4343
structure: structural information of the system
4444
"""
4545
structure::Any
46+
"""
47+
type: type of the system
48+
"""
49+
connection_type::Any
4650
end
4751

4852
function NonlinearSystem(eqs, states, ps;
49-
observed = [],
50-
name = gensym(:NonlinearSystem),
53+
observed=[],
54+
name=gensym(:NonlinearSystem),
5155
default_u0=Dict(),
5256
default_p=Dict(),
5357
defaults=_merge(Dict(default_u0), Dict(default_p)),
54-
systems = NonlinearSystem[])
58+
systems=NonlinearSystem[],
59+
connection_type=nothing,
60+
)
5561
if !(isempty(default_u0) && isempty(default_p))
5662
Base.depwarn("`default_u0` and `default_p` are deprecated. Use `defaults` instead.", :NonlinearSystem, force=true)
5763
end
5864
defaults = todict(defaults)
5965
defaults = Dict(value(k) => value(v) for (k, v) in pairs(defaults))
60-
NonlinearSystem(eqs, value.(states), value.(ps), observed, name, systems, defaults, nothing)
66+
NonlinearSystem(eqs, value.(states), value.(ps), observed, name, systems, defaults, nothing, connection_type)
6167
end
6268

6369
function calculate_jacobian(sys::NonlinearSystem;sparse=false,simplify=false)

src/systems/pde/pdesystem.jl

+10-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,16 @@ struct PDESystem <: ModelingToolkit.AbstractSystem
5252
parameters are not supplied in `ODEProblem`.
5353
"""
5454
defaults::Dict
55-
@add_kwonly function PDESystem(eqs, bcs, domain, indvars, depvars, ps = SciMLBase.NullParameters(), defaults = Dict())
56-
new(eqs, bcs, domain, indvars, depvars, ps, defaults)
55+
"""
56+
type: type of the system
57+
"""
58+
connection_type::Any
59+
@add_kwonly function PDESystem(eqs, bcs, domain, indvars, depvars,
60+
ps=SciMLBase.NullParameters();
61+
defaults=Dict(),
62+
connection_type=nothing,
63+
)
64+
new(eqs, bcs, domain, indvars, depvars, ps, defaults, connection_type)
5765
end
5866
end
5967

src/systems/reaction/reactionsystem.jl

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,16 @@ struct Reaction{S, T <: Number}
6060
`true` if `rate` represents the full reaction rate law.
6161
"""
6262
only_use_rate::Bool
63+
"""
64+
type: type of the system
65+
"""
66+
connection_type::Any
6367
end
6468

6569
function Reaction(rate, subs, prods, substoich, prodstoich;
66-
netstoich=nothing, only_use_rate=false, kwargs...)
70+
netstoich=nothing, only_use_rate=false,
71+
connection_type=nothing,
72+
kwargs...)
6773

6874
(isnothing(prods)&&isnothing(subs)) && error("A reaction requires a non-nothing substrate or product vector.")
6975
(isnothing(prodstoich)&&isnothing(substoich)) && error("Both substrate and product stochiometry inputs cannot be nothing.")
@@ -80,7 +86,7 @@ function Reaction(rate, subs, prods, substoich, prodstoich;
8086
subs = value.(subs)
8187
prods = value.(prods)
8288
ns = isnothing(netstoich) ? get_netstoich(subs, prods, substoich, prodstoich) : netstoich
83-
Reaction(value(rate), subs, prods, substoich, prodstoich, ns, only_use_rate)
89+
Reaction(value(rate), subs, prods, substoich, prodstoich, ns, only_use_rate, connection_type)
8490
end
8591

8692

0 commit comments

Comments
 (0)