Files
engineering/tube.py
2019-02-08 10:22:48 +01:00

88 lines
2.6 KiB
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""\
Tube
"""
from __future__ import absolute_import, division, print_function, unicode_literals
from math import sqrt
__author__ = "Daniel Weschke"
__copyright__ = "Copyright 2019 Daniel Weschke"
__credits__ = ["Daniel Weschke"]
__license__ = "MIT"
__version__ = "2019.02.07"
__maintainer__ = "Daniel Weschke"
__email__ = "daniel.weschke@directbox.de"
__status__ = "Production" # "Prototype", "Development", "Production"
VERSION = """\
%(prog)s version {version} {copyright}
For Unicode characters check the file encoding that the console is using.
Windows user may execute the command "chcp 65001".""".format(
version=__version__, copyright=__copyright__)
EPILOG = """\
"""
def critical_buckling_stress(r, nu, E, t):
"""\
Critical buckling stress of a thin tube loaded with external pressure p.
r mean radius (r_a + r_i)/2
nu Poisson's ratio
E Young's modulus
t thickness
"""
return (E/(4*(1-nu**2))*(t/r)**3)
def allowable_stress(sigma, S):
"""\
Allowable stress.
sigma stress
S safety factor, elastic buckling stress state S = 3
"""
return sigma/S
def main():
"""\
Main function
"""
import argparse
parser = argparse.ArgumentParser(
description=__doc__, prefix_chars='-', epilog=EPILOG,
#usage="%(prog)s [OPTION]... NAME",
formatter_class=argparse.RawTextHelpFormatter,
)
parser.add_argument('-v', '--verbose', action="store_true", help="Verbose output")
parser.add_argument('-V', '--version', action='version', version=VERSION)
parser.add_argument('-D', '--debug', dest='debug', action='store_true', help=argparse.SUPPRESS)
subparsers = parser.add_subparsers(help='', dest='case')
parser_a = subparsers.add_parser(
'buckling', help="critical buckling stress", prefix_chars='-',
description="Critical buckling stress of a thin tube loaded with external pressure p.")
parser_a.add_argument('NU', type=float, help='Poisson\'s ratio')
parser_a.add_argument('R', type=float, help='mean radius')
parser_a.add_argument('E', type=float, help='Young\'s modulus')
parser_a.add_argument('T', type=float, help='thickness')
parser_a.add_argument('S', nargs='?', type=float, default=3., help='safety factor [default for elastic stress state: 3]')
args = parser.parse_args()
if args.debug:
print(args)
if args.case == 'buckling':
p_crit = critical_buckling_stress(args.R, args.NU, args.E, args.T)
print("p_crit =", p_crit)
print("p_allow =", allowable_stress(p_crit, args.S))
return 0
if __name__ == "__main__":
import sys
sys.exit(main())