<commit_before>//----------------------------  solver_gmres.h  ---------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 1998, 1999, 2000, 2001, 2002 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//----------------------------  solver_gmres.h  ---------------------------
#ifndef __deal2__solver_gmres_h
#define __deal2__solver_gmres_h


/*----------------------------   solver_pgmres.h     ---------------------------*/

#include <base/config.h>
#include <base/subscriptor.h>
#include <base/logstream.h>
#include <lac/solver.h>
#include <lac/solver_control.h>
#include <lac/full_matrix.h>
#include <vector>


/**
 * Implementation of the Restarted Preconditioned Direct Generalized
 * Minimal Residual Method. The stopping criterion is the norm of the
 * residual.
 *
 * You have to give the maximum number of temporary vectors to the
 * constructor which are to be used to do the orthogonalization. If
 * the number of iterations needed to solve the problem to the given
 * criterion, an intermediate solution is computed and a restart is
 * performed. If you don't want to use the restarted method, you can
 * limit the number of iterations (stated in the @p{SolverControl}
 * object given to the constructor) to be below the number of
 * temporary vectors minus three. Note the subtraction, which is due
 * to the fact that three vectors are used for other purposes, so the
 * number of iterations before a restart occurs is less by three than
 * the total number of temporary vectors. If the size of the matrix is
 * smaller than the maximum number of temporary vectors, then fewer
 * vectors are allocated since GMRES can then be used as a direct
 * solver.
 *
 * Note that restarts don't compensate temporary vectors very well,
 * i.e.  giving too few temporary vectors will increase the necessary
 * iteration steps greatly; it is not uncommon that you will need more
 * iterations than there are degrees of freedom in your solution
 * vector, if the number of temporary vectors is lower than the size
 * of the vector, even though GMRES is an exact solver if a sufficient
 * number of temporary vectors is given. You should therefore always
 * give as many temporary vectors as you can, unless you are limited
 * by the available memory; only then should you start to trade
 * computational speed against memory. One of the few other
 * possibilities is to use a good preconditioner.
 *
 * Like all other solver classes, this class has a local structure called
 * @p{AdditionalData} which is used to pass additional parameters to the
 * solver, like damping parameters or the number of temporary vectors. We
 * use this additional structure instead of passing these values directly
 * to the constructor because this makes the use of the @p{SolverSelector} and
 * other classes much easier and guarantees that these will continue to
 * work even if number or type of the additional parameters for a certain
 * solver changes.
 *
 * For the GMRes method, the @p{AdditionalData} structure contains the number
 * of temporary vectors as commented upon above. By default, the number
 * of these vectors is set to 30.
 *
 * For the requirements on matrices and vectors in order to work with
 * this class, see the documentation of the @ref{Solver} base class.
 *
 * @author <NAME>
 */
template <class VECTOR = Vector<double> >
class SolverGMRES : public Solver<VECTOR>
{
  public:
    				     /**
				      * Standardized data struct to
				      * pipe additional data to the
				      * solver.
				      */
    struct AdditionalData 
    {
					 /**
					  * Constructor. By default,
					  * set the number of
					  * temporary vectors to 30
					  * and preconditioning from
					  * left..
					  */
	AdditionalData(const unsigned int max_n_tmp_vectors = 30,
		       bool right_preconditioning = false)
			:
			max_n_tmp_vectors(max_n_tmp_vectors),
			right_preconditioning(right_preconditioning)
	  {};
	
					 /**
					  * Maximum number of
					  * tmp vectors.
					  */
	unsigned int    max_n_tmp_vectors;
					   /**
					    * Flag for right preconditioning.
					    */
	  bool right_preconditioning;
    };
    
				     /**
				      * Constructor.
				      */
    SolverGMRES (SolverControl        &cn,
		 VectorMemory<VECTOR> &mem,
		 const AdditionalData &data=AdditionalData());

				     /**
				      * Solve the linear system $Ax=b$
				      * for x.
				      */
    template<class MATRIX, class PRECONDITIONER>
    void
    solve (const MATRIX         &A,
	   VECTOR               &x,
	   const VECTOR         &b,
	   const PRECONDITIONER &precondition);

    DeclException1 (ExcTooFewTmpVectors,
		    int,
		    << "The number of temporary vectors you gave ("
		    << arg1 << ") is too small. It should be at least 10 for "
		    << "any results, and much more for reasonable ones.");
    
