Variable Class¶
The variable system provides typed containers for scalar and profile values used by
fusdb.Reactor and fusdb.RelationSystem.
Related modules:
fusdb.variable_class
Related pages:
Class Structure¶
Variable: container for scalar (shape==0) and profile (shape==1) values.
Shared Fields¶
name: canonical variable nameunit: canonical registry unitshape:0for scalar,1for 1D profilerel_tol: optional relative tolerance overrideconstraints: validation constraints (expressions)fixed: whether solve modes may change the value
Runtime value fields:
value: the current canonical-unit value (scalar or 1Dnumpy.ndarray)reference_value: a copy of the initialvaluecaptured at constructionsource: provenance label such as"given","missing", or"computed"
API and behavior¶
Construct a variable with:
from fusdb.variable import Variable
v = Variable(name="R", value=3.2, unit="m", rel_tol=0.02, fixed=False)
Key methods and helpers:
clone(**changes)-> return a freshVariablewith selected overridesset_value(value, *, source=None)-> set a canonical-unit value and updatesourceas_dict()-> serializable view useful for result payloads
Profiles (shape==1) accept scalar inputs (broadcast to the profile length) or
1D arrays; the constructor or set_value will validate shape and size and
convert numeric inputs to numpy.ndarray where appropriate.
Validation errors (NaN, wrong dimensionality, out-of-domain) raise ValueError.
Example¶
import numpy as np
from fusdb.variable import Variable
# Scalar variable
R = Variable("R", value=3.2, unit="m", rel_tol=0.02)
R.set_value(3.3, source="user")
print(R.reference_value, R.value)
# Profile variable
n_e = Variable("n_e", value=np.array([1.1e20, 1.05e20, 1.0e20]), unit="m^-3")
print(np.mean(n_e.value))