| 
73 | 73 |         v_array(t)[1:N, 1:M]  | 
74 | 74 |         v_for_defaults(t)  | 
75 | 75 |     end  | 
76 |  | -    @extend ModelB(; p1)  | 
 | 76 | +    @extend ModelB(p1 = 1)  | 
77 | 77 |     @components begin  | 
78 | 78 |         model_a = ModelA(; k_array)  | 
79 | 79 |         model_array_a = [ModelA(; k = i) for i in 1:N]  | 
@@ -149,14 +149,18 @@ julia> ModelingToolkit.getdefault(model_c1.v)  | 
149 | 149 | 
 
  | 
150 | 150 | #### `@extend` begin block  | 
151 | 151 | 
 
  | 
152 |  | -  - Partial systems can be extended in a higher system as `@extend PartialSystem(; kwargs)`.  | 
153 |  | -  - Keyword arguments pf partial system in the `@extend` definition are added as the keyword arguments of the base system.  | 
154 |  | -  - Note that in above example, `p1` is promoted as an argument of `ModelC`. Users can set the value of `p1`. However, as `p2` isn't listed in the model definition, its initial guess can't be specified while creating an instance of `ModelC`.  | 
 | 152 | +Partial systems can be extended in a higher system in two ways:  | 
155 | 153 | 
 
  | 
156 |  | -```julia  | 
157 |  | -julia> @mtkbuild model_c2 = ModelC(; p1 = 2.0)  | 
 | 154 | +  - `@extend PartialSystem(var1 = value1)`  | 
 | 155 | +      | 
 | 156 | +      + This is the recommended way of extending a base system.  | 
 | 157 | +      + The default values for the arguments of the base system can be declared in the `@extend` statement.  | 
 | 158 | +      + Note that all keyword arguments of the base system are added as the keyword arguments of the main system.  | 
158 | 159 | 
 
  | 
159 |  | -```  | 
 | 160 | +  - `@extend var_to_unpack1, var_to_unpack2 = partial_sys = PartialSystem(var1 = value1)`  | 
 | 161 | +      | 
 | 162 | +      + In this method: explicitly list the variables that should be unpacked, provide a name for the partial system and declare the base system.  | 
 | 163 | +      + Note that only the arguments listed out in the declaration of the base system (here: `var1`) are added as the keyword arguments of the higher system.  | 
160 | 164 | 
 
  | 
161 | 165 | #### `@components` begin block  | 
162 | 166 | 
 
  | 
@@ -325,11 +329,11 @@ For example, the structure of `ModelC` is:  | 
325 | 329 | julia> ModelC.structure  | 
326 | 330 | Dict{Symbol, Any} with 10 entries:  | 
327 | 331 |   :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)]]  | 
328 |  | -  :variables             => Dict{Symbol, Dict{Symbol, Any}}(:v=>Dict(:default=>:v_var, :type=>Real), :v_for_defaults=>Dict(:type=>Real))  | 
 | 332 | +  :variables             => Dict{Symbol, Dict{Symbol, Any}}(:v=>Dict(:default=>:v_var, :type=>Real), :v_array=>Dict(:value=>nothing, :type=>Real, :size=>(:N, :M)), :v_for_defaults=>Dict(:type=>Real))  | 
329 | 333 |   :icon                  => URI("https://github.com/SciML/SciMLDocs/blob/main/docs/src/assets/logo.png")  | 
330 |  | -  :kwargs                => Dict{Symbol, Dict}(:f => Dict(:value => :sin), :N => Dict(:value => 2), :M => Dict(:value => 3), :v => Dict{Symbol, Any}(:value => :v_var, :type => Real), :v_for_defaults => Dict{Symbol, Union{Nothing, DataType}}(:value => nothing, :type => Real), :p1 => Dict(:value => nothing)),  | 
331 |  | -  :structural_parameters => Dict{Symbol, Dict}(:f => Dict(:value => :sin), :N => Dict(:value => 2), :M => Dict(:value => 3))  | 
332 |  | -  :independent_variable  => t  | 
 | 334 | +  :kwargs                => Dict{Symbol, Dict}(:f=>Dict(:value=>:sin), :p2=>Dict(:value=>NoValue()), :N=>Dict(:value=>2), :M=>Dict(:value=>3), :v=>Dict{Symbol, Any}(:value=>:v_var, :type=>Real), :v_array=>Dict{Symbol, Any}(:value=>nothing, :type=>Real, :size=>(:N, :M)), :v_for_defaults=>Dict{Symbol, Union{Nothing, DataType}}(:value=>nothing, :type=>Real), :p1=>Dict(:value=>1))  | 
 | 335 | +  :structural_parameters => Dict{Symbol, Dict}(:f=>Dict(:value=>:sin), :N=>Dict(:value=>2), :M=>Dict(:value=>3))  | 
 | 336 | +  :independent_variable  => :t  | 
333 | 337 |   :constants             => Dict{Symbol, Dict}(:c=>Dict{Symbol, Any}(:value=>1, :type=>Int64, :description=>"Example constant."))  | 
334 | 338 |   :extend                => Any[[:p2, :p1], Symbol("#mtkmodel__anonymous__ModelB"), :ModelB]  | 
335 | 339 |   :defaults              => Dict{Symbol, Any}(:v_for_defaults=>2.0)  | 
 | 
0 commit comments