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 5, 2023
1 parent 89e99f7 commit d691373
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions docs/src/basics/MTKModel_Connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ end
@icon "https://github.com/SciML/SciMLDocs/blob/main/docs/src/assets/logo.png"
@structural_parameters begin
f = sin
N = 2
end
begin
v_var = 1.0
Expand All @@ -65,6 +66,11 @@ end
@extend ModelB(; p1)
@components begin
model_a = ModelA(; k_array)
model_array_a = [ModelA(; k = i) for i in 1:N]
model_array_b = for i in 1:N
k = i^2
ModelA(; k)
end
end
@equations begin
model_a.k ~ f(v)
Expand Down Expand Up @@ -136,6 +142,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,13 +250,13 @@ For example, the structure of `ModelC` is:
```julia
julia> ModelC.structure
Dict{Symbol, Any} with 7 entries:
:components => [[:model_a, :ModelA]]
: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)]]
: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, :N=>2, :v=>:v_var, :v_array=>nothing, :p1=>nothing)
:independent_variable => t
:extend => Any[[:p2, :p1], Symbol("#mtkmodel__anonymous__ModelB"), :ModelB]
:equations => ["model_a.k ~ f(v)"]
:equations => Any["model_a.k ~ f(v)"]
```

### Using conditional statements
Expand Down

0 comments on commit d691373

Please sign in to comment.