topoptlab.gmg module

topoptlab.gmg.check_stride(nelx: int, nely: int, nelz: None | int, stride: int) None[source]

.

Parameters:
  • nelx (int) – number of elements in x direction.

  • nelx – number of elements in y direction.

  • nelx – number of elements in z direction.

  • stride (int) – coarsening factor in each coordinate direction.

Return type:

None

topoptlab.gmg.create_coarse_inds(nelx: int, nely: int, nelz: None | int = None, ndof: int = 1, stride: int = 2) ndarray[source]

Create degree of freedom indices for coarse degrees of freedom for a geometric multigrid (GMG) solver.

Parameters:
  • nelx (int) – number of elements in x direction.

  • nely (int) – number of elements in y direction.

  • nelz (int) – number of elements in z direction.

  • ndof (int) – number of nodal degrees of freedom.

  • stride (int) – coarsening factor in each coordinate direction.

Returns:

indices – degree of freedom indices of coarse dofs.

Return type:

np.ndarray

topoptlab.gmg.create_coarse_mask(nelx: int, nely: int, nelz: None | int = None, ndof: int = 1, stride: int = 2) ndarray[source]

Create a boolean mask identifying the coarse-grid degrees of freedom for a geometric multigrid (GMG) solver.

Parameters:
  • nelx (int) – number of elements in x direction.

  • nely (int) – number of elements in y direction.

  • nelz (int) – number of elements in z direction.

  • ndof (int) – number of nodal degrees of freedom.

  • stride (int) – coarsening factor in each coordinate direction.

Returns:

mask – mask for degree of freedom indices of coarse dofs.

Return type:

np.ndarray

topoptlab.gmg.create_gmg(A: sparray, interpol: Callable, nlevels: int) Tuple[ndarray, int][source]

Create a generic geometric multigrid (GMG) solver for the linear problem Ax=b. The key ingredients in are i) coarse/fine splitting ii) interpolation method. The first is typically based on some notion of the strength/importance of connections between two variables via the matrix entry a_{ij} of the matrix A.

Parameters:
  • A (scipy.sparse.sparse_array) – system matrix (e. g. stiffness matrix)

  • interpol (callable) – interpolation method.

  • nlevels (int) – number of grid levels.

Returns:

prolongators – hierarchy of prolongators.

Return type:

list of sparse arrays

topoptlab.gmg.create_interpolator(nelx: int, nely: int, nelz: None | int = None, ndof: int = 1, stride: int | Tuple = 2, pbc: Tuple | bool = False, shape_fncts: None | Callable = None) sparray[source]

Construct the interpolation (prolongation) operator for geometric multigrid (GMG).

The interpolation maps values from coarse grid nodes to fine grid nodes using shape functions. The stride determines the spacing between coarse grid nodes in each coordinate direction. For example, a stride of 2 means that every second fine grid node is designated as a coarse grid node.

Parameters:
  • nelx (int) – Number of elements in the x direction.

  • nely (int) – Number of elements in the y direction.

  • nelz (int) – Number of elements in the z direction (for 3D problems).

  • ndof (int) – Number of degrees of freedom per node.

  • stride (int) – coarsening factor in each coordinate direction. Defines the “stride” between coarse grid nodes.

  • pbc (bool or tuple) – flags for periodic boundary conditions.

  • shape_fncts (callable) – Shape function evaluator. If None, bilinear quadrilateral (2D) or trilinear hexahedron (3D) shape functions are used.

Returns:

interpolator – Interpolation operator mapping coarse grid values to fine grid values.

Return type:

scipy.sparse.sp_array