<commit_before>// ---------------------------------------------------------------------
//
// Copyright (C) 1999 - 2017 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------

#ifndef dealii_solver_qmrs_h
#define dealii_solver_qmrs_h

#include <deal.II/base/config.h>
#include <deal.II/lac/solver.h>
#include <deal.II/lac/solver_control.h>
#include <deal.II/base/logstream.h>
#include <cmath>
#include <deal.II/base/subscriptor.h>

#include <cmath>

DEAL_II_NAMESPACE_OPEN

/*!@addtogroup Solvers */
/*@{*/

/**
 * <h3>Quasi-minimal method for symmetric matrices (SQMR)</h3>
 *
 * The SQMR (symmetric quasi-minimal residual) method is supposed to solve symmetric
 * indefinite linear systems with symmetric, not necessarily definite preconditioners.
 * It is a variant of the original quasi-minimal residual method (QMR) and produces
 * the same iterative solution. This version of SQMR is adapted from the respective
 * symmetric QMR-from-BiCG algorithm given by both Freund/Nachtigal: A new
 * Krylov-subspace method for symmetric indefinite linear systems, NASA STI/Recon
 * Technical Report N, 95 (1994) and Freund/Nachtigal: Software for simplified
 * Lanczos and QMR algorithms, Appl. Num. Math. 19 (1995), pp. 319-341 and provides
 * both right and left (but not split) preconditioning.
 *
 *
 * <h3>Trade off of stability to simplicity</h3>
 *
 * Note, that the QMR implementation that the given algorithm is based on is
 * derived from classical BiCG. It can be shown (Freund/Szeto: A transpose-free
 * quasi-minimal residual squared algorithm for non-Hermitian linear systems,
 * Advances in Computer Methods for Partial Differential Equations VII
 * (IMACS, New Brunswick, NJ, 1992) pp. 258-264) that the QMR iterates can
 * be generated from the BiCG iteration through one additional vector and
 * some scalar updates. Possible breakdowns (or precisely, divisions by
 * zero) of BiCG therefore obviously transfer to this simple no-look-ahead algorithm.
 *
 * In return the algorithm is cheap compared to classical QMR or BiCGStab,
 * using only one matrix-vector product with the system matrix and
 * one application of the preconditioner per iteration respectively.
 *
 * The residual used for measuring convergence is only approximately calculated
 * by an upper bound. If this value comes below a threshold prescribed within the
 * AdditionalData struct, then the exact residual of the current
 * QMR iterate will be calculated using another multiplication with the system
 * matrix. By experience (according to Freund and Nachtigal) this technique
 * is useful for a threshold that is ten times the solving tolerance, and in
 * that case will be only used in the last one or two steps of the complete iteration.
 *
 * For the requirements on matrices and vectors in order to work with this
 * class, see the documentation of the Solver base class.
 *
 * 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.
 *
 *
 * <h3>Observing the progress of linear solver iterations</h3>
 *
 * The solve() function of this class uses the mechanism described in the
 * Solver base class to determine convergence. This mechanism can also be used
 * to observe the progress of the iteration.
 *
 *
 * @author <NAME>, 1999; <NAME> 2017
 */
template <typename VectorType = Vector<double> >
class SolverQMRS : public Solver<VectorType>
{
public:
  /**
   * Standardized data struct to pipe additional data to the solver.
   *
   * The user is able to switch between right and left preconditioning, that means
   * solving the systems <i>P<sup>-1</sup>A</i> and <i>AP<sup>-1</sup></i> respectively,
   * using the corresponding parameter. Note that left preconditioning means to
   * employ the preconditioned (BiCG-)residual and otherwise the unpreconditioned one.
   * The default is the application from the right side.
   *
   * The @p solver_tolerance threshold is used to define the said bound below which the residual
   * is computed exactly. See the class documentation for more information. The default value is 1e-9,
   * that is the default solving precision multiplied by ten.
   *
   * SQMR is susceptible to breakdowns (divisions by zero), so we need a parameter telling us
   * which numbers are considered zero. The proper breakdown criterion is very
   * unclear, so experiments may be necessary here. It is even possible to achieve convergence
   * despite of dividing through by small numbers. There are even cases in which it is advantageous to
   * accept such divisions because the cheap iteration cost makes the algorithm the fastest of all
   * available indefinite iterative solvers. Nonetheless, the default breakdown threshold value is 1e-16.
   */
  struct AdditionalData
  {
    /**
     * Constructor.
     *
     * The default is right preconditioning, with the @p solver_tolerance chosen to be 1e-9 and the @p breakdown_threshold set at 1e-16.
     */
    explicit
    AdditionalData (const bool left_preconditioning = false,
                    const double solver_tolerance = 1.e-9,
                    const bool breakdown_testing = true,
                    const double breakdown_threshold = 1.e-16)
      :
      left_preconditioning (left_preconditioning),
      solver_tolerance (solver_tolerance),
      breakdown_testing (breakdown_testing),
      breakdown_threshold (breakdown_threshold)
    {
    }

