Initialize engineering session with standard constants, units, and imports
Standardize engineering sessions with a consistent environment that includes:
This helper eliminates the need to repeatedly set up the same environment at the start of each engineering session, ensuring consistency and saving time.
Simply run the initialization script at the start of your session:
exec(open('init-script.py').read())
Or copy-paste the contents of init-script.py directly into your Python session.
# After running init-script.py
from pint import UnitRegistry
ureg = UnitRegistry()
# Define a pressure with units
pressure = 500 * ureg.kPa
print(f"Pressure: {pressure}")
print(f"Pressure in psi: {pressure.to('psi')}")
# Calculate ideal gas properties
T = 300 * ureg.kelvin
V = 2 * ureg.m**3
n = (pressure * V / (R * T)).to('mol')
print(f"Moles of gas: {n:.2f}")
# After running init-script.py
# Calculate density at altitude using standard constants
altitude = 5000 # meters
T = T_std - 0.0065 * altitude # Temperature lapse rate
P = P_atm * (T / T_std) ** (g / (0.0065 * R_air))
rho = P / (R_air * T)
print(f"At {altitude}m altitude:")
print(f"Temperature: {T:.2f} K ({T-273.15:.2f} °C)")
print(f"Pressure: {P:.2f} Pa ({P/1000:.2f} kPa)")
print(f"Density: {rho:.4f} kg/m³")
# After running init-script.py
# Reynolds number calculation
velocity = 50 # m/s
length = 2 # m characteristic length
Re = velocity * length / nu_air_std
print(f"Reynolds number: {Re:.2e}")
if Re > 5e5:
print("Flow is turbulent")