## Spring Design Optimization Problem

## Main.SpringDesign History

Hide minor edits - Show changes to output

Changed lines 97-98 from:

kW = m.Intermediate((4 * d_coil - d_wire)/(4 * (d_coil-d_wire)) + 0.62 * d_wire/d_coil)

to:

kW = m.Intermediate((4 * d_coil - d_wire)/(4 * (d_coil-d_wire)) \

+ 0.62 * d_wire/d_coil)

+ 0.62 * d_wire/d_coil)

Changed line 132 from:

(:sourceend:)

to:

(:sourceend:)

Added lines 50-131:

----

'''Solution Help'''

%width=150px%Attach:gekko.png

See [[https://gekko.readthedocs.io/en/latest/|GEKKO documentation]] and [[https://apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization|additional example problems]].

(:source lang=python:)

from gekko import GEKKO

# Initialize Gekko model

m = GEKKO()

#Maximize force of a spring at its preload height h_0 of 1 inches

#The stress at Hs (solid height) must be less than Sy to protect from damage

# Constants

from numpy import pi

# Model Parameters

delta_0 = 0.4 # inches (spring deflection)

h_0 = 1.0 # inches (preload height)

Q = 15e4 # psi

G = 12e6 # psi

S_e = 45e3 # psi

S_f = 1.5

w = 0.18

# Variables

# inches (wire diameter)

d_wire = m.Var(value=0.07247, lb = 0.01, ub = 0.2)

# inches (coil diameter)

d_coil = m.Var(value=0.6775, lb = 0.0)

# number of coils in the spring

n_coils = m.Var(value=7.58898, lb = 0.0)

# inches (free height spring exerting no force)

h_f = m.Var(value=1.368117, lb = 1.0)

F = m.Var() # Spring force

# Intermediates

S_y = m.Intermediate((0.44 * Q) / (d_wire**w))

h_s = m.Intermediate(n_coils * d_wire)

k = m.Intermediate((G * d_wire**4)/(8 * d_coil**3 * n_coils))

kW = m.Intermediate((4 * d_coil - d_wire)/(4 * (d_coil-d_wire)) + 0.62 * d_wire/d_coil)

n = m.Intermediate((8 * kW * d_coil)/(pi * d_wire**3))

tau_max = m.Intermediate((h_f - h_0 + delta_0) * k * n)

tau_min = m.Intermediate((h_f - h_0) * k * n)

tau_mean = m.Intermediate((tau_max + tau_min) / 2)

tau_alt = m.Intermediate((tau_max - tau_min) / 2)

h_def = m.Intermediate(h_0 - delta_0)

tau_hs = m.Intermediate((h_f - h_s) * k * n)

# Equations

m.Equations([

F == k * (h_f - h_0),

d_coil / d_wire >= 4,

d_coil / d_wire <= 16,

d_coil + d_wire < 0.75,

h_def - h_s > 0.05,

tau_alt < S_e / S_f,

tau_alt + tau_mean < S_y / S_f,

tau_hs < S_y / S_f

])

# Objective function

m.Obj(-F)

# Send to solver

m.solve()

# Print solution

print('Maximum force: ' + str(F[0]))

print('Optimal values: ')

print('d_wire : ' + str(d_wire[0]))

print('d_coil : ' + str(d_coil[0]))

print('n_coils : ' + str(n_coils[0]))

print('h_f : ' + str(h_f[0]))

(:sourceend:)

Deleted lines 49-67:

----

(:html:)

<div id="disqus_thread"></div>

<script type="text/javascript">

/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */

var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname

/* * * DON'T EDIT BELOW THIS LINE * * */

(function() {

var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;

dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';

(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);

})();

</script>

<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

(:htmlend:)

Added lines 34-35:

!!!! Introduction to the Spring Problem

Added lines 38-45:

(:htmlend:)

----

!!!! Help Session

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/Z2jid2kPOnY" frameborder="0" allowfullscreen></iframe>

----

!!!! Help Session

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/Z2jid2kPOnY" frameborder="0" allowfullscreen></iframe>

Added lines 31-36:

----

(:html:)

<iframe width="560" height="315" src="https://www.youtube.com/embed/flmhHZD0YEA?rel=0" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

Changed lines 33-53 from:

Attach:collaborative50.png This assignment can be completed in collaboration with others. Additional guidelines on individual, collaborative, and group assignments are provided under the [[Main/CourseStandards | Expectations link]].

to:

Attach:collaborative50.png This assignment can be completed in collaboration with others. Additional guidelines on individual, collaborative, and group assignments are provided under the [[Main/CourseStandards | Expectations link]].

----

----

(:html:)

<div id="disqus_thread"></div>

<script type="text/javascript">

/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */

var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname

/* * * DON'T EDIT BELOW THIS LINE * * */

(function() {

var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;

dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';

(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);

})();

</script>

<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

(:htmlend:)

----

----

(:html:)

<div id="disqus_thread"></div>

<script type="text/javascript">

/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */

var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname

/* * * DON'T EDIT BELOW THIS LINE * * */

(function() {

var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;

dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';

(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);

})();

</script>

<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

(:htmlend:)

Changed line 7 from:

[[Attach:spring.pdf | Spring Design Assignment]]

to:

[[Attach:spring.pdf | Full Spring Design Assignment]]

Changed line 11 from:

Turn in a report~~ (less than 3 pages)~~ with the following sections:

to:

Turn in a report with the following sections:

Changed line 33 from:

Attach:collaborative50.png This assignment can be completed ~~as a collaborative assignment~~. Additional guidelines on individual, collaborative, and group assignments are provided under the [[Main/CourseStandards | Expectations link]].

to:

Attach:collaborative50.png This assignment can be completed in collaboration with others. Additional guidelines on individual, collaborative, and group assignments are provided under the [[Main/CourseStandards | Expectations link]].

Changed lines 33-34 from:

This assignment can be completed as a collaborative ~~Attach:collaborative50~~.~~png assignment. ~~Additional guidelines on individual, collaborative, and group assignments are provided under the [[Main/CourseStandards | Expectations link]].

to:

Attach:collaborative50.png This assignment can be completed as a collaborative assignment. Additional guidelines on individual, collaborative, and group assignments are provided under the [[Main/CourseStandards | Expectations link]].

Added lines 31-34:

----

This assignment can be completed as a collaborative Attach:collaborative50.png assignment. Additional guidelines on individual, collaborative, and group assignments are provided under the [[Main/CourseStandards | Expectations link]].

Changed line 11 from:

Turn in a report with the following sections:

to:

Turn in a report (less than 3 pages) with the following sections:

Changed lines 5-6 from:

The specifications and modeling equations for a compression spring create a number of trade-offs that must be considered during design. We wish to determine the spring design that maximizes the force of a spring at its preload height, '~~'h'~~_o_' ~~'', ~~of 1.0 inches. The spring is to operate an indefinite number of times through a deflection ~~o~~, of 0.4 inches, which is an additional deflection from ~~ho~~. The stress at the solid height, ~~hs~~, must be less than ~~Sy~~ to protect the spring from inadvertent damage.

to:

The specifications and modeling equations for a compression spring create a number of trade-offs that must be considered during design. We wish to determine the spring design that maximizes the force of a spring at its preload height, h'_o_', of 1.0 inches. The spring is to operate an indefinite number of times through a deflection delta'_o_', of 0.4 inches, which is an additional deflection from h'_o_'. The stress at the solid height, h'_s_', must be less than S'_y_' to protect the spring from inadvertent damage.

Changed lines 11-30 from:

to:

Turn in a report with the following sections:

# Title Page with Summary. The Summary should be short (less than 50 words), and give the main optimization results.

# Procedure: Give a brief description of your model. You are welcome to refer to the assignment which should be in the Appendix. Also include:

## A table with the analysis variables, design variables, analysis functions and design functions.

# Results: Briefly describe the results of optimization (values). Also include:

## A table showing the optimum values of variables and functions, indicating binding constraints and/or variables at bounds (highlighted)

## A table giving the various starting points which were tried along with the optimal objective values reached from that point.

# Discussion of Results: Briefly discuss the optimum and design space around the optimum. Do you feel this is a global optimum? Also include and briefly discuss:

## A “zoomed out” contour plot showing the design space (both feasible and infeasible) for coil diameter vs. wire diameter, with the feasible region shaded and optimum marked.

## A “zoomed in” contour plot of the design space (mostly feasible space) for coil diameter vs. wire diameter, with the feasible region shaded and optimum marked.

# Appendix:

## Listing of your model with all variables and equations

## Solver output with details of the convergence to the optimal values

Any output from the software is to be integrated into the report (either physically or electronically pasted) as given in the sections above. Tables and figures should all have explanatory captions. Do not just staple pages of output to your assignment: all raw output is to have notations made on it. For graphs, you are to shade the feasible region and mark the optimum point. For tables of design values, you are to indicate, with arrows and comments, any variables at bounds, any binding constraints, the objective, etc. (You need to show that you understand the meaning of the output you have included.)

# Title Page with Summary. The Summary should be short (less than 50 words), and give the main optimization results.

# Procedure: Give a brief description of your model. You are welcome to refer to the assignment which should be in the Appendix. Also include:

## A table with the analysis variables, design variables, analysis functions and design functions.

# Results: Briefly describe the results of optimization (values). Also include:

## A table showing the optimum values of variables and functions, indicating binding constraints and/or variables at bounds (highlighted)

## A table giving the various starting points which were tried along with the optimal objective values reached from that point.

# Discussion of Results: Briefly discuss the optimum and design space around the optimum. Do you feel this is a global optimum? Also include and briefly discuss:

## A “zoomed out” contour plot showing the design space (both feasible and infeasible) for coil diameter vs. wire diameter, with the feasible region shaded and optimum marked.

## A “zoomed in” contour plot of the design space (mostly feasible space) for coil diameter vs. wire diameter, with the feasible region shaded and optimum marked.

# Appendix:

## Listing of your model with all variables and equations

## Solver output with details of the convergence to the optimal values

Any output from the software is to be integrated into the report (either physically or electronically pasted) as given in the sections above. Tables and figures should all have explanatory captions. Do not just staple pages of output to your assignment: all raw output is to have notations made on it. For graphs, you are to shade the feasible region and mark the optimum point. For tables of design values, you are to indicate, with arrows and comments, any variables at bounds, any binding constraints, the objective, etc. (You need to show that you understand the meaning of the output you have included.)

Added lines 1-11:

(:title Spring Design Optimization Problem:)

(:keywords nonlinear, optimization, engineering optimization, two-bar optimization, engineering design, interior point, active set, differential, algebraic, modeling language, university course:)

(:description Engineering design of a spring to stay within constraints and meet an optimal criteria. Optimization principles are used to design the system.:)

The specifications and modeling equations for a compression spring create a number of trade-offs that must be considered during design. We wish to determine the spring design that maximizes the force of a spring at its preload height, ''h'_o_' '', of 1.0 inches. The spring is to operate an indefinite number of times through a deflection o, of 0.4 inches, which is an additional deflection from ho. The stress at the solid height, hs, must be less than Sy to protect the spring from inadvertent damage.

[[Attach:spring.pdf | Spring Design Assignment]]

Attach:spring.png

This introductory assignment is designed as a means of demonstrating the optimization capabilities of a number of software packages. Below are tutorials for solving this problem with a number of software tools.

(:keywords nonlinear, optimization, engineering optimization, two-bar optimization, engineering design, interior point, active set, differential, algebraic, modeling language, university course:)

(:description Engineering design of a spring to stay within constraints and meet an optimal criteria. Optimization principles are used to design the system.:)

The specifications and modeling equations for a compression spring create a number of trade-offs that must be considered during design. We wish to determine the spring design that maximizes the force of a spring at its preload height, ''h'_o_' '', of 1.0 inches. The spring is to operate an indefinite number of times through a deflection o, of 0.4 inches, which is an additional deflection from ho. The stress at the solid height, hs, must be less than Sy to protect the spring from inadvertent damage.

[[Attach:spring.pdf | Spring Design Assignment]]

Attach:spring.png

This introductory assignment is designed as a means of demonstrating the optimization capabilities of a number of software packages. Below are tutorials for solving this problem with a number of software tools.