sktopt.mesh
This package provides mesh utilities and task domain definitions.
- class sktopt.mesh.FEMDomain(basis: CellBasis, dirichlet_nodes: ndarray | list[ndarray] | None, dirichlet_dofs: ndarray | list[ndarray] | None, dirichlet_elements: ndarray | None, dirichlet_values: float | list[float] | None, neumann_nodes: ndarray | list[ndarray] | None, neumann_elements: ndarray | None, neumann_dir_type: str | list[str] | None, neumann_values: float | list[float] | None, robin_facets_ids: ndarray | list[ndarray] | None, robin_nodes: ndarray | list[ndarray] | None, robin_elements: ndarray | None, robin_coefficient: float | list[float] | None, robin_bc_value: float | list[float] | None, design_robin_boundary: bool | None, design_elements: ndarray, free_dofs: ndarray, free_elements: ndarray, all_elements: ndarray, fixed_elements: ndarray, dirichlet_neumann_elements: ndarray, elements_volume: ndarray)
Bases:
objectContainer for storing finite element and optimization-related data used in topology optimization tasks.
This class holds material properties, boundary condition information, designable and non-designable element indices, as well as force vectors and volume data for each element. It is typically constructed using LinearElasticity.from_defaults.
- basis
Finite element basis object associated with the mesh and function space.
- Type:
skfem.Basis
- dirichlet_dofs
Degrees of freedom constrained by Dirichlet (displacement) boundary conditions.
- Type:
np.ndarray
- dirichlet_elements
Elements that contain Dirichlet boundary points.
- Type:
np.ndarray
- neumann_elements
Elements that contain the force application points.
- Type:
np.ndarray
- force
External force vector(s) applied to the system. A list is used when multiple load cases are present.
- Type:
np.ndarray or list of np.ndarray
- design_elements
Indices of elements that are considered designable in the optimization.
- Type:
np.ndarray
- free_dofs
Degrees of freedom that are not fixed by boundary conditions.
- Type:
np.ndarray
- free_elements
Elements associated with the free degrees of freedom.
- Type:
np.ndarray
- all_elements
Array of all element indices in the mesh.
- Type:
np.ndarray
- fixed_elements
Elements excluded from the design domain.
- Type:
np.ndarray
- dirichlet_neumann_elements
Union of Dirichlet and force elements. Useful for identifying constrained and loaded regions.
- Type:
np.ndarray
- elements_volume
Volume of each finite element, used in volume constraints and integration.
- Type:
np.ndarray
- class sktopt.mesh.LinearElasticity(basis: CellBasis, dirichlet_nodes: ndarray | list[ndarray] | None, dirichlet_dofs: ndarray | list[ndarray] | None, dirichlet_elements: ndarray | None, dirichlet_values: float | list[float] | None, neumann_nodes: ndarray | list[ndarray] | None, neumann_elements: ndarray | None, neumann_dir_type: str | list[str] | None, neumann_values: float | list[float] | None, robin_facets_ids: ndarray | list[ndarray] | None, robin_nodes: ndarray | list[ndarray] | None, robin_elements: ndarray | None, robin_coefficient: float | list[float] | None, robin_bc_value: float | list[float] | None, design_robin_boundary: bool | None, design_elements: ndarray, free_dofs: ndarray, free_elements: ndarray, all_elements: ndarray, fixed_elements: ndarray, dirichlet_neumann_elements: ndarray, elements_volume: ndarray, E: float, nu: float, neumann_linear: list[array], body_force: ndarray | None = None)
Bases:
FEMDomainContainer for storing finite element and optimization-related data used in topology optimization tasks.
This class holds material properties, boundary condition information, designable and non-designable element indices, as well as force vectors and volume data for each element. It is typically constructed using LinearElasticity.from_defaults.
- E
Young’s modulus of the base material.
- Type:
float
- nu
Poisson’s ratio of the base material.
- Type:
float
- classmethod from_facets(basis: CellBasis, dirichlet_facets_ids: ndarray | list[ndarray], dirichlet_dir: Literal['u^1', 'u^2', 'u^3', 'all'] | list[Literal['u^1', 'u^2', 'u^3', 'all']], force_facets_ids: ndarray | list[ndarray], force_dir_type: str | list[str], force_value: float | list[float], design_elements: ndarray, E: float, nu: float) LinearElasticity
Create a TaskConfig from facet-based boundary-condition specifications.
This constructor allows you to specify Dirichlet and Neumann boundaries directly via facet indices (rather than node indices). It will internally:
Convert dirichlet_facets_ids into the corresponding Dirichlet node set.
Resolve Dirichlet DOFs from those nodes and dirichlet_dir.
Convert force_facets_ids into the corresponding force node set.
- Assemble the Neumann (surface) load vector(s) using
assemble_surface_forces.
Forward all data to TaskConfig.neumann_ to build the final config.
- Parameters:
E (float) – Young’s modulus.
nu (float) – Poisson’s ratio.
basis (skfem.Basis) – Finite-element space providing mesh and DOFs.
dirichlet_facets_ids (np.ndarray or list[np.ndarray]) – Indices of facets subject to Dirichlet boundary conditions. If a list is given, each entry corresponds to a boundary region.
dirichlet_dir (_lit_bc or list[_lit_bc]) – Direction specifier(s) for Dirichlet constraints. _lit_bc = Literal[‘u^1’, ‘u^2’, ‘u^3’, ‘all’] - ‘all’ fixes all displacement components. - ‘u^1’, ‘u^2’, ‘u^3’ fix the respective component only.
force_facets_ids (np.ndarray or list[np.ndarray]) – Indices of facets subject to Neumann (surface) forces. A list denotes multiple load regions.
force_dir_type (str or list[str]) – Direction specifier(s) for each force region. _lit_force = Literal[‘u^1’, ‘u^2’, ‘u^3’] Indicates along which component the surface load is applied.
force_value (float or list[float]) – Magnitude(s) of the surface forces, one per region if multiple.
design_elements (np.ndarray) – Element indices initially considered designable. Force-touching elements will be excluded downstream.
- Returns:
A fully initialized TaskConfig, equivalent to what TaskConfig.neumann_ produces but constructed from facet-based specifications.
- Return type:
TaskConfig
- class sktopt.mesh.LinearHeatConduction(basis: skfem.assembly.basis.cell_basis.CellBasis, dirichlet_nodes: numpy.ndarray | list[numpy.ndarray] | None, dirichlet_dofs: numpy.ndarray | list[numpy.ndarray] | None, dirichlet_elements: numpy.ndarray | None, dirichlet_values: float | list[float] | None, neumann_nodes: numpy.ndarray | list[numpy.ndarray] | None, neumann_elements: numpy.ndarray | None, neumann_dir_type: str | list[str] | None, neumann_values: float | list[float] | None, robin_facets_ids: numpy.ndarray | list[numpy.ndarray] | None, robin_nodes: numpy.ndarray | list[numpy.ndarray] | None, robin_elements: numpy.ndarray | None, robin_coefficient: float | list[float] | None, robin_bc_value: float | list[float] | None, design_robin_boundary: bool | None, design_elements: numpy.ndarray, free_dofs: numpy.ndarray, free_elements: numpy.ndarray, all_elements: numpy.ndarray, fixed_elements: numpy.ndarray, dirichlet_neumann_elements: numpy.ndarray, elements_volume: numpy.ndarray, k: float, robin_bilinear: list | None = None, robin_linear: list | None = None, objective: Literal['compliance'] = 'compliance')
Bases:
FEMDomain