I am trying to build a script to size a tank. At some point I have to minimize the weight of the tank depending on three parameters (A_frames, A_stringers and t_skin) and I am using the minimize function of scipy with the SLSQP method to do it.
I begun with a very simple case without any constraints at first. I have to minize the weight for different combination of N_frames/N_stringers but for 3/4 of the combination scipy stops the optimisation at the initial guess, thinking it is the minimum value when it is obviously not (the weight function is linear and very simple!)
I don't understand this at all, especially as it doesn't appear with other methods like ‘L-BFGS-B’ but I can't use the others as they don't take into account bounds and/or constraints.
If someone has the explanation for this it would help me a lot
Here is the section of my code where the problem appears :
import numpy as np
import pandas as pd
from scipy.optimize import minimize
L_tank = 11
rho_s = 2850
rho_f= 2850
rho_skin = 2850
r_tank = 1.9
def Weight(X):
A_frames = X[0]
A_stringers = X[1]
t_skin = X[2]
return L_tank*A_stringers*rho_s*N_stringers + N_frames *A_frames*rho_f*2*np.pi*r_tank + 2*np.pi*r_tank*L_tank*t_skin*rho_skin
def grad_weight(X):
A_frames = X[0]
A_stringers = X[1]
t_skin = X[2]
grad = np.array([rho_f*2*np.pi*r_tank, L_tank*rho_s*N_stringers , 2*np.pi*r_tank*L_tank*rho_skin])
return grad
for N_frames in range (4,40):
for N_stringers in range (8,130,2):
bnd = ((0.0, None), (0.0, None),(tshear, None))
X0 = [0.001,0.000001,0.005]
sol = minimize(Weight, x0 = X0, bounds=bnd, method='SLSQP', jac = grad_weight)
if sol.success:
A_frames = sol.x[0]
A_stringers = sol.x[1]
t_skin = sol.x[2]
weight = Weight(sol.x)