    /**
     * Flag for using a left-preconditioned version.
     */<commit_msg>Tidy up some documentation<commit_after>// ---------------------------------------------------------------------
//
// Copyright (C) 1999 - 2017 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------

#ifndef dealii_solver_qmrs_h
#define dealii_solver_qmrs_h

#include <deal.II/base/config.h>
#include <deal.II/lac/solver.h>
#include <deal.II/lac/solver_control.h>
#include <deal.II/base/logstream.h>
#include <cmath>
#include <deal.II/base/subscriptor.h>

#include <cmath>

DEAL_II_NAMESPACE_OPEN

/*!@addtogroup Solvers */
/*@{*/

/**
 * <h3>Quasi-minimal method for symmetric matrices (SQMR)</h3>
 *
 * The SQMR (symmetric quasi-minimal residual) method is supposed to solve symmetric
 * indefinite linear systems with symmetric, not necessarily definite preconditioners.
 * It is a variant of the original quasi-minimal residual method (QMR) and produces
 * the same iterative solution. This version of SQMR is adapted from the respective
 * symmetric QMR-from-BiCG algorithm given by both Freund/Nachtigal: A new
 * Krylov-subspace method for symmetric indefinite linear systems, NASA STI/Recon
 * Technical Report N, 95 (1994) and Freund/Nachtigal: Software for simplified
 * Lanczos and QMR algorithms, Appl. Num. Math. 19 (1995), pp. 319-341 and provides
 * both right and left (but not split) preconditioning.
 *
 *
 * <h3>Trade off of stability to simplicity</h3>
 *
 * Note, that the QMR implementation that the given algorithm is based on is
 * derived from classical BiCG. It can be shown (Freund/Szeto: A transpose-free
 * quasi-minimal residual squared algorithm for non-Hermitian linear systems,
 * Advances in Computer Methods for Partial Differential Equations VII
 * (IMACS, New Brunswick, NJ, 1992) pp. 258-264) that the QMR iterates can
 * be generated from the BiCG iteration through one additional vector and
 * some scalar updates. Possible breakdowns (or precisely, divisions by
 * zero) of BiCG therefore obviously transfer to this simple no-look-ahead algorithm.
 *
 * In return the algorithm is cheap compared to classical QMR or BiCGStab,
 * using only one matrix-vector product with the system matrix and
 * one application of the preconditioner per iteration respectively.
 *
 * The residual used for measuring convergence is only approximately calculated
 * by an upper bound. If this value comes below a threshold prescribed within the
 * AdditionalData struct, then the exact residual of the current
 * QMR iterate will be calculated using another multiplication with the system
 * matrix. By experience (according to Freund and Nachtigal) this technique
 * is useful for a threshold that is ten times the solving tolerance, and in
 * that case will be only used in the last one or two steps of the complete iteration.
 *
 * For the requirements on matrices and vectors in order to work with this
 * class, see the documentation of the Solver base class.
 *
 * 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.
 *
 *
 * <h3>Observing the progress of linear solver iterations</h3>
 *
 * The solve() function of this class uses the mechanism described in the
 * Solver base class to determine convergence. This mechanism can also be used
 * to observe the progress of the iteration.
 *
 *
 * @author <NAME>, 1999; <NAME> 2017
 */
template <typename VectorType = Vector<double> >
class SolverQMRS : public Solver<VectorType>
{
public:
  /**
   * Standardized data struct to pipe additional data to the solver.
   *
   * The user is able to switch between right and left preconditioning, that means
   * solving the systems <i>P<sup>-1</sup>A</i> and <i>AP<sup>-1</sup></i> respectively,
   * using the corresponding parameter. Note that left preconditioning means to
   * employ the preconditioned (BiCG-)residual and otherwise the unpreconditioned one.
   * The default is the application from the right side.
   *
   * The @p solver_tolerance threshold is used to define the said bound below which the residual
   * is computed exactly. See the class documentation for more information. The default value is 1e-9,
   * that is the default solving precision multiplied by ten.
   *
   * SQMR is susceptible to breakdowns (divisions by zero), so we need a parameter telling us
   * which numbers are considered zero. The proper breakdown criterion is very
   * unclear, so experiments may be necessary here. It is even possible to achieve convergence
   * despite of dividing through by small numbers. There are even cases in which it is advantageous to
   * accept such divisions because the cheap iteration cost makes the algorithm the fastest of all
   * available indefinite iterative solvers. Nonetheless, the default breakdown threshold value is 1e-16.
   */
  struct AdditionalData
  {
    /**
     * Constructor.
     *
     * The default is right preconditioning, with the @p solver_tolerance chosen to be 1e-9 and 
     * the @p breakdown_threshold set at 1e-16.
     */
    explicit
    AdditionalData (const bool left_preconditioning = false,
                    const double solver_tolerance = 1.e-9,
                    const bool breakdown_testing = true,
                    const double breakdown_threshold = 1.e-16)
      :
      left_preconditioning (left_preconditioning),
      solver_tolerance (solver_tolerance),
      breakdown_testing (breakdown_testing),
      breakdown_threshold (breakdown_threshold)
    {
    }

    /**
     * Flag for using a left-preconditioned version.
     */
{'fraction_non_alphanumeric': 0.08448612739351309, 'fraction_numerical': 0.01078546307151231, 'mean_word_length': 3.339097999321804, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, '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': '3377277', 'n_tokens_mistral': 3469, 'n_tokens_neox': 3191, 'n_words': 1609}