@@ -7,7 +7,7 @@ ModelingToolkit component or connector with metadata
7
7
$(FIELDS)
8
8
"""
9
9
struct Model{F, S}
10
- """ The constructor that returns ODESystem ."""
10
+ """ The constructor that returns System ."""
11
11
f:: F
12
12
"""
13
13
The dictionary with metadata like keyword arguments (:kwargs), base
@@ -29,8 +29,8 @@ Base.parentmodule(m::Model) = parentmodule(m.f)
29
29
for f in (:connector , :mtkmodel )
30
30
isconnector = f == :connector ? true : false
31
31
@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))
34
34
end
35
35
end
36
36
end
@@ -41,7 +41,16 @@ function flatten_equations(eqs::Vector{Union{Equation, Vector{Equation}}})
41
41
foldl (flatten_equations, eqs; init = Equation[])
42
42
end
43
43
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
45
54
exprs = Expr (:block )
46
55
dict = Dict {Symbol, Any} (
47
56
:constants => Dict {Symbol, Dict} (),
@@ -61,7 +70,9 @@ function _model_macro(mod, name, expr, isconnector)
61
70
62
71
push! (exprs. args, :(variables = []))
63
72
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[]))
65
76
push! (exprs. args, :(equations = Union{Equation, Vector{Equation}}[]))
66
77
push! (exprs. args, :(defaults = Dict {Num, Union{Number, Symbol, Function}} ()))
67
78
@@ -114,7 +125,7 @@ function _model_macro(mod, name, expr, isconnector)
114
125
@inline pop_structure_dict! .(
115
126
Ref (dict), [:constants , :defaults , :kwargs , :structural_parameters ])
116
127
117
- sys = :($ ODESystem ($ (flatten_equations)(equations), $ iv, variables, parameters;
128
+ sys = :($ type ($ (flatten_equations)(equations), $ iv, variables, parameters;
118
129
name, description = $ description, systems, gui_metadata = $ gui_metadata, defaults))
119
130
120
131
if length (ext) == 0
0 commit comments