libMesh
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | List of all members
libMesh::PetscDiffSolver Class Reference

This class defines a solver which uses a PETSc SNES context to handle a DifferentiableSystem. More...

#include <petsc_diff_solver.h>

Inheritance diagram for libMesh::PetscDiffSolver:
[legend]

Public Types

typedef DiffSolver Parent
 
enum  SolveResult {
  INVALID_SOLVE_RESULT = 0, CONVERGED_NO_REASON = 1, CONVERGED_ABSOLUTE_RESIDUAL = 2, CONVERGED_RELATIVE_RESIDUAL = 4,
  CONVERGED_ABSOLUTE_STEP = 8, CONVERGED_RELATIVE_STEP = 16, DIVERGED_NO_REASON = 32, DIVERGED_MAX_NONLINEAR_ITERATIONS = 64,
  DIVERGED_BACKTRACKING_FAILURE = 128, DIVERGED_LINEAR_SOLVER_FAILURE = 256
}
 Enumeration return type for the solve() function. More...
 
typedef ImplicitSystem sys_type
 The type of system. More...
 

Public Member Functions

 PetscDiffSolver (sys_type &system)
 Constructor. More...
 
virtual ~PetscDiffSolver ()
 Destructor. More...
 
virtual void reinit () override
 The reinitialization function. More...
 
virtual void init () override
 The initialization function. More...
 
void clear ()
 The clear function. More...
 
virtual unsigned int solve () override
 This method performs a solve. More...
 
unsigned int total_outer_iterations ()
 
unsigned int total_inner_iterations ()
 
unsigned int solve_result ()
 
const sys_typesystem () const
 
sys_typesystem ()
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static std::unique_ptr< DiffSolverbuild (sys_type &s)
 Factory method. More...
 
static std::string get_info ()
 Gets a string containing the reference information. More...
 
static void print_info (std::ostream &out=libMesh::out)
 Prints the reference information, by default to libMesh::out. More...
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects. More...
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info() More...
 
static void disable_print_counter_info ()
 

Public Attributes

unsigned int max_linear_iterations
 Each linear solver step should exit after max_linear_iterations is exceeded. More...
 
unsigned int max_nonlinear_iterations
 The DiffSolver should exit in failure if max_nonlinear_iterations is exceeded and continue_after_max_iterations is false, or should end the nonlinear solve if max_nonlinear_iterations is exceeded and continue_after_max_iterations is true. More...
 
bool quiet
 The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is true. More...
 
bool verbose
 The DiffSolver may print a lot more to libMesh::out if verbose is set to true; default is false. More...
 
bool continue_after_max_iterations
 Defaults to true, telling the DiffSolver to continue rather than exit when a solve has reached its maximum number of nonlinear iterations. More...
 
bool continue_after_backtrack_failure
 Defaults to false, telling the DiffSolver to throw an error when the backtracking scheme fails to find a descent direction. More...
 
Real absolute_residual_tolerance
 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. More...
 
Real relative_residual_tolerance
 
Real absolute_step_tolerance
 The DiffSolver should exit after the full nonlinear step norm is reduced to either less than absolute_step_tolerance or less than relative_step_tolerance times the largest nonlinear solution which has been seen so far. More...
 
Real relative_step_tolerance
 
Real initial_linear_tolerance
 Any required linear solves will at first be done with this tolerance; the DiffSolver may tighten the tolerance for later solves. More...
 
Real minimum_linear_tolerance
 The tolerance for linear solves is kept above this minimum. More...
 
std::unique_ptr< LinearSolutionMonitorlinear_solution_monitor
 Pointer to functor which is called right after each linear solve. More...
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 Data structure to log the information. More...
 

Protected Member Functions

void increment_constructor_count (const std::string &name)
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name)
 Increments the destruction counter. More...
 

Protected Attributes

SNES _snes
 Nonlinear solver context. More...
 
PetscDMWrapper _dm_wrapper
 Wrapper object for interacting with PetscDM. More...
 
Real max_solution_norm
 The largest solution norm which the DiffSolver has yet seen will be stored here, to be used for stopping criteria based on relative_step_tolerance. More...
 
Real max_residual_norm
 The largest nonlinear residual which the DiffSolver has yet seen will be stored here, to be used for stopping criteria based on relative_residual_tolerance. More...
 
unsigned int _outer_iterations
 The number of outer iterations used by the last solve. More...
 
unsigned int _inner_iterations
 The number of inner iterations used by the last solve. More...
 
sys_type_system
 A reference to the system we are solving. More...
 
unsigned int _solve_result
 Initialized to zero. More...
 
