libMesh::EigenSparseLinearSolver< T > Class Template Reference

#include <eigen_sparse_linear_solver.h>

Inheritance diagram for libMesh::EigenSparseLinearSolver< T >:

Public Member Functions

 EigenSparseLinearSolver (const libMesh::Parallel::Communicator &comm_in LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
 
 ~EigenSparseLinearSolver ()
 
virtual void clear () libmesh_override
 
virtual void init (const char *name=libmesh_nullptr) libmesh_override
 
virtual std::pair< unsigned int, Realsolve (SparseMatrix< T > &matrix, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its) libmesh_override
 
virtual std::pair< unsigned int, Realadjoint_solve (SparseMatrix< T > &matrix, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its) libmesh_override
 
virtual std::pair< unsigned int, Realsolve (SparseMatrix< T > &matrix, SparseMatrix< T > &pc, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its) libmesh_override
 
virtual std::pair< unsigned int, Realsolve (const ShellMatrix< T > &shell_matrix, NumericVector< T > &solution_in, NumericVector< T > &rhs_in, const double tol, const unsigned int m_its) libmesh_override
 
virtual std::pair< unsigned int, Realsolve (const ShellMatrix< T > &shell_matrix, const SparseMatrix< T > &precond_matrix, NumericVector< T > &solution_in, NumericVector< T > &rhs_in, const double tol, const unsigned int m_its) libmesh_override
 
virtual LinearConvergenceReason get_converged_reason () const libmesh_override
 
bool initialized () const
 
virtual void init_names (const System &)
 
SolverType solver_type () const
 
void set_solver_type (const SolverType st)
 
PreconditionerType preconditioner_type () const
 
void set_preconditioner_type (const PreconditionerType pct)
 
void attach_preconditioner (Preconditioner< T > *preconditioner)
 
virtual void reuse_preconditioner (bool)
 
bool get_same_preconditioner ()
 
virtual void restrict_solve_to (const std::vector< unsigned int > *const dofs, const SubsetSolveMode subset_solve_mode=SUBSET_ZERO)
 
std::pair< unsigned int, Realsolve (SparseMatrix< T > &matrix, SparseMatrix< T > *precond_matrix, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)
 
std::pair< unsigned int, Realsolve (const ShellMatrix< T > &matrix, const SparseMatrix< T > *precond_matrix, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)
 
virtual void print_converged_reason () const
 
void set_solver_configuration (SolverConfiguration &solver_configuration)
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static UniquePtr< LinearSolver< T > > build (const libMesh::Parallel::Communicator &comm_in, const SolverPackage solver_package=libMesh::default_solver_package())
 
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 ()
 

Protected Types

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

Protected Member Functions

void increment_constructor_count (const std::string &name)
 
void increment_destructor_count (const std::string &name)
 

Protected Attributes

SolverType _solver_type
 
PreconditionerType _preconditioner_type
 
bool _is_initialized
 
Preconditioner< T > * _preconditioner
 
bool same_preconditioner
 
SolverConfiguration_solver_configuration
 
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
 

Private Member Functions

void set_eigen_preconditioner_type ()
 

Static Private Member Functions

static std::map< Eigen::ComputationInfo, LinearConvergenceReasonbuild_map ()
 

Private Attributes

Eigen::ComputationInfo _comp_info
 

Static Private Attributes

static std::map< Eigen::ComputationInfo, LinearConvergenceReason_convergence_reasons = EigenSparseLinearSolver<T>::build_map()
 

Detailed Description

template<typename T>
class libMesh::EigenSparseLinearSolver< T >

This class provides an interface to Eigen iterative solvers that is compatible with the libMesh LinearSolver<>

Author
Benjamin Kirk
Date
2013

Definition at line 48 of file eigen_sparse_linear_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 119 of file reference_counter.h.

Constructor & Destructor Documentation

template<typename T >
libMesh::EigenSparseLinearSolver< T >::EigenSparseLinearSolver ( const libMesh::Parallel::Communicator &comm_in  LIBMESH_CAN_DEFAULT_TO_COMMWORLD)

Constructor. Initializes Eigen data structures

Definition at line 41 of file eigen_sparse_linear_solver.C.

References libMesh::LinearSolver< T >::_solver_type, and libMesh::BICGSTAB.

41  :
42  LinearSolver<T>(comm_in),
43  _comp_info(Eigen::Success)
44 {
45  // The GMRES _solver_type can be used in EigenSparseLinearSolver,
46  // however, the GMRES iterative solver is currently in the Eigen
47  // "unsupported" directory, so we use BICGSTAB as our default.
48  this->_solver_type = BICGSTAB;
49 }
template<typename T >
libMesh::EigenSparseLinearSolver< T >::~EigenSparseLinearSolver ( )
inline

Destructor.

Definition at line 177 of file eigen_sparse_linear_solver.h.

References libMesh::EigenSparseLinearSolver< T >::clear().

178 {
179  this->clear ();
180 }
virtual void clear() libmesh_override

Member Function Documentation

template<typename T >
std::pair< unsigned int, Real > libMesh::EigenSparseLinearSolver< T >::adjoint_solve ( SparseMatrix< T > &  matrix,
NumericVector< T > &  solution,
NumericVector< T > &  rhs,
const double  tol,
const unsigned int  m_its 
)
virtual

Call the Eigen solver to solve A^T x = b

Reimplemented from libMesh::LinearSolver< T >.

Definition at line 232 of file eigen_sparse_linear_solver.C.

References libMesh::ParallelObject::comm(), libMesh::SparseMatrix< T >::get_transpose(), and libMesh::EigenSparseLinearSolver< T >::solve().

237 {
238  LOG_SCOPE("adjoint_solve()", "EigenSparseLinearSolver");
239 
240  libmesh_experimental();
241  EigenSparseMatrix<T> mat_trans(this->comm());
242  matrix_in.get_transpose(mat_trans);
243 
244  std::pair<unsigned int, Real> retval = this->solve (mat_trans,
245  solution_in,
246  rhs_in,
247  tol,
248  m_its);
249 
250  return retval;
251 }
const Parallel::Communicator & comm() const
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &matrix, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its) libmesh_override
template<typename T>
void libMesh::LinearSolver< T >::attach_preconditioner ( Preconditioner< T > *  preconditioner)
inherited

