151 lines
7.6 KiB
Markdown
151 lines
7.6 KiB
Markdown
# test_mql
|
|
|
|
本目录记录从 AMESim 模型 `test_mql.ame` 迁移到 `PythonModels` 的当前状态。
|
|
|
|
## 模型命名
|
|
|
|
- 仓库内模型名:`test_mql`
|
|
- Python 系统类:`TestMqlSystem`
|
|
- Python 配置解析类:`TestMqlConfig`
|
|
- Python 运行入口:`PythonModels/scripts/run_test_mql.py`
|
|
|
|
## 源文件
|
|
|
|
- AMESim 源模型:`AmesimModels/test_mql.ame`
|
|
- 该 `.ame` 文件本质是一个 tar 包,内部包含 `test_mql_.cir`、`test_mql_.param`、`test_mql_.modelinfo`、`test_mql_.sim`、`test_mql_.data`、`test_mql_.results`、`test_mql_.var` 等文件。
|
|
- `test_mql_.results` 是 AMESim 主时序结果文件;`test_mql_.data` 是配套结果/数据文件。
|
|
|
|
## 当前新增文件
|
|
|
|
- `PythonModels/systems/test_mql.py`
|
|
- 记录 AMESim 组件清单、全局参数、子模型分布、连接拓扑和 AMESim modelinfo 状态数。
|
|
- 当前是结构化 Python 迁移骨架,不是完整 AMESim 物理方程复刻。
|
|
|
|
- `PythonModels/systems/test_mql_config.py`
|
|
- 提供 `TestMqlConfig.from_amesim_specs()`。
|
|
- 负责把 AMESim 全局参数和组件参数解析成后续可用的 Python 配置对象。
|
|
- `test_mql` 默认工质已按 AMESim 模型确认设为氦气。
|
|
- 已支持常量、全局参数引用、四则运算、括号和 AMESim 风格的 `^` 指数表达式。
|
|
- 非数值文本会保留为 `None`,后续按具体子模型显式处理。
|
|
|
|
- `PythonModels/scripts/run_test_mql.py`
|
|
- 提供独立运行入口。
|
|
- 当前输出结构摘要和基础序列,后续逐步接入真实物理方程。
|
|
|
|
- `tests/test_test_mql_structural.py`
|
|
- 保护组件数、连接数、状态数、全局参数和关键子模型计数。
|
|
|
|
- `tests/test_test_mql_config.py`
|
|
- 保护全局参数解析、AMESim 表达式解析、按子模型分组、默认氦气工质和典型组件参数解析。
|
|
|
|
- `PythonModels/core/peng_robinson.py`
|
|
- 提供 Peng-Robinson 状态方程小物性库。
|
|
- 当前覆盖压缩因子、摩尔体积、密度和由密度反算压力。
|
|
- 已内置 `HELIUM_PR`,供 `test_mql` 默认使用。
|
|
|
|
- `PythonModels/components/amesim_pneumatic.py`
|
|
- 提供 `test_mql` 后续会用到的 AMESim 气动组件原语。
|
|
- 当前包含氦气 PR 压力闭合的气动容腔、标准可压缩孔口流量、单位换算 helper。
|
|
- 这层仍是首版近似原语,后续必须通过 AMESim 结果对齐修正。
|
|
|
|
- `PythonModels/reporting/amesim_results.py`
|
|
- 直接解析 `.ame` 包内的 AMESim 二进制结果。
|
|
- 当前已确认 `test_mql_.results` 结构为:2 个 int32 头字段、1116 个保存变量映射、1002 行 `time + 1116变量` 的 double 时序矩阵,以及尾部 `time + 1278变量终值`。
|
|
|
|
- `tests/test_amesim_results.py`
|
|
- 保护 `test_mql_.results` 的时间轴、变量数量、Data_Path 映射和典型样本值。
|
|
|
|
- `PythonModels/reporting/test_mql_comparison.py`
|
|
- 提供 `test_mql` 专用的 AMESim/Python 时序对齐工具。
|
|
- 按 AMESim `Data_Path` 做时间插值、最大绝对误差、平均绝对误差、最大相对误差和终值误差统计。
|
|
- 可导出 `test_mql_amesim_baseline.csv` 和 `test_mql_amesim_comparison.csv`,供后续组件方程校验使用。
|
|
|
|
- `tests/test_test_mql_comparison.py`
|
|
- 保护 AMESim 原始序列零误差对齐、粗时间步插值、偏移误差统计、缺失变量报错和 CSV 输出。
|
|
|
|
- `PythonModels/systems/test_mql_pneumatic.py`
|
|
- 把 AMESim 配置中的 `PNCH023`、`PNCH012`、`PNOR001`、`PNVO001` 装配成 Python 气动对象。
|
|
- 当前覆盖 4 个固定气室、8 个变容气室、8 个固定孔口、8 个可变孔口,alias 沿用 AMESim 原名。
|
|
- 初始压力按 AMESim 全局参数 `P0=153 bar` 和大气压 `1.013 bar` 转成 `15198700 Pa`。
|
|
|
|
- `tests/test_test_mql_pneumatic.py`
|
|
- 保护气动装配数量、alias、氦气工质、气室体积、孔口面积/流量系数和基础质量流量计算。
|
|
|
|
- `PythonModels/reporting/test_mql_variables.py`
|
|
- 建立 AMESim `Data_Path` 到信号名、组件/连接 alias、owner 类型和子模型的变量目录。
|
|
- 当前 1100 个有 `Data_Path` 的变量全部可归属,其中组件变量 712 个、连接/管路变量 388 个。
|
|
|
|
- `tests/test_test_mql_variables.py`
|
|
- 保护变量目录覆盖率、组件变量映射、连接变量映射、子模型计数和非法 `Data_Path` 报错。
|
|
|
|
- `PythonModels/systems/test_mql_lines.py`
|
|
- 把 AMESim `CONNECTION_SPECS` 中的管路连接装配成 Python 管路目录。
|
|
- 当前覆盖 `PNL0001` 20 条、`PNL0002` 8 条、`PNL0003` 8 条、`PNL00R` 4 条,共 40 条。
|
|
- 保留 `pneumatic_*` alias、源/目标组件端口、`C-R`/`R-C-R`/`C-R-C`/`R` 模式和对应 `Data_Path`。
|
|
|
|
- `tests/test_test_mql_lines.py`
|
|
- 保护管路数量、拓扑端口、管路模式、典型 `Data_Path` 和子模型分组。
|
|
|
|
## 物性约定
|
|
|
|
AMESim 模型中 `test_mql` 使用氦气,Python 侧当前通过 `HELIUM_PR` 使用 Peng-Robinson 状态方程计算气体压缩因子和密度。当前物性层先覆盖状态方程相关量,完整焓/内能偏差函数后续在接气室能量方程时再补。
|
|
|
|
## 当前提取结果
|
|
|
|
- 组件数:117
|
|
- 连接数:84
|
|
- AMESim 连续状态数:132
|
|
- AMESim 离散状态数:24
|
|
- 全局参数:`D1=20`、`D2=20`、`D3=14`、`P0=153`、`Pdq=1`、`V=15`、`cf=0.45`
|
|
|
|
主要 AMESim 子模型分布:
|
|
|
|
- `F000`: 16
|
|
- `PNPL01`: 16
|
|
- `MECMAS21`: 10
|
|
- `PNRP17`: 8
|
|
- `LSTP00A`: 8
|
|
- `PNCH012`: 8
|
|
- `PNOR001`: 8
|
|
- `PN3NODE2`: 8
|
|
- `P4NODE2`: 8
|
|
- `PNVO001`: 8
|
|
- `STEP0`: 8
|
|
- `PNCH023`: 4
|
|
- `LMECHN1`: 2
|
|
- `FORC`: 2
|
|
- `UD00`: 2
|
|
- `PNGD00`: 1
|
|
|
|
|
|
## 结果对齐原则
|
|
|
|
后续 Python 仿真结果必须以 AMESim 为基准做一一对应校验:
|
|
|
|
1. 组件别名优先沿用 AMESim 原名,例如 `pn_brp2_8`、`pn_c1_8`、`pn_orifice_18`。
|
|
2. 子模型族优先沿用 AMESim 子模型名,例如 `PNRP17`、`PNCH012`、`PNOR001`、`PNVO001`。
|
|
3. 输出变量命名要能追溯到 AMESim 的 `Data_Path`,避免 Python 侧改名后无法对比。
|
|
4. Python 每完成一批物理方程,都应优先使用 `test_mql_.results` 解析出的 AMESim 原始时序做误差对比。
|
|
5. CSV 仍可作为人工检查或外部交换格式,但不是自动对齐的前置条件。
|
|
6. 在没有完成逐变量误差对比前,不能把 Python 输出描述为“已经和 AMESim 几乎一致”,只能说明完成了结构、参数、结果读取或某类组件方程。
|
|
|
|
## 验证方式
|
|
|
|
```bash
|
|
python3 -m py_compile PythonModels/components/amesim_pneumatic.py PythonModels/core/peng_robinson.py PythonModels/reporting/amesim_results.py PythonModels/reporting/test_mql_comparison.py PythonModels/reporting/test_mql_variables.py PythonModels/systems/test_mql.py PythonModels/systems/test_mql_config.py PythonModels/systems/test_mql_lines.py PythonModels/systems/test_mql_pneumatic.py PythonModels/scripts/run_test_mql.py
|
|
python3 -m PythonModels.scripts.run_test_mql
|
|
python3 -m unittest discover -s tests -t .
|
|
```
|
|
|
|
当前测试覆盖的是结构、配置解析、气动原语、气动件装配、管路连接装配、AMESim 结果读取、变量目录和 AMESim/Python 时序对齐工具,不代表已经完成 AMESim 物理结果复刻。
|
|
|
|
## 后续方向
|
|
|
|
后续继续补模型时,保持只新增或修改 `test_mql` 相关代码,不改旧的 `testmodel`。建议按下面顺序逐步实现真实物理方程:
|
|
|
|
1. `PNGD00`:气体属性。
|
|
2. `PNCH023 / PNCH012`:固定气室和变容气室。
|
|
3. `PNOR001 / PNVO001`:固定孔口和可变孔口。每完成一项后用 `test_mql_comparison.py` 按 `Data_Path` 对齐 AMESim 结果。
|
|
4. `PNL0001 / PNL0002 / PNL0003 / PNL00R`:管路阻容连接。
|
|
5. `PNRP17 / MECMAS21 / LSTP00A / LMECHN1`:气动活塞、机械负载和端止动。
|