@@ -1114,9 +1114,25 @@ function _apply_to_variables(f::F, ex) where {F}
11141114 metadata (ex))
11151115end
11161116
1117+ """
1118+ Variable metadata key which contains information about scoping/namespacing of the
1119+ variable in a hierarchical system.
1120+ """
11171121abstract type SymScope end
11181122
1123+ """
1124+ $(TYPEDEF)
1125+
1126+ The default scope of a variable. It belongs to the system whose equations it is involved
1127+ in and is namespaced by every level of the hierarchy.
1128+ """
11191129struct LocalScope <: SymScope end
1130+
1131+ """
1132+ $(TYPEDSIGNATURES)
1133+
1134+ Apply `LocalScope` to `sym`.
1135+ """
11201136function LocalScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} )
11211137 apply_to_variables (sym) do sym
11221138 if iscall (sym) && operation (sym) === getindex
@@ -1130,9 +1146,25 @@ function LocalScope(sym::Union{Num, Symbolic, Symbolics.Arr{Num}})
11301146 end
11311147end
11321148
1149+ """
1150+ $(TYPEDEF)
1151+
1152+ Denotes that the variable does not belong to the system whose equations it is involved
1153+ in. It is not namespaced by this system. In the immediate parent of this system, the
1154+ scope of this variable is given by `parent`.
1155+
1156+ # Fields
1157+
1158+ $(TYPEDFIELDS)
1159+ """
11331160struct ParentScope <: SymScope
11341161 parent:: SymScope
11351162end
1163+ """
1164+ $(TYPEDSIGNATURES)
1165+
1166+ Apply `ParentScope` to `sym`, with `parent` being `LocalScope`.
1167+ """
11361168function ParentScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} )
11371169 apply_to_variables (sym) do sym
11381170 if iscall (sym) && operation (sym) === getindex
@@ -1148,10 +1180,31 @@ function ParentScope(sym::Union{Num, Symbolic, Symbolics.Arr{Num}})
11481180 end
11491181end
11501182
1183+ """
1184+ $(TYPEDEF)
1185+
1186+ Denotes that a variable belongs to a system that is at least `N + 1` levels up in the
1187+ hierarchy from the system whose equations it is involved in. It is namespaced by the
1188+ first `N` parents and not namespaced by the `N+1`th parent in the hierarchy. The scope
1189+ of the variable after this point is given by `parent`.
1190+
1191+ In other words, this scope delays applying `ParentScope` by `N` levels, and applies
1192+ `LocalScope` in the meantime.
1193+
1194+ # Fields
1195+
1196+ $(TYPEDFIELDS)
1197+ """
11511198struct DelayParentScope <: SymScope
11521199 parent:: SymScope
11531200 N:: Int
11541201end
1202+
1203+ """
1204+ $(TYPEDSIGNATURES)
1205+
1206+ Apply `DelayParentScope` to `sym`, with a delay of `N` and `parent` being `LocalScope`.
1207+ """
11551208function DelayParentScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} , N)
11561209 apply_to_variables (sym) do sym
11571210 if iscall (sym) && operation (sym) == getindex
@@ -1166,9 +1219,29 @@ function DelayParentScope(sym::Union{Num, Symbolic, Symbolics.Arr{Num}}, N)
11661219 end
11671220 end
11681221end
1222+
1223+ """
1224+ $(TYPEDSIGNATURES)
1225+
1226+ Apply `DelayParentScope` to `sym`, with a delay of `1` and `parent` being `LocalScope`.
1227+ """
11691228DelayParentScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} ) = DelayParentScope (sym, 1 )
11701229
1230+ """
1231+ $(TYPEDEF)
1232+
1233+ Denotes that a variable belongs to the root system in the hierarchy, regardless of which
1234+ equations of subsystems in the hierarchy it is involved in. Variables with this scope
1235+ are never namespaced and only added to the unknowns/parameters of a system when calling
1236+ `complete` or `structural_simplify`.
1237+ """
11711238struct GlobalScope <: SymScope end
1239+
1240+ """
1241+ $(TYPEDSIGNATURES)
1242+
1243+ Apply `GlobalScope` to `sym`.
1244+ """
11721245function GlobalScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} )
11731246 apply_to_variables (sym) do sym
11741247 if iscall (sym) && operation (sym) == getindex
0 commit comments