Topology Optimization Utilities¶
TMR implements the class TopoProblem
which is designed for topology optimization with ParOpt.
This class can be set up to contain information about how to evaluate the objective function and constraints using a TACS.Assembler object.
The adjoint derivative calculations for all members are implemented within the code.
-
class
tmr.TMR.
TopoProblem
¶ Creates and stores information for topology optimization problems
-
addBucklingConstraint
()¶ Add buckling/natural frequency constraints
-
addConstraints
(self, case, funcs, offset, scale)¶ Add a list of constraints for the specified load case. The constraints are specified as follows:
scale[i]*(funcs[i] + offset[i]) >= 0
-
addFrequencyConstraint
()¶ Add buckling/natural frequency constraints
-
addLinearConstraints
(self, vecs, offset)¶ Add a set of load-case independent linear constraints represented by the provided vectors. The constraints are imposed as:
dot(vecs[i], x) + offset[i] >= 0.0
-
addStressConstraint
(self, case, sc, offset=1.0, scale=1.0)¶ Add a stress constraint formulated with stress reconstruction.
scale*(sc + offset) >= 0
-
getAssembler
(self)¶ Get the Assembler object associated with the finest finite-element mesh
- Returns
The finest Assembler ojbect
- Return type
Assembler
-
getFilter
(self)¶ Get the OctForest or QuadForest object associated with the finest topology opt discretization.
- Returns
The forest associated with the finest mesh
- Return type
-
getNumLoadCases
(self)¶ Get the number of load cases set in the optimization problem
- Returns
The number of load cases
- Return type
-
initialize
(self)¶ Initialize the topology optimization instance. The optimization problem cannot be solved before this call. After this call, no more constraints can be added and the design problem is considered fixed.
-
setF5EigenOutputFlags
(self, freq, elem_type, flag)¶ Set the output frequency and data for generating an .f5 file for eigenvector visualization. The elem_type and flag arguments dictate the type of data to be written to the .f5 file.
-
setF5OutputFlags
(self, freq, elem_type, flag)¶ Set the output frequency and data for generating an .f5 file for solution visualization. The elem_type and flag arguments dictate the type of data to be written to the .f5 file.
-
setInitDesignVars
(self, pvec, lbvec, ubvec)¶ Set the initial design variables and lower and upper bounds.
- Parameters
pvec (PVec) – ParOpt.PVec class storing the initial design vector
lbvec (PVec) – ParOpt.PVec class storing the lower bound vector
ubvec (PVec) – ParOpt.PVec class storing the upper bound vector
-
setIterationCounter
(self, count)¶ Set an offset for the iteration counter. All iteration counts will start from the provided value.
- Parameters
count (int) – Iteration counter offset >= 0
-
setLoadCases
(self, forces)¶ Set the load cases to use within the optimization problem. The input list of forces is used as a vector of right-hand-sides within the TopoProblem solution method.
- Parameters
forces (list) – A list of TACS.Vec vector instances
-
setObjective
(self, weights, funcs=None)¶ Set the objective function for the design problem.
If no list of functions is provided, the weighted compliance is assumed to be the objective. Otherwise a weighted sum of the functions evaluaed for each load case is used. Note that if a weight is set to zero, then the function and its gradient are not evaluated.
-
-
class
While you can create the TopoProblem
from scratch, there are several utilities that can assist you with the creation of this object.
createTopoProblem()
generates a problem class with a specified hierarchy of octree or quadtree meshes.
The construction of the finite-element discretization and the topology parametrization are problem-specific, so these are generated through a callback.
Several additional helper functions are implemented to enable the creation of load vectors: computeVertexLoad()
creates a load vector from forces at named vertices,
computeTractionLoad()
creates a load vector based on traction on named edges or faces.
interpolateDesignVec()
interpolates between design vectors after a refinement step.
-
tmr.TopOptUtils.
createTopoProblem
(forest, callback, filter_type, nlevels=2, repartition=True, design_vars_per_node=1, s=2.0, N=10, r0=0.05, lowest_order=2, ordering=5, scale_coordinate_factor=1.0)[source]¶ Create a topology optimization problem instance and a hierarchy of meshes. This code takes in the OctForest or QuadForest on the finest mesh level and creates a series of coarser meshes for analysis and optimization. The discretization at each level is created via a callback function that generates the appropriate TACSCreator object and its associated filter (the QuadForest or OctForest on which the design parametrization is defined.) The code then creates a TMRTopoFilter class which stores information about the design parametrization and hierarchy. It creates a multigrid object and finally a TMRTopoProblem instance for optimization.
The callback function takes in a forest object, corresponding to the finite- element discretization and returns a creator object and a filter object in the following form:
creator, filter = callback(forest)
- Parameters
callback – A callback function that takes in the forest and returns the filter and the associated creator class
filter_type (str) – Type of filter to create
forest (TMROctForest or TMRQuadForest) – Forest type
repartition (bool) – Repartition the mesh
design_vars_per_node (int) – number of design variables for each node
s (float) – Matrix filter smoothing parameter
N (int) – Matrix filter approximation parameter
r0 (float) – Helmholtz filter radius
lowest_order (int) – Lowest order mesh to create
ordering – TACS Assembler ordering type
scale_coordinate_factor (float) – Scale all coordinates by this factor
- Returns
The allocated topology optimization problem
- Return type
problem (TopoProblem)
-
tmr.TopOptUtils.
computeVertexLoad
(name, forest, assembler, point_force)[source]¶ Add a load at vertices with the given name value. The assembler object must be created from the forest. The point_force must be equal to the number of variables per node in the assembler object.
- Parameters
name (str) – Name of the surface where the traction will be added
forest (QuadForest or OctForest) – Forest for the finite-element mesh
assembler (Assembler) – TACSAssembler object for the finite-element problem
point_force (list) – List of point forces to apply at the vertices
- Returns
A force vector containing the point load
- Return type
Vec
-
tmr.TopOptUtils.
computeTractionLoad
(name, forest, assembler, trac)[source]¶ Add a surface traction to all quadrants or octants that touch a face or edge with the given name. The assembler must be created from the provided forest. The list trac must have a traction for each face (6) for octants or each edge (4) for quadrants.
Note: This code uses the fact that the getOctsWithName or getQuadsWithName returns the local face or edge index touching the surface or edge in the info member.
- Parameters
name (str) – Name of the surface where the traction will be added
forest (QuadForest or OctForest) – Forest for the finite-element mesh
assembler (Assembler) – TACSAssembler object for the finite-element problem
trac (list) – List of tractions, one for each possible face/edge orientation
- Returns
A force vector containing the traction
- Return type
Vec
-
tmr.TopOptUtils.
compute3DTractionLoad
(name, forest, assembler, tr)[source]¶ Add a constant surface traction to all octants that touch a face or edge with the given name.
- Parameters
forest (QuadForest or OctForest) – Forest for the finite-element mesh
name (str) – Name of the surface where the traction will be added
assembler (Assembler) – TACSAssembler object for the finite-element problem
tr (list) – The 3D components of the traction.
- Returns
A force vector containing the traction
- Return type
Vec
-
tmr.TopOptUtils.
interpolateDesignVec
(orig_filter, orig_vec, new_filter, new_vec)[source]¶ This function interpolates a design vector from the original design space defined on an OctForest or QuadForest and interpolates it to a new OctForest or QuadForest.
This function is used after a mesh adaptation step to get the new design space.
- Parameters
orig_filter (OctForest or QuadForest) – Original filter Oct or QuadForest object
orig_vec (PVec) – Design variables on the original mesh in a ParOpt.PVec
new_filter (OctForest or QuadForest) – New filter Oct or QuadForest object
new_vec (PVec) – Design variables on the new mesh in a ParOpt.PVec (set on ouput)
-
tmr.TopOptUtils.
addNaturalFrequencyConstraint
(problem, omega_min, **kwargs)[source]¶ Add a natural frequency constraint to a TopoProblem optimization problem
This function automatically sets good default arguments that can be overridden with keyword arguments passed in through kwargs.
- Parameters
problem (TopoProblem) – TopoProblem optimization problem
omega_min (float) – Minimum natural frequency, Hz
**kwargs – Frequency constraint parameters; check TMR documentation for more detail
-
tmr.TopOptUtils.
densityBasedRefine
(forest, assembler, index=0, lower=0.05, upper=0.5, reverse=False, min_lev=0, max_lev=30)[source]¶ Apply a density-based refinement criteria.
This function takes in a Quad or OctForest that has been used for analysis and its corresponding Assembler object. It then uses the data set in the constitutive object to extract the density within each element. If the density falls below the the bound lower the element is coarsened, if the density exceeds upper the element is refined. If reverse is set, this scheme is reversed so low design values are refined. The refinement is applied directly to the forest.
- Parameters
forest (QuadForest or OctForest) – OctForest or QuadForest to refine
assembler (Assembler) – The TACS.Assembler object associated with forest
index (int) – The index used in the call to getDVOutputValue
lower (float) – the lower limit used for coarsening
upper (float) – the upper limit used for refinement
reverse (bool) – Reverse the refinement scheme
min_lev (int) – Minimum refinement level
max_lev (int) – Maximum refinement level
-
-
tmr.TMR.
convertPVecToVec
(pvec)¶ Converts a ParOpt.PVec class to a TACS.Vec class.
- Parameters
pvec (PVec) – A vector generated by TopoProblem
- Returns
A TACS.Vec instance
- Return type
Vec
-