[SSAMG] RelChange tests a stale temporary vector instead of the coarse correction
> This is generated from an LLM code audit. This bug appears plausible to me, but it may be a false positive. Feedback is appreciated.
## Summary
`HYPRE_SStructSSAMGSetRelChange` is meant to require that the relative change in `x` be small. `hypre_SSAMGSolve` computes that change from `e_l[0]`, but the fine-grid interpolation path never writes the correction into `e_l[0]`. Instead, it applies interpolation directly into `x_l[0]`, leaving `e_l[0]` as the relaxation temp vector (`tx_l[0]`) with unrelated contents.
## Reason
Setup aliases both residual and error work vectors to `tx_l`:
```c
r_l = tx_l;
e_l = tx_l;
```
During the up cycle, the fine-grid correction is applied in-place at `src/sstruct_ls/ssamg_solve.c:343-345`:
```c
hypre_SStructMatvecCompute(interp_data_l[0],
1.0, P_l[0], x_l[1],
1.0, x_l[0], x_l[0]);
```
The relative-change norm is then computed from `e_l[0]` at `src/sstruct_ls/ssamg_solve.c:386-398` after the correction has already bypassed `e_l[0]`. The debug output at `src/sstruct_ls/ssamg_solve.c:351-354` also prints `e_l[0]` as if it were the correction. Comparable SysPFMG and PFMG solve paths compute interpolation into `e_l[0]` and then add it to `x_l[0]`.
## Proposed Patch
Compute the coarse-grid correction into `e_l[l]` with beta zero, then add it to `x_l[l]`. This makes the relative-change test use the actual correction.
```diff
diff --git a/src/sstruct_ls/ssamg_solve.c b/src/sstruct_ls/ssamg_solve.c
@@
hypre_SStructMatvecCompute(interp_data_l[l],
1.0, P_l[l], x_l[l + 1],
- 1.0, x_l[l], x_l[l]);
+ 0.0, e_l[l], e_l[l]);
+ hypre_SStructAxpy(1.0, e_l[l], x_l[l]);
@@
hypre_SStructMatvecCompute(interp_data_l[0],
1.0, P_l[0], x_l[1],
- 1.0, x_l[0], x_l[0]);
+ 0.0, e_l[0], e_l[0]);
+ hypre_SStructAxpy(1.0, e_l[0], x_l[0]);
```
If `hypre_SStructAxpy` is not available in this compilation unit through the existing includes, add the appropriate SStruct MV prototype include rather than reimplementing vector addition.
0 条评论