#include <petsc_diff_solver.h>
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 DifferentiableSystem sys_type
PetscDiffSolver (sys_type &system)
virtual ~PetscDiffSolver ()
virtual void reinit ()
void init ()
void clear ()
virtual unsigned int solve ()
virtual unsigned int adjoint_solve ()
unsigned int total_outer_iterations ()
unsigned int total_inner_iterations ()
unsigned int solve_result ()
const sys_type & system () const
sys_type & system ()
static AutoPtr< DiffSolver > build (sys_type &s)
static std::string get_info ()
static void print_info ()
static unsigned int n_objects ()
unsigned int max_linear_iterations
unsigned int max_nonlinear_iterations
bool quiet
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
typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
void increment_constructor_count (const std::string &name)
void increment_destructor_count (const std::string &name)
SNES _snes
Real max_solution_norm
Real max_residual_norm
unsigned int _outer_iterations
unsigned int _inner_iterations
sys_type & _system
unsigned int _solve_result
static Counts _counts
static Threads::atomic< unsigned int > _n_objects
static Threads::spin_mutex _mutex
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:
Definition at line 52 of file petsc_diff_solver.h.
Definition at line 105 of file reference_counter.h.
Definition at line 66 of file petsc_diff_solver.h.
Definition at line 56 of file diff_solver.h.
Enumerator:
Definition at line 200 of file diff_solver.h.
{ 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 };
Definition at line 155 of file petsc_diff_solver.C.
: Parent(s) { }
Definition at line 199 of file petsc_diff_solver.C.
{ }
Implements DiffSolver.
Definition at line 287 of file petsc_diff_solver.C.
References DiffSolver::_system, ExplicitSystem::assemble_qoi_derivative(), DifferentiableSystem::assembly(), DiffSolver::build(), SparseMatrix< T >::close(), DiffSolver::CONVERGED_RELATIVE_RESIDUAL, DofMap::enforce_constraints_exactly(), System::get_dof_map(), ImplicitSystem::get_matrix(), SparseMatrix< T >::get_transpose(), ImplicitSystem::have_matrix(), ImplicitSystem::matrix, DiffSolver::max_linear_iterations, DiffSolver::relative_residual_tolerance, ExplicitSystem::rhs, System::solution, and System::update().
{ // The adjoint_solve API (and all APIs using it) are about to see a // series of non-backwards-compatible changes, primarily to add // multiple-QoI support libmesh_experimental(); START_LOG('adjoint_solve()', 'PetscDiffSolver'); // Do DiffSystem assembly _system.assembly(false, true); _system.matrix->close(); // But take the adjoint _system.matrix->get_transpose(*_system.matrix); if (_system.have_matrix('Preconditioner')) { SparseMatrix<Number> &pre = _system.get_matrix('Preconditioner'); pre.get_transpose(pre); } // And set the right hand side to the quantity of interest // derivative _system.assemble_qoi_derivative(); // Then build something to solve the _linear_ system AutoPtr<LinearSolver<Number> > linear_solver = LinearSolver<Number>::build(); // Solve the linear system. Two cases: const std::pair<unsigned int, Real> rval = (_system.have_matrix('Preconditioner')) ? // 1.) User-supplied preconditioner linear_solver->solve (*_system.matrix, _system.get_matrix('Preconditioner'), *_system.solution, *_system.rhs, relative_residual_tolerance, max_linear_iterations) : // 2.) Use system matrix for the preconditioner linear_solver->solve (*_system.matrix, *_system.solution, *_system.rhs, relative_residual_tolerance, max_linear_iterations); // We may need to localize a parallel solution _system.update (); // The linear solver may not have fit our constraints exactly #ifdef LIBMESH_ENABLE_AMR _system.get_dof_map().enforce_constraints_exactly(_system); #endif STOP_LOG('adjoint_solve()', 'PetscDiffSolver'); // FIXME - We'll worry about getting the solve result right later... return DiffSolver::CONVERGED_RELATIVE_RESIDUAL; }
Definition at line 47 of file diff_solver.C.
Referenced by adjoint_solve(), and TimeSolver::init().
{ return AutoPtr<DiffSolver>(new NewtonSolver(s)); }
Definition at line 205 of file petsc_diff_solver.C.
References _snes, and libMesh::COMM_WORLD.
Referenced by solve().
{ START_LOG('clear()', 'PetscDiffSolver'); int ierr=0; ierr = SNESDestroy(_snes); CHKERRABORT(libMesh::COMM_WORLD,ierr); STOP_LOG('clear()', 'PetscDiffSolver'); }
Definition at line 45 of file reference_counter.C.
References ReferenceCounter::_counts, and Quality::name().
Referenced by ReferenceCounter::print_info().
{ #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG) std::ostringstream out; out << ' << ' ---------------------------------------------------------------------------- << '| Reference count information | << ' ---------------------------------------------------------------------------- ; for (Counts::iterator it = _counts.begin(); it != _counts.end(); ++it) { const std::string name(it->first); const unsigned int creations = it->second.first; const unsigned int destructions = it->second.second; out << '| ' << name << ' reference count information: << '| Creations: ' << creations << ' << '| Destructions: ' << destructions << '; } out << ' ---------------------------------------------------------------------------- ; return out.str(); #else return ''; #endif }
Definition at line 149 of file reference_counter.h.
References ReferenceCounter::_counts, Quality::name(), and Threads::spin_mtx.
Referenced by ReferenceCountedObject< Value >::ReferenceCountedObject().
{ Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); std::pair<unsigned int, unsigned int>& p = _counts[name]; p.first++; }
Definition at line 167 of file reference_counter.h.
References ReferenceCounter::_counts, Quality::name(), and Threads::spin_mtx.
Referenced by ReferenceCountedObject< Value >::~ReferenceCountedObject().
{ Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); std::pair<unsigned int, unsigned int>& p = _counts[name]; p.second++; }
Reimplemented from DiffSolver.
Definition at line 161 of file petsc_diff_solver.C.
References __libmesh_petsc_diff_solver_monitor(), _snes, libMesh::COMM_WORLD, and DiffSolver::init().
Referenced by solve().
{ START_LOG('init()', 'PetscDiffSolver'); Parent::init(); int ierr=0; #if PETSC_VERSION_LESS_THAN(2,1,2) // At least until Petsc 2.1.1, the SNESCreate had a different // calling syntax. The second argument was of type SNESProblemType, // and could have a value of either SNES_NONLINEAR_EQUATIONS or // SNES_UNCONSTRAINED_MINIMIZATION. ierr = SNESCreate(libMesh::COMM_WORLD, SNES_NONLINEAR_EQUATIONS, &_snes); CHKERRABORT(libMesh::COMM_WORLD,ierr); #else ierr = SNESCreate(libMesh::COMM_WORLD,&_snes); CHKERRABORT(libMesh::COMM_WORLD,ierr); #endif #if PETSC_VERSION_LESS_THAN(2,3,3) ierr = SNESSetMonitor (_snes, __libmesh_petsc_diff_solver_monitor, this, PETSC_NULL); #else // API name change in PETSc 2.3.3 ierr = SNESMonitorSet (_snes, __libmesh_petsc_diff_solver_monitor, this, PETSC_NULL); #endif CHKERRABORT(libMesh::COMM_WORLD,ierr); ierr = SNESSetFromOptions(_snes); CHKERRABORT(libMesh::COMM_WORLD,ierr); STOP_LOG('init()', 'PetscDiffSolver'); }
Definition at line 76 of file reference_counter.h.
References ReferenceCounter::_n_objects.
Referenced by System::read_serialized_blocked_dof_objects(), and System::write_serialized_blocked_dof_objects().
{ return _n_objects; }
Definition at line 83 of file reference_counter.C.
References ReferenceCounter::get_info().
{ #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG) std::cout << ReferenceCounter::get_info(); #endif }
Reimplemented from DiffSolver.
Definition at line 219 of file petsc_diff_solver.C.
References DiffSolver::reinit().
{ Parent::reinit(); }
Implements DiffSolver.
Definition at line 226 of file petsc_diff_solver.C.
References __libmesh_petsc_diff_solver_jacobian(), __libmesh_petsc_diff_solver_residual(), DiffSolver::_outer_iterations, _snes, DiffSolver::_system, clear(), PetscMatrix< T >::close(), PetscVector< T >::close(), libMesh::COMM_WORLD, DiffSolver::CONVERGED_RELATIVE_RESIDUAL, DofMap::enforce_constraints_exactly(), AutoPtr< Tp >::get(), System::get_dof_map(), init(), PetscMatrix< T >::mat(), ImplicitSystem::matrix, ExplicitSystem::rhs, System::solution, and PetscVector< T >::vec().
{ this->init(); START_LOG('solve()', 'PetscDiffSolver'); PetscVector<Number> &x = *(libmesh_cast_ptr<PetscVector<Number>*>(_system.solution.get())); PetscMatrix<Number> &jac = *(libmesh_cast_ptr<PetscMatrix<Number>*>(_system.matrix)); PetscVector<Number> &r = *(libmesh_cast_ptr<PetscVector<Number>*>(_system.rhs)); x.close(); r.close(); jac.close(); #ifdef LIBMESH_ENABLE_AMR _system.get_dof_map().enforce_constraints_exactly(_system); #endif int ierr = 0; ierr = SNESSetFunction (_snes, r.vec(), __libmesh_petsc_diff_solver_residual, this); CHKERRABORT(libMesh::COMM_WORLD,ierr); ierr = SNESSetJacobian (_snes, jac.mat(), jac.mat(), __libmesh_petsc_diff_solver_jacobian, this); CHKERRABORT(libMesh::COMM_WORLD,ierr); # if PETSC_VERSION_LESS_THAN(2,2,0) ierr = SNESSolve (_snes, x.vec(), &_outer_iterations); CHKERRABORT(libMesh::COMM_WORLD,ierr); // 2.2.x style #elif PETSC_VERSION_LESS_THAN(2,3,0) ierr = SNESSolve (_snes, x.vec()); CHKERRABORT(libMesh::COMM_WORLD,ierr); // 2.3.x & newer style #else ierr = SNESSolve (_snes, PETSC_NULL, x.vec()); CHKERRABORT(libMesh::COMM_WORLD,ierr); #endif STOP_LOG('solve()', 'PetscDiffSolver'); this->clear(); // FIXME - We'll worry about getting the solve result right later... return DiffSolver::CONVERGED_RELATIVE_RESIDUAL; }
Definition at line 116 of file diff_solver.h.
References DiffSolver::_solve_result.
{ return _solve_result; }
Definition at line 121 of file diff_solver.h.
References DiffSolver::_system.
Referenced by __libmesh_petsc_diff_solver_jacobian(), and __libmesh_petsc_diff_solver_residual().
{ return _system; }
Definition at line 126 of file diff_solver.h.
References DiffSolver::_system.
{ return _system; }
Definition at line 111 of file diff_solver.h.
References DiffSolver::_inner_iterations.
{ return _inner_iterations; }
Definition at line 105 of file diff_solver.h.
References DiffSolver::_outer_iterations.
{ return _outer_iterations; }
Definition at line 110 of file reference_counter.h.
Referenced by ReferenceCounter::get_info(), ReferenceCounter::increment_constructor_count(), and ReferenceCounter::increment_destructor_count().
Definition at line 280 of file diff_solver.h.
Referenced by NewtonSolver::solve(), and DiffSolver::total_inner_iterations().
Definition at line 123 of file reference_counter.h.
Definition at line 118 of file reference_counter.h.
Referenced by ReferenceCounter::n_objects(), ReferenceCounter::ReferenceCounter(), and ReferenceCounter::~ReferenceCounter().
Definition at line 275 of file diff_solver.h.
Referenced by NewtonSolver::line_search(), solve(), NewtonSolver::solve(), and DiffSolver::total_outer_iterations().
Definition at line 105 of file petsc_diff_solver.h.
Referenced by clear(), init(), and solve().
Definition at line 293 of file diff_solver.h.
Referenced by NewtonSolver::line_search(), NewtonSolver::solve(), DiffSolver::solve_result(), and NewtonSolver::test_convergence().
Definition at line 285 of file diff_solver.h.
Referenced by adjoint_solve(), NewtonSolver::adjoint_solve(), NewtonSolver::line_search(), solve(), NewtonSolver::solve(), and DiffSolver::system().
Users should increase any of these tolerances that they want to use for a stopping condition.
Definition at line 169 of file diff_solver.h.
Referenced by NewtonSolver::print_convergence(), and NewtonSolver::test_convergence().
Users should increase any of these tolerances that they want to use for a stopping condition.
Definition at line 181 of file diff_solver.h.
Referenced by NewtonSolver::print_convergence(), and NewtonSolver::test_convergence().
Definition at line 158 of file diff_solver.h.
Referenced by NewtonSolver::line_search().
Definition at line 152 of file diff_solver.h.
Referenced by NewtonSolver::solve().
Definition at line 188 of file diff_solver.h.
Referenced by NewtonSolver::solve().
Definition at line 132 of file diff_solver.h.
Referenced by adjoint_solve(), NewtonSolver::adjoint_solve(), ContinuationSystem::continuation_solve(), NewtonSolver::solve(), and ContinuationSystem::solve_tangent().
Definition at line 140 of file diff_solver.h.
Referenced by ContinuationSystem::continuation_solve(), NewtonSolver::solve(), and ContinuationSystem::update_solution().
Definition at line 270 of file diff_solver.h.
Referenced by DiffSolver::init(), NewtonSolver::print_convergence(), DiffSolver::reinit(), NewtonSolver::solve(), and NewtonSolver::test_convergence().
Definition at line 263 of file diff_solver.h.
Referenced by DiffSolver::init(), NewtonSolver::print_convergence(), DiffSolver::reinit(), NewtonSolver::solve(), and NewtonSolver::test_convergence().
Definition at line 193 of file diff_solver.h.
Referenced by NewtonSolver::solve().
Definition at line 146 of file diff_solver.h.
Referenced by NewtonSolver::adjoint_solve(), NewtonSolver::line_search(), NewtonSolver::print_convergence(), and NewtonSolver::solve().
Definition at line 170 of file diff_solver.h.
Referenced by adjoint_solve(), NewtonSolver::adjoint_solve(), NewtonSolver::print_convergence(), and NewtonSolver::test_convergence().
Definition at line 182 of file diff_solver.h.
Referenced by NewtonSolver::print_convergence(), and NewtonSolver::test_convergence().
Generated automatically by Doxygen for libMesh from the source code.