Optimization

MMA

beam_mma.main(mesh_file, nelx, nely, lx, ly, func_name, load_matrix, restri_matrix=None, freq1=180, constr_func=['area'], constr_values=[50], n1=1, multiobjective=(None, 0), const_func=100, fac_ratio=2.1, modes=None, rho=7860, E=210000000000.0, v=0.3, x_min_m=0.001, x_min_k=0.001, alpha_par=0, beta_par=5e-06, eta_par=0, alpha_plot=0, beta_plot=1e-08, eta_plot=0, p_par=3, q_par=1, passive_coord=None, freq_rsp=[], dens_filter=True, each_iter=True, max_iter=100, mesh_deform=False, factor=1000, save=False, timing=False)
Parameters
  • nelx (int) – Number of elements on the x-axis.

  • nely (int) – Number of elements on the y-axis.

  • lx (float) – x-axis length.

  • ly (float) – x-axis length.

  • func_name (str) –

    Objective function used.

    • It can be “compliance”, “input_power”, “elastic_potential_energy”, “kinetic_energy”, “r_ratio”, “local_ep”, “local_ki” or “local_r”.

    • The objective functions “local_ep”, “local_ki” and “local_r” are designed to passive elements.

    • If the multiobjective function is being calculated, weight n1 is assigned.

  • load_matrix (numpy.array) –

    List of dictionaries. The dictionary can be:

    • {“coord”:value_coordinate, “axis”:column_to_compare, “eps”:error_margin, “x_direc”:force_applied_x, “y_direc”:force_applied_y, “force”:force_value}

    • {“x_coord”:x_coordinate, “y_coord”:y_coordinate, “apply_x”:force_applied_x, “apply_y”:force_applied_y, “force”:force_value}

  • restri_matrix (numpy.array, optional) –

    List of dictionaries. Defaults to None. The dictionary can be:

    • {“x_coord”:x_coordinate, “y_coord”:y_coordinate, “constrain_disp_x”:constrain_disp_x, “constrain_disp_y”:constrain_disp_y}

    • {“coord”:value_coordinate, “axis”:column_to_compare, “eps”:error_margin, “constrain_disp_x”:constrain_disp_x, “constrain_disp_y”:constrain_disp_y}

  • freq1 (int, optional) – Optimized frequency. Defaults to 180.

  • constr_func (list, optional) –

    Constraint functions applied. Defaults to “area”.

    • It can be: “area”, “r_ratio”, “compliance”, “local_ep”, “local_ki” or “local_r”.

    • The first function in the list will be used to define the initial value of xval.

    • If the same function is passed 2x,the box constraint is used. Negative values indicate the lower constraint.

    • Example:
      • constr_func = [“area”, “area”]

      • constr_values = [50, -20]

  • constr_values (list, optional) –

    Values of constraint functions applied. Defaults to 50.

    • Value in position i relates to the function in position i of the list constr_func.

    • constr_values[i] < 0 = lower constraint

    • constr_values[i] > 0 = upper constraint

    • If “compliance”, “local_ep”, “local_ki” or “local_r” is passed a tuple with constraint value and frequency respectively.

    • Example:
      • constr_func = [“area”, “area”, “compliance”, “r_ratio”]

      • constr_values = [50, -20, (50, 1000), 10]

  • n1 (float, optional) –

    Weight n1 used in func_name. Defaults to 1.

    • If n1 < 0: Maximize objective function

    • If n1 > 0: Minimize objective function

  • multiobjective (tuple, optional) –

    Second function and frequency in the multiobjective. Defaults to (None, 0).

    • First value is the second function of the multiobjective function. The assigned weight is (1 - n1).

    • Second value is the frequency that func_name2 is being optimized.

  • const_func (float, optional) – Defaults to 100.

  • fac_ratio (float, optional) – Factor applied in the radius to get elements in the vicinity of each element. Defaults to 2.1.

  • modes (int, optional) – If not None is used the Mode Superposition Method to calculate the displacement. Defaults to None.

  • rho (float, optional) – Density. Defaults to 7860.

  • E (float, optional) – Elastic modulus. Defaults to 210e9.

  • v (float, optional) – Poisson’s ratio. Defaults to 0.3.

  • x_min_m (float, optional) – Minimum relative densities to mass. Defaults to 0.001.

  • x_min_k (float, optional) – Minimum relative densities to stiffness. Defaults to 0.001.

  • alpha_par (float, optional) – Damping coefficient proportional to mass. Defaults to 0.

  • beta_par (float, optional) – Damping coefficient proportional to stiffness. Defaults to 5e-6.

  • eta_par (float, optional) – Damping coefficient. Defaults to 0.

  • alpha_plot (float, optional) – Damping coefficient proportional to mass to generate the graph. Defaults to 0.

  • beta_plot (float, optional) – Damping coefficient proportional to stiffness to generate the graph. Defaults to 1e-8.

  • eta_plot (float, optional) – Damping coefficient to generate the graph. Defaults to 0.

  • p_par (int, optional) – Penalization power to stiffness. Defaults to 3.

  • q_par (int, optional) – Penalization power to mass. Defaults to 1.

  • passive_coord (tuple) –

    Region that the shape will not be changed. Defaults to None.

    • Example: ((0.5, 1), (0.3, 0.6)) = ((x_initial, x_final), (y_initial, y_final))

  • freq_rsp (list, optional) –

    If len is 3, a frequency response graph of the original and optimized structure is generated. Defaults to [].

    • First value is the minimum frequency of the graph.

    • Second value is the maximum frequency of the graph.

    • Third value is the step between each calculation of the objective function.

  • dens_filter (bool, optional) – If True use density filter and False use sensitivity filter. Defaults to True.

  • each_iter (bool, optional) – If True plots the convergence graph for each iteration of the optimization. Defaults to True.

  • max_iter (int, optional) – Number of iterations. Defaults to 100.

  • mesh_deform (bool, optional) – If True plots the mesh deformation of the dynamic function. Defaults to False.

  • factor (float, optional) – Factor to deform the mesh. Defaults to 1000.

  • save (bool, optional) – if True save the optimization and frequency response graphs as PNG. Defaults to False.

  • timing (bool, optional) – If True shows the process optimization time. Defaults to False.

GCMMA

