set_parametrization_function#

ClosedCurve.set_parametrization_function(func, n_params: int, bounds: Tuple[float, float] | List[Tuple[float, float]] | None = None)#

Set a user-defined parametrization function for the geometry.

The function must be callable and return a list of ParamVertex objects that specify how each vertex should be displaced based on the optimization parameters.

Parameters:
funccallable()

Function with signature: list[ParamVertex] = func(params) where params is a 1D array of optimization parameters.

n_paramsint

Number of optimization parameters.

boundstuple or list of tuples, optional

Bounds for the optimization parameters. Can be either: - A single tuple (min, max) to apply the same bounds to all parameters - A list of tuples [(min1, max1), (min2, max2), …] for per-parameter bounds If None, defaults to (-500e-9, 500e-9) for all parameters.

Raises:
RuntimeError

If make_segments_parametric() was already used.

ValueError

If func is not callable or doesn’t return ParamVertex list, or if bounds are invalid.

Examples

>>> def parametrization(params):
>>>    return [
>>>        ParamVertex(idx=2, delta_y=params[0]),
>>>        ParamVertex(idx=3, delta_y=params[1]),
>>>        ParamVertex(idx=14, delta_y=-params[1]),
>>>        ParamVertex(idx=15, delta_y=-params[0])
>>>    ]
>>>
>>> # With default bounds
>>> geom.set_parametrization_function(func=parametrization, n_params=2)
>>>
>>> # With custom uniform bounds
>>> geom.set_parametrization_function(func=parametrization, n_params=2, bounds=(-200e-9, 300e-9))
>>>
>>> # With per-parameter bounds
>>> geom.set_parametrization_function(func=parametrization, n_params=2, 
>>>                                  bounds=[(-200e-9, 200e-9), (-100e-9, 300e-9)])