Skip to content

Commit 5c24fa1

Browse files
refactor: mark variable default manipulation functions as public
1 parent 434b34a commit 5c24fa1

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

docs/src/API/variables.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ Symbolic variables can have metadata attached to them. The defaults and guesses
1818
at variable construction time are examples of this metadata. ModelingToolkit also defines
1919
additional types of metadata.
2020

21+
## Variable defaults
22+
23+
Variables can be assigned default values to avoid having to specify defaults to the
24+
[`System`](@ref) constructor.
25+
26+
```@docs
27+
ModelingToolkit.hasdefault
28+
ModelingToolkit.getdefault
29+
ModelingToolkit.setdefault
30+
```
31+
2132
## Variable descriptions
2233

2334
Descriptive strings can be attached to variables using the `[description = "descriptive string"]` syntax:

src/ModelingToolkit.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ export DynamicOptSolution
342342
@public VariableType, MTKVariableTypeCtx, VariableBounds, VariableConnectType
343343
@public VariableDescription, VariableInput, VariableIrreducible, VariableMisc
344344
@public VariableOutput, VariableStatePriority, VariableUnit, collect_scoped_vars!
345-
@public collect_var_to_name!, collect_vars!, eqtype_supports_collect_vars
345+
@public collect_var_to_name!, collect_vars!, eqtype_supports_collect_vars, hasdefault
346+
@public getdefault, setdefault
346347

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

src/utils.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,23 @@ function iv_from_nested_derivative(x, op = Differential)
250250
end
251251
end
252252

253+
"""
254+
$(TYPEDSIGNATURES)
255+
256+
Check if the symbolic variable `v` has a default value.
257+
"""
253258
hasdefault(v) = hasmetadata(v, Symbolics.VariableDefaultValue)
259+
"""
260+
$(TYPEDSIGNATURES)
261+
262+
Return the default value of symbolic variable `v`.
263+
"""
254264
getdefault(v) = value(Symbolics.getdefaultval(v))
265+
"""
266+
$(TYPEDSIGNATURES)
267+
268+
Set the default value of symbolic variable `v` to `val`.
269+
"""
255270
function setdefault(v, val)
256271
val === nothing ? v : wrap(setdefaultval(unwrap(v), value(val)))
257272
end

0 commit comments

Comments
 (0)