Attaches a Preconditioner object to be used

Definition at line 103 of file linear_solver.C.

References libMesh::libMeshPrivateData::_is_initialized, and libMesh::SHELL_PRECOND.

Referenced by libMesh::LinearSolver< Number >::set_solver_type().

104 {
105  if (this->_is_initialized)
106  libmesh_error_msg("Preconditioner must be attached before the solver is initialized!");
107 
109  _preconditioner = preconditioner;
110 }
Preconditioner< T > * _preconditioner
PreconditionerType _preconditioner_type
template<typename T >
UniquePtr< LinearSolver< T > > libMesh::LinearSolver< T >::build ( const libMesh::Parallel::Communicator comm_in,
const SolverPackage  solver_package = libMesh::default_solver_package() 
)
staticinherited

Builds a LinearSolver using the linear solver package specified by solver_package

Definition at line 42 of file linear_solver.C.

References libMesh::EIGEN_SOLVERS, libMesh::LASPACK_SOLVERS, libMesh::libmesh_ignore(), libMesh::PETSC_SOLVERS, and libMesh::TRILINOS_SOLVERS.

Referenced by libMesh::ImplicitSystem::get_linear_solver(), and libMesh::TimeSolver::init().

44 {
45  // Avoid unused parameter warnings when no solver packages are enabled.
47 
48  // Build the appropriate solver
49  switch (solver_package)
50  {
51 #ifdef LIBMESH_HAVE_LASPACK
52  case LASPACK_SOLVERS:
53  return UniquePtr<LinearSolver<T> >(new LaspackLinearSolver<T>(comm));
54 #endif
55 
56 
57 #ifdef LIBMESH_HAVE_PETSC
58  case PETSC_SOLVERS:
59  return UniquePtr<LinearSolver<T> >(new PetscLinearSolver<T>(comm));
60 #endif
61 
62 
63 #ifdef LIBMESH_TRILINOS_HAVE_AZTECOO
64  case TRILINOS_SOLVERS:
65  return UniquePtr<LinearSolver<T> >(new AztecLinearSolver<T>(comm));
66 #endif
67 
68 
69 #ifdef LIBMESH_HAVE_EIGEN
70  case EIGEN_SOLVERS:
71  return UniquePtr<LinearSolver<T> >(new EigenSparseLinearSolver<T>(comm));
72 #endif
73 
74  default:
75  libmesh_error_msg("ERROR: Unrecognized solver package: " << solver_package);
76  }
77 
78  return UniquePtr<LinearSolver<T> >();
79 }
EIGEN_SOLVERS
Definition: libmesh.C:262
TRILINOS_SOLVERS
Definition: libmesh.C:260
LASPACK_SOLVERS
Definition: libmesh.C:264
void libmesh_ignore(const T &)
const Parallel::Communicator & comm() const
template<typename T >
static std::map<Eigen::ComputationInfo, LinearConvergenceReason> libMesh::EigenSparseLinearSolver< T >::build_map ( )
inlinestaticprivate

Static function used to initialize _convergence_reasons map

Definition at line 153 of file eigen_sparse_linear_solver.h.

References libMesh::CONVERGED_ITS, libMesh::DIVERGED_BREAKDOWN, libMesh::DIVERGED_ITS, and libMesh::DIVERGED_NULL.

