MAST
slepc_eigen_solver.cpp
Go to the documentation of this file.
1 /*
2  * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3  * Copyright (C) 2013-2019 Manav Bhatia
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 // MAST includes
22 
23 // libMesh includes
24 #include "libmesh/petsc_vector.h"
25 #include "libmesh/enum_eigen_solver_type.h"
26 
27 
28 MAST::SlepcEigenSolver::SlepcEigenSolver(const libMesh::Parallel::Communicator & comm_in):
29 libMesh::SlepcEigenSolver<Real>(comm_in) {
30 
31 }
32 
33 
34 
35 
36 std::pair<Real, Real>
38 
39  PetscErrorCode ierr=0;
40 
41  PetscReal re, im;
42 
43  ierr = EPSGetEigenvalue(eps(), i, &re, &im);
44 
45  CHKERRABORT(this->comm().get(), ierr);
46 
47  return std::make_pair(re, im);
48 }
49 
50 
51 
52 
53 std::pair<Real, Real>
55  libMesh::NumericVector<Real> &eig_vec,
56  libMesh::NumericVector<Real> *eig_vec_im) {
57 
58  // make sure that for non-Hermitian problems with real matrices
59  // a vector is provided for imaginary part.
60 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
61  libmesh_assert(eig_vec_im == NULL);
62 #else
63  if (this->eigen_problem_type() == libMesh::HEP ||
64  this->eigen_problem_type() == libMesh::GHEP)
65  libmesh_assert(eig_vec_im == NULL);
66 #endif
67 
68  PetscErrorCode ierr=0;
69 
70  PetscReal re, im;
71 
72  // Make sure the NumericVector passed in is really a PetscVector
73  libMesh::PetscVector<Real>
74  *v_re = libMesh::cast_ptr<libMesh::PetscVector<Real>*>(&eig_vec),
75  *v_im = NULL;
76 
77  // real and imaginary part of the ith eigenvalue.
78  PetscScalar kr, ki;
79 
80  eig_vec.close();
81  if (eig_vec_im) {
82 
83  eig_vec_im = libMesh::libmesh_cast_ptr<libMesh::PetscVector<Real>*>(eig_vec_im);
84  eig_vec_im->close();
85 
86  // now get the eigenvector
87  ierr = EPSGetEigenpair(eps(), i, &kr, &ki, v_re->vec(), v_im->vec());
88  }
89  else
90  ierr = EPSGetEigenpair(eps(), i, &kr, &ki, v_re->vec(), PETSC_NULL);
91 
92  CHKERRABORT(this->comm().get(), ierr);
93 
94 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
95  re = PetscRealPart(kr);
96  im = PetscImaginaryPart(kr);
97 #else
98  re = kr;
99  im = ki;
100 #endif
101 
102  return std::make_pair(re, im);
103 }
104 
virtual std::pair< Real, Real > get_eigenpair(unsigned int i, libMesh::NumericVector< Real > &eig_vec, libMesh::NumericVector< Real > *eig_vec_im=libmesh_nullptr)
This function returns the real and imaginary part of the ith eigenvalue and copies the respective eig...
This class inherits from libMesh::SlepcEigenSolver<Real> and implements a method for retriving the re...
virtual std::pair< Real, Real > get_eigenvalue(unsigned int i)
This function returns the real and imaginary part of the ith eigenvalues.
libMesh::Real Real
SlepcEigenSolver(const libMesh::Parallel::Communicator &comm_in)