]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Replace logstream.push/pop by Logstream::Prefix.
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 5 Oct 2017 22:57:41 +0000 (16:57 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 5 Oct 2017 22:57:41 +0000 (16:57 -0600)
include/deal.II/lac/solver_bicgstab.h
include/deal.II/lac/solver_cg.h
include/deal.II/lac/solver_fire.h
include/deal.II/lac/solver_gmres.h
include/deal.II/lac/solver_minres.h
include/deal.II/lac/solver_qmrs.h
include/deal.II/lac/solver_relaxation.h
include/deal.II/lac/solver_richardson.h

index 7450a871429dbcf900d966fac26ca3c70b4241d2..43093e076d89a6d56b5b14af518b94aed5335925 100644 (file)
@@ -449,7 +449,7 @@ SolverBicgstab<VectorType>::solve(const MatrixType         &A,
                                   const VectorType         &b,
                                   const PreconditionerType &preconditioner)
 {
-  deallog.push("Bicgstab");
+  LogStream::Prefix prefix("Bicgstab");
   Vr    = typename VectorMemory<VectorType>::Pointer(this->memory);
   Vrbar = typename VectorMemory<VectorType>::Pointer(this->memory);
   Vp    = typename VectorMemory<VectorType>::Pointer(this->memory);
@@ -488,8 +488,6 @@ SolverBicgstab<VectorType>::solve(const MatrixType         &A,
     }
   while (state.breakdown == true);
 
-  deallog.pop();
-
   // in case of failure: throw exception
   AssertThrow(state.state == SolverControl::success,
               SolverControl::NoConvergence (state.last_step,
index 3d784e5867a1a4176c2888b1e4b454cee4c8c480..028d4031e5d7c475d85638b386b67f16d52e236c 100644 (file)
@@ -310,7 +310,7 @@ SolverCG<VectorType>::solve (const MatrixType         &A,
 {
   SolverControl::State conv=SolverControl::iterate;
 
-  deallog.push("cg");
+  LogStream::Prefix prefix("cg");
 
   // Memory allocation
   typename VectorMemory<VectorType>::Pointer g_pointer(this->memory);
@@ -336,114 +336,102 @@ SolverCG<VectorType>::solve (const MatrixType         &A,
   int  it=0;
   double res = -std::numeric_limits<double>::max();
 
-  try
+  double eigen_beta_alpha = 0;
+
+  // resize the vectors, but do not set
+  // the values since they'd be overwritten
+  // soon anyway.
+  g.reinit(x, true);
+  d.reinit(x, true);
+  h.reinit(x, true);
+
+  double gh,beta;
+
+  // compute residual. if vector is
+  // zero, then short-circuit the
+  // full computation
+  if (!x.all_zero())
     {
-      double eigen_beta_alpha = 0;
+      A.vmult(g,x);
+      g.add(-1.,b);
+    }
+  else
+    g.equ(-1.,b);
+  res = g.l2_norm();
 
-      // resize the vectors, but do not set
-      // the values since they'd be overwritten
-      // soon anyway.
-      g.reinit(x, true);
-      d.reinit(x, true);
-      h.reinit(x, true);
+  conv = this->iteration_status(0, res, x);
+  if (conv != SolverControl::iterate)
+    return;
 
-      double gh,beta;
+  if (std::is_same<PreconditionerType,PreconditionIdentity>::value == false)
+    {
+      preconditioner.vmult(h,g);
 
-      // compute residual. if vector is
-      // zero, then short-circuit the
-      // full computation
-      if (!x.all_zero())
-        {
-          A.vmult(g,x);
-          g.add(-1.,b);
-        }
-      else
-        g.equ(-1.,b);
-      res = g.l2_norm();
+      d.equ(-1.,h);
+
+      gh = g*h;
+    }
+  else
+    {
+      d.equ(-1.,g);
+      gh = res*res;
+    }
+
+  while (conv == SolverControl::iterate)
+    {
+      it++;
+      A.vmult(h,d);
+
+      double alpha = d*h;
+      Assert(alpha != 0., ExcDivideByZero());
+      alpha = gh/alpha;
+
+      x.add(alpha,d);
+      res = std::sqrt(g.add_and_dot(alpha, h, g));
 
-      conv = this->iteration_status(0, res, x);
+      print_vectors(it, x, g, d);
+
+      conv = this->iteration_status(it, res, x);
       if (conv != SolverControl::iterate)
-        {
-          deallog.pop();
-          return;
-        }
+        break;
 
-      if (std::is_same<PreconditionerType,PreconditionIdentity>::value == false)
+      if (std::is_same<PreconditionerType,PreconditionIdentity>::value
+          == false)
         {
           preconditioner.vmult(h,g);
 
-          d.equ(-1.,h);
-
-          gh = g*h;
+          beta = gh;
+          Assert(beta != 0., ExcDivideByZero());
+          gh   = g*h;
+          beta = gh/beta;
+          d.sadd(beta,-1.,h);
         }
       else
         {
-          d.equ(-1.,g);
+          beta = gh;
           gh = res*res;
+          beta = gh/beta;
+          d.sadd(beta,-1.,g);
         }
 
-      while (conv == SolverControl::iterate)
+      this->coefficients_signal(alpha,beta);
+      // set up the vectors
+      // containing the diagonal
+      // and the off diagonal of
+      // the projected matrix.
+      if (do_eigenvalues)
         {
-          it++;
-          A.vmult(h,d);
-
-          double alpha = d*h;
-          Assert(alpha != 0., ExcDivideByZero());
-          alpha = gh/alpha;
-
-          x.add(alpha,d);
-          res = std::sqrt(g.add_and_dot(alpha, h, g));
-
-          print_vectors(it, x, g, d);
-
-          conv = this->iteration_status(it, res, x);
-          if (conv != SolverControl::iterate)
-            break;
-
-          if (std::is_same<PreconditionerType,PreconditionIdentity>::value
-              == false)
-            {
-              preconditioner.vmult(h,g);
-
-              beta = gh;
-              Assert(beta != 0., ExcDivideByZero());
-              gh   = g*h;
-              beta = gh/beta;
-              d.sadd(beta,-1.,h);
-            }
-          else
-            {
-              beta = gh;
-              gh = res*res;
-              beta = gh/beta;
-              d.sadd(beta,-1.,g);
-            }
-
-          this->coefficients_signal(alpha,beta);
-          // set up the vectors
-          // containing the diagonal
-          // and the off diagonal of
-          // the projected matrix.
-          if (do_eigenvalues)
-            {
-              diagonal.push_back(1./alpha + eigen_beta_alpha);
-              eigen_beta_alpha = beta/alpha;
-              offdiagonal.push_back(std::sqrt(beta)/alpha);
-            }
-          compute_eigs_and_cond(diagonal,offdiagonal,all_eigenvalues_signal,
-                                all_condition_numbers_signal);
+          diagonal.push_back(1./alpha + eigen_beta_alpha);
+          eigen_beta_alpha = beta/alpha;
+          offdiagonal.push_back(std::sqrt(beta)/alpha);
         }
+      compute_eigs_and_cond(diagonal,offdiagonal,all_eigenvalues_signal,
+                            all_condition_numbers_signal);
     }
-  catch (...)
-    {
-      deallog.pop();
-      throw;
-    }
+
   compute_eigs_and_cond(diagonal,offdiagonal,eigenvalues_signal,
                         condition_number_signal);
 
-  deallog.pop();
-
   // in case of failure: throw exception
   if (conv != SolverControl::success)
     AssertThrow(false, SolverControl::NoConvergence (it, res));
index 316b664fb745f76044d6a9bd8cd310cd41816736..486f8dcce64fec75f01974c3f6fd20c3230ace7d 100644 (file)
@@ -251,7 +251,7 @@ SolverFIRE<VectorType>::solve
  VectorType                                                    &x,
  const PreconditionerType                                      &inverse_mass_matrix)
 {
-  deallog.push("FIRE");
+  LogStream::Prefix prefix("FIRE");
 
   // FIRE algorithm constants
   const double DELAYSTEP       = 5;
@@ -361,8 +361,6 @@ SolverFIRE<VectorType>::solve
 
     } // While we need to iterate.
 
-  deallog.pop();
-
   // In the case of failure: throw exception.
   if (conv != SolverControl::success)
     AssertThrow (false,
index 4920926e28b5d77b0fce957207cf927523be49bb..ab8494d4df55e45abf632dbc5d4a3121dd5346ab 100644 (file)
@@ -777,7 +777,7 @@ SolverGMRES<VectorType>::solve (const MatrixType         &A,
 //TODO:[?] Check, why there are two different start residuals.
 //TODO:[GK] Make sure the parameter in the constructor means maximum basis size
 
-  deallog.push("GMRES");
+  LogStream::Prefix prefix("GMRES");
   const unsigned int n_tmp_vectors = additional_data.max_n_tmp_vectors;
 
   // Generate an object where basis vectors are stored.
@@ -1046,8 +1046,6 @@ SolverGMRES<VectorType>::solve (const MatrixType         &A,
   if (!krylov_space_signal.empty())
     krylov_space_signal(tmp_vectors);
 
-  deallog.pop();
-
   // in case of failure: throw exception
   AssertThrow(iteration_state == SolverControl::success,
               SolverControl::NoConvergence (accumulated_iterations,
@@ -1172,7 +1170,7 @@ SolverFGMRES<VectorType>::solve (const MatrixType         &A,
                                  const VectorType         &b,
                                  const PreconditionerType &preconditioner)
 {
-  deallog.push("FGMRES");
+  LogStream::Prefix prefix("FGMRES");
 
   SolverControl::State iteration_state = SolverControl::iterate;
 
@@ -1257,7 +1255,6 @@ SolverFGMRES<VectorType>::solve (const MatrixType         &A,
     }
   while (iteration_state == SolverControl::iterate);
 
-  deallog.pop();
   // in case of failure: throw exception
   if (iteration_state != SolverControl::success)
     AssertThrow(false, SolverControl::NoConvergence (accumulated_iterations,
index d46cbb9d80e33aaf0df639ddb811f547b7470589..3c7f79566e3266abed7765a89a05783975ffb147 100644 (file)
@@ -193,7 +193,7 @@ SolverMinRes<VectorType>::solve (const MatrixType         &A,
                                  const VectorType         &b,
                                  const PreconditionerType &preconditioner)
 {
-  deallog.push("minres");
+  LogStream::Prefix prefix("minres");
 
   // Memory allocation
   typename VectorMemory<VectorType>::Pointer Vu0 (this->memory);
@@ -350,9 +350,6 @@ SolverMinRes<VectorType>::solve (const MatrixType         &A,
       delta[1] = delta[2];
     }
 
-  // Output
-  deallog.pop ();
-
   // in case of failure: throw exception
   AssertThrow(conv == SolverControl::success,
               SolverControl::NoConvergence (j, r_l2));
index df6fef22f9d5b47e96f3166c613d8d61810ee920..a3b40b1e7d5de5c21681aa4233e318616d9491bd 100644 (file)
@@ -260,7 +260,7 @@ SolverQMRS<VectorType>::solve (const MatrixType         &A,
                                const VectorType         &b,
                                const PreconditionerType &preconditioner)
 {
-  deallog.push("QMRS");
+  LogStream::Prefix prefix("QMRS");
 
   // temporary vectors, allocated through the @p VectorMemory object at the
   // start of the actual solution process and deallocated at the end.
@@ -291,9 +291,6 @@ SolverQMRS<VectorType>::solve (const MatrixType         &A,
     }
   while (state.state == SolverControl::iterate);
 
-  // Output
-  deallog.pop();
-
   // in case of failure: throw exception
   AssertThrow(state.state == SolverControl::success,
               SolverControl::NoConvergence (step,
index 0f212b37c80f16e5b90f21db0c05864992a478f6..7ae5880248f0d75fb54c8009d674b46081031377 100644 (file)
@@ -122,35 +122,26 @@ SolverRelaxation<VectorType>::solve (const MatrixType     &A,
   VectorType &d  = *Vd;
   d.reinit(x);
 
-  deallog.push("Relaxation");
+  LogStream::Prefix prefix("Relaxation");
 
   int iter=0;
-  try
+  // Main loop
+  for (; conv==SolverControl::iterate; iter++)
     {
-      // Main loop
-      for (; conv==SolverControl::iterate; iter++)
-        {
-          // Compute residual
-          A.vmult(r,x);
-          r.sadd(-1.,1.,b);
-
-          // The required norm of the
-          // (preconditioned)
-          // residual is computed in
-          // criterion() and stored
-          // in res.
-          conv = this->iteration_status (iter, r.l2_norm(), x);
-          if (conv != SolverControl::iterate)
-            break;
-          R.step(x,b);
-        }
+      // Compute residual
+      A.vmult(r,x);
+      r.sadd(-1.,1.,b);
+
+      // The required norm of the
+      // (preconditioned)
+      // residual is computed in
+      // criterion() and stored
+      // in res.
+      conv = this->iteration_status (iter, r.l2_norm(), x);
+      if (conv != SolverControl::iterate)
+        break;
+      R.step(x,b);
     }
-  catch (...)
-    {
-      deallog.pop();
-      throw;
-    }
-  deallog.pop();
 
   // in case of failure: throw exception
   AssertThrow(conv == SolverControl::success,
index 487f8e55907b2838d1722b2e9b68bb194bdf29fa..23e7b7fb9c0adc540ca0882bf2137a6be62c64c1 100644 (file)
@@ -217,40 +217,30 @@ SolverRichardson<VectorType>::solve (const MatrixType         &A,
   VectorType &d  = *Vd;
   d.reinit(x);
 
-  deallog.push("Richardson");
+  LogStream::Prefix prefix("Richardson");
 
-  try
+  // Main loop
+  while (conv==SolverControl::iterate)
     {
-      // Main loop
-      while (conv==SolverControl::iterate)
-        {
-          // Do not use residual,
-          // but do it in 2 steps
-          A.vmult(r,x);
-          r.sadd(-1.,1.,b);
-          preconditioner.vmult(d,r);
-
-          // get the required norm of the (possibly preconditioned)
-          // residual
-          last_criterion = criterion(r, d);
-          conv = this->iteration_status (iter, last_criterion, x);
-          if (conv != SolverControl::iterate)
-            break;
-
-          x.add(additional_data.omega,d);
-          print_vectors(iter,x,r,d);
-
-          ++iter;
-        }
-    }
-  catch (...)
-    {
-      deallog.pop();
-      throw;
+      // Do not use residual,
+      // but do it in 2 steps
+      A.vmult(r,x);
+      r.sadd(-1.,1.,b);
+      preconditioner.vmult(d,r);
+
+      // get the required norm of the (possibly preconditioned)
+      // residual
+      last_criterion = criterion(r, d);
+      conv = this->iteration_status (iter, last_criterion, x);
+      if (conv != SolverControl::iterate)
+        break;
+
+      x.add(additional_data.omega,d);
+      print_vectors(iter,x,r,d);
+
+      ++iter;
     }
 
-  deallog.pop();
-
   // in case of failure: throw exception
   if (conv != SolverControl::success)
     AssertThrow(false, SolverControl::NoConvergence (iter,
@@ -284,37 +274,28 @@ SolverRichardson<VectorType>::Tsolve (const MatrixType         &A,
   VectorType &d  = *Vd;
   d.reinit(x);
 
-  deallog.push("RichardsonT");
+  LogStream::Prefix prefix("RichardsonT");
 
-  try
-    {
-      // Main loop
-      while (conv==SolverControl::iterate)
-        {
-          // Do not use Tresidual,
-          // but do it in 2 steps
-          A.Tvmult(r,x);
-          r.sadd(-1.,1.,b);
-          preconditioner.Tvmult(d,r);
-
-          last_criterion = criterion(r, d);
-          conv = this->iteration_status (iter, last_criterion, x);
-          if (conv != SolverControl::iterate)
-            break;
-
-          x.add(additional_data.omega,d);
-          print_vectors(iter,x,r,d);
-
-          ++iter;
-        }
-    }
-  catch (...)
+  // Main loop
+  while (conv==SolverControl::iterate)
     {
-      deallog.pop();
-      throw;
+      // Do not use Tresidual,
+      // but do it in 2 steps
+      A.Tvmult(r,x);
+      r.sadd(-1.,1.,b);
+      preconditioner.Tvmult(d,r);
+
+      last_criterion = criterion(r, d);
+      conv = this->iteration_status (iter, last_criterion, x);
+      if (conv != SolverControl::iterate)
+        break;
+
+      x.add(additional_data.omega,d);
+      print_vectors(iter,x,r,d);
+
+      ++iter;
     }
 
-  deallog.pop();
   // in case of failure: throw exception
   if (conv != SolverControl::success)
     AssertThrow(false, SolverControl::NoConvergence (iter, last_criterion));

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.