21 gsStatus gsEigenProblemBase<T>::compute()
26 bool verbose = m_options.getSwitch(
"verbose");
27 if (verbose) {
gsInfo<<
"Solving eigenvalue problem" ; }
30 T shift = m_options.getReal(
"shift");
32 m_eigSolver.compute(m_A-shift*m_B,m_B);
34 m_eigSolver.compute(m_A,m_B);
36 if (verbose) {
gsInfo<<
"." ; }
37 m_values = m_eigSolver.eigenvalues();
38 m_values.array() += shift;
39 if (verbose) {
gsInfo<<
"." ; }
40 m_vectors = m_eigSolver.eigenvectors();
41 if (verbose) {
gsInfo<<
"." ; }
42 if (verbose) {
gsInfo<<
"Finished\n" ; }
59 #ifdef gsSpectra_ENABLED
60 if (m_options.getInt(
"solver")==0)
61 return computeSparse_impl<Spectra::GEigsMode::Cholesky>(number);
62 else if (m_options.getInt(
"solver")==1)
63 return computeSparse_impl<Spectra::GEigsMode::RegularInverse>(number);
64 else if (m_options.getInt(
"solver")==2)
65 return computeSparse_impl<Spectra::GEigsMode::ShiftInvert>(number);
66 else if (m_options.getInt(
"solver")==3)
67 return computeSparse_impl<Spectra::GEigsMode::Buckling>(number);
68 else if (m_options.getInt(
"solver")==4)
69 return computeSparse_impl<Spectra::GEigsMode::Cayley>(number);
72 gsWarn<<
"Solver index "<<m_options.getInt(
"solver")<<
" unknown.\n";
77 gsWarn<<
"Sparse solver is not implemented without gsSpectra. Please compile gismo with Spectra.\n";
83 #ifdef gsSpectra_ENABLED
85 template< Spectra::GEigsMode _GEigsMode>
86 typename std::enable_if<_GEigsMode==Spectra::GEigsMode::Cholesky ||
87 _GEigsMode==Spectra::GEigsMode::RegularInverse
90 gsEigenProblemBase<T>::computeSparse_impl(
index_t number)
92 bool verbose = m_options.getSwitch(
"verbose");
93 T shift = m_options.getReal(
"shift");
95 Spectra::SortRule selectionRule =
static_cast<Spectra::SortRule
>(m_options.getInt(
"selectionRule"));
96 Spectra::SortRule sortRule =
static_cast<Spectra::SortRule
>(m_options.getInt(
"sortRule"));
98 index_t ncvFac = m_options.getInt(
"ncvFac");
99 T tol = m_options.getReal(
"tolerance");
100 if (verbose) {
gsInfo<<
"Solving eigenvalue problem" ; }
102 gsSparseMatrix<T> Atmp;
104 Atmp = m_A-shift*m_B;
108 gsSpectraGenSymSolver<gsSparseMatrix<T>,_GEigsMode> solver(Atmp,m_B,number,ncvFac*number);
110 if (verbose) {
gsInfo<<
"." ; }
112 if (verbose) {
gsInfo<<
"." ; }
113 solver.compute(selectionRule,1000,tol,sortRule);
115 if (solver.info()==Spectra::CompInfo::Successful)
117 gsDebug<<
"Spectra converged in "<<solver.num_iterations()<<
" iterations and with "<<solver.num_operations()<<
"operations. \n";
118 if (verbose) {
gsInfo<<
"." ; }
119 m_values = solver.eigenvalues();
120 m_values.array() += shift;
121 if (verbose) {
gsInfo<<
"." ; }
122 m_vectors = solver.eigenvectors();
123 if (verbose) {
gsInfo<<
"Finished\n" ; }
127 else if (solver.info()==Spectra::CompInfo::NotConverging)
129 gsWarn<<
"Spectra did not converge! Error code: NotConverging\n";
132 else if (solver.info()==Spectra::CompInfo::NumericalIssue)
134 gsWarn<<
"Spectra did not converge! Error code: NumericalIssue\n";
137 else if (solver.info()==Spectra::CompInfo::NotComputed)
139 gsWarn<<
"Spectra did not converge! Error code: NotComputed\n";
144 gsWarn<<
"No error code known\n";
151 #ifdef gsSpectra_ENABLED
153 template< Spectra::GEigsMode _GEigsMode>
154 typename std::enable_if<_GEigsMode==Spectra::GEigsMode::ShiftInvert ||
155 _GEigsMode==Spectra::GEigsMode::Buckling ||
156 _GEigsMode==Spectra::GEigsMode::Cayley
159 gsEigenProblemBase<T>::computeSparse_impl(
index_t number)
161 bool verbose = m_options.getSwitch(
"verbose");
162 T shift = m_options.getReal(
"shift");
164 Spectra::SortRule selectionRule =
static_cast<Spectra::SortRule
>(m_options.getInt(
"selectionRule"));
165 Spectra::SortRule sortRule =
static_cast<Spectra::SortRule
>(m_options.getInt(
"sortRule"));
167 if (selectionRule == Spectra::SortRule::SmallestMagn )
168 gsWarn<<
"Selection Rule 'SmallestMagn' is selected, but for ShiftInvert, Buckling and Cayley it is advised to use 'LargestMagn'!\n";
169 if (selectionRule == Spectra::SortRule::SmallestAlge )
170 gsWarn<<
"Selection Rule 'SmallestAlge' is selected, but for ShiftInvert, Buckling and Cayley it is advised to use 'LargestMagn'!\n";
172 index_t ncvFac = m_options.getInt(
"ncvFac");
173 T tol = m_options.getReal(
"tolerance");
174 if (verbose) {
gsInfo<<
"Solving eigenvalue problem" ; }
175 gsSpectraGenSymShiftSolver<gsSparseMatrix<T>,_GEigsMode> solver(m_A,m_B,number,ncvFac*number,shift);
176 if (verbose) {
gsInfo<<
"." ; }
178 if (verbose) {
gsInfo<<
"." ; }
179 solver.compute(selectionRule,1000,tol,sortRule);
181 if (solver.info()==Spectra::CompInfo::Successful)
183 gsDebug<<
"Spectra converged in "<<solver.num_iterations()<<
" iterations and with "<<solver.num_operations()<<
"operations. \n";
184 if (verbose) {
gsInfo<<
"." ; }
185 m_values = solver.eigenvalues();
187 if (verbose) {
gsInfo<<
"." ; }
188 m_vectors = solver.eigenvectors();
189 if (verbose) {
gsInfo<<
"Finished\n" ; }
193 else if (solver.info()==Spectra::CompInfo::NotConverging)
195 gsWarn<<
"Spectra did not converge! Error code: NotConverging\n";
198 else if (solver.info()==Spectra::CompInfo::NumericalIssue)
200 gsWarn<<
"Spectra did not converge! Error code: NumericalIssue\n";
203 else if (solver.info()==Spectra::CompInfo::NotComputed)
205 gsWarn<<
"Spectra did not converge! Error code: NotComputed\n";
210 gsWarn<<
"No error code known\n";
218 gsStatus gsEigenProblemBase<T>::computePower()
223 bool verbose = m_options.getSwitch(
"verbose");
224 if (verbose) {
gsInfo<<
"Solving eigenvalue problem" ; }
225 gsMatrix<T> D = m_A.toDense().inverse() * (m_B);
227 gsVector<T> v(D.cols());
229 gsVector<T> v_old(D.cols());
233 real_t error,tol = m_options.getReal(
"tolerance");
234 for (
index_t k=0; k!=kmax; k++)
239 error = (v-v_old).norm();
253 m_values = (v.transpose() * v) / (v.transpose() * D * v);
255 if (verbose) {
gsInfo<<
"Finished\n" ; }
260 std::vector<std::pair<T,gsMatrix<T>> > gsEigenProblemBase<T>::makeMode(
int k)
const
262 std::vector<std::pair<T,gsMatrix<T>> > mode;
263 mode.push_back( std::make_pair( m_values.at(k), m_vectors.col(k) ) );
#define gsDebug
Definition: gsDebug.h:61
Assembly problem in step.
Assembly failed due to an error in the expression (e.g. overflow)
#define index_t
Definition: gsConfig.h:32
gsStatus
Definition: gsStructuralAnalysisTypes.h:20
#define gsWarn
Definition: gsDebug.h:50
#define gsInfo
Definition: gsDebug.h:43