@@ -1085,6 +1085,7 @@ function getvar(sys::AbstractSystem, name::Symbol; namespace = does_namespacing(
1085
1085
1086
1086
if has_eqs (sys)
1087
1087
for eq in get_eqs (sys)
1088
+ eq isa Equation || continue
1088
1089
if eq. lhs isa AnalysisPoint && nameof (eq. rhs) == name
1089
1090
return namespace ? renamespace (sys, eq. rhs) : eq. rhs
1090
1091
end
@@ -1122,9 +1123,25 @@ function _apply_to_variables(f::F, ex) where {F}
1122
1123
metadata (ex))
1123
1124
end
1124
1125
1126
+ """
1127
+ Variable metadata key which contains information about scoping/namespacing of the
1128
+ variable in a hierarchical system.
1129
+ """
1125
1130
abstract type SymScope end
1126
1131
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
+ """
1127
1138
struct LocalScope <: SymScope end
1139
+
1140
+ """
1141
+ $(TYPEDSIGNATURES)
1142
+
1143
+ Apply `LocalScope` to `sym`.
1144
+ """
1128
1145
function LocalScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} )
1129
1146
apply_to_variables (sym) do sym
1130
1147
if iscall (sym) && operation (sym) === getindex
@@ -1138,9 +1155,25 @@ function LocalScope(sym::Union{Num, Symbolic, Symbolics.Arr{Num}})
1138
1155
end
1139
1156
end
1140
1157
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
+ """
1141
1169
struct ParentScope <: SymScope
1142
1170
parent:: SymScope
1143
1171
end
1172
+ """
1173
+ $(TYPEDSIGNATURES)
1174
+
1175
+ Apply `ParentScope` to `sym`, with `parent` being `LocalScope`.
1176
+ """
1144
1177
function ParentScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} )
1145
1178
apply_to_variables (sym) do sym
1146
1179
if iscall (sym) && operation (sym) === getindex
@@ -1156,11 +1189,34 @@ function ParentScope(sym::Union{Num, Symbolic, Symbolics.Arr{Num}})
1156
1189
end
1157
1190
end
1158
1191
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
+ """
1159
1207
struct DelayParentScope <: SymScope
1160
1208
parent:: SymScope
1161
1209
N:: Int
1162
1210
end
1211
+
1212
+ """
1213
+ $(TYPEDSIGNATURES)
1214
+
1215
+ Apply `DelayParentScope` to `sym`, with a delay of `N` and `parent` being `LocalScope`.
1216
+ """
1163
1217
function DelayParentScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} , N)
1218
+ Base. depwarn (
1219
+ " `DelayParentScope` is deprecated and will be removed soon" , :DelayParentScope )
1164
1220
apply_to_variables (sym) do sym
1165
1221
if iscall (sym) && operation (sym) == getindex
1166
1222
args = arguments (sym)
@@ -1174,9 +1230,29 @@ function DelayParentScope(sym::Union{Num, Symbolic, Symbolics.Arr{Num}}, N)
1174
1230
end
1175
1231
end
1176
1232
end
1233
+
1234
+ """
1235
+ $(TYPEDSIGNATURES)
1236
+
1237
+ Apply `DelayParentScope` to `sym`, with a delay of `1` and `parent` being `LocalScope`.
1238
+ """
1177
1239
DelayParentScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} ) = DelayParentScope (sym, 1 )
1178
1240
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
+ """
1179
1249
struct GlobalScope <: SymScope end
1250
+
1251
+ """
1252
+ $(TYPEDSIGNATURES)
1253
+
1254
+ Apply `GlobalScope` to `sym`.
1255
+ """
1180
1256
function GlobalScope (sym:: Union{Num, Symbolic, Symbolics.Arr{Num}} )
1181
1257
apply_to_variables (sym) do sym
1182
1258
if iscall (sym) && operation (sym) == getindex
0 commit comments