  protected:
				     /**
				      * Includes the maximum number of
				      * tmp vectors.<commit_msg>Indent correctly according to out standards.<commit_after>//----------------------------  solver_gmres.h  ---------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 1998, 1999, 2000, 2001, 2002 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//----------------------------  solver_gmres.h  ---------------------------
#ifndef __deal2__solver_gmres_h
#define __deal2__solver_gmres_h


/*----------------------------   solver_pgmres.h     ---------------------------*/

#include <base/config.h>
#include <base/subscriptor.h>
#include <base/logstream.h>
#include <lac/solver.h>
#include <lac/solver_control.h>
#include <lac/full_matrix.h>
#include <vector>


/**
 * Implementation of the Restarted Preconditioned Direct Generalized
 * Minimal Residual Method. The stopping criterion is the norm of the
 * residual.
 *
 * You have to give the maximum number of temporary vectors to the
 * constructor which are to be used to do the orthogonalization. If
 * the number of iterations needed to solve the problem to the given
 * criterion, an intermediate solution is computed and a restart is
 * performed. If you don't want to use the restarted method, you can
 * limit the number of iterations (stated in the @p{SolverControl}
 * object given to the constructor) to be below the number of
 * temporary vectors minus three. Note the subtraction, which is due
 * to the fact that three vectors are used for other purposes, so the
 * number of iterations before a restart occurs is less by three than
 * the total number of temporary vectors. If the size of the matrix is
 * smaller than the maximum number of temporary vectors, then fewer
 * vectors are allocated since GMRES can then be used as a direct
 * solver.
 *
 * Note that restarts don't compensate temporary vectors very well,
 * i.e.  giving too few temporary vectors will increase the necessary
 * iteration steps greatly; it is not uncommon that you will need more
 * iterations than there are degrees of freedom in your solution
 * vector, if the number of temporary vectors is lower than the size
 * of the vector, even though GMRES is an exact solver if a sufficient
 * number of temporary vectors is given. You should therefore always
 * give as many temporary vectors as you can, unless you are limited
 * by the available memory; only then should you start to trade
 * computational speed against memory. One of the few other
 * possibilities is to use a good preconditioner.
 *
 * Like all other solver classes, this class has a local structure called
 * @p{AdditionalData} which is used to pass additional parameters to the
 * solver, like damping parameters or the number of temporary vectors. We
 * use this additional structure instead of passing these values directly
 * to the constructor because this makes the use of the @p{SolverSelector} and
 * other classes much easier and guarantees that these will continue to
 * work even if number or type of the additional parameters for a certain
 * solver changes.
 *
 * For the GMRes method, the @p{AdditionalData} structure contains the number
 * of temporary vectors as commented upon above. By default, the number
 * of these vectors is set to 30.
 *
 * For the requirements on matrices and vectors in order to work with
 * this class, see the documentation of the @ref{Solver} base class.
 *
 * @author <NAME>
 */
template <class VECTOR = Vector<double> >
class SolverGMRES : public Solver<VECTOR>
{
  public:
    				     /**
				      * Standardized data struct to
				      * pipe additional data to the
				      * solver.
				      */
    struct AdditionalData 
    {
					 /**
					  * Constructor. By default,
					  * set the number of
					  * temporary vectors to 30
					  * and preconditioning from
					  * left..
					  */
	AdditionalData(const unsigned int max_n_tmp_vectors = 30,
		       bool right_preconditioning = false)
			:
			max_n_tmp_vectors(max_n_tmp_vectors),
			right_preconditioning(right_preconditioning)
	  {};
	
					 /**
					  * Maximum number of
					  * tmp vectors.
					  */
	unsigned int    max_n_tmp_vectors;

					 /**
					  * Flag for right preconditioning.
					  */
	bool right_preconditioning;
    };
    
				     /**
				      * Constructor.
				      */
    SolverGMRES (SolverControl        &cn,
		 VectorMemory<VECTOR> &mem,
		 const AdditionalData &data=AdditionalData());

				     /**
				      * Solve the linear system $Ax=b$
				      * for x.
				      */
    template<class MATRIX, class PRECONDITIONER>
    void
    solve (const MATRIX         &A,
	   VECTOR               &x,
	   const VECTOR         &b,
	   const PRECONDITIONER &precondition);

    DeclException1 (ExcTooFewTmpVectors,
		    int,
		    << "The number of temporary vectors you gave ("
		    << arg1 << ") is too small. It should be at least 10 for "
		    << "any results, and much more for reasonable ones.");
    
  protected:
				     /**
				      * Includes the maximum number of
				      * tmp vectors.
{'fraction_non_alphanumeric': 0.09697028174450019, 'fraction_numerical': 0.0061752219220378235, 'mean_word_length': 2.508801624915369, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7471758', 'n_tokens_mistral': 3111, 'n_tokens_neox': 2627, 'n_words': 1228}