cashocs.DeflatedTopologyOptimizationProblem#

class cashocs.DeflatedTopologyOptimizationProblem(
state_forms: list[ufl.Form] | ufl.Form,
bcs_list: list[list[fenics.DirichletBC]] | list[fenics.DirichletBC] | fenics.DirichletBC,
cost_functional_form: list[_typing.CostFunctional] | _typing.CostFunctional,
states: list[fenics.Function] | fenics.Function,
adjoints: list[fenics.Function] | fenics.Function,
levelset_function: fenics.Function,
topological_derivative_neg: fenics.Function | ufl.Form,
topological_derivative_pos: fenics.Function | ufl.Form,
update_levelset: Callable,
volume_restriction: float | tuple[float, float] | None = None,
config: io.Config | None = None,
riesz_scalar_products: list[ufl.Form] | ufl.Form | None = None,
initial_guess: list[fenics.Function] | None = None,
ksp_options: _typing.KspOption | list[_typing.KspOption] | None = None,
adjoint_ksp_options: _typing.KspOption | list[_typing.KspOption] | None = None,
gradient_ksp_options: _typing.KspOption | list[_typing.KspOption] | None = None,
preconditioner_forms: list[ufl.Form] | ufl.Form | None = None,
pre_callback: Callable | None = None,
post_callback: Callable | None = None,
linear_solver: _utils.linalg.LinearSolver | None = None,
adjoint_linear_solver: _utils.linalg.LinearSolver | None = None,
newton_linearizations: ufl.Form | list[ufl.Form] | None = None,
excluded_from_time_derivative: list[int] | list[list[int]] | None = None,
)[source]#

Bases: DeflatedProblem

A deflated topology optimization problem.

Initializes self.

Parameters:
  • state_forms (list[ufl.Form] | ufl.Form) – The weak form of the state equation (user implemented). Can be either a single UFL form, or a (ordered) list of UFL forms.

  • bcs_list (list[list[fenics.DirichletBC]] | list[fenics.DirichletBC] | fenics.DirichletBC) – The list of fenics.DirichletBC objects describing Dirichlet (essential) boundary conditions. If this is None, then no Dirichlet boundary conditions are imposed.

  • cost_functional_form (list[_typing.CostFunctional] | _typing.CostFunctional) – UFL form of the cost functional. Can also be a list of summands of the cost functional

  • states (list[fenics.Function] | fenics.Function) – The state variable(s), can either be a fenics.Function, or a list of these.

  • adjoints (list[fenics.Function] | fenics.Function) – The adjoint variable(s), can either be a fenics.Function, or a (ordered) list of these.

  • levelset_function (fenics.Function) – A fenics.Function which represents the levelset function.

  • topological_derivative_neg (fenics.Function | ufl.Form) – The topological derivative inside the domain, where the levelset function is negative.

  • topological_derivative_pos (fenics.Function | ufl.Form) – The topological derivative inside the domain, where the levelset function is positive.

  • update_levelset (Callable) – A python function (without arguments) which is called to update the coefficients etc. when the levelset function is changed.

  • volume_restriction (float | tuple[float, float] | None) – A volume restriction for the optimization problem. A single float describes an equality constraint and a tuple of floats an inequality constraint.

  • config (io.Config | None) – The config file for the problem, generated via cashocs.create_config(). Alternatively, this can also be None, in which case the default configurations are used, except for the optimization algorithm. This has then to be specified in the solve method. The default is None.

  • riesz_scalar_products (list[ufl.Form] | ufl.Form | None) – The scalar products of the control space. Can either be None or a single UFL form. If it is None, the \(L^2(\Omega)\) product is used (default is None).

  • initial_guess (list[fenics.Function] | None) – list of functions that act as initial guess for the state variables, should be valid input for fenics.assign(). Defaults to None, which means a zero initial guess.

  • ksp_options (_typing.KspOption | list[_typing.KspOption] | None) – A list of strings corresponding to command line options for PETSc, used to solve the state systems. If this is None, then the direct solver mumps is used (default is None).

  • adjoint_ksp_options (_typing.KspOption | list[_typing.KspOption] | None) – A list of strings corresponding to command line options for PETSc, used to solve the adjoint systems. If this is None, then the same options as for the state systems are used (default is None).

  • gradient_ksp_options (_typing.KspOption | list[_typing.KspOption] | None) – A list of dicts corresponding to command line options for PETSc, used to compute the (shape) gradient. If this is None, either a direct or an iterative method is used (depending on the configuration, section OptimizationRoutine, key gradient_method).

  • preconditioner_forms (list[ufl.Form] | ufl.Form | None) – The list of forms for the preconditioner. The default is None, so that the preconditioner matrix is the same as the system matrix.

  • pre_callback (Callable | None) – A function (without arguments) that will be called before each solve of the state system

  • post_callback (Callable | None) – A function (without arguments) that will be called after the computation of the gradient.

  • linear_solver (_utils.linalg.LinearSolver | None) – The linear solver (KSP) which is used to solve the linear systems arising from the discretized PDE.

  • adjoint_linear_solver (_utils.linalg.LinearSolver | None) – The linear solver (KSP) which is used to solve the (linear) adjoint system.

  • newton_linearizations (ufl.Form | list[ufl.Form] | None) – A (list of) UFL forms describing which (alternative) linearizations should be used for the (nonlinear) state equations when solving them (with Newton’s method). The default is None, so that the Jacobian of the supplied state forms is used.

  • excluded_from_time_derivative (list[int] | list[list[int]] | None) – For each state equation, a list of indices which are not part of the first order time derivative for pseudo time stepping. Example: Pressure for incompressible flow. Default is None.

