Project

Optimization of Two bar truss

For optimization we need to install a package GEKKO using PIP.

Consider the design of a simple tubular symmetric truss shown in Fig. 1.1 below. A design of the truss is specified by a unique set ofvalues for the analysis variables: height (H), diameter, (d), thickness (t), separation distance (B), modulus of elasticity (E), and material density (`rho`). Suppose we are interested in designing a truss that has a minimum weight, will not yield, will not buckle,and does not deflect "excessively,” and so we decide our model should calculate weight, stress, buckling stress and deflection as analysis functions

"""
Two bar optimization problem
"""

import numpy as np
from gekko import GEKKO

# create new model
m = GEKKO()

# declare model parameters
width = m.Param(value=60)
thickness = m.Param(value=0.15)
density = m.Param(value=0.3)
modulus= m.Param(value=30000)
load = m.Param(value=66)

# declare variables and initial guesses
height = m.Var(value=30.00, lb=10.0, ub=50.0)
diameter = m.Var(value=3.00, lb=1.0, ub=4.0)
weight=m.Var()

# intermidiate variables with explicit equations
length = m.Intermediate(m.sqrt((width/2)**2 + height**2))
area = m.Intermediate(np.pi*diameter*thickness)
ioverall = m.Intermediate((diameter**2+thickness**2)/8)
stress = m.Intermediate(load*length/(2*area*height))
buckling = m.Intermediate(np.pi**2*modulus*ioverall/length**2)
deflection = m.Intermediate(load*length**3 /2*modulus*area*height**2)

# implicit equations
m.Equation(weight==2*density*area*length)
m.Equation(weight<24)
m.Equation(stress<100)
m.Equation(stress<buckling)
m.Equation(deflection<0.25)

# minimize weight
m.Obj(weight)


# solve optimization
m.solve() #remote=false for local solve

print('')
print('---Results of the Optimization Problem---')
print('Height:' + str(height.value))
print('Diameter:' + str(diameter.value))
print('Weight:' + str(weight.value))
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.