<commit_before>// $Id$

// The libMesh Finite Element Library.
// Copyright (C) 2002-2008 <NAME>, <NAME>, <NAME>
  
// This library is free software; you can 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.
  
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
  
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA



#ifndef __diff_solver_h__
#define __diff_solver_h__

// C++ includes
#include <vector>

// Local includes
#include "auto_ptr.h"
#include "libmesh_common.h"
#include "reference_counted_object.h"

namespace libMesh
{

// Forward Declarations
class DiffSolver;
class ImplicitSystem;
class ParameterVector;

/**
 * This is a generic class that defines a solver to handle
 * DifferentiableSystems  A user can define a solver by 
 * deriving from this class and implementing certain functions.
 *
 * This class is part of the new DifferentiableSystem framework,
 * which is still experimental.  Users of this framework should
 * beware of bugs and future API changes.
 *
 * @author <NAME> 2006
 */

// ------------------------------------------------------------
// Solver class definition
class DiffSolver : public ReferenceCountedObject<DiffSolver>
{
public:
  /**
   * The type of system
   */
  typedef ImplicitSystem sys_type;
  
  /**
   * Constructor. Requires a reference to the system
   * to be solved.
   */
  DiffSolver (sys_type& s);

  /**
   * Factory.  Requires a reference to the system
   * to be solved.  Returns a NewtonSolver by default
   */
  static AutoPtr<DiffSolver> build(sys_type& s);
  
  /**
   * Destructor.
   */
  virtual ~DiffSolver () {}

  /**
   * The initialization function.  This method is used to
   * initialize internal data structures before a simulation begins.
   */
  virtual void init ();

  /**
   * The reinitialization function.  This method is used after
   * changes in the mesh.
   */
  virtual void reinit ();

  /**
   * This method performs a solve.  What occurs in
   * this method will depend on the type of solver.  See
   * the subclasses for more details.  
   */
  virtual unsigned int solve () = 0;

  /**
   * @returns the number of "outer" (e.g. quasi-Newton) iterations
   * required by the last solve.
   */
  unsigned int total_outer_iterations() { return _outer_iterations; }

  /**
   * @returns the number of "inner" (e.g. Krylov) iterations
   * required by the last solve.
   */
  unsigned int total_inner_iterations() { return _inner_iterations; }

  /**
   * @returns the value of the SolveResult from the last solve.
   */
  unsigned int solve_result() { return _solve_result; }

  /**
   * @returns a constant reference to the system we are solving.
   */
  const sys_type & system () const { return _system; }

  /**
   * @returns a writeable reference to the system we are solving.
   */
  sys_type & system () { return _system; }
  
  /**
   * Each linear solver step should exit after \p max_linear_iterations
   * is exceeded.
   */
  unsigned int max_linear_iterations;

  /**
   * The DiffSolver should exit in failure if \p max_nonlinear_iterations
   * is exceeded and \p continue_after_max_iterations is false, or should
   * end the nonlinear solve if \p max_nonlinear_iterations is exceeded and \p
   * continue_after_max_iterations is true.
   */
  unsigned int max_nonlinear_iterations;

  /**
   * The DiffSolver should not print anything to libMesh::out
   * unless quiet is set to false
   */
  bool quiet;

  /**
   * Defaults to true, telling the DiffSolver to continue rather than exit when
   * a solve has reached its maximum number of nonlinear iterations.
   */
  bool continue_after_max_iterations;

  /**
   * Defaults to false, telling the DiffSolver to throw a libmesh_error() when
   * the backtracking scheme fails to find a descent direction.
   */
  bool continue_after_backtrack_failure;

