@@ -472,15 +472,18 @@ function namespace_defaults(sys)
472
472
for (k, v) in pairs (defs))
473
473
end
474
474
475
- function namespace_equations (sys:: AbstractSystem )
475
+ function namespace_equations (sys:: AbstractSystem , ivs = nothing )
476
476
eqs = equations (sys)
477
477
isempty (eqs) && return Equation[]
478
- map (eq -> namespace_equation (eq, sys), eqs)
478
+ map (eq -> namespace_equation (eq, sys; ivs ), eqs)
479
479
end
480
480
481
- function namespace_equation (eq:: Equation , sys, n = nameof (sys))
482
- _lhs = namespace_expr (eq. lhs, sys, n)
483
- _rhs = namespace_expr (eq. rhs, sys, n)
481
+ function namespace_equation (eq:: Equation ,
482
+ sys,
483
+ n = nameof (sys);
484
+ ivs = independent_variables (sys))
485
+ _lhs = namespace_expr (eq. lhs, sys, n; ivs)
486
+ _rhs = namespace_expr (eq. rhs, sys, n; ivs)
484
487
_lhs ~ _rhs
485
488
end
486
489
@@ -490,15 +493,14 @@ function namespace_assignment(eq::Assignment, sys)
490
493
Assignment (_lhs, _rhs)
491
494
end
492
495
493
- function namespace_expr (O, sys, n = nameof (sys))
494
- ivs = independent_variables (sys)
496
+ function namespace_expr (O, sys, n = nameof (sys); ivs = independent_variables (sys))
495
497
O = unwrap (O)
496
498
if any (isequal (O), ivs)
497
499
return O
498
500
elseif istree (O)
499
501
T = typeof (O)
500
502
renamed = let sys = sys, n = n, T = T
501
- map (a -> namespace_expr (a, sys, n):: Any , arguments (O))
503
+ map (a -> namespace_expr (a, sys, n; ivs ):: Any , arguments (O))
502
504
end
503
505
if isvariable (O)
504
506
# Use renamespace so the scope is correct, and make sure to use the
@@ -513,7 +515,7 @@ function namespace_expr(O, sys, n = nameof(sys))
513
515
renamespace (n, O)
514
516
elseif O isa Array
515
517
let sys = sys, n = n
516
- map (o -> namespace_expr (o, sys, n), O)
518
+ map (o -> namespace_expr (o, sys, n; ivs ), O)
517
519
end
518
520
else
519
521
O
0 commit comments