Optimization Tools
- opti_tool.lagrangian_cost(cost_value, constraint_value, parameters)[source]
Compute the Lagrangian cost, which is the sum of the cost function and the constraint term using the Augmented Lagrangian Method (ALM).
With the ALM method, it is defined as:
\[\mathcal{L}(\Omega^{n}) = J(\Omega^{n}) + \lambda_{ALM}^{n} \left( C(\Omega^{n}) + s_{ALM}^{n} \right) + \frac{\mu_{ALM}^{n}}{2} \left( C(\Omega^{n}) s_{ALM}^{n} \right)^{2}.\]- Parameters:
cost_value (float) – The cost value, \(J(\Omega^{n})\).
constraint_value (float) – The value of \(C(\Omega^{n})\).
parameters (Parameters) – The parameter object.
- Returns:
The Lagrangian cost.
- Return type:
float.
- opti_tool.adapt_c_HJ(c, crit, tol, lagrangian)[source]
Automatically compute the parameter \(c\) for time step \(dt\) adaptation using the cost values from the previous three iterations, the three previous Lagrangian cost values, and a tolerance value denoted as tol.
- Parameters:
c (float) – The previous value of the parameter c.
crit (np.array) – The cost values from the last three iterations.
lagrangian (np.array) – The Lagrangian cost values from the last three iterations.
- Returns:
The updated value of c.
- Return type:
float.
- opti_tool.adapt_dt(_lagrangian_cost, lagrangian_cost_previous, max_velocity, parameters, c)[source]
Compute the adaptive time step (dt) based on compliance with the Lagrangian cost evolution.
The time step is scaled using a factor c and the ratio of parameters.h to max_velocity. The minimum value of dt is taken to ensure numerical stability.
- Parameters:
_lagrangian_cost (float) – The current Lagrangian cost (not used in the function but likely relevant for future modifications).
lagrangian_cost_previous (float) – The Lagrangian cost from the previous iteration.
max_velocity (float) – The maximum velocity in the system.
parameters (Parameters) – An object containing various simulation parameters, including h.
c (float) – A scaling factor to control the time step size.
- Returns:
The adapted time step dt.
- Return type:
float
- opti_tool.adapt_HJ(_lagrangian_cost, lagrangian_cost_previous, j_max, dt, parameters)[source]
Compute an adaptive j_max parameter for number iteration of advection equation.
The function calculates the shape derivative using the difference in Lagrangian costs and adjusts the j_max value within a bounded range.
Note
For Non linear problem like the minimization of Lp norm of Von Mises constraint the bounded range is more restrictive.
- Parameters:
_lagrangian_cost (float) – The current Lagrangian cost.
lagrangian_cost_previous (float) – The Lagrangian cost from the previous iteration.
j_max (int) – The maximum iteration step index.
dt (float) – The time step size.
parameters (dict) – Additional parameters (not used in function but included for extensibility).
c (any) – Additional argument (not used in function but included for extensibility).
- Returns:
A computed adaptation value between 1 and 10, based on the shape derivative.
- Return type:
int
- opti_tool.catch_NAN(cost, lagrangian_cost, rest_constraint, dt, adv_bool)[source]
Handle and check for potential NaN (Not a Number) or very small values in the input parameters.
The function checks if the cost, Lagrangian cost, and rest constraint are all close to zero, indicating a potential numerical issue (NaN or very small values). If the conditions are met and the adv_bool parameter is greater than or equal to 1, the function returns the time step dt and a zero value. Otherwise, it returns dt and twice the value of adv_bool.
- Parameters:
cost (float) – The current cost value.
lagrangian_cost (float) – The current Lagrangian cost.
rest_constraint (float) – The rest constraint value.
dt (float) – The time step size.
adv_bool (int) – A boolean-like value (1 or 0) indicating whether to perform an adaptation.
- Returns:
A tuple with the time step dt and either 0 or 2 * adv_bool, based on the conditions.
- Return type:
tuple