libMesh
Loading...
Searching...
No Matches
eigen_solver.C
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
31namespace libMesh
32{
33
34
35//------------------------------------------------------------------
36// EigenSolver members
37template <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
51template <typename T>
53
54
55
56template <typename T>
57std::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
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
78template <typename T>
80{
81 _solver_configuration = &solver_configuration;
82}
83
84template <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
95template <typename T>
97{
98 _position_of_spectrum = target;
99 _target_val = pos;
100}
101
102
103
104//------------------------------------------------------------------
105// Explicit instantiations
106template class LIBMESH_EXPORT EigenSolver<Number>;
107
108} // namespace libMesh
109
110
111#endif // LIBMESH_HAVE_SLEPC
This class provides an interface to solvers for eigenvalue problems.
static std::unique_ptr< EigenSolver< T > > build(const Parallel::Communicator &comm_in, const SolverPackage solver_package=SLEPC_SOLVERS)
Builds an EigenSolver using the linear solver package specified by solver_package.
void set_position_of_spectrum(PositionOfSpectrum pos)
Sets the position of the spectrum.
virtual ~EigenSolver()
Destructor.
EigenSolver(const Parallel::Communicator &comm_in)
Constructor.
void set_solver_configuration(SolverConfiguration &solver_configuration)
Set the solver configuration object.
An object whose state is distributed along a set of processors.
This class stores solver configuration data, e.g.
The libMesh namespace provides an interface to certain functionality in the library.
PositionOfSpectrum
Defines an enum for the position of the spectrum, i.e.
SolverPackage
Defines an enum for various linear solver packages.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real