I'm using gekko for the first time to do optimization with python. I don't have a lot of experience with python, but I know the basics. I get error code -13 when I run the optimization:
#import Gekko optimization package
from gekko import gekko
import math
#create gekko model
m = gekko()
#constants
pi = math.pi
#initialize needed variables
frictionLoss = m.Var()
empirical = m.Var(value=1)
widthInlet = m.Var(value=1) #in meters
heightInlet = m.Var(value=1) #in meters
diameterOutlet = m.Var(value=1) #in meters
diameterCut = m.Var()
viscosity = m.Var(value=1) #kg/m*s
turns = m.Var()
velocityInlet = m.Var(value=1) #m/s
densityParticle = 10000 #kg/m**3
densityGas = 1.225 #kg/m**3
lengthCone = m.Var(value=1) #in meters
lengthCylinder = m.Var(value=1) #in meters
gravity = 9.806 #m/s^2
separation = m.Var()
#define box equations
m.Equation(frictionLoss==empirical*widthInlet*heightInlet/diameterOutlet**2)
m.Equation(turns==((pi*(2*lengthCylinder - lengthCone))/heightInlet))
m.Equation(diameterCut==((9*viscosity*widthInlet)/(2*pi*turns*velocityInlet*(densityParticle-densityGas)))**.5)
m.Equation(separation==((velocityInlet**2)/((diameterCut/2 )+ gravity)))
#add constraint on surface area
#m.Equation(separation<=.9)
#define object function (negative to maximize instead of minimize)
m.Obj(-separation)
#set mode to steady state optimization (solution does not change with time)
m.options.IMODE = 3
m.solve()
#print results
print('the optimized friction loss is: ' + str(frictionLoss.value))
print('the optimized empirical constant is: ' + str(empirical.value))
print('the optimized inlet width is: ' + str(widthInlet.value))
print('the optimized inlet height is: ' + str(heightInlet.value))
print('the optimized outlet diameter is: ' + str(diameterOutlet.value))
print('the optimized cut diameter is: ' + str(diameterCut.value))
print('the optimized viscosity is: ' + str(viscosity.value))
print('the optimized number of turns is: ' + str(turns.value))
print('the optimized inlet velocity is: ' + str(velocityInlet.value))
print('the optimized particle density is: ' + str(densityParticle.value))
print('the optimized gas density is: ' + str(densityGas.value))
print('the optimized cone length is: ' + str(lengthCone.value))
print('the optimized cylinder length is: ' + str(lengthCylinder.value))
The error returned is:
File "/Users/username/Documents/me 46200/optimization/cyclone optimization/cyclone_optimization.py", line 45, in <module>
m.solve()
File "/Users/username/opt/anaconda3/lib/python3.8/site-packages/gekko/gekko.py", line 2174, in solve
raise Exception(response)
Exception: @error: Solution Not Found
I'm sure this is another rookie fudge up of mine. Any assistance would be appreciated :)
The IPOPT solver error is:
This typically occurs when there is a
NaN
evaluated because of divide by zero. You can either reformulate equations such asx==1/y
tox*y==1
or else put a lower bound ony
to avoid divide by zero. Here is a modified version of your problem that solves successfully.The solution is:
There is additional information in the Design Optimization course such as the two bar truss problem that is related to your problem.