  /**
   * The DiffSolver should exit after the residual is
   * reduced to either less than absolute_residual_tolerance
   * or less than relative_residual_tolerance times the
   * initial residual.
   *
   * Users should increase any of these tolerances that they want to use for a<commit_msg>Updated DiffSolver comments<commit_after>// $Id$

// The libMesh Finite Element Library.
// Copyright (C) 2002-2008 <NAME>, <NAME>, <NAME>
  
// This library is free software; you can 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.
  
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
  
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA



#ifndef __diff_solver_h__
#define __diff_solver_h__

// C++ includes
#include <vector>

// Local includes
#include "auto_ptr.h"
#include "libmesh_common.h"
#include "reference_counted_object.h"

namespace libMesh
{

// Forward Declarations
class DiffSolver;
class ImplicitSystem;
class ParameterVector;

/**
 * This is a generic class that defines a solver to handle
 * ImplicitSystem classes, including NonlinearImplicitSystem and
 * DifferentiableSystem   A user can define a solver by 
 * deriving from this class and implementing certain functions.
 *
 * This class is part of the new DifferentiableSystem framework,
 * which is still experimental.  Users of this framework should
 * beware of bugs and future API changes.
 *
 * @author <NAME> 2006-2010
 */

// ------------------------------------------------------------
// Solver class definition
class DiffSolver : public ReferenceCountedObject<DiffSolver>
{
public:
  /**
   * The type of system
   */
  typedef ImplicitSystem sys_type;
  
  /**
   * Constructor. Requires a reference to the system
   * to be solved.
   */
  DiffSolver (sys_type& s);

  /**
   * Factory.  Requires a reference to the system
   * to be solved.  Returns a NewtonSolver by default
   */
  static AutoPtr<DiffSolver> build(sys_type& s);
  
  /**
   * Destructor.
   */
  virtual ~DiffSolver () {}

  /**
   * The initialization function.  This method is used to
   * initialize internal data structures before a simulation begins.
   */
  virtual void init ();

  /**
   * The reinitialization function.  This method is used after
   * changes in the mesh.
   */
  virtual void reinit ();

  /**
   * This method performs a solve.  What occurs in
   * this method will depend on the type of solver.  See
   * the subclasses for more details.  
   */
  virtual unsigned int solve () = 0;

  /**
   * @returns the number of "outer" (e.g. quasi-Newton) iterations
   * required by the last solve.
   */
  unsigned int total_outer_iterations() { return _outer_iterations; }

  /**
   * @returns the number of "inner" (e.g. Krylov) iterations
   * required by the last solve.
   */
  unsigned int total_inner_iterations() { return _inner_iterations; }

  /**
   * @returns the value of the SolveResult from the last solve.
   */
  unsigned int solve_result() { return _solve_result; }

  /**
   * @returns a constant reference to the system we are solving.
   */
  const sys_type & system () const { return _system; }

  /**
   * @returns a writeable reference to the system we are solving.
   */
  sys_type & system () { return _system; }
  
  /**
   * Each linear solver step should exit after \p max_linear_iterations
   * is exceeded.
   */
  unsigned int max_linear_iterations;

  /**
   * The DiffSolver should exit in failure if \p max_nonlinear_iterations
   * is exceeded and \p continue_after_max_iterations is false, or should
   * end the nonlinear solve if \p max_nonlinear_iterations is exceeded and \p
   * continue_after_max_iterations is true.
   */
  unsigned int max_nonlinear_iterations;

  /**
   * The DiffSolver should not print anything to libMesh::out
   * unless quiet is set to false; default is true.
   */
  bool quiet;

  /**
   * Defaults to true, telling the DiffSolver to continue rather than exit when
   * a solve has reached its maximum number of nonlinear iterations.
   */
  bool continue_after_max_iterations;

  /**
   * Defaults to false, telling the DiffSolver to throw a libmesh_error() when
   * the backtracking scheme fails to find a descent direction.
   */
  bool continue_after_backtrack_failure;

  /**
   * The DiffSolver should exit after the residual is
   * reduced to either less than absolute_residual_tolerance
   * or less than relative_residual_tolerance times the
   * initial residual.
   *
   * Users should increase any of these tolerances that they want to use for a
{'fraction_non_alphanumeric': 0.09020234291799788, 'fraction_numerical': 0.006602768903088392, 'mean_word_length': 3.0270154373927958, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '3860101', 'n_tokens_mistral': 2726, 'n_tokens_neox': 2596, 'n_words': 1109}