libMesh::NewtonSolver Class Reference

#include <newton_solver.h>

Inheritance diagram for libMesh::NewtonSolver:

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
}
 
typedef ImplicitSystem sys_type
 

Public Member Functions

 NewtonSolver (sys_type &system)
 
virtual ~NewtonSolver ()
 
virtual void reinit ()
 
virtual unsigned int solve ()
 
virtual void init ()
 
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 AutoPtr< DiffSolverbuild (sys_type &s)
 
static std::string get_info ()
 
static void print_info (std::ostream &out=libMesh::out)
 
static unsigned int n_objects ()
 
static void enable_print_counter_info ()
 
static void disable_print_counter_info ()
 

Public Attributes

bool require_residual_reduction
 
bool require_finite_residual
 
bool brent_line_search
 
Real minsteplength
 
Real linear_tolerance_multiplier
 
unsigned int max_linear_iterations
 
unsigned int max_nonlinear_iterations
 
bool quiet
 
bool verbose
 
bool continue_after_max_iterations
 
bool continue_after_backtrack_failure
 
Real absolute_residual_tolerance
 
Real relative_residual_tolerance
 
Real absolute_step_tolerance
 
Real relative_step_tolerance
 
Real initial_linear_tolerance
 
Real minimum_linear_tolerance
 
AutoPtr< LinearSolutionMonitorlinear_solution_monitor
 

Protected Types

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

Protected Member Functions

Real line_search (Real tol, Real last_residual, Real &current_residual, NumericVector< Number > &newton_iterate, const NumericVector< Number > &linear_solution)
 
void print_convergence (unsigned int step_num, Real current_residual, Real step_norm, bool linear_solve_finished)
 
bool test_convergence (Real current_residual, Real step_norm, bool linear_solve_finished)
 
void increment_constructor_count (const std::string &name)
 
void increment_destructor_count (const std::string &name)
 

Protected Attributes

AutoPtr< LinearSolver< Number > > linear_solver
 
Real max_solution_norm
 
Real max_residual_norm
 
unsigned int _outer_iterations
 
unsigned int _inner_iterations
 
sys_type_system
 
unsigned int _solve_result
 
const Parallel::Communicator_communicator
 

Static Protected Attributes

static Counts _counts
 
static Threads::atomic
< unsigned int > 
_n_objects
 
static Threads::spin_mutex _mutex
 
static bool _enable_print_counter = true
 

Detailed Description

This class defines a solver which uses the default libMesh linear solver in a quasiNewton method 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 2006

Definition at line 48 of file newton_solver.h.

Member Typedef Documentation

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 113 of file reference_counter.h.

Definition at line 63 of file newton_solver.h.

The type of system

Definition at line 77 of file diff_solver.h.

Member Enumeration Documentation

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)

Definition at line 220 of file diff_solver.h.

220  {
226 
232 
238 
244 
250 
256 
261  DIVERGED_NO_REASON = 32,
262 
269 
275  };

Constructor & Destructor Documentation

libMesh::NewtonSolver::NewtonSolver ( sys_type system)
explicit

Constructor. Requires a reference to the system to be solved.

Definition at line 232 of file newton_solver.C.

233  : Parent(s),
236  brent_line_search(true),
237  minsteplength(1e-5),
240 {
241 }
libMesh::NewtonSolver::~NewtonSolver ( )
virtual

Destructor.

Definition at line 245 of file newton_solver.C.

246 {
247 }

Member Function Documentation

AutoPtr< DiffSolver > libMesh::DiffSolver::build ( sys_type s)
staticinherited

Factory. Requires a reference to the system to be solved. Returns a NewtonSolver by default

Definition at line 51 of file diff_solver.C.

Referenced by libMesh::TimeSolver::init().

52 {
53  return AutoPtr<DiffSolver>(new NewtonSolver(s));
54 }
const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inlineinherited
Returns
a reference to the Parallel::Communicator object used by this mesh.

