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:
- func
callable() Function with signature: list[ParamVertex] = func(params) where params is a 1D array of optimization parameters.
- n_params
int Number of optimization parameters.
- bounds
tupleorlistoftuples,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.
- func
- Raises:
RuntimeErrorIf make_segments_parametric() was already used.
ValueErrorIf 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)])