From 3115ca2530f3f3d27e359adc5158daf865a6f8b1 Mon Sep 17 00:00:00 2001 From: "Ryan C. Cooper" Date: Fri, 15 Nov 2019 10:23:38 -0500 Subject: [PATCH] initial repo commit --- README.md | 31 +++++++++++++++++++++++++++++++ solve_cylinder_rt.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 README.md create mode 100755 solve_cylinder_rt.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c7ea4b --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# Convert parallipiped dimesions to equivalent axisymmetric cylinder dimensions + +## For a given w x t x L block + +## Return the equivalent r x h cylinder + +## maintaining surface area and volume + +Running the code (2 options): + +1. open a terminal and type: + + $ `python solve_cylinder_rt 1 2 3` + + returns + + `A 1.00 x 2.00 x 3.00 parallelipiped + has the same surface area and volume as a cylinder + that is r=0.6104 and t=5.1257` + +2. In a jupyter notebook, + + a. `import solve_cylinder_rt as sc` + + b. `sc.solve_cylinder(1,2,3)` + + `output: A 1.00 x 2.00 x 3.00 parallelipiped + has the same surface area and volume as a cylinder + that is r=0.6104 and t=5.1257` + + diff --git a/solve_cylinder_rt.py b/solve_cylinder_rt.py new file mode 100755 index 0000000..ee315cd --- /dev/null +++ b/solve_cylinder_rt.py @@ -0,0 +1,41 @@ +#!/opt/miniconda3/bin/python +import numpy as np +from scipy.optimize import fsolve +import sys + +def parapiped(w,h,L): + A=2*(w*h+w*L+h*L) + V=w*h*L + return np.array([A,V]) +def cylinder(r,t): + A=2*np.pi*r*(r+t) + V=np.pi*r**2*t + return np.array([A,V]) + +def matchAV(dim_cyl,dims): + r,t=dim_cyl + w,h,L=dims + AVp=parapiped(w,h,L) + AVc=cylinder(r,t) + return AVp-AVc + +def return_hr(w,h,L): + r,t=fsolve(matchAV,[1,2],args=[w,h,L]) + print('A %1.2f x %1.2f x %1.2f parallelipiped'%(w,h,L) ) + print('has the same surface area and volume as a cylinder') + print('that is r=%1.4f and t=%1.4f'%(r,t)) + + +if __name__=='__main__': + if len(sys.argv)<=3: + print('error, please enter w-by-t-by-L dimensions of parallelipiped as w t L') + else: + print(sys.argv) + w=float(sys.argv[1]) + h=float(sys.argv[2]) + L=float(sys.argv[3]) + r,t=fsolve(matchAV,[1,2],args=[w,h,L]) + print('A %1.2f x %1.2f x %1.2f parallelipiped'%(w,h,L) ) + print('has the same surface area and volume as a cylinder') + print('that is r=%1.4f and t=%1.4f'%(r,t)) +