Relation Class¶
fusdb.Relation represents one physical relation: a callable that
computes outputs (or a residual) from explicit inputs.
Relations are usually declared with the @relation decorator exported by
the fusdb package.
Core Fields¶
Set at construction:
name: stable relation name (defaults to the function name when using the decorator)input_names: ordered canonical input variable namesoutputs: declared output variable names (empty means the function implements an outputless residual)func: Python callable implementing the forward evaluationtags: classification tags, for example("geometry", "plasma")constraints: relation-local validity constraintsenforce: whether the relation is enforced (True) or warning-only (False)
Key properties and methods¶
input_names-> tuple of input namesevaluate(namespace)-> call the underlying Python function with the provided namespaceoutput_map(result)-> map a function result to declared outputscomparisons(namespace)-> list of comparison tuples(lhs, op, rhs, output_name)used by the solverimplicit-> whether outputs also appear among inputsfrom_function(...)and therelationdecorator -> helpers to construct and registerRelationobjects
Creating Relations¶
Direct construction¶
from fusdb.relation import Relation
rel = Relation(
name="Aspect ratio",
func=lambda R, a: R / a,
input_names=("R", "a"),
outputs=("A",),
tags=("geometry",),
constraints=("R > 0", "a > 0", "a < R"),
)
Decorator (recommended)¶
from fusdb.relation import relation
@relation(
name="Aspect ratio",
outputs=("A",),
tags=("geometry",),
constraints=("R > 0", "a > 0", "a < R"),
)
def aspect_ratio(R: float, a: float) -> float:
return R / a
Decorator parameters:
name: relation name used for registrationoutputs: output variable name or tuple of namestags: classification tagsenforce: make a relation warning-only by settingenforce=Falseconstraints: relation-local validity constraints
Note
For symbolic inversion to work, keep relation functions SymPy-friendly: avoid NumPy-only expressions and use SymPy-compatible math/branching.
Example with RelationSystem¶
from fusdb import RelationSystem
from fusdb.variable import Variable
from fusdb.relation import relation
@relation(name="Aspect ratio", outputs=("A",))
def aspect_ratio(R: float, a: float) -> float:
return R / a
R = Variable("R", value=3.0, unit="m")
a = Variable("a", value=1.0, unit="m")
A = Variable("A", value=None, unit="1")
rel_system = RelationSystem(variables=[R, a, A], relations=[aspect_ratio])
result = rel_system.run(mode="verify")
print(result["variables"]["A"].value)