beam_gcmma.main(mesh_file, nelx, nely, lx, ly, func_name, force_matrix, restri_matrix=None, freq1=180, constr_func=['area'], constr_values=[50], n1=1, multiobjective=(None, 0), const_func=100, fac_ratio=2.1, modes=None, rho=7860, E=210000000000.0, v=0.3, x_min_m=0.001, x_min_k=0.001, alpha_par=0, beta_par=5e-06, eta_par=0, alpha_plot=0, beta_plot=1e-08, eta_plot=0, p_par=3, q_par=1, passive_coord=None, freq_rsp=[], dens_filter=True, each_iter=True, max_iter=100, mesh_deform=False, factor=1000, save=False, timing=False)
Parameters
  • nelx (int) – Number of elements on the X-axis.

  • nely (int) – Number of elements on the Y-axis.

  • lx (float) – X-axis length.

  • ly (float) – Y-axis length.

  • func_name (str) –

    Objective function used.

    • It can be “compliance”, “input_power”, “elastic_potential_energy”, “kinetic_energy”, “r_ratio”, “local_ep”, “local_ki” or “local_r”.

    • The objective functions “local_ep”, “local_ki” and “local_r” are designed to passive elements.

    • If the multiobjective function is being calculated, weight n1 is assigned.

  • load_matrix (numpy.array) –

    List of dictionaries. The dictionary can be:

    • {“coord”:value_coordinate, “axis”:column_to_compare, “eps”:error_margin, “x_direc”:force_applied_x, “y_direc”:force_applied_y, “force”:force_value}

    • {“x_coord”:x_coordinate, “y_coord”:y_coordinate, “apply_x”:force_applied_x, “apply_y”:force_applied_y, “force”:force_value}

  • restri_matrix (numpy.array, optional) –

    List of dictionaries. Defaults to None. The dictionary can be:

    • {“x_coord”:x_coordinate, “y_coord”:y_coordinate, “constrain_disp_x”:constrain_disp_x, “constrain_disp_y”:constrain_disp_y}

    • {“coord”:value_coordinate, “axis”:column_to_compare, “eps”:error_margin, “constrain_disp_x”:constrain_disp_x, “constrain_disp_y”:constrain_disp_y}

  • freq1 (int, optional) – Optimized frequency. Defaults to 180.

  • constr_func (list, optional) –

    Constraint functions applied. Defaults to “area”.

    • It can be: “area”, “r_ratio”, “compliance”, “local_ep”, “local_ki” or “local_r”.

    • The first function in the list will be used to define the initial value of xval.

    • If the same function is passed 2x,the box constraint is used. Negative values indicate the lower constraint.

    • Example:
      • constr_func = [“area”, “area”]

      • constr_values = [50, -20]

  • constr_values (list, optional) –

    Values of constraint functions applied. Defaults to 50.

    • Value in position i relates to the function in position i of the list constr_func.

    • It can be a maximum of 6 values.

    • constr_values[i] < 0 = lower constraint

    • constr_values[i] > 0 = upper constraint

    • If “compliance”, “local_ep”, “local_ki” or “local_r” is passed a tuple with constraint value and frequency respectively.

    • Example:
      • constr_func = [“area”, “area”, “compliance”, “r_ratio”]

      • constr_values = [50, -20, (50, 1000), 10]

  • n1 (float, optional) –

    Weight n1 used in func_name. Defaults to 1.

    • If n1 < 0: Maximize objective function

    • If n1 > 0: Minimize objective function

  • multiobjective (tuple, optional) –

    Second function and frequency in the multiobjective. Defaults to (None, 0).

    • First value is the second function of the multiobjective function. The assigned weight is (1 - n1).

    • Second value is the frequency that func_name2 is being optimized.

  • const_func (float, optional) – Defaults to 100.

  • fac_ratio (float, optional) – Factor applied in the radius to get elements in the vicinity of each element. Defaults to 2.1.

  • modes (int, optional) – If not None is used the Mode Superposition Method to calculate the displacement. Defaults to None.

  • rho (float, optional) – Density. Defaults to 7860.

  • E (float, optional) – Elastic modulus. Defaults to 210e9.

  • v (float, optional) – Poisson’s ratio. Defaults to 0.3.

  • x_min_m (float, optional) – Minimum relative densities to mass. Defaults to 0.001.

  • x_min_k (float, optional) – Minimum relative densities to stiffness. Defaults to 0.001.

  • alpha_par (float, optional) – Damping coefficient proportional to mass. Defaults to 0.

  • beta_par (float, optional) – Damping coefficient proportional to stiffness. Defaults to 5e-6.

  • eta_par (float, optional) – Damping coefficient. Defaults to 0.

  • alpha_plot (float, optional) – Damping coefficient proportional to mass to generate the graph. Defaults to 0.

  • beta_plot (float, optional) – Damping coefficient proportional to stiffness to generate the graph. Defaults to 1e-8.

  • eta_plot (float, optional) – Damping coefficient to generate the graph. Defaults to 0.

  • p_par (int, optional) – Penalization power to stiffness. Defaults to 3.

  • q_par (int, optional) – Penalization power to mass. Defaults to 1.

  • passive_coord (tuple) –

    Region that the shape will not be changed. Defaults to None.

    • Example: ((0.5, 1), (0.3, 0.6)) = ((x_initial, x_final), (y_initial, y_final))

  • freq_rsp (list, optional) –

    If len is 3, a frequency response graph of the original and optimized structure is generated. Defaults to [].

    • First value is the minimum frequency of the graph.

    • Second value is the maximum frequency of the graph.

    • Third value is the step between each calculation of the objective function.

  • dens_filter (bool, optional) – If True use density filter and False use sensitivity filter. Defaults to True.

  • each_iter (bool, optional) – If True plots the convergence graph for each iteration of the optimization. Defaults to True.

  • max_iter (int, optional) – Number of iterations. Defaults to 100.

  • mesh_deform (bool, optional) – If True plots the mesh deformation of the dynamic function. Defaults to False.

  • factor (float, optional) – Factor to deform the mesh. Defaults to 1000.

  • save (bool, optional) – if True save the optimization and frequency response graphs as PNG. Defaults to False.

  • timing (bool, optional) – If True shows the process optimization time. Defaults to False.

General functions

functions_opt.apply_constr(fval, dfdx, constr_func, constr_values, freq_constr, ind_constr2, lx, ly, ngl, coord, connect, E, v, rho, alpha_par, beta_par, eta_par, p_par, q_par, x_min_m, x_min_k, area, xval, modes, disp_vector, dyna_stif, stif_matrix, mass_matrix, damp_matrix, load_vector, omega_par, const_func, free_ind, passive_el, ind_dofs, gradients=True)

Calculates constraint functions and derivative functions.

functions_opt.assembly_dyna_stif(omega_par, mass_matrix, damp_matrix, stif_matrix)

Assembly the dynamic stiffness matrix.

Parameters
  • omega_par (float) – 2 pi frequency.

  • mass_matrix (numpy.array) – Mass matrix.

  • damp_matrix (numpy.array) – Damping matrix.

  • stif_matrix (numpy.array) – Stiffness matrix.

Returns

Dynamic stiffness matrix.

functions_opt.assembly_matrices(data_k, data_m, ind_rows, ind_cols, ngl, alpha, beta)

Assembly of stiffness and mass matrices.

Parameters
  • data_k (numpy.array) – Data to assemble stiffness matrix.

  • data_m (numpy.array) – Data to assemble mass matrix.

  • ind_rows (numpy.array) – Node indices to make the assembly.

  • ind_cols (numpy.array) – Node indices to make the assembly.

  • ngl (int) – Degrees of freedom.

  • alpha (float) – Damping coefficient proportional to mass.

  • beta (float) – Damping coefficient proportional to stiffness.

Returns

A tuple with stiffness matrix, mass matrix and damping matrix.

functions_opt.calc_A(coord, ind)

Calculates the total area.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • ind (numpy.array) – Element connectivity.

Returns

The element area.

functions_opt.calc_xnew(H, neighbors, xval)

Recalculates xval.

Parameters
  • H (csc_matrix) – Radius subtracted from the distance between the element and the neighbors.

  • neighbors (csc_matrix) – Neighbors of each element.

  • xval (numpy.array) – Indicates where there is mass.

Returns

New xval values.

functions_opt.check_func_name(func_name, func_name2, constr_func)

Checks if the objective function and the constraint functions are correct.

Parameters
  • func_name (str) – Objective function used.

  • func_name2 (str) – Second objective function used.

  • constr_func (list) – Constraint functions applied.

functions_opt.constr_with_freq(constr_func, constr_values)

Separates the constraint value and the frequency of the constrain function.

