Skip to content

Commit ba7ee60

Browse files
refactor: mark renamespace, namespace_equations as public
1 parent b002c97 commit ba7ee60

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

docs/src/API/System.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,14 @@ ModelingToolkit.collect_vars!
213213
ModelingToolkit.eqtype_supports_collect_vars
214214
ModelingToolkit.modified_unknowns!
215215
```
216+
217+
## Namepsace manipulation
218+
219+
ModelingToolkit namespaces variables from subsystems when using them in a parent system to
220+
disambiguate from identically named variables in other subsystems or the parent system. The
221+
following functions are useful for manipulating namespacing functionality.
222+
223+
```@docs
224+
ModelingToolkit.renamespace
225+
ModelingToolkit.namespace_equations
226+
```

src/ModelingToolkit.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ export DynamicOptSolution
344344
@public VariableOutput, VariableStatePriority, VariableUnit, collect_scoped_vars!
345345
@public collect_var_to_name!, collect_vars!, eqtype_supports_collect_vars, hasdefault
346346
@public getdefault, setdefault, iscomplete, isparameter, modified_unknowns!
347+
@public renamespace, namespace_equations
347348

348349
for prop in [SYS_PROPS; [:continuous_events, :discrete_events]]
349350
getter = Symbol(:get_, prop)

src/systems/abstractsystem.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,12 @@ end
10951095
renamespace(sys, eq::Equation) = namespace_equation(eq, sys)
10961096

10971097
renamespace(names::AbstractVector, x) = foldr(renamespace, names, init = x)
1098+
1099+
"""
1100+
$(TYPEDSIGNATURES)
1101+
1102+
Namespace `x` with the name of `sys`.
1103+
"""
10981104
function renamespace(sys, x)
10991105
sys === nothing && return x
11001106
x = unwrap(x)
@@ -1141,6 +1147,11 @@ function namespace_guesses(sys)
11411147
Dict(unknowns(sys, k) => namespace_expr(v, sys) for (k, v) in guess)
11421148
end
11431149

1150+
"""
1151+
$(TYPEDSIGNATURES)
1152+
1153+
Return `equations(sys)`, namespaced by the name of `sys`.
1154+
"""
11441155
function namespace_equations(sys::AbstractSystem, ivs = independent_variables(sys))
11451156
eqs = equations(sys)
11461157
isempty(eqs) && return Equation[]
@@ -1162,6 +1173,11 @@ function namespace_tstops(sys::AbstractSystem)
11621173
end
11631174
end
11641175

1176+
"""
1177+
$(TYPEDSIGNATURES)
1178+
1179+
Namespace the given equation with the name of the given system `sys`.
1180+
"""
11651181
function namespace_equation(eq::Equation,
11661182
sys,
11671183
n = nameof(sys);

0 commit comments

Comments
 (0)