topoptlab.geometries module

topoptlab.geometries.ball(nelx: int, nely: int, nelz: int, center: ndarray, radius: float, fill_value: int = 1) ndarray[source]

Create element flags for a ball located at the specified center with the specified radius.

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.

  • center (list or tuple or np.ndarray) – coordinates of sphere center.

  • radius (float) – sphere radius.

  • fill_value (int) – value that is prescribed to elements within ball.

Returns:

el_flags – element flags of shape (nelx*nely*nelz)

Return type:

np.ndarray

topoptlab.geometries.bounding_rectangle(nelx: int, nely: int, faces: List = ['b', 't', 'r', 'l']) ndarray[source]

Create element flags for a bounding box of one element thickness. It is possible to draw only specified faces of the bounding box.

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

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

  • faces (list of str) – which faces of bounding box are supposed to be drawn. Possible values are “b” for bottom, “t” for top, “l” for left and “r” for right.

Returns:

el_flags – element flags of shape (nelx*nely)

Return type:

np.ndarray

topoptlab.geometries.cube_mask(coords: ndarray, low: ndarray, upp: ndarray, **kwargs: Any) ndarray[source]

Take coordinate and return mask of coordinates lying between the lower and upper boundaries.

Parameters:
  • coords (np.ndarray) – element coordinates of shape shape (ncoords,ndim).

  • low (np.ndarray) – lower boundaries of the cuboid of shape shape (ndim).

  • upp (np.ndarray) – upper boundaries of the cuboid of shape shape (ndim).

Returns:

mask – mask for coordinates of shape (ncoords).

Return type:

np.ndarray

topoptlab.geometries.diracdelta(nelx: int, nely: int, nelz: None | int = None, location: None | int = None) ndarray[source]

Create element flags for a Dirac delta located at the specified location. Depending on the location and the number of elements in each direction this results in either a single element with flag 1 or 4/8 elements in 2/3 dimensions.

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.

  • location (list or tuple or np.ndarray) – coordinate of Dirac delta.

Returns:

el_flags – element flags / densities

Return type:

np.ndarray shape (nelx*nely) or shape (nelx*nely*nelz)

topoptlab.geometries.elids_in_mask(el: ndarray, spatial_mask_fnc: Callable, mask_kw: Dict, nelx: int, nely: int, nelz: None | int = None, l: float | List | ndarray = [1.0, 1.0, 1.0], g: List | ndarray = [0.0, 0.0], **kwargs: Any) ndarray[source]

Find element IDs within an interval of cartesian coordinates in the usual regular grid.

Parameters:
  • el (np.ndarray) – element IDs of shape (nel).

  • spatial_mask_fnc (callable) – function that creates the spatial mask based on coordinates and mask_kw.

  • mask_kw – keywords for the spatial mask.

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

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

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

  • l (float or list) – side length of elements.

  • g (float or list) – angle of elements. if both angles zero, element is rectangular/cuboid.

Returns:

indices – element indices shape (n).

Return type:

np.ndarray

topoptlab.geometries.ellipse(nelx: int, nely: int, center: ndarray, ax_half_lengths: ndarray, fill_value: int = 1) ndarray[source]

Create element flags for an axis-aligned ellipse.

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

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

  • center (np.ndarray) – (cx, cy) coordinates of ellipse center.

  • ax_half_lengths (np.ndarray) – (a, b) ellipse semi-axes lengths.

  • fill_value (int) – value assigned to elements inside the ellipse.

Returns:

el_flags – element flags of shape (nelx*nely)

Return type:

np.ndarray

topoptlab.geometries.ellipsoid(nelx: int, nely: int, nelz: int, center: ndarray, ax_half_lengths: ndarray, fill_value: int = 1) ndarray[source]

Create element flags for an axis-aligned ellipse.

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

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

  • center (np.ndarray) – (cx, cy, cz) coordinates of ellipse center.

  • ax_half_lengths (np.ndarray) – (a, b,c) ellipse semi-axes lengths.

  • fill_value (int) – value assigned to elements inside the ellipse.

Returns:

el_flags – element flags of shape (nelx*nely)

Return type:

np.ndarray

topoptlab.geometries.nodeids_in_mask(node_id: ndarray, spatial_mask_fnc: Callable, mask_kw: Dict, nelx: int, nely: int, nelz: None | int = None, l: float | List | ndarray = [1.0, 1.0, 1.0], g: List | ndarray = [0.0, 0.0], **kwargs: Any) ndarray[source]

Find node IDs within an interval of cartesian coordinates in the usual regular grid.

Parameters:
  • nd_id (np.ndarray) – node IDs of shape (n_node).

  • spatial_mask_fnc (callable) – function that creates the spatial mask based on coordinates and mask_kw.

  • mask_kw – keywords for the spatial mask.

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

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

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

  • l (float or list) – side length of elements.

  • g (float or list) – angle of elements. if both angles zero, element is rectangular/cuboid.

Returns:

indices – node indices shape (n).

Return type:

np.ndarray

topoptlab.geometries.slab(nelx: int, nely: int, center: ndarray, widths: None | List = None, fill_value: int = 1) ndarray[source]

Create element flags for a slab located at the specified center with the specified width in each dimension.

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

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

  • center (list or tuple or np.ndarray) – coordinates of slab center.

  • widths (iterable of floats and None) – width in x and y direction. If one entry is None or it is width is None, then nelx/nely is taken as width in this direction.

  • fill_value (int) – value that is prescribed to elements within sphere.

Returns:

el_flags – element flags of shape (nelx*nely)

Return type:

np.ndarray

topoptlab.geometries.sphere(nelx: int, nely: int, center: ndarray, radius: float, fill_value: int = 1) ndarray[source]

Create element flags for a sphere located at the specified center with the specified radius.

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

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

  • center (np.ndarray) – coordinates of sphere center.

  • radius (float) – sphere radius.

  • fill_value (int) – value that is prescribed to elements within sphere.

Returns:

el_flags – element flags of shape (nelx*nely)

Return type:

np.ndarray