@@ -1085,6 +1085,7 @@ function getvar(sys::AbstractSystem, name::Symbol; namespace = does_namespacing(
10851085
10861086 if has_eqs (sys)
10871087 for eq in get_eqs (sys)
1088+ eq isa Equation || continue
10881089 if eq. lhs isa AnalysisPoint && nameof (eq. rhs) == name
10891090 return namespace ? renamespace (sys, eq. rhs) : eq. rhs
10901091 end
@@ -1122,9 +1123,25 @@ function _apply_to_variables(f::F, ex) where {F}
11221123 metadata (ex))
11231124end
11241125
1126+ """
1127+ Variable metadata key which contains information about scoping/namespacing of the
1128+ variable in a hierarchical system.
1129+ """
11251130abstract type SymScope end
11261131
1132+ """
1133+ $(TYPEDEF)
1134+
1135+ The default scope of a variable. It belongs to the system whose equations it is involved
1136+ in and is namespaced by every level of the hierarchy.
1137+ """
11271138struct LocalScope <: SymScope end
1139+
1140+ """
1141+ $(TYPEDSIGNATURES)
1142+
1143+ Apply `LocalScope` to `sym`.
1144+ """
11281145function LocalScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} )
11291146 apply_to_variables (sym) do sym
11301147 if iscall (sym) && operation (sym) === getindex
@@ -1138,9 +1155,25 @@ function LocalScope(sym::Union{Num, Symbolic, Symbolics.Arr{Num}})
11381155 end
11391156end
11401157
1158+ """
1159+ $(TYPEDEF)
1160+
1161+ Denotes that the variable does not belong to the system whose equations it is involved
1162+ in. It is not namespaced by this system. In the immediate parent of this system, the
1163+ scope of this variable is given by `parent`.
1164+
1165+ # Fields
1166+
1167+ $(TYPEDFIELDS)
1168+ """
11411169struct ParentScope <: SymScope
11421170 parent:: SymScope
11431171end
1172+ """
1173+ $(TYPEDSIGNATURES)
1174+
1175+ Apply `ParentScope` to `sym`, with `parent` being `LocalScope`.
1176+ """
11441177function ParentScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} )
11451178 apply_to_variables (sym) do sym
11461179 if iscall (sym) && operation (sym) === getindex
@@ -1156,11 +1189,34 @@ function ParentScope(sym::Union{Num, Symbolic, Symbolics.Arr{Num}})
11561189 end
11571190end
11581191
1192+ """
1193+ $(TYPEDEF)
1194+
1195+ Denotes that a variable belongs to a system that is at least `N + 1` levels up in the
1196+ hierarchy from the system whose equations it is involved in. It is namespaced by the
1197+ first `N` parents and not namespaced by the `N+1`th parent in the hierarchy. The scope
1198+ of the variable after this point is given by `parent`.
1199+
1200+ In other words, this scope delays applying `ParentScope` by `N` levels, and applies
1201+ `LocalScope` in the meantime.
1202+
1203+ # Fields
1204+
1205+ $(TYPEDFIELDS)
1206+ """
11591207struct DelayParentScope <: SymScope
11601208 parent:: SymScope
11611209 N:: Int
11621210end
1211+
1212+ """
1213+ $(TYPEDSIGNATURES)
1214+
1215+ Apply `DelayParentScope` to `sym`, with a delay of `N` and `parent` being `LocalScope`.
1216+ """
11631217function DelayParentScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} , N)
1218+ Base. depwarn (
1219+ " `DelayParentScope` is deprecated and will be removed soon" , :DelayParentScope )
11641220 apply_to_variables (sym) do sym
11651221 if iscall (sym) && operation (sym) == getindex
11661222 args = arguments (sym)
@@ -1174,9 +1230,29 @@ function DelayParentScope(sym::Union{Num, Symbolic, Symbolics.Arr{Num}}, N)
11741230 end
11751231 end
11761232end
1233+
1234+ """
1235+ $(TYPEDSIGNATURES)
1236+
1237+ Apply `DelayParentScope` to `sym`, with a delay of `1` and `parent` being `LocalScope`.
1238+ """
11771239DelayParentScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} ) = DelayParentScope (sym, 1 )
11781240
1241+ """
1242+ $(TYPEDEF)
1243+
1244+ Denotes that a variable belongs to the root system in the hierarchy, regardless of which
1245+ equations of subsystems in the hierarchy it is involved in. Variables with this scope
1246+ are never namespaced and only added to the unknowns/parameters of a system when calling
1247+ `complete` or `structural_simplify`.
1248+ """
11791249struct GlobalScope <: SymScope end
1250+
1251+ """
1252+ $(TYPEDSIGNATURES)
1253+
1254+ Apply `GlobalScope` to `sym`.
1255+ """
11801256function GlobalScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} )
11811257 apply_to_variables (sym) do sym
11821258 if iscall (sym) && operation (sym) == getindex
0 commit comments