topoptlab.fem module
- class topoptlab.fem.FEM_Phys[source]
Bases:
ABCBase class for different FEM physical problems.
- abstractmethod assemble_system()[source]
Assemble linear system for the global matrix.
- Return type:
None
- abstractmethod solve()[source]
Solve generic problem. This calls _solve or _nonlinsolve depending on the function arguments.
- Return type:
None
- topoptlab.fem.apply_bc(K: sparray, solver: str, free: None | ndarray = None, fixed: None | ndarray = None) sparray | spmatrix[source]
Apply boundary conditions to matrix K. At the moment only implements Dirichlet boundary conditions equal to zero.
- Parameters:
K (scipy.sparse.sparray shape (nodf,ndof)) – matrix.
free (np.ndarray) – indices of variables for which we solve.
fixed (np.ndarray) – indices of variables to be set to zero.
- Returns:
K – new matrix with applied boundary conditions.
- Return type:
scipy.sparse.sparray or cvxopt.spmatrix shape (ndof_new,ndof_new)
- topoptlab.fem.assemble_matrix(sK: ndarray, iK: ndarray, jK: ndarray, ndof: int, solver: str, springs: None | List) csc_array[source]
Assemble matrix from indices.
- Parameters:
sK (np.ndarray) – element degree of freedom matrix.
sK – matrix values.
iK (np.ndarray) – matrix row indices.
jK (np.ndarray) – matrix column indices.
ndof (int) – number of degrees of freedom
solver (str) – solver used to solve the linear system.
springs (list) – contains two np.ndarrays. The first one contains the indices of the degrees of freedom to which the springs are attached. The second one contains the spring constants.
- Returns:
M – assembled matrix.
- Return type:
scipy.sparse.csc_array, shape (ndof,ndof)
- topoptlab.fem.create_matrixinds(edofMat: ndarray, mode: str = 'full') Tuple[ndarray, ndarray][source]
Create matrix indices to set up FE linear system / matrix.
- Parameters:
edofMat (np.ndarray (nel,n_nodedof)) – element degree of freedom matrix.
mode (str) – construct .
- Returns:
iM (np.ndarray shape (N)) – row indices for matrix construction.
jM (np.ndarray shape (N)) – column indices for matrix construction.
- topoptlab.fem.deleterowcol(A: csc_array, delrow: ndarray, delcol: ndarray) coo_array[source]
Copied from the topopt_cholmod.py code by Niels Aage and Villads Egede.
- Parameters:
A (scipy.sparse.sparray shape (nodf,ndof)) – matrix.
delrow (np.ndarray) – rows to delete .
delcol (np.ndarray) – columns to delete .
- Returns:
A – new matrix with rows and columns deleted.
- Return type:
coo_array shape (ndof_new,ndof_new)
- topoptlab.fem.get_integrpoints(ndim: int, nq: int, method: str | Callable) Tuple[ndarray, ndarray][source]
Get integration points and weights for numerical quadrature of integrals in interval [-1,1].
- Parameters:
ndim (int) – number of spatial dimensions.
nq (int) – number of integration/quadrature points.
method (str or callable) – name of quadrature method or function/callable that returns coordinates of quadrature points and weights. Currently only ‘gauss-legendre’, ‘gauss-lobatto’, ‘gauss-hermite’, ‘gauss-chebyshev’ and ‘gauss-laguerre’ are supported.
- Returns:
x (np.ndarray, shape (nq,ndim)) – coordinates of quadrature point.
w (np.ndarray, shape (nq)) – weight of quadrature points.
- topoptlab.fem.interpolate(ue: ndarray, xi: ndarray, eta: ndarray, zeta: None | ndarray = None, shape_functions: Callable = <function shape_functions>) ndarray[source]
Interpolate node values in each element. Coordinates are assumed to be in the reference domain.
- Parameters:
ue (np.ndarray,shape (nels,nedof).) – node values used for interpolation.
xi (np.ndarray) – x coordinate of shape (nels). Coordinates are assumed to be in the reference domain.
eta (np.ndarray) – y coordinate of shape (ncoords). Coordinates are assumed to be in the reference domain.
zeta (np.ndarray or None) – z coordinate of shape (ncoords). Coordinates are assumed to be in the reference domain.
shape_functions (callable) – shape functions of respective element
- Returns:
u – interpolated state variable.
- Return type:
np.ndarray, shape (nels,nnodedof)
- topoptlab.fem.update_indices(indices: ndarray, fixed: ndarray, mask: ndarray) ndarray[source]
Update the indices for the stiffness matrix construction by kicking out the fixed degrees of freedom and renumbering the indices. This is useful only if just one set of boundary conditions needs to be solved.
- Parameters:
indices (np.ndarray) – indices of degrees of freedom used to construct the stiffness matrix.
fixed (np.ndarray) – indices of fixed degrees of freedom.
mask (np.ndarray) – mask to kick out fixed degrees of freedom.
- Returns:
indices – updated indices.
- Return type:
np.ndarray