coordinates.base.class_expression#
- coordinates.base.class_expression(name: str | None = None) classmethod [source]#
Mark a class method as a symbolic expression (“class expression”) in a coordinate system.
Class expressions are symbolic methods that define expressions such as metric tensors, Jacobians, or differential geometry terms. When decorated with this function, the method is automatically registered during class construction and evaluated on demand via
get_class_expression()
.The decorated method must be a
@classmethod
with the following signature:def some_expr(cls, *axes_symbols, **parameter_symbols): ...
- Parameters:
name (
str
, optional) – A custom name to assign to the expression. If omitted, the method name is used.- Returns:
The decorated class method with metadata attached for registration and deferred evaluation.
- Return type:
classmethod
Notes
The decorator only works on methods already marked as
@classmethod
.Registered expressions are stored on the class and evaluated once when first accessed.
Use
get_class_expression(name)()
to access the expression symbolically.
Example
class MySystem(CoordinateSystemBase): __AXES__ = ["r", "theta"] __PARAMETERS__ = {} @class_expression() @classmethod def metric_tensor(cls, r, theta): return sp.Matrix([[1, 0], [0, r**2]]) expr = MySystem.get_class_expression("metric_tensor") print(expr) # => Matrix([[1, 0], [0, r**2]])