sktopt.mesh.task
- class sktopt.mesh.task.TaskConfig(E: float, nu: float, basis: CellBasis, dirichlet_nodes: ndarray, dirichlet_dofs: ndarray, dirichlet_elements: ndarray, force_nodes: ndarray | list[ndarray], force_elements: ndarray, force: ndarray | list[ndarray], design_elements: ndarray, free_dofs: ndarray, free_elements: ndarray, all_elements: ndarray, fixed_elements: ndarray, dirichlet_force_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 TaskConfig.from_defaults.
- E
Young’s modulus of the base material.
- Type:
float
- nu
Poisson’s ratio of the base material.
- Type:
float
- 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
- force_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_force_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
- E: float
- all_elements: ndarray
- basis: CellBasis
- design_elements: ndarray
- property design_mask
- dirichlet_dofs: ndarray
- dirichlet_elements: ndarray
- dirichlet_force_elements: ndarray
- dirichlet_nodes: ndarray
- elements_volume: ndarray
- exlude_dirichlet_from_design()
- export_analysis_condition_on_mesh(dst_path: str)
- fixed_elements: ndarray
- force: ndarray | list[ndarray]
- force_elements: ndarray
- force_nodes: ndarray | list[ndarray]
- property force_nodes_all: ndarray
- free_dofs: ndarray
- free_elements: ndarray
- classmethod from_facets(E: float, nu: float, 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) TaskConfig
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.from_nodes 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.from_nodes produces but constructed from facet-based specifications.
- Return type:
TaskConfig
- classmethod from_json(path: str)
- classmethod from_mesh_tags(E: float, nu: float, basis: CellBasis, dirichlet_dir: Literal['u^1', 'u^2', 'u^3', 'all'] | list[Literal['u^1', 'u^2', 'u^3', 'all']], force_dir_type: str | list[str], force_value: float | list[float]) TaskConfig
- classmethod from_nodes(E: float, nu: float, basis: CellBasis, dirichlet_nodes: ndarray | list[ndarray], dirichlet_dir: Literal['u^1', 'u^2', 'u^3', 'all'] | list[Literal['u^1', 'u^2', 'u^3', 'all']], force_nodes: ndarray | list[ndarray], force: ndarray | list[ndarray], design_elements: ndarray) TaskConfig
Create a TaskConfig from material parameters and boundary-condition specifications expressed by node-index sets.
- This constructor:
Resolves Dirichlet DOFs from dirichlet_nodes and dirichlet_dir.
Identifies Dirichlet/Neumann (force) elements that touch those nodes.
Builds load vector(s) from force and filters out non-designable elements.
Derives sets such as free DOFs/elements and fixed/design elements.
Precomputes per-element volumes.
- Parameters:
E (float) – Young’s modulus.
nu (float) – Poisson’s ratio.
basis (skfem.Basis) – Finite-element space (provides mesh, DOFs, etc.).
dirichlet_nodes (np.ndarray or list[np.ndarray]) – Global node indices that define Dirichlet boundaries. If a list is provided, it must align one-to-one with dirichlet_dir.
dirichlet_dir (_lit_bc or list[_lit_bc]) – Direction specifier(s) for Dirichlet constraints. _lit_bc = Literal[‘u^1’, ‘u^2’, ‘u^3’, ‘all’] Use ‘all’ to fix all components, or ‘u^1’|’u^2’|’u^3’ to fix a single component (compatible with basis.get_dofs(…).nodal[…]). When dirichlet_nodes is a list, this must be a list of equal length.
force_nodes (np.ndarray or list[np.ndarray]) – Global node indices where Neumann (external) loads are applied. A list denotes multiple load regions (load cases).
force (np.ndarray or list[np.ndarray]) – Load vector(s) associated with force_nodes. Provide a list to match multiple regions/cases. Each vector should already be assembled in the global DOF ordering expected by the solver.
design_elements (np.ndarray) – Element indices initially considered designable. Elements touching force_nodes are removed from this set.
- Returns:
- A fully initialized configuration containing:
material parameters (E, nu)
mesh/basis
dirichlet_nodes, dirichlet_dofs, dirichlet_elements
force_nodes, force_elements, force
filtered design_elements
free_dofs, free_elements
all_elements, fixed_elements, dirichlet_force_elements
elements_volume
- Return type:
TaskConfig
Notes
Element sets are computed via utils.get_elements_by_nodes(…), i.e., elements touching the provided node sets.
free_dofs = all DOFs dirichlet_dofs; free_elements are elements touching free_dofs (convenience for downstream assembly/solves).
If you prefer facet-based specification (with direction literals for surface forces, e.g., _lit_force = Literal[‘u^1’,’u^2’,’u^3’]), consider using TaskConfig.from_facets(…) which will assemble surface loads internally.
- property mesh
- nodes_and_elements_stats(dst_path: str)
- nu: float
- scale(L_scale: float, F_scale: float)
- sktopt.mesh.task.assemble_surface_forces(basis, force_facets_ids: ndarray | List[ndarray], force_dir_type: str | List[str], force_value: float | List[float], *, treat_value_as_total_force: bool = True)
- sktopt.mesh.task.setdiff1d(a, b)