Skip to content

novaphy.pressure_func

Decorator that marks a Python function as a custom hydroelastic SDF pressure law. The decorator itself only adds a marker; constructing a HydroelasticSdfConfig compiles the function's source into the CPU/CUDA pressure-law bytecode.

@novaphy.pressure_func
def pressure(signed_depth, shape_idx, data):
    ...

Parameters

Parameter Description
signed_depth Signed hydroelastic penetration depth supplied by the collision pipeline.
shape_idx Current shape index; the only supported index for array data.
data User object containing float scalars or DeviceArray[float] fields.

The compiler accepts numeric constants, simple assignments, annotated assignments, a return statement, one if branch, unary minus, +, -, *, /, single comparisons, and supported calls to pow, abs, min, and max. A pressure-data object may contain at most eight referenced device arrays. Each array may only be indexed as data.field[shape_idx] and must live on the same device as the model.

The function must be defined in inspectable Python source. Lambdas and functions created in environments where inspect.getsource() cannot recover the definition are rejected with PressureCompileError.

Example

import novaphy


class PressureData:
    scale = 2.0


@novaphy.pressure_func
def scaled_pressure(signed_depth, shape_idx, data):
    return -data.scale * signed_depth


config = novaphy.HydroelasticSdfConfig(
    pressure_func=scaled_pressure,
    pressure_data=PressureData(),
)
assert config.has_pressure_func

See Also