Parameters
  • constr_values (list) – Values of constraint functions applied.

  • constr_func (list) – Constraint functions applied.

Returns

constr_values, freq_constr, ind_freq_constr

functions_opt.create_header(multiobj_bool, constr_func)

Creates header to save data.

Parameters
  • multiobj_bool (bool) – True if multiobjective function is used.

  • constr_func (list) – Constraint functions applied.

Returns

Header.

functions_opt.density_filter(H1, neighbors, dfdx, df0dx, df0dx2=None)

Applies the density filter to the derivative of the functions (constrain, objective and multiobjective).

Parameters
  • H (csc_matrix) – Radius subtracted from the distance between the element and the neighbors.

  • neighbors (csc_matrix) – Neighbors of each element.

  • dfdx (numpy.array) – Value of the constraint derivative.

  • df0dx (numpy.array) – Derivative value of the objective function.

  • df0dx2 (numpy.array, optional) – Derivative value of the second objective function.

Returns

Density filter applied to the derivative values.

functions_opt.finite_difference(mesh_file, nelx, nely, lx, ly, func_name, load_matrix, restri_matrix=None, freq1=180, const_func=100, fac_ratio=2.1, modes=None, rho=7860, E=210000000000.0, v=0.3, x_min_m=0.001, x_min_k=0.001, alpha_par=0, beta_par=5e-06, eta_par=0, p_par=3, q_par=1, passive_coord=None, nodes=[0], number_deltas=5, delta_interval=(1e-12, 0.01))

Approximate method for solving partial differential equations.

Parameters
  • el (list) –

    List of elements to be used.

    • Example: el = [0, 1, 2]

  • number_deltas (int) – Number of delta to calculate FDM.

  • delta_interval (float) – Delta range used.

functions_opt.freqresponse(coord, connect, ind_rows, ind_cols, nelx, nely, ngl, E, v, rho, alpha, beta, eta, xval, x_min_m, x_min_k, p_par, q_par, freq_range, func_name, const_func, modes, load_vector, passive_el, ind_passive, aux_R, **kwargs)

Calculates the objective function for a range of frequencies.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • ind_rows (numpy.array) – Node indices to make the assembly.

  • ind_cols (numpy.array) – Node indices to make the assembly.

  • nelx (int) – Number of elements on the X-axis.

  • nely (int) – Number of elements on the Y-axis.

  • ngl (int) – Degrees of freedom.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

  • alpha (float) – Damping coefficient proportional to mass.

  • beta (float) – Damping coefficient proportional to stiffness.

  • eta (float) – Damping coefficient.

  • xval (numpy.array) – Indicates where there is mass.

  • x_min_m (float) – Minimum relative densities to mass.

  • x_min_k (float) – Minimum relative densities to stiffness.

  • p_par (int) – Penalization power to stiffness.

  • q_par (int) – Penalization power to mass.

  • freq_range (list) – Frequency range. First value is the minimum frequency. Second value is the maximum frequency. Third value is the step between each calculation of the objective function.

  • func_name (str) – Objective function used.

  • const_func (float) –

  • modes (int) – The number of eigenvalues and eigenvectors desired.

  • load_vector (numpy.array) – Load.

  • passive_el (numpy.array) – Passive element nodes.

  • ind_passive (numpy.array) – Index of passive elements.

Returns

Objective function for the frequency range.

functions_opt.get_disp_vector(modes, stif_matrix, mass_matrix, dyna_stif, load_vector, free_ind, omega_par, alpha_par, beta_par, eta_par, ngl)

Calculates displacement vector.

Parameters
  • modes (int) – The number of eigenvalues and eigenvectors desired.

  • stif_matrix (numpy.array) – Stiffness matrix.

  • mass_matrix (numpy.array) – Mass matrix.

  • dyna_stif (numpy.array) – Dynamic stiffness matrix.

  • load_vector (numpy.array) – Load.

  • free_ind (numpy.array) – Free dofs.

  • omega_par (float) – 2 pi frequency.

  • alpha_par (float) – Damping coefficient proportional to mass.

  • beta_par (float) – Damping coefficient proportional to stiffness.

  • eta_par (float) – Damping coefficient.

  • ngl (int) – Degrees of freedom.

Returns

displacement vector, natural frequencies if using modal analysis and time to calculate the displacement vector.

functions_opt.get_neighbors_radius(nelx, nely, coord, connect, radius)

Check neighboring elements that have the centroid within the predetermined radius.

Parameters
  • nelx (int) – Number of elements on the x axis.

  • nely (int) – Number of elements on the x axis

  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • radius (float) – Radius to get elements in the vicinity of each element.

Returns

neighbors, H, centroids

functions_opt.get_passive_el(passive_coord, centroids)

Gets index of passive elements .

Parameters
  • passive_coord (tuple) – Region that the shape will not be changed.

  • centroids (numpy.array) – Coordinate (x,y) of the centroid of each element.

Returns

Index of passive elements.

functions_opt.harmonic_problem(ngl, dyna_stif, load_vector, free_ind=None)

Calculates displacement.

Parameters
  • ngl (int) – Degrees of freedom.

  • dyna_stif (numpy.array) – Dynamic stiffness matrix.

  • load_vector (numpy.array) – Load.

  • free_ind (numpy.array) – Free dofs.

Returns

A tuple with displacement vector and time.

functions_opt.modal_analysis(stif_matrix, mass_matrix, free_ind, modes=20)

Modal Analysis. Use eigh Scipy function.

Parameters
  • stif_matrix (numpy.array) – Stiffness matrix.

  • mass_matrix (numpy.array) – Mass matrix.

  • modes (int, optional) – The number of eigenvalues and eigenvectors desired.

Returns

A tuple with natural frequencies and modes shape.

functions_opt.mode_superposition(natural_frequencies, modal_shape, stif_matrix, load_vector, omega_par, alpha, beta, eta, free_ind)
Perform an harmonic analysis through superposition method and returns the response of

all nodes due the external or internal equivalent load. It has been implemented two different damping models: Viscous Proportional and Hysteretic Proportional Entries for Viscous Proportional Model Damping: (alpha_v, beta_v) Entries for Hyteretic Proportional Model Damping: (alpha_h, beta_h)

Parameters
  • stif_matrix (numpy.array) – Stiffness matrix.

  • load_vector (numpy.array) – Load.

  • omega_par (float) – 2 pi frequency

  • alpha (float) – Damping coefficient proportional to mass.

  • beta (float) – Damping coefficient proportional to stiffness.

  • eta (float) – Damping coefficient.

  • free_ind (numpy.array) – Free dofs.

Returns

A tuple with displacement and time to solve the problem.

functions_opt.normalize(n, f0_scale, f0val, df0dx)

Normalizes objective functions and it’s derivative.

Parameters
  • n (float) – Weight associated with function.

  • f0_scale (float) – Value of the function.

  • f0val (numpy.array) – Objective function.

  • df0dx (numpy.array) – Derivative value of the function.

Returns

Normalized function and it’s derivative.

functions_opt.normalize_constr(fval, f_scale_constr)

Normalizes constraint functions.

Parameters
  • f_scale_constr (float) – Value of the function.

  • fval (numpy.array) – Constraint functions.

Returns

Normalized functions.

functions_opt.out_deriv(all_deriv, dfdx, df0dx2)

Auxiliary function.

functions_opt.printProgressBar(iteration, total, prefix='', suffix='', decimals=1, length=100, fill='█', printEnd='\r')

Call in a loop to create terminal progress bar.

Code link

