constraint_explorer#

Constraint boundary exploration utilities for OpenMDAO systems.

This module provides tools to automatically explore and visualize constraint boundaries in parameter space using adaptive sampling and refinement techniques.

Functions#

explore_constraint_boundary_2d(prob, param1, param2, ...)

Explore 2D parameter space to find constraint boundary.

trace_constraint_boundary_2d(prob, param1, param2, ...)

Trace constraint boundary curve starting from a known boundary point.

Module Contents#

constraint_explorer.explore_constraint_boundary_2d(prob, param1, param2, constraint_name, param1_range, param2_range, initial_resolution=(20, 20), refinement_levels=0, refinement_factor=2, constraint_tolerance=0.1, feasibility_threshold=1.0)#

Explore 2D parameter space to find constraint boundary.

Evaluates the constraint on a grid of parameter values to identify the boundary between feasible and infeasible regions. Optionally performs adaptive mesh refinement near the boundary for improved accuracy.

Parameters:
  • prob (om.Problem) – OpenMDAO Problem instance (must be set up).

  • param1 (str) – Name of first input parameter to vary.

  • param2 (str) – Name of second input parameter to vary.

  • constraint_name (str) – Name of constraint output to evaluate.

  • param1_range (tuple of float) – (min, max) range for param1.

  • param2_range (tuple of float) – (min, max) range for param2.

  • initial_resolution (tuple of int, optional) – (n1, n2) grid resolution for initial sampling. Default is (20, 20).

  • refinement_levels (int, optional) – Number of adaptive refinement iterations. Default is 0 (no refinement).

  • refinement_factor (int, optional) – Grid subdivision factor near boundaries. Default is 2.

  • constraint_tolerance (float, optional) – Distance from threshold to consider “near boundary”. Default is 0.1.

  • feasibility_threshold (float, optional) – Constraint value for feasibility (>= threshold is feasible). Default is 1.0.

Returns:

Dictionary containing: - ‘param1_values’: Array of param1 evaluation points - ‘param2_values’: Array of param2 evaluation points - ‘constraint_values’: Array of constraint values - ‘feasible_mask’: Boolean array (True where feasible) - ‘boundary_points’: List of (param1, param2) tuples near boundary - ‘num_evaluations’: Total number of system evaluations

Return type:

dict

Notes

The function uses OpenMDAO’s prob.set_val() and prob.run_model() to evaluate the system at each grid point. The constraint is considered feasible when its value is >= feasibility_threshold.

For normalized OpenMDAO constraints, feasibility_threshold=1.0 means the constraint is satisfied.

Examples

>>> prob = om.Problem()
>>> # ... setup problem ...
>>> result = explore_constraint_boundary_2d(
...     prob,
...     "frequency",
...     "voltage",
...     "hv_operating_window_satisfied",
...     param1_range=(1e3, 1e6),
...     param2_range=(1e3, 2e4),
... )
>>> print(f"Evaluated {result['num_evaluations']} points")
constraint_explorer.trace_constraint_boundary_2d(prob, param1, param2, constraint_name, start_point, step_size=0.01, max_points=100, constraint_tolerance=0.001, feasibility_threshold=1.0)#

Trace constraint boundary curve starting from a known boundary point.

Uses a predictor-corrector method to follow the constraint boundary curve in parameter space. This is more efficient than grid sampling for smooth, well-defined boundaries.

Parameters:
  • prob (om.Problem) – OpenMDAO Problem instance (must be set up).

  • param1 (str) – Name of first input parameter.

  • param2 (str) – Name of second input parameter.

  • constraint_name (str) – Name of constraint output to trace.

  • start_point (tuple of float) – (param1_val, param2_val) starting point on or near the boundary.

  • step_size (float, optional) – Arc length step size along curve. Default is 0.01 (relative to parameter ranges).

  • max_points (int, optional) – Maximum number of points to trace. Default is 100.

  • constraint_tolerance (float, optional) – How close to threshold to maintain (convergence criterion). Default is 1e-3.

  • feasibility_threshold (float, optional) – Constraint value defining the boundary. Default is 1.0.

Returns:

Array of shape (n_points, 2) containing (param1, param2) boundary points.

Return type:

np.ndarray

Notes

The algorithm: 1. Project start_point onto boundary if needed (solve constraint = threshold) 2. Compute constraint gradient via finite differences 3. Step along tangent direction (perpendicular to gradient) 4. Project back to boundary using Newton iteration 5. Repeat until domain boundary reached or max_points exceeded

Examples

>>> prob = om.Problem()
>>> # ... setup problem ...
>>> boundary = trace_constraint_boundary_2d(
...     prob,
...     "frequency",
...     "voltage",
...     "hv_operating_window_satisfied",
...     start_point=(10e3, 5000.0),
... )