const Parallel::Communicator_communicator
 

Static Protected Attributes

static Counts _counts
 Actually holds the data. More...
 
static Threads::atomic< unsigned int > _n_objects
 The number of objects. More...
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting. More...
 
static bool _enable_print_counter
 Flag to control whether reference count information is printed when print_info is called. More...
 

Private Member Functions

void setup_petsc_data ()
 Common helper function to setup PETSc data structures. More...
 

Detailed Description

This class defines a solver which uses a PETSc SNES context to handle a DifferentiableSystem.

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
Roy H. Stogner
Date
2008

Definition at line 49 of file petsc_diff_solver.h.

Member Typedef Documentation

◆ Counts

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information.

The log is identified by the class name.

Definition at line 117 of file reference_counter.h.

◆ Parent

Definition at line 64 of file petsc_diff_solver.h.

◆ sys_type

The type of system.

Definition at line 78 of file diff_solver.h.

Member Enumeration Documentation

◆ SolveResult

Enumeration return type for the solve() function.

Multiple SolveResults may be combined (OR'd) in the single return. To test which ones are present, just AND the return value with any of the SolveResult flags defined below.

Enumerator
INVALID_SOLVE_RESULT 

A default or invalid solve result.

This usually means no solve has occurred yet.

CONVERGED_NO_REASON 

The solver converged but no particular reason is specified.

CONVERGED_ABSOLUTE_RESIDUAL 

The DiffSolver achieved the desired absolute residual tolerance.

CONVERGED_RELATIVE_RESIDUAL 

The DiffSolver achieved the desired relative residual tolerance.

CONVERGED_ABSOLUTE_STEP 

The DiffSolver achieved the desired absolute step size tolerance.

CONVERGED_RELATIVE_STEP 

The DiffSolver achieved the desired relative step size tolerance.

DIVERGED_NO_REASON 

The DiffSolver diverged but no particular reason is specified.

DIVERGED_MAX_NONLINEAR_ITERATIONS 

The DiffSolver reached the maximum allowed number of nonlinear iterations before satisfying any convergence tests.

DIVERGED_BACKTRACKING_FAILURE 

The DiffSolver failed to find a descent direction by backtracking (See newton_solver.C)

DIVERGED_LINEAR_SOLVER_FAILURE 

The linear solver used by the DiffSolver failed to find a solution.

Definition at line 223 of file diff_solver.h.

223  {
229 
235 
241 
247 
253 
259 
264  DIVERGED_NO_REASON = 32,
265 
272 
278 
284  };
The DiffSolver achieved the desired absolute step size tolerance.
Definition: diff_solver.h:252
The linear solver used by the DiffSolver failed to find a solution.
Definition: diff_solver.h:283
The DiffSolver reached the maximum allowed number of nonlinear iterations before satisfying any conve...
Definition: diff_solver.h:271
The DiffSolver achieved the desired relative step size tolerance.
Definition: diff_solver.h:258
The DiffSolver achieved the desired relative residual tolerance.
Definition: diff_solver.h:246
The solver converged but no particular reason is specified.
Definition: diff_solver.h:234
The DiffSolver achieved the desired absolute residual tolerance.
Definition: diff_solver.h:240
The DiffSolver failed to find a descent direction by backtracking (See newton_solver.C)
Definition: diff_solver.h:277
The DiffSolver diverged but no particular reason is specified.
Definition: diff_solver.h:264
A default or invalid solve result.
Definition: diff_solver.h:228

Constructor & Destructor Documentation

◆ PetscDiffSolver()

libMesh::PetscDiffSolver::PetscDiffSolver ( sys_type system)
explicit

Constructor.

Requires a reference to the system to be solved.

◆ ~PetscDiffSolver()

virtual libMesh::PetscDiffSolver::~PetscDiffSolver ( )
virtual

Destructor.

Member Function Documentation

◆ build()

static std::unique_ptr<DiffSolver> libMesh::DiffSolver::build ( sys_type s)
staticinherited

Factory method.

Requires a reference to the system to be solved.

Returns
A NewtonSolver by default.

◆ clear()

void libMesh::PetscDiffSolver::clear ( )

The clear function.

Called if we reinit or when we destroy this object.

◆ comm()

const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inherited

◆ disable_print_counter_info()

static void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

◆ enable_print_counter_info()

static void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

◆ get_info()

static std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

◆ increment_constructor_count()

void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
protectedinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

Definition at line 181 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

182 {
183  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
184  std::pair<unsigned int, unsigned int> & p = _counts[name];
185 
186  p.first++;
187 }
std::string name(const ElemQuality q)
static Counts _counts
Actually holds the data.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.

◆ increment_destructor_count()

void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
protectedinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

Definition at line 194 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

195 {
196  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
197  std::pair<unsigned int, unsigned int> & p = _counts[name];
198 
199  p.second++;
200 }
std::string name(const ElemQuality q)
static Counts _counts
Actually holds the data.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.

◆ init()

virtual void libMesh::PetscDiffSolver::init ( )
overridevirtual

The initialization function.

Reimplemented from libMesh::DiffSolver.

◆ n_objects()

static unsigned int libMesh::ReferenceCounter::n_objects ( )
staticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 83 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

84  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.

◆ n_processors()

processor_id_type libMesh::ParallelObject::n_processors ( ) const
inherited
Returns
The number of processors in the group.

Definition at line 93 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::size().

Referenced by libMesh::MeshBase::partition().

94  { return cast_int<processor_id_type>(_communicator.size()); }
processor_id_type size() const
Definition: communicator.h:175
const Parallel::Communicator & _communicator

◆ print_info()

static void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

◆ processor_id()

processor_id_type libMesh::ParallelObject::processor_id ( ) const
inherited

◆ reinit()

virtual void libMesh::PetscDiffSolver::reinit ( )
overridevirtual

The reinitialization function.

This method is used after changes in the mesh.

Reimplemented from libMesh::DiffSolver.

◆ setup_petsc_data()

void libMesh::PetscDiffSolver::setup_petsc_data ( )
private

Common helper function to setup PETSc data structures.

◆ solve()

virtual unsigned int libMesh::PetscDiffSolver::solve ( )
overridevirtual

This method performs a solve.

What occurs in this method will depend on the PETSc SNES settings. See the PETSc documentation for more details.

Implements libMesh::DiffSolver.

◆ solve_result()

unsigned int libMesh::DiffSolver::solve_result ( )
inherited
Returns
The value of the SolveResult from the last solve.

Definition at line 133 of file diff_solver.h.

References libMesh::DiffSolver::_solve_result.

133 { return _solve_result; }
unsigned int _solve_result
Initialized to zero.
Definition: diff_solver.h:327

◆ system() [1/2]

const sys_type& libMesh::DiffSolver::system ( ) const
inherited
Returns
A constant reference to the system we are solving.

Definition at line 138 of file diff_solver.h.

References libMesh::DiffSolver::_system.

138 { return _system; }
sys_type & _system
A reference to the system we are solving.
Definition: diff_solver.h:319

◆ system() [2/2]

sys_type& libMesh::DiffSolver::system ( )
inherited
Returns
A writable reference to the system we are solving.

Definition at line 143 of file diff_solver.h.

References libMesh::DiffSolver::_system.

143 { return _system; }
sys_type & _system
A reference to the system we are solving.
Definition: diff_solver.h:319

◆ total_inner_iterations()

unsigned int libMesh::DiffSolver::total_inner_iterations ( )
inherited
Returns
The number of "inner" (e.g. Krylov) iterations required by the last solve.

Definition at line 128 of file diff_solver.h.

References libMesh::DiffSolver::_inner_iterations.

128 { return _inner_iterations; }
unsigned int _inner_iterations
The number of inner iterations used by the last solve.
Definition: diff_solver.h:314

◆ total_outer_iterations()

unsigned int libMesh::DiffSolver::total_outer_iterations ( )
inherited
Returns
The number of "outer" (e.g. quasi-Newton) iterations required by the last solve.

Definition at line 122 of file diff_solver.h.

References libMesh::DiffSolver::_outer_iterations.

122 { return _outer_iterations; }
unsigned int _outer_iterations
The number of outer iterations used by the last solve.
Definition: diff_solver.h:309

Member Data Documentation

◆ _communicator

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited

◆ _counts

Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

◆ _dm_wrapper

PetscDMWrapper libMesh::PetscDiffSolver::_dm_wrapper
protected

Wrapper object for interacting with PetscDM.

Definition at line 99 of file petsc_diff_solver.h.

◆ _enable_print_counter

bool libMesh::ReferenceCounter::_enable_print_counter
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

Definition at line 141 of file reference_counter.h.

◆ _inner_iterations

unsigned int libMesh::DiffSolver::_inner_iterations
protectedinherited

The number of inner iterations used by the last solve.

Definition at line 314 of file diff_solver.h.

Referenced by libMesh::DiffSolver::total_inner_iterations().

◆ _mutex

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 135 of file reference_counter.h.

◆ _n_objects

Threads::atomic<unsigned int> libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects.

Print the reference count information when the number returns to 0.

Definition at line 130 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter(), and libMesh::ReferenceCounter::~ReferenceCounter().

◆ _outer_iterations

unsigned int libMesh::DiffSolver::_outer_iterations
protectedinherited

The number of outer iterations used by the last solve.

Definition at line 309 of file diff_solver.h.

Referenced by libMesh::DiffSolver::total_outer_iterations().

◆ _snes

SNES libMesh::PetscDiffSolver::_snes
protected

Nonlinear solver context.

Definition at line 94 of file petsc_diff_solver.h.

◆ _solve_result

unsigned int libMesh::DiffSolver::_solve_result
protectedinherited

Initialized to zero.

solve_result is typically set internally in the solve() function before it returns. When non-zero, solve_result tells the result of the latest solve. See enum definition for description.

Definition at line 327 of file diff_solver.h.

Referenced by libMesh::DiffSolver::solve_result().

◆ _system

sys_type& libMesh::DiffSolver::_system
protectedinherited

A reference to the system we are solving.

Definition at line 319 of file diff_solver.h.

Referenced by libMesh::DiffSolver::system().

◆ absolute_residual_tolerance

Real libMesh::DiffSolver::absolute_residual_tolerance
inherited

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 stopping condition.

Definition at line 192 of file diff_solver.h.

Referenced by TimeSolverTestImplementation< TimeSolverType >::run_test_with_exact_soln().

◆ absolute_step_tolerance

Real libMesh::DiffSolver::absolute_step_tolerance
inherited

The DiffSolver should exit after the full nonlinear step norm is reduced to either less than absolute_step_tolerance or less than relative_step_tolerance times the largest nonlinear solution which has been seen so far.

Users should increase any of these tolerances that they want to use for a stopping condition.

Definition at line 204 of file diff_solver.h.

◆ continue_after_backtrack_failure

bool libMesh::DiffSolver::continue_after_backtrack_failure
inherited

Defaults to false, telling the DiffSolver to throw an error when the backtracking scheme fails to find a descent direction.

Definition at line 181 of file diff_solver.h.

◆ continue_after_max_iterations

bool libMesh::DiffSolver::continue_after_max_iterations
inherited

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

Definition at line 175 of file diff_solver.h.

◆ initial_linear_tolerance

Real libMesh::DiffSolver::initial_linear_tolerance
inherited

Any required linear solves will at first be done with this tolerance; the DiffSolver may tighten the tolerance for later solves.

Definition at line 211 of file diff_solver.h.

◆ linear_solution_monitor

std::unique_ptr<LinearSolutionMonitor> libMesh::DiffSolver::linear_solution_monitor
inherited

Pointer to functor which is called right after each linear solve.

Definition at line 289 of file diff_solver.h.

◆ max_linear_iterations

unsigned int libMesh::DiffSolver::max_linear_iterations
inherited

Each linear solver step should exit after max_linear_iterations is exceeded.

Definition at line 149 of file diff_solver.h.

◆ max_nonlinear_iterations

unsigned int libMesh::DiffSolver::max_nonlinear_iterations
inherited

The DiffSolver should exit in failure if max_nonlinear_iterations is exceeded and continue_after_max_iterations is false, or should end the nonlinear solve if max_nonlinear_iterations is exceeded and continue_after_max_iterations is true.

Definition at line 157 of file diff_solver.h.

◆ max_residual_norm

Real libMesh::DiffSolver::max_residual_norm
protectedinherited

The largest nonlinear residual which the DiffSolver has yet seen will be stored here, to be used for stopping criteria based on relative_residual_tolerance.

Definition at line 304 of file diff_solver.h.

◆ max_solution_norm

Real libMesh::DiffSolver::max_solution_norm
protectedinherited

The largest solution norm which the DiffSolver has yet seen will be stored here, to be used for stopping criteria based on relative_step_tolerance.

Definition at line 297 of file diff_solver.h.

◆ minimum_linear_tolerance

Real libMesh::DiffSolver::minimum_linear_tolerance
inherited

The tolerance for linear solves is kept above this minimum.

Definition at line 216 of file diff_solver.h.

◆ quiet

bool libMesh::DiffSolver::quiet
inherited

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

Definition at line 163 of file diff_solver.h.

◆ relative_residual_tolerance

Real libMesh::DiffSolver::relative_residual_tolerance
inherited

◆ relative_step_tolerance

Real libMesh::DiffSolver::relative_step_tolerance
inherited

◆ verbose

bool libMesh::DiffSolver::verbose
inherited

The DiffSolver may print a lot more to libMesh::out if verbose is set to true; default is false.

Definition at line 169 of file diff_solver.h.


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