DVConstraint

The main purpose of this class is to place linear constraints on design variables within the same component. The constraints are of the form:

c = a_0 * dv_0 + a_1 * dv_1 + ... + a_n * dv_n

Where which design variables to include (dv_0, dv_1, etc.) and the corresponding weights (a_0, a_1, etc.) are defined by the user.

As an example, this constraint can be used to enforce ply fraction constraints for composite design optimization:

pf_0 + pf_45 + pf_m45 + pf_90 = 1.0

Or to enforce that stiffener and panel thicknesses of a blade-stiffened panel do not differ by too much:

-delta_t < st - pt < delta_t

For applying constraints on design variables across components, see AdjacencyConstraint.

Note

This class should be created using the pyTACS.createDVConstraint method.

API Reference

class tacs.constraints.DVConstraint(name, assembler, comm, outputViewer=None, meshLoader=None, options=None)[source]

NOTE: This class should not be initialized directly by the user. Use pyTACS.createDVConstraint instead.

Parameters:
  • name (str) -- Name of this tacs problem

  • assembler (TACS.Assembler) -- Cython object responsible for creating and setting tacs objects used to solve problem

  • comm (mpi4py.MPI.Intracomm) -- The comm object on which to create the pyTACS object.

  • outputViewer (TACS.TACSToFH5) -- Cython object used to write out f5 files that can be converted and used for postprocessing.

  • meshLoader (pymeshloader.pyMeshLoader) -- pyMeshLoader object used to create the assembler.

  • options (dict) -- Dictionary holding problem-specific option parameters (case-insensitive).

addConstraint(conName, compIDs=None, lower=-1e+20, upper=1e+20, dvIndices=0, dvWeights=1.0)[source]

Generic method to adding a new constraint set for TACS.

Parameters:
  • conName (str) -- The user-supplied name for the constraint set. This will typically be a string that is meaningful to the user

  • compIDs (list[int] or None) -- List of compIDs to select. One constraint will be added for each component. If None, all compIDs will be selected. Defaults to None.

  • lower (float or complex) -- lower bound for constraint. Defaults to -1e20.

  • upper (float or complex) -- upper bound for constraint. Defaults to 1e20.

  • dvIndices (int or array-like[int]) -- Index numbers of element DVs to be used in constraint. Defaults to 0.

  • dvWeights (float or complex or array-like[float] or array-like[complex]) -- Linear scaling factors for each DV used in constraint definition. If list, should match length of dvIndices. Defaults to 1's.

evalConstraints(funcs, evalCons=None, ignoreMissing=False)[source]

Evaluate values for constraints. The constraints corresponding to the strings in evalCons are evaluated and updated into the provided dictionary.

Parameters:
  • funcs (dict) -- Dictionary into which the constraints are saved.

  • evalCons (iterable object containing strings.) -- If not none, use these constraints to evaluate.

  • ignoreMissing (bool) -- Flag to supress checking for a valid constraint. Please use this option with caution.

Examples

>>> funcs = {}
>>> dvConstraint.evalConstraints(funcs, 'LE_SPAR')
>>> funcs
>>> # Result will look like (if DVConstraint has name of 'c1'):
>>> # {'c1_LE_SPAR': array([12354.10])}
evalConstraintsSens(funcsSens, evalCons=None)[source]

This is the main routine for returning useful (sensitivity) information from constraint. The derivatives of the constraints corresponding to the strings in evalCons are evaluated and updated into the provided dictionary. The derivitives with respect to all design variables and node locations are computed.

Parameters:
  • funcsSens (dict) -- Dictionary into which the derivatives are saved.

  • evalCons (iterable object containing strings) -- The constraints the user wants returned

Examples

>>> funcsSens = {}
>>> dvConstraint.evalConstraintsSens(funcsSens, 'LE_SPAR')
>>> funcsSens
>>> # Result will look like (if DVConstraint has name of 'c1'):
>>> # {'c1_LE_SPAR':{'struct':<50x242 sparse matrix of type '<class 'numpy.float64'>' with 100 stored elements in Compressed Sparse Row format>}}
dtype

alias of float64