Parameters
  • iteration (int) – current iteration.

  • total (int) – total iterations.

  • prefix (str, optional) – prefix string.

  • suffix (str, optional) – suffix string.

  • decimals (int, optional) – positive number of decimals in percent complete.

  • length (int, optional) – character length of bar.

  • fill (str, optional) – bar fill character.

  • printEnd (str, optional) – end character.

functions_opt.sensitivity_filter(H, neighbors, x_min_k, xval, dfdx, df0dx, df0dx2=None)

Applies the sensitivity filter to the derivative of the functions (constrain, objective and multiobjective).

Parameters
  • H (csc_matrix) – Radius subtracted from the distance between the element and the neighbors.

  • neighbors (csc_matrix) – Neighbors of each element.

  • xval (numpy.array) – Indicates where there is mass.

  • dfdx (numpy.array) – Value of the constraint derivative.

  • df0dx (numpy.array) – Derivative value of the objective function.

  • df0dx2 (numpy.array, optional) – Derivative value of the second objective function.

Returns

Sensitivity filter applied to the derivative values.

functions_opt.set_deriv(dfdx, df0dx, df0dx2)

Auxiliary function.

functions_opt.set_initxval(constr_func, constr_values)

Calculates the initial value of xval.

Parameters
  • constr_func (list) – constraint functions applied.

  • constr_values (list) – Values of constraint functions applied.

Returns

First value of xval

Return type

initial_xval (float)

functions_opt.set_passive_el(xmin, xval, passive_el)

Sets the values of passive elements.

Parameters
  • xmin (numpy.array) –

  • xval (numpy.array) – Indicates where there is mass.

  • passive_el (numpy.array) – Passive element nodes.

Returns

A tuple with updated xmin and xval.

functions_opt.solution2D(coord, connect, nelx, nely, E, v, rho, xval, x_min_m, x_min_k, p_par, q_par)

Gets values for assembling the stiffness and mass matrices.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • nelx (int) – Number of elements on the X-axis.

  • nely (int) – Number of elements on the Y-axis.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

  • xval (numpy.array) – Indicates where there is mass.

  • x_min_m (float) – Minimum relative densities to mass.

  • x_min_k (float) – Minimum relative densities to stiffness.

  • p_par (int) – Penalization power to c.

  • q_par (int) – Penalization power to mass.

Returns

A tuple with stiffness matrix, mass matrix and time to assembly the matrices.

functions_opt.total_area(lx, ly, area, xval)

Calculates the total element area.

Parameters
  • lx (float) – X-axis length.

  • ly (float) – Y-axis length.

  • nelx (int) – Number of elements on the X-axis.

  • nely (int) – Number of elements on the Y-axis.

Returns

Total element area.

functions_opt.update_lists(outit, fval, f0val, list_iter, list_fvals, list_f0val, constr_values)

Adds new values to list of functions to plot convergence

Parameters
  • outit (int) – Iteration.

  • fval (numpy.array) – Constraint function.

  • f0val (numpy.array) – Objective function.

  • list_iter (list) – All iteration values.

  • list_fvals (list) – All constraint function values.

  • list_f0val (list) – All objective function values.

  • constr_values (list) – Values of constraint functions applied.

Returns

A tuple of lists with iterations, objective and constraint function.

Objective functions

functions_obj.R_ratio(disp_vector, stif_matrix, mass_matrix, omega_par, const_func)

Calculates the strain-to-kinetic energy ratio R.

Parameters
  • disp_vector (numpy.array) – Displacement.

  • stif_matrix (numpy.array) – Stiffness matrix.

  • mass_matrix (numpy.array) – Mass matrix.

  • omega_par (float) – 2 * pi * frequency.

  • const_func (float) –

Returns

Strain-to-kinetic energy ratio on the logarithmic scale and the non-logarithmic strain-to-kinetic energy ratio.

functions_obj.R_ratio_local(omega_par, disp_vector, passive_el, ind_passive, coord, connect, E, v, rho, const_func, aux_R=True)

Calculates the local strain-to-kinetic energy ratio function.

Parameters
  • omega_par (float) – 2 * pi * frequency.

  • disp_vector (numpy.array) – Displacement.

  • passive_el (numpy.array, optional) – Passive element nodes.

  • ind_passive (numpy.array, optional) – Index of passive elements.

  • coord (numpy.array, optional) – Coordinates of the element.

  • connect (numpy.array, optional) – Element connectivity.

  • E (float, optional) – Elastic modulus.

  • v (float, optional) – Poisson’s ratio.

  • rho (float, optional) – Density.

  • aux_R (bool, optional) – If True fvirg is a tuple with local kinetic energy and local elastic potential energy.

Returns

Local strain-to-kinetic energy ratio on the logarithmic scale and the non-logarithmic strain-to-kinetic energy ratio.

functions_obj.compliance(disp_vector, load_vector)

Calculates the compliance function.

Parameters
  • disp_vector (numpy.array) – Displacement.

  • load_vector (numpy.array) – Force.

Returns

non-logarithmic compliance.

functions_obj.elastic_potential_energy(disp_vector, stif_matrix, const_func)

Calculates the elastic potential energy function.

Parameters
  • disp_vector (numpy.array) – Displacement.

  • stif_matrix (numpy.array) – Stiffness matrix.

  • const_func (float) –

Returns

Potential elastic energy on the logarithmic scale and the non-logarithmic potential elastic energy.

functions_obj.elastic_potential_local(disp_vector, passive_el, ind_passive, coord, connect, E, v, rho, const_func)

Calculates the local elastic potential energy function.

Parameters
  • disp_vector (numpy.array) – Displacement.

  • passive_el (numpy.array, optional) – Passive element nodes.

  • ind_passive (numpy.array, optional) – Index of passive elements.

  • coord (numpy.array, optional) – Coordinates of the element.

  • connect (numpy.array, optional) – Element connectivity.

  • E (float, optional) – Elastic modulus.

  • v (float, optional) – Poisson’s ratio.

  • rho (float, optional) – Density.

Returns

Local elastic potential energy on the logarithmic scale and the non-logarithmic local elastic potential energy.

functions_obj.input_power(disp_vector, load_vector, omega_par, const_func)

Calculates the input power function.

Parameters
  • disp_vector (numpy.array) – Displacement.

  • load_vector (numpy.array) – Force.

  • omega_par (float) – 2 * pi * frequency.

  • const_func (float) –

Returns

Input power on the logarithmic scale and the non-logarithmic input power.

functions_obj.kinetic_energy(disp_vector, mass_matrix, omega_par, const_func)

Calculates the kinetic energy function.

Parameters
  • disp_vector (numpy.array) – Displacement.

  • mass_matrix (numpy.array) – Mass matrix.

  • omega_par (float) – 2 * pi * frequency.

  • const_func (float) –

Returns

Kinetic energy on the logarithmic scale and the non-logarithmic kinetic energy.

functions_obj.kinetic_local(omega_par, disp_vector, passive_el, ind_passive, coord, connect, E, v, rho, const_func)

Calculates the local kinetic energy function.

Parameters
  • omega_par (float) – 2 * pi * frequency.

  • disp_vector (numpy.array) – Displacement.

  • passive_el (numpy.array, optional) – Passive element nodes.

  • ind_passive (numpy.array, optional) – Index of passive elements.

  • coord (numpy.array, optional) – Coordinates of the element.

  • connect (numpy.array, optional) – Element connectivity.

  • E (float, optional) – Elastic modulus.

  • v (float, optional) – Poisson’s ratio.

  • rho (float, optional) – Density.

