@@ -465,6 +465,40 @@ function setbounds(x::Num, bounds)
465465 return setmetadata (x, VariableBounds, (lb, ub))
466466end
467467
468+ # # Nominal =====================================================================
469+ struct VariableNominal end
470+ Symbolics. option_to_metadata_type (:: Val{:nominal} ) = VariableNominal
471+
472+ """
473+ getnominal(x)
474+
475+ Get the nominal value associated with symbolic variable `x`. Returns `1.0` if no nominal value is set.
476+ Create variables with a nominal value like this
477+
478+ ```
479+ @variables x [nominal = 4785.0]
480+ ```
481+ """
482+ getnominal (x:: Union{Num, Symbolics.Arr} ) = getnominal (unwrap (x))
483+ function getnominal (x:: SymbolicT )
484+ s = Symbolics. getmetadata_maybe_indexed (x, VariableNominal, nothing )
485+ s === nothing ? 1.0 : s
486+ end
487+
488+ """
489+ hasnominal(x)
490+
491+ Determine whether symbolic variable `x` has a nominal value associated with it.
492+ See also [`getnominal`](@ref).
493+ """
494+ function hasnominal (x)
495+ Symbolics. getmetadata_maybe_indexed (unwrap (x), VariableNominal, nothing ) != = nothing
496+ end
497+
498+ function setnominal (x:: Num , val)
499+ return setmetadata (x, VariableNominal, val)
500+ end
501+
468502# # Disturbance =================================================================
469503struct VariableDisturbance end
470504Symbolics. option_to_metadata_type (:: Val{:disturbance} ) = VariableDisturbance
@@ -608,6 +642,26 @@ function getbounds(p::AbstractVector)
608642 return (; lb, ub)
609643end
610644
645+ """
646+ getnominal(sys::ModelingToolkitBase.AbstractSystem, vars = parameters(sys))
647+
648+ Returns a dict with pairs `var => nominal` mapping variables of `sys` to their nominal values.
649+ Create variables with a nominal value like this
650+
651+ ```
652+ @variables x [nominal = 40.0]
653+ ```
654+
655+ To obtain unknown variable nominal values, call `getnominal(sys, unknowns(sys))`
656+ """
657+ function getnominal (sys:: ModelingToolkitBase.AbstractSystem , p = parameters (sys))
658+ return Dict (p .=> getnominal .(p))
659+ end
660+
661+ function getnominal (p:: AbstractVector )
662+ return getnominal .(p)
663+ end
664+
611665# # Description =================================================================
612666"""
613667 $TYPEDEF
0 commit comments