Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions pyoptsparse/pyOpt_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import copy
import os
from typing import Callable, Dict, Iterable, List, Optional, Tuple, Union
import warnings

# External modules
import numpy as np
Expand Down Expand Up @@ -368,8 +369,10 @@ def addConGroup(
wrt: Optional[Union[str, Iterable[str]]] = None,
jac=None,
):
r"""Add a group of variables into a variable set. This is the main
function used for adding variables to pyOptSparse.
r"""Add a group of constraints into the constraint set. This is the main function used for adding constraints to
pyOptSparse.

To define equality constraints, set both the lower and upper bounds to the same value.

Parameters
----------
Expand All @@ -379,27 +382,20 @@ def addConGroup(
nCon : int
The number of constraints in this group

lower : scalar or array
The lower bound(s) for the constraint. If it is a scalar,
it is applied to all nCon constraints. If it is an array,
the array must be the same length as nCon.
lower : scalar or array, optional
The lower bound(s) for the constraint. If it is a scalar, it is applied to all nCon constraints. If it is an
array, the array must be of length nCon. By default no lower bound is applied.

upper : scalar or array
The upper bound(s) for the constraint. If it is a scalar,
it is applied to all nCon constraints. If it is an array,
the array must be the same length as nCon.
upper : scalar or array, optional
Identical to ``lower``, but for the upper bound(s).

scale : scalar or array
scale : scalar or array, optional
A scaling factor for the constraint. It is generally advisable to have most optimization constraint around
the same order of magnitude. By default 1.0.

A scaling factor for the constraint. It is generally
advisable to have most optimization constraint around the
same order of magnitude.

linear : bool
Flag to specify if this constraint is linear. If the
constraint is linear, both the ``wrt`` and ``jac`` keyword
arguments must be given to specify the constant portion of
the constraint Jacobian.
linear : bool, optional
Flag to specify if this constraint is linear. If the constraint is linear, both the ``wrt`` and ``jac``
keyword arguments must be given to specify the constant portion of the constraint Jacobian. By default False.

The intercept term of linear constraints must be supplied as
part of the bound information. The linear constraint :math:`g_L \leq Ax + b \leq g_U`
Expand All @@ -410,12 +406,12 @@ def addConGroup(

jac = {"dvName" : A, ...}, lower = gL - b, upper = gU - b

wrt : iterable (list, set, OrderedDict, array etc)
'wrt' stand for stands for 'With Respect To'. This
specifies for what dvs have non-zero Jacobian values
for this set of constraints. The order is not important.
wrt : iterable (list, set, OrderedDict, array etc), optional
'wrt' stands for 'With Respect To'. This specifies which dvs this constraint is assumed to depend on, and
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be expanded upon by explaining that it needs to be an iterable of str which specifies the DVGroups which are sensitive to.

therefore which blocks of the Jacobian will have non-zero values. The order is not important. By default the
constraint is assumed to depend on all design variables.

jac : dictionary
jac : dictionary, optional
For linear and sparse non-linear constraints, the constraint
Jacobian must be passed in. The structure of jac dictionary
is as follows:
Expand Down Expand Up @@ -456,6 +452,11 @@ def addConGroup(
the Jacobian change throughout the optimization. This
stipulation is automatically checked internally.
"""
if lower is None and upper is None:
warnings.warn(
f"No upper or lower bounds were given for constraint '{name}'. This constraint will have no effect.",
stacklevel=2,
)
self.finalized = False
if name in self.constraints:
raise KeyError(f"The supplied name '{name}' for a constraint group has already been used.")
Expand Down
Loading