@@ -7,7 +7,7 @@ ModelingToolkit component or connector with metadata
77$(FIELDS)
88"""
99struct Model{F, S}
10- """ The constructor that returns ODESystem ."""
10+ """ The constructor that returns System ."""
1111 f:: F
1212 """
1313 The dictionary with metadata like keyword arguments (:kwargs), base
@@ -29,8 +29,8 @@ Base.parentmodule(m::Model) = parentmodule(m.f)
2929for f in (:connector , :mtkmodel )
3030 isconnector = f == :connector ? true : false
3131 @eval begin
32- macro $f (name :: Symbol , body)
33- esc ($ (:_model_macro )(__module__, name , body, $ isconnector))
32+ macro $f (fullname :: Union{Expr, Symbol} , body)
33+ esc ($ (:_model_macro )(__module__, fullname , body, $ isconnector))
3434 end
3535 end
3636end
@@ -41,7 +41,16 @@ function flatten_equations(eqs::Vector{Union{Equation, Vector{Equation}}})
4141 foldl (flatten_equations, eqs; init = Equation[])
4242end
4343
44- function _model_macro (mod, name, expr, isconnector)
44+ function _model_macro (mod, fullname:: Union{Expr, Symbol} , expr, isconnector)
45+ if fullname isa Symbol
46+ name, type = fullname, :System
47+ else
48+ if fullname. head == :(:: )
49+ name, type = fullname. args
50+ else
51+ error (" `$fullname ` is not a valid name." )
52+ end
53+ end
4554 exprs = Expr (:block )
4655 dict = Dict {Symbol, Any} (
4756 :constants => Dict {Symbol, Dict} (),
@@ -61,7 +70,9 @@ function _model_macro(mod, name, expr, isconnector)
6170
6271 push! (exprs. args, :(variables = []))
6372 push! (exprs. args, :(parameters = []))
64- push! (exprs. args, :(systems = ODESystem[]))
73+ # We build `System` by default; vectors can't be created for `System` as it is
74+ # a function.
75+ push! (exprs. args, :(systems = ModelingToolkit. AbstractSystem[]))
6576 push! (exprs. args, :(equations = Union{Equation, Vector{Equation}}[]))
6677 push! (exprs. args, :(defaults = Dict {Num, Union{Number, Symbol, Function}} ()))
6778
@@ -114,7 +125,7 @@ function _model_macro(mod, name, expr, isconnector)
114125 @inline pop_structure_dict! .(
115126 Ref (dict), [:constants , :defaults , :kwargs , :structural_parameters ])
116127
117- sys = :($ ODESystem ($ (flatten_equations)(equations), $ iv, variables, parameters;
128+ sys = :($ type ($ (flatten_equations)(equations), $ iv, variables, parameters;
118129 name, description = $ description, systems, gui_metadata = $ gui_metadata, defaults))
119130
120131 if length (ext) == 0
0 commit comments