<commit_before>//---------------------------------------------------------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 2008 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.
//
//---------------------------------------------------------------------------
#ifndef __deal2__trilinos_solver_h
#define __deal2__trilinos_solver_h

#include <base/config.h>
#include <lac/exceptions.h>
#include <lac/solver_control.h>
#include <boost/shared_ptr.hpp>


#ifdef DEAL_II_USE_TRILINOS

#include <Epetra_LinearProblem.h>
#include <AztecOO.h>
#include <Epetra_Operator.h>

DEAL_II_NAMESPACE_OPEN


namespace TrilinosWrappers
{
                                   // forward declarations
  class SparseMatrix;
  class VectorBase;
  class PreconditionBase;
  class PreconditionAMG;
  
  
/**
 * Base class for solver classes using the Trilinos solvers. Since
 * solvers in Trilinos are selected based on flags passed to a generic
 * solver object, basically all the actual solver calls happen in this
 * class, and derived classes simply set the right flags to select one
 * solver or another, or to set certain parameters for individual
 * solvers. For a general discussion on the Trilinos solver package
 * AztecOO, we refer to the <a href =
 * "http://trilinos.sandia.gov/packages/aztecoo/AztecOOUserGuide.pdf">AztecOO
 * user guide</a>.
 *
 * @ingroup TrilinosWrappers
 * @author <NAME>, 2008
 */
  class SolverBase
  {
    public:

                                       /**
                                        * Standardized data struct to
                                        * pipe additional data to the
                                        * solver.
                                        */
      struct AdditionalData
      {
				       /**
					* Restart parameter in case
					* the derived class is
					* GMRES.
					* 
					* TODO: Find a better way for
					* doing this.
					*/
	AdditionalData (const unsigned int gmres_restart_parameter = 30);

	const unsigned int gmres_restart_parameter;
      };

                                       /**
                                        * Constructor. Takes the
                                        * solver control object and
                                        * the MPI communicator over
                                        * which parallel computations
                                        * are to happen.
                                        */
      SolverBase (SolverControl  &cn);
      
                                       /**
                                        * Destructor.
                                        */
      virtual ~SolverBase ();

                                       /**
                                        * Solve the linear system
                                        * <tt>Ax=b</tt>. Depending on
                                        * the information provided by
                                        * derived classes and the
                                        * object passed as a
                                        * preconditioner, one of the
                                        * linear solvers and
                                        * preconditioners of Trilinos
                                        * is chosen.
                                        */
      void
      solve (const SparseMatrix     &A,
             VectorBase             &x,
             const VectorBase       &b,
             const PreconditionBase &preconditioner);

                                       /**
                                        * Solve the linear system
                                        * <tt>Ax=b</tt>. In contrast
                                        * to the other <tt>vmult</tt>
                                        * function, this solves the
                                        * system with an AMG
                                        * preconditioner.
                                        */
      void
      solve (const SparseMatrix     &A,
             VectorBase             &x,
             const VectorBase       &b,
             const PreconditionAMG  &preconditioner);

                                       /**
                                        * Access to object that controls
                                        * convergence.
                                        */
      SolverControl & control() const;

                                       /**
                                        * Exception
                                        */
      DeclException1 (ExcTrilinosError,
                      int,
                      << "An error with error number " << arg1
                      << " occured while calling a Trilinos function");

    protected:

                                       /**
                                        * Reference to the object that
                                        * controls convergence of the
                                        * iterative solver. In fact,
                                        * for these Trilinos wrappers,
                                        * Trilinos does so itself, but
                                        * we copy the data from this
                                        * object before starting the
                                        * solution process, and copy
                                        * the data back into it
                                        * afterwards.
                                        */
      SolverControl &solver_control;

				       /**
					* String object that is set in
					* the constructor of the
					* derived classes and tells
					* Trilinos which solver to
					* use. Currently enabled
					* options are <tt>"cg", "cgs",
					* "gmres", "bicgstab"</tt>,
					* and <tt>"tfqmr"</tt>.
					*/
      enum SolverName {cg, cgs, gmres, bicgstab, tfqmr} solver_name;

    private:

				       /**
					* Since we might need to call
					* the solver with different
					* types of preconditioners
					* (Ifpack, ML), we write an
					* additional function that
					* does the actual job, whereas
					* the public <tt>vmult</tt>
					* operations do call this
					* function with the respective
					* argument.
					*/
      void solve (const SparseMatrix     &A,
		  VectorBase             &x,
		  const VectorBase       &b,
		  const Epetra_Operator* preconditioner);

                                       /**
					* A structure that collects
					* the Trilinos sparse matrix,
					* the right hand side vector
					* and the solution vector,
					* which is passed down to the
					* Trilinos solver.
					*/
      std::auto_ptr<Epetra_LinearProblem> linear_problem;

                                       /**
                                        * A structure that contains
                                        * the Trilinos solver and
                                        * preconditioner objects.
                                        */
      AztecOO solver;

