libMesh
eigen_solver.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 #include "libmesh/libmesh_config.h"
20 #ifdef LIBMESH_HAVE_SLEPC
21 
22 // Local Includes
23 #include "libmesh/eigen_solver.h"
24 #include "libmesh/slepc_eigen_solver.h"
25 #include "libmesh/solver_configuration.h"
26 #include "libmesh/auto_ptr.h" // libmesh_make_unique
27 #include "libmesh/enum_eigen_solver_type.h"
28 
29 namespace libMesh
30 {
31 
32 
33 //------------------------------------------------------------------
34 // EigenSolver members
35 template <typename T>
36 EigenSolver<T>::EigenSolver (const Parallel::Communicator & comm_in) :
37  ParallelObject(comm_in),
38  _eigen_solver_type (ARNOLDI),
39  _eigen_problem_type (NHEP),
40  _position_of_spectrum (LARGEST_MAGNITUDE),
41  _is_initialized (false),
42  _solver_configuration(nullptr),
43  _close_matrix_before_solve(true)
44 {
45 }
46 
47 
48 
49 template <typename T>
51 {
52  this->clear ();
53 }
54 
55 
56 
57 template <typename T>
58 std::unique_ptr<EigenSolver<T>>
59 EigenSolver<T>::build(const Parallel::Communicator & comm,
60  const SolverPackage solver_package)
61 {
62  // Build the appropriate solver
63  switch (solver_package)
64  {
65 
66 #ifdef LIBMESH_HAVE_SLEPC
67  case SLEPC_SOLVERS:
68  return libmesh_make_unique<SlepcEigenSolver<T>>(comm);
69 #endif
70 
71  default:
72  libmesh_error_msg("ERROR: Unrecognized eigen solver package: " << solver_package);
73  }
74 
75  return std::unique_ptr<EigenSolver<T>>();
76 }
77 
78 
79 template <typename T>
81 {
82  _solver_configuration = &solver_configuration;
83 }
84 
85 template <typename T>
87 {
88  if (pos >= 0)
89  _position_of_spectrum = TARGET_MAGNITUDE;
90  else
91  _position_of_spectrum = TARGET_REAL;
92 
93  _target_val = pos;
94 }
95 
96 template <typename T>
98 {
99  _position_of_spectrum = target;
100  _target_val = pos;
101 }
102 
103 
104 
105 //------------------------------------------------------------------
106 // Explicit instantiations
107 template class EigenSolver<Number>;
108 
109 } // namespace libMesh
110 
111 
112 #endif // LIBMESH_HAVE_SLEPC
libMesh::SolverPackage
SolverPackage
Defines an enum for various linear solver packages.
Definition: enum_solver_package.h:34
libMesh::TARGET_REAL
Definition: enum_eigen_solver_type.h:80
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::EigenSolver::EigenSolver
EigenSolver(const Parallel::Communicator &comm_in)
Constructor.
Definition: eigen_solver.C:36
libMesh::ARNOLDI
Definition: enum_eigen_solver_type.h:37
libMesh::LARGEST_MAGNITUDE
Definition: enum_eigen_solver_type.h:75
libMesh::NHEP
Definition: enum_eigen_solver_type.h:55
libMesh::libMeshPrivateData::_is_initialized
bool _is_initialized
Flag that tells if init() has been called.
Definition: libmesh.C:246
libMesh::PositionOfSpectrum
PositionOfSpectrum
Defines an enum for the position of the spectrum, i.e.
Definition: enum_eigen_solver_type.h:74
libMesh::EigenSolver
This class provides an interface to solvers for eigenvalue problems.
Definition: eigen_solver.h:67
libMesh::SLEPC_SOLVERS
Definition: enum_solver_package.h:39
libMesh::SolverConfiguration
This class stores solver configuration data, e.g.
Definition: solver_configuration.h:39
libMesh::TARGET_MAGNITUDE
Definition: enum_eigen_solver_type.h:77
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::ParallelObject
An object whose state is distributed along a set of processors.
Definition: parallel_object.h:55