SpectraRust/.claude/skills/tlusty-iteration/SKILL.md
2026-04-04 23:01:19 +08:00

175 lines
7.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
name: tlusty-iteration
description: "TLUSTY Rust主程序迭代开发。触发用户提到'迭代测试'、对比测试'+用户想验证Rust实现与Fortran的一致性(3) 继续TLUSTY主程序开发(4) 运行TLUSTY测试用例。从主程序开始逐模块对比Fortran源码持久化检查进度断点续查。严格逐行对比发现差异立即修复循环验证。不依赖f2r-check."
---
# TLUSTY Rust 主程序迭代
## 文件路径
| 内容 | 路径 |
|------|------|
| Fortran 源码 | `/home/fmq/program/tlusty/tl208-s54/rust/tlusty/extracted/*.f` |
| Rust 源码 | `src/tlusty/` |
| 检查进度 | `.claude/skills/tlusty-iteration/progress.md` |
| Fortran 测试 | `tests/tlusty/hhe_fortran/` |
| Rust 测试 | `tests/tlusty/hhe_rust/` |
## 测试方式
```bash
cargo build --bin tlusty
cd tests/tlusty/hhe_rust
rm -f fort.7
../../../target/debug/tlusty < hhe35lt.5 > rust.6 2>stderr.txt
```
## 检查工作流(严格遵守)
```
每次调用本 skill 时:
1. 读取 progress.md → 恢复检查进度
2. 运行 Rust → 与 Fortran 对比输出
3. 如果输出一致 → 更新 progress.md → 结束
4. 如果输出不一致 → 从断点继续检查:
a. 读取 progress.md 中 "下一个待检查模块"
b. ★ 必须先读取对应的 Fortran 文件,逐行理解原始逻辑
c. 然后读取对应的 Rust 文件
d. 逐行对比: 调用顺序、变量映射、索引转换、逻辑分支
e. 发现差异 → 立即修复 → cargo build 验证
f. 更新 progress.md → 继续下一个模块
5. 全部通过 → 运行测试验证 → 更新 progress.md
```
## ★ 核心原则:必须参考 Fortran 代码
```
严禁凭猜测修改代码!每次修改前必须:
1. 先读取对应的 Fortran 源码文件
2. 理解 Fortran 的确切逻辑流程
3. 找到 Fortran 中的对应行
4. 然后对照修改 Rust 代码
违反此原则是产生 bug 的最主要原因。
```
## Fortran 调用链(检查顺序)
从主程序开始,沿着调用链深度优先检查:
```
TLUSTY (tlusty.f)
→ START (start.f)
→ INITIA (initia.f) ★ 最大模块927行
→ HEDIF (hedif.f) [可选]
→ COMSET (comset.f)
→ PRDINI (prdini.f)
→ RESOLV (resolv.f)
→ INILAM, LINSEL, OPAINI ...
→ OPACF0, OPACF1, RTEFR1 ...
→ LUCY (lucy.f)
→ OUTPUT
→ ACCEL2 (accel2.f)
→ SOLVE / SOLVES / RYBSOL
→ MATGEN → BRTE, BHE, BRE
→ MATINV
```
## 模块文件映射(精确路径)
每个 Fortran 模块对应的 Rust 文件:
| Fortran 模块 | Fortran 文件 | Rust 文件 | 子目录 |
|-------------|-------------|-----------|--------|
| TLUSTY | tlusty.f | `src/tlusty/main.rs` | (主程序入口) |
| START | start.f | `src/tlusty/io/start.rs` | io/ |
| INITIA | initia.f | `src/tlusty/io/initia.rs` | io/ |
| HEDIF | hedif.f | `src/tlusty/math/hydrogen/hedif.rs` | math/hydrogen/ |
| COMSET | comset.f | `src/tlusty/math/utils/comset.rs` | math/utils/ |
| PRDINI | prdini.f | `src/tlusty/math/opacity/prdini.rs` | math/opacity/ |
| RESOLV | resolv.f | `src/tlusty/io/resolv.rs` | io/ |
| INILAM | inilam.f | `src/tlusty/math/opacity/inilam.rs` | math/opacity/ |
| LINSEL | linsel.f | `src/tlusty/math/opacity/linsel.rs` | math/opacity/ |
| OPAINI | opaini.f | `src/tlusty/math/continuum/opaini.rs` | math/continuum/ |
| OPACF0 | opacf0.f | `src/tlusty/math/continuum/opacf0.rs` | math/continuum/ |
| OPACF1 | opacf1.f | `src/tlusty/math/continuum/opacf1.rs` | math/continuum/ |
| RTEFR1 | rtefr1.f | `src/tlusty/math/radiative/rtefr1.rs` | math/radiative/ |
| LUCY | lucy.f | `src/tlusty/math/temperature/lucy.rs` | math/temperature/ |
| OUTPUT | output.f | `src/tlusty/math/io/output.rs` | math/io/ |
| ELDENS | eldens.f | `src/tlusty/math/eos/eldens.rs` | math/eos/ |
| ACCEL2 | accel2.f | `src/tlusty/math/solvers/accel2.rs` | math/solvers/ |
| SOLVE | solve.f | `src/tlusty/math/solvers/solve.rs` | math/solvers/ |
| SOLVES | solves.f | `src/tlusty/math/solvers/solves.rs` | math/solvers/ |
| RYBSOL | rybsol.f | `src/tlusty/math/solvers/rybsol.rs` | math/solvers/ |
| MATGEN | matgen.f | `src/tlusty/math/solvers/matgen.rs` | math/solvers/ |
| MATINV | matinv.f | `src/tlusty/math/solvers/matinv.rs` | math/solvers/ |
| BRTE | brte.f | `src/tlusty/math/hydrogen/brte.rs` | math/hydrogen/ |
| BHE | bhe.f | `src/tlusty/math/hydrogen/bhe.rs` | math/hydrogen/ |
| BRE | bre.f | `src/tlusty/math/hydrogen/bre.rs` | math/hydrogen/ |
| CORRWM | corrwm.f | `src/tlusty/math/opacity/corrwm.rs` | math/opacity/ |
| QUASIM | quasim.f | `src/tlusty/math/opacity/quasim.rs` | math/opacity/ |
### 文件搜索规则
查找 Fortran 模块对应的 Rust 文件时,按以下顺序搜索:
1. `src/tlusty/math/{name}.rs`
2. `src/tlusty/math/{subdir}/{name}.rs` subdir 见下)
3. `src/tlusty/io/{name}.rs`
4. 特殊映射(多个 Fortran 函数合并到一个 Rust 文件)
math 子目录: ali, atomic, continuum, convection, eos, hydrogen, interpolation, io, odf, opacity, partition, population, radiative, rates, solvers, special, temperature, utils
特殊映射(多合一 Rust 文件):
- `bhe.rs` ← BHE, BHED, BHEZ
- `gfree.rs` ← GFREE0, GFREED, GFREE1
- `interpolate.rs` ← YINT, LAGRAN
- `sgmer.rs` ← SGMER0, SGMER1, SGMERD
- `ctdata.rs` ← HCTION, HCTRECOM
- `cross.rs` ← CROSS, CROSSD
- `expint.rs` ← EINT, EXPINX
- `erfcx.rs` ← ERFCX, ERFCIN
- `lineqs.rs` ← LINEQS, LINEQS_NR
- `convec.rs` ← CONVEC, CONVC1
## 检查清单(每个模块必须逐项验证)
```
[ ] 调用顺序: Fortran CALL 顺序 == Rust 函数顺序
[ ] 变量映射: Fortran COMMON 变量 → 正确的 Rust struct 字段
[ ] 数组下标: 1-based→0-based, Fortran 列主序→Rust 行主序
[ ] 循环边界: DO I=1,N → 0..n, DO I=N,1,-1 → (0..n).rev()
[ ] IF 条件: .AND.→&&, .OR.→||, .EQ.→==, .NE.→!=, 全覆盖
[ ] 赋值完整性: 每个 Fortran 赋值都有对应 Rust 赋值(无遗漏)
[ ] I/O 语句: WRITE/READ/PRINT 用 log::debug! 或条件打印实现
[ ] 函数调用: 每个子程序调用参数正确传递
[ ] 回调模式: 回调/closure 必须调用实际函数(不能是空壳 NoOp
[ ] 数学公式: 常数和计算公式与特殊函数完全一致
[ ] 编译验证: cargo build 无错误
```
## 判断标准
模块检查结果只有三种状态:
```
通过 — 逐行对比一致,调用完整,无空壳,逻辑相同。通过时立即检查下一个模块
未通过 — 发现具体差异,修复后 cargo build 通过,但输出仍不一致
跳过 — 不需要检查(如纯工具函数)
```
## 修复原则
```
1. 严格对照 Fortran: 按 Fortran 代码行号逐行对比 Rust 实现
2. 保持调用顺序: Fortran 中的 CALL 顺序必须严格保持
3. 正确映射 COMMON: 使用 Fortran INCLUDE 文件确认变量含义
4. 控制流程等价: IF/DO/SELECT CASE 逻辑必须一致
5. 数组下标转换: Fortran 列主序 1-based → Rust 行主序 0-based
6. 不能用 NoOp 回调: 如果 Fortran 有 CALLRust 必须调用实际函数
7. 复杂模块分解: 分步骤修复,每步验证编译
```
## 日志记录
每次修改 SKILL.md 的模块进度表或同步更新 progress.md。
progress.md 只记录通过/未通过状态SKILL.md 只记录检查发现和备注。