计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
engineering-context-init【效率与协作】Initialize engineering session with standard constants, units, and imports
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: engineering-context-init description: "Initialize engineering session with standard constants, units, and imports" category: helpers domain: general complexity: basic dependencies:
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")
else:
print("Flow is laminar")
# After running init-script.py
import numpy as np
import matplotlib.pyplot as plt
# The plotting style is already configured
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
plt.figure()
plt.plot(x, y, linewidth=2)
plt.xlabel('x [rad]')
plt.ylabel('sin(x)')
plt.title('Example Plot with Pre-configured Style')
plt.show()
# After running init-script.py
# Power calculation with unit conversions
force = 1000 * ureg.N
velocity = 30 * ureg.m / ureg.s
power = (force * velocity).to('kW')
print(f"Power: {power}")
print(f"Power in hp: {power.to('hp'):.2f}")
print(f"Power in BTU/hr: {power.to('BTU/hr'):.2f}")
ureg for unit-aware calculationsYou can modify init-script.py to: