sktopt.core.optimizers.common

class sktopt.core.optimizers.common.DensityMethod(cfg: DensityMethodConfig, tsk: TaskConfig)

Bases: object

Base class for sensitivity-based topology optimization routines.

This class provides common functionality shared by multiple optimization strategies (e.g., OC, LDMOC, EUMOC), including finite element analysis (FEA), sensitivity filtering, and density projection using Heaviside-type functions. It does not perform the optimization update itself — that logic is delegated to subclasses.

Typical usage involves: - Assembling the global stiffness matrix - Solving the displacement field under given loads and boundary conditions - Computing the compliance and its sensitivity with respect to density - Applying density or sensitivity filters (e.g., Helmholtz, cone filters) - Projecting intermediate densities using smooth Heaviside functions

This class is designed for reuse and extension. All algorithm-specific update steps (e.g., density changes, Lagrange multiplier updates) should be implemented in derived classes such as OC_Optimizer, LDMOC_Optimizer, or ` EUMOC_Optimizer`.

Responsibilities

  • Manage problem configuration (e.g., material parameters, mesh, basis)

  • Provide filtered sensitivities for stable optimization

  • Apply projection functions for sharp interface control

  • Evaluate objective functions such as compliance

Notes

This class serves as the backbone of sensitivity-based topology optimization. Subclasses are expected to override methods such as rho_update() to implement specific optimization logic.

tsk

Contains FEM mesh, basis, boundary condition data, and load vectors.

Type:

TaskConfig

config

Holds numerical and algorithmic settings like filtering radius, penalization power, projection beta, etc.

Type:

DensityMethodConfig

init_schedulers(export: bool = True)
initialize_density()
initialize_params()
load_parameters()
optimize()
parameterize()
rho_update(iter_loop: int, rho_candidate: ndarray, rho_projected: ndarray, dC_drho_ave: ndarray, u_dofs: ndarray, strain_energy_ave: ndarray, scaling_rate: ndarray, move_limit: float, eta: float, tmp_lower: ndarray, tmp_upper: ndarray, lambda_lower: float, lambda_upper: float, percentile: float, elements_volume_design: ndarray, elements_volume_design_sum: float, vol_frac: float)
scale()
unscale()
class sktopt.core.optimizers.common.DensityMethodConfig(dst_path: str = './result/pytests', interpolation: Literal['SIMP', 'RAMP'] = 'SIMP', record_times: int = 20, max_iters: int = 200, p_init: float = 1.0, p: float = 3.0, p_step: int = -1, vol_frac_init: float = 0.8, vol_frac: float = 0.4, vol_frac_step: int = -3, beta_init: float = 1.0, beta: float = 2, beta_step: int = -1, beta_curvature: float = 2.0, beta_eta: float = 0.5, eta: float = 0.6, percentile_init: float = 60, percentile: float = -90, percentile_step: int = -1, filter_radius_init: float = 2.0, filter_radius: float = 1.2, filter_radius_step: int = -3, E0: float = 210000000000.0, E_min: float = 210000000.0, rho_min: float = 0.01, rho_max: float = 1.0, move_limit_init: float = 0.3, move_limit: float = 0.1, move_limit_step: int = -3, restart: bool = False, restart_from: int = -1, export_img: bool = False, export_img_opaque: bool = False, design_dirichlet: bool = False, lambda_lower: float = 1e-07, lambda_upper: float = 10000000.0, sensitivity_filter: bool = False, solver_option: Literal['spsolve', 'cg_pyamg'] = 'spsolve', scaling: bool = False)

Bases: object

Configuration class for controlling parameters in topology optimization.

This class defines optimization parameters, filtering and projection settings, continuation schedules, and numerical solver options. It is designed to support sensitivity-based topology optimization algorithms such as SIMP and RAMP.

dst_path

Directory to which results and logs are saved.

Type:

str

interpolation

Interpolation method for material penalization.

Type:

{“SIMP”, “RAMP”}

record_times

Number of snapshots to record during optimization.

Type:

int

max_iters

Maximum number of optimization iterations.

Type:

int

p_init

Initial penalization power in SIMP/RAMP interpolation.

Type:

float

p

Final value of the penalization power.

Type:

float

p_step

Number of steps to continue p from p_init to p. If negative, p is fixed at p_init.

Type:

int

vol_frac_init

