Difference between revisions of "Numerical Code for calculating Pressurized Hydrogen Storage"
(Created page with "<syntaxhighlight lang="xml"> from math import pi import pprint ''' r = radius circle_area = pi * r**2 circle_circumference = 2 * pi * r h = height cylinder_volume = pi *...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | [[File:Result1_JW.png|400px|thumb|Result of first section of code]] | ||
+ | |||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
Line 35: | Line 37: | ||
pprint.pprint(mylist) | pprint.pprint(mylist) | ||
+ | |||
+ | |||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | [[File:Result2_JW.png|400px|thumb|Geometry optimization result for radius and height for minimum surface area]] | ||
+ | |||
+ | <syntaxhighlight lang="xml"> | ||
+ | |||
+ | r = 5 | ||
+ | surface_list = [] | ||
+ | while True: | ||
+ | cylinder_surface = 2 * (pi * r**2) + (2 * pi * r * 1000/(pi * r**2)) | ||
+ | surface_list.append((cylinder_surface, r)) | ||
+ | r += 0.01 | ||
+ | if r > 6: | ||
+ | break | ||
+ | |||
+ | print('minimum surface area and radius: ', min(surface_list)) | ||
+ | |||
+ | min_surface = min(surface_list)[0] | ||
+ | sf = "Minimum surface of a 1000ml tank = {:0.2f} square centimeters" | ||
+ | print(sf.format(min_surface)) | ||
+ | radius = min(surface_list)[1] | ||
+ | print("Radius of 1000ml tank = {:0.2f} centimeters".format(radius)) | ||
+ | height = 1000/(pi * radius**2) | ||
+ | print("Height of 1000ml tank = {:0.2f} centimeters".format(height)) | ||
+ | sf = "Ratio of height to radius of a minimized surface can = {:0.2f}" | ||
+ | print(sf.format(height/radius)) | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 22:08, 4 June 2023
from math import pi
import pprint
'''
r = radius
circle_area = pi * r**2
circle_circumference = 2 * pi * r
h = height
cylinder_volume = pi * r**2 * h
cylinder_surface = 2 * (pi * r**2) + (2 * pi * r * h)
constraint for cylinder_volume be a constant of 1 liter (cubic centimeter)
cylinder_volume = 1000
h in terms of r
h = 1000/(pi * r**2)
substitute in
cylinder_surface = 2 * (pi * r**2) + (2 * pi * r * 1000/(pi * r**2))
'''
mylist = [] # create a list of (surface area, radius)
for r in range(1, 21): # assume a maximum of 20cm radius
cylinder_surface = 2 * (pi * r**2) + (2 * pi * r * 1000/(pi * r**2))
mylist.append((cylinder_surface, r))
# test
pprint.pprint(mylist)
r = 5
surface_list = []
while True:
cylinder_surface = 2 * (pi * r**2) + (2 * pi * r * 1000/(pi * r**2))
surface_list.append((cylinder_surface, r))
r += 0.01
if r > 6:
break
print('minimum surface area and radius: ', min(surface_list))
min_surface = min(surface_list)[0]
sf = "Minimum surface of a 1000ml tank = {:0.2f} square centimeters"
print(sf.format(min_surface))
radius = min(surface_list)[1]
print("Radius of 1000ml tank = {:0.2f} centimeters".format(radius))
height = 1000/(pi * radius**2)
print("Height of 1000ml tank = {:0.2f} centimeters".format(height))
sf = "Ratio of height to radius of a minimized surface can = {:0.2f}"
print(sf.format(height/radius))