Returns

Local kinetic energy on the logarithmic scale and the non-logarithmic local kinetic energy.

functions_obj.objective_funcs(func_name, disp_vector, stif_matrix=None, mass_matrix=None, load_vector=None, omega_par=None, const_func=None, passive_el=None, ind_passive=None, coord=None, connect=None, E=None, v=None, rho=None, aux_R=True)

Calculates the objective function.

Parameters
  • func_name (str) – Objective function used.

  • disp_vector (numpy.array) – Displacement.

  • stif_matrix (numpy.array, optional) – Stiffness matrix.

  • mass_matrix (numpy.array, optional) – Mass matrix.

  • load_vector (numpy.array, optional) – Force.

  • omega_par (float, optional) – 2 * pi * frequency.

  • const_func (float) –

  • passive_el (numpy.array, optional) – Passive element nodes.

  • ind_passive (numpy.array, optional) – Index of passive elements.

  • coord (numpy.array, optional) – Coordinates of the element.

  • connect (numpy.array, optional) – Element connectivity.

  • E (float, optional) – Elastic modulus.

  • v (float, optional) – Poisson’s ratio.

  • rho (float, optional) – Density.

  • aux_R (bool, optional) – If True fvirg is a tuple with local kinetic energy and local elastic potential energy.

Returns

Objective function on the logarithmic scale and the non-logarithmic objective function.

Derived Objective functions

functions_deriv.derivative_R(coord, connect, E, v, rho, alpha, beta, omega_par, p_par, q_par, x_min_m, x_min_k, xval, disp_vector, lam, fvirg, kinetic_e)

Calculates the derivative of the strain-to-kinetic function.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

  • alpha (float) – Damping coefficient proportional to mass.

  • beta (float) – Damping coefficient proportional to stiffness.

  • omega_par (float) – 2 * pi * frequency

  • p_par (float) – Penalization power to stiffness.

  • q_par (float) – Penalization power to mass.

  • x_min_m (float) – Minimum relative densities to mass.

  • x_min_k (float) – Minimum relative densities to stiffness.

  • xval (numpy.array) – Indicates where there is mass.

  • disp_vector (numpy.array) – Displacement vector.

  • lam (float) – Lambda parameter.

  • fvirg (float) – Strain-to-kinetic function.

  • kinetic_e (float) – Kinetic energy function.

Returns

Derivative of the strain-to-kinetic function function.

functions_deriv.derivative_compliance(coord, connect, E, v, rho, alpha, beta, omega_par, p_par, q_par, x_min_m, x_min_k, xval, disp_vector, lam)

calculates the derivative of the compliance function.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

  • alpha (float) – Damping coefficient proportional to mass.

  • beta (float) – Damping coefficient proportional to stiffness.

  • omega_par (float) – 2 * pi * frequency

  • p_par (float) – Penalization power to stiffness.

  • q_par (float) – Penalization power to mass.

  • x_min_m (float) – Minimum relative densities to mass.

  • x_min_k (float) – Minimum relative densities to stiffness.

  • xval (numpy.array) – Indicates where there is mass.

  • disp_vector (numpy.array) – Displacement vector.

  • lam (float) – Lambda parameter.

Returns

Derivative of the compliance function.

functions_deriv.derivative_ek(coord, connect, E, v, rho, alpha, beta, omega_par, p_par, q_par, x_min_m, x_min_k, xval, disp_vector, lam)

Calculates the derivative of the kinetic energy function.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

  • alpha (float) – Damping coefficient proportional to mass.

  • beta (float) – Damping coefficient proportional to stiffness.

  • omega_par (float) – 2 * pi * frequency

  • p_par (float) – Penalization power to stiffness.

  • q_par (float) – Penalization power to mass.

  • x_min_m (float) – Minimum relative densities to mass.

  • x_min_k (float) – Minimum relative densities to stiffness.

  • xval (numpy.array) – Indicates where there is mass.

  • disp_vector (numpy.array) – Displacement vector.

  • lam (float) – Lambda parameter.

Returns

Derivative of the kinetic energy function.

functions_deriv.derivative_ep(coord, connect, E, v, rho, alpha, beta, omega_par, p_par, q_par, x_min_m, x_min_k, xval, disp_vector, lam)

calculates the derivative of the elastic potential energy function.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

  • alpha (float) – Damping coefficient proportional to mass.

  • beta (float) – Damping coefficient proportional to stiffness.

  • omega_par (float) – 2 * pi * frequency

  • p_par (float) – Penalization power to stiffness.

  • q_par (float) – Penalization power to mass.

  • x_min_m (float) – Minimum relative densities to mass.

  • x_min_k (float) – Minimum relative densities to stiffness.

  • xval (numpy.array) – Indicates where there is mass.

  • disp_vector (numpy.array) – Displacement.

  • lam (float) – Lambda parameter.

  • fvirg (float) – Elastic potential energy function.

Returns

Derivative elastic potential energy function.

functions_deriv.derivative_input_power(coord, connect, E, v, rho, alpha, beta, omega_par, p_par, q_par, x_min_m, x_min_k, xval, disp_vector)

Calculates the derivative of the input power function.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

  • alpha (float) – Damping coefficient proportional to mass.

  • beta (float) – Damping coefficient proportional to stiffness.

  • omega_par (float) – 2 * pi * frequency

  • p_par (float) – Penalization power to stiffness.

  • q_par (float) – Penalization power to mass.

  • x_min_m (float) – Minimum relative densities to mass.

  • x_min_k (float) – Minimum relative densities to stiffness.

  • xval (numpy.array) – Indicates where there is mass.

  • disp_vector (numpy.array) – Displacement vector.

Returns

Derivative of the input power function.

functions_deriv.derivative_local_R(df_ep, df_ki, fvirg)

Calculates the derivative of the local strain-to-kinetic function.

Parameters
  • df_ep (numpy.array) – Elastic potential energy derivative.

  • df_ki (numpy.array) – Kinetic energy derivative.

  • fvirg (float) – Local strain-to-kinetic function.

Returns

Derivative of the local strain-to-kinetic function function.

functions_deriv.derivative_local_ep(passive_el, lam, ind_dofs, xval, disp_vector, connect, coord, E, v, rho, x_min_k, x_min_m, omega_par, alpha, beta, p_par, q_par)

Calculates the derivative of the local elastic potential energy function.

Parameters
  • passive_el (numpy.array) – Passive element nodes.

  • lam (float) – Lambda parameter.

  • ind_dofs (numpy.array, optional) – TODO

  • xval (numpy.array) – Indicates where there is mass.

  • disp_vector (numpy.array) – Displacement vector.

  • connect (numpy.array) – Element connectivity.

  • coord (numpy.array) – Coordinates of the element.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

  • x_min_m (float) – Minimum relative densities to mass.

  • x_min_k (float) – Minimum relative densities to stiffness.

  • omega_par (float) – 2 * pi * frequency.

  • alpha (float) – Damping coefficient proportional to mass.

  • beta (float) – Damping coefficient proportional to stiffness.

  • p_par (int) – Penalization power to stiffness.

  • q_par (int) – Penalization power to mass.

Returns

Derivative of the local elastic potential energy function.

functions_deriv.derivative_local_ki(coord, connect, E, v, rho, alpha, beta, omega_par, p_par, q_par, x_min_m, x_min_k, xval, disp_vector, lam, ind_dofs, passive_el)