Methods Summary

check_for_restart()

Checks if a restart of the optimization of the unpenalized problem is needed.

construct_penalty_functions(gamma, delta)

Constructs the penalty functions for the deflation procedure.

distance_shapes()

Computes the distance of a minimizer to previous ones.

inject_post_callback(function)

Changes the a-posteriori callback of the OptimizationProblem.

inject_pre_callback(function)

Changes the a-priori callback of the OptimizationProblem.

inject_pre_post_callback(pre_function, ...)

Changes the a-priori (pre) and a-posteriori (post) callbacks of the problem.

map_abstract_control()

Maps the abstract control for the optimization problem.

reset_starting_value()

Resets the starting value for the optimization problem.

save_functions(argument)

Stores the newly computed local minimizers during the deflation procedure.

solve([tol, it_deflation, gamma, delta, ...])

Deflation procedure to find multiple local minimizers.

update_level_set_deflation()

update_levelset function for the deflated topology optimization problem.

Methods Documentation

check_for_restart() bool#

Checks if a restart of the optimization of the unpenalized problem is needed.

Returns:

Bool that indicates if a restart of the unpenalized problem with the local minimizer of the deflated problem is needed. This is the case if not all penality functions vanish in the local minimizer of the deflated problem.

Return type:

bool

construct_penalty_functions(
gamma: int | float,
delta: int | float,
) None[source]#

Constructs the penalty functions for the deflation procedure.

Parameters:
  • gamma (int | float) – Threshold value for the local support of the penalty function. If the distance of two shapes is larger than this threshold, the penalty function vanishes.

  • delta (int | float) – Penalty parameter of the penalty function.

Return type:

None

distance_shapes() bool#

Computes the distance of a minimizer to previous ones.

Returns:

True if the distance of the new local minimizer to all previous found ones exceeds the threshold gamma. False if at least one distance does not meet the threshold (no new minimizer of the actual problem found).

Return type:

bool

inject_post_callback(
function: Callable[[], None] | Callable[[_typing.OptimizationProblem], None] | None,
) None#

Changes the a-posteriori callback of the OptimizationProblem.

Parameters:

function (Callable[[], None] | Callable[[_typing.OptimizationProblem], None] | None) – A custom function without arguments, which will be called after the computation of the gradient(s)

Return type:

None

inject_pre_callback(
function: Callable[[], None] | Callable[[_typing.OptimizationProblem], None] | None,
) None#

Changes the a-priori callback of the OptimizationProblem.

Parameters:

function (Callable[[], None] | Callable[[_typing.OptimizationProblem], None] | None) – A custom function without arguments, which will be called before each solve of the state system

Return type:

None

inject_pre_post_callback(
pre_function: Callable[[], None] | Callable[[_typing.OptimizationProblem], None] | None,
post_function: Callable[[], None] | Callable[[_typing.OptimizationProblem], None] | None,
) None#

Changes the a-priori (pre) and a-posteriori (post) callbacks of the problem.

Parameters:
  • pre_function (Callable[[], None] | Callable[[_typing.OptimizationProblem], None] | None) – A function without arguments, which is to be called before each solve of the state system

  • post_function (Callable[[], None] | Callable[[_typing.OptimizationProblem], None] | None) – A function without arguments, which is to be called after each computation of the (shape) gradient

Return type:

None

map_abstract_control() fenics.Function[source]#

Maps the abstract control for the optimization problem.

Returns:

The mapped abstract control is defined as the

characteristic function of the domain that is given by the level-set function (abstract_control).

Return type:

abstract_control_mapped

reset_starting_value() None#

Resets the starting value for the optimization problem.

Return type:

None

save_functions(
argument: str | list[str],
) None#

Stores the newly computed local minimizers during the deflation procedure.

Parameters:

argument (str | list[str]) – str that indicates in which list the abstract_control of the newly computed minimizer gets stored. ‘solution’: local minimizer of the deflated optimization problems. ‘restart’: local minimizers of the restart procedure. ‘final’: (distinct) local minimizers of the undeflated optimization problem.

Return type:

None

solve(
tol: float = 0.01,
it_deflation: int = 5,
gamma: float = 0.5,
delta: float = 1.0,
inner_rtol: float | None = None,
inner_atol: float | None = None,
angle_tol: float | None = 1.0,
) None#

Deflation procedure to find multiple local minimizers.

Parameters:
  • tol (float) – An overall tolerance to be used in the algorithm. This will set the relative tolerance for the inner optimization problems to tol. Default is 1e-2.

  • it_deflation (int) – Number of performed deflation loops. Default is 5.

  • gamma (float) – Parameter to control the support of the penalty functions for the deflation procedure.

  • delta (float) – Penalty parameter of the penalty functions for the deflation

  • procedure.

  • inner_rtol (float | None) – Relative tolerance for the inner problem. Default is None,

  • used. (so that inner_rtol = tol is)

  • inner_atol (float | None) – Absolute tolerance for the inner problem. Default is None, so that inner_atol = tol/10 is used.

  • angle_tol (float | None) – Absolute tolerance for the inner topology optimization problem. Default is None.

Return type:

None

update_level_set_deflation() None[source]#

update_levelset function for the deflated topology optimization problem.

Return type:

None