Skip to content

Commit 5fa720c

Browse files
committed
docs: add component array in the docs
1 parent 5317958 commit 5fa720c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

docs/src/basics/MTKModel_Connector.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ end
5454
@icon "https://github.com/SciML/SciMLDocs/blob/main/docs/src/assets/logo.png"
5555
@structural_parameters begin
5656
f = sin
57+
N = 2
5758
end
5859
begin
5960
v_var = 1.0
@@ -65,6 +66,11 @@ end
6566
@extend ModelB(; p1)
6667
@components begin
6768
model_a = ModelA(; k_array)
69+
model_array_a = [ModelA(; k = i) for i in 1:N]
70+
model_array_b = for i in 1:N
71+
k = i^2
72+
ModelA(; k)
73+
end
6874
end
6975
@equations begin
7076
model_a.k ~ f(v)
@@ -136,6 +142,7 @@ julia> @mtkbuild model_c2 = ModelC(; p1 = 2.0)
136142
#### `@components` begin block
137143

138144
- Declare the subcomponents within `@components` begin block.
145+
- Array of components can be declared with a for loop or a list comprehension.
139146
- The arguments in these subcomponents are promoted as keyword arguments as `subcomponent_name__argname` with `nothing` as default value.
140147
- Whenever components are created with `@named` macro, these can be accessed with `.` operator as `subcomponent_name.argname`
141148
- In the above example, as `k` of `model_a` isn't listed while defining the sub-component in `ModelC`, its default value can't be modified by users. While `k_array` can be set as:
@@ -243,13 +250,13 @@ For example, the structure of `ModelC` is:
243250
```julia
244251
julia> ModelC.structure
245252
Dict{Symbol, Any} with 7 entries:
246-
:components => [[:model_a, :ModelA]]
253+
:components => Any[Union{Expr, Symbol}[:model_a, :ModelA], Union{Expr, Symbol}[:model_array_a, :ModelA, :(1:N)], Union{Expr, Symbol}[:model_array_b, :ModelA, :(1:N)]]
247254
:variables => Dict{Symbol, Dict{Symbol, Any}}(:v=>Dict(:default=>:v_var), :v_array=>Dict(:size=>(2, 3)))
248255
:icon => URI("https://github.com/SciML/SciMLDocs/blob/main/docs/src/assets/logo.png")
249-
:kwargs => Dict{Symbol, Any}(:f=>:sin, :v=>:v_var, :v_array=>nothing, :model_a__k_array=>nothing, :p1=>nothing)
256+
:kwargs => Dict{Symbol, Any}(:f=>:sin, :N=>2, :v=>:v_var, :v_array=>nothing, :p1=>nothing)
250257
:independent_variable => t
251258
:extend => Any[[:p2, :p1], Symbol("#mtkmodel__anonymous__ModelB"), :ModelB]
252-
:equations => ["model_a.k ~ f(v)"]
259+
:equations => Any["model_a.k ~ f(v)"]
253260
```
254261

255262
### Using conditional statements

0 commit comments

Comments
 (0)