Calculates the derivative of the local kinetic energy function.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

  • alpha (float) – Damping coefficient proportional to mass.

  • beta (float) – Damping coefficient proportional to stiffness.

  • omega_par (float) – 2 * pi * frequency.

  • p_par (int) – Penalization power to stiffness.

  • q_par (int) – Penalization power to mass.

  • x_min_m (float) – Minimum relative densities to mass.

  • x_min_k (float) – Minimum relative densities to stiffness.

  • xval (numpy.array) – Indicates where there is mass.

  • disp_vector (numpy.array) – Displacement vector.

  • lam (float) – Lambda parameter.

  • ind_dofs (numpy.array, optional) – TODO

  • passive_el (numpy.array) – Passive element nodes.

Returns

Derivative of the local input power energy function.

functions_deriv.derivatives_objective(func_name, fvirg, disp_vector, coord, connect, E, v, rho, alpha_par, beta_par, omega_par, p_par, q_par, x_min_m, x_min_k, xval, load_vector=None, mass_matrix=None, stif_matrix=None, dyna_stif=None, free_ind=None, ind_dofs=None, ngl=None, ind_passive=None, passive_el=None)

Calculates the derivative of the specified function.

Parameters
  • func_name (str) – Objective function used.

  • fvirg (float) – Non-logarithm function value.

  • disp_vector (numpy.array) – Displacement vector.

  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

  • alpha_par (float) – Damping coefficient proportional to mass.

  • beta_par (float) – Damping coefficient proportional to stiffness.

  • omega_par (float) – 2 * pi * frequency.

  • p_par (int) – Penalization power to stiffness.

  • q_par (int) – Penalization power to mass.

  • x_min_m (float) – Minimum relative densities to mass.

  • x_min_k (float) – Minimum relative densities to stiffness.

  • xval (numpy.array) – Indicates where there is mass.

  • load_vector (numpy.array, optional) – Force vector.

  • mass_matrix (numpy.array, optional) – Mass matrix.

  • stif_matrix (numpy.array, optional) – Stiffness matrix.

  • dyna_stif (numpy.array, optional) – Dynamic stiffness matrix.

  • free_ind (numpy.array, optional) – Free dofs.

  • ind_dofs (numpy.array, optional) – Defaults to None.

  • ngl (int) – Degrees of freedom.

  • ind_passive (numpy.array, optional) – Index of passive elements.

  • passive_el (numpy.array, optional) – Passive element nodes.

Returns

Derivative of the specified function.

functions_deriv.lambda_R(disp_vector, dyna_stif, stif_matrix, mass_matrix, omega_par, fvirg, kinetic_e, free_ind)

Calculates the lambda solution of the strain-to-kinetic function.

Parameters
  • disp_vector (numpy.array) – Displacement vector.

  • dyna_stif (array) – Stifness matrix.

  • stif_matrix (numpy.array) – Stiffness matrix.

  • mass_matrix (numpy.array) – Mass matrix.

  • omega_par (float) – 2 * pi * frequency.

  • fvirg (float) – Strain-to-kinetic function.

  • kinetic_e (float) –

  • free_ind (numpy.array) – Free dofs.

Returns

Lambda parameter solution.

functions_deriv.lambda_compliance(disp_vector, load_vector, function)

Calculates the lambda parameter of the compliance function.

Parameters
  • disp_vector (numpy.array) – Displacement vector.

  • load_vector (numpy.array) – Force vector.

  • function (float) – Function value.

Returns

Lambda parameter solution.

functions_deriv.lambda_ek(disp_vector, mass_matrix, dyna_stif, omega_par, free_ind)

Calculates the lambda solution of the kinetic energy function.

Parameters
  • disp_vector (numpy.array) – Displacement vector.

  • mass_matrix (numpy.array) – Mass matrix.

  • dyna_stif (array) – Stifness matrix.

  • omega_par (float) – 2 * pi * frequency.

  • free_ind (numpy.array) – Free dofs.

Returns

Lambda parameter solution.

functions_deriv.lambda_ep(disp_vector, stif_matrix, dyna_stif, free_ind)

Calculates the lambda solution of the elastic potential energy function.

Parameters
  • disp_vector (numpy.array) – Displacement vector.

  • stif_matrix (numpy.array) – Stiffness matrix.

  • dyna_stif (numpy.array) – Dynamic stiffness matrix.

  • free_ind (numpy.array) – Free dofs.

Returns

Lambda parameter solution.

functions_deriv.lambda_local_ep(ngl, ind_passive, passive_el, disp_vector, dyna_stif, coord, connect, E, v, rho)

Calculates the lambda parameter of the local elastic potential energy function.

Parameters
  • ngl (int) – Degrees of freedom.

  • ind_passive (numpy.array) – Index of passive elements.

  • passive_el (numpy.array) – Passive element nodes.

  • disp_vector (numpy.array) – Displacement vector.

  • dyna_stif (numpy.array) – Dynamic stiffness matrix.

  • omega_par (float) – 2 * pi * frequency.

  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

Returns

Lambda parameter solution.

functions_deriv.lambda_local_ki(ngl, ind_passive, passive_el, disp_vector, dyna_stif, omega_par, coord, connect, E, v, rho)

Calculates the lambda parameter of the local kinetic energy function.

Parameters
  • ngl (int) – Degrees of freedom.

  • ind_passive (numpy.array) – Index of passive elements.

  • passive_el (numpy.array) – Passive element nodes.

  • disp_vector (numpy.array) – Displacement vector.

  • dyna_stif (numpy.array) – Dynamic stiffness matrix.

  • omega_par (float) – 2 * pi * frequency.

  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

Returns

Lambda parameter solution.

Optimization functions

Orginal work Written by Krister Svanberg in Matlab. This is the python version of the code written by Arjen Deetman.

This file gives the functions mmasub, gcmmasub, subsolv and kktcheck.

mma_opt.asymp(outeriter, n, xval, xold1, xold2, xmin, xmax, low, upp, raa0, raa, raa0eps, raaeps, df0dx, dfdx)

Values on the parameters raa0, raa, low and upp are calculated in the beginning of each outer iteration.

Parameters
  • outeriter – Current iteration number.

  • n – The number of variables x_j.

  • xval – Column vector with the current values of the variables x_j.

  • xold1 – xval, one iteration ago (provided that iter>1).

  • xold2 – xval, two iterations ago (provided that iter>2).

  • xmin – Column vector with the lower bounds for the variables x_j.

  • xmax – Column vector with the upper bounds for the variables x_j.

  • low – Column vector with the lower asymptotes from the previous iteration (provided that iter>1).

  • upp – Column vector with the upper asymptotes from the previous iteration (provided that iter>1).

  • raa0

  • raa

  • raa0eps

  • raaeps

  • df0dx – Column vector with the derivatives of the objective function f_0 with respect to the variables x_j, calculated at xval.

  • dfdx – (m x n)-matrix with the derivatives of the constraint functions f_i with respect to the variables x_j, calculated at xval. dfdx(i,j) = the derivative of f_i with respect to x_j.

Returns

The parameters low, upp, raa0, raa

mma_opt.concheck(m, epsimin, f0app, f0valnew, fapp, fvalnew)

If the current approximations are conservative, the parameter conserv is set to 1.

Parameters
  • m – The number of general constraints.

  • epsimin

  • f0app

  • f0valnew – The value of the objective function f_0 at xval.

  • fapp

  • fvalnew – Column vector with the values of the constraint functions f_i, calculated at xval.

Returns

