mcpField
E
engineering-context-init

engineering-context-init

github.com/soljourner数据与数据库9539 次安装51 周前更新
代码仓库

关于 engineering-context-init

engineering-context-init 是用于初始化工程计算环境的 Python 技能,适合需要重复进行科学计算的工程工作者。它集中设置常用物理常数、Pint 单位注册表、可用的科学计算库、绘图样式和数值精度。

主要功能

  1. 01加载常用物理常数
  2. 02配置 Pint 单位注册表
  3. 03导入可用科学计算库
  4. 04设置默认绘图样式
  5. 05统一 NumPy 输出精度

适用场景

  1. 01开始工程计算时加载标准参数
  2. 02执行带单位换算的计算
  3. 03为科学数据快速绘图
  4. 04统一不同会话的数值输出格式

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/soljourner/claude-engineering-skills --skill engineering-context-init

安装后在 Claude Code 中输入/engineering-context-init确认已加载。

附带文件constants.mdinit-script.py

详细介绍

工程上下文初始化助手

用途

使用一致的环境规范化工程会话,其中包括:

  • 标准物理常数
  • 用于量纲分析的单位注册表
  • 常用科学计算库
  • 默认绘图配置
  • 数值计算的精度设置

此助手无需在每次工程会话开始时反复设置相同的环境,从而确保一致性并节省时间。

设置内容

标准常数
  • g:标准重力加速度(9.80665 m/s²)
  • R:通用气体常数(8.314462618 J/(mol·K))
  • R_air:空气的比气体常数(287.05 J/(kg·K))
  • gamma_air:空气的比热比(1.4)
  • P_atm:标准大气压(101325 Pa)
  • T_std:标准温度(288.15 K / 15°C)
  • rho_air_std:标准空气密度(1.225 kg/m³)
  • mu_air_std:标准条件下空气的动力黏度(1.789e-5 Pa·s)
  • nu_air_std:标准条件下空气的运动黏度(1.460e-5 m²/s)
  • c_light:光速(299792458 m/s)
  • sigma_sb:斯特藩-玻尔兹曼常数(5.670374419e-8 W/(m²·K⁴))
单位注册表(Pint)
  • 配置用于量纲分析的 pint UnitRegistry
  • 支持单位换算
  • 带单位的计算
常用导入项
  • NumPy:数组运算和数学函数
  • SciPy:科学计算(优化、积分、插值、特殊函数)
  • Matplotlib:绘图和可视化
  • Pandas:数据处理(可选,若可用)
默认绘图样式
  • 图像尺寸:10x6 英寸
  • 启用网格
  • LaTeX 风格的字体渲染(若可用)
  • 专业配色方案
精度设置
  • NumPy 打印精度:小数点后 6 位
  • 对较小值启用打印抑制
  • 跨会话保持格式一致

用法

快速开始

只需在会话开始时运行初始化脚本:

exec(open('init-script.py').read())

或者将 init-script.py 的内容直接复制粘贴到 Python 会话中。

示例 1:带单位的基本计算
# 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}")
示例 2:大气计算
# 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³")
示例 3:流动计算
# 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")
示例 4:快速绘图
# 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()
示例 5:单位换算
# 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}")

包含的文件

  • SKILL.md:本文档
  • init-script.py:可直接运行的完整初始化脚本
  • constants.md:所有常数及其数值的参考列表

说明

  • 脚本会检查库是否可用,并且只导入可用的库
  • 如果 matplotlib 不可用,则跳过绘图配置
  • 如果 pandas 不可用,则不导入(可选)
  • 除非另有说明,所有常数均使用 SI 单位
  • pint UnitRegistry 会创建为 ureg,用于带单位的计算

自定义

你可以修改 init-script.py 来:

  • 添加特定领域的常数
  • 更改默认绘图样式
  • 调整精度设置
  • 导入其他库
  • 在 pint 中定义自定义单位

最佳实践

  1. 在每个新的工程会话开始时运行初始化
  2. 使用最常用的常数更新脚本
  3. 记录你添加的任何自定义常数
  4. 所有涉及物理量的计算都使用单位注册表
  5. 将脚本保存在项目目录中,以便轻松访问

评论

支持 Markdown