Definition at line 86 of file parallel_object.h.

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_petsc_snes_jacobian(), libMesh::__libmesh_petsc_snes_residual(), libMesh::MeshRefinement::_coarsen_elements(), libMesh::ExactSolution::_compute_error(), libMesh::MetisPartitioner::_do_partition(), libMesh::ParmetisPartitioner::_do_repartition(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), libMesh::EquationSystems::_read_impl(), libMesh::MeshRefinement::_refine_elements(), libMesh::ParallelMesh::add_elem(), libMesh::ImplicitSystem::add_matrix(), libMesh::ParallelMesh::add_node(), libMesh::System::add_vector(), libMesh::UnstructuredMesh::all_second_order(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::DofMap::attach_matrix(), libMesh::MeshTools::bounding_box(), libMesh::System::calculate_norm(), libMesh::MeshRefinement::coarsen_elements(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMLibMeshSetSystem(), DMVariableBounds_libMesh(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::for(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::LocationMap< T >::init(), libMesh::PetscDiffSolver::init(), libMesh::TimeSolver::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ParmetisPartitioner::initialize(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::ParallelMesh::libmesh_assert_valid_parallel_flags(), libMesh::MeshTools::libmesh_assert_valid_procids< Elem >(), libMesh::MeshTools::libmesh_assert_valid_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshRefinement::make_flags_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::FEMSystem::mesh_position_set(), libMesh::MeshSerializer::MeshSerializer(), libMesh::ParallelMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::MeshTools::n_levels(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::MeshTools::n_p_levels(), libMesh::ParallelMesh::parallel_max_elem_id(), libMesh::ParallelMesh::parallel_max_node_id(), libMesh::ParallelMesh::parallel_n_elem(), libMesh::ParallelMesh::parallel_n_nodes(), libMesh::Partitioner::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::System::project_vector(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshRefinement::refine_and_coarsen_elements(), libMesh::MeshRefinement::refine_elements(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::Parallel::sync_element_data_by_parent_id(), libMesh::MeshRefinement::test_level_one(), libMesh::MeshRefinement::test_unflagged(), libMesh::MeshTools::total_weight(), libMesh::CheckpointIO::write(), libMesh::XdrIO::write(), libMesh::UnstructuredMesh::write(), libMesh::LegacyXdrIO::write_mesh(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), and libMesh::DivaIO::write_stream().

87  { return _communicator; }
void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 106 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

107 {
108  _enable_print_counter = false;
109  return;
110 }
void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

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

Definition at line 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

101 {
102  _enable_print_counter = true;
103  return;
104 }
std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

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

Referenced by libMesh::ReferenceCounter::print_info().

48 {
49 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50 
51  std::ostringstream oss;
52 
53  oss << '\n'
54  << " ---------------------------------------------------------------------------- \n"
55  << "| Reference count information |\n"
56  << " ---------------------------------------------------------------------------- \n";
57 
58  for (Counts::iterator it = _counts.begin();
59  it != _counts.end(); ++it)
60  {
61  const std::string name(it->first);
62  const unsigned int creations = it->second.first;
63  const unsigned int destructions = it->second.second;
64 
65  oss << "| " << name << " reference count information:\n"
66  << "| Creations: " << creations << '\n'
67  << "| Destructions: " << destructions << '\n';
68  }
69 
70  oss << " ---------------------------------------------------------------------------- \n";
71 
72  return oss.str();
73 
74 #else
75 
76  return "";
77 
78 #endif
79 }
void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectedinherited

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

Definition at line 163 of file reference_counter.h.

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

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

164 {
165  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
166  std::pair<unsigned int, unsigned int>& p = _counts[name];
167 
168  p.first++;
169 }
void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectedinherited

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

Definition at line 176 of file reference_counter.h.

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

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

177 {
178  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
179  std::pair<unsigned int, unsigned int>& p = _counts[name];
180 
181  p.second++;
182 }
void libMesh::DiffSolver::init ( )
virtualinherited

The initialization function. This method is used to initialize internal data structures before a simulation begins.

Reimplemented in libMesh::PetscDiffSolver.

Definition at line 67 of file diff_solver.C.

References libMesh::DiffSolver::max_residual_norm, and libMesh::DiffSolver::max_solution_norm.

Referenced by libMesh::PetscDiffSolver::init().

68 {
69  // Reset the max_step_size and max_residual_norm for a new problem
70  max_solution_norm = 0.;
71  max_residual_norm = 0.;
72 }
Real libMesh::NewtonSolver::line_search ( Real  tol,
Real  last_residual,
Real current_residual,
NumericVector< Number > &  newton_iterate,
const NumericVector< Number > &  linear_solution 
)
protected

This does a line search in the direction opposite linear_solution to try and minimize the residual of newton_iterate. newton_iterate is moved to the end of the quasiNewton step, and the return value is the substep size.

Definition at line 38 of file newton_solver.C.

References libMesh::DiffSolver::_outer_iterations, libMesh::DiffSolver::_solve_result, libMesh::DiffSolver::_system, std::abs(), libMesh::NumericVector< T >::add(), libMesh::ImplicitSystem::assembly(), brent_line_search, libMesh::NumericVector< T >::close(), libMesh::DiffSolver::continue_after_backtrack_failure, libMesh::DiffSolver::DIVERGED_BACKTRACKING_FAILURE, libMesh::NumericVector< T >::l2_norm(), libMesh::libmesh_isnan(), std::max(), std::min(), minsteplength, libMesh::out, libMesh::DiffSolver::quiet, libMesh::Real, require_finite_residual, require_residual_reduction, libMesh::ExplicitSystem::rhs, libMesh::SIGN(), and libMesh::DiffSolver::verbose.

Referenced by solve().

43 {
44  // Take a full step if we got a residual reduction or if we
45  // aren't substepping
46  if ((current_residual < last_residual) ||
48  (!require_finite_residual || !libmesh_isnan(current_residual))))
49  return 1.;
50 
51  // The residual vector
52  NumericVector<Number> &rhs = *(_system.rhs);
53 
54  Real ax = 0.; // First abscissa, don't take negative steps
55  Real cx = 1.; // Second abscissa, don't extrapolate steps
56 
57  // Find bx, a step length that gives lower residual than ax or cx
58  Real bx = 1.;
59 
60  while (libmesh_isnan(current_residual) ||
61  (current_residual > last_residual &&
63  {
64  // Reduce step size to 1/2, 1/4, etc.
65  Real substepdivision;
66  if (brent_line_search && !libmesh_isnan(current_residual))
67  {
68  substepdivision = std::min(0.5, last_residual/current_residual);
69  substepdivision = std::max(substepdivision, tol*2.);
70  }
71  else
72  substepdivision = 0.5;
73 
74  newton_iterate.add (bx * (1.-substepdivision),
75  linear_solution);
76  newton_iterate.close();
77  bx *= substepdivision;
78  if (verbose)
79  libMesh::out << " Shrinking Newton step to "
80  << bx << std::endl;
81 
82  // Check residual with fractional Newton step
83  _system.assembly (true, false);
84 
85  rhs.close();
86  current_residual = rhs.l2_norm();
87  if (verbose)
88  libMesh::out << " Current Residual: "
89  << current_residual << std::endl;
90 
91  if (bx/2. < minsteplength &&
92  (libmesh_isnan(current_residual) ||
93  (current_residual > last_residual)))
94  {
95  libMesh::out << "Inexact Newton step FAILED at step "
96  << _outer_iterations << std::endl;
97 
99  {
100  libmesh_convergence_failure();
101  }
102  else
103  {
104  libMesh::out << "Continuing anyway ..." << std::endl;
106  return bx;
107  }
108  }
109  } // end while (current_residual > last_residual)
110 
111  // Now return that reduced-residual step, or use Brent's method to
112  // find a more optimal step.
113 
114  if (!brent_line_search)
115  return bx;
116 
117  // Brent's method adapted from Numerical Recipes in C, ch. 10.2
118  Real e = 0.;
119 
120  Real x = bx, w = bx, v = bx;
121 
122  // Residuals at bx
123  Real fx = current_residual,
124  fw = current_residual,
125  fv = current_residual;
126 
127  // Max iterations for Brent's method loop
128  const unsigned int max_i = 20;
129 
130  // for golden ratio steps
131  const Real golden_ratio = 1.-(std::sqrt(5.)-1.)/2.;
132 
133  for (unsigned int i=1; i <= max_i; i++)
134  {
135  Real xm = (ax+cx)*0.5;
136  Real tol1 = tol * std::abs(x) + tol*tol;
137  Real tol2 = 2.0 * tol1;
138 
139  // Test if we're done
140  if (std::abs(x-xm) <= (tol2 - 0.5 * (cx - ax)))
141  return x;
142 
143  Real d;
144 
145  // Construct a parabolic fit
146  if (std::abs(e) > tol1)
147  {
148  Real r = (x-w)*(fx-fv);
149  Real q = (x-v)*(fx-fw);
150  Real p = (x-v)*q-(x-w)*r;
151  q = 2. * (q-r);
152  if (q > 0.)
153  p = -p;
154  else
155  q = std::abs(q);
156  if (std::abs(p) >= std::abs(0.5*q*e) ||
157  p <= q * (ax-x) ||
158  p >= q * (cx-x))
159  {
160  // Take a golden section step
161  e = x >= xm ? ax-x : cx-x;
162  d = golden_ratio * e;
163  }
164  else
165  {
166  // Take a parabolic fit step
167  d = p/q;
168  if (x+d-ax < tol2 || cx-(x+d) < tol2)
169  d = SIGN(tol1, xm - x);
170  }
171  }
172  else
173  {
174  // Take a golden section step
175  e = x >= xm ? ax-x : cx-x;
176  d = golden_ratio * e;
177  }
178 
179  Real u = std::abs(d) >= tol1 ? x+d : x + SIGN(tol1,d);
180 
181  // Assemble the residual at the new steplength u
182  newton_iterate.add (bx - u, linear_solution);
183  newton_iterate.close();
184  bx = u;
185  if (verbose)
186  libMesh::out << " Shrinking Newton step to "
187  << bx << std::endl;
188 
189  _system.assembly (true, false);
190 
191  rhs.close();
192  Real fu = current_residual = rhs.l2_norm();
193  if (verbose)
194  libMesh::out << " Current Residual: "
195  << fu << std::endl;
196 
197  if (fu <= fx)
198  {
199  if (u >= x)
200  ax = x;
201  else
202  cx = x;
203  v = w; w = x; x = u;
204  fv = fw; fw = fx; fx = fu;
205  }
206  else
207  {
208  if (u < x)
209  ax = u;
210  else
211  cx = u;
212  if (fu <= fw || w == x)
213  {
214  v = w; w = u;
215  fv = fw; fw = fu;
216  }
217  else if (fu <= fv || v == x || v == w)
218  {
219  v = u;
220  fv = fu;
221  }
222  }
223  }
224 
225  if (!quiet)
226  libMesh::out << "Warning! Too many iterations used in Brent line search!"
227  << std::endl;
228  return bx;
229 }
static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited

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

Definition at line 79 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

80  { return _n_objects; }
processor_id_type libMesh::ParallelObject::n_processors ( ) const
inlineinherited
Returns
the number of processors in the group.

Definition at line 92 of file parallel_object.h.

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

Referenced by libMesh::ParmetisPartitioner::_do_repartition(), libMesh::ParallelMesh::add_elem(), libMesh::ParallelMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::ParallelMesh::assign_unique_ids(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::ParallelMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshBase::get_info(), libMesh::EquationSystems::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_procids< Elem >(), libMesh::MeshTools::libmesh_assert_valid_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshBase::n_active_elem_on_proc(), libMesh::MeshBase::n_elem_on_proc(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::Partitioner::partition(), libMesh::MeshBase::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::PetscLinearSolver< T >::PetscLinearSolver(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshTools::processor_bounding_box(), libMesh::System::project_vector(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::UnstructuredMesh::read(), libMesh::System::read_parallel_data(), libMesh::System::read_SCALAR_dofs(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::System::read_serialized_vector(), libMesh::Partitioner::repartition(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::BoundaryInfo::sync(), libMesh::ParallelMesh::update_parallel_id_counts(), libMesh::CheckpointIO::write(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::System::write_parallel_data(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

93  { return libmesh_cast_int<processor_id_type>(_communicator.size()); }
void libMesh::NewtonSolver::print_convergence ( unsigned int  step_num,
Real  current_residual,
Real  step_norm,
bool  linear_solve_finished 
)
protected

This prints output for the convergence criteria based on by the given residual and step size.

Definition at line 549 of file newton_solver.C.

References libMesh::DiffSolver::absolute_residual_tolerance, libMesh::DiffSolver::absolute_step_tolerance, libMesh::DiffSolver::max_residual_norm, libMesh::DiffSolver::max_solution_norm, libMesh::out, libMesh::DiffSolver::relative_residual_tolerance, libMesh::DiffSolver::relative_step_tolerance, and libMesh::DiffSolver::verbose.

Referenced by solve().

553 {
554  // Is our absolute residual low enough?
555  if (current_residual < absolute_residual_tolerance)
556  {
557  libMesh::out << " Nonlinear solver converged, step " << step_num
558  << ", residual " << current_residual
559  << std::endl;
560  }
562  {
563  if (verbose)
564  libMesh::out << " Nonlinear solver current_residual "
565  << current_residual << " > "
566  << (absolute_residual_tolerance) << std::endl;
567  }
568 
569  // Is our relative residual low enough?
570  if ((current_residual / max_residual_norm) <
572  {
573  libMesh::out << " Nonlinear solver converged, step " << step_num
574  << ", residual reduction "
575  << current_residual / max_residual_norm
576  << " < " << relative_residual_tolerance
577  << std::endl;
578  }
580  {
581  if (verbose)
582  libMesh::out << " Nonlinear solver relative residual "
583  << (current_residual / max_residual_norm)
584  << " > " << relative_residual_tolerance
585  << std::endl;
586  }
587 
588  // For incomplete linear solves, it's not safe to test step sizes
589  if (!linear_solve_finished)
590  return;
591 
592  // Is our absolute Newton step size small enough?
593  if (step_norm < absolute_step_tolerance)
594  {
595  libMesh::out << " Nonlinear solver converged, step " << step_num
596  << ", absolute step size "
597  << step_norm
598  << " < " << absolute_step_tolerance
599  << std::endl;
600  }
601  else if (absolute_step_tolerance)
602  {
603  if (verbose)
604  libMesh::out << " Nonlinear solver absolute step size "
605  << step_norm
606  << " > " << absolute_step_tolerance
607  << std::endl;
608  }
609 
610  // Is our relative Newton step size small enough?
611  if (step_norm / max_solution_norm <
613  {
614  libMesh::out << " Nonlinear solver converged, step " << step_num
615  << ", relative step size "
616  << (step_norm / max_solution_norm)
617  << " < " << relative_step_tolerance
618  << std::endl;
619  }
620  else if (relative_step_tolerance)
621  {
622  if (verbose)
623  libMesh::out << " Nonlinear solver relative step size "
624  << (step_norm / max_solution_norm)
625  << " > " << relative_step_tolerance
626  << std::endl;
627  }
628 }
void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

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

Definition at line 88 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter, and libMesh::ReferenceCounter::get_info().

89 {
91 }
processor_id_type libMesh::ParallelObject::processor_id ( ) const
inlineinherited
Returns
the rank of this processor in the group.

Definition at line 98 of file parallel_object.h.

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

Referenced by libMesh::MetisPartitioner::_do_partition(), libMesh::EquationSystems::_read_impl(), libMesh::SerialMesh::active_local_elements_begin(), libMesh::ParallelMesh::active_local_elements_begin(), libMesh::SerialMesh::active_local_elements_end(), libMesh::ParallelMesh::active_local_elements_end(), libMesh::SerialMesh::active_local_subdomain_elements_begin(), libMesh::ParallelMesh::active_local_subdomain_elements_begin(), libMesh::SerialMesh::active_local_subdomain_elements_end(), libMesh::ParallelMesh::active_local_subdomain_elements_end(), libMesh::SerialMesh::active_not_local_elements_begin(), libMesh::ParallelMesh::active_not_local_elements_begin(), libMesh::SerialMesh::active_not_local_elements_end(), libMesh::ParallelMesh::active_not_local_elements_end(), libMesh::ParallelMesh::add_elem(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::ParallelMesh::add_node(), libMesh::UnstructuredMesh::all_second_order(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::ParmetisPartitioner::build_graph(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::DofMap::build_sparsity(), libMesh::ParallelMesh::clear(), libMesh::ExodusII_IO_Helper::close(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::compute_communication_map_parameters(), libMesh::Nemesis_IO_Helper::compute_internal_and_border_elems_and_internal_nodes(), libMesh::Nemesis_IO_Helper::compute_node_communication_maps(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::ExodusII_IO_Helper::create(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DofMap::end_dof(), libMesh::DofMap::end_old_dof(), libMesh::EnsightIO::EnsightIO(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::DofMap::first_dof(), libMesh::DofMap::first_old_dof(), libMesh::Nemesis_IO_Helper::get_cmap_params(), libMesh::Nemesis_IO_Helper::get_eb_info_global(), libMesh::Nemesis_IO_Helper::get_elem_cmap(), libMesh::Nemesis_IO_Helper::get_elem_map(), libMesh::MeshBase::get_info(), libMesh::Nemesis_IO_Helper::get_init_global(), libMesh::Nemesis_IO_Helper::get_init_info(), libMesh::Nemesis_IO_Helper::get_loadbal_param(), libMesh::Nemesis_IO_Helper::get_node_cmap(), libMesh::Nemesis_IO_Helper::get_node_map(), libMesh::Nemesis_IO_Helper::get_ns_param_global(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::MeshFunction::gradient(), libMesh::MeshFunction::hessian(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::initialize_discontinuous(), libMesh::ExodusII_IO_Helper::initialize_element_variables(), libMesh::ExodusII_IO_Helper::initialize_global_variables(), libMesh::ExodusII_IO_Helper::initialize_nodal_variables(), libMesh::SparsityPattern::Build::join(), libMesh::DofMap::last_dof(), libMesh::MeshTools::libmesh_assert_valid_procids< Elem >(), libMesh::MeshTools::libmesh_assert_valid_procids< Node >(), libMesh::SerialMesh::local_elements_begin(), libMesh::ParallelMesh::local_elements_begin(), libMesh::SerialMesh::local_elements_end(), libMesh::ParallelMesh::local_elements_end(), libMesh::SerialMesh::local_level_elements_begin(), libMesh::ParallelMesh::local_level_elements_begin(), libMesh::SerialMesh::local_level_elements_end(), libMesh::ParallelMesh::local_level_elements_end(), libMesh::SerialMesh::local_nodes_begin(), libMesh::ParallelMesh::local_nodes_begin(), libMesh::SerialMesh::local_nodes_end(), libMesh::ParallelMesh::local_nodes_end(), libMesh::SerialMesh::local_not_level_elements_begin(), libMesh::ParallelMesh::local_not_level_elements_begin(), libMesh::SerialMesh::local_not_level_elements_end(), libMesh::ParallelMesh::local_not_level_elements_end(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::n_active_local_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::DofMap::n_local_dofs(), libMesh::System::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::SerialMesh::not_local_elements_begin(), libMesh::ParallelMesh::not_local_elements_begin(), libMesh::SerialMesh::not_local_elements_end(), libMesh::ParallelMesh::not_local_elements_end(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::MeshFunction::operator()(), libMesh::ParallelMesh::ParallelMesh(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::System::project_vector(), libMesh::Nemesis_IO_Helper::put_cmap_params(), libMesh::Nemesis_IO_Helper::put_elem_cmap(), libMesh::Nemesis_IO_Helper::put_elem_map(), libMesh::Nemesis_IO_Helper::put_loadbal_param(), libMesh::Nemesis_IO_Helper::put_node_cmap(), libMesh::Nemesis_IO_Helper::put_node_map(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::UnstructuredMesh::read(), libMesh::CheckpointIO::read_connectivity(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::System::read_parallel_data(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::System::read_serialized_data(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::MeshData::read_xdr(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::BoundaryInfo::sync(), libMesh::MeshTools::total_weight(), libMesh::ParallelMesh::update_parallel_id_counts(), libMesh::MeshTools::weight(), libMesh::ExodusII_IO::write(), libMesh::CheckpointIO::write(), libMesh::XdrIO::write(), libMesh::UnstructuredMesh::write(), libMesh::EquationSystems::write(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::ExodusII_IO_Helper::write_element_values(), libMesh::ExodusII_IO_Helper::write_elements(), libMesh::ExodusII_IO_Helper::write_elements_discontinuous(), libMesh::ExodusII_IO::write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), libMesh::System::write_header(), libMesh::ExodusII_IO::write_information_records(), libMesh::ExodusII_IO_Helper::write_information_records(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates_discontinuous(), libMesh::UCDIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::ExodusII_IO_Helper::write_nodal_values(), libMesh::ExodusII_IO_Helper::write_nodesets(), libMesh::Nemesis_IO_Helper::write_nodesets(), libMesh::System::write_parallel_data(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::System::write_serialized_data(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), libMesh::ExodusII_IO_Helper::write_sidesets(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO::write_timestep(), and libMesh::ExodusII_IO_Helper::write_timestep().

99  { return libmesh_cast_int<processor_id_type>(_communicator.rank()); }
void libMesh::NewtonSolver::reinit ( )
virtual

The reinitialization function. This method is used after changes in the mesh.

Reimplemented from libMesh::DiffSolver.

Definition at line 251 of file newton_solver.C.

References linear_solver, and libMesh::DiffSolver::reinit().

252 {
253  Parent::reinit();
254 
255  linear_solver->clear();
256 }
unsigned int libMesh::NewtonSolver::solve ( )
virtual

This method performs a solve, using an inexact Newton-Krylov method with line search.

Implements libMesh::DiffSolver.

Definition at line 260 of file newton_solver.C.

References libMesh::DiffSolver::_inner_iterations, libMesh::DiffSolver::_outer_iterations, libMesh::DiffSolver::_solve_result, libMesh::DiffSolver::_system, libMesh::NumericVector< T >::add(), libMesh::ImplicitSystem::assembly(), libMesh::NumericVector< T >::close(), libMesh::DiffSolver::continue_after_max_iterations, libMesh::DiffSolver::DIVERGED_BACKTRACKING_FAILURE, libMesh::DiffSolver::DIVERGED_MAX_NONLINEAR_ITERATIONS, libMesh::DofMap::enforce_constraints_exactly(), libMesh::System::get_dof_map(), libMesh::DiffSolver::initial_linear_tolerance, libMesh::DiffSolver::INVALID_SOLVE_RESULT, libMesh::NumericVector< T >::l2_norm(), libMesh::libmesh_assert(), libMesh::libmesh_isnan(), line_search(), libMesh::DiffSolver::linear_solution_monitor, linear_solver, linear_tolerance_multiplier, libMesh::ImplicitSystem::matrix, std::max(), libMesh::DiffSolver::max_linear_iterations, libMesh::DiffSolver::max_nonlinear_iterations, libMesh::DiffSolver::max_residual_norm, libMesh::DiffSolver::max_solution_norm, std::min(), libMesh::DiffSolver::minimum_linear_tolerance, libMesh::out, print_convergence(), libMesh::DiffSolver::quiet, libMesh::Real, libMesh::ImplicitSystem::request_matrix(), require_finite_residual, require_residual_reduction, libMesh::ExplicitSystem::rhs, libMesh::System::solution, libMesh::START_LOG(), libMesh::STOP_LOG(), test_convergence(), libMesh::TOLERANCE, libMesh::System::update(), libMesh::DiffSolver::verbose, libMesh::NumericVector< T >::zero(), and libMesh::NumericVector< T >::zero_clone().

261 {
262  START_LOG("solve()", "NewtonSolver");
263 
264  // Reset any prior solve result
266 
267  NumericVector<Number> &newton_iterate = *(_system.solution);
268 
269  AutoPtr<NumericVector<Number> > linear_solution_ptr = newton_iterate.zero_clone();
270  NumericVector<Number> &linear_solution = *linear_solution_ptr;
271  NumericVector<Number> &rhs = *(_system.rhs);
272 
273  newton_iterate.close();
274  linear_solution.close();
275  rhs.close();
276 
277 #ifdef LIBMESH_ENABLE_CONSTRAINTS
279 #endif
280 
281  SparseMatrix<Number> &matrix = *(_system.matrix);
282 
283  // Prepare to take incomplete steps
284  Real last_residual=0.;
285 
286  // Set starting linear tolerance
287  Real current_linear_tolerance = initial_linear_tolerance;
288 
289  // Start counting our linear solver steps
290  _inner_iterations = 0;
291 
292  // Now we begin the nonlinear loop
295  {
296  if (verbose)
297  libMesh::out << "Assembling the System" << std::endl;
298 
299  _system.assembly(true, true);
300  rhs.close();
301  Real current_residual = rhs.l2_norm();
302  last_residual = current_residual;
303 
304  if (libmesh_isnan(current_residual))
305  {
306  libMesh::out << " Nonlinear solver DIVERGED at step "
308  << " with residual Not-a-Number"
309  << std::endl;
310  libmesh_convergence_failure();
311  continue;
312  }
313 
314  max_residual_norm = std::max (current_residual,
316 
317  // Compute the l2 norm of the whole solution
318  Real norm_total = newton_iterate.l2_norm();
319 
321 
322  if (verbose)
323  libMesh::out << "Nonlinear Residual: "
324  << current_residual << std::endl;
325 
326  // Make sure our linear tolerance is low enough
327  current_linear_tolerance = std::min (current_linear_tolerance,
328  current_residual * linear_tolerance_multiplier);
329 
330  // But don't let it be too small
331  if (current_linear_tolerance < minimum_linear_tolerance)
332  {
333  current_linear_tolerance = minimum_linear_tolerance;
334  }
335 
336  // At this point newton_iterate is the current guess, and
337  // linear_solution is now about to become the NEGATIVE of the next
338  // Newton step.
339 
340  // Our best initial guess for the linear_solution is zero!
341  linear_solution.zero();
342 
343  if (verbose)
344  libMesh::out << "Linear solve starting, tolerance "
345  << current_linear_tolerance << std::endl;
346 
347  // Solve the linear system.
348  const std::pair<unsigned int, Real> rval =
349  linear_solver->solve (matrix, _system.request_matrix("Preconditioner"),
350  linear_solution, rhs, current_linear_tolerance,
352 
353  // We may need to localize a parallel solution
354  _system.update ();
355  // The linear solver may not have fit our constraints exactly
356 #ifdef LIBMESH_ENABLE_CONSTRAINTS
358  (_system, &linear_solution, /* homogeneous = */ true);
359 #endif
360 
361  const unsigned int linear_steps = rval.first;
362  libmesh_assert_less_equal (linear_steps, max_linear_iterations);
363  _inner_iterations += linear_steps;
364 
365  const bool linear_solve_finished =
366  !(linear_steps == max_linear_iterations);
367 
368  if (verbose)
369  libMesh::out << "Linear solve finished, step " << linear_steps
370  << ", residual " << rval.second
371  << std::endl;
372 
373  // Compute the l2 norm of the nonlinear update
374  Real norm_delta = linear_solution.l2_norm();
375 
376  if (verbose)
377  libMesh::out << "Trying full Newton step" << std::endl;
378  // Take a full Newton step
379  newton_iterate.add (-1., linear_solution);
380  newton_iterate.close();
381 
382  if (this->linear_solution_monitor.get()) {
383  // Compute the l2 norm of the whole solution
384  norm_total = newton_iterate.l2_norm();
385  rhs.close();
386  (*this->linear_solution_monitor)(
387  linear_solution, norm_delta,
388  newton_iterate, norm_total,
389  rhs, rhs.l2_norm(), _outer_iterations);
390  }
391 
392  // Check residual with full Newton step, if that's useful for determining
393  // whether to line search, whether to quit early, or whether to die after
394  // hitting our max iteration count
395  if (this->require_residual_reduction ||
396  this->require_finite_residual ||
397  _outer_iterations+1 < max_nonlinear_iterations ||
399  {
400  _system.assembly(true, false);
401 
402  rhs.close();
403  current_residual = rhs.l2_norm();
404  if (verbose)
405  libMesh::out << " Current Residual: "
406  << current_residual << std::endl;
407 
408  // don't fiddle around if we've already converged
409  if (test_convergence(current_residual, norm_delta,
410  linear_solve_finished &&
411  current_residual <= last_residual))
412  {
413  if (!quiet)
414  print_convergence(_outer_iterations, current_residual,
415  norm_delta, linear_solve_finished &&
416  current_residual <= last_residual);
418  break; // out of _outer_iterations for loop
419  }
420  }
421 
422  // since we're not converged, backtrack if necessary
423  Real steplength =
424  this->line_search(std::sqrt(TOLERANCE),
425  last_residual, current_residual,
426  newton_iterate, linear_solution);
427  norm_delta *= steplength;
428 
429  // Check to see if backtracking failed,
430  // and break out of the nonlinear loop if so...
432  {
434  break; // out of _outer_iterations for loop
435  }
436 
437  if (_outer_iterations + 1 >= max_nonlinear_iterations)
438  {
439  libMesh::out << " Nonlinear solver reached maximum step "
440  << max_nonlinear_iterations << ", latest evaluated residual "
441  << current_residual << std::endl;
443  {
445  libMesh::out << " Continuing..." << std::endl;
446  }
447  else
448  {
449  libmesh_convergence_failure();
450  }
451  continue;
452  }
453 
454  // Compute the l2 norm of the whole solution
455  norm_total = newton_iterate.l2_norm();
456 
458 
459  // Print out information for the
460  // nonlinear iterations.
461  if (verbose)
462  libMesh::out << " Nonlinear step: |du|/|u| = "
463  << norm_delta / norm_total
464  << ", |du| = " << norm_delta
465  << std::endl;
466 
467  // Terminate the solution iteration if the difference between
468  // this iteration and the last is sufficiently small.
469  if (test_convergence(current_residual, norm_delta / steplength,
470  linear_solve_finished))
471  {
472  if (!quiet)
473  print_convergence(_outer_iterations, current_residual,
474  norm_delta / steplength,
475  linear_solve_finished);
477  break; // out of _outer_iterations for loop
478  }
479  } // end nonlinear loop
480 
481  // The linear solver may not have fit our constraints exactly
482 #ifdef LIBMESH_ENABLE_CONSTRAINTS
484 #endif
485 
486  // We may need to localize a parallel solution
487  _system.update ();
488 
489  STOP_LOG("solve()", "NewtonSolver");
490 
491  // Make sure we are returning something sensible as the
492  // _solve_result, except in the edge case where we weren't really asked to
493  // solve.
495  !max_nonlinear_iterations);
496 
497  return _solve_result;
498 }
unsigned int libMesh::DiffSolver::solve_result ( )
inlineinherited
Returns
the value of the SolveResult from the last solve.

Definition at line 130 of file diff_solver.h.

References libMesh::DiffSolver::_solve_result.

130 { return _solve_result; }
const sys_type& libMesh::DiffSolver::system ( ) const
inlineinherited
Returns
a constant reference to the system we are solving.

Definition at line 135 of file diff_solver.h.

References libMesh::DiffSolver::_system.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), and libMesh::__libmesh_petsc_diff_solver_residual().

135 { return _system; }
sys_type& libMesh::DiffSolver::system ( )
inlineinherited
Returns
a writeable reference to the system we are solving.

Definition at line 140 of file diff_solver.h.

References libMesh::DiffSolver::_system.

140 { return _system; }
bool libMesh::NewtonSolver::test_convergence ( Real  current_residual,
Real  step_norm,
bool  linear_solve_finished 
)
protected

This returns true if a convergence criterion has been passed by the given residual and step size; false otherwise.

Definition at line 502 of file newton_solver.C.

References libMesh::DiffSolver::_solve_result, libMesh::DiffSolver::absolute_residual_tolerance, libMesh::DiffSolver::absolute_step_tolerance, libMesh::DiffSolver::CONVERGED_ABSOLUTE_RESIDUAL, libMesh::DiffSolver::CONVERGED_ABSOLUTE_STEP, libMesh::DiffSolver::CONVERGED_RELATIVE_RESIDUAL, libMesh::DiffSolver::CONVERGED_RELATIVE_STEP, libMesh::DiffSolver::max_residual_norm, libMesh::DiffSolver::max_solution_norm, libMesh::DiffSolver::relative_residual_tolerance, and libMesh::DiffSolver::relative_step_tolerance.

Referenced by solve().

505 {
506  // We haven't converged unless we pass a convergence test
507  bool has_converged = false;
508 
509  // Is our absolute residual low enough?
510  if (current_residual < absolute_residual_tolerance)
511  {
513  has_converged = true;
514  }
515 
516  // Is our relative residual low enough?
517  if ((current_residual / max_residual_norm) <
519  {
521  has_converged = true;
522  }
523 
524  // For incomplete linear solves, it's not safe to test step sizes
525  if (!linear_solve_finished)
526  {
527  return has_converged;
528  }
529 
530  // Is our absolute Newton step size small enough?
531  if (step_norm < absolute_step_tolerance)
532  {
534  has_converged = true;
535  }
536 
537  // Is our relative Newton step size small enough?
538  if (step_norm / max_solution_norm <
540  {
542  has_converged = true;
543  }
544 
545  return has_converged;
546 }
unsigned int libMesh::DiffSolver::total_inner_iterations ( )
inlineinherited
Returns
the number of "inner" (e.g. Krylov) iterations required by the last solve.

Definition at line 125 of file diff_solver.h.

References libMesh::DiffSolver::_inner_iterations.

125 { return _inner_iterations; }
unsigned int libMesh::DiffSolver::total_outer_iterations ( )
inlineinherited
Returns
the number of "outer" (e.g. quasi-Newton) iterations required by the last solve.

Definition at line 119 of file diff_solver.h.

References libMesh::DiffSolver::_outer_iterations.

119 { return _outer_iterations; }

Member Data Documentation

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited
bool libMesh::ReferenceCounter::_enable_print_counter = true
staticprotectedinherited

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

Definition at line 137 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info(), and libMesh::ReferenceCounter::print_info().

unsigned int libMesh::DiffSolver::_inner_iterations
protectedinherited

The number of inner iterations used by the last solve

Definition at line 305 of file diff_solver.h.

Referenced by solve(), and libMesh::DiffSolver::total_inner_iterations().

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

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 131 of file reference_counter.h.

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 126 of file reference_counter.h.

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

unsigned int libMesh::DiffSolver::_outer_iterations
protectedinherited

The number of outer iterations used by the last solve

Definition at line 300 of file diff_solver.h.

Referenced by line_search(), solve(), libMesh::PetscDiffSolver::solve(), and libMesh::DiffSolver::total_outer_iterations().

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 318 of file diff_solver.h.

Referenced by line_search(), solve(), libMesh::DiffSolver::solve_result(), and test_convergence().

sys_type& libMesh::DiffSolver::_system
protectedinherited

A reference to the system we are solving.

Definition at line 310 of file diff_solver.h.

Referenced by line_search(), solve(), libMesh::PetscDiffSolver::solve(), and libMesh::DiffSolver::system().

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 189 of file diff_solver.h.

Referenced by print_convergence(), and test_convergence().

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 201 of file diff_solver.h.

Referenced by print_convergence(), and test_convergence().

bool libMesh::NewtonSolver::brent_line_search

If require_residual_reduction is true, the solver may reduce step lengths when required. If so, brent_line_search is an option. If brent_line_search is set to false, the solver reduces the length of its steps by 1/2 iteratively until it finds residual reduction. If true, step lengths are first reduced by 1/2 or more to find some residual reduction, then Brent's method is used to find as much residual reduction as possible.

brent_line_search is currently set to true by default.

Definition at line 106 of file newton_solver.h.

Referenced by line_search().

bool libMesh::DiffSolver::continue_after_backtrack_failure
inherited

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

Definition at line 178 of file diff_solver.h.

Referenced by line_search().

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 172 of file diff_solver.h.

Referenced by solve().

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 208 of file diff_solver.h.

Referenced by solve().

AutoPtr<LinearSolutionMonitor> libMesh::DiffSolver::linear_solution_monitor
inherited

Pointer to functor which is called right after each linear solve

Definition at line 280 of file diff_solver.h.

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), and solve().

AutoPtr<LinearSolver<Number> > libMesh::NewtonSolver::linear_solver
protected

The LinearSolver defines the interface used to solve the linear_implicit system. This class handles all the details of interfacing with various linear algebra packages like PETSc or LASPACK.

Definition at line 130 of file newton_solver.h.

Referenced by reinit(), and solve().

Real libMesh::NewtonSolver::linear_tolerance_multiplier

The tolerance for linear solves is kept below this multiplier (which defaults to 1e-3) times the norm of the current nonlinear residual

Definition at line 120 of file newton_solver.h.

Referenced by solve().

unsigned int libMesh::DiffSolver::max_linear_iterations
inherited

Each linear solver step should exit after max_linear_iterations is exceeded.

Definition at line 146 of file diff_solver.h.

Referenced by libMesh::ContinuationSystem::continuation_solve(), solve(), and libMesh::ContinuationSystem::solve_tangent().

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 154 of file diff_solver.h.

Referenced by libMesh::ContinuationSystem::continuation_solve(), solve(), and libMesh::ContinuationSystem::update_solution().

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 295 of file diff_solver.h.

Referenced by libMesh::DiffSolver::init(), print_convergence(), libMesh::DiffSolver::reinit(), solve(), and test_convergence().

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 288 of file diff_solver.h.

Referenced by libMesh::DiffSolver::init(), print_convergence(), libMesh::DiffSolver::reinit(), solve(), and test_convergence().

Real libMesh::DiffSolver::minimum_linear_tolerance
inherited

The tolerance for linear solves is kept above this minimum

Definition at line 213 of file diff_solver.h.

Referenced by solve().

Real libMesh::NewtonSolver::minsteplength

If the quasi-Newton step length must be reduced to below this factor to give a residual reduction, then the Newton solver dies with a libmesh_error() It is currently set to 1e-5 by default.

Definition at line 114 of file newton_solver.h.

Referenced by line_search().

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 160 of file diff_solver.h.

Referenced by line_search(), and solve().

Real libMesh::DiffSolver::relative_residual_tolerance
inherited

Definition at line 190 of file diff_solver.h.

Referenced by print_convergence(), and test_convergence().

Real libMesh::DiffSolver::relative_step_tolerance
inherited

Definition at line 202 of file diff_solver.h.

Referenced by print_convergence(), and test_convergence().

bool libMesh::NewtonSolver::require_finite_residual

If this is set to true, the solver is forced to test the residual after each Newton step, and to reduce the length of its steps whenever necessary to avoid an infinite or NaN residual. It is currently set to true by default; set it to false to avoid unnecessary residual assembly on well-behaved systems.

Definition at line 93 of file newton_solver.h.

Referenced by line_search(), and solve().

bool libMesh::NewtonSolver::require_residual_reduction

If this is set to true, the solver is forced to test the residual after each Newton step, and to reduce the length of its steps whenever necessary to avoid a residual increase. It is currently set to true by default; set it to false to avoid unnecessary residual assembly on well-behaved systems.

Definition at line 84 of file newton_solver.h.

Referenced by line_search(), and solve().

bool libMesh::DiffSolver::verbose
inherited

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

Site Created By: libMesh Developers
Last modified: February 07 2014 16:58:01 UTC

Hosted By:
SourceForge.net Logo