You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Creates the found expressions that will create the compound species.
63
63
# The `Expr(:escape, :(...))` is required so that teh expressions are evaluated in the scope the users use the macro in (to e.g. detect already exiting species).
64
+
non_t_iv_error_check_expr =Expr(:escape, :(@species$species_expr)) # E.g. `@species CO2(t)`
64
65
species_declaration_expr =Expr(:escape, :(@species$species_expr)) # E.g. `@species CO2(t)`
# Currently, non-t independent variables are not supported for compounds. If there are any like these, we throw an error:
71
+
non_t_iv_error_check_expr =Expr(:escape, :(issetequal(unique(reduce(vcat, arguments.(ModelingToolkit.unwrap.($components)))), [t]) ||error("Currently, compounds depending on components that are not \"t\" are not supported.")))
Copy file name to clipboardExpand all lines: src/expression_utils.jl
+8-4Lines changed: 8 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -50,19 +50,23 @@ end
50
50
# X(t), [metadata=true]
51
51
# X(t) = 1.0, [metadata=true]
52
52
# (In this example the independent variable t was inserted).
53
+
# Extra dispatch is to ensure so that iv is a vector (so that we can handle both single or multiple iv insertion in one function).
54
+
# - This way we don't have to make a check for how to create the final expression (which is different for symbol or vector of symbols).
53
55
functioninsert_independent_variable(expr_in, iv)
56
+
# If iv is a symbol (e.g. :t), we convert to vector (e.g. [:t]). This way we can handle single and multiple ivs using the same code, without needing to check at the end.
57
+
(iv isa Symbol) && (iv = [iv])
54
58
# If expr is a symbol, just attach the iv. If not we have to create a new expr and mutate it.
55
59
# Because Symbols (a possible input) cannot be mutated, this function cannot mutate the input (would have been easier if Expr input was guaranteed).
56
-
(expr_in isa Symbol) && (return:($(expr_in)($iv)))
60
+
(expr_in isa Symbol) && (returnExpr(:call, expr_in, iv...))
57
61
expr =deepcopy(expr_in)
58
62
59
63
if expr.head == :(=) # Case: :(X = 1.0)
60
-
expr.args[1] =:($(expr.args[1])($iv))
64
+
expr.args[1] =Expr(:call, expr.args[1], iv...)
61
65
elseif expr.head ==:tuple
62
66
if expr.args[1] isa Symbol # Case: :(X, [metadata=true])
0 commit comments