|
54 | 54 | @icon "https://github.com/SciML/SciMLDocs/blob/main/docs/src/assets/logo.png"
|
55 | 55 | @structural_parameters begin
|
56 | 56 | f = sin
|
| 57 | + N = 2 |
57 | 58 | end
|
58 | 59 | begin
|
59 | 60 | v_var = 1.0
|
|
65 | 66 | @extend ModelB(; p1)
|
66 | 67 | @components begin
|
67 | 68 | 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 |
68 | 74 | end
|
69 | 75 | @equations begin
|
70 | 76 | model_a.k ~ f(v)
|
@@ -136,6 +142,7 @@ julia> @mtkbuild model_c2 = ModelC(; p1 = 2.0)
|
136 | 142 | #### `@components` begin block
|
137 | 143 |
|
138 | 144 | - Declare the subcomponents within `@components` begin block.
|
| 145 | + - Array of components can be declared with a for loop or a list comprehension. |
139 | 146 | - The arguments in these subcomponents are promoted as keyword arguments as `subcomponent_name__argname` with `nothing` as default value.
|
140 | 147 | - Whenever components are created with `@named` macro, these can be accessed with `.` operator as `subcomponent_name.argname`
|
141 | 148 | - 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:
|
243 | 250 | ```julia
|
244 | 251 | julia> ModelC.structure
|
245 | 252 | 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)]] |
247 | 254 | :variables => Dict{Symbol, Dict{Symbol, Any}}(:v=>Dict(:default=>:v_var), :v_array=>Dict(:size=>(2, 3)))
|
248 | 255 | :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) |
250 | 257 | :independent_variable => t
|
251 | 258 | :extend => Any[[:p2, :p1], Symbol("#mtkmodel__anonymous__ModelB"), :ModelB]
|
252 |
| - :equations => ["model_a.k ~ f(v)"] |
| 259 | + :equations => Any["model_a.k ~ f(v)"] |
253 | 260 | ```
|
254 | 261 |
|
255 | 262 | ### Using conditional statements
|
|
0 commit comments