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