Parameter conserv.

mma_opt.gcmmasub(m, n, iter, epsimin, xval, xmin, xmax, low, upp, raa0, raa, f0val, df0dx, fval, dfdx, a0, a, c, d)

This function gcmmasub performs one GCMMA-iteration, aimed at solving the nonlinear programming problem:

Minimize f_0(x) + a_0*z + sum(c_i*y_i + 0.5*d_i*(y_i)^2)

subject to f_i(x) - a_i*z - y_i <= 0, i = 1,…, m

xmin_j <= x_j <= xmax_j, j = 1,…, n

z >= 0, y_i >= 0, i = 1,…,m

Parameters
  • m – The number of general constraints.

  • n – The number of variables x_j.

  • iter – Current iteration number ( =1 the first time mmasub is called).

  • epsimin – Associate to error.

  • xval – Column vector with the current values of the variables x_j.

  • xmin – Column vector with the lower bounds for the variables x_j.

  • xmax – Column vector with the upper bounds for the variables x_j.

  • low – Column vector with the lower asymptotes from the previous iteration (provided that iter>1).

  • upp – Column vector with the upper asymptotes from the previous iteration (provided that iter>1).

  • xold1 – xval, one iteration ago (provided that iter>1).

  • xold2 – xval, two iterations ago (provided that iter>2).

  • f0val – The value of the objective function f_0 at xval.

  • df0dx – Column vector with the derivatives of the objective function f_0 with respect to the variables x_j, calculated at xval.

  • fval – Column vector with the values of the constraint functions f_i, calculated at xval.

  • dfdx – (m x n)-matrix with the derivatives of the constraint functions f_i with respect to the variables x_j, calculated at xval. dfdx(i,j) = the derivative of f_i with respect to x_j.

  • raa0

  • raa

  • f0val – The value of the objective function f_0 at xval.

  • df0dx – Column vector with the derivatives of the objective function f_0 with respect to the variables x_j, calculated at xval.

  • fval – Column vector with the values of the constraint functions f_i, calculated at xval.

  • dfdx – (m x n)-matrix with the derivatives of the constraint functions f_i with respect to the variables x_j, calculated at xval. dfdx(i,j) = the derivative of f_i with respect to x_j.

  • a0 – The constants a_0 in the term a_0*z.

  • a – Column vector with the constants a_i in the terms a_i*z.

  • c – Column vector with the constants c_i in the terms c_i*y_i.

  • d – Column vector with the constants d_i in the terms 0.5*d_i*(y_i)^2.

Returns

  • xmma : Column vector with the optimal values of the variables x_j in the current MMA subproblem.

  • ymma : Column vector with the optimal values of the variables y_i in the current MMA subproblem.

  • zmma : Scalar with the optimal value of the variable z in the current MMA subproblem.

  • lam : Lagrange multipliers for the m general MMA constraints.

  • xsi : Lagrange multipliers for the n constraints alfa_j - x_j <= 0.

  • eta : Lagrange multipliers for the n constraints x_j - beta_j < : 0.

  • mu : Lagrange multipliers for the m constraints -y_i <= 0.

  • zet : Lagrange multiplier for the single constraint -z <= 0.

  • s : Slack variables for the m general MMA constraints.

  • f0app :

  • fapp :

Return type

(tuple)

mma_opt.kktcheck(m, n, x, y, z, lam, xsi, eta, mu, zet, s, xmin, xmax, df0dx, fval, dfdx, a0, a, c, d)

The left hand sides of the KKT conditions for the following nonlinear programming problem are calculated.

Minimize f_0(x) + a_0*z + sum(c_i*y_i + 0.5*d_i*(y_i)^2)

subject to f_i(x) - a_i*z - y_i <= 0, i = 1,…,m

xmax_j <= x_j <= xmin_j, j = 1,…,n

z >= 0, y_i >= 0, i = 1,…,m.

Parameters
  • m – The number of general constraints.

  • n – The number of variables x_j.

  • x – Current values of the n variables x_j.

  • y – Current values of the m variables y_i.

  • z – Current value of the single variable z.

  • lam – Lagrange multipliers for the m general constraints.

  • xsi – Lagrange multipliers for the n constraints xmin_j - x_j <= 0.

  • eta – Lagrange multipliers for the n constraints x_j - xmax_j <= 0.

  • mu – Lagrange multipliers for the m constraints -y_i <= 0.

  • zet – Lagrange multiplier for the single constraint -z <= 0.

  • s – Slack variables for the m general constraints.

  • xmin – Lower bounds for the variables x_j.

  • xmax – Upper bounds for the variables x_j.

  • df0dx – Vector with the derivatives of the objective function f_0 with respect to the variables x_j, calculated at x.

  • fval – Vector with the values of the constraint functions f_i, calculated at x.

  • dfdx – [m x n] matrix with the derivatives of the constraint functions f_i with respect to the variables x_j, calculated at x. dfdx(i,j) = the derivative of f_i with respect to x_j.

  • a0 – The constants a_0 in the term a_0*z.

  • a – Vector with the constants a_i in the terms a_i*z.

  • c – Vector with the constants c_i in the terms c_i*y_i.

  • d – Vector with the constants d_i in the terms 0.5*d_i*(y_i)^2.

Returns

  • residu : the residual vector for the KKT conditions.

  • residunorm : sqrt(residu.T*residu).

  • residumax : max(abs(residu)).

Return type

(tuple)

mma_opt.mmasub(m, n, iter, xval, xmin, xmax, xold1, xold2, f0val, df0dx, fval, dfdx, low, upp, a0, a, c, d, move)

This function mmasub performs one MMA-iteration, aimed at solving the nonlinear programming problem:

Minimize f_0(x) + a_0*z + sum(c_i*y_i + 0.5*d_i*(y_i)^2)

subject to f_i(x) - a_i*z - y_i <= 0, i = 1,…, m

xmin_j <= x_j <= xmax_j, j = 1,…, n

z >= 0, y_i >= 0, i = 1,…,m

Parameters
  • m – The number of general constraints.

  • n – The number of variables x_j.

  • iter – Current iteration number ( =1 the first time mmasub is called).

  • xval – Column vector with the current values of the variables x_j.

  • xmin – Column vector with the lower bounds for the variables x_j.

  • xmax – Column vector with the upper bounds for the variables x_j.

  • xold1 – xval, one iteration ago (provided that iter>1).

  • xold2 – xval, two iterations ago (provided that iter>2).

  • f0val – The value of the objective function f_0 at xval.

  • df0dx – Column vector with the derivatives of the objective function f_0 with respect to the variables x_j, calculated at xval.

  • fval – Column vector with the values of the constraint functions f_i, calculated at xval.

  • dfdx – (m x n)-matrix with the derivatives of the constraint functions f_i with respect to the variables x_j, calculated at xval. dfdx(i,j) = the derivative of f_i with respect to x_j.

  • low – Column vector with the lower asymptotes from the previous iteration (provided that iter>1).

  • upp – Column vector with the upper asymptotes from the previous iteration (provided that iter>1).

  • a0 – The constants a_0 in the term a_0*z.

  • a – Column vector with the constants a_i in the terms a_i*z.

  • c – Column vector with the constants c_i in the terms c_i*y_i.

  • d – Column vector with the constants d_i in the terms 0.5*d_i*(y_i)^2.

  • move – Step taken.

