Created
August 16, 2018 13:37
-
-
Save bhalonen/4080b945e4f6cf4edfcab4bba089cc8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"using Unitful: m, Length, N, inch,rad,°,@u_str,lbf, lb,s, ustrip, psi,uconvert\n", | |
"using CSV\n", | |
"using DataFrames\n", | |
"using DSP\n", | |
"using GR" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Bar Info\n", | |
"Very average information on bar actually, nothing new here\n", | |
"Unit packages are freaking nice, obviously. Is your input in inches? cm? miles? run- |>u\"m\", now it is in meters." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"#approximate, but close enough\n", | |
"function yeild_strength_to_shear_yeild(yeild_strength)\n", | |
" yeild_strength*.58\n", | |
"end\n", | |
"bar_diameter=.75u\"inch\"|>u\"m\"\n", | |
"bar_radius=bar_diameter/2\n", | |
"poisson_ratio=.33\n", | |
"youngs_modulus=29*(10^6)u\"psi\"|>u\"Pa\"\n", | |
"bar_density= .284u\"lb/inch^3\"|>u\"kg/m^3\"\n", | |
"transmitted_strain_gauge_distance=36u\"inch\"|>u\"m\"\n", | |
"incident_strain_gauge_distance=24u\"inch\"|>u\"m\"\n", | |
"yeild_strength=50800u\"psi\"|>u\"Pa\"\n", | |
"shear_yeild_strength=yeild_strength_to_shear_yeild(yeild_strength)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Shot information\n", | |
"Two big driving variables, length of bar twisted and how far the bar was twisted" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"length_of_bar_twisted=12u\"inch\"|>u\"m\"\n", | |
"twist_angle=20u\"°\"|>u\"rad\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"function compute_shear_modulus(youngs_modulus,poisson_ratio)\n", | |
" youngs_modulus/2/(1+poisson_ratio)\n", | |
"end\n", | |
"shear_modulus= compute_shear_modulus(youngs_modulus,poisson_ratio)\n", | |
"shear_wave_speed=√((shear_modulus|>u\"(kg*m/s^2)/m^2\")/(bar_density))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Shot Prediction\n", | |
"Note shear strain is in radians. That is not a typo.\n", | |
"The incident pulse would be twice the duration of crossing the twisted area,\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"#Important function\n", | |
"function polar_moment_inertia_bar(bar_radius)\n", | |
" π*bar_radius^4/2\n", | |
"end\n", | |
"#Important function\n", | |
"function surface_strain_to_bar_torque(surface_strain,bar_radius,shear_modulus)\n", | |
" torque_bar=(shear_modulus|>u\"N/m^2\")*polar_moment_inertia_bar(bar_radius)*surface_strain/bar_radius\n", | |
"end\n", | |
"function bar_torque_to_surface_strain(torque_bar,bar_radius,shear_modulus)\n", | |
" torque_bar*bar_radius/((shear_modulus|>u\"N/m^2\")*polar_moment_inertia_bar(bar_radius))\n", | |
"end\n", | |
"#counter part of \"speed limit\" for shear test- how much can you torque the bar befor it dies?\n", | |
"function predicted_max_torque(shear_yeild_strength,bar_radius)\n", | |
" (shear_yeild_strength|>u\"N/m^2\")*polar_moment_inertia_bar(bar_radius)/bar_radius\n", | |
"end\n", | |
"function predicted_strain_of_shot(bar_radius,twist_angle,length_of_bar_twisted)\n", | |
" bar_radius*twist_angle/length_of_bar_twisted\n", | |
"end\n", | |
"shear_strain_surface=bar_radius*twist_angle/length_of_bar_twisted\n", | |
"duration_pulse= 2*length_of_bar_twisted/shear_wave_speed\n", | |
"shear_stress_surface=ustrip(shear_strain_surface)*shear_modulus*bar_radius\n", | |
"J_bar=polar_moment_inertia_bar(bar_radius)\n", | |
"torque_bar=surface_strain_to_bar_torque(shear_strain_surface,bar_radius,shear_modulus)\n", | |
"predicted_max_torque(shear_yeild_strength,bar_radius)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Sample parameters\n", | |
"The sample is a tube or a hollow cylinder of metal" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"sample_inner_diameter=10u\"mm\"|>u\"m\"\n", | |
"sample_outer_diameter=12u\"mm\"|>u\"m\"\n", | |
"sample_length=5u\"mm\" |>u\"m\"\n", | |
"sample_mean_radius=(sample_inner_diameter+sample_outer_diameter)/4\n", | |
"sample_thickness=(sample_outer_diameter-sample_inner_diameter)/2\n", | |
"sample_youngs_modulus=10*(10^6)u\"psi\"|>u\"Pa\"\n", | |
"sample_shear_modulus=compute_shear_modulus(sample_youngs_modulus,.33)\n", | |
"\n", | |
"#this isnt a parameter\n", | |
"sample_flow_shear_stress=200u\"MPa\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"#Important function\n", | |
"function polar_moment_of_tube(inner_radius,outer_radius)\n", | |
" polar_moment_inertia_bar(outer_radius)-polar_moment_inertia_bar(inner_radius)\n", | |
"end\n", | |
"function sample_stress_to_sample_torque(sample_outer_diameter,sample_inner_diameter,shear_stress)\n", | |
" moment_of_inertia=polar_moment_of_tube(sample_inner_diameter/2,sample_outer_diameter/2)\n", | |
" torque_sample=(shear_stress|>u\"N/m^2\")*moment_of_inertia/((sample_outer_diameter+sample_inner_diameter)/4)\n", | |
"end\n", | |
"#Important function\n", | |
"function sample_torque_to_sample_stress(torque_sample,sample_outer_diameter,sample_inner_diameter)\n", | |
" moment_of_inertia=polar_moment_of_tube(sample_inner_diameter/2,sample_outer_diameter/2)\n", | |
" torque_sample/moment_of_inertia*((sample_outer_diameter+sample_inner_diameter)/4)\n", | |
"end\n", | |
"#incident and reflected pulses to sample shear strain rate\n", | |
"function compute_shear_strain_rate(reflected_shear_strain,bar_diameter,sample_average_diameter,\n", | |
" shear_wave_speed,length_of_sample)\n", | |
" 4*(sample_average_diameter/2)*shear_wave_speed/(bar_diameter/2*length_of_sample)*(reflected_shear_strain) \n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Simulated Shot \n", | |
"Twist 12 inches of bar 2 degrees \n", | |
"sample as described above. \n", | |
"Expect flow stress of 200 MPa \n", | |
"total strain of .66, strain rate of 3360 \n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"length_of_bar_twisted=12u\"inch\"|>u\"m\"\n", | |
"twist_angle=2u\"°\"|>u\"rad\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"transmitted_torque=sample_stress_to_sample_torque(sample_outer_diameter,sample_inner_diameter,sample_flow_shear_stress)\n", | |
"transmitted_strain=bar_torque_to_surface_strain(transmitted_torque,bar_radius,shear_modulus)\n", | |
"predicted_strain=predicted_strain_of_shot(bar_radius,twist_angle,length_of_bar_twisted)\n", | |
"reflected_strain=predicted_strain-transmitted_strain\n", | |
"compute_shear_strain_rate(reflected_strain,bar_diameter,sample_mean_radius*2,\n", | |
" shear_wave_speed,sample_length)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"lead_time=collect(0u\"s\":1u\"μs\":0.0001u\"s\")\n", | |
"duration_pulse=length_of_bar_twisted*2/shear_wave_speed\n", | |
"lead_in=map(time->0.0,0u\"s\":1u\"μs\":0.0001u\"s\")\n", | |
"incident_pulse=map(time->ustrip(predicted_strain),0u\"s\":1u\"μs\":duration_pulse)\n", | |
"gap=map(time->0.0,0u\"s\":1u\"μs\":(2*incident_strain_gauge_distance/shear_wave_speed))\n", | |
"reflected_pulse = map(time->-ustrip(reflected_strain),0u\"s\":1u\"μs\":duration_pulse)\n", | |
"end_out=map(time->0.0,0u\"s\":1u\"μs\":0.0001u\"s\")\n", | |
"transmitted_pulse=map(time->ustrip(transmitted_strain),0u\"s\":1u\"μs\":duration_pulse)\n", | |
"gap_transmitted=map(time->0.0,0u\"s\":1u\"μs\":(1u\"μs\"+2*incident_strain_gauge_distance/shear_wave_speed+duration_pulse))\n", | |
"\n", | |
"time=map(time->ustrip(time),0u\"s\":1u\"μs\":(4u\"μs\"+0.0001u\"s\"*2+duration_pulse*2+(2*incident_strain_gauge_distance/shear_wave_speed)))\n", | |
"#quick little filter so it doesn't look dumb\n", | |
"proto=Butterworth(1)\n", | |
"zpk = digitalfilter(Lowpass(0.2), proto)\n", | |
"tf = convert(PolynomialRatio, zpk)\n", | |
"\n", | |
"incident_bar_strain_history=filt(tf,cat(dims=1,lead_in,incident_pulse,gap,reflected_pulse,end_out))\n", | |
"transmitted_bar_strain_history=filt(tf,cat(dims=1,lead_in,gap_transmitted,transmitted_pulse,end_out));" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"GR.setviewport(0.1, 0.95, 0.1, 0.95)\n", | |
"GR.setwindow(-2, 2, -2, 2)\n", | |
"GR.setspace(-0.5, 0.5, 0, 90)\n", | |
"GR.setmarkersize(1)\n", | |
"GR.setmarkertype(-1)\n", | |
"GR.setcharheight(0.024)\n", | |
"GR.settextalign(2, 0)\n", | |
"GR.settextfontprec(3, 0)\n", | |
"\n", | |
"\n", | |
"plot(time,incident_bar_strain_history)\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"GR.setviewport(0.1, 0.95, 0.1, 0.95)\n", | |
"GR.setwindow(-2, 2, -2, 2)\n", | |
"GR.setspace(-0.5, 0.5, 0, 90)\n", | |
"GR.setmarkersize(1)\n", | |
"GR.setmarkertype(-1)\n", | |
"GR.setcharheight(0.024)\n", | |
"GR.settextalign(2, 0)\n", | |
"GR.settextfontprec(3, 0)\n", | |
"\n", | |
"plot(time,transmitted_bar_strain_history)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"data_frame=DataFrame(time_seconds=time,incident_strain_gauge=incident_bar_strain_history,transmitted_strain_gauge=transmitted_bar_strain_history)\n", | |
"CSV.write(\"example_data.csv\",data_frame)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Julia 1.0.0", | |
"language": "julia", | |
"name": "julia-1.0" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"mimetype": "application/julia", | |
"name": "julia", | |
"version": "1.0.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment