oomph::GS< MATRIX > Class Template Reference

The Gauss Seidel method. More...

#include <iterative_linear_solver.h>

+ Inheritance diagram for oomph::GS< MATRIX >:

Public Member Functions

 GS ()
 Constructor. More...
 
virtual ~GS ()
 Destructor (cleanup storage) More...
 
 GS (const GS &)=delete
 Broken copy constructor. More...
 
void operator= (const GS &)=delete
 Broken assignment operator. More...
 
void disable_resolve ()
 Overload disable resolve so that it cleans up memory too. More...
 
void smoother_setup (DoubleMatrixBase *matrix_pt)
 Set up the smoother for the matrix specified by the pointer. More...
 
void smoother_solve (const DoubleVector &rhs, DoubleVector &result)
 
void solve (Problem *const &problem_pt, DoubleVector &result)
 
void solve (DoubleMatrixBase *const &matrix_pt, const DoubleVector &rhs, DoubleVector &solution)
 
void solve (DoubleMatrixBase *const &matrix_pt, const Vector< double > &rhs, Vector< double > &result)
 
void resolve (const DoubleVector &rhs, DoubleVector &result)
 
double preconditioner_setup_time () const
 Returns the time taken to set up the preconditioner. More...
 
unsigned iterations () const
 Number of iterations taken. More...
 
- Public Member Functions inherited from oomph::Smoother
 Smoother ()
 Empty constructor. More...
 
virtual ~Smoother ()
 Virtual empty destructor. More...
 
template<typename MATRIX >
void check_validity_of_solve_helper_inputs (MATRIX *const &matrix_pt, const DoubleVector &rhs, DoubleVector &solution, const double &n_dof)
 
- Public Member Functions inherited from oomph::IterativeLinearSolver
 IterativeLinearSolver ()
 
 IterativeLinearSolver (const IterativeLinearSolver &)=delete
 Broken copy constructor. More...
 
void operator= (const IterativeLinearSolver &)=delete
 Broken assignment operator. More...
 
virtual ~IterativeLinearSolver ()
 Destructor (empty) More...
 
Preconditioner *& preconditioner_pt ()
 Access function to preconditioner. More...
 
Preconditioner *const & preconditioner_pt () const
 Access function to preconditioner (const version) More...
 
doubletolerance ()
 Access to convergence tolerance. More...
 
unsignedmax_iter ()
 Access to max. number of iterations. More...
 
void enable_doc_convergence_history ()
 Enable documentation of the convergence history. More...
 
void disable_doc_convergence_history ()
 Disable documentation of the convergence history. More...
 
void open_convergence_history_file_stream (const std::string &file_name, const std::string &zone_title="")
 
void close_convergence_history_file_stream ()
 Close convergence history output stream. More...
 
double jacobian_setup_time () const
 
double linear_solver_solution_time () const
 return the time taken to solve the linear system More...
 
void enable_setup_preconditioner_before_solve ()
 Setup the preconditioner before the solve. More...
 
void disable_setup_preconditioner_before_solve ()
 Don't set up the preconditioner before the solve. More...
 
void enable_error_after_max_iter ()
 Throw an error if we don't converge within max_iter. More...
 
void disable_error_after_max_iter ()
 Don't throw an error if we don't converge within max_iter (default). More...
 
void enable_iterative_solver_as_preconditioner ()
 
void disable_iterative_solver_as_preconditioner ()
 
- Public Member Functions inherited from oomph::LinearSolver
 LinearSolver ()
 Empty constructor, initialise the member data. More...
 
 LinearSolver (const LinearSolver &dummy)=delete
 Broken copy constructor. More...
 
void operator= (const LinearSolver &)=delete
 Broken assignment operator. More...
 
virtual ~LinearSolver ()
 Empty virtual destructor. More...
 
void enable_doc_time ()
 Enable documentation of solve times. More...
 
void disable_doc_time ()
 Disable documentation of solve times. More...
 
bool is_doc_time_enabled () const
 Is documentation of solve times enabled? More...
 
bool is_resolve_enabled () const
 Boolean flag indicating if resolves are enabled. More...
 
virtual void enable_resolve ()
 
virtual void solve_transpose (Problem *const &problem_pt, DoubleVector &result)
 
virtual void solve_transpose (DoubleMatrixBase *const &matrix_pt, const DoubleVector &rhs, DoubleVector &result)
 
virtual void solve_transpose (DoubleMatrixBase *const &matrix_pt, const Vector< double > &rhs, Vector< double > &result)
 
virtual void resolve_transpose (const DoubleVector &rhs, DoubleVector &result)
 
virtual void enable_computation_of_gradient ()
 
void disable_computation_of_gradient ()
 
void reset_gradient ()
 
void get_gradient (DoubleVector &gradient)
 function to access the gradient, provided it has been computed More...
 
- Public Member Functions inherited from oomph::DistributableLinearAlgebraObject
 DistributableLinearAlgebraObject ()
 Default constructor - create a distribution. More...
 
 DistributableLinearAlgebraObject (const DistributableLinearAlgebraObject &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const DistributableLinearAlgebraObject &)=delete
 Broken assignment operator. More...
 
virtual ~DistributableLinearAlgebraObject ()
 Destructor. More...
 
LinearAlgebraDistributiondistribution_pt () const
 access to the LinearAlgebraDistribution More...
 
unsigned nrow () const
 access function to the number of global rows. More...
 
unsigned nrow_local () const
 access function for the num of local rows on this processor. More...
 
unsigned nrow_local (const unsigned &p) const
 access function for the num of local rows on this processor. More...
 
unsigned first_row () const
 access function for the first row on this processor More...
 
unsigned first_row (const unsigned &p) const
 access function for the first row on this processor More...
 
bool distributed () const
 distribution is serial or distributed More...
 
bool distribution_built () const
 
void build_distribution (const LinearAlgebraDistribution *const dist_pt)
 
void build_distribution (const LinearAlgebraDistribution &dist)
 

Private Member Functions

void solve_helper (DoubleMatrixBase *const &matrix_pt, const DoubleVector &rhs, DoubleVector &solution)
 General interface to solve function. More...
 
void clean_up_memory ()
 Cleanup data that's stored for resolve (if any has been stored) More...
 

Private Attributes

MATRIX * Matrix_pt
 System matrix pointer in the format specified by the template argument. More...
 
unsigned Iterations
 Number of iterations taken. More...
 
bool Resolving
 
bool Matrix_can_be_deleted
 

Additional Inherited Members

- Protected Member Functions inherited from oomph::DistributableLinearAlgebraObject
void clear_distribution ()
 
- Protected Attributes inherited from oomph::Smoother
bool Use_as_smoother
 
- Protected Attributes inherited from oomph::IterativeLinearSolver
bool Doc_convergence_history
 
std::ofstream Output_file_stream
 Output file stream for convergence history. More...
 
double Tolerance
 Convergence tolerance. More...
 
unsigned Max_iter
 Maximum number of iterations. More...
 
PreconditionerPreconditioner_pt
 Pointer to the preconditioner. More...
 
double Jacobian_setup_time
 Jacobian setup time. More...
 
double Solution_time
 linear solver solution time More...
 
double Preconditioner_setup_time
 Preconditioner setup time. More...
 
bool Setup_preconditioner_before_solve
 
bool Throw_error_after_max_iter
 
bool Use_iterative_solver_as_preconditioner
 Use the iterative solver as preconditioner. More...
 
bool First_time_solve_when_used_as_preconditioner
 
- Protected Attributes inherited from oomph::LinearSolver
bool Enable_resolve
 
bool Doc_time
 Boolean flag that indicates whether the time taken. More...
 
bool Compute_gradient
 
bool Gradient_has_been_computed
 flag that indicates whether the gradient was computed or not More...
 
DoubleVector Gradient_for_glob_conv_newton_solve
 
- Static Protected Attributes inherited from oomph::IterativeLinearSolver
static IdentityPreconditioner Default_preconditioner
 

Detailed Description

template<typename MATRIX>
class oomph::GS< MATRIX >

The Gauss Seidel method.

//////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

Constructor & Destructor Documentation

◆ GS() [1/2]

template<typename MATRIX >
oomph::GS< MATRIX >::GS ( )
inline

Constructor.

603  : Matrix_pt(0),
604  Iterations(0),
605  Resolving(false),
607  {
608  }
unsigned Iterations
Number of iterations taken.
Definition: iterative_linear_solver.h:764
bool Matrix_can_be_deleted
Definition: iterative_linear_solver.h:772
bool Resolving
Definition: iterative_linear_solver.h:768
MATRIX * Matrix_pt
System matrix pointer in the format specified by the template argument.
Definition: iterative_linear_solver.h:761

◆ ~GS()

template<typename MATRIX >
virtual oomph::GS< MATRIX >::~GS ( )
inlinevirtual

Destructor (cleanup storage)

612  {
613  clean_up_memory();
614  }
void clean_up_memory()
Cleanup data that's stored for resolve (if any has been stored)
Definition: iterative_linear_solver.h:746

References oomph::GS< MATRIX >::clean_up_memory().

◆ GS() [2/2]

template<typename MATRIX >
oomph::GS< MATRIX >::GS ( const GS< MATRIX > &  )
delete

Broken copy constructor.

Member Function Documentation

◆ clean_up_memory()

template<typename MATRIX >
void oomph::GS< MATRIX >::clean_up_memory ( )
inlineprivatevirtual

Cleanup data that's stored for resolve (if any has been stored)

Reimplemented from oomph::LinearSolver.

747  {
748  // If the matrix pointer isn't null and we're allowed to delete it
749  // delete the matrix and assign the pointer the value NULL
750  if ((Matrix_pt != 0) && (Matrix_can_be_deleted))
751  {
752  // Destroy the matrix
753  delete Matrix_pt;
754 
755  // Make it a null pointer
756  Matrix_pt = 0;
757  }
758  } // End of clean_up_memory

References oomph::GS< MATRIX >::Matrix_can_be_deleted, and oomph::GS< MATRIX >::Matrix_pt.

Referenced by oomph::GS< MATRIX >::disable_resolve(), oomph::GS< CRDoubleMatrix >::disable_resolve(), oomph::GS< CRDoubleMatrix >::solve(), oomph::GS< MATRIX >::~GS(), and oomph::GS< CRDoubleMatrix >::~GS().

◆ disable_resolve()

template<typename MATRIX >
void oomph::GS< MATRIX >::disable_resolve ( )
inlinevirtual

Overload disable resolve so that it cleans up memory too.

Reimplemented from oomph::LinearSolver.

624  {
626  clean_up_memory();
627  } // End of disable_resolve
virtual void disable_resolve()
Definition: linear_solver.h:144

References oomph::GS< MATRIX >::clean_up_memory(), and oomph::LinearSolver::disable_resolve().

◆ iterations()

template<typename MATRIX >
unsigned oomph::GS< MATRIX >::iterations ( ) const
inlinevirtual

Number of iterations taken.

Implements oomph::IterativeLinearSolver.

735  {
736  return Iterations;
737  } // End of iterations

References oomph::GS< MATRIX >::Iterations.

◆ operator=()

template<typename MATRIX >
void oomph::GS< MATRIX >::operator= ( const GS< MATRIX > &  )
delete

Broken assignment operator.

◆ preconditioner_setup_time()

template<typename MATRIX >
double oomph::GS< MATRIX >::preconditioner_setup_time ( ) const
inlinevirtual

Returns the time taken to set up the preconditioner.

Reimplemented from oomph::IterativeLinearSolver.

