Skip to content

Commit 6eddd71

Browse files
SebastianM-Cclaude
andcommitted
Rename VariableNominalValue to VariableNominal
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3306d2b commit 6eddd71

4 files changed

Lines changed: 56 additions & 56 deletions

File tree

docs/src/API/variables.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,24 +180,24 @@ for scaling constraints in optimal control problems, preventing ill-conditioning
180180
variables have vastly different magnitudes. The default nominal value is `1.0`.
181181

182182
```@repl metadata
183-
@variables x [nominal_value = 1000.0];
184-
hasnominalvalue(x)
185-
getnominalvalue(x)
183+
@variables x [nominal = 1000.0];
184+
hasnominal(x)
185+
getnominal(x)
186186
```
187187

188188
Nominal values can also be specified for array variables:
189189

190190
```@repl metadata
191-
@variables x[1:3] [nominal_value = [100.0, 200.0, 300.0]];
192-
getnominalvalue(x)
193-
getnominalvalue(x[1])
191+
@variables x[1:3] [nominal = [100.0, 200.0, 300.0]];
192+
getnominal(x)
193+
getnominal(x[1])
194194
```
195195

196196
```@docs
197-
hasnominalvalue
198-
getnominalvalue
199-
setnominalvalue
200-
ModelingToolkit.VariableNominalValue
197+
hasnominal
198+
getnominal
199+
setnominal
200+
ModelingToolkit.VariableNominal
201201
```
202202

203203
## Guess

lib/ModelingToolkitBase/src/ModelingToolkitBase.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export flatten
257257
export connect, domain_connect, @connector, Connection, AnalysisPoint, Flow, Stream,
258258
instream
259259
export @component, @mtkcompile, @mtkbuild, @mtkcomplete
260-
export isinput, isoutput, getbounds, hasbounds, getnominalvalue, hasnominalvalue, setnominalvalue, getguess, hasguess, isdisturbance,
260+
export isinput, isoutput, getbounds, hasbounds, getnominal, hasnominal, setnominal, getguess, hasguess, isdisturbance,
261261
istunable, getdist, hasdist,
262262
tunable_parameters, isirreducible, getdescription, hasdescription,
263263
hasunit, getunit, hasconnect, getconnect,

lib/ModelingToolkitBase/src/variables.jl

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -465,38 +465,38 @@ function setbounds(x::Num, bounds)
465465
return setmetadata(x, VariableBounds, (lb, ub))
466466
end
467467

468-
## NominalValue ================================================================
469-
struct VariableNominalValue end
470-
Symbolics.option_to_metadata_type(::Val{:nominal_value}) = VariableNominalValue
468+
## Nominal =====================================================================
469+
struct VariableNominal end
470+
Symbolics.option_to_metadata_type(::Val{:nominal}) = VariableNominal
471471

472472
"""
473-
getnominalvalue(x)
473+
getnominal(x)
474474
475475
Get the nominal value associated with symbolic variable `x`. Returns `1.0` if no nominal value is set.
476476
Create variables with a nominal value like this
477477
478478
```
479-
@variables x [nominal_value = 4785.0]
479+
@variables x [nominal = 4785.0]
480480
```
481481
"""
482-
getnominalvalue(x::Union{Num, Symbolics.Arr}) = getnominalvalue(unwrap(x))
483-
function getnominalvalue(x::SymbolicT)
484-
s = Symbolics.getmetadata_maybe_indexed(x, VariableNominalValue, nothing)
482+
getnominal(x::Union{Num, Symbolics.Arr}) = getnominal(unwrap(x))
483+
function getnominal(x::SymbolicT)
484+
s = Symbolics.getmetadata_maybe_indexed(x, VariableNominal, nothing)
485485
s === nothing ? 1.0 : s
486486
end
487487

488488
"""
489-
hasnominalvalue(x)
489+
hasnominal(x)
490490
491491
Determine whether symbolic variable `x` has a nominal value associated with it.
492-
See also [`getnominalvalue`](@ref).
492+
See also [`getnominal`](@ref).
493493
"""
494-
function hasnominalvalue(x)
495-
Symbolics.getmetadata_maybe_indexed(unwrap(x), VariableNominalValue, nothing) !== nothing
494+
function hasnominal(x)
495+
Symbolics.getmetadata_maybe_indexed(unwrap(x), VariableNominal, nothing) !== nothing
496496
end
497497

498-
function setnominalvalue(x::Num, val)
499-
return setmetadata(x, VariableNominalValue, val)
498+
function setnominal(x::Num, val)
499+
return setmetadata(x, VariableNominal, val)
500500
end
501501

502502
## Disturbance =================================================================
@@ -643,23 +643,23 @@ function getbounds(p::AbstractVector)
643643
end
644644

645645
"""
646-
getnominalvalue(sys::ModelingToolkitBase.AbstractSystem, vars = parameters(sys))
646+
getnominal(sys::ModelingToolkitBase.AbstractSystem, vars = parameters(sys))
647647
648-
Returns a dict with pairs `var => nominal_value` mapping variables of `sys` to their nominal values.
648+
Returns a dict with pairs `var => nominal` mapping variables of `sys` to their nominal values.
649649
Create variables with a nominal value like this
650650
651651
```
652-
@variables x [nominal_value = 40.0]
652+
@variables x [nominal = 40.0]
653653
```
654654
655-
To obtain unknown variable nominal values, call `getnominalvalue(sys, unknowns(sys))`
655+
To obtain unknown variable nominal values, call `getnominal(sys, unknowns(sys))`
656656
"""
657-
function getnominalvalue(sys::ModelingToolkitBase.AbstractSystem, p = parameters(sys))
658-
return Dict(p .=> getnominalvalue.(p))
657+
function getnominal(sys::ModelingToolkitBase.AbstractSystem, p = parameters(sys))
658+
return Dict(p .=> getnominal.(p))
659659
end
660660

661-
function getnominalvalue(p::AbstractVector)
662-
return getnominalvalue.(p)
661+
function getnominal(p::AbstractVector)
662+
return getnominal.(p)
663663
end
664664

665665
## Description =================================================================

lib/ModelingToolkitBase/test/test_variable_metadata.jl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -264,48 +264,48 @@ x = ModelingToolkitBase.toparam(x)
264264
@brownians z
265265
@test ModelingToolkitBase.getvariabletype(z) == ModelingToolkitBase.BROWNIAN
266266

267-
# NominalValue
268-
@variables x [nominal_value = 100.0]
269-
@test getnominalvalue(x) == 100.0
270-
@test hasnominalvalue(x)
267+
# Nominal
268+
@variables x [nominal = 100.0]
269+
@test getnominal(x) == 100.0
270+
@test hasnominal(x)
271271

272272
@variables y
273-
@test !hasnominalvalue(y)
274-
@test getnominalvalue(y) == 1.0
273+
@test !hasnominal(y)
274+
@test getnominal(y) == 1.0
275275

276-
y2 = setnominalvalue(y, 50.0)
277-
@test getnominalvalue(y2) == 50.0
278-
@test hasnominalvalue(y2)
276+
y2 = setnominal(y, 50.0)
277+
@test getnominal(y2) == 50.0
278+
@test hasnominal(y2)
279279

280-
@variables z [nominal_value = 0.001]
281-
@test getnominalvalue(z) == 0.001
280+
@variables z [nominal = 0.001]
281+
@test getnominal(z) == 0.001
282282

283283
# Vector of variables
284-
vals = getnominalvalue([x, y, z])
284+
vals = getnominal([x, y, z])
285285
@test vals == [100.0, 1.0, 0.001]
286286

287287
# Vector variables
288-
@variables yv[1:3] [nominal_value = [100.0, 200.0, 300.0]]
289-
@test hasnominalvalue(yv)
290-
@test getnominalvalue(yv) == [100.0, 200.0, 300.0]
288+
@variables yv[1:3] [nominal = [100.0, 200.0, 300.0]]
289+
@test hasnominal(yv)
290+
@test getnominal(yv) == [100.0, 200.0, 300.0]
291291
for i in 1:3
292-
@test hasnominalvalue(yv[i])
292+
@test hasnominal(yv[i])
293293
end
294-
@test getnominalvalue(yv[1]) == 100.0
295-
@test getnominalvalue(yv[2]) == 200.0
296-
@test getnominalvalue(yv[3]) == 300.0
294+
@test getnominal(yv[1]) == 100.0
295+
@test getnominal(yv[2]) == 200.0
296+
@test getnominal(yv[3]) == 300.0
297297

298298
@variables wv[1:3]
299-
@test !hasnominalvalue(wv)
300-
@test getnominalvalue(wv[1]) == 1.0
299+
@test !hasnominal(wv)
300+
@test getnominal(wv[1]) == 1.0
301301

302302
# System-level accessor
303303
@independent_variables t5
304304
Dₜ5 = Differential(t5)
305-
@variables x5(t5) [nominal_value = 100.0] y5(t5) z5(t5) [nominal_value = 0.001]
305+
@variables x5(t5) [nominal = 100.0] y5(t5) z5(t5) [nominal = 0.001]
306306
@parameters α5 = 1.5 β5 = 1.0
307307
eqs5 = [Dₜ5(x5) ~ α5 * x5, Dₜ5(y5) ~ -β5 * y5, Dₜ5(z5) ~ x5 - z5]
308308
sys5 = System(eqs5, t5, name = :nominal_test)
309-
nv = getnominalvalue(sys5, unknowns(sys5))
309+
nv = getnominal(sys5, unknowns(sys5))
310310
@test nv isa Dict
311311
@test length(nv) == length(unknowns(sys5))

0 commit comments

Comments
 (0)