Skip to content

Commit

Permalink
docs: add component array in the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ven-k committed Dec 4, 2023
1 parent 4a5b646 commit 26097d3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions docs/src/basics/MTKModel_Connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ end
@extend ModelB(; p1)
@components begin
model_a = ModelA(; k_array)
model_array_a = [Model_A(; k = i) for in in 1:N]
model_array_b = for i in 1:N
k = i^2
Model_A(; k)
end
end
@equations begin
model_a.k ~ f(v)
Expand Down Expand Up @@ -136,6 +141,7 @@ julia> @mtkbuild model_c2 = ModelC(; p1 = 2.0)
#### `@components` begin block

- Declare the subcomponents within `@components` begin block.
- Array of components can be declared with a for loop or a list comprehension.
- The arguments in these subcomponents are promoted as keyword arguments as `subcomponent_name__argname` with `nothing` as default value.
- Whenever components are created with `@named` macro, these can be accessed with `.` operator as `subcomponent_name.argname`
- 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:
Expand Down Expand Up @@ -243,10 +249,10 @@ For example, the structure of `ModelC` is:
```julia
julia> ModelC.structure
Dict{Symbol, Any} with 7 entries:
:components => [[:model_a, :ModelA]]
:components => Vector{Union{Expr, Symbol}}[[:model_a, :ModelA], [:model_array_a, :Model_A, :(1:N)], [:model_array_b, :Model_A, :(1:N)]]
:variables => Dict{Symbol, Dict{Symbol, Any}}(:v=>Dict(:default=>:v_var), :v_array=>Dict(:size=>(2, 3)))
:icon => URI("https://github.com/SciML/SciMLDocs/blob/main/docs/src/assets/logo.png")
:kwargs => Dict{Symbol, Any}(:f=>:sin, :v=>:v_var, :v_array=>nothing, :model_a__k_array=>nothing, :p1=>nothing)
:kwargs => Dict{Symbol, Any}(:f=>:sin, :model_array_b__k=>nothing, :v=>:v_var, :v_array=>nothing, :model_a__k_array=>nothing, :model_array_a__k=>nothing, :p1=>nothing)
:independent_variable => t
:extend => Any[[:p2, :p1], Symbol("#mtkmodel__anonymous__ModelB"), :ModelB]
:equations => ["model_a.k ~ f(v)"]
Expand Down

0 comments on commit 26097d3

Please sign in to comment.