Skip to content

Commit 94bd1ab

Browse files
authored
Update convergence criterion for MLMG (#6408)
In #2410, the convergence criterion of the MLMG solver was modified so as to use the norm of `b` (whenever `|b|` is not zero), to evaluate the relative error in the Poisson equation (written as `Ax = b`) and decide when to stop the iterations. However, there are cases where this it not suitable. A typical case is when the user fixes a large value of the potential at the boundaries (or on the embedded boundary), and also has a very low-charge beam in the simulation. In this case, the residual is dominated by the potential created by the boundaries, but the norm of `b` (which depends on the charge density of the beam) is very low, resulting in a large `resid/bnorm`. In some cases, this large `resid/bnorm` can even trigger the error `MLMG failing so lets stop here` because of this check in AMREX: https://github.com/AMReX-Codes/amrex/blob/development/Src/LinearSolvers/MLMG/AMReX_MLMG.H#L539 Instead, with this PR, we always use the maximum of the norm of `b` and of the initial residual `resid0` to evaluate the relative error in the Poisson equation - instead of using directly the maximum of the norm of `b`. I also checked that this fixes the issue mentioned here: #6161 (comment) The changes in the checksum is because of the change in convergence criterion.
1 parent d158107 commit 94bd1ab

File tree

5 files changed

+23
-28
lines changed

5 files changed

+23
-28
lines changed
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
22
"lev=0": {
3-
"rho_electrons": 0.03558889420026204,
4-
"rho_he_ions": 0.041762340951146074
3+
"rho_electrons": 0.03558889420351498,
4+
"rho_he_ions": 0.04176234095095327
55
},
66
"he_ions": {
7-
"particle_momentum_x": 2.8840921556995102e-18,
8-
"particle_momentum_y": 2.1957048736351022e-18,
9-
"particle_momentum_z": 2.198216674541737e-18,
10-
"particle_position_x": 17607.425457505866,
11-
"particle_position_y": 1100.0247860590894,
7+
"particle_momentum_x": 2.8840921570976e-18,
8+
"particle_momentum_y": 2.195704873634808e-18,
9+
"particle_momentum_z": 2.1982166745272215e-18,
10+
"particle_position_x": 17607.425457559715,
11+
"particle_position_y": 1100.024786059876,
1212
"particle_weight": 71976747650.1465
1313
},
1414
"electrons": {
15-
"particle_momentum_x": 1.0105526130672624e-18,
16-
"particle_momentum_y": 2.8197429889743996e-19,
17-
"particle_momentum_z": 2.8091808266114265e-19,
18-
"particle_position_x": 17136.01865030665,
19-
"particle_position_y": 936.3651769884851,
15+
"particle_momentum_x": 1.010552606677337e-18,
16+
"particle_momentum_y": 2.81974298750407e-19,
17+
"particle_momentum_z": 2.8091808348750305e-19,
18+
"particle_position_x": 17136.0186559433,
19+
"particle_position_y": 936.3651746710019,
2020
"particle_weight": 61113170379.63868
2121
}
22-
}
22+
}

Regression/Checksum/benchmarks_json/test_2d_embedded_boundary_cube.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"Bx": 9.2636945391314e-05,
44
"By": 0.00031905198911870116,
55
"Bz": 7.328424778796838e-05,
6-
"Ex": 8553.90669231672,
6+
"Ex": 8553.906692257373,
77
"Ey": 60867.0482641368,
8-
"Ez": 4.223901049143958e-06
8+
"Ez": 3.35209259952839e-08
99
}
1010
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"lev=0": {
3-
"Ex": 4.865922376234882e-11,
3+
"Ex": 1.5548810315827429e-18,
44
"Ey": 0.0,
5-
"Ez": 2.3293326580399806e-10
5+
"Ez": 9.69073951936753e-18
66
}
7-
}
7+
}

Source/ablastr/fields/EffectivePotentialPoissonSolver.H

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ computeEffectivePotentialPhi (
150150

151151
auto const finest_level = static_cast<int>(rho.size() - 1);
152152

153-
// determine if rho is zero everywhere
154-
const amrex::Real max_norm_b = getMaxNormRho(
155-
amrex::GetVecOfConstPtrs(rho), finest_level, absolute_tolerance);
156-
157153
const amrex::LPInfo info;
158154

159155
for (int lev=0; lev<=finest_level; lev++) {
@@ -231,7 +227,7 @@ computeEffectivePotentialPhi (
231227
amrex::MLMG mlmg(*linop); // actual solver defined here
232228
mlmg.setVerbose(verbosity);
233229
mlmg.setMaxIter(max_iters);
234-
mlmg.setConvergenceNormType((max_norm_b > 0) ? amrex::MLMGNormType::bnorm : amrex::MLMGNormType::greater);
230+
mlmg.setConvergenceNormType(amrex::MLMGNormType::greater);
235231

236232
const int ng = int(grid_type == utils::enums::GridType::Collocated); // ghost cells
237233
if (ng) {

Source/ablastr/fields/PoissonSolver.H

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,6 @@ computePhi (
261261
[](const auto b){return (b<1.0_rt);}),
262262
"Components of beta_solver must be < 1.");
263263

264-
// determine if rho is zero everywhere
265-
const amrex::Real max_norm_b = getMaxNormRho(
266-
amrex::GetVecOfConstPtrs(rho), finest_level, absolute_tolerance);
267-
268264
amrex::LPInfo info;
269265

270266
for (int lev=0; lev<=finest_level; lev++) {
@@ -274,6 +270,9 @@ computePhi (
274270
geom[lev].CellSize(2)/std::sqrt(1._rt-beta_solver[2]*beta_solver[2]))};
275271

276272
#if (defined(ABLASTR_USE_FFT) && defined(WARPX_DIM_3D))
273+
// determine if rho is zero everywhere
274+
const amrex::Real max_norm_b = getMaxNormRho(
275+
amrex::GetVecOfConstPtrs(rho), finest_level, absolute_tolerance);
277276
// Use the Integrated Green Function solver (FFT) on the coarsest level if it was selected
278277
if(is_solver_igf_on_lev0 && lev==0){
279278
if ( max_norm_b == 0 ) {
@@ -404,7 +403,7 @@ computePhi (
404403
amrex::MLMG mlmg(*linop); // actual solver defined here
405404
mlmg.setVerbose(verbosity);
406405
mlmg.setMaxIter(max_iters);
407-
mlmg.setConvergenceNormType((max_norm_b > 0) ? amrex::MLMGNormType::bnorm : amrex::MLMGNormType::greater);
406+
mlmg.setConvergenceNormType(amrex::MLMGNormType::greater);
408407

409408
const int ng = int(grid_type == utils::enums::GridType::Collocated); // ghost cells
410409
if (ng) {

0 commit comments

Comments
 (0)