Initial volume fraction for continuation.

Type:

float

vol_frac

Final volume fraction constraint.

Type:

float

vol_frac_step

Number of continuation steps from vol_frac_init to vol_frac. If negative, vol_frac is fixed at vol_frac_init.

Type:

int

beta_init

Initial sharpness parameter for Heaviside projection.

Type:

float

beta

Final beta value for projection.

Type:

float

beta_step

Number of continuation steps from beta_init to beta. If negative, beta is fixed at beta_init.

Type:

int

beta_curvature

Controls the curvature of the Heaviside projection function.

Type:

float

beta_eta

Threshold parameter for Heaviside projection; determines where the projection function switches rapidly between 0 and 1.

Type:

float

eta

Threshold density used in projection. Often used to define intermediate region in Heaviside or filtering.

Type:

float

percentile_init

Initial percentile used to scale sensitivity fields.

Type:

float

percentile

Final percentile value. If set to a negative value, percentile-based scaling is disabled, resulting in a more “exact” optimization behavior.

Type:

float

percentile_step

Number of continuation steps for the percentile value. If negative, fixed at percentile_init.

Type:

int

filter_radius_init

Initial radius of the sensitivity or density filter.

Type:

float

filter_radius

Final filter radius.

Type:

float

filter_radius_step

Number of continuation steps for filter radius. If negative, filter_radius is fixed at initial value.

Type:

int

E0

Young’s modulus of the solid material.

Type:

float

E_min

Minimum Young’s modulus (used for void regions).

Type:

float

rho_min

Minimum density value (to avoid singular stiffness).

Type:

float

rho_max

Maximum density value (usually 1.0 for full material).

Type:

float

move_limit_init

Initial move limit for density update.

Type:

float

move_limit

Final move limit.

Type:

float

move_limit_step

Number of continuation steps for move limit. If negative, move limit is fixed.

Type:

int

restart

Whether to resume optimization from an existing state.

Type:

bool

restart_from

Iteration index to restart from.

Type:

int

export_img

Whether to export images during optimization.

Type:

bool

export_img_opaque

If True, image export uses opaque rendering.

Type:

bool

design_dirichlet

If True, Dirichlet boundary elements are included in the design domain.

Type:

bool

lambda_lower

Lower bound for the Lagrange multiplier in constrained optimization.

Type:

float

lambda_upper

Upper bound for the Lagrange multiplier.

Type:

float

sensitivity_filter

If True, applies filtering to the sensitivity field.

Type:

bool

solver_option

Linear solver to be used in analysis. “cg_pyamg” enables multigrid acceleration.

Type:

{“spsolve”, “cg_pyamg”}

scaling

If True, length and force scaling are applied to normalize the mesh geometry and load magnitudes. This helps improve numerical stability by making the system dimensionless or better conditioned.

Type:

bool

E0: float = 210000000000.0
E_min: float = 210000000.0
beta: float = 2
beta_curvature: float = 2.0
beta_eta: float = 0.5
beta_init: float = 1.0
beta_step: int = -1
design_dirichlet: bool = False
dst_path: str = './result/pytests'
eta: float = 0.6
export(path: str)
export_img: bool = False
export_img_opaque: bool = False
filter_radius: float = 1.2
filter_radius_init: float = 2.0
filter_radius_step: int = -3
classmethod from_defaults(**args)
image_path(iter: int, prefix: str)
classmethod import_from(path: str) DensityMethodConfig
interpolation: Literal['SIMP', 'RAMP'] = 'SIMP'
lambda_lower: float = 1e-07
lambda_upper: float = 10000000.0
max_iters: int = 200
move_limit: float = 0.1
move_limit_init: float = 0.3
move_limit_step: int = -3
p: float = 3.0
p_init: float = 1.0
p_step: int = -1
percentile: float = -90
percentile_init: float = 60
percentile_step: int = -1
record_times: int = 20
restart: bool = False
restart_from: int = -1
rho_max: float = 1.0
rho_min: float = 0.01
scaling: bool = False
sensitivity_filter: bool = False
solver_option: Literal['spsolve', 'cg_pyamg'] = 'spsolve'
vol_frac: float = 0.4
vol_frac_init: float = 0.8
vol_frac_step: int = -3
vtu_path(iter: int)
sktopt.core.optimizers.common.interpolation_funcs(cfg: DensityMethodConfig)