constraints.Constraint
constraints.Constraint(weight=1.0)
Base class for geometric constraints.
Constraints are represented as residual equations c(x) = 0. The Jacobian ∂c/∂x is computed via AD over the flat residual function (:func:cadjoint.constraints.residual.build_residual_fn), not per-constraint.
Subclasses must implement: - compute_residual(): Returns constraint violation c(x) - dof_reduction(): Number of DOF this constraint removes - get_parameters(): List of parameters involved in this constraint
Attributes
| Name | Type | Description |
|---|---|---|
| weight | float | Scalar applied to this constraint’s residuals in penalty-based optimization. Use to normalize across types or scales — e.g. weight=1/distance makes a DistanceConstraint residual dimensionless. Defaults to 1.0. |
Methods
| Name | Description |
|---|---|
| compute_residual | Compute constraint residual c(x). |
| dof_reduction | Number of degrees of freedom this constraint removes. |
| get_parameters | Get list of parameters involved in this constraint. |
compute_residual
constraints.Constraint.compute_residual(param_values)
Compute constraint residual c(x).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| param_values | dict[str, Array] | Dictionary mapping parameter names to their current values | required |
Returns
| Name | Type | Description |
|---|---|---|
| Array | Constraint residual (scalar or array). Zero means constraint is satisfied. |
dof_reduction
constraints.Constraint.dof_reduction()
Number of degrees of freedom this constraint removes.
Returns
| Name | Type | Description |
|---|---|---|
| int | Number of independent constraint equations (typically 1) |
get_parameters
constraints.Constraint.get_parameters()
Get list of parameters involved in this constraint.
Returns
| Name | Type | Description |
|---|---|---|
| list[Parameter] | List of Parameter objects that this constraint depends on |