Skip to content

Commit 7736e52

Browse files
rois1995claudeEvertBunschotenbigfootedrois1995
authored
BCGSTAB: do not return the initial guess as the best iterate (#2979)
## Proposed Changes Since #2933, BCGSTAB returns the iterate with the smallest residual. The initial guess (zero) was also a candidate. When no step lowered the residual, the solver returned zero, so the variables got no update. With few linear iterations this happens often. In RAE2822 SA (`LINEAR_SOLVER_ITER= 3`) the turbulence variable stops being updated from iteration 11, and the case converges to a wrong solution. Now only the computed iterates are candidates. Only `turbmod_sa_neg_rae2822` changes. Its reference values are updated from the CI. ## Related Work - #2933 ## PR Checklist - [x] I am submitting my contribution to the develop branch. - [x] My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson). - [x] My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/). - [x] I used the pre-commit hook to prevent dirty commits and used `pre-commit run --all` to format old commits. - [ ] I have added a test case that demonstrates my contribution, if necessary. - [ ] I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Evert Bunschoten <38651601+EvertBunschoten@users.noreply.github.com> Co-authored-by: Nijso <bigfootedrockmidget@hotmail.com> Co-authored-by: rois1995 <rauxa1995@gmail.com>
1 parent 50dd0e3 commit 7736e52

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎Common/src/linear_algebra/CSysSolve.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,6 @@ unsigned long CSysSolve<ScalarType>::BCGSTAB_LinSolver(const CSysVector<ScalarTy
11371137

11381138
ScalarType alpha = 1.0, omega = 1.0, rho = 1.0, rho_prime = 1.0;
11391139
ScalarType norm_best = norm_r;
1140-
if (config->GetComm_Level() == COMM_FULL) x_best = x;
11411140
p = ScalarType(0.0);
11421141
v = ScalarType(0.0);
11431142
r_0 = r;
@@ -1198,7 +1197,7 @@ unsigned long CSysSolve<ScalarType>::BCGSTAB_LinSolver(const CSysVector<ScalarTy
11981197
/*--- Check if solution has converged, else output the relative residual if necessary ---*/
11991198

12001199
norm_r = r.norm();
1201-
if (norm_r < norm_best) {
1200+
if ((i == 0) || (norm_r < norm_best)) {
12021201
norm_best = norm_r;
12031202
x_best = x;
12041203
}
@@ -1211,7 +1210,8 @@ unsigned long CSysSolve<ScalarType>::BCGSTAB_LinSolver(const CSysVector<ScalarTy
12111210
}
12121211
}
12131212

1214-
/*--- BCGSTAB does not reduce the residual monotonically, return the best iterate. ---*/
1213+
/*--- BCGSTAB does not reduce the residual monotonically, return the best iterate.
1214+
* The initial guess is not a candidate, returning it would mean no update at all. ---*/
12151215

12161216
if ((config->GetComm_Level() == COMM_FULL) && (norm_r > norm_best)) {
12171217
x = x_best;

‎TestCases/parallel_regression.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ def main():
10161016
turbmod_sa_neg_rae2822.cfg_dir = "turbulence_models/sa/rae2822"
10171017
turbmod_sa_neg_rae2822.cfg_file = "turb_SA_NEG_RAE2822.cfg"
10181018
turbmod_sa_neg_rae2822.test_iter = 10
1019-
turbmod_sa_neg_rae2822.test_vals = [1.275731, 1.063097, -2.067745, 1.301949, 0.481304, 0.000000]
1019+
turbmod_sa_neg_rae2822.test_vals = [1.451597, 1.501625, 4.235621, 1.337846, 0.493212, 0.000000]
10201020
turbmod_sa_neg_rae2822.test_vals_aarch64 = [-1.345593, 1.448310, 1.208721, -0.846597, 1.248410, 0.489117, 0.000000]
10211021
test_list.append(turbmod_sa_neg_rae2822)
10221022

0 commit comments

Comments
 (0)