NeoPZ
pzsbndmat.cpp
Go to the documentation of this file.
1 
6 #include <math.h>
7 #include <stdlib.h>
8 
9 #include "pzfmatrix.h"
10 #include "pzsbndmat.h"
11 
12 #ifdef USING_LAPACK
13 
14 #include "TPZLapack.h"
15 #define BLAS_MULT
16 #endif
17 
18 #include <sstream>
19 #include "pzlog.h"
20 #ifdef LOG4CXX
21 static LoggerPtr logger(Logger::getLogger("pz.matrix.tpzsbmatrix"));
22 #endif
23 
24 using namespace std;
25 
26 /*******************/
27 /*** TPZSBMatrix ***/
28 
29 /**************************** PUBLIC ****************************/
30 
31 /*****************************/
32 /*** Construtor (int) ***/
33 
34 template<class TVar>
35 TPZSBMatrix<TVar>::TPZSBMatrix( int64_t dim, int64_t band )
36 : TPZRegisterClassId(&TPZSBMatrix::ClassId),
37 TPZMatrix<TVar>( dim, dim )
38 {
39  fBand = ( band > (dim - 1) ? (dim - 1) : band );
40  fDiag.resize(Size());
41 
42  Zero();
43 }
44 template<class TVar>
45 TVar Random(TVar){
46  return ((TVar) rand() )/((TVar)RAND_MAX);
47 }
48 
49 template<>
50 std::complex<float> Random(std::complex<float>){
51  std::complex<float> I(0,1);
52  return ((std::complex<float>) rand() + I*(float)rand() )/((std::complex<float>)RAND_MAX);
53 }
54 template<>
55 std::complex<double> Random( std::complex<double> ){
56  std::complex<double> I(0,1);
57  return ((std::complex<double>) rand() + I*(double)rand() )/((std::complex<double>)RAND_MAX);
58 }
59 
60 
62 template <class TVar>
63 void TPZSBMatrix<TVar>::AutoFill(int64_t nrow, int64_t ncol, int symmetric) {
64 
65  if (nrow != ncol || symmetric == 0) {
66  DebugStop();
67  }
68  fBand = nrow/10;
69  if (fBand == 0) {
70  fBand = nrow-1;
71  }
72  Resize(nrow, ncol);
73 
74  int64_t i, j;
75  TVar val = 0, sum;
77  for(i=0;i<this->Rows();i++) {
78  sum = 0.0;
79  int64_t jmax = i+fBand+1;
80  if (jmax >= this->Rows()) {
81  jmax = this->Rows();
82  }
83  for (j=0; j<i; j++) {
84  sum += fabs(GetVal(i, j));
85  }
86  for(j=i;j<jmax;j++) {
87  val = Random( val );
88  if(!PutVal(i,j,val))
89  {
90  std::cout << "AutoFill (TPZMatrix) failed.";
91  DebugStop();
92  }
93  if(i!=j) sum += fabs(val);
94  else{
95  // AQUI !!!
96  std::complex<double> complex_val(val);
97  val = std::real(complex_val);
98  //val = std::real( val );
99  }
100  }
101  if (this->Rows() == this->Cols()) {
103  if(fabs(sum) > fabs(GetVal(i,i))) // Deve satisfazer: |Aii| > SUM( |Aij| ) sobre j != i
104  PutVal(i,i,sum+(TVar)1.);
105  // To sure diagonal is not zero.
106  if(IsZero(sum) && IsZero(GetVal(i,i)))
107  PutVal(i,i,1.);
108  }
109  }
110 
111 }
112 /**************/
113 /*** PutVal ***/
114 template <>
115 int
116 TPZSBMatrix< std::complex<float> >::PutVal(const int64_t r,const int64_t c,const std::complex<float>& value )
117 {
118  // inicializando row e col para trabalhar com a triangular superior
119  int64_t row(r),col(c);
120  if ( row > col )
121  DebugStop();//this->Swap( &row, &col );
122 
123  int64_t index;
124  if ( (index = col-row) > fBand )
125  {
126 #ifdef PZDEBUG
127  if (value != this->gZero) {
128  DebugStop();
129  }
130 #endif
131  return( 0 ); // O elemento esta fora da banda.
132  }
133  fDiag[ Index(row,col) ] = value;
134  this->fDecomposed = 0;
135  return( 1 );
136 }
137 
138 template <>
139 int
140 TPZSBMatrix< std::complex<double> >::PutVal(const int64_t r,const int64_t c,const std::complex<double>& value )
141 {
142  // inicializando row e col para trabalhar com a triangular superior
143  int64_t row(r),col(c);
144  if ( row > col )
145  this->Swap( &row, &col );
146 
147  int64_t index;
148  if ( (index = col-row) > fBand )
149  {
150 #ifdef PZDEBUG
151  if (value != this->gZero) {
152  DebugStop();
153  }
154 #endif
155  return( 0 ); // O elemento esta fora da banda.
156  }
157  fDiag[ Index(row,col) ] = value;
158  this->fDecomposed = 0;
159  return( 1 );
160 }
161 template <class TVar>
162 int
163 TPZSBMatrix<TVar>::PutVal(const int64_t r,const int64_t c,const TVar& value )
164 {
165  // inicializando row e col para trabalhar com a triangular superior
166  int64_t row(r),col(c);
167  if ( row > col )
168  this->Swap( &row, &col );
169 
170  int64_t index;
171  if ( (index = col-row) > fBand )
172  {
173 #ifdef PZDEBUG
174  if (value != this->gZero) {
175  DebugStop();
176  }
177 #endif
178  return( 0 ); // O elemento esta fora da banda.
179  }
180  fDiag[ Index(row,col) ] = value;
181  this->fDecomposed = 0;
182  return( 1 );
183 }
184 
185 /**************/
186 /*** GetVal ***/
187 template<>
188 const std::complex<float>
189 &TPZSBMatrix< std::complex<float> >::GetVal(const int64_t r,const int64_t c ) const
190 {
191  // inicializando row e col para trabalhar com a triangular superior
192  int64_t row(r),col(c);
193  bool mustConj = false;
194  if ( row > col ){
195  this->Swap( &row, &col );
196  mustConj = true;
197  }
198 
199  int64_t index;
200  if ( (index = col-row) > fBand )
201  return( this->gZero ); // O elemento esta fora da banda.
202 
203 
204  if( mustConj == true){
205  static std::complex<float> cpVal;
206  cpVal = fDiag[ Index(row,col) ];
207  cpVal = std::conj( cpVal );
208  return cpVal;
209  }
210  else{
211  return( fDiag[ Index(row,col) ] );
212  }
213 }
214 
215 template<>
216 const std::complex<double>
217 &TPZSBMatrix< std::complex<double> >::GetVal(const int64_t r,const int64_t c ) const
218 {
219  // inicializando row e col para trabalhar com a triangular superior
220  int64_t row(r), col(c);
221  bool mustConj = false;
222  if ( row > col ){
223  this->Swap( &row, &col );
224  mustConj = true;
225  }
226 
227  int64_t index;
228  if ( (index = col-row) > fBand )
229  return( this->gZero ); // O elemento esta fora da banda.
230 
231  if( mustConj == true){
232  static std::complex<double> cpVal;
233  cpVal = fDiag[ Index(row,col) ];
234  cpVal = std::conj( cpVal );
235  return cpVal;
236  }
237  else{
238  return( fDiag[ Index(row,col) ] );
239  }
240 }
241 
242 template<class TVar>
243 const TVar
244 &TPZSBMatrix<TVar>::GetVal(const int64_t r,const int64_t c ) const
245 {
246 
247  // inicializando row e col para trabalhar com a triangular superior
248  int64_t row(r),col(c);
249  if ( row > col )
250  this->Swap( &row, &col );
251 
252  int64_t index;
253  if ( (index = col-row) > fBand )
254  return( this->gZero ); // O elemento esta fora da banda.
255 
256  return( fDiag[ Index(row,col) ] );
257 }
258 
259 template<>
260 std::complex<float>
261 &TPZSBMatrix< std::complex< float> >::operator()(const int64_t r,const int64_t c )
262 {
263 
264  // inicializando row e col para trabalhar com a triangular superior
265  int64_t row(r),col(c);
266  bool mustConj = false;
267  if ( row > col ){
268  this->Swap( &row, &col );
269  mustConj = true;
270  }
271 
272  int64_t index;
273  if ( (index = col-row) > fBand )
274  return( this->gZero ); // O elemento esta fora da banda.
275  if( mustConj ){
276  static std::complex<float> cpVal;
277  cpVal = std::conj( fDiag[ Index(row,col) ] );
278  return cpVal;
279  }
280  else
281  return( fDiag[ Index(row,col) ] );
282 }
283 
284 template<>
285 std::complex<double>
286 &TPZSBMatrix< std::complex<double> >::operator()(const int64_t r,const int64_t c )
287 {
288 
289  // inicializando row e col para trabalhar com a triangular superior
290  int64_t row(r),col(c);
291  bool mustConj = false;
292  if ( row > col ){
293  this->Swap( &row, &col );
294  mustConj = true;
295  }
296 
297  int64_t index;
298  if ( (index = col-row) > fBand )
299  return( this->gZero ); // O elemento esta fora da banda.
300  if( mustConj ){
301  static std::complex<double> cpVal;
302  cpVal = std::conj( fDiag[ Index(row,col) ] );
303  return cpVal;
304  }
305  else
306  return( fDiag[ Index(row,col) ] );
307 }
308 
309 
310 template<class TVar>
311 TVar &TPZSBMatrix<TVar>::operator()(int64_t row, int64_t col)
312 {
313  // inicializando row e col para trabalhar com a triangular superior
314  if ( row > col )
315  this->Swap( &row, &col );
316 
317  int64_t index;
318  if ( (index = col-row) > fBand )
319  return( this->gZero ); // O elemento esta fora da banda.
320 
321  return( fDiag[ Index(row,col) ] );
322 
323 }
324 
325 /*************/
326 /*** Print ***/
327 
328 template<class TVar>
329 void
330 TPZSBMatrix<TVar> ::Print(const char *name, std::ostream& out,const MatrixOutputFormat form) const
331 {
332  out.width( 8 );
333  out.precision( 4 );
334 
335  out << "Writing matrix '" << name;
336  out << "' (" << this->Rows() << " x " << this->Cols() << ") Bandwith = "<<fBand<<"\n";
337  TPZMatrix<TVar>::Print(name,out,form);
338  /*
339  for ( int row = 0; row < Rows(); row++)
340  {
341  out << "\t";
342  for ( int col = 0; col < Cols(); col++ )
343  out << Get( row, col) << " ";
344  out << "\n";
345  }
346 
347  out << "\n";
348  */
349 }
350 
352 template<class TVar>
353 std::ostream&
354 operator<<(std::ostream& out,TPZSBMatrix<TVar> &A)
355 {
356  out.width( 8 );
357  out.precision( 4 );
358 
359  out <<"\n(" << A.Rows() << " x " << A.Cols()
360  << ") Bandwith = "<< A.GetBand()<<"\n";
361 
362  for ( int64_t row = 0; row < A.Rows(); row++)
363  {
364  out << "\t";
365  for ( int64_t col = 0; col < A.Cols(); col++ )
366  out << A.Get( row, col) << " ";
367  out << "\n";
368  }
369 
370  return out << "\n";
371 }
372 
373 /******** Operacoes com matrizes BANDA SIMETRICA ********/
374 
375 /******************/
376 /*** Operator = ***/
377 
378 template<class TVar>
381 {
382  Clear();
383  Copy( A );
384  return( *this );
385 }
386 
387 /******************/
388 /*** Operator + ***/
389 
390 template<class TVar>
393 {
394  if ( this->Dim() != A.Dim() || fBand != A.fBand)
395  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,"operator+( TPZSBMatrix ) <incompatible dimensions>" );
396 
397  // Define os ponteiros e tamanhos para os elementos da maior e da
398  // menor banda.
399  TPZSBMatrix Res(*this);
400  Res += A;
401  return Res;
402 }
403 
404 /******************/
405 /*** Operator - ***/
406 
407 template<class TVar>
410 {
411  if ( this->Dim() != A.Dim() || fBand != A.fBand)
412  {
413  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "operator-( TPZSBMatrix ) <incompatible dimensions>" );
414  }
415 
416  TPZSBMatrix<TVar> res(*this);
417  res -= A;
418 
419  return( res );
420 }
421 
422 /*******************/
423 /*** Operator += ***/
424 
425 template<class TVar>
428 {
429  if ( this->Dim() != A.Dim() || fBand != A.fBand)
430  {
431  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "operator+=( TPZSBMatrix ) <incompatible dimensions>" );
432  }
433  int64_t siz= fDiag.size();
434  for (int64_t i=0; i<siz; i++) {
435  fDiag[i] += A.fDiag[i];
436  }
437  return( *this );
438 }
439 
440 /*******************/
441 /*** Operator -= ***/
442 
443 template<class TVar>
446 {
447  if ( this->Dim() != A.Dim() || fBand != A.fBand)
448  {
449  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "operator-=( TPZSBMatrix ) <incompatible dimensions>" );
450  }
451  int64_t siz= fDiag.size();
452  for (int64_t i=0; i<siz; i++) {
453  fDiag[i] -= A.fDiag[i];
454  }
455 
456  return( *this );
457 }
458 
459 template<class TVar>
461  const TVar alpha,const TVar beta ,const int opt) const {
462  // Computes z = beta * y + alpha * opt(this)*x
463  // z and x cannot overlap in memory
464  if ((!opt && this->Cols() != x.Rows()) || this->Rows() != x.Rows())
465  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "TPZSBMatrix::MultAdd <matrixs with incompatible dimensions>" );
466  if(x.Cols() != y.Cols() || x.Cols() != z.Cols() || x.Rows() != y.Rows() || x.Rows() != z.Rows()) {
467  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,"TPZSBMatrix::MultAdd incompatible dimensions\n");
468  }
469  this->PrepareZ(y,z,beta,opt);
470  int64_t rows = this->Rows();
471  int64_t xcols = x.Cols();
472  int64_t ic, r;
473  for (ic = 0; ic < xcols; ic++) {
474  int64_t begin, end;
475  for ( r = 0; r < rows; r++ ) {
476  begin = MAX( r - fBand, 0 );
477  end = MIN( r + fBand + 1, rows );
478  TVar val = 0.;
479  // Calcula um elemento da resposta.
480  for ( int64_t i = begin ; i < end; i++ ) val += GetVal( r, i ) * x.GetVal(i, ic );
481  val *= alpha;
482  val += z.GetVal(r,ic);
483  z.PutVal( r , ic, val );
484  }
485  }
486 }
487 
488 /******** Operacoes com MATRIZES GENERICAS ********/
489 
490 // Estas operacoes com matrizes genericas, usam a parte triangular
491 // inferior da maior matriz quadrada de A. Ex.:
492 //
493 // Se A = 01 02 03 04 A matriz usada sera': 01 05 09
494 // 05 06 07 08 05 06 10
495 // 09 10 11 12 09 10 11
496 //
497 
498 /******** Operacoes com valores NUMERICOS ********/
499 //
500 // As operacoes com valores numericos sao efetuadas apenas nos
501 // elementos alocados. Em especial, as operacoes A = 0.0 e A *= 0.0
502 // desalocam todos os elementos da matriz.
503 //
504 
505 /*****************************/
506 /*** Operator * ( REAL ) ***/
507 
508 template<class TVar>
510 TPZSBMatrix<TVar>::operator*(const TVar value ) const
511 {
512  TPZSBMatrix<TVar> res( *this );
513 
514  int64_t siz= fDiag.size();
515  for (int64_t i=0; i<siz; i++) {
516  res.fDiag[i] *= value;
517  }
518 
519  return( res );
520 }
521 
522 /******************************/
523 /*** Operator += ( REAL ) ***/
524 
525 /******************************/
526 /*** Operator *= ( REAL ) ***/
527 
528 template<class TVar>
531 {
532  int64_t siz= fDiag.size();
533  for (int64_t i=0; i<siz; i++) {
534  fDiag[i] *= value;
535  }
536 
537  return( *this );
538 }
539 
540 /**************/
541 /*** Resize ***/
542 //
543 // Muda as dimensoes da matriz, mas matem seus valores antigos. Novas
544 // posicoes sao criadas com ZEROS.
545 //
546 template<class TVar>
547 int
548 TPZSBMatrix<TVar>::Resize(const int64_t newDim ,const int64_t)
549 {
550  if ( newDim == this->Dim() )
551  return( 1 );
552 
553  Redim(newDim,newDim);
554  return( 1 );
555 }
556 
557 /*************/
558 /*** Redim ***/
559 //
560 // Muda as dimensoes da matriz e ZERA seus elementos.
561 //
562 template<class TVar>
563 int
564 TPZSBMatrix<TVar>::Redim(const int64_t newDim ,const int64_t otherDim)
565 {
566  if (newDim != otherDim) {
567  DebugStop();
568  }
569 
570  if ( newDim != this->Dim() )
571  {
572  TPZMatrix<TVar>::Redim(newDim,newDim);
573  if (fBand > newDim-1) {
574  fBand = newDim-1;
575  }
576  fDiag.resize(Size());
577  }
578 
579  Zero();
580  this->fDecomposed = 0;
581  this->fDefPositive = 0;
582  return( 1 );
583 }
584 
585 template<class TVar>
586 int
588 {
589  int64_t siz= fDiag.size();
590  for (int64_t i=0; i<siz; i++) {
591  fDiag[i] = (TVar)0.;
592  }
593 
594 
595  this->fDecomposed = 0;
596  this->fDefPositive = 0;
597  return( 1 );
598 }
599 
600 
601 /****************/
602 /*** Set Band ***/
603 template<class TVar>
604 int
605 TPZSBMatrix<TVar>::SetBand(int64_t newBand )
606 {
607  if ( this->fBand == newBand )
608  return( 1 );
609  // AQUI!!!
610  int64_t nB = newBand;
611  if ( newBand > (this->Dim() - 1) )
612  {
613  //newBand = this->Dim()-1;
614  nB = this->Dim()-1;
615  }
616  //fBand = newBand;
617  fBand = nB;
618  fDiag.resize(Size());
619  Zero();
620 
621  return( 1 );
622 }
623 
624 /********************* Resolucao de sistemas *********************/
625 
626 
627 #ifdef USING_LAPACK
628 /**************************/
629 /*** Decompose Cholesky ***/
630 template<class TVar>
631 int
632 TPZSBMatrix<TVar>::Decompose_Cholesky(std::list<int64_t> &singular)
633 {
634  return Decompose_Cholesky();
635 }
636 
637 template<>
638 int
640 {
641  if (fDecomposed == ECholesky) {
642  return 1;
643  }
644  if (fDecomposed != ENoDecompose) {
645  DebugStop();
646  }
647 
648  char uplo[] = "Upper";
649  int n = this->Dim();
650  int lda = this->fBand + 1;
651  int kd = this->fBand;
652  int info = -666;
653 
654  cpbtrf_(uplo, &n, &kd , (varfloatcomplex*) fDiag.begin(), &lda, &info);
655  if( info > 0){
656  TPZMatrix<std::complex<float> >::Error(__PRETTY_FUNCTION__,"Decompose_Cholesky <The matrix is not positive definite>");
657  }
658  else if ( info < 0){
659  TPZMatrix<std::complex<float> >::Error(__PRETTY_FUNCTION__,"Decompose_Cholesky <Invalid argument. Check info value for more information>");
660  }
661 
662  this->fDecomposed = ECholesky;
663  this->fDefPositive = 1;
664  return( 1 );
665 }
666 
667 //final_ok
668 template<>
669 int
671 {
672  if (fDecomposed == ECholesky) {
673  return 1;
674  }
675  if (fDecomposed != ENoDecompose) {
676  DebugStop();
677  }
678 
679  char uplo[] = "Upper";
680  int n = this->Dim();
681  int lda = this->fBand + 1;
682  int kd = this->fBand;
683  int info = -666;
684  zpbtrf_(uplo, &n, &kd, (vardoublecomplex *) fDiag.begin(), &lda, &info);
685  if( info > 0){
686  TPZMatrix<std::complex<double> >::Error(__PRETTY_FUNCTION__,"Decompose_Cholesky <The matrix is not positive definite>");
687  }
688  else if ( info < 0){
689  TPZMatrix<std::complex<double> >::Error(__PRETTY_FUNCTION__,"Decompose_Cholesky <Invalid argument. Check info value for more information>");
690  }
691 
692  this->fDecomposed = ECholesky;
693  this->fDefPositive = 1;
694  return( 1 );
695 }
696 
697 template<>
699 {
700  if (fDecomposed == ECholesky) {
701  return 1;
702  }
703  if (fDecomposed != ENoDecompose) {
704  DebugStop();
705  }
706  char uplo[]="Upper";
707  int n = Dim();
708  int kd = fBand;
709  int nrhs = 0;
710  float *ab = &fDiag[0];
711  int ldab = fBand+1;
712  float b = 0;
713  int info;
714 
715  // spbsv_(<#char *__uplo#>, <#__CLPK_integer *__n#>, <#__CLPK_integer *__kd#>, <#__CLPK_integer *__nrhs#>, <#__CLPK_real *__ab#>, <#__CLPK_integer *__ldab#>, <#__CLPK_real *__b#>, <#__CLPK_integer *__ldb#>, <#__CLPK_integer *__info#>)
716  spbsv_(uplo, &n, &kd, &nrhs, ab, &ldab, &b, &n, &info);
717 
718  if (info != 0) {
719  DebugStop();
720  }
722  return 1;
723 }
724 
725 template<>
727 {
728  if (fDecomposed == ECholesky) {
729  return 1;
730  }
731  if (fDecomposed != ENoDecompose) {
732  DebugStop();
733  }
734  char uplo[]="Upper";
735  int n = Dim();
736  int kd = fBand;
737  int nrhs = 0;
738  double *ab = &fDiag[0];
739  int ldab = fBand+1;
740  double b = 0;
741  int info;
742 
743  // spbsv_(<#char *__uplo#>, <#__CLPK_integer *__n#>, <#__CLPK_integer *__kd#>, <#__CLPK_integer *__nrhs#>, <#__CLPK_real *__ab#>, <#__CLPK_integer *__ldab#>, <#__CLPK_real *__b#>, <#__CLPK_integer *__ldb#>, <#__CLPK_integer *__info#>)
744  dpbsv_(uplo, &n, &kd, &nrhs, ab, &ldab, &b, &n, &info);
745 
746  if (info != 0) {
747  DebugStop();
748  }
750  return 1;
751 }
752 
753 template<class TVar>
754 int
756 {
758 }
759 #endif
760 
761 /**********************/
762 /*** Decompose LDLt ***/
763 template<class TVar>
764 int
765 TPZSBMatrix<TVar>::Decompose_LDLt(std::list<int64_t> &singular)
766 {
767  return Decompose_LDLt();
768 }
769 
770 template<class TVar>
771 int
773 {
774 
775  if ( this->fDecomposed ) TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "Decompose_LDLt <Matrix already Decomposed>" );
776 
777  int64_t j,k,l, begin,end;
778  TVar sum;
779 
780  for ( j = 0; j < this->Dim(); j++ )
781  {
782  //Print("curernt");
783  sum=0.;
784 
785  begin = MAX( int64_t(j - fBand), 0 );
786  //cout<<"begin="<<begin<<"\n";
787  for ( k=begin; k<j; k++)
788  {
789  sum=sum-GetVal(k,k)*GetVal(k,j)*GetVal(k,j);
790  //cout<<"(k,j)"<<k<<" "<<j<<"\n";
791  }
792 
793 
794  // operator()(j,j)=GetVal(j,j)+sum;
795  PutVal(j,j,GetVal(j,j)+sum);
796  //cout<<"\n(j,j)"<<j<<" "<<j<<"\n\n";
797  for ( k=0; k<j; k++)
798  {
799  end = MIN( int64_t(k + fBand )+1, this->Dim() );
800  for( l=j+1; l<end;l++)
801  {
802  PutVal(l,j, GetVal(l,j)-GetVal(k,k)*GetVal(j,k)*GetVal(l,k) );
803  /*cout<<"end="<<end<<"\n";
804  cout<<"(l,j)"<<l<<" "<<j<<"\n";
805  cout<<"(j,k)"<<j<<" "<<k<<"\n";
806  cout<<"(l,k)"<<l<<" "<<k<<"\n\n";
807  */
808  }
809  }
810 
811  if ( IsZero(GetVal(j,j)) ) TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "Decompose_LDLt <Zero on diagonal>" );
812  end = MIN( int64_t(j + fBand )+1, this->Dim() );
813  //cout<<"end="<<end<<"\n";
814  for( l=j+1; l<end;l++)
815  {
816  //cout<<"(l,j)"<<l<<" "<<j<<"\n";
817  PutVal( l,j,GetVal(l,j)/GetVal(j,j) ) ;
818  }
819  }
820  this->fDecomposed = 1;
821  this->fDefPositive = 0;
822 
823  return( 1 );
824 
825 }
826 
827 /*********************/
828 /*** Subst Forward ***/
829 //
830 // Faz Ax = b, onde A e' triangular inferior.
831 //
832 #ifdef USING_LAPACK
833 template<>
834 int
836 {
837  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
838  {
839  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"Subst_Forward-> uncompatible matrices") ;
840  }
841  int n = Rows();
842  int kd = fBand;
843  int lda = 1+fBand;
844  int64_t bcols = B->Cols();
845  for(int64_t ic=0; ic<bcols; ic++)
846  {
847  // cblas_stbsv(<#const enum CBLAS_ORDER __Order#>, <#const enum CBLAS_UPLO __Uplo#>, <#const enum CBLAS_TRANSPOSE __TransA#>, <#const enum CBLAS_DIAG __Diag#>, <#const int __N#>, <#const int __K#>, <#const float *__A#>, <#const int __lda#>, <#float *__X#>, <#const int __incX#>)
848  float *bptr = &(*B)(0,ic);
849  cblas_stbsv(CblasColMajor, CblasUpper, CblasTrans, CblasNonUnit, n, kd, &fDiag[0], lda, bptr , 1);
850  }
851  return 1;
852 }
853 
854 template<>
855 int
857 {
858  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
859  {
860  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"Subst_Forward-> uncompatible matrices") ;
861  }
862  int n = Rows();
863  int kd = fBand;
864  int lda = 1+fBand;
865  int64_t bcols = B->Cols();
866  for(int64_t ic=0; ic<bcols; ic++)
867  {
868  // cblas_stbsv(<#const enum CBLAS_ORDER __Order#>, <#const enum CBLAS_UPLO __Uplo#>, <#const enum CBLAS_TRANSPOSE __TransA#>, <#const enum CBLAS_DIAG __Diag#>, <#const int __N#>, <#const int __K#>, <#const float *__A#>, <#const int __lda#>, <#float *__X#>, <#const int __incX#>)
869  double *bptr = &(*B)(0,ic);
870  cblas_dtbsv(CblasColMajor, CblasUpper, CblasTrans, CblasNonUnit, n, kd, &fDiag[0], lda, bptr , 1);
871  }
872  return 1;
873 }
874 
875 template<>
876 int
877 TPZSBMatrix<std::complex<float> >::Subst_Forward( TPZFMatrix<std::complex<float> >*B ) const
878 {
879  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
880  {
881  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"Subst_Forward-> uncompatible matrices") ;
882  }
883  int n = Rows();
884  int kd = fBand;
885  int lda = 1+fBand;
886  int64_t bcols = B->Cols();
887  for(int64_t ic=0; ic<bcols; ic++)
888  {
889  std::complex<float> *bptr = &(*B)(0,ic);
890  cblas_ctbsv(CblasColMajor, CblasUpper, CblasTrans, CblasNonUnit, n, kd, &fDiag[0], lda, bptr , 1);
891  }
892  return 1;
893 }
894 
895 template<>
896 int
897 TPZSBMatrix<std::complex<double> >::Subst_Forward( TPZFMatrix<std::complex<double> >*B ) const
898 {
899  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
900  {
901  TPZMatrix<std::complex<double> >::Error(__PRETTY_FUNCTION__,"Subst_Forward-> uncompatible matrices") ;
902  }
903  int n = Rows();
904  int kd = fBand;
905  int lda = 1+fBand;
906  int64_t bcols = B->Cols();
907  for(int64_t ic=0; ic<bcols; ic++)
908  {
909  std::complex<double> *bptr = &(*B)(0,ic);
910  cblas_ztbsv(CblasColMajor, CblasUpper, CblasTrans, CblasNonUnit, n, kd, &fDiag[0], lda, bptr , 1);
911  }
912  return 1;
913 }
914 
915 template<>
916 int
918 {
919  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
920  {
921  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"Subst_Backward-> uncompatible matrices") ;
922  }
923  int n = Rows();
924  int kd = fBand;
925  int lda = 1+fBand;
926  int64_t bcols = B->Cols();
927  for(int64_t ic=0; ic<bcols; ic++)
928  {
929  float *bptr = &(*B)(0,ic);
930  cblas_stbsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, kd, &fDiag[0], lda, bptr , 1);
931  }
932  return 1;
933 }
934 
935 
936 template<>
937 int
939 {
940  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
941  {
942  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"Subst_Backward-> uncompatible matrices") ;
943  }
944  int n = Rows();
945  int kd = fBand;
946  int lda = 1+fBand;
947  int64_t bcols = B->Cols();
948  for(int64_t ic=0; ic<bcols; ic++)
949  {
950  double *bptr = &(*B)(0,ic);
951  cblas_dtbsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, kd, &fDiag[0], lda, bptr , 1);
952  }
953  return 1;
954 }
955 
956 template<>
957 int
958 TPZSBMatrix<std::complex<float> >::Subst_Backward( TPZFMatrix<std::complex<float> >*B ) const
959 {
960  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
961  {
962  TPZMatrix<std::complex<float> >::Error(__PRETTY_FUNCTION__,"Subst_Backward-> uncompatible matrices") ;
963  }
964  int n = Rows();
965  int kd = fBand;
966  int lda = 1+fBand;
967  int64_t bcols = B->Cols();
968  for(int64_t ic=0; ic<bcols; ic++)
969  {
970  std::complex<float> *bptr = &(*B)(0,ic);
971  cblas_ctbsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, kd, &fDiag[0], lda, bptr , 1);
972  }
973  return 1;
974 }
975 
976 
977 template<>
978 int
979 TPZSBMatrix<std::complex<double> >::Subst_Backward( TPZFMatrix<std::complex<double> >*B ) const
980 {
981  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
982  {
983  TPZMatrix<std::complex<double> >::Error(__PRETTY_FUNCTION__,"Subst_Backward-> uncompatible matrices") ;
984  }
985  int n = Rows();
986  int kd = fBand;
987  int lda = 1+fBand;
988  int64_t bcols = B->Cols();
989  for(int64_t ic=0; ic<bcols; ic++)
990  {
991  std::complex<double> *bptr = &(*B)(0,ic);
992  cblas_ztbsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, n, kd, &fDiag[0], lda, bptr , 1);
993  }
994  return 1;
995 }
996 
997 template<>
998 int
1000 {
1001  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
1002  {
1003  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"Subst_Forward-> uncompatible matrices") ;
1004  }
1005  int n = Rows();
1006  int kd = fBand;
1007  int lda = 1+fBand;
1008  int64_t bcols = B->Cols();
1009  for(int64_t ic=0; ic<bcols; ic++)
1010  {
1011  float *bptr = &(*B)(0,ic);
1012  cblas_stbsv(CblasColMajor, CblasUpper, CblasTrans, CblasUnit, n, kd, &fDiag[0], lda, bptr , 1);
1013  }
1014  return 1;
1015 }
1016 
1017 template<>
1018 int
1020 {
1021  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
1022  {
1023  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"Subst_Forward-> uncompatible matrices") ;
1024  }
1025  int n = Rows();
1026  int kd = fBand;
1027  int lda = 1+fBand;
1028  int64_t bcols = B->Cols();
1029  for(int64_t ic=0; ic<bcols; ic++)
1030  {
1031  double *bptr = &(*B)(0,ic);
1032  cblas_dtbsv(CblasColMajor, CblasUpper, CblasTrans, CblasUnit, n, kd, &fDiag[0], lda, bptr , 1);
1033  }
1034  return 1;
1035 }
1036 
1037 template<>
1038 int
1039 TPZSBMatrix<std::complex<float> >::Subst_LForward( TPZFMatrix<std::complex<float> >*B ) const
1040 {
1041  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
1042  {
1043  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"Subst_Forward-> uncompatible matrices") ;
1044  }
1045  int n = Rows();
1046  int kd = fBand;
1047  int lda = 1+fBand;
1048  int64_t bcols = B->Cols();
1049  for(int64_t ic=0; ic<bcols; ic++)
1050  {
1051  std::complex<float> *bptr = &(*B)(0,ic);
1052  cblas_ctbsv(CblasColMajor, CblasUpper, CblasTrans, CblasUnit, n, kd, &fDiag[0], lda, bptr , 1);
1053  }
1054  return 1;
1055 }
1056 
1057 template<>
1058 int
1059 TPZSBMatrix<std::complex<double> >::Subst_LForward( TPZFMatrix<std::complex<double> >*B ) const
1060 {
1061  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
1062  {
1063  TPZMatrix<std::complex<double> >::Error(__PRETTY_FUNCTION__,"Subst_Forward-> uncompatible matrices") ;
1064  }
1065  int n = Rows();
1066  int kd = fBand;
1067  int lda = 1+fBand;
1068  int64_t bcols = B->Cols();
1069  for(int64_t ic=0; ic<bcols; ic++)
1070  {
1071  std::complex<double> *bptr = &(*B)(0,ic);
1072  cblas_ztbsv(CblasColMajor, CblasUpper, CblasTrans, CblasUnit, n, kd, &fDiag[0], lda, bptr , 1);
1073  }
1074  return 1;
1075 }
1076 
1077 template<>
1078 int
1080 {
1081  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
1082  {
1083  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"Subst_Backward-> uncompatible matrices") ;
1084  }
1085  int n = Rows();
1086  int kd = fBand;
1087  int lda = 1+fBand;
1088  int64_t bcols = B->Cols();
1089  for(int64_t ic=0; ic<bcols; ic++)
1090  {
1091  float *bptr = &(*B)(0,ic);
1092  cblas_stbsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasUnit, n, kd, &fDiag[0], lda, bptr , 1);
1093  }
1094  return 1;
1095 }
1096 
1097 
1098 template<>
1099 int
1101 {
1102  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
1103  {
1104  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"Subst_Backward-> uncompatible matrices") ;
1105  }
1106  int n = Rows();
1107  int kd = fBand;
1108  int lda = 1+fBand;
1109  int64_t bcols = B->Cols();
1110  for(int64_t ic=0; ic<bcols; ic++)
1111  {
1112  double *bptr = &(*B)(0,ic);
1113  cblas_dtbsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasUnit, n, kd, &fDiag[0], lda, bptr , 1);
1114  }
1115  return 1;
1116 }
1117 
1118 template<>
1119 int
1120 TPZSBMatrix<std::complex<float> >::Subst_LBackward( TPZFMatrix<std::complex<float> >*B ) const
1121 {
1122  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
1123  {
1124  TPZMatrix<std::complex<float> >::Error(__PRETTY_FUNCTION__,"Subst_Backward-> uncompatible matrices") ;
1125  }
1126  int n = Rows();
1127  int kd = fBand;
1128  int lda = 1+fBand;
1129  int64_t bcols = B->Cols();
1130  for(int64_t ic=0; ic<bcols; ic++)
1131  {
1132  std::complex<float> *bptr = &(*B)(0,ic);
1133  cblas_ctbsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasUnit, n, kd, &fDiag[0], lda, bptr , 1);
1134  }
1135  return 1;
1136 }
1137 
1138 
1139 template<>
1140 int
1141 TPZSBMatrix<std::complex<double> >::Subst_LBackward( TPZFMatrix<std::complex<double> >*B ) const
1142 {
1143  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
1144  {
1145  TPZMatrix<std::complex<double> >::Error(__PRETTY_FUNCTION__,"Subst_Backward-> uncompatible matrices") ;
1146  }
1147  int n = Rows();
1148  int kd = fBand;
1149  int lda = 1+fBand;
1150  int64_t bcols = B->Cols();
1151  for(int64_t ic=0; ic<bcols; ic++)
1152  {
1153  std::complex<double> *bptr = &(*B)(0,ic);
1154  cblas_ztbsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasUnit, n, kd, &fDiag[0], lda, bptr , 1);
1155  }
1156  return 1;
1157 }
1158 
1159 #endif
1160 
1161 template<class TVar>
1162 int
1164 {
1165  if ( (B->Rows() != this->Dim()) || ! this->fDecomposed)
1166  {
1167  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,"Subst_Forward-> uncompatible matrices") ;
1168  }
1170 }
1171 /***********************/
1172 /*** Subst L Forward ***/
1173 //
1174 // Faz a "Forward substitution" assumindo que os elementos
1175 // da diagonal sao todos iguais a 1.
1176 //
1177 template<class TVar>
1179 {
1180  if ( (B->Rows() != this->Dim()) || !this->fDecomposed )
1181  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,"Subst_LForward-> uncompatible matrices") ;
1182 
1183  int64_t size = fBand + 1;
1184  int64_t i,j,k;
1185  for ( k = 0; k < this->Dim(); k++ )
1186  {
1187  for ( j = 0; j < B->Cols(); j++ )
1188  {
1189  // Faz sum = SOMA( A[k,i] * B[i,j] ), para i = 1, ..., k-1.
1190 
1191  int64_t imin = k-fBand;
1192  if(imin < 0) imin = 0;
1193 
1194  int64_t end=(k-fBand>0)? fBand:k; //misael
1195  TVar sum = 0.0;
1196  for ( i = imin; i < k ; i++ )//misael
1197  {
1198  sum += GetVal(k,i) * B->GetVal(i,j);
1199  }
1200  // Faz b[k] = (b[k] - sum).
1201  //
1202  B->PutVal( k, j, (B->GetVal( k, j ) - sum) );
1203 
1204  }
1205  }
1206  return( 1 );
1207 }
1208 
1209 /******************/
1210 /*** Subst Diag ***/
1211 //
1212 // Faz Ax = b, sendo que A e' assumida ser uma matriz diagonal.
1213 //
1214 template<class TVar>
1216 {
1217 
1218  if ( (B->Rows() != this->Dim()) || !this->fDecomposed )
1219  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,"Subst_Diag-> uncompatible matrices") ;
1220 
1221 
1222  int64_t size = fBand + 1;
1223  for ( int64_t k = 0; k < this->Dim(); k++ )
1224  for ( int64_t j = 0; j < B->Cols(); j++ )
1225  B->PutVal( k, j, B->GetVal( k, j) / GetVal(k,k) );
1226 
1227  return( 1 );
1228 }
1229 
1230 template<class TVar>
1232 {
1233  if ( (B->Rows() != this->Dim()) || !this->fDecomposed )
1234  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,"Subst_Forward-> uncompatible matrices") ;
1235 
1237  return ( 1 ) ;
1238 
1239 }
1240 
1241 template<class TVar>
1243 {
1244  if ( (B->Rows() != this->Dim()) || !this->fDecomposed )
1245  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,"Subst_LBackward-> uncompatible matrices") ;
1246 
1247  int64_t k,j,jmax,stepcol=fBand+2;
1248 
1249  for(k=0; k<B->Cols() ; k++)
1250  {
1251  for(int64_t i=this->Rows()-1; i>=0; i--)
1252  {
1253  jmax=( (i+fBand+1)>this->Rows())? this->Rows() : i+fBand+1;
1254  TVar sum = 0.;
1255  for(j=i+1;j<jmax;j++)
1256  {
1257  TVar el = GetVal(i,j);
1258  sum += B->GetVal(j,k)*el;
1259  }
1260  B->operator()(i,k) -= sum;
1261  }
1262 
1263  }
1264 
1265  return 1;
1266 
1267 }
1268 
1269 /**************************** PRIVATE ****************************/
1270 
1271 /*************/
1272 /*** CLear ***/
1273 template<class TVar>
1274 int
1276 {
1277  this->fRow = this->fCol = 0;
1278  fDiag.resize(0);
1279  this->fDecomposed = 0;
1280  return( 1 );
1281 }
1282 
1283 /************/
1284 /*** Copy ***/
1285 
1286 template<class TVar>
1287 void
1289 {
1291  this->fBand = A.fBand;
1292  this->fDiag = A.fDiag;
1293 }
1294 
1295 #ifdef USING_LAPACK
1296 /*** @name Solve eigenvalues ***/
1298 template< class TVar>
1299 int
1300 TPZSBMatrix<TVar>::SolveEigenProblem(TPZVec < complex<double> > &eigenvalues, TPZFMatrix < complex<double> > &eigenVectors)
1301 {
1302  TPZMatrix<float>::Error(__PRETTY_FUNCTION__, "SolveEigenProblem <LAPACK does not support this specific data type>" );
1303  return( 0 );
1304 }
1305 
1306 template< class TVar>
1307 int
1308 TPZSBMatrix<TVar>::SolveEigenProblem(TPZVec < complex<double> > &w)
1309 {
1310  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "SolveEigenProblem <LAPACK does not support this specific data type>" );
1311  return( 0 );
1312 }
1313 
1314 template<>
1315 int
1316 TPZSBMatrix<double>::SolveEigenProblem(TPZVec < complex<double> > &eigenvalues)
1317 {
1318 
1319 #ifdef USING_LAPACK
1320  char jobz = 'n'; //compute eigenvalues only
1321  char uplo = 'u';//assume upper triangular
1322  int n = this->Dim();
1323  int kd = this->fBand;
1324  int ldab = this->fBand + 1;
1325  TPZVec<double> w(0,0.);
1326  w.Resize( this->Dim() );
1327  TPZVec <double> z( this->Dim() *this->Dim() );
1328  int ldz = this->Dim();
1329  TPZVec <double> work( 3 *this->Dim() );
1330  int info = -666;
1331 
1332  dsbev_(&jobz, &uplo, &n, &kd, fDiag.begin(), &ldab, w.begin(), z.begin(), &ldz, work.begin(), &info);
1333  if( info > 0){
1334  TPZMatrix<double>::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <The algorithm failed to converge>");
1335  }
1336  else if( info < 0){
1337  TPZMatrix<double>::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <Invalid argument. Check info value for more information>");
1338  }
1339 #endif
1340  eigenvalues.Resize( this->Dim() );
1341  for (int i = 0 ; i < this->Dim() ; i++) {
1342  eigenvalues[i] = w[i];
1343  }
1344  return( 1 );
1345 }
1346 
1347 template<>
1348 int
1349 TPZSBMatrix<complex <double> >::SolveEigenProblem(TPZVec <complex<double> > &eigenvalues)
1350 {
1351 #ifdef USING_LAPACK
1352 
1353  char jobz = 'n'; //compute eigenvalues only
1354  char uplo = 'u';//assume upper triangular
1355  int n = this->Dim();
1356  int kd = this->fBand;
1357  int ldab = this->fBand + 1;
1358  TPZVec<double> w(this->Dim() , 0.);
1359  w.Resize( this->Dim() );
1360  TPZVec <complex <double> > z( this->Dim() *this->Dim() );
1361  int ldz = this->Dim();
1362  TPZVec <complex <double> > work( this->Dim() );
1363  TPZVec < double > rwork( 3 *this->Dim() );
1364  int info = -666;
1365 
1366  zhbev_(&jobz, &uplo, &n, &kd, (vardoublecomplex *)fDiag.begin(), &ldab, w.begin(), (vardoublecomplex *)z.begin(), &ldz, (vardoublecomplex *)work.begin(),rwork.begin(), &info);
1367  if( info > 0){
1368  TPZMatrix<complex<double> >::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <The algorithm failed to converge>");
1369  }
1370  else if( info < 0){
1371  TPZMatrix<complex<double> >::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <Invalid argument. Check info value for more information>");
1372  }
1373 
1374 #endif
1375  eigenvalues.Resize( this->Dim() );
1376  for (int i = 0 ; i < this->Dim() ; i++) {
1377  eigenvalues[i] = w[i];
1378  }
1379 
1380  return( 1 );
1381 }
1382 
1383 template<>
1384 int
1385 TPZSBMatrix<double>::SolveEigenProblem(TPZVec < std::complex<double> > &eigenvalues, TPZFMatrix < std::complex<double> > &eigenVectors)
1386 {
1387 
1388 #ifdef USING_LAPACK
1389  char jobz = 'V'; //compute eigenvectors
1390  char uplo = 'U';//assume upper triangular
1391  int n = this->Dim();
1392  int kd = this->fBand;
1393  int ldab = this->fBand + 1;
1394  int ldbb = this->fBand + 1;
1395  TPZVec < double > w(0,0.);
1396  w.Resize( this->Dim() );
1397  TPZFMatrix<double> z( this->Dim() ,this->Dim() );
1398  int ldz = this->Dim();
1399  TPZVec <double> work( 3 *this->Dim() );
1400  int info = -666;
1401 
1402  dsbev_(&jobz, &uplo, &n, &kd, fDiag.begin(), &ldab, w.begin(), &z(0,0), &ldz, work.begin(), &info);
1403  if( info > 0){
1404  TPZMatrix<double>::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <The algorithm failed to converge>");
1405  }
1406  else if( info < 0){
1407  TPZMatrix<double>::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <Invalid argument. Check info value for more information>");
1408  }
1409  eigenvalues.Resize( this->Dim() );
1410  for(int i = 0 ; i < this->Dim() ; i++){
1411  eigenvalues[i] = w[i];
1412  }
1413  eigenVectors.Redim(this->Dim(), this->Dim());
1414  for (int iVec = 0 ; iVec < this->Dim(); iVec++) {
1415  for (int iCol = 0; iCol < this->Dim(); iCol++) {
1416  eigenVectors( iVec , iCol) = z(iVec, iCol);
1417  }
1418  }
1419 
1420 #endif
1421 
1422  return( 1 );
1423 }
1424 
1425 template<>
1426 int
1427 TPZSBMatrix<complex <double> >::SolveEigenProblem(TPZVec <complex<double> > &eigenvalues, TPZFMatrix <complex <double> > &eigenVectors)
1428 {
1429 
1430 #ifdef USING_LAPACK
1431  char jobz = 'V'; //compute eigenvectors
1432  char uplo = 'U';//assume upper triangular
1433  int n = this->Dim();
1434  int kd = this->fBand;
1435  int ldab = this->fBand + 1;
1437  w.Resize( this->Dim() );
1438  TPZFMatrix <complex <double> > z( this->Dim(),this->Dim() );
1439  int ldz = this->Dim();
1440  TPZVec <complex <double> > work( this->Dim() );
1441  TPZVec < double > rwork( 3 *this->Dim() );
1442  int info = -666;
1443 
1444  zhbev_(&jobz, &uplo, &n, &kd, (vardoublecomplex *)fDiag.begin(), &ldab, w.begin(), (vardoublecomplex *)&z(0,0), &ldz, (vardoublecomplex *)work.begin(),rwork.begin(), &info);
1445  if( info > 0){
1446  TPZMatrix<complex<double> >::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <The algorithm failed to converge>");
1447  }
1448  else if( info < 0){
1449  TPZMatrix<complex<double> >::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <Invalid argument. Check info value for more information>");
1450  }
1451  eigenvalues.Resize( this->Dim());
1452  for(int i = 0; i < this->Dim(); i++){
1453  eigenvalues[i] = w[i];
1454  }
1455  eigenVectors.Redim(this->Dim(), this->Dim());
1456  for (int iVec = 0 ; iVec < this->Dim(); iVec++) {
1457  for (int iCol = 0; iCol < this->Dim(); iCol++) {
1458  eigenVectors( iVec , iCol) = z(iVec,iCol);
1459  }
1460  }
1461 
1462 #endif
1463 
1464  return( 1 );
1465 }
1466 
1467 template<>
1468 int
1469 TPZSBMatrix<float>::SolveEigenProblem(TPZVec < complex<double> > &eigenvalues)
1470 {
1471 
1472 #ifdef USING_LAPACK
1473  char jobz = 'n'; //compute eigenvalues only
1474  char uplo = 'u';//assume upper triangular
1475  int n = this->Dim();
1476  int kd = this->fBand;
1477  int ldab = this->fBand + 1;
1478  TPZVec<float> w(0,0.);
1479  w.Resize( this->Dim() );
1480  TPZVec <float> z( this->Dim() *this->Dim() );
1481  int ldz = this->Dim();
1482  TPZVec <float> work( 3 *this->Dim() );
1483  int info = -666;
1484 
1485  ssbev_(&jobz, &uplo, &n, &kd, fDiag.begin(), &ldab, w.begin(), z.begin(), &ldz, work.begin(), &info);
1486  if( info > 0){
1487  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <The algorithm failed to converge>");
1488  }
1489  else if( info < 0){
1490  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <Invalid argument. Check info value for more information>");
1491  }
1492 #endif
1493  eigenvalues.Resize( this->Dim() );
1494  for (int i = 0 ; i < this->Dim() ; i++) {
1495  eigenvalues[i] = w[i];
1496  }
1497  return( 1 );
1498 }
1499 
1500 template<>
1501 int
1502 TPZSBMatrix<complex <float> >::SolveEigenProblem(TPZVec <complex<double> > &eigenvalues)
1503 {
1504 #ifdef USING_LAPACK
1505 
1506  char jobz = 'n'; //compute eigenvalues only
1507  char uplo = 'u';//assume upper triangular
1508  int n = this->Dim();
1509  int kd = this->fBand;
1510  int ldab = this->fBand + 1;
1511  TPZVec<float> w(this->Dim() , 0.);
1512  w.Resize( this->Dim() );
1513  TPZVec <complex <float> > z( this->Dim() *this->Dim() );
1514  int ldz = this->Dim();
1515  TPZVec <complex <float> > work( this->Dim() );
1516  TPZVec < float > rwork( 3 *this->Dim() );
1517  int info = -666;
1518 
1519  chbev_(&jobz, &uplo, &n, &kd, (varfloatcomplex *)fDiag.begin(), &ldab, w.begin(), (varfloatcomplex *)z.begin(), &ldz, (varfloatcomplex *)work.begin(),rwork.begin(), &info);
1520  if( info > 0){
1521  TPZMatrix<complex<float> >::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <The algorithm failed to converge>");
1522  }
1523  else if( info < 0){
1524  TPZMatrix<complex<float> >::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <Invalid argument. Check info value for more information>");
1525  }
1526 
1527 #endif
1528  eigenvalues.Resize( this->Dim() );
1529  for (int i = 0 ; i < this->Dim() ; i++) {
1530  eigenvalues[i] = w[i];
1531  }
1532 
1533  return( 1 );
1534 }
1535 
1536 template<>
1537 int
1538 TPZSBMatrix<float>::SolveEigenProblem(TPZVec < std::complex<double> > &eigenvalues, TPZFMatrix < std::complex<double> > &eigenVectors)
1539 {
1540 
1541 #ifdef USING_LAPACK
1542  char jobz = 'V'; //compute eigenvectors
1543  char uplo = 'U';//assume upper triangular
1544  int n = this->Dim();
1545  int kd = this->fBand;
1546  int ldab = this->fBand + 1;
1547  int ldbb = this->fBand + 1;
1548  TPZVec < float > w(0,0.);
1549  w.Resize( this->Dim() );
1550  TPZFMatrix <float> z( this->Dim(),this->Dim() );
1551  int ldz = this->Dim();
1552  TPZVec <float> work( 3 *this->Dim() );
1553  int info = -666;
1554 
1555  ssbev_(&jobz, &uplo, &n, &kd, fDiag.begin(), &ldab, w.begin(), &z(0,0), &ldz, work.begin(), &info);
1556  if( info > 0){
1557  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <The algorithm failed to converge>");
1558  }
1559  else if( info < 0){
1560  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <Invalid argument. Check info value for more information>");
1561  }
1562  eigenvalues.Resize( this->Dim() );
1563  for(int i = 0 ; i < this->Dim() ; i++){
1564  eigenvalues[i] = w[i];
1565  }
1566  eigenVectors.Redim(this->Dim(), this->Dim());
1567  for (int iVec = 0 ; iVec < this->Dim(); iVec++) {
1568  for (int iCol = 0; iCol < this->Dim(); iCol++) {
1569  eigenVectors( iVec , iCol) = z(iVec,iCol);
1570  }
1571  }
1572 
1573 #endif
1574 
1575  return( 1 );
1576 }
1577 
1578 template<>
1579 int
1580 TPZSBMatrix<complex <float> >::SolveEigenProblem(TPZVec <complex<double> > &eigenvalues, TPZFMatrix <complex <double> > &eigenVectors)
1581 {
1582 
1583 #ifdef USING_LAPACK
1584  char jobz = 'V'; //compute eigenvectors
1585  char uplo = 'U';//assume upper triangular
1586  int n = this->Dim();
1587  int kd = this->fBand;
1588  int ldab = this->fBand + 1;
1589  TPZVec < float > w;
1590  w.Resize( this->Dim() );
1591  TPZFMatrix <complex <float> > z( this->Dim(), this->Dim() );
1592  int ldz = this->Dim();
1593  TPZVec <complex <float> > work( this->Dim() );
1594  TPZVec < float > rwork( 3 *this->Dim() );
1595  int info = -666;
1596 
1597  chbev_(&jobz, &uplo, &n, &kd, (varfloatcomplex *)fDiag.begin(), &ldab, w.begin(), (varfloatcomplex *)&z(0,0), &ldz, (varfloatcomplex *)work.begin(),rwork.begin(), &info);
1598  if( info > 0){
1599  TPZMatrix<complex<float> >::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <The algorithm failed to converge>");
1600  }
1601  else if( info < 0){
1602  TPZMatrix<complex<float> >::Error(__PRETTY_FUNCTION__,"SolveEigenProblem <Invalid argument. Check info value for more information>");
1603  }
1604  eigenvalues.Resize( this->Dim());
1605  for(int i = 0; i < this->Dim(); i++){
1606  eigenvalues[i] = w[i];
1607  }
1608  eigenVectors.Redim(this->Dim(), this->Dim());
1609  for (int iVec = 0 ; iVec < this->Dim(); iVec++) {
1610  for (int iCol = 0; iCol < this->Dim(); iCol++) {
1611  eigenVectors( iVec , iCol) = z(iVec,iCol);
1612  }
1613  }
1614 
1615 #endif
1616 
1617  return( 1 );
1618 }
1619 
1620 template< class TVar>
1621 int
1622 TPZSBMatrix<TVar>::SolveGeneralisedEigenProblem(TPZSBMatrix<TVar> &B , TPZVec < complex<double> > &w, TPZFMatrix < complex<double> > &eigenVectors)
1623 {
1624  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <LAPACK does not support this specific data type>" );
1625  return( 0 );
1626 }
1627 template< class TVar>
1628 int
1630 {
1631  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <LAPACK does not support this specific data type>" );
1632  return( 0 );
1633 }
1634 template<>
1635 int
1636 TPZSBMatrix<float>::SolveGeneralisedEigenProblem(TPZSBMatrix<float> &B , TPZVec <complex<double> > &eigenvalues, TPZFMatrix < complex<double> > &eigenVectors)
1637 {
1638  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
1639  {
1640  TPZMatrix<float>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
1641  }
1642 
1643 #ifdef USING_LAPACK
1644  char jobz = 'V'; //compute eigenvectors
1645  char uplo = 'U';//assume upper triangular
1646  int n = this->Dim();
1647  int ka = this->fBand;
1648  int kb = B.fBand;
1649  int ldab = this->fBand + 1;
1650  int ldbb = this->fBand + 1;
1651  TPZVec< float > w(0,0.);
1652  w.Resize( this->Dim() );
1653  TPZFMatrix<float> z( this->Dim(), this->Dim() );
1654  int ldz = this->Dim();
1655  TPZVec <float> work( 3 *this->Dim() );
1656  int info = -666;
1657 
1658  ssbgv_(&jobz, &uplo, &n, &ka, &kb, fDiag.begin(), &ldab, B.fDiag.begin(), &ldbb, w.begin(), &z(0,0), &ldz, work.begin(), &info);
1659  if( info > 0){
1660  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"SolveGeneralisedEigenProblem <The algorithm failed to converge>");
1661  }
1662  else if( info < 0){
1663  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"SolveGeneralisedEigenProblem <Invalid argument. Check info value for more information>");
1664  }
1665  eigenvalues.Resize( this->Dim() );
1666  eigenVectors.Resize( this->Dim() , this->Dim() );
1667  for (int i = 0; i < this->Dim() ; i++) {
1668  eigenvalues[i] = w[i];
1669  for (int j = 0 ; j < this->Dim() ; j++) {
1670  eigenVectors(i,j) = z(i,j);
1671  }
1672  }
1673 
1674 #endif
1675 
1676  return( 1 );
1677 }
1678 
1679 
1680 template<>
1681 int
1683 {
1684  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
1685  {
1686  TPZMatrix<float>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
1687  }
1688 
1689 #ifdef USING_LAPACK
1690  char jobz = 'N'; //do NOT compute eigenvectors
1691  char uplo = 'U';//assume upper triangular
1692  int n = this->Dim();
1693  int ka = this->fBand;
1694  int kb = B.fBand;
1695  int ldab = this->fBand + 1;
1696  int ldbb = this->fBand + 1;
1697  TPZVec< float > w(0,0.);
1698  w.Resize( this->Dim() );
1699  TPZFMatrix<float> z( this->Dim(), this->Dim() );
1700  int ldz = this->Dim();
1701  TPZVec <float> work( 3 *this->Dim() );
1702  int info = -666;
1703 
1704  ssbgv_(&jobz, &uplo, &n, &ka, &kb, fDiag.begin(), &ldab, B.fDiag.begin(), &ldbb, w.begin(), &z(0,0), &ldz, work.begin(), &info);
1705  if( info > 0){
1706  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"SolveGeneralisedEigenProblem <The algorithm failed to converge>");
1707  }
1708  else if( info < 0){
1709  TPZMatrix<float>::Error(__PRETTY_FUNCTION__,"SolveGeneralisedEigenProblem <Invalid argument. Check info value for more information>");
1710  }
1711  eigenvalues.Resize( this->Dim() );
1712  for (int i = 0; i < this->Dim() ; i++) {
1713  eigenvalues[i] = w[i];
1714  }
1715 
1716 #endif
1717 
1718  return( 1 );
1719 }
1720 
1721 template<>
1722 int
1723 TPZSBMatrix<complex<float> >::SolveGeneralisedEigenProblem(TPZSBMatrix<complex<float> > &B , TPZVec <complex<double> > &eigenvalues, TPZFMatrix < complex<double> > &eigenVectors)
1724 {
1725  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
1726  {
1727  TPZMatrix<float>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
1728  }
1729 
1730 #ifdef USING_LAPACK
1731  char jobz = 'V'; //compute eigenvectors
1732  char uplo = 'U';//assume upper triangular
1733  int n = this->Dim();
1734  int ka = this->fBand;
1735  int kb = B.fBand;
1736  int ldab = this->fBand + 1;
1737  int ldbb = this->fBand + 1;
1738  TPZVec<float> w(0,0.);
1739  w.Resize( this->Dim() );
1740  TPZFMatrix <complex <float> > z( this->Dim() ,this->Dim() );
1741  int ldz = this->Dim();
1742  TPZVec <complex <float> > work( this->Dim() );
1743  TPZVec < float > rwork( 3 *this->Dim() );
1744  int info = -666;
1745 
1746  chbgv_(&jobz, &uplo, &n, &ka, &kb, (varfloatcomplex *)fDiag.begin(), &ldab, (varfloatcomplex *)B.fDiag.begin(), &ldbb, w.begin(), (varfloatcomplex *)&z(0,0), &ldz, (varfloatcomplex *)work.begin(),rwork.begin(), &info);
1747  if( info > 0){
1748  TPZMatrix<complex<float> >::Error(__PRETTY_FUNCTION__,"Solve_EigenProblem <The algorithm failed to converge>");
1749  }
1750  else if( info < 0){
1751  TPZMatrix<complex<float> >::Error(__PRETTY_FUNCTION__,"Solve_EigenProblem <Invalid argument. Check info value for more information>");
1752  }
1753  eigenvalues.Resize( this->Dim() );
1754  eigenVectors.Resize( this->Dim() , this->Dim() );
1755  for (int i = 0; i < this->Dim() ; i++) {
1756  eigenvalues[i] = w[i];
1757  for (int j = 0 ; j < this->Dim() ; j++) {
1758  eigenVectors(i,j) = z(i,j);
1759  }
1760  }
1761 
1762 #endif
1763 
1764  return( 1 );
1765 }
1766 
1767 
1768 template<>
1769 int
1770 TPZSBMatrix<complex<float> >::SolveGeneralisedEigenProblem(TPZSBMatrix<complex<float> > &B , TPZVec <complex<double> > &eigenvalues)
1771 {
1772  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
1773  {
1774  TPZMatrix<float>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
1775  }
1776 
1777 #ifdef USING_LAPACK
1778  char jobz = 'N'; //do NOT compute eigenvectors
1779  char uplo = 'U';//assume upper triangular
1780  int n = this->Dim();
1781  int ka = this->fBand;
1782  int kb = B.fBand;
1783  int ldab = this->fBand + 1;
1784  int ldbb = this->fBand + 1;
1785  TPZVec<float> w(0,0.);
1786  w.Resize( this->Dim() );
1787  TPZFMatrix <complex <float> > z( this->Dim() ,this->Dim() );
1788  int ldz = this->Dim();
1789  TPZVec <complex <float> > work( this->Dim() );
1790  TPZVec < float > rwork( 3 *this->Dim() );
1791  int info = -666;
1792 
1793  chbgv_(&jobz, &uplo, &n, &ka, &kb, (varfloatcomplex *)fDiag.begin(), &ldab, (varfloatcomplex *)B.fDiag.begin(), &ldbb, w.begin(), (varfloatcomplex *)&z(0,0), &ldz, (varfloatcomplex *)work.begin(),rwork.begin(), &info);
1794  if( info > 0){
1795  TPZMatrix<complex<float> >::Error(__PRETTY_FUNCTION__,"Solve_EigenProblem <The algorithm failed to converge>");
1796  }
1797  else if( info < 0){
1798  TPZMatrix<complex<float> >::Error(__PRETTY_FUNCTION__,"Solve_EigenProblem <Invalid argument. Check info value for more information>");
1799  }
1800  eigenvalues.Resize( this->Dim() );
1801  for (int i = 0; i < this->Dim() ; i++) {
1802  eigenvalues[i] = w[i];
1803  }
1804 
1805 #endif
1806 
1807  return( 1 );
1808 }
1809 
1810 
1811 template<>
1812 int
1813 TPZSBMatrix<double>::SolveGeneralisedEigenProblem(TPZSBMatrix<double> &B , TPZVec <complex<double> > &eigenvalues, TPZFMatrix < complex<double> > &eigenVectors)
1814 {
1815  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
1816  {
1817  TPZMatrix<double>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
1818  }
1819 
1820 #ifdef USING_LAPACK
1821  char jobz = 'V'; //compute eigenvectors
1822  char uplo = 'U';//assume upper triangular
1823  int n = this->Dim();
1824  int ka = this->fBand;
1825  int kb = B.fBand;
1826  int ldab = this->fBand + 1;
1827  int ldbb = this->fBand + 1;
1828  TPZVec< double > w(0,0.);
1829  w.Resize( this->Dim() );
1830  TPZFMatrix<double> z( this->Dim(), this->Dim() );
1831  int ldz = this->Dim();
1832  TPZVec <double> work( 3 *this->Dim() );
1833  int info = -666;
1834 
1835  dsbgv_(&jobz, &uplo, &n, &ka, &kb, fDiag.begin(), &ldab, B.fDiag.begin(), &ldbb, w.begin(), &z(0,0), &ldz, work.begin(), &info);
1836  if( info > 0){
1837  TPZMatrix<double>::Error(__PRETTY_FUNCTION__,"SolveGeneralisedEigenProblem <The algorithm failed to converge>");
1838  }
1839  else if( info < 0){
1840  TPZMatrix<double>::Error(__PRETTY_FUNCTION__,"SolveGeneralisedEigenProblem <Invalid argument. Check info value for more information>");
1841  }
1842  eigenvalues.Resize( this->Dim() );
1843  eigenVectors.Resize( this->Dim() , this->Dim() );
1844  for (int i = 0; i < this->Dim() ; i++) {
1845  eigenvalues[i] = w[i];
1846  for (int j = 0 ; j < this->Dim() ; j++) {
1847  eigenVectors(i,j) = z(i,j);
1848  }
1849  }
1850 
1851 #endif
1852 
1853  return( 1 );
1854 }
1855 
1856 
1857 template<>
1858 int
1860 {
1861  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
1862  {
1863  TPZMatrix<double>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
1864  }
1865 
1866 #ifdef USING_LAPACK
1867  char jobz = 'N'; //do NOT compute eigenvectors
1868  char uplo = 'U';//assume upper triangular
1869  int n = this->Dim();
1870  int ka = this->fBand;
1871  int kb = B.fBand;
1872  int ldab = this->fBand + 1;
1873  int ldbb = this->fBand + 1;
1874  TPZVec< double > w(0,0.);
1875  w.Resize( this->Dim() );
1876  TPZFMatrix<double> z( this->Dim(), this->Dim() );
1877  int ldz = this->Dim();
1878  TPZVec <double> work( 3 *this->Dim() );
1879  int info = -666;
1880 
1881  dsbgv_(&jobz, &uplo, &n, &ka, &kb, fDiag.begin(), &ldab, B.fDiag.begin(), &ldbb, w.begin(), &z(0,0), &ldz, work.begin(), &info);
1882  if( info > 0){
1883  TPZMatrix<double>::Error(__PRETTY_FUNCTION__,"SolveGeneralisedEigenProblem <The algorithm failed to converge>");
1884  }
1885  else if( info < 0){
1886  TPZMatrix<double>::Error(__PRETTY_FUNCTION__,"SolveGeneralisedEigenProblem <Invalid argument. Check info value for more information>");
1887  }
1888  eigenvalues.Resize( this->Dim() );
1889  for (int i = 0; i < this->Dim() ; i++) {
1890  eigenvalues[i] = w[i];
1891  }
1892 
1893 #endif
1894 
1895  return( 1 );
1896 }
1897 template<>
1898 int
1899 TPZSBMatrix<complex<double> >::SolveGeneralisedEigenProblem(TPZSBMatrix<complex<double> > &B , TPZVec <complex<double> > &eigenvalues, TPZFMatrix < complex<double> > &eigenVectors)
1900 {
1901  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
1902  {
1903  TPZMatrix<double>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
1904  }
1905 
1906 #ifdef USING_LAPACK
1907  char jobz = 'V'; //compute eigenvectors
1908  char uplo = 'U';//assume upper triangular
1909  int n = this->Dim();
1910  int ka = this->fBand;
1911  int kb = B.fBand;
1912  int ldab = this->fBand + 1;
1913  int ldbb = this->fBand + 1;
1914  TPZVec<double> w(0,0.);
1915  w.Resize( this->Dim() );
1916  TPZFMatrix <complex <double> > z( this->Dim() ,this->Dim() );
1917  int ldz = this->Dim();
1918  TPZVec <complex <double> > work( this->Dim() );
1919  TPZVec < double > rwork( 3 *this->Dim() );
1920  int info = -666;
1921 
1922  zhbgv_(&jobz, &uplo, &n, &ka, &kb, (vardoublecomplex *)fDiag.begin(), &ldab, (vardoublecomplex *)B.fDiag.begin(), &ldbb, w.begin(), (vardoublecomplex *)&z(0,0), &ldz, (vardoublecomplex *)work.begin(),rwork.begin(), &info);
1923  if( info > 0){
1924  TPZMatrix<complex<double> >::Error(__PRETTY_FUNCTION__,"Solve_EigenProblem <The algorithm failed to converge>");
1925  }
1926  else if( info < 0){
1927  TPZMatrix<complex<double> >::Error(__PRETTY_FUNCTION__,"Solve_EigenProblem <Invalid argument. Check info value for more information>");
1928  }
1929  eigenvalues.Resize( this->Dim() );
1930  eigenVectors.Resize( this->Dim() , this->Dim() );
1931  for (int i = 0; i < this->Dim() ; i++) {
1932  eigenvalues[i] = w[i];
1933  for (int j = 0 ; j < this->Dim() ; j++) {
1934  eigenVectors(i,j) = z(i,j);
1935  }
1936  }
1937 
1938 #endif
1939 
1940  return( 1 );
1941 }
1942 
1943 
1944 template<>
1945 int
1946 TPZSBMatrix<complex<double> >::SolveGeneralisedEigenProblem(TPZSBMatrix<complex<double> > &B , TPZVec <complex<double> > &eigenvalues)
1947 {
1948  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
1949  {
1950  TPZMatrix<double>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
1951  }
1952 
1953 #ifdef USING_LAPACK
1954  char jobz = 'N'; //do NOT compute eigenvectors
1955  char uplo = 'U';//assume upper triangular
1956  int n = this->Dim();
1957  int ka = this->fBand;
1958  int kb = B.fBand;
1959  int ldab = this->fBand + 1;
1960  int ldbb = this->fBand + 1;
1961  TPZVec<double> w(0,0.);
1962  w.Resize( this->Dim() );
1963  TPZFMatrix <complex <double> > z( this->Dim() ,this->Dim() );
1964  int ldz = this->Dim();
1965  TPZVec <complex <double> > work( this->Dim() );
1966  TPZVec < double > rwork( 3 *this->Dim() );
1967  int info = -666;
1968 
1969  zhbgv_(&jobz, &uplo, &n, &ka, &kb, (vardoublecomplex *)fDiag.begin(), &ldab, (vardoublecomplex *)B.fDiag.begin(), &ldbb, w.begin(), (vardoublecomplex *)&z(0,0), &ldz, (vardoublecomplex *)work.begin(),rwork.begin(), &info);
1970  if( info > 0){
1971  TPZMatrix<complex<double> >::Error(__PRETTY_FUNCTION__,"Solve_EigenProblem <The algorithm failed to converge>");
1972  }
1973  else if( info < 0){
1974  TPZMatrix<complex<double> >::Error(__PRETTY_FUNCTION__,"Solve_EigenProblem <Invalid argument. Check info value for more information>");
1975  }
1976  eigenvalues.Resize( this->Dim() );
1977  for (int i = 0; i < this->Dim() ; i++) {
1978  eigenvalues[i] = w[i];
1979  }
1980 
1981 #endif
1982 
1983  return( 1 );
1984 }
1985 
1987 #endif
1988 template<class TVar>
1990  return Hash("TPZSBMatrix") ^ TPZMatrix<TVar>::ClassId() << 1;
1991 }
1992 
1993 // Inicializando os templates
1994 template class TPZSBMatrix<float>;
1995 template class TPZSBMatrix<double>;
1996 template class TPZSBMatrix< complex<float> >;
1997 template class TPZSBMatrix< complex<double> >;
1998 template class TPZSBMatrix<long double>;
1999 
int ClassId() const override
Define the class id associated with the class.
Definition: pzsbndmat.cpp:1989
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ fabs
Definition: tfadfunc.h:140
void Copy(const TPZSBMatrix< TVar > &)
Definition: pzsbndmat.cpp:1288
int Redim(const int64_t newDim)
Redimension the matrix and zeroes its elements.
Definition: pzsbndmat.h:94
Implements symmetric band matrices. Matrix.
Definition: pzsbndmat.h:25
int Decompose_LDLt() override
Decomposes the current matrix using LDLt.
Definition: pzsbndmat.cpp:772
bool IsZero(long double a)
Returns if the value a is close Zero as the allowable tolerance.
Definition: pzreal.h:668
Contains TPZSBMatrix class which implements symmetric band matrices(hermitian, for the complex case...
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
int64_t Size() const
Definition: pzsbndmat.h:155
TPZSBMatrix & operator-=(const TPZSBMatrix< TVar > &A)
Definition: pzsbndmat.cpp:445
static int Error(const char *msg, const char *msg2=0)
Returns error messages.
Definition: pzmatrix.cpp:1402
virtual void resize(const int64_t newsize)
Definition: pzvec.h:213
TPZSBMatrix & operator=(const TPZSBMatrix< TVar > &A)
Operadores com matrizes SKY LINE.
Definition: pzsbndmat.cpp:380
int Clear() override
It clears data structure.
Definition: pzsbndmat.cpp:1275
MatrixOutputFormat
Defines output format.
Definition: pzmatrix.h:55
int64_t fRow
Number of rows in matrix.
Definition: pzmatrix.h:779
void PrepareZ(const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar beta, const int opt) const
Is an auxiliar method used by MultiplyAdd.
Definition: pzmatrix.cpp:135
char fDecomposed
Decomposition type used to decompose the current matrix.
Definition: pzmatrix.h:783
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
virtual int Subst_Forward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is lower triangular.
Definition: pzmatrix.cpp:1284
#define MAX(a, b)
Gets maxime value between a and b.
Definition: pzreal.h:81
char fDefPositive
Definite Posistiveness of current matrix.
Definition: pzmatrix.h:785
static TVar gZero
Initializing value to static variable.
Definition: pzmatrix.h:786
TVar & operator()(int64_t row, int64_t col)
Definition: pzsbndmat.cpp:311
TPZSBMatrix< TVar > & operator*=(const TVar v)
Definition: pzsbndmat.cpp:530
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
Definition: pzvec.h:373
int Resize(const int64_t newDim, const int64_t) override
Redimension the matrix keeping original elements.
Definition: pzsbndmat.cpp:548
int64_t fBand
Definition: pzsbndmat.h:174
Contains TPZMatrixclass which implements full matrix (using column major representation).
const TVar & GetVal(const int64_t row, const int64_t col) const override
Get values without bounds checking This method is faster than "Get" if DEBUG is defined.
Definition: pzsbndmat.cpp:244
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
TPZSBMatrix & operator+=(const TPZSBMatrix< TVar > &A)
Definition: pzsbndmat.cpp:427
int Subst_LBackward(TPZFMatrix< TVar > *B) const override
Computes B = Y, where A*Y = B, A is upper triangular with A(i,i)=1.
Definition: pzsbndmat.cpp:1242
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
string res
Definition: test.py:151
int PutVal(const int64_t row, const int64_t col, const TVar &element) override
Put values without bounds checking This method is faster than "Put" if DEBUG is defined.
Definition: pzsbndmat.cpp:163
void AutoFill(int64_t nrow, int64_t ncol, int symmetric)
Definition: pzsbndmat.cpp:63
TPZVec< TVar > fDiag
Definition: pzsbndmat.h:173
int Subst_Forward(TPZFMatrix< TVar > *B) const override
To solve linear systems.
Definition: pzsbndmat.cpp:1163
TPZSBMatrix operator+(const TPZSBMatrix< TVar > &A) const
Definition: pzsbndmat.cpp:392
int SetBand(const int64_t newBand)
Definition: pzsbndmat.cpp:605
T * begin() const
Casting operator. Returns The fStore pointer.
Definition: pzvec.h:450
#define MIN(a, b)
Gets minime value between a and b.
Definition: pzreal.h:85
virtual int Redim(const int64_t newRows, const int64_t newCols)
Redimensions the matrix reinitializing it with zero.
Definition: pzmatrix.h:289
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
virtual int64_t Dim() const
Returns the dimension of the matrix if the matrix is square.
Definition: pzmatrix.h:892
int Subst_Backward(TPZFMatrix< TVar > *b) const override
Computes B = Y, where A*Y = B, A is upper triangular.
Definition: pzsbndmat.cpp:1231
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
TPZSBMatrix< TVar > operator*(const TVar v) const
Definition: pzsbndmat.cpp:510
int64_t fCol
Number of cols in matrix.
Definition: pzmatrix.h:781
void Print(const char *name=NULL, std::ostream &out=std::cout, const MatrixOutputFormat form=EFormatted) const override
It prints the matrix data in a MatrixFormat Rows X Cols.
Definition: pzsbndmat.cpp:330
virtual int Decompose_Cholesky()
Decomposes the current matrix using Cholesky method. The current matrix has to be symmetric...
Definition: pzmatrix.cpp:1252
static void Swap(int64_t *a, int64_t *b)
Swaps contents of a in b and b in a.
Definition: pzmatrix.h:949
int Subst_Diag(TPZFMatrix< TVar > *B) const override
Computes B = Y, where A*Y = B, A is diagonal matrix.
Definition: pzsbndmat.cpp:1215
int Subst_LForward(TPZFMatrix< TVar > *B) const override
Computes B = Y, where A*Y = B, A is lower triangular with A(i,i)=1.
Definition: pzsbndmat.cpp:1178
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
TPZSBMatrix< TVar > operator-() const
Definition: pzsbndmat.h:88
TVar Random(TVar)
Definition: pzsbndmat.cpp:45
int Zero() override
Zeroes the elements of the matrix.
Definition: pzsbndmat.cpp:587
int PutVal(const int64_t row, const int64_t col, const TVar &value) override
Put values without bounds checking This method is faster than "Put" if DEBUG is defined.
Definition: pzfmatrix.h:548
void MultAdd(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar alpha=1., const TVar beta=0., const int opt=0) const override
Computes z = beta * y + alpha * opt(this)*x.
Definition: pzsbndmat.cpp:460
const TVar & GetVal(const int64_t row, const int64_t col) const override
Get values without bounds checking This method is faster than "Get" if DEBUG is defined.
Definition: pzfmatrix.h:566
int64_t Index(int64_t i, int64_t j) const
Definition: pzsbndmat.h:164
int ClassId() const override
Define the class id associated with the class.
Definition: pzmatrix.h:957
virtual int Subst_Backward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is upper triangular.
Definition: pzmatrix.cpp:1309
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60