getConstraintBounds(bounds, evalCons=None)

Get bounds for constraints. The constraints corresponding to the strings in evalCons are evaluated and updated into the provided dictionary.

Parameters:
  • bounds (dict) -- Dictionary into which the constraint bounds are saved. Bounds will be saved as a tuple: (lower, upper)

  • evalCons (iterable object containing strings.) -- If not none, use these constraints to evaluate.

Examples

>>> conBounds = {}
>>> tacsConstraint.getConstraintBounds(conBounds, 'LE_SPAR')
>>> conBounds
>>> # Result will look like (if TACSConstraint has name of 'c1'):
>>> # {'c1_LE_SPAR': (array([-1e20]), array([1e20]))}
getConstraintKeys()

Return a list of the current constraint key names

Returns:

conNames -- List containing user-defined names for constraint groups added so far.

Return type:

list[str]

getConstraintSizes(sizes, evalCons=None)

Get number for constraint equations in each set. The constraints corresponding to the strings in evalCons are evaluated and updated into the provided dictionary.

Parameters:
  • sizes (dict) -- Dictionary into which the constraint sizes are saved.

  • evalCons (iterable object containing strings.) -- If not none, use these constraints to evaluate.

Examples

>>> conSizes = {}
>>> tacsConstraint.getConstraintSizes(conSizes, 'LE_SPAR')
>>> funconSizescs
>>> # Result will look like (if TACSConstraint has name of 'c1'):
>>> # {'c1_LE_SPAR': 10}
getDesignVarRange()

get the lower/upper bounds for the design variables.

Returns:

  • xlb (numpy.ndarray) -- The design variable lower bound.

  • xub (numpy.ndarray) -- The design variable upper bound.

getDesignVars()

Get the current set of design variables for this problem.

Returns:

x -- The current design variable vector set in tacs.

Return type:

numpy.ndarray

getNodes()

Return the mesh coordinates of this problem.

Returns:

coords -- Structural coordinate in array of size (N * 3) where N is the number of structural nodes on this processor.

Return type:

numpy.ndarray

getNumCoordinates()

Return the number of mesh coordinates on this processor.

Returns:

ncoords -- Number of mesh coordinates on this processor.

Return type:

int

getNumDesignVars()

Return the number of design variables on this processor.

Returns:

ndvs -- Number of design variables on this processor.

Return type:

int

getNumOwnedNodes()

Get the number of nodes owned by this processor.

Returns:

nnodes -- Number of nodes on this processor.

Return type:

int

getNumVariables()

Return the number of degrees of freedom (states) that are on this processor

Returns:

nstate -- number of states.

Return type:

int

getOption(name)

Get a solver option value. The name is not case sensitive.

Parameters:

name (str) -- Name of option to get

getVarsPerNode()

Get the number of variables per node for the model.

Returns:

vpn -- Number of variables per node.

Return type:

int

classmethod printDefaultOptions()

Prints a nicely formatted dictionary of all the default solver options to the stdout

printModifiedOptions()

Prints a nicely formatted table of all the options that have been modified from their defaults

printOptions()

Prints a nicely formatted dictionary of all the current solver options to the stdout on the root processor

setDesignVars(x)

Update the design variables used by tacs.

Parameters:

x (numpy.ndarray or dict or tacs.TACS.Vec) -- The variables (typically from the optimizer) to set. It looks for variable in the self.varName attribute if in dict.

setNodes(Xpts)

Set the mesh coordinates of the structure.

Parameters:

Xpts (numpy.ndarray) -- Structural coordinate in array of size (N * 3) where N is the number of structural nodes on this processor.

setOption(name, value)

Set a solver option value. The name is not case sensitive.

Parameters:
  • name (str) -- Name of option to modify

  • value (depends on option) -- New option value to set

setOptions(options)

Set multiple solver options at once. The names are not case sensitive.

Parameters:

options (dict) -- Dictionary of option names and values to set

setVarName(varName)

Set a name for the structural variables in pyOpt. Only needs to be changed if more than 1 pytacs object is used in an optimization

Parameters:

varName (str) -- Name of the structural variable used in addVarGroup().