Returns

  • xmma : Column vector with the optimal values of the variables x_j in the current MMA subproblem.

  • ymma : Column vector with the optimal values of the variables y_i in the current MMA subproblem.

  • zmma : Scalar with the optimal value of the variable z in the current MMA subproblem.

  • lam : Lagrange multipliers for the m general MMA constraints.

  • xsi : Lagrange multipliers for the n constraints alfa_j - x_j <= 0.

  • eta : Lagrange multipliers for the n constraints x_j - beta_j < : 0.

  • mu : Lagrange multipliers for the m constraints -y_i <= 0.

  • zet : Lagrange multiplier for the single constraint -z <= 0.

  • s : Slack variables for the m general MMA constraints.

  • low : Column vector with the lower asymptotes, calculated and used in the current MMA subproblem.

  • upp : Column vector with the upper asymptotes, calculated and used in the current MMA subproblem.

Return type

(tuple)

mma_opt.raaupdate(xmma, xval, xmin, xmax, low, upp, f0valnew, fvalnew, f0app, fapp, raa0, raa, raa0eps, raaeps, epsimin)

Values of the parameters raa0 and raa are updated during an inner iteration.

Parameters
  • xmma – Column vector with the optimal values of the variables x_j in the current MMA subproblem.

  • xval – Column vector with the current values of the variables x_j.

  • xmin – Column vector with the lower bounds for the variables x_j.

  • xmax – Column vector with the upper bounds for the variables x_j.

  • low – Column vector with the lower asymptotes from the previous iteration (provided that iter>1).

  • upp – Column vector with the upper asymptotes from the previous iteration (provided that iter>1).

  • f0valnew – Vector with the values of the constraint functions f_i, calculated at x.

  • f0app

  • fapp

  • raa0

  • raa

  • raa0eps

  • raaeps

  • epsimin

Returns

Parameters raa0 and raa.

mma_opt.subsolv(m, n, epsimin, low, upp, alfa, beta, p0, q0, P, Q, a0, a, b, c, d)

This function subsolv solves the MMA subproblem:

minimize SUM[p0j/(uppj-xj) + q0j/(xj-lowj)] + a0*z + SUM[ci*yi + 0.5*di*(yi)^2],

subject to SUM[pij/(uppj-xj) + qij/(xj-lowj)] - ai*z - yi <= bi, alfaj <= xj <= betaj, yi >= 0, z >= 0.

Parameters
  • m – The number of general constraints.

  • n – The number of variables x_j.

  • epsimin

  • low – Column vector with the lower asymptotes from the previous iteration (provided that iter>1).

  • upp – Column vector with the upper asymptotes from the previous iteration (provided that iter>1).

  • alfa

  • beta

  • p0

  • q0

  • P

  • Q

  • a0 – The constants a_0 in the term a_0*z.

  • a – Column vector with the constants a_i in the terms a_i*z.

  • b

  • c – Column vector with the constants c_i in the terms c_i*y_i.

  • d – Column vector with the constants d_i in the terms 0.5*d_i*(y_i)^2.

Returns

xmma, ymma, zmma, slack variables and Lagrange multiplers.

Plot

plots_opt.compare_freqresponse(freq_range, newf, oldf, func_name)

Plot the frequency response of the original and the optimized function.

Parameters
  • freq_range (list) – Range of analyzed frequencies. First value is the minimum frequency. Second value is the maximum frequency. Third value is the step between each calculation of the objective function.

  • newf (array) – Optimized function.

  • oldf (array) – Original function.

  • func_name (str) – Objective function name. It can be: “compliance”, “input_power”, “elastic_potential_energy”, “kinetic_energy” or “r_ratio”.

Returns

A figure object and a single Axes object from matplotlib.pyplot.

plots_opt.freqrsp_modes(freq_range, newf, oldf, modes, func_name, save)

Plot the frequency response of the function with multiple modes.

Parameters
  • freq_range (list) – Range of frequencies analyzed. First value is the minimum frequency. Second value is the maximum frequency. Third value is the step between each calculation of the objective function.

  • newf (numpy.array) – Optimized function.

  • oldf (numpy.array) – Original function.

  • modes (list) – Analyzed modes.

  • func_name (str) – Objective function name. It can be: “compliance”, “input_power”, “elastic_potential_energy”, “kinetic_energy” or “r_ratio”.

  • save (bool) – True for save the graphic in PNG.

plots_opt.legend_constr(constr_func)

Defines the labels of the constraint functions.

Parameters

constr_func (list) – Restriction functions applied.

Returns

Numpy array with the labels.

plots_opt.save_fig(fig, path, pg_graph)

Saves the graphics: optimized part, convergence graph, frequency response graph and deformed mesh.

Parameters
  • fig – Object with the graph. It can be: - pyqtgraph.graphicsItems.PlotItem or - matplotlib.pyplot.figure.

  • path – Directory to save the graph.

  • pg_graph (bool) – Specifies the type of figure.

plots_opt.set_conv_data(outit, curves_funcs, list_iter, list_f0val, list_fvals, constr_func)

Updates values of the objective function and the constraint function to plot the convergence graph.

plots_opt.set_coord_grid(lx, ly, nelx, nely)

Defines dimensions of the optimized part.

plots_opt.simple_window()

Generates a window to plot the optimized mesh.

Returns

Principal window, optimized part.

plots_opt.update_conv(constr_func, p, list_iter, list_f0val, list_fvals)

Updates values of the objective function and the constraint function to plot the convergence graph.

Parameters
  • constr_func (list) – Restriction functions applied.

  • p (pyqtgraph.graphicsItems.PlotItem) – Convergence graph window

  • list_iter (list) – All iteration values.

  • list_f0val (list) – All objective function values.

  • list_fvals (list) – All constraint function values.

Returns

Convergence graph window.

plots_opt.win_convergence(constr_func, list_iter, list_f0val, list_fvals, func_name, label)

Generates a window to plot the convergence graph.

Parameters
  • constr_func (list) – Restriction functions applied.

  • list_iter (list) – All iteration values.

  • list_f0val (list) – All objective function values.

  • list_fvals (list) – All constraint function values.

  • func_name (str) – Objective function name.

  • label (numpy.array) – Label of the constraint functions.

Returns

Principal window, convergece graph.

plots_opt.window_each_iter(constr_func, func_name, label)

Generates a window to plot the optimized mesh and the convergence graph in the same window.

Parameters
  • constr_func (list) – Restriction functions applied.

  • func_name (str) – Objective function name.

  • label (numpy.array) – Label of the constraint functions.

Returns

Principal window, convergece graph, optimized part.

class plot_grid.PColorMeshItem(*args, **kwargs)

Bases: GraphicsObject

boundingRect(self) QRectF
paint(self, QPainter, QStyleOptionGraphicsItem, widget: QWidget = None)
setData(*args)

Set the data to be drawn.

Parameters
  • x (np.ndarray, optional, default None) – 2D array containing the coordinates of the polygons

  • y (np.ndarray, optional, default None) – 2D array containing the coordinates of the polygons

  • z (np.ndarray) –

    2D array containing the value which will be maped into the polygons colors. If x and y is None, the polygons will be displaced on a grid otherwise x and y will be used as polygons vertices coordinates as:

    (x[i+1, j], y[i+1, j])           (x[i+1, j+1], y[i+1, j+1])
                        +---------+
                        | z[i, j] |
                        +---------+
        (x[i, j], y[i, j])           (x[i, j+1], y[i, j+1])
    
    ”ASCII from: <https://matplotlib.org/3.2.1/api/_as_gen/

    matplotlib.pyplot.pcolormesh.html>”.