Line data Source code
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> 38 348 : EigenSolver<T>::EigenSolver (const Parallel::Communicator & comm_in) : 39 : ParallelObject(comm_in), 40 332 : _eigen_solver_type (ARNOLDI), 41 332 : _eigen_problem_type (NHEP), 42 332 : _position_of_spectrum (LARGEST_MAGNITUDE), 43 332 : _is_initialized (false), 44 332 : _solver_configuration(nullptr), 45 348 : _close_matrix_before_solve(true) 46 : { 47 348 : } 48 : 49 : 50 : 51 : template <typename T> 52 332 : EigenSolver<T>::~EigenSolver () = default; 53 : 54 : 55 : 56 : template <typename T> 57 : std::unique_ptr<EigenSolver<T>> 58 348 : EigenSolver<T>::build(const Parallel::Communicator & comm, 59 : const SolverPackage solver_package) 60 : { 61 : // Build the appropriate solver 62 348 : switch (solver_package) 63 : { 64 : 65 : #ifdef LIBMESH_HAVE_SLEPC 66 348 : case SLEPC_SOLVERS: 67 348 : return std::make_unique<SlepcEigenSolver<T>>(comm); 68 : #endif 69 : 70 0 : default: 71 0 : 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> 79 0 : void EigenSolver<T>::set_solver_configuration(SolverConfiguration & solver_configuration) 80 : { 81 0 : _solver_configuration = &solver_configuration; 82 0 : } 83 : 84 : template <typename T> 85 70 : void EigenSolver<T>::set_position_of_spectrum (Real pos) 86 : { 87 70 : if (pos >= 0) 88 70 : _position_of_spectrum = TARGET_MAGNITUDE; 89 : else 90 0 : _position_of_spectrum = TARGET_REAL; 91 : 92 70 : _target_val = pos; 93 70 : } 94 : 95 : template <typename T> 96 140 : void EigenSolver<T>::set_position_of_spectrum (Real pos, PositionOfSpectrum target) 97 : { 98 140 : _position_of_spectrum = target; 99 140 : _target_val = pos; 100 140 : } 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