Root cause: inner-cavity cap loop edges are degree-3 collocated curves (33 cps, 30 knot spans); measure.cpp's planar Green area uses a single 12-pt Gauss over the whole parameter domain for degree != 2 edges, biasing inner cap area by +2.66e-4. Amplified by (H-t) it produced the thin-wall t=1.0 volume residual 1.209e-6 (target 1e-6). Fix: raise kSpline mapped boundary curve collocation degree 3 -> 4 (kSplineEdgeFitDegree). Fit error 6.06e-7 -> 4.05e-8 and single-span Gauss area bias 2.66e-4 -> 8.4e-6 simultaneously. Measured (Release, W46/W52 suite): - ellipse thin closed t=1.0: 1.209e-06 -> 1.595e-08 (gate 1e-6) - ellipse closed t=1.5: 9.641e-07 -> 1.594e-08 - ellipse open top t=1.5: 1.187e-07 -> 1.233e-09 - ellipse thin open t=1.0: -> 1.254e-08 - thickness sweep 0.5/1.0/1.5/2.0: -> 3.9e-08 worst - torus 2.583e-10 / circle prism 3.305e-11 unchanged (exact same-space) Tests: updated W46EllipseThinClosedFitTolerance (threshold 2e-6 -> 1e-6, report-field reproducibility) + 4 new W52 tests (open top, thickness sweep, inner cap area consistency, quartic boundary fit). 29/29 shell suite green; directed ctest 94/94; CBRA 18 lines byte-identical; B5 4/4 digest d1c875b2322e097d bit_identical. Notes: docs/planning/wave9/shell-notes.md
15 KiB
Wave 9 · W52 shell 薄壁/接缝误差闭环 —— 交付说明
任务:KCP-1.0 Wave 9 W52(task-128,agent cp9-shell)。
工作区:D:\3_Source\VDE_cp9_shell(分支 feat/kcp9-shell,基线 cf0bf2c5)。
主题:brep_shell_ex kSpline 薄壁/接缝误差闭环——把薄壁椭圆闭壳 t=1.0 闭合到 ≤1e-6,
同时不回退厚壁/环面/圆棱柱/拔模/真实 STEP 案例。
1. 结论摘要(硬门槛实测)
| # | 门槛 | 实测 | 结果 |
|---|---|---|---|
| ① | 薄壁椭圆闭壳 t=1.0 体积 rel ≤ 1e-6(原 1.209e-6) | 1.595e-08(1239.414367637 vs 1239.414387403) | ✅ 64× 余量 |
| ② | t=1.5 闭壳 ≤1e-6、开口 ≤1e-5 | 闭壳 1.594e-08;开口 1.233e-09 | ✅ |
| ③ | 环面 2.583e-10 / 圆棱柱 3.305e-11 不回退 | 逐位不变:2.583e-10 / 3.305e-11(均走 exact same-space 分支,fit_tol=0, iters=0) | ✅ |
| ④ | 新增/更新测试 ≥4 例 + 报告字段可复现 | 更新 1 例 + 新增 4 例(见 §5);断言 fit_tolerance≈6.145e-7±1e-9、iterations==8、[W52-CAP]/[W52-EDGE] 字段 |
✅ |
| ⑤ | 18 行 gated [CBRA] 逐字节一致 |
18/18 行 IDENTICAL(2341 B 内容逐字节;参考文件 2344 B 含 BOM),见 cbra_gated_18lines.txt |
✅ |
| ⑥ | B5 4/4 + digest d1c875b2322e097d |
pass=4/4,digest d1c875b2322e097d,bit_identical=true,284v/436e/146l/146f/1sh | ✅ |
| ⑦ | 定向 ctest -R "Shell|Draft|Blend|Brep|Fit" 0 failed |
94/94 passed, 0 failed | ✅ |
| ⑧ | legacy brep_shell/brep_draft 默认路径零行为变化 |
legacy 用例全绿;解析分支数值逐位不变(torus/circle prism fit_tol=0);CBRA/B5 与基线逐字节一致 | ✅ |
2. 误差表(before / after)
[W46-SHELL] 证据行格式:v_expect v_meas rel fit_tol max_rel iters nf(体积为 analytic_volume 结果)。
| 案例 | 参数 | before rel | after rel | fit_tolerance | max_rel_error | iterations |
|---|---|---|---|---|---|---|
| torus_exact_same_space | R=10 r=2 t=0.5 | 2.583e-10 | 2.583e-10 | 0 | 1.614e-16 | 0 |
| ellipse_closed_fit | rx=10 ry=6 H=20 t=1.5 | 9.641e-07 | 1.594e-08 | 6.145e-07 | 1.597e-09 | 8 |
| ellipse_open_top_fit | t=1.5 open top | 1.187e-07 | 1.233e-09 | 6.145e-07 | 1.597e-09 | 8 |
| circle_prism_closed_fit | r=8 H=20 t=1.5 | 3.305e-11 | 3.305e-11 | 0 | 0 | 0 |
| ellipse_thin_closed_fit | rx=10 ry=6 H=20 t=1.0 | 1.209e-06 | 1.595e-08 | 6.145e-07 | 1.135e-09 | 8 |
| ellipse_thin_open_top_fit(新增) | t=1.0 open top | — | 1.254e-08 | 6.145e-07 | 1.135e-09 | 8 |
| 厚度扫描 t=0.5 | rx=10 ry=6 H=20 | — | 1.658e-08 | 6.145e-07 | 1.026e-09 | 8 |
| 厚度扫描 t=1.0 | 同上 | — | 1.595e-08 | 6.145e-07 | 1.135e-09 | 8 |
| 厚度扫描 t=1.5 | 同上 | — | 1.594e-08 | 6.145e-07 | 1.597e-09 | 8 |
| 厚度扫描 t=2.0 | 同上 | — | 3.911e-08 | 6.145e-07 | 2.271e-09 | 8 |
| 真实 STEP 曲面件 3 例 | t=0.3736 / 0.0520 | fit_tol=0, iters=0(same-space) | 不变 | 0 | 0 | 0 |
wave8 遗留误差(docs/planning/wave8/shell-notes.md §5):薄壁 t=1.0 = 1.209e-06,超目标 21%;
本轮定位到根因并闭环到 1.595e-08。
3. 误差归因:W46 残差来自哪里
3.1 逐面分解(薄壁 t=1.0 闭壳,12 面;外 A=188.495559215,内 A_in=140.583154142,h=H−2t=18)
VDE_TRACE_PLANAR=1 VDE_TRACE_FACEMEASURE=1 的**基线(修复前)**逐面 triple:
| 面组 | 解析 triple | 基线实测 | 偏差 | 备注 |
|---|---|---|---|---|
| 外壁 4 面(f0/f2/f4/f6) | +2AH/4 = +1884.955592 | 1884.955592 | ~0 | 解析 ruled 面,精确 |
| 内壁 4 面(f1/f3/f5/f7) | −2A_in·h/4 = −1265.248399 | −1265.248372 | +1.1e-4(合计) | 壁面拟合误差 3.5e-8,量级可忽略 |
| 外底/外顶(f8/f10) | 0 / +A·H=3769.911184 | 0 / 3769.911184 | ~0 | 精确 |
| 内底端面(f9, z=t) | +t·A_in = +140.583154 | 140.583411097 | +2.57e-4 | 环面积偏大 |
| 内顶端面(f11, z=H−t) | −(H−t)·A_in = −2671.079929 | −2671.084810570 | −4.88e-3 | ×(H−t) 放大,主导项 |
体积 = Σtriple/3,顶部端面一项 (−4.88e-3) 就解释了整壳 −1.498e-3 绝对体积误差 (rel 1.209e-6)的绝大部分;底部端面 +2.57e-4/3 次之;内壁合计 ~1e-4 可忽略。
3.2 逐环(内腔端面边界环)面积
同一组 kSpline 拟合边界曲线同时被内底/内顶端面与内壁面引用,因此端面环面积可独立交叉验证:
- 解析 Steiner 内偏置面积:
A_in = A − L·t + πt²(L=椭圆周长 51.05399772679101,numpy 数值验证 1e-10) → t=1.0:140.583154142;t=1.5:118.983146096。 - 基线(修复前)环面积:内底 140.583411097(+2.5696e-4)、内顶 140.583411083;外环 188.495559215 精确。
- 修复后(四次配点边界曲线):内底 140.583162011(+7.9e-6)、内顶 140.583162008; 剩余偏差 = measure.cpp 对非二次曲线单段 12 点 Gauss 的面积口径(见 §3.4),已从 2.6e-4 降到 8e-6。
- 开口壳 rim 交叉验证:rim 4 块面积合计 69.5125033 → 内顶环面积 = A_outer − rim = 118.9830559, 与内底端面(同一条曲线的另一个 z)118.9834426 相差 ~3.9e-4,说明基线两个端面环都系统性偏大。
3.3 逐边(8 条四分之一椭圆内边界边)
VDE_W46_DEBUG=1 的 edge coll 行:
| 边 | before raw_err(deg 3) | after raw_err(deg 4) | 独立稠密验证(4ncp+1=133 点) |
|---|---|---|---|
| 内底 4 条四分之一弧 | 6.058e-07 | 4.053e-08 | 对解析内偏置椭圆 max_dev 4.394e-08 |
| 内顶 4 条四分之一弧 | 6.058e-07 | 4.051e-08 | 同上 |
- 端点强制与内腔顶点一致:
(9,0,1)/(0,5,1)/(−9,0,1)/(0,−5,1)与z=19对应点,误差 1e-11 量级。 - 壁面(ruled 偏置面)不变、且不是残差来源:
ruled att=0 ncp=33 measured=6.836e-07(t=1.0)/9.601e-07(t=1.5),att=1 ncp=66 measured=3.488e-08 / 4.908e-08——壁面拟合精度 ~3.5e-8, 无法解释 2.5e-4 面积偏差。
3.4 根因机理
src/brep/measure.cpp 的 exact_planar_measure(measure.cpp:809-908)对平面面用 Green 公式沿真实 3D
边界曲线积分面积,边界边分派规则(measure.cpp:844-849):
degree() == 2→green_add_curve_spanned(逐节点区间 12 点 Gauss,VDE-1402 修复);- 其它次数 →
green_add_curve→green_add_curve_span(measure.cpp:472-504),整个参数域单段 12 点 Gauss。
W46 的内腔边界曲线是 collocate_curve 生成的 degree-3、33 控制点、30 个节点区间的 C2 样条:
单段 12 点 Gauss 对跨 30 段的样条积分欠采样,面积出现 +2.66e-4 系统偏差(scipy 独立复现:
deg3/ncp33 单段 12 点 Gauss 面积 +2.658e-04,与实测 cap 面积偏差 +2.5696e-4 一致)。
该偏差被 (H−t)/3 直接放大进体积:δV ≈ (H−t)·δA/3 = 19×2.66e-4/3 ≈ 1.7e-3 ⇒ rel 1.2e-6,与实测吻合。
scipy 数值实验(collocate_curve 同参数:均匀 clamped 节点 + Greville 配点,目标 = 解析内偏置椭圆四分之一弧):
| 配置 | 拟合 max_err | 单段 12 点 Gauss 面积偏差 |
|---|---|---|
| ncp=33, deg=3 | 1.049e-06 | +2.658e-04 |
| ncp=65, deg=3 | 5.687e-08 | −1.261e-05 |
| ncp=33, deg=4 | 4.219e-08 | +8.371e-06 |
| ncp=65, deg=4 | ~3e-09 | ~1e-06 |
| ncp=33, deg=2 | 1.800e-05 | −1.302e-02 |
结论:同一控制点数下升到四次配点同时改善两个目标——几何拟合误差 1.05e-6→4.2e-8, 单段 Gauss 面积偏差 2.66e-4→8.4e-6(因四次样条节点区间更少、且被积函数更光滑)。 先前"插值偏差"假设已被证伪(scipy not-a-knot 插值实验中环面积偏差仅 −7.5e-6,无法解释残差)。
3.5 为何修复点选在 blend_ops2.cpp 而不是 measure.cpp
measure.cpp 的单段 Gauss 分派是更上游的口径问题,但:
- 本任务写作用域限定
src/brep/blend_ops2.cpp、include/vde/brep/advanced_blend.h、tests/brep/test_shell_draft_curved.cpp、tests/brep/CMakeLists.txt、本 notes; - 改 measure.cpp 属跨任务共享路径,影响所有平面的面积/体积口径,对门槛 ⑤⑥⑦ 有系统性风险;
- 升阶配点本身就是真实的几何精度改进(边界曲线拟合误差降 25×),不是仅绕开积分口径的补丁。
若后续要把 measure.cpp 的单段 Gauss 改为跨节点分段积分(与
green_add_curve_spanned对齐), 建议另立任务专门做,并用 B5/CBRA/面积回归护栏覆盖。
4. 代码变更
src/brep/blend_ops2.cpp(2 处,+10/−2 行):
- W46 容差常量区(
kSplineEdgeAcceptRelTol之后,约 line 1066)新增:constexpr int kSplineEdgeFitDegree = 4; // W52:映射边界曲线配点阶次 fit_mapped_edge_curve的分支 2(约 line 1466):collocate_curve(ncp, 3, sampler, fitted, coll_diag)→collocate_curve(ncp, kSplineEdgeFitDegree, ...)。
tests/brep/test_shell_draft_curved.cpp(+190/−5 行):更新 1 例 + 新增 4 例(§5),
新增 <algorithm>/<utility> 头。
未改动:include/vde/brep/advanced_blend.h、tests/brep/CMakeLists.txt(无需新字段/新目标)、任何阈值。
5. 测试(≥4 例目标:实际 5 例)
更新:
W46EllipseThinClosedFitTolerance(t=1.0 薄壁闭壳):- rel 门槛 2e-6 → 1e-6(收紧,不是放宽);
- 断言报告字段可复现:
fit_tolerance ≈ 6.145e-7 ± 1e-9、iterations == 8、max_rel_error ≤ 1e-6; - 注释记录 W52 根因与修复数据。
新增:
W52EllipseThinOpenTopFitTolerance:t=1.0 开口壳(open top at z=H),期望A·H − A_in·(H−t),rel<1e-6 → 实测 1.254e-08。W52EllipseClosedThicknessSweep:t ∈ {0.5, 1.0, 1.5, 2.0} 闭壳全厚度带,各自 rel<1e-6 → 实测 1.658e-08 / 1.595e-08 / 1.594e-08 / 3.911e-08。W52InnerCapAreaConsistency:用face_measure直接测内腔底面/顶面(平面 Green 面积 + triple), 断言 |area − A_in| ≤ 2e-5、|triple − z·area| ≤ 1e-9、|triple_bottom − triple_top − H·A_in| ≤ 5e-4, 打印[W52-CAP] area/triple/d_area可复现证据行。W52InnerBoundaryCurveQuarticFit:遍历内腔端面环,断言恰好 4 条曲线边且degree()==4, 逐点(128 点/边)到解析内偏置椭圆的最近点距离 ≤ 2e-6(黄金分割精化投影), 打印[W52-EDGE] edge/deg/p0/p1/max_dev。
复现证据行(修复后):
[W46-SHELL] ellipse_thin_closed_fit v_expect=1239.414387403 v_meas=1239.414367637 rel=1.595e-08 fit_tol=6.145e-07 max_rel=1.135e-09 iters=8 nf=12
[W52-CAP] inner_bottom area=140.583162011 a_expect=140.583155384 d_area=6.628e-06 triple=140.583162011 | inner_top area=140.583162008 triple=-2671.080078150
[W52-EDGE] inner_cap curved_edges=4 quartic=4 max_dev=4.394e-08
6. 门槛证据(D:\3_Source\VDE_drawint\build\kcp9_evidence\shell\)
| 门槛 | 证据文件 | 结果 |
|---|---|---|
| ④ 测试全绿(29/29) | shell_tests.log |
[PASSED] 29 tests |
| ⑤ 18 行 gated CBRA | cbra_gated.log、cbra_gated_18lines.txt |
18 行、2341 B 内容与 D:\3_Source\ViewDesignEngine\build\ab_1050_final_cbra_gated.txt 逐字节一致(CBRA18=IDENTICAL) |
| ⑥ B5 | b5_report.json、b5_run.log |
pass=4/4、digest d1c875b2322e097d、bit_identical=true |
| ⑦ 定向 ctest | ctest_directed.log |
94/94 passed,0 failed |
| ①–③ 体积误差 | shell_tests.log([W46-SHELL] 行) |
见 §2 表 |
| 诊断 | w46_debug_after.log(VDE_W46_DEBUG=1) |
edge coll ... raw_err=2.058e-08/3.450e-08、ruled 壁面 att 数据 |
7. 复现命令(Release worktree)
cd D:\3_Source\VDE_cp9_shell
# 一次性 configure(FetchContent 全部离线)
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DFETCHCONTENT_FULLY_DISCONNECTED=ON `
-DFETCHCONTENT_SOURCE_DIR_EIGEN3=D:/3_Source/ViewDesignEngine/eigen3 `
-DFETCHCONTENT_SOURCE_DIR_JSON=D:/3_Source/ViewDesignEngine/json `
-DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=D:/3_Source/ViewDesignEngine/googletest `
-DVDE_NATIVE_CORPUS_DIR=D:/3_Source/VDE_drawint/corpus/real `
-DVDE_REAL_CORPUS_DIR=D:/3_Source/VDE_drawint/tests/data/fixtures/real
cmake --build build --target test_shell_draft_curved bench_kcp test_curved_boolean_baseline -j3
# ①–④ 壳/拔模用例(含 W52 证据行)
build\tests\brep\test_shell_draft_curved.exe
$env:VDE_W46_DEBUG=1
build\tests\brep\test_shell_draft_curved.exe --gtest_filter=*EllipseThin*:*EllipseClosedFit*
# ⑤ 18 行 gated CBRA 逐字节
$env:VDE_CB4_SLOW_INTEGRATION="1"
build\tests\brep\test_curved_boolean_baseline.exe --gtest_filter=CurvedBooleanBaseline.CurvedSurfaceFixturesBaseline
# 提取 ^\[CBRA\] 18 行与 D:\3_Source\ViewDesignEngine\build\ab_1050_final_cbra_gated.txt 比较
# ⑥ B5
$env:OMP_NUM_THREADS="1"
build\tests\benchmark\bench_kcp.exe --suite b5 --rounds 3 --threads 1 --json-out <ev>\b5_report.json
# ⑦ 定向回归
ctest --test-dir build -C Release -j4 -R "Shell|Draft|Blend|Brep|Fit" --output-on-failure
8. 变更文件与提交
src/brep/blend_ops2.cpp:kSplineEdgeFitDegree = 4+fit_mapped_edge_curve配点阶次。tests/brep/test_shell_draft_curved.cpp:更新 1 例 + 新增 4 例(W52 证据行)。docs/planning/wave9/shell-notes.md:本文件。
提交:见 feat/kcp9-shell 分支 commit(附 git diff --stat:2 文件 195 insertions / 5 deletions,
notes 另计)。补丁:D:\3_Source\VDE_drawint\build\catchup9\shell.patch。
9. 未达项 / 后续建议
- 硬门槛 ①–⑧ 全部达成,无未达项。
- 已知遗留(不属本任务写作用域):
measure.cpp对degree != 2的平面环边仍用整参数域单段 12 点 Gauss(green_add_curve); W52 通过让边界曲线达到 measure 口径可接受的四次配点回避了该问题。建议另立任务把该分派改为 跨节点分段积分(对齐green_add_curve_spanned),可再降 cap 面积口径偏差 8e-6→~1e-6。- 内壁 ruled 偏置面在
ncp=33时 fit 不合格(measured 6.8e-79.6e-7),需升到4.9e-8);当前ncp=66才达标 (measured 3.5e-8iterations=8(每面两轮)稳定收敛,但若未来放宽采样预算需关注。 validate worst d=1.17e-01(17×9 参数对应校验)为参数对应口径的既有诊断量,W46/W52 均未改变, 不代表几何偏差(壁面独立稠密校验 3.5e-8)。