725  {
726  throw OomphLibError(
727  "Gauss Seidel is not a preconditionable iterative solver",
730  return 0;
731  } // End of preconditioner_setup_time
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

◆ resolve()

template<typename MATRIX >
void oomph::GS< MATRIX >::resolve ( const DoubleVector rhs,
DoubleVector result 
)
inlinevirtual

Re-solve the system defined by the last assembled Jacobian and the rhs vector specified here. Solution is returned in the vector result.

Reimplemented from oomph::LinearSolver.

703  {
704  // We are re-solving
705  Resolving = true;
706 
707 #ifdef PARANOID
708  if (Matrix_pt == 0)
709  {
710  throw OomphLibError("No matrix was stored -- cannot re-solve",
713  }
714 #endif
715 
716  // Call linear algebra-style solver
717  solve(Matrix_pt, rhs, result);
718 
719  // Reset re-solving flag
720  Resolving = false;
721  } // End of resolve
void solve(Problem *const &problem_pt, DoubleVector &result)
Definition: iterative_linear_solver.cc:1104

References oomph::GS< MATRIX >::Matrix_pt, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::GS< MATRIX >::Resolving, and oomph::GS< MATRIX >::solve().

◆ smoother_setup()

template<typename MATRIX >
void oomph::GS< MATRIX >::smoother_setup ( DoubleMatrixBase matrix_pt)
inlinevirtual

Set up the smoother for the matrix specified by the pointer.

Implements oomph::Smoother.

631  {
632  // Assume the matrix has been passed in from the outside so we must
633  // not delete it. This is needed to avoid pre- and post-smoothers
634  // deleting the same matrix in the MG solver. If this was originally
635  // set to TRUE then this will be sorted out in the other functions
636  // from which this was called
637  Matrix_can_be_deleted = false;
638 
639  // Upcast the input matrix to system matrix to the type MATRIX
640  Matrix_pt = dynamic_cast<MATRIX*>(matrix_pt);
641  } // End of smoother_setup

References oomph::GS< MATRIX >::Matrix_can_be_deleted, and oomph::GS< MATRIX >::Matrix_pt.

◆ smoother_solve()

template<typename MATRIX >
void oomph::GS< MATRIX >::smoother_solve ( const DoubleVector rhs,
DoubleVector result 
)
inlinevirtual

The smoother_solve function performs fixed number of iterations on the system A*result=rhs. The number of (smoothing) iterations is the same as the max. number of iterations in the underlying IterativeLinearSolver class.

Implements oomph::Smoother.

648  {
649  // If you use a smoother but you don't want to calculate the residual
650  Use_as_smoother = true;
651 
652  // Call the helper function
653  solve_helper(Matrix_pt, rhs, result);
654  } // End of smoother_setup
void solve_helper(DoubleMatrixBase *const &matrix_pt, const DoubleVector &rhs, DoubleVector &solution)
General interface to solve function.
Definition: iterative_linear_solver.cc:1164
bool Use_as_smoother
Definition: iterative_linear_solver.h:585

References oomph::GS< MATRIX >::Matrix_pt, oomph::GS< MATRIX >::solve_helper(), and oomph::Smoother::Use_as_smoother.

◆ solve() [1/3]

template<typename MATRIX >
void oomph::GS< MATRIX >::solve ( DoubleMatrixBase *const &  matrix_pt,
const DoubleVector rhs,
DoubleVector solution 
)
inlinevirtual

Linear-algebra-type solver: Takes pointer to a matrix and rhs vector and returns the solution of the linear system.

Reimplemented from oomph::LinearSolver.

666  {
667  // Reset the Use_as_smoother_flag as the solver is not being used
668  // as a smoother
669  Use_as_smoother = false;
670 
671  // Set up the distribution
672  this->build_distribution(rhs.distribution_pt());
673 
674  // Store the matrix if required
675  if ((Enable_resolve) && (!Resolving))
676  {
677  // Upcast to the appropriate matrix type
678  Matrix_pt = dynamic_cast<MATRIX*>(matrix_pt);
679  }
680 
681  // Matrix has been passed in from the outside so we must not delete it
682  Matrix_can_be_deleted = false;
683 
684  // Call the helper function
685  this->solve_helper(matrix_pt, rhs, solution);
686  } // End of solve
void build_distribution(const LinearAlgebraDistribution *const dist_pt)
Definition: linear_algebra_distribution.h:507
bool Enable_resolve
Definition: linear_solver.h:73
void solution(const Vector< double > &x, Vector< double > &u)
Definition: two_d_biharmonic.cc:113

References oomph::DistributableLinearAlgebraObject::build_distribution(), oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::LinearSolver::Enable_resolve, oomph::GS< MATRIX >::Matrix_can_be_deleted, oomph::GS< MATRIX >::Matrix_pt, oomph::GS< MATRIX >::Resolving, BiharmonicTestFunctions1::solution(), oomph::GS< MATRIX >::solve_helper(), and oomph::Smoother::Use_as_smoother.

◆ solve() [2/3]

template<typename MATRIX >
void oomph::GS< MATRIX >::solve ( DoubleMatrixBase *const &  matrix_pt,
const Vector< double > &  rhs,
Vector< double > &  result 
)
inlinevirtual

Linear-algebra-type solver: Takes pointer to a matrix and rhs vector and returns the solution of the linear system Call the broken base-class version. If you want this, please implement it

Reimplemented from oomph::LinearSolver.

695  {
696  LinearSolver::solve(matrix_pt, rhs, result);
697  } // End of solve
virtual void solve(Problem *const &problem_pt, DoubleVector &result)=0

References oomph::LinearSolver::solve().

◆ solve() [3/3]

template<typename MATRIX >
void oomph::GS< MATRIX >::solve ( Problem *const &  problem_pt,
DoubleVector result 
)
virtual

Solver: Takes pointer to problem and returns the results vector which contains the solution of the linear system defined by the problem's fully assembled Jacobian and residual vector.

//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// Solver: Takes pointer to problem and returns the results vector which contains the solution of the linear system defined by the problem's fully assembled Jacobian and residual vector.

Implements oomph::LinearSolver.

1105  {
1106  // Reset the Use_as_smoother_flag as the solver is not being used
1107  // as a smoother
1108  Use_as_smoother = false;
1109 
1110  // Find the # of degrees of freedom (variables)
1111  unsigned n_dof = problem_pt->ndof();
1112 
1113  // Initialise timer
1114  double t_start = TimingHelpers::timer();
1115 
1116  // We're not re-solving
1117  Resolving = false;
1118 
1119  // Get rid of any previously stored data
1120  clean_up_memory();
1121 
1122  // Set up the distribution
1123  LinearAlgebraDistribution dist(problem_pt->communicator_pt(), n_dof, false);
1124 
1125  // Assign the distribution to the LinearSolver
1126  this->build_distribution(dist);
1127 
1128  // Allocate space for the Jacobian matrix in format specified
1129  // by template parameter
1130  Matrix_pt = new MATRIX;
1131 
1132  // Get the nonlinear residuals vector
1133  DoubleVector f;
1134 
1135  // Assign the Jacobian and the residuals vector
1136  problem_pt->get_jacobian(f, *Matrix_pt);
1137 
1138  // We've made the matrix, we can delete it...
1139  Matrix_can_be_deleted = true;
1140 
1141  // Doc time for setup
1142  double t_end = TimingHelpers::timer();
1143  Jacobian_setup_time = t_end - t_start;
1144 
1145  // If time documentation is enabled
1146  if (Doc_time)
1147  {
1148  oomph_info << "Time for setup of Jacobian [sec]: " << Jacobian_setup_time
1149  << std::endl;
1150  }
1151 
1152  // Call linear algebra-style solver
1153  this->solve_helper(Matrix_pt, f, result);
1154 
1155  // Kill matrix unless it's still required for resolve
1157  } // End of solve
std::vector< double > DoubleVector
loads clump configuration
Definition: ClumpInput.h:26
double Jacobian_setup_time
Jacobian setup time.
Definition: iterative_linear_solver.h:248
bool Doc_time
Boolean flag that indicates whether the time taken.
Definition: linear_solver.h:77
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237
double timer()
returns the time in seconds after some point in past
Definition: oomph_utilities.cc:1295
OomphInfo oomph_info
Definition: oomph_definitions.cc:319

References oomph::TerminateHelper::clean_up_memory(), oomph::Problem::communicator_pt(), f(), oomph::Problem::get_jacobian(), oomph::Problem::ndof(), oomph::oomph_info, and oomph::TimingHelpers::timer().

Referenced by oomph::GS< MATRIX >::resolve(), and oomph::GS< CRDoubleMatrix >::resolve().

◆ solve_helper()

template<typename MATRIX >
void oomph::GS< MATRIX >::solve_helper ( DoubleMatrixBase *const &  matrix_pt,
const DoubleVector rhs,
DoubleVector solution 
)
private

General interface to solve function.

Linear-algebra-type solver: Takes pointer to a matrix and rhs vector and returns the solution of the linear system.

1167  {
1168  // Get number of dofs
1169  unsigned n_dof = rhs.nrow();
1170 
1171 #ifdef PARANOID
1172  // Upcast the matrix to the appropriate type
1173  MATRIX* tmp_matrix_pt = dynamic_cast<MATRIX*>(matrix_pt);
1174 
1175  // PARANOID Run the self-tests to check the inputs are correct
1176  this->check_validity_of_solve_helper_inputs<MATRIX>(
1177  tmp_matrix_pt, rhs, solution, n_dof);
1178 
1179  // We don't need the pointer any more but we do still need the matrix
1180  // so just make tmp_matrix_pt a null pointer
1181  tmp_matrix_pt = 0;
1182 #endif
1183 
1184  // Set up the solution if it is not
1185  if (!solution.distribution_pt()->built())
1186  {
1187  // Build it!
1188  solution.build(this->distribution_pt(), 0.0);
1189  }
1190  // If the solution is already set up
1191  else
1192  {
1193  // If we're inside the multigrid solver then as we traverse up the
1194  // hierarchy we use the smoother on the updated approximate solution.
1195  // As such, we should ONLY be resetting all the values to zero if
1196  // we're NOT inside the multigrid solver
1197  if (!Use_as_smoother)
1198  {
1199  // Initialise the vector with all entries set to zero
1200  solution.initialise(0.0);
1201  }
1202  } // if (!solution.distribution_pt()->built())
1203 
1204  // Initialise timer
1205  double t_start = TimingHelpers::timer();
1206 
1207  // Copy the solution vector into x
1209 
1210  // Create a vector to hold the residual. This will only be built if
1211  // we're not inside the multigrid solver
1212  DoubleVector current_residual;
1213 
1214  // Variable to hold the current residual norm. Only used if we're
1215  // not inside the multigrid solver
1216  double norm_res = 0.0;
1217 
1218  // Variables to hold the initial residual norm. Only used if we're
1219  // not inside the multigrid solver
1220  double norm_f = 0.0;
1221 
1222  // Initialise the value of Iterations
1223  Iterations = 0;
1224 
1225  // Calculate the residual only if we're not inside the multigrid solver
1226  if (!Use_as_smoother)
1227  {
1228  // Build the residual vector
1229  current_residual.build(this->distribution_pt(), 0.0);
1230 
1231  // Calculate the residual r=b-Ax
1232  matrix_pt->residual(x, rhs, current_residual);
1233 
1234  // Calculate the 2-norm of the residual vector
1235  norm_res = current_residual.norm();
1236 
1237  // Store the initial norm
1238  norm_f = norm_res;
1239 
1240  // If required, document the convergence history to screen or file (if
1241  // the output stream open)
1243  {
1244  // If the output file stream isn't open
1245  if (!Output_file_stream.is_open())
1246  {
1247  // Output the result to screen
1248  oomph_info << Iterations << " " << norm_res << std::endl;
1249  }
1250  // If the output file stream is open
1251  else
1252  {
1253  // Document the result to file
1254  Output_file_stream << Iterations << " " << norm_res << std::endl;
1255  }
1256  } // if (Doc_convergence_history)
1257  } // if (!Use_as_smoother)
1258 
1259  // Start of the main GS loop: run up to Max_iter times
1260  for (unsigned iter_num = 0; iter_num < Max_iter; iter_num++)
1261  {
1262  // Loop over rows
1263  for (unsigned i = 0; i < n_dof; i++)
1264  {
1265  double dummy = rhs[i];
1266  for (unsigned j = 0; j < i; j++)
1267  {
1268  dummy -= (*(matrix_pt))(i, j) * x[j];
1269  }
1270  for (unsigned j = (i + 1); j < n_dof; j++)
1271  {
1272  dummy -= (*(matrix_pt))(i, j) * x[j];
1273  }
1274  x[i] = dummy / (*(matrix_pt))(i, i);
1275  } // for(unsigned i=0;i<n_dof;i++)
1276 
1277  // Increment the value of Iterations
1278  Iterations++;
1279 
1280  // Calculate the residual only if we're not inside the multigrid solver
1281  if (!Use_as_smoother)
1282  {
1283  // Get residual
1284  matrix_pt->residual(x, rhs, current_residual);
1285 
1286  // Calculate the relative residual norm (i.e.
1287  // \frac{\|r_{i}\|}{\|r_{0}\|})
1288  norm_res = current_residual.norm() / norm_f;
1289 
1290  // If required will document convergence history to screen or file (if
1291  // stream open)
1293  {
1294  if (!Output_file_stream.is_open())
1295  {
1296  oomph_info << Iterations << " " << norm_res << std::endl;
1297  }
1298  else
1299  {
1300  Output_file_stream << Iterations << " " << norm_res << std::endl;
1301  }
1302  } // if (Doc_convergence_history)
1303 
1304  // Check the tolerance only if the residual norm is being computed
1305  if (norm_res < Tolerance)
1306  {
1307  // Break out of the for-loop
1308  break;
1309  }
1310  } // if (!Use_as_smoother)
1311  } // for (unsigned iter_num=0;iter_num<Max_iter;iter_num++)
1312 
1313  // Calculate the residual only if we're not inside the multigrid solver
1314  if (!Use_as_smoother)
1315  {
1316  // If time documentation is enabled
1317  if (Doc_time)
1318  {
1319  oomph_info << "\nGS converged. Residual norm: " << norm_res
1320  << "\nNumber of iterations to convergence: " << Iterations
1321  << "\n"
1322  << std::endl;
1323  }
1324  } // if (!Use_as_smoother)
1325 
1326  // Copy result into result
1327  solution = x;
1328 
1329  // Doc. time for solver
1330  double t_end = TimingHelpers::timer();
1331  Solution_time = t_end - t_start;
1332  if (Doc_time)
1333  {
1334  oomph_info << "Time for solve with GS [sec]: " << Solution_time
1335  << std::endl;
1336  }
1337 
1338  // If the solver failed to converge and the user asked for an error if
1339  // this happened
1341  {
1342  std::string error_message =
1343  "Solver failed to converge and you requested ";
1344  error_message += "an error on convergence failures.";
1345  throw OomphLibError(
1347  }
1348  } // End of solve_helper
int i
Definition: BiCGSTAB_step_by_step.cpp:9
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
Definition: linear_algebra_distribution.h:457
double Tolerance
Convergence tolerance.
Definition: iterative_linear_solver.h:239
bool Throw_error_after_max_iter
Definition: iterative_linear_solver.h:262
unsigned Max_iter
Maximum number of iterations.
Definition: iterative_linear_solver.h:242
double Solution_time
linear solver solution time
Definition: iterative_linear_solver.h:251
std::ofstream Output_file_stream
Output file stream for convergence history.
Definition: iterative_linear_solver.h:231
bool Doc_convergence_history
Definition: iterative_linear_solver.h:228
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
list x
Definition: plotDoE.py:28
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References oomph::DoubleVector::build(), i, Global_Variables::Iterations, j, oomph::BlackBoxFDNewtonSolver::Max_iter, oomph::DoubleVector::norm(), oomph::DistributableLinearAlgebraObject::nrow(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::oomph_info, oomph::DoubleMatrixBase::residual(), BiharmonicTestFunctions1::solution(), oomph::Global_string_for_annotation::string(), oomph::TimingHelpers::timer(), and plotDoE::x.

Referenced by oomph::GS< MATRIX >::smoother_solve(), oomph::GS< CRDoubleMatrix >::smoother_solve(), oomph::GS< MATRIX >::solve(), and oomph::GS< CRDoubleMatrix >::solve().

Member Data Documentation

◆ Iterations

template<typename MATRIX >
unsigned oomph::GS< MATRIX >::Iterations
private

◆ Matrix_can_be_deleted

◆ Matrix_pt

◆ Resolving

template<typename MATRIX >
bool oomph::GS< MATRIX >::Resolving
private

Boolean flag to indicate if the solve is done in re-solve mode, bypassing setup of matrix and preconditioner

Referenced by oomph::GS< MATRIX >::resolve(), oomph::GS< CRDoubleMatrix >::resolve(), oomph::GS< MATRIX >::solve(), and oomph::GS< CRDoubleMatrix >::solve().


The documentation for this class was generated from the following files: