C02_gather_3Dxyz_bspline Test
测试目标
tests/007_gather/C02_gather_3Dxyz_bspline 是
C02_gather_3Dxyz_bspline
的直接 gather 回归测试。它测试的是完整电磁场插值路径,而不只是权重生成:
顶层接口
sub_C02_gather_3Dxyz_bspline是否能正确读取par和六个场数组。order=1时是否退化为 C01 的三线性 gather。B-spline 权重对常数场是否保持常数。
order>=1时,对线性场是否给出解析粒子位置处的值。
本测试不覆盖 guard-cell 交换、边界条件、粒子推进或沉积。
覆盖接口
sub_C02_gather_3Dxyz_bspline:被测顶层子程序。sub_C02_bspline_stencil_1d、fun_C02_bspline_shape、fun_C02_gather_scalar_bspline:通过顶层 gather 间接覆盖。sub_C01_gather_3Dxyz:只在order1_c01子测试中作为对照参考。
文件说明
文件 |
作用 |
|---|---|
|
构造确定性粒子和场数组,运行三个逐分量比较子测试。 |
|
读取运行时比较结果,按子测试阈值统计最大误差和 PASS/FAIL。 |
|
使用 |
|
清理旧运行结果、编译、运行 Fortran 程序并执行 Python 分析。 |
|
删除编译产物、运行时临时结果和 Python 缓存。 |
运行方式
cd tests/007_gather/C02_gather_3Dxyz_bspline
bash run.sh
主流程
Fortran 程序构造确定性粒子和场数组。
order1_c01子测试用非线性场填充六个分量,同时调用 C01 和 C02order=1,逐分量比较。constant子测试对order=0..4使用常数场,检查 gather 后仍为同一常数。linear子测试对order=1..4使用线性场,检查 gather 值等于解析的F(x,y,z)。Python 脚本读取运行时比较结果,按子测试阈值判定 PASS/FAIL。
子测试说明
子测试 |
阶数 |
判断方式 |
|---|---|---|
|
|
C02 的 |
|
|
六个场分量全部填为常数;gather 后应保持这些常数。 |
|
|
六个场分量填为三维线性函数;gather 后应等于粒子坐标处的解析值。 |
结果判断
source_py/analyze.py 使用固定阈值判断结果:
子测试 |
阈值 |
说明 |
|---|---|---|
|
|
允许不同计算顺序带来的双精度舍入误差。 |
|
|
常数保持应接近机器精度。 |
|
|
|
参考运行结果:
rows : 1842
constant : max_abs=5.551e-16, tol=1.0e-12, rows=810
linear : max_abs=2.220e-15, tol=1.0e-11, rows=648
order1_c01 : max_abs=1.332e-15, tol=1.0e-11, rows=384
failures : 0
result : PASS
参考图
c02_bspline_gather_shape_curves.png:不同 order 的中心化
B-spline 形函数曲线。横轴为粒子到网格点的距离 \(r\),纵轴为权重
\(S_{order}(r)\)。这张图展示的是 gather 使用的局部权重形状,
便于直接查看不同阶数的支撑范围和平滑程度。
c02_bspline_gather_ref_vs_value.png:横轴为参考值,纵轴为
sub_C02_gather_3Dxyz_bspline 的 gather 输出。虚线为
value=reference。三类子测试都落在对角线附近,说明 direct gather
路径在这些基准场上与参考值一致。
c02_bspline_gather_errors.png:按子测试和 B-spline 阶数统计最大绝对误差。
纵轴为对数坐标。constant 覆盖 order=0..4,linear 覆盖
order=1..4,order1_c01 检查 order=1 与 C01 的一致性。
高阶误差略大来自浮点舍入累积:阶数越高,模板点、递归求值和乘加次数越多。
图中误差仍在机器精度附近,远低于阈值,不表示高阶 gather 变差。
常见误读
order1_c01不要求逐 bit 完全相等;它比较的是数值误差。constant和linear是形函数一致性测试,不代表高阶非线性场的收敛阶测试。本测试假定粒子位置和模板位于可访问数组范围内;它不测试 guard-cell 通信。
Test Goal
tests/007_gather/C02_gather_3Dxyz_bspline is the direct-gather
regression test for
C02_gather_3Dxyz_bspline.
It tests the complete electromagnetic-field interpolation path, not only
weight generation:
Whether the top-level
sub_C02_gather_3Dxyz_bsplineinterface readsparand the six field arrays correctly.Whether
order=1reduces to the C01 trilinear gather.Whether B-spline weights preserve constant fields.
Whether
order>=1reproduces linear fields at the analytic particle position.
The test does not cover guard-cell exchange, boundary conditions, particle pushing, or deposition.
Covered Interfaces
sub_C02_gather_3Dxyz_bspline: the top-level routine under test.sub_C02_bspline_stencil_1d,fun_C02_bspline_shape, andfun_C02_gather_scalar_bspline: covered indirectly through the top-level gather.sub_C01_gather_3Dxyz: used only as a reference in theorder1_c01subtest.
Files
File |
Role |
|---|---|
|
Builds deterministic particles and field arrays and runs three componentwise comparison subtests. |
|
Reads runtime comparison results, computes maximum errors with case-specific tolerances, and reports PASS/FAIL. |
|
Compiles the test program with |
|
Cleans previous run products, builds, runs the Fortran program, and executes the Python analysis. |
|
Removes build products, runtime temporary results, and Python cache files. |
Run Command
cd tests/007_gather/C02_gather_3Dxyz_bspline
bash run.sh
Main Flow
The Fortran program builds deterministic particles and field arrays.
The
order1_c01subtest fills all six components with a nonlinear field, calls both C01 and C02 withorder=1, and compares every component.The
constantsubtest uses constant fields fororder=0..4and checks that gathered values remain constant.The
linearsubtest uses 3D linear fields fororder=1..4and checks gathered values against analyticF(x,y,z).The Python script reads runtime comparison results and applies case-specific tolerances.
Subtests
Subtest |
Orders |
Check |
|---|---|---|
|
|
Compare C02 |
|
|
Fill all six components with constants; gathered values should preserve those constants. |
|
|
Fill all six components with 3D linear functions; gathered values should match analytic values at the particle coordinate. |
Result Criteria
source_py/analyze.py uses fixed tolerances:
Subtest |
Tolerance |
Meaning |
|---|---|---|
|
|
Allows double-precision round-off from different evaluation order. |
|
|
Constant preservation should be near machine precision. |
|
|
|
Reference run:
rows : 1842
constant : max_abs=5.551e-16, tol=1.0e-12, rows=810
linear : max_abs=2.220e-15, tol=1.0e-11, rows=648
order1_c01 : max_abs=1.332e-15, tol=1.0e-11, rows=384
failures : 0
result : PASS
Reference Figures
c02_bspline_gather_shape_curves.png: centered B-spline shape
functions for different order values. The x-axis is the
particle-grid distance \(r\); the y-axis is the weight
\(S_{order}(r)\). This figure shows the local weight shapes used by
gather, making the support width and smoothness of each order visible.
c02_bspline_gather_ref_vs_value.png: reference values on the x-axis
and gathered values from sub_C02_gather_3Dxyz_bspline on the y-axis.
The dashed line is value=reference. All three subtests lie close to
the diagonal, showing that the direct gather path agrees with the
references for these benchmark fields.
c02_bspline_gather_errors.png: maximum absolute error grouped by
subtest and B-spline order. The y-axis is logarithmic. constant
covers order=0..4, linear covers order=1..4, and
order1_c01 checks agreement with C01 for order=1. The slightly
larger high-order errors come from accumulated floating-point round-off:
higher orders use more stencil points, recursive evaluations, and
multiply-add operations. The errors remain near machine precision and
far below the tolerances, so this is not a loss of high-order accuracy.
Common Misreadings
order1_c01does not require bitwise equality; it checks numerical error.constantandlinearare shape-function consistency checks, not convergence-order tests for nonlinear fields.This test assumes particle positions and stencils are inside the accessible array range; it does not test guard-cell communication.