]> https://gitweb.dealii.org/ - dealii.git/commitdiff
SolverGMRES: Fix loop bound for orthogonalization
authorMartin Kronbichler <martin.kronbichler@rub.de>
Mon, 11 Mar 2024 12:29:52 +0000 (13:29 +0100)
committerMartin Kronbichler <martin.kronbichler@rub.de>
Mon, 11 Mar 2024 12:29:52 +0000 (13:29 +0100)
include/deal.II/lac/solver_gmres.h

index 7ac8083e122c4141a8f7e82aa3c8bc4203d44b24..19414566757bf91e8db1f2c1259a4588c64692ab 100644 (file)
@@ -930,10 +930,11 @@ namespace internal
     {
       Assert(dim > 0, ExcInternalError());
 
-      for (unsigned int i = 0; i < dim; ++i)
+      for (unsigned int i = 0; i < dim - 1; ++i)
         vv.add(-h(i), orthogonal_vectors[i]);
 
-      return std::sqrt(vv.add_and_dot(-h(dim), orthogonal_vectors[dim], vv));
+      return std::sqrt(
+        vv.add_and_dot(-h(dim - 1), orthogonal_vectors[dim - 1], vv));
     }
 
 
@@ -1366,6 +1367,8 @@ SolverGMRES<VectorType>::solve(const MatrixType         &A,
     }
 
   bool re_orthogonalize = additional_data.force_re_orthogonalization;
+  // reset this vector to the right size
+  h.reinit(n_tmp_vectors - 1);
 
   ///////////////////////////////////////////////////////////////////////////
   // outer iteration: loop until we either reach convergence or the maximum
@@ -1373,9 +1376,6 @@ SolverGMRES<VectorType>::solve(const MatrixType         &A,
   // restart
   do
     {
-      // reset this vector to the right size
-      h.reinit(n_tmp_vectors - 1);
-
       double rho = 0.0;
 
       if (left_precondition)
@@ -1577,7 +1577,7 @@ SolverGMRES<VectorType>::solve(const MatrixType         &A,
             p, dim, h, tmp_vectors, true);
           preconditioner.vmult(v, p);
           x.add(1., v);
-        };
+        }
       // end of outer iteration. restart if no convergence and the number of
       // iterations is not exceeded
     }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.