@@ -29,7 +29,7 @@ ModelingToolkit.dump_variable_metadata(p)
29
29
"""
30
30
function dump_variable_metadata (var)
31
31
uvar = unwrap (var)
32
- vartype, name = get (uvar. metadata , VariableSource, (:unknown , :unknown ))
32
+ vartype, name = Symbolics . getmetadata (uvar, VariableSource, (:unknown , :unknown ))
33
33
type = symtype (uvar)
34
34
if type <: AbstractArray
35
35
shape = Symbolics. shape (var)
@@ -39,14 +39,14 @@ function dump_variable_metadata(var)
39
39
else
40
40
shape = nothing
41
41
end
42
- unit = get (uvar. metadata, VariableUnit, nothing )
43
- connect = get (uvar. metadata, VariableConnectType, nothing )
44
- noise = get (uvar. metadata, VariableNoiseType, nothing )
42
+ unit = getunit (uvar)
43
+ connect = getconnect (uvar)
44
+ noise = getnoise (uvar)
45
45
input = isinput (uvar) || nothing
46
46
output = isoutput (uvar) || nothing
47
- irreducible = get (uvar . metadata, VariableIrreducible, nothing )
48
- state_priority = get (uvar. metadata , VariableStatePriority, nothing )
49
- misc = get (uvar. metadata, VariableMisc, nothing )
47
+ irreducible = isirreducible (var )
48
+ state_priority = Symbolics . getmetadata (uvar, VariableStatePriority, nothing )
49
+ misc = getmisc (uvar)
50
50
bounds = hasbounds (uvar) ? getbounds (uvar) : nothing
51
51
desc = getdescription (var)
52
52
if desc == " "
@@ -57,12 +57,13 @@ function dump_variable_metadata(var)
57
57
disturbance = isdisturbance (uvar) || nothing
58
58
tunable = istunable (uvar, isparameter (uvar))
59
59
dist = getdist (uvar)
60
- type = symtype (uvar)
60
+ variable_type = getvariabletype (uvar)
61
61
62
62
meta = (
63
63
var = var,
64
64
vartype,
65
65
name,
66
+ variable_type,
66
67
shape,
67
68
unit,
68
69
connect,
@@ -85,11 +86,28 @@ function dump_variable_metadata(var)
85
86
return NamedTuple (k => v for (k, v) in pairs (meta) if v != = nothing )
86
87
end
87
88
89
+ # ## Connect
88
90
abstract type AbstractConnectType end
89
91
struct Equality <: AbstractConnectType end # Equality connection
90
92
struct Flow <: AbstractConnectType end # sum to 0
91
93
struct Stream <: AbstractConnectType end # special stream connector
92
94
95
+ """
96
+ getconnect(x)
97
+
98
+ Get the connect type of x. See also [`hasconnect`](@ref).
99
+ """
100
+ getconnect (x) = getconnect (unwrap (x))
101
+ getconnect (x:: Symbolic ) = Symbolics. getmetadata (x, VariableConnectType, nothing )
102
+ """
103
+ hasconnect(x)
104
+
105
+ Determine whether variable `x` has a connect type. See also [`getconnect`](@ref).
106
+ """
107
+ hasconnect (x) = getconnect (x) != = nothing
108
+ setconnect (x, t:: Type{T} ) where T <: AbstractConnectType = setmetadata (x, VariableConnectType, t)
109
+
110
+ # ## Input, Output, Irreducible
93
111
isvarkind (m, x:: Union{Num, Symbolics.Arr} ) = isvarkind (m, value (x))
94
112
function isvarkind (m, x)
95
113
iskind = getmetadata (x, m, nothing )
@@ -98,15 +116,17 @@ function isvarkind(m, x)
98
116
getmetadata (x, m, false )
99
117
end
100
118
101
- setinput (x, v) = setmetadata (x, VariableInput, v)
102
- setoutput (x, v) = setmetadata (x, VariableOutput, v)
103
- setio (x, i, o) = setoutput (setinput (x, i), o)
119
+ setinput (x, v:: Bool ) = setmetadata (x, VariableInput, v)
120
+ setoutput (x, v:: Bool ) = setmetadata (x, VariableOutput, v)
121
+ setio (x, i:: Bool , o:: Bool ) = setoutput (setinput (x, i), o)
122
+
104
123
isinput (x) = isvarkind (VariableInput, x)
105
124
isoutput (x) = isvarkind (VariableOutput, x)
125
+
106
126
# Before the solvability check, we already have handled IO variables, so
107
127
# irreducibility is independent from IO.
108
128
isirreducible (x) = isvarkind (VariableIrreducible, x)
109
- setirreducible (x, v) = setmetadata (x, VariableIrreducible, v)
129
+ setirreducible (x, v:: Bool ) = setmetadata (x, VariableIrreducible, v)
110
130
state_priority (x) = convert (Float64, getmetadata (x, VariableStatePriority, 0.0 )):: Float64
111
131
112
132
function default_toterm (x)
@@ -545,3 +565,52 @@ function get_default_or_guess(x)
545
565
return getguess (x)
546
566
end
547
567
end
568
+
569
+ # # Miscellaneous metadata ======================================================================
570
+ """
571
+ getmisc(x)
572
+
573
+ Fetch any miscellaneous data associated with symbolic variable `x`.
574
+ See also [`hasmisc(x)`](@ref).
575
+ """
576
+ getmisc (x) = getmisc (unwrap (x))
577
+ getmisc (x:: Symbolic ) = Symbolics. getmetadata (x, VariableMisc, nothing )
578
+ """
579
+ hasmisc(x)
580
+
581
+ Determine whether a symbolic variable `x` has misc
582
+ metadata associated with it.
583
+
584
+ See also [`getmisc(x)`](@ref).
585
+ """
586
+ hasmisc (x) = getmisc (x) != = nothing
587
+ setmisc (x, miscdata) = setmetadata (x, VariableMisc, miscdata)
588
+
589
+ # # Units ======================================================================
590
+ """
591
+ getunit(x)
592
+
593
+ Alias for [`get_unit(x)`](@ref).
594
+ """
595
+ getunit (x) = get_unit (x)
596
+ """
597
+ hasunit(x)
598
+
599
+ Check if the variable `x` has a unit.
600
+ """
601
+ hasunit (x) = getunit (x) != = nothing
602
+
603
+ # # Noise ======================================================================
604
+ """
605
+ getnoise(x)
606
+
607
+ Get the noise type of variable `x`.
608
+ """
609
+ getnoise (x) = getnoise (unwrap (x))
610
+ getnoise (x:: Symbolic ) = Symbolics. getmetadata (x, VariableNoiseType, nothing )
611
+ """
612
+ hasnoise(x)
613
+
614
+ Determine if variable `x` has a noise type.
615
+ """
616
+ hasnoise (x) = getnoise (x) != = nothing
0 commit comments