154  {
155  std::map<Eigen::ComputationInfo, LinearConvergenceReason> ret;
156  ret[Eigen::Success] = CONVERGED_ITS;
157  ret[Eigen::NumericalIssue] = DIVERGED_BREAKDOWN;
158  ret[Eigen::NoConvergence] = DIVERGED_ITS;
159  ret[Eigen::InvalidInput] = DIVERGED_NULL;
160  return ret;
161  }
const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inlineinherited
Returns
A reference to the Parallel::Communicator object used by this mesh.

Definition at line 87 of file parallel_object.h.

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_petsc_snes_jacobian(), libMesh::__libmesh_petsc_snes_postcheck(), libMesh::__libmesh_petsc_snes_residual(), libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_equality_constraints_jacobian(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_hessian(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints_jacobian(), libMesh::__libmesh_tao_objective(), libMesh::MeshRefinement::_coarsen_elements(), libMesh::ExactSolution::_compute_error(), libMesh::ParmetisPartitioner::_do_repartition(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), libMesh::EquationSystems::_read_impl(), libMesh::MeshRefinement::_refine_elements(), libMesh::MeshRefinement::_smooth_flags(), libMesh::ImplicitSystem::add_matrix(), libMesh::System::add_vector(), libMesh::EigenSparseLinearSolver< T >::adjoint_solve(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::DofMap::attach_matrix(), libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), libMesh::Parallel::Sort< KeyType, IdxType >::binsort(), libMesh::MeshCommunication::broadcast(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram(), libMesh::PetscNonlinearSolver< T >::build_mat_null_space(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::MeshBase::cache_elem_dims(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::DistributedVector< T >::clone(), libMesh::EigenSparseVector< T >::clone(), libMesh::LaspackVector< T >::clone(), libMesh::EpetraVector< T >::clone(), libMesh::PetscVector< T >::clone(), libMesh::EpetraVector< T >::close(), libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins(), 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::MeshTools::create_bounding_box(), libMesh::MeshTools::create_nodal_bounding_box(), libMesh::MeshRefinement::create_parent_error_vector(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::MeshTools::create_subdomain_bounding_box(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::EpetraVector< T >::EpetraVector(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::EquationSystems::get_solution(), libMesh::LocationMap< T >::init(), libMesh::PetscDiffSolver::init(), libMesh::TimeSolver::init(), libMesh::TopologyMap::init(), libMesh::TaoOptimizationSolver< T >::init(), libMesh::PetscNonlinearSolver< T >::init(), libMesh::DistributedVector< T >::init(), libMesh::EpetraVector< T >::init(), libMesh::PetscVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ParmetisPartitioner::initialize(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_flags(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_p_levels(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshTools::libmesh_assert_valid_unique_ids(), libMesh::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::limit_overrefined_boundary(), libMesh::MeshRefinement::limit_underrefined_boundary(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshRefinement::make_flags_parallel_consistent(), libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_unique_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::DistributedVector< T >::max(), libMesh::FEMSystem::mesh_position_set(), libMesh::MeshSerializer::MeshSerializer(), libMesh::DistributedVector< T >::min(), libMesh::DistributedMesh::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::BoundaryInfo::n_shellface_conds(), libMesh::DistributedMesh::parallel_max_elem_id(), libMesh::DistributedMesh::parallel_max_node_id(), libMesh::ReplicatedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_n_elem(), libMesh::DistributedMesh::parallel_n_nodes(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MeshTools::paranoid_n_levels(), libMesh::Partitioner::partition(), libMesh::MetisPartitioner::partition_range(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::SparseMatrix< T >::print(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::Parallel::sync_element_data_by_parent_id(), libMesh::Parallel::sync_node_data_by_element_id(), libMesh::MeshRefinement::test_level_one(), libMesh::MeshRefinement::test_unflagged(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::DistributedVector< T >::zero_clone(), libMesh::LaspackVector< T >::zero_clone(), libMesh::EigenSparseVector< T >::zero_clone(), libMesh::EpetraVector< T >::zero_clone(), and libMesh::PetscVector< T >::zero_clone().

88  { return _communicator; }
const Parallel::Communicator & _communicator
void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited
void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

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

Definition at line 101 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

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

102 {
103  _enable_print_counter = true;
104  return;
105 }
template<typename T >
LinearConvergenceReason libMesh::EigenSparseLinearSolver< T >::get_converged_reason ( ) const
virtual
Returns
The solver's convergence flag

Implements libMesh::LinearSolver< T >.

Definition at line 317 of file eigen_sparse_linear_solver.C.

References libMesh::EigenSparseLinearSolver< T >::_comp_info, libMesh::EigenSparseLinearSolver< T >::_convergence_reasons, and libMesh::CONVERGED_ITS.

318 {
319  std::map<Eigen::ComputationInfo, LinearConvergenceReason>::iterator it =
321 
322  // If later versions of Eigen start returning new enumerations,
323  // we'll need to add them to the map...
324  if (it == _convergence_reasons.end())
325  {
326  libmesh_warning("Warning: unknown Eigen::ComputationInfo: " \
327  << _comp_info \
328  << " returning CONVERGED_ITS." \
329  << std::endl);
330  return CONVERGED_ITS;
331  }
332  else
333  return it->second;
334 }
static std::map< Eigen::ComputationInfo, LinearConvergenceReason > _convergence_reasons
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 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
template<typename T >
bool libMesh::LinearSolver< T >::get_same_preconditioner ( )
inlineinherited
Returns
same_preconditioner, which indicates if we reuse the same preconditioner for subsequent solves.

Definition at line 326 of file linear_solver.h.

References libMesh::LinearSolver< T >::same_preconditioner.

Referenced by libMesh::LinearSolver< Number >::set_solver_type().

327 {
328  return same_preconditioner;
329 }
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 185 of file reference_counter.h.

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

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

186 {
187  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188  std::pair<unsigned int, unsigned int> & p = _counts[name];
189 
190  p.first++;
191 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
spin_mutex spin_mtx
Definition: threads.C:29
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 198 of file reference_counter.h.

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

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

199 {
200  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
201  std::pair<unsigned int, unsigned int> & p = _counts[name];
202 
203  p.second++;
204 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
spin_mutex spin_mtx
Definition: threads.C:29
template<typename T >
void libMesh::EigenSparseLinearSolver< T >::init ( const char *  name = libmesh_nullptr)
virtual

Initialize data structures if not done so already.

Implements libMesh::LinearSolver< T >.

Definition at line 68 of file eigen_sparse_linear_solver.C.

References libMesh::LinearSolver< T >::_is_initialized, and libMesh::LinearSolver< T >::initialized().

Referenced by libMesh::EigenSparseLinearSolver< T >::solve().

69 {
70  // Initialize the data structures if not done so already.
71  if (!this->initialized())
72  {
73  this->_is_initialized = true;
74  }
75 }
bool initialized() const
Definition: linear_solver.h:85
template<typename T>
virtual void libMesh::LinearSolver< T >::init_names ( const System )
inlinevirtualinherited

Apply names to the system to be solved. For most packages this is a no-op; for PETSc this sets an option prefix from the system name and sets field names from the system's variable names.

Since field names are applied to DoF numberings, this method must be called again after any System reinit.

Reimplemented in libMesh::PetscLinearSolver< T >.

Definition at line 106 of file linear_solver.h.

106 {}
template<typename T>
bool libMesh::LinearSolver< T >::initialized ( ) const
inlineinherited
Returns
true if the data structures are initialized, false otherwise.

Definition at line 85 of file linear_solver.h.

Referenced by libMesh::EigenSparseLinearSolver< T >::clear(), and libMesh::EigenSparseLinearSolver< T >::init().

85 { return _is_initialized; }
static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited
processor_id_type libMesh::ParallelObject::n_processors ( ) const
inlineinherited
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::ParmetisPartitioner::_do_repartition(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::DistributedMesh::add_elem(), libMesh::DistributedMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::MeshCommunication::broadcast(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DistributedMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::MeshBase::get_info(), libMesh::EquationSystems::get_solution(), libMesh::DistributedVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::DistributedMesh::insert_elem(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::DofMap::local_variable_indices(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::n_active_elem_on_proc(), libMesh::MeshBase::n_elem_on_proc(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::SparsityPattern::Build::parallel_sync(), 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::SparseMatrix< T >::print(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_nodes(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::Partitioner::repartition(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

94  { return cast_int<processor_id_type>(_communicator.size()); }
unsigned int size() const
Definition: parallel.h:722
const Parallel::Communicator & _communicator
template<typename T >
PreconditionerType libMesh::LinearSolver< T >::preconditioner_type ( ) const
inherited
Returns
The type of preconditioner to use.

Definition at line 83 of file linear_solver.C.

Referenced by libMesh::LinearSolver< Number >::set_solver_type().

84 {
85  if (_preconditioner)
86  return _preconditioner->type();
87 
88  return _preconditioner_type;
89 }
Preconditioner< T > * _preconditioner
PreconditionerType _preconditioner_type
template<typename T >
void libMesh::LinearSolver< T >::print_converged_reason ( ) const
virtualinherited

Prints a useful message about why the latest linear solve con(di)verged.

Reimplemented in libMesh::AztecLinearSolver< T >, and libMesh::LaspackLinearSolver< T >.

Definition at line 155 of file linear_solver.C.

References libMesh::Utility::enum_to_string(), and libMesh::out.

Referenced by libMesh::LinearSolver< Number >::set_solver_type().

156 {
158  libMesh::out << "Linear solver convergence/divergence reason: " << Utility::enum_to_string(reason) << std::endl;
159 }
virtual LinearConvergenceReason get_converged_reason() const =0
std::string enum_to_string(const T e)
OStreamProxy out(std::cout)
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().

Referenced by libMesh::LibMeshInit::LibMeshInit().

89 {
91  out_stream << ReferenceCounter::get_info();
92 }
static std::string get_info()
processor_id_type libMesh::ParallelObject::processor_id ( ) const
inlineinherited
Returns
The rank of this processor in the group.

Definition at line 99 of file parallel_object.h.

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

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::EquationSystems::_read_impl(), libMesh::DistributedMesh::add_elem(), libMesh::BoundaryInfo::add_elements(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::MeshRefinement::add_node(), libMesh::MeshTools::Modification::all_tri(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::MeshCommunication::broadcast(), 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::BoundaryInfo::build_node_list_from_side_list(), libMesh::DofMap::build_sparsity(), libMesh::DistributedMesh::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::MeshTools::correct_node_proc_ids(), libMesh::ExodusII_IO_Helper::create(), libMesh::DistributedMesh::delete_elem(), libMesh::DistributedMesh::delete_node(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshFunction::find_element(), libMesh::MeshFunction::find_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), 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::DofMap::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::EquationSystems::get_solution(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::SparsityPattern::Build::handle_vi_vj(), libMesh::DistributedVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::initialize_element_variables(), libMesh::ExodusII_IO_Helper::initialize_global_variables(), libMesh::ExodusII_IO_Helper::initialize_nodal_variables(), libMesh::DistributedMesh::insert_elem(), libMesh::DofMap::is_evaluable(), libMesh::SparsityPattern::Build::join(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DofMap::local_variable_indices(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::n_active_local_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::System::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MetisPartitioner::partition_range(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NumericVector< T >::print_global(), 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::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::CheckpointIO::read_header(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::Parallel::Packing< Node * >::unpack(), libMesh::Parallel::Packing< Elem * >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::MeshTools::weight(), libMesh::NameBasedIO::write(), libMesh::CheckpointIO::write(), libMesh::XdrIO::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::write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), libMesh::ExodusII_IO::write_information_records(), libMesh::ExodusII_IO_Helper::write_information_records(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), 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::Nemesis_IO_Helper::write_nodesets(), libMesh::ExodusII_IO_Helper::write_nodesets(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO_Helper::write_sidesets(), libMesh::ExodusII_IO::write_timestep(), and libMesh::ExodusII_IO_Helper::write_timestep().

100  { return cast_int<processor_id_type>(_communicator.rank()); }
const Parallel::Communicator & _communicator
unsigned int rank() const
Definition: parallel.h:720
template<typename T >
void libMesh::LinearSolver< T >::restrict_solve_to ( const std::vector< unsigned int > *const  dofs,
const SubsetSolveMode  subset_solve_mode = SUBSET_ZERO 
)
virtualinherited

After calling this method, all successive solves will be restricted to the given set of dofs, which must contain local dofs on each processor only and not contain any duplicates. This mode can be disabled by calling this method with dofs being a NULL pointer.

Reimplemented in libMesh::PetscLinearSolver< T >.

Definition at line 121 of file linear_solver.C.

References libmesh_nullptr.

Referenced by libMesh::LinearSolver< Number >::set_solver_type().

123 {
124  if (dofs != libmesh_nullptr)
125  libmesh_not_implemented();
126 }
const class libmesh_nullptr_t libmesh_nullptr
template<typename T >
void libMesh::LinearSolver< T >::reuse_preconditioner ( bool  reuse_flag)
virtualinherited

Set the same_preconditioner flag, which indicates if we reuse the same preconditioner for subsequent solves.

Definition at line 114 of file linear_solver.C.

Referenced by libMesh::ImplicitSystem::disable_cache(), and libMesh::LinearSolver< Number >::set_solver_type().

115 {
116  same_preconditioner = reuse_flag;
117 }
template<typename T >
void libMesh::EigenSparseLinearSolver< T >::set_eigen_preconditioner_type ( )
private

Tells Eigen to use the user-specified preconditioner stored in _preconditioner_type

Definition at line 286 of file eigen_sparse_linear_solver.C.

287 {
288  libmesh_not_implemented();
289 
290  // switch (this->_preconditioner_type)
291  // {
292  // case IDENTITY_PRECOND:
293  // _precond_type = libmesh_nullptr; return;
294 
295  // case ILU_PRECOND:
296  // _precond_type = ILUPrecond; return;
297 
298  // case JACOBI_PRECOND:
299  // _precond_type = JacobiPrecond; return;
300 
301  // case SSOR_PRECOND:
302  // _precond_type = SSORPrecond; return;
303 
304 
305  // default:
306  // libMesh::err << "ERROR: Unsupported LASPACK Preconditioner: "
307  // << this->_preconditioner_type << std::endl
308  // << "Continuing with ILU" << std::endl;
309  // this->_preconditioner_type = ILU_PRECOND;
310  // this->set_laspack_preconditioner_type();
311  // }
312 }
template<typename T >
void libMesh::LinearSolver< T >::set_preconditioner_type ( const PreconditionerType  pct)
inherited

Sets the type of preconditioner to use.

Definition at line 93 of file linear_solver.C.

Referenced by libMesh::LinearSolver< Number >::set_solver_type().

94 {
95  if (_preconditioner)
96  _preconditioner->set_type(pct);
97  else
99 }
Preconditioner< T > * _preconditioner
PreconditionerType _preconditioner_type
template<typename T >
void libMesh::LinearSolver< T >::set_solver_configuration ( SolverConfiguration solver_configuration)
inherited

Set the solver configuration object.

Definition at line 162 of file linear_solver.C.

Referenced by libMesh::LinearSolver< Number >::set_solver_type().

163 {
164  _solver_configuration = &solver_configuration;
165 }
SolverConfiguration * _solver_configuration
template<typename T>
void libMesh::LinearSolver< T >::set_solver_type ( const SolverType  st)
inlineinherited

Sets the type of solver to use.

Definition at line 116 of file linear_solver.h.

117  { _solver_type = st; }
template<typename T >
std::pair< unsigned int, Real > libMesh::EigenSparseLinearSolver< T >::solve ( SparseMatrix< T > &  matrix,
NumericVector< T > &  solution,
NumericVector< T > &  rhs,
const double  tol,
const unsigned int  m_its 
)
virtual

Call the Eigen solver

Implements libMesh::LinearSolver< T >.

Definition at line 81 of file eigen_sparse_linear_solver.C.

References libMesh::EigenSparseLinearSolver< T >::_comp_info, libMesh::EigenSparseMatrix< T >::_mat, libMesh::LinearSolver< T >::_solver_configuration, libMesh::LinearSolver< T >::_solver_type, libMesh::BICGSTAB, libMesh::CG, libMesh::EigenSparseMatrix< T >::close(), libMesh::Utility::enum_to_string(), libMesh::err, libMesh::GMRES, libMesh::EigenSparseLinearSolver< T >::init(), libMesh::SolverConfiguration::int_valued_data, libMesh::out, libMesh::PetscDiffSolver::solve(), libMesh::solver, and libMesh::SPARSELU.

Referenced by libMesh::EigenSparseLinearSolver< T >::adjoint_solve().

86 {
87  LOG_SCOPE("solve()", "EigenSparseLinearSolver");
88  this->init ();
89 
90  // Make sure the data passed in are really Eigen types
91  EigenSparseMatrix<T> & matrix = cast_ref<EigenSparseMatrix<T> &>(matrix_in);
92  EigenSparseVector<T> & solution = cast_ref<EigenSparseVector<T> &>(solution_in);
93  EigenSparseVector<T> & rhs = cast_ref<EigenSparseVector<T> &>(rhs_in);
94 
95  // Close the matrix and vectors in case this wasn't already done.
96  matrix.close();
97  solution.close();
98  rhs.close();
99 
100  std::pair<unsigned int, Real> retval(0,0.);
101 
102  // Solve the linear system
103  switch (this->_solver_type)
104  {
105  // Conjugate-Gradient
106  case CG:
107  {
108  Eigen::ConjugateGradient<EigenSM> solver (matrix._mat);
109  solver.setMaxIterations(m_its);
110  solver.setTolerance(tol);
111  solution._vec = solver.solveWithGuess(rhs._vec,solution._vec);
112  libMesh::out << "#iterations: " << solver.iterations() << std::endl;
113  libMesh::out << "estimated error: " << solver.error() << std::endl;
114  retval = std::make_pair(solver.iterations(), solver.error());
115  _comp_info = solver.info();
116  break;
117  }
118 
119  // Bi-Conjugate Gradient Stabilized
120  case BICGSTAB:
121  {
122  Eigen::BiCGSTAB<EigenSM> solver (matrix._mat);
123  solver.setMaxIterations(m_its);
124  solver.setTolerance(tol);
125  solution._vec = solver.solveWithGuess(rhs._vec,solution._vec);
126  libMesh::out << "#iterations: " << solver.iterations() << std::endl;
127  libMesh::out << "estimated error: " << solver.error() << std::endl;
128  retval = std::make_pair(solver.iterations(), solver.error());
129  _comp_info = solver.info();
130  break;
131  }
132 
133  // Generalized Minimum Residual
134  case GMRES:
135  {
136  Eigen::GMRES<EigenSM> solver (matrix._mat);
137  solver.setMaxIterations(m_its);
138  solver.setTolerance(tol);
139 
140  // If there is an int parameter called "gmres_restart" in the
141  // SolverConfiguration object, pass it to the Eigen GMRES
142  // solver.
143  if (this->_solver_configuration)
144  {
145  std::map<std::string, int>::iterator it =
146  this->_solver_configuration->int_valued_data.find("gmres_restart");
147 
148  if (it != this->_solver_configuration->int_valued_data.end())
149  solver.set_restart(it->second);
150  }
151 
152  libMesh::out << "Eigen GMRES solver, restart = " << solver.get_restart() << std::endl;
153  solution._vec = solver.solveWithGuess(rhs._vec, solution._vec);
154  libMesh::out << "#iterations: " << solver.iterations() << std::endl;
155  libMesh::out << "estimated error: " << solver.error() << std::endl;
156  retval = std::make_pair(solver.iterations(), solver.error());
157  _comp_info = solver.info();
158  break;
159  }
160 
161  case SPARSELU:
162  {
163  // SparseLU solver code adapted from:
164  // http://eigen.tuxfamily.org/dox-devel/classEigen_1_1SparseLU.html
165  //
166  // From Eigen docs:
167  // The input matrix A should be in a compressed and
168  // column-major form. Otherwise an expensive copy will be
169  // made. You can call the inexpensive makeCompressed() to get
170  // a compressed matrix.
171  //
172  // Note: we don't have a column-major storage format here, so
173  // I think a copy must be made in order to use SparseLU. It
174  // appears that we also have to call makeCompressed(),
175  // otherwise you get a segfault.
176  matrix._mat.makeCompressed();
177 
178  // Build the SparseLU solver object. Note, there is one other
179  // sparse direct solver available in Eigen:
180  //
181  // Eigen::SparseQR<EigenSM, Eigen::AMDOrdering<int> > solver;
182  //
183  // I've tested it, and it works, but it is much slower than
184  // SparseLU. The main benefit of SparseQR is that it can
185  // handle non-square matrices, but we don't allow non-square
186  // sparse matrices to be built in libmesh...
187  Eigen::SparseLU<EigenSM> solver;
188 
189  // Compute the ordering permutation vector from the structural pattern of the matrix.
190  solver.analyzePattern(matrix._mat);
191 
192  // Compute the numerical factorization
193  solver.factorize(matrix._mat);
194 
195  // Use the factors to solve the linear system
196  solution._vec = solver.solve(rhs._vec);
197 
198  // Set up the return value. The SparseLU solver doesn't
199  // support asking for the number of iterations or the final
200  // error, so we'll just report back 1 and 0, respectively.
201  retval = std::make_pair(/*n. iterations=*/1, /*error=*/0);
202 
203  // Store the success/failure reason and break out.
204  _comp_info = solver.info();
205  break;
206  }
207 
208  // Unknown solver, use BICGSTAB
209  default:
210  {
211  libMesh::err << "ERROR: Unsupported Eigen Solver: "
212  << Utility::enum_to_string(this->_solver_type) << std::endl
213  << "Continuing with BICGSTAB" << std::endl;
214 
215  this->_solver_type = BICGSTAB;
216 
217  return this->solve (matrix,
218  solution,
219  rhs,
220  tol,
221  m_its);
222  }
223  }
224 
225  return retval;
226 }
PetscDiffSolver & solver
std::map< std::string, int > int_valued_data
SolverConfiguration * _solver_configuration
OStreamProxy err(std::cerr)
std::string enum_to_string(const T e)
virtual unsigned int solve() libmesh_override
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &matrix, NumericVector< T > &solution, NumericVector< T > &rhs, const double tol, const unsigned int m_its) libmesh_override
OStreamProxy out(std::cout)
virtual void init(const char *name=libmesh_nullptr) libmesh_override
template<typename T >
std::pair< unsigned int, Real > libMesh::EigenSparseLinearSolver< T >::solve ( SparseMatrix< T > &  matrix,
SparseMatrix< T > &  pc,
NumericVector< T > &  solution,
NumericVector< T > &  rhs,
const double  tol,
const unsigned int  m_its 
)
inlinevirtual

Call the Eigen solver

Implements libMesh::LinearSolver< T >.

Definition at line 187 of file eigen_sparse_linear_solver.h.

193 {
194  libmesh_error_msg("ERROR: Eigen does not support a user-supplied preconditioner!");
195 
196  std::pair<unsigned int, Real> p;
197  return p;
198 }
template<typename T >
std::pair< unsigned int, Real > libMesh::EigenSparseLinearSolver< T >::solve ( const ShellMatrix< T > &  shell_matrix,
NumericVector< T > &  solution_in,
NumericVector< T > &  rhs_in,
const double  tol,
const unsigned int  m_its 
)
virtual

This function solves a system whose matrix is a shell matrix.

Implements libMesh::LinearSolver< T >.

Definition at line 258 of file eigen_sparse_linear_solver.C.

263 {
264  libmesh_not_implemented();
265  return std::make_pair(0,0.0);
266 }
template<typename T >
std::pair< unsigned int, Real > libMesh::EigenSparseLinearSolver< T >::solve ( const ShellMatrix< T > &  shell_matrix,
const SparseMatrix< T > &  precond_matrix,
NumericVector< T > &  solution_in,
NumericVector< T > &  rhs_in,
const double  tol,
const unsigned int  m_its 
)
virtual

This function solves a system whose matrix is a shell matrix, but a sparse matrix is used as preconditioning matrix, this allowing other preconditioners than JACOBI.

Implements libMesh::LinearSolver< T >.

Definition at line 272 of file eigen_sparse_linear_solver.C.

278 {
279  libmesh_not_implemented();
280  return std::make_pair(0,0.0);
281 }
template<typename T>
std::pair< unsigned int, Real > libMesh::LinearSolver< T >::solve ( SparseMatrix< T > &  matrix,
SparseMatrix< T > *  precond_matrix,
NumericVector< T > &  sol,
NumericVector< T > &  rhs,
const double  tol,
const unsigned int  n_iter 
)
inlineinherited

This function calls the solver "_solver_type" preconditioned with the "_preconditioner_type" preconditioner. The preconditioning matrix is used if it is provided, or the system matrix is used if precond_matrix is null

Definition at line 334 of file linear_solver.h.

References libMesh::LinearSolver< T >::solve().

340 {
341  if (pc_mat)
342  return this->solve(mat, *pc_mat, sol, rhs, tol, n_iter);
343  else
344  return this->solve(mat, sol, rhs, tol, n_iter);
345 }
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0
template<typename T>
std::pair< unsigned int, Real > libMesh::LinearSolver< T >::solve ( const ShellMatrix< T > &  matrix,
const SparseMatrix< T > *  precond_matrix,
NumericVector< T > &  sol,
NumericVector< T > &  rhs,
const double  tol,
const unsigned int  n_iter 
)
inlineinherited

This function solves a system whose matrix is a shell matrix, but an optional sparse matrix may be used as preconditioning matrix.

Definition at line 351 of file linear_solver.h.

References libMesh::LinearSolver< T >::solve().

357 {
358  if (pc_mat)
359  return this->solve(mat, *pc_mat, sol, rhs, tol, n_iter);
360  else
361  return this->solve(mat, sol, rhs, tol, n_iter);
362 }
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0
template<typename T>
SolverType libMesh::LinearSolver< T >::solver_type ( ) const
inlineinherited
Returns
The type of solver to use.

Definition at line 111 of file linear_solver.h.

111 { return _solver_type; }

Member Data Documentation

template<typename T >
Eigen::ComputationInfo libMesh::EigenSparseLinearSolver< T >::_comp_info
private
template<typename T >
std::map< Eigen::ComputationInfo, LinearConvergenceReason > libMesh::EigenSparseLinearSolver< T >::_convergence_reasons = EigenSparseLinearSolver<T>::build_map()
staticprivate

Static map between Eigen ComputationInfo enumerations and libMesh LinearConvergenceReason enumerations.

Definition at line 148 of file eigen_sparse_linear_solver.h.

Referenced by libMesh::EigenSparseLinearSolver< T >::get_converged_reason().

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

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

template<typename T>
bool libMesh::LinearSolver< T >::_is_initialized
protectedinherited

Flag indicating if the data structures have been initialized.

Definition at line 276 of file linear_solver.h.

Referenced by libMesh::EigenSparseLinearSolver< T >::clear(), libMesh::EigenSparseLinearSolver< T >::init(), and libMesh::LinearSolver< Number >::initialized().

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

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 137 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 132 of file reference_counter.h.

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

template<typename T>
Preconditioner<T>* libMesh::LinearSolver< T >::_preconditioner
protectedinherited

Holds the Preconditioner object to be used for the linear solves.

Definition at line 281 of file linear_solver.h.

template<typename T>
PreconditionerType libMesh::LinearSolver< T >::_preconditioner_type
protectedinherited
template<typename T>
SolverConfiguration* libMesh::LinearSolver< T >::_solver_configuration
protectedinherited

Optionally store a SolverOptions object that can be used to set parameters like solver type, tolerances and iteration limits.

Definition at line 295 of file linear_solver.h.

Referenced by libMesh::EigenSparseLinearSolver< T >::solve().

template<typename T>
bool libMesh::LinearSolver< T >::same_preconditioner
protectedinherited

Boolean flag to indicate whether we want to use an identical preconditioner to the previous solve. This can save substantial work in the cases where the system matrix is the same for successive solves.

Definition at line 289 of file linear_solver.h.

Referenced by libMesh::LinearSolver< T >::get_same_preconditioner().


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