                                       /**
                                        * Store a copy of the flags for this
                                        * particular solver.
                                        */
      const AdditionalData additional_data;

  };



/**
 * An implementation of the solver interface using the Trilinos CG
 * solver.<commit_msg>Add one more file with generic preconditioner interfaces.<commit_after>//---------------------------------------------------------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 2008 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.
//
//---------------------------------------------------------------------------
#ifndef __deal2__trilinos_solver_h
#define __deal2__trilinos_solver_h

#include <base/config.h>
#include <lac/exceptions.h>
#include <lac/solver_control.h>
#include <boost/shared_ptr.hpp>


#ifdef DEAL_II_USE_TRILINOS

#include <Epetra_LinearProblem.h>
#include <AztecOO.h>
#include <Epetra_Operator.h>

DEAL_II_NAMESPACE_OPEN


namespace TrilinosWrappers
{
                                   // forward declarations
  class SparseMatrix;
  class VectorBase;
  class PreconditionBase;
  
  
/**
 * Base class for solver classes using the Trilinos solvers. Since
 * solvers in Trilinos are selected based on flags passed to a generic
 * solver object, basically all the actual solver calls happen in this
 * class, and derived classes simply set the right flags to select one
 * solver or another, or to set certain parameters for individual
 * solvers. For a general discussion on the Trilinos solver package
 * AztecOO, we refer to the <a href =
 * "http://trilinos.sandia.gov/packages/aztecoo/AztecOOUserGuide.pdf">AztecOO
 * user guide</a>.
 *
 * @ingroup TrilinosWrappers
 * @author <NAME>, 2008
 */
  class SolverBase
  {
    public:

                                       /**
                                        * Standardized data struct to
                                        * pipe additional data to the
                                        * solver.
                                        */
      struct AdditionalData
      {
				       /**
					* Restart parameter in case
					* the derived class is
					* GMRES.
					* 
					* TODO: Find a better way for
					* doing this.
					*/
	AdditionalData (const unsigned int gmres_restart_parameter = 30);

	const unsigned int gmres_restart_parameter;
      };

                                       /**
                                        * Constructor. Takes the
                                        * solver control object and
                                        * the MPI communicator over
                                        * which parallel computations
                                        * are to happen.
                                        */
      SolverBase (SolverControl  &cn);
      
                                       /**
                                        * Destructor.
                                        */
      virtual ~SolverBase ();

                                       /**
                                        * Solve the linear system
                                        * <tt>Ax=b</tt>. Depending on
                                        * the information provided by
                                        * derived classes and the
                                        * object passed as a
                                        * preconditioner, one of the
                                        * linear solvers and
                                        * preconditioners of Trilinos
                                        * is chosen.
                                        */
      void
      solve (const SparseMatrix     &A,
             VectorBase             &x,
             const VectorBase       &b,
             const PreconditionBase &preconditioner);

                                       /**
                                        * Access to object that controls
                                        * convergence.
                                        */
      SolverControl & control() const;

                                       /**
                                        * Exception
                                        */
      DeclException1 (ExcTrilinosError,
                      int,
                      << "An error with error number " << arg1
                      << " occured while calling a Trilinos function");

    protected:

                                       /**
                                        * Reference to the object that
                                        * controls convergence of the
                                        * iterative solver. In fact,
                                        * for these Trilinos wrappers,
                                        * Trilinos does so itself, but
                                        * we copy the data from this
                                        * object before starting the
                                        * solution process, and copy
                                        * the data back into it
                                        * afterwards.
                                        */
      SolverControl &solver_control;

				       /**
					* String object that is set in
					* the constructor of the
					* derived classes and tells
					* Trilinos which solver to
					* use. Currently enabled
					* options are <tt>"cg", "cgs",
					* "gmres", "bicgstab"</tt>,
					* and <tt>"tfqmr"</tt>.
					*/
      enum SolverName {cg, cgs, gmres, bicgstab, tfqmr} solver_name;

    private:

                                       /**
					* A structure that collects
					* the Trilinos sparse matrix,
					* the right hand side vector
					* and the solution vector,
					* which is passed down to the
					* Trilinos solver.
					*/
      std::auto_ptr<Epetra_LinearProblem> linear_problem;

                                       /**
                                        * A structure that contains
                                        * the Trilinos solver and
                                        * preconditioner objects.
                                        */
      AztecOO solver;

                                       /**
                                        * Store a copy of the flags for this
                                        * particular solver.
                                        */
      const AdditionalData additional_data;

  };



/**
 * An implementation of the solver interface using the Trilinos CG
 * solver.
{'fraction_non_alphanumeric': 0.078665161563426, 'fraction_numerical': 0.0019754480033864824, 'mean_word_length': 0.8656225322453277, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 198, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5438423', 'n_tokens_mistral': 3140, 'n_tokens_neox': 2708, 'n_words': 958}