Skip to content

Commit 44a9776

Browse files
committed
fix: add the structural_parameters metadata to the model structure.
1 parent 9024cc6 commit 44a9776

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

docs/src/basics/MTKModel_Connector.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ end
220220
```
221221

222222
!!! note
223-
223+
224224
For more examples of usage, checkout [ModelingToolkitStandardLibrary.jl](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/)
225225

226226
## More on `Model.structure`
@@ -229,7 +229,7 @@ end
229229

230230
- `:components`: List of sub-components in the form of [[name, sub_component_name],...].
231231
- `:extend`: The list of extended unknowns, name given to the base system, and name of the base system.
232-
- `:structural_parameters`: Dictionary of structural parameters mapped to their default values.
232+
- `:structural_parameters`: Dictionary of structural parameters mapped to their metadata.
233233
- `:parameters`: Dictionary of symbolic parameters mapped to their metadata. For
234234
parameter arrays, length is added to the metadata as `:size`.
235235
- `:variables`: Dictionary of symbolic variables mapped to their metadata. For
@@ -243,13 +243,14 @@ For example, the structure of `ModelC` is:
243243
```julia
244244
julia> ModelC.structure
245245
Dict{Symbol, Any} with 7 entries:
246-
:components => [[:model_a, :ModelA]]
247-
:variables => Dict{Symbol, Dict{Symbol, Any}}(:v=>Dict(:default=>:v_var), :v_array=>Dict(:size=>(2, 3)))
248-
:icon => URI("https://github.com/SciML/SciMLDocs/blob/main/docs/src/assets/logo.png")
249-
:kwargs => Dict{Symbol, Dict}(:f=>Dict(:value=>:sin), :v=>Dict{Symbol, Union{Nothing, Symbol}}(:value=>:v_var, :type=>nothing), :v_array=>Dict(:value=>nothing, :type=>nothing), :p1=>Dict(:value=>nothing))
250-
:independent_variable => t
251-
:extend => Any[[:p2, :p1], Symbol("#mtkmodel__anonymous__ModelB"), :ModelB]
252-
:equations => ["model_a.k ~ f(v)"]
246+
:components => [[:model_a, :ModelA]]
247+
:variables => Dict{Symbol, Dict{Symbol, Any}}(:v=>Dict(:default=>:v_var), :v_array=>Dict(:size=>(2, 3)))
248+
:icon => URI("https://github.com/SciML/SciMLDocs/blob/main/docs/src/assets/logo.png")
249+
:kwargs => Dict{Symbol, Dict}(:f=>Dict(:value=>:sin), :v=>Dict{Symbol, Union{Nothing, Symbol}}(:value=>:v_var, :type=>nothing), :v_array=>Dict(:value=>nothing, :type=>nothing), :p1=>Dict(:value=>nothing))
250+
:structural_parameters => Dict{Symbol, Dict}(:f=>Dict(:value=>:sin))
251+
:independent_variable => t
252+
:extend => Any[[:p2, :p1], Symbol("#mtkmodel__anonymous__ModelB"), :ModelB]
253+
:equations => ["model_a.k ~ f(v)"]
253254
```
254255

255256
### Using conditional statements
@@ -322,11 +323,12 @@ The conditional parts are reflected in the `structure`. For `BranchOutsideTheBlo
322323
```julia
323324
julia> BranchOutsideTheBlock.structure
324325
Dict{Symbol, Any} with 5 entries:
325-
:components => Any[(:if, :flag, [[:sys1, :C]], Any[])]
326-
:kwargs => Dict{Symbol, Dict}(:flag=>Dict{Symbol, Bool}(:value=>1))
327-
:independent_variable => t
328-
:parameters => Dict{Symbol, Dict{Symbol, Any}}(:a1=>Dict(:condition=>(:if, :flag, Dict{Symbol, Any}(:kwargs => Dict{Any, Any}(:a1 => nothing), :parameters => Any[Dict{Symbol, Dict{Symbol, Any}}(:a1 => Dict())]), Dict{Symbol, Any}(:kwargs => Dict{Any, Any}(:a2 => nothing), :parameters => Any[Dict{Symbol, Dict{Symbol, Any}}(:a2 => Dict())]))
329-
:equations => Any[(:if, :flag, ["a1 ~ 0"], ["a2 ~ 0"])]
326+
:components => Any[(:if, :flag, [[:sys1, :C]], Any[])]
327+
:kwargs => Dict{Symbol, Dict}(:flag=>Dict{Symbol, Bool}(:value=>1))
328+
:structural_parameters => Dict{Symbol, Dict}(:flag=>Dict{Symbol, Bool}(:value=>1))
329+
:independent_variable => t
330+
:parameters => Dict{Symbol, Dict{Symbol, Any}}(:a1=>Dict(:condition=>(:if, :flag, Dict{Symbol, Any}(:kwargs => Dict{Any, Any}(:a1 => nothing), :parameters => Any[Dict{Symbol, Dict{Symbol, Any}}(:a1 => Dict())]), Dict{Symbol, Any}(:kwargs => Dict{Any, Any}(:a2 => nothing), :parameters => Any[Dict{Symbol, Dict{Symbol, Any}}(:a2 => Dict())]))
331+
:equations => Any[(:if, :flag, ["a1 ~ 0"], ["a2 ~ 0"])]
330332
```
331333
332334
Conditional entries are entered in the format of `(branch, condition, [case when it is true], [case when it is false])`;

src/systems/model_parsing.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function _model_macro(mod, name, expr, isconnector)
3737
exprs = Expr(:block)
3838
dict = Dict{Symbol, Any}(
3939
:kwargs => Dict{Symbol, Dict}(),
40+
:structural_parameters => Dict{Symbol, Dict}()
4041
)
4142
comps = Symbol[]
4243
ext = Ref{Any}(nothing)
@@ -332,17 +333,18 @@ function parse_structural_parameters!(exprs, sps, dict, mod, body, kwargs)
332333
b = _type_check!(Core.eval(mod, b), a, type)
333334
push!(sps, a)
334335
push!(kwargs, Expr(:kw, Expr(:(::), a, type), b))
335-
dict[:kwargs][a] = Dict(:value => b, :type => type)
336+
dict[:structural_parameters][a] = dict[:kwargs][a] = Dict(
337+
:value => b, :type => type)
336338
end
337339
Expr(:(=), a, b) => begin
338340
push!(sps, a)
339341
push!(kwargs, Expr(:kw, a, b))
340-
dict[:kwargs][a] = Dict(:value => b)
342+
dict[:structural_parameters][a] = dict[:kwargs][a] = Dict(:value => b)
341343
end
342344
a => begin
343345
push!(sps, a)
344346
push!(kwargs, a)
345-
dict[:kwargs][a] = Dict(:value => nothing)
347+
dict[:structural_parameters][a] = dict[:kwargs][a] = Dict(:value => nothing)
346348
end
347349
end
348350
end

0 commit comments

Comments
 (0)