libMesh
eigen_solver.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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/enum_eigen_solver_type.h"
27 
28 // C++ Includes
29 #include <memory>
30 
31 namespace libMesh
32 {
33 
34 
35 //------------------------------------------------------------------
36 // EigenSolver members
37 template <typename T>
39  ParallelObject(comm_in),
40  _eigen_solver_type (ARNOLDI),
41  _eigen_problem_type (NHEP),
42  _position_of_spectrum (LARGEST_MAGNITUDE),
43  _is_initialized (false),
44  _solver_configuration(nullptr),
45  _close_matrix_before_solve(true)
46 {
47 }
48 
49 
50 
51 template <typename T>
52 EigenSolver<T>::~EigenSolver () = default;
53 
54 
55 
56 template <typename T>
57 std::unique_ptr<EigenSolver<T>>
59  const SolverPackage solver_package)
60 {
61  // Build the appropriate solver
62  switch (solver_package)
63  {
64 
65 #ifdef LIBMESH_HAVE_SLEPC
66  case SLEPC_SOLVERS:
67  return std::make_unique<SlepcEigenSolver<T>>(comm);
68 #endif
69 
70  default:
71  libmesh_error_msg("ERROR: Unrecognized eigen solver package: " << solver_package);
72  }
73 
74  return std::unique_ptr<EigenSolver<T>>();
75 }
76 
77 
78 template <typename T>
80 {
81  _solver_configuration = &solver_configuration;
82 }
83 
84 template <typename T>
86 {
87  if (pos >= 0)
88  _position_of_spectrum = TARGET_MAGNITUDE;
89  else
90  _position_of_spectrum = TARGET_REAL;
91 
92  _target_val = pos;
93 }
94 
95 template <typename T>
97 {
98  _position_of_spectrum = target;
99  _target_val = pos;
100 }
101 
102 
103 
104 //------------------------------------------------------------------
105 // Explicit instantiations
106 template class LIBMESH_EXPORT EigenSolver<Number>;
107 
108 } // namespace libMesh
109 
110 
111 #endif // LIBMESH_HAVE_SLEPC
The libMesh namespace provides an interface to certain functionality in the library.
bool _is_initialized
Flag that tells if init() has been called.
Definition: libmesh.C:257
This class stores solver configuration data, e.g.
PositionOfSpectrum
Defines an enum for the position of the spectrum, i.e.
EigenSolver(const Parallel::Communicator &comm_in)
Constructor.
Definition: eigen_solver.C:38
An object whose state is distributed along a set of processors.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
SolverPackage
Defines an enum for various linear solver packages.
This class provides an interface to solvers for eigenvalue problems.
Definition: eigen_solver.h:58