Skip to content

Commit e8110d0

Browse files
committed
pass ODESystem kwargs via @mtkmodel constructor
1 parent 1c00326 commit e8110d0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/systems/model_parsing.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ function _model_macro(mod, name, expr, isconnector)
115115
Ref(dict), [:constants, :defaults, :kwargs, :structural_parameters])
116116

117117
sys = :($ODESystem($(flatten_equations)(equations), $iv, variables, parameters;
118-
name, description = $description, systems, gui_metadata = $gui_metadata, defaults))
118+
name, description = $description, systems,
119+
gui_metadata = $gui_metadata, defaults, syskwargs...))
119120

120121
if length(ext) == 0
121122
push!(exprs.args, :(var"#___sys___" = $sys))
@@ -137,11 +138,11 @@ function _model_macro(mod, name, expr, isconnector)
137138
]))))
138139

139140
f = if length(where_types) == 0
140-
:($(Symbol(:__, name, :__))(; name, $(kwargs...)) = $exprs)
141+
:($(Symbol(:__, name, :__))(; name, $(kwargs...), syskwargs...) = $exprs)
141142
else
142143
f_with_where = Expr(:where)
143144
push!(f_with_where.args,
144-
:($(Symbol(:__, name, :__))(; name, $(kwargs...))), where_types...)
145+
:($(Symbol(:__, name, :__))(; name, $(kwargs...), syskwargs...)), where_types...)
145146
:($f_with_where = $exprs)
146147
end
147148

test/model_parsing.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,3 +1011,17 @@ end
10111011
@test any(isequal(u), vars)
10121012
end
10131013
end
1014+
1015+
@testset "Pass kwargs to ODESystem" begin
1016+
@mtkmodel UnitFailure begin
1017+
@variables begin
1018+
x(t), [unit = u"V"]
1019+
y(t), [unit = u"A"]
1020+
end
1021+
@equations begin
1022+
x ~ y
1023+
end
1024+
end
1025+
@test_throws ModelingToolkit.ValidationError UnitFailure(name = :uf)
1026+
UnitFailure(name = :uf, checks = false) # no error with passed kwarg
1027+
end

0 commit comments

Comments
 (0)