NeoPZ
pzfmatrix.cpp
Go to the documentation of this file.
1 
7 #include "pzfmatrix.h"
8 #include <math.h>
9 #include <stdbool.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <cmath>
13 #include <complex>
14 #include <map>
15 #include <sstream>
16 #include <string>
17 #include <utility>
18 #include "pzerror.h"
19 #include "pzaxestools.h"
20 #include "pzextractval.h"
21 #include "pzlog.h"
22 #include "pzmatrix.h"
23 #include "TPZSavable.h"
24 #include "pzvec.h"
25 #include "tpzverysparsematrix.h"
26 
27 #ifdef _AUTODIFF
28 #include "tfad.h"
29 #include "fad.h"
30 #endif
31 
32 class TPZStream;
33 
34 #ifdef PZDEBUG
35 #define DEBUG2
36 #endif
37 
38 #ifdef LOG4CXX
39 static LoggerPtr logger(Logger::getLogger("pz.matrix.tpzfmatrix"));
40 static LoggerPtr loggerCheck(Logger::getLogger("pz.checkconsistency"));
41 #endif
42 
43 #ifdef USING_LAPACK
44 
45 #include "TPZLapack.h"
46 #define BLAS_MULT
47 #endif
48 
49 
50 //#define IsZero( a ) ( fabs(a) < 1.e-20)
51 
52 
53 using namespace std;
54 
55 /********************/
56 /*** Constructors ***/
57 
58 template <class TVar>
61 TPZMatrix<TVar>(mat), fElem(0),fGiven(0),fSize(0) {
62  if(this->fRow*this->fCol) {
63 
64  fElem = new TVar[this->fRow*this->fCol];
65  TVar * p = fElem;
66  int64_t i,j;
67  for(j=0; j<this->fCol; j++) {
68  for(i=0; i<this->fRow; i++) {
69  *p++ = mat.GetVal(i,j);
70  }
71  }
72  }
73 }
74 
75 
76 /********************************/
77 /*** Constructor( TPZFMatrix<TVar> & ) ***/
78 
79 template<class TVar>
82 TPZMatrix<TVar>( A.fRow, A.fCol ), fElem(0), fGiven(0), fSize(0) {
83  int64_t size = this->fRow * this->fCol;
84  if(!size) return;
85  fElem = new TVar[ size ] ;
86 #ifdef PZDEBUG2
87  if ( size && fElem == NULL ) Error( "Constructor <memory allocation error>." );
88 #endif
89  // Copia a matriz
90  TVar * src = A.fElem;
91  TVar * p = fElem;
92  memcpy((void *)(p),(void *)(src),(size_t)size*sizeof(TVar));
93 }
94 
95 /********************************/
96 /*** Constructor( TPZVerySparseMatrix<TVar> & ) ***/
97 
98 template<class TVar>
101 TPZMatrix<TVar>( A.Rows(), A.Cols() ), fElem(0), fGiven(0), fSize(0) {
102 
103  int64_t size = this->fRow * this->fCol;
104  if(!size) return;
105  fElem = new TVar[ size ] ;
106 
107 #ifdef PZDEBUG2
108  if ( size && fElem == NULL ) Error( "Constructor <memory allocation error>." );
109 #endif
110 
111  typename std::map <std::pair<int64_t, int64_t>, TVar>::const_iterator it = A.MapBegin();
112  typename std::map <std::pair<int64_t, int64_t>, TVar>::const_iterator end = A.MapEnd();
113 
114  TVar * p = fElem;
115  memset((void *)p, 0, (size_t)size*sizeof(TVar));
116 
117  for (; it != end; it++) {
118  const std::pair<int64_t, int64_t>& key = it->first;
119  PutVal(key.first, key.second, it->second);
120  }
121 
122 }
123 
124 
125 
126 /******** Operacoes com matrizes FULL ********/
127 
128 /******************/
129 /*** Operator = ***/
130 template<class TVar>
132  if(this == &A) return *this;
133  int64_t size = A.fRow * A.fCol;
134 
135  TVar * newElem = fElem;
136  if(fSize < size && size != this->fRow*this->fCol) {
137  newElem = new TVar
138  [size] ;
139  } else if (fSize >= size) {
140  newElem = fGiven;
141  }
142 
143  if ( newElem == NULL && size > 0) Error( "Operator= <memory allocation error>." );
144  if (fElem && fElem != newElem && fElem != fGiven) delete[]( fElem );
145  this->fRow = A.fRow;
146  this->fCol = A.fCol;
147  fElem = newElem;
148 
149  // Copia a matriz
150  memcpy((void *)(fElem),(void *)(A.fElem),(size_t)size*sizeof(TVar));
151 
153 
154 
155  return *this;
156 }
157 
158 template< class TVar >
159 TPZFMatrix<TVar>& TPZFMatrix<TVar>::operator= (const std::initializer_list<TVar>& list) {
160  Resize(list.size(), 1);
161 
162  auto it = list.begin();
163  auto it_end = list.end();
164  TVar* aux = fElem;
165  for (; it != it_end; it++, aux++)
166  *aux = *it;
167 
168  return *this;
169 }
170 
171 template< class TVar >
172 TPZFMatrix<TVar>& TPZFMatrix<TVar>::operator= (const std::initializer_list< std::initializer_list<TVar> >& list) {
173  size_t n_row = list.size();
174  size_t n_col = 1;
175 
176  auto row_it = list.begin();
177  auto row_it_end = list.end();
178 
179 #ifdef PZDEBUG
180  bool col_n_found = false;
181  for (auto it = row_it; it != row_it_end; it++) {
182  if (!col_n_found) {
183  n_col = it->size();
184  col_n_found = true;
185  }
186  else {
187  if (n_col != it->size())
188  Error("TPZFMatrix constructor: inconsistent number of columns in initializer list");
189  }
190  }
191 #else
192  n_col = row_it->size();
193 #endif
194  Resize(n_row, n_col);
195 
196  for (uint32_t row_n = 0; row_it != row_it_end; row_it++, row_n++) {
197  auto col_it = row_it->begin();
198  auto col_it_end = row_it->end();
199  for (uint32_t col_n = 0; col_it != col_it_end; col_it++, col_n++) {
200  fElem[col_n * this->fRow + row_n] = *col_it;
201  }
202  }
203 
204  return *this;
205 }
206 
207 
208 template <class TVar>
210  if(rhs.Cols() != this->Cols()) {
211  PZError << "TPZFMatrix::AddFel number of columns does not correspond\n";
212  DebugStop();
213  return;
214  }
215  int64_t ncol = this->Cols();
216  int64_t nrow = rhs.Rows();
217  int64_t i,j;
218  for(j=0; j<ncol; j++) {
219  for(i=0; i<nrow; i++) {
220  operator()(destination[i],j) += rhs(i,j);
221  }
222  }
223 }
224 
225 template<class TVar>
227  if(rhs.Cols() != this->Cols() && source.NElements()) {
228  PZError << "TPZFMatrix::AddFel number of columns does not correspond\n";
229  DebugStop();
230  return;
231  }
232  int64_t ncol = this->Cols();
233  int64_t nrow = source.NElements();
234  int64_t i,j;
235  for(j=0; j<ncol; j++) {
236  for(i=0; i<nrow; i++) {
237  operator()(destination[i],j) += rhs(source[i],j);
238  }
239  }
240 }
241 
242 template<>
244  if(rhs.Cols() != this->Cols() && source.NElements()) {
245  PZError << "TPZFMatrix::AddFel number of columns does not correspond\n";
246  DebugStop();
247  return;
248  }
249  int64_t ncol = this->Cols();
250  int64_t nrow = source.NElements();
251  int64_t i,j;
252  for(j=0; j<ncol; j++) {
253  for(i=0; i<nrow; i++) {
254 #pragma omp atomic
255  operator()(destination[i],j) += rhs(source[i],j);
256  }
257  }
258 }
259 
260 template<>
262  if(rhs.Cols() != this->Cols() && source.NElements()) {
263  PZError << "TPZFMatrix::AddFel number of columns does not correspond\n";
264  DebugStop();
265  return;
266  }
267  int64_t ncol = this->Cols();
268  int64_t nrow = source.NElements();
269  int64_t i,j;
270  for(j=0; j<ncol; j++) {
271  for(i=0; i<nrow; i++) {
272 #pragma omp atomic
273  operator()(destination[i],j) += rhs(source[i],j);
274  }
275  }
276 }
277 
278 
279 
280 /*******************************/
281 /*** Operator+( TPZFMatrix>& ) ***/
282 
283 template <class TVar>
285  if ( (A.Rows() != this->Rows()) || (A.Cols() != this->Cols()) )
286  Error( "Operator+ <matrixs with different dimensions>" );
287 
289  res.Redim( this->Rows(), this->Cols() );
290  int64_t size = ((int64_t)this->Rows()) * this->Cols();
291  TVar * pm = fElem, *plast = fElem+size;
292  TVar * pa = A.fElem;
293  TVar * pr = res.fElem;
294 
295  while(pm < plast) *pr++ = (*pm++) + (*pa++);
296 
297  return( res );
298 }
299 
300 /*******************************/
301 /*** Operator-( TPZFMatrix<>& ) ***/
302 template <class TVar>
304  if ( (A.Rows() != this->Rows()) || (A.Cols() != this->Cols()) )
305  Error( "Operator- <matrixs with different dimensions>" );
306 
308  res.Redim( this->Rows(), this->Cols() );
309  int64_t size = ((int64_t)this->Rows()) * this->Cols();
310  TVar * pm = fElem;
311  TVar * pa = A.fElem;
312  TVar * pr = res.fElem, *prlast =pr+size;
313 
314  while(pr < prlast) *pr++ = (*pm++) - (*pa++);
315  return( res );
316 }
317 
318 template<>
319 void TPZFMatrix<int>::GramSchmidt(TPZFMatrix<int> &Orthog, TPZFMatrix<int> &TransfToOrthog)
320 {
321  std::cout << "Nothing to do\n";
322  DebugStop();
323 }
324 
325 #ifdef _AUTODIFF
326 template <>
328 {
329  DebugStop();
330 }
331 
332 template <>
334 {
335  DebugStop();
336 }
337 
338 #endif
339 
340 template <class TVar>
342 {
343 #ifdef LOG4CXX2
344  if (logger->isDebugEnabled())
345  {
346  std::stringstream sout;
347  Print("GrSchmidt Entrada",sout);
348  LOGPZ_DEBUG(logger,sout.str())
349  }
350 #endif
351 
352  double scale = 1.;
353  for(int64_t j = 0; j < this->Cols(); j++)
354  {
355  double norm = 0.;
356  for(int64_t i = 0; i < this->Rows(); i++)
357  {
358  norm += fabs(TPZExtractVal::val(this->GetVal(i,j)*this->GetVal(i,j)));
359  }
360  norm = sqrt(norm);
361  if(norm > 1.e-10)
362  {
363  if((1.)/norm > scale) scale = (1.)/norm;
364  }
365  }
366 
367  this->operator *=( scale );
368 
369  int64_t QTDcomp = this->Rows();
370  int64_t QTDvec = this->Cols();
371  Orthog.Resize(QTDcomp,QTDvec);
372  Orthog.Zero();
374  for(int64_t r = 0; r < QTDcomp; r++)
375  {
376  for(int64_t c = 0; c < QTDvec; c++)
377  {
378  Orthog(r,c) = GetVal(r,c);
379  }
380  }
381 
382 #ifdef PZDEBUG
383  int check = 0;
384  for(int64_t c = 0; c < QTDvec; c++)
385  {
386  TVar summ = 0.;
387  for(int64_t r = 0; r < QTDcomp; r++)
388  {
389  summ += fabs(GetVal(r,c));
390  }
391  if(fabs(summ) < 0.00001)
392  {
393  std::stringstream sout;
394  sout << "Null Vector on Gram-Schmidt Method! Col = " << c << "\n";
395  LOGPZ_ERROR(logger,sout.str())
396  check = 1;
397  }
398  }
399 #endif
400 
401  TVar dotUp, dotDown;
402  for(int64_t c = 1; c < QTDvec; c++)
403  {
404  for(int64_t stop = 0; stop < c; stop++)
405  {
406  dotUp = 0.;
407  dotDown = 0.;
408  for(int64_t r = 0; r < QTDcomp; r++)
409  {
410  dotUp += GetVal(r,c)*Orthog(r,stop);
411  dotDown += Orthog(r,stop)*Orthog(r,stop);
412  }
413  if(fabs(dotDown) < 1.E-8)
414  {
415 #ifdef PZDEBUG
416  if(check == 0)
417  {
418  std::stringstream sout;
419  sout << "Parallel Vectors on Gram-Schmidt Method! Col = " << stop << "\n";
420  LOGPZ_ERROR(logger,sout.str())
421  }
422 #endif
423 
424  for(int64_t r = 0; r < QTDcomp; r++)
425  {
426  Orthog(r,stop) = 0.;
427  }
428  }
429  else
430  {
431 #ifdef LOG4CXX2
432  if (logger->isDebugEnabled())
433  {
434  std::stringstream sout;
435  sout << "dotdown = " << dotDown << " dotup = " << dotUp;
436  LOGPZ_DEBUG(logger,sout.str())
437  }
438 #endif
439 
440  for(int64_t r = 0; r < QTDcomp; r++)
441  {
442  Orthog(r,c) -= dotUp*Orthog(r,stop)/dotDown;
443  }
444  }
445  }
446  }
447  for(int64_t c = 0; c < QTDvec; c++)
448  {
449  dotUp = 0.;
450  for(int64_t r = 0; r < QTDcomp; r++)
451  {
452  dotUp += Orthog(r,c)*Orthog(r,c);
453  }
454  if(fabs(dotUp) > 1.e-8)
455  {
456  for(int64_t r = 0; r < QTDcomp; r++)
457  {
458  Orthog(r,c) = Orthog(r,c)/sqrt(dotUp);
459  }
460  }
461  else {
462 #ifdef LOG4CXX
463  std::stringstream sout;
464  sout << "Linearly dependent columns dotUp = " << dotUp;
465  LOGPZ_ERROR(logger,sout.str())
466 #endif
467 
468  for(int64_t r = 0; r < QTDcomp; r++)
469  {
470  Orthog(r,c) = 0.;
471  }
472  }
473 
474  }
475  Orthog.Multiply(*this,TransfToOrthog,1);
476 
477  this->operator*= ( 1./scale );
478  TransfToOrthog.operator*= ( 1./scale );
479 
480 #ifdef LOG4CXX2
481  if (logger->isDebugEnabled())
482  {
483  std::stringstream sout;
484  sout << endl;
485  sout << "Output GS" << endl;
486  Orthog.Print("Orthog matrix",sout);
487  TransfToOrthog.Print("TransfToOrthog matrix",sout);
488  LOGPZ_DEBUG(logger,sout.str())
489  }
490 #endif
491 
492 #ifdef PZDEBUG
493  TPZFNMatrix<9, TVar> OrthogT;
494  Orthog.Transpose(&OrthogT);
496 #endif
497 }
498 
499 template <>
501 {
502  std::cout << __PRETTY_FUNCTION__ << " please implement me\n";
503  DebugStop();
504 }
505 
506 template <class TVar>
508 {
509  TPZFNMatrix<100, TVar> copy(*this);
510  inverse.Redim(this->Rows(),this->Rows());
511  int64_t r;
512  for(r=0; r<this->Rows(); r++) inverse(r,r) = 1.;
513  copy.Solve_LU(&inverse);
514  determinant = 1.;
515  for(r=0; r<this->Rows(); r++) determinant *= copy(r,r);
516 }
517 
518 #ifdef USING_LAPACK
519 
520 template <class TVar>
523 {
524  fPivot.Resize(this->Rows());
525  for(int64_t i = 0; i < this->Rows(); i++){
526  fPivot[i] = i+1; // Fortran based indexing
527  }
528 }
529 
530 #endif
531 
532 template <class TVar>
533 void TPZFMatrix<TVar>::MultAdd(const TVar *ptr, int64_t rows, int64_t cols, const TPZFMatrix<TVar> &x,const TPZFMatrix<TVar> &y, TPZFMatrix<TVar> &z,
534  const TVar alpha,const TVar beta ,const int opt)
535 {
536 
537 
538  if ((!opt && cols != x.Rows()) || (opt && rows != x.Rows())) {
539  Error( "TPZFMatrix::MultAdd matrix x with incompatible dimensions>" );
540  return;
541  }
542  if(beta != (TVar)0. && ((!opt && rows != y.Rows()) || (opt && cols != y.Rows()) || y.Cols() != x.Cols())) {
543  Error( "TPZFMatrix::MultAdd matrix y with incompatible dimensions>" );
544  return;
545  }
546  if(!opt) {
547  if(z.Cols() != x.Cols() || z.Rows() != rows) {
548  z.Redim(rows,x.Cols());
549  }
550  } else {
551  if(z.Cols() != x.Cols() || z.Rows() != cols) {
552  z.Redim(cols,x.Cols());
553  }
554  }
555  unsigned numeq = opt ? cols : rows;
556  int64_t xcols = x.Cols();
557  int64_t ic, c;
558  if(!(rows*cols)) return;
559  for (ic = 0; ic < xcols; ic++) {
560  TVar *zp = &z(0,ic), *zlast = zp+numeq;
561  if(beta != (TVar)0.) {
562  const TVar *yp = &y.g(0,ic);
563  if(&z != &y) {
564  memcpy((void *)zp,(void *)yp,numeq*sizeof(TVar));
565  }
566  for(int64_t i=0; i< numeq; i++) for(int64_t c=0; c<xcols; c++) z(i,c) *= beta;
567  } else {
568  while(zp != zlast) {
569  *zp = 0.;
570  zp ++;
571  }
572  }
573  }
574 
575 
576  for (ic = 0; ic < xcols; ic++) {
577  if(!opt) {
578  for ( c = 0; c<cols; c++) {
579  TVar * zp = &z(0,ic), *zlast = zp+rows;
580  const TVar * fp = ptr +rows*c;
581  const TVar * xp = &x.g(c,ic);
582  while(zp < zlast) {
583  *zp += alpha* *fp++ * *xp;
584  zp ++;
585  }
586  }
587  } else {
588  const TVar * fp = ptr;
589  TVar *zp = &z(0,ic);
590  for (c = 0; c<cols; c++) {
591  TVar val = 0.;
592  // bug correction philippe 5/2/97
593  // REAL * xp = &x(0,ic), xlast = xp + numeq;
594  const TVar *xp = &x.g(0,ic);
595  const TVar *xlast = xp + rows;
596  while(xp < xlast) {
597  val += *fp++ * *xp;
598  xp ++;
599  }
600  *zp += alpha *val;
601  zp ++;
602  }
603  }
604  }
605 
606 
607 
608 
609 
610 }
611 
612 #ifdef USING_LAPACK
613 template<>
615  const double alpha,const double beta,const int opt) const {
616 
617 #ifdef PZDEBUG
618  if ((!opt && this->Cols() != x.Rows()) || (opt && this->Rows() != x.Rows())) {
619  Error( "TPZFMatrix::MultAdd matrix x with incompatible dimensions>" );
620  return;
621  }
622  if(beta != (double)0. && ((!opt && this->Rows() != y.Rows()) || (opt && this->Cols() != y.Rows()) || y.Cols() != x.Cols())) {
623  Error( "TPZFMatrix::MultAdd matrix y with incompatible dimensions>" );
624  return;
625  }
626 #endif
627  if(!opt) {
628  if(z.Cols() != x.Cols() || z.Rows() != this->Rows()) {
629  z.Redim(this->Rows(),x.Cols());
630  }
631  } else {
632  if(z.Cols() != x.Cols() || z.Rows() != this->Cols()) {
633  z.Redim(this->Cols(),x.Cols());
634  }
635  }
636  if(this->Cols() == 0) {
637  z.Zero();
638  if (beta != 0) {
639  z = y;
640  z *= beta;
641  }
642  return;
643  }
644  if (beta != (double)0.) {
645  z = y;
646  }
647  if (Rows() == 0 || Cols() == 0 || x.Rows() == 0 || x.Cols() == 0) {
648  return;
649  }
650  if (!opt) {
651  cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, this->Rows(), x.Cols(), this->Cols(),
652  alpha, this->fElem, this->Rows(), x.fElem, x.Rows(), beta, z.fElem, z.Rows());
653  } else {
654  cblas_dgemm(CblasColMajor, CblasTrans, CblasNoTrans, this->Cols(), x.Cols(), this->Rows(),
655  alpha, this->fElem, this->Rows(), x.fElem, x.Rows(), beta, z.fElem, z.Rows());
656  }
657 
658 }
659 template<>
661  const float alpha,const float beta,const int opt) const {
662 
663 #ifdef PZDEBUG
664  if ((!opt && this->Cols() != x.Rows()) || (opt && this->Rows() != x.Rows())) {
665  Error( "TPZFMatrix::MultAdd matrix x with incompatible dimensions>" );
666  return;
667  }
668  if(beta != (float)0. && ((!opt && this->Rows() != y.Rows()) || (opt && this->Cols() != y.Rows()) || y.Cols() != x.Cols())) {
669  Error( "TPZFMatrix::MultAdd matrix y with incompatible dimensions>" );
670  return;
671  }
672 #endif
673  if(!opt) {
674  if(z.Cols() != x.Cols() || z.Rows() != this->Rows()) {
675  z.Redim(this->Rows(),x.Cols());
676  }
677  } else {
678  if(z.Cols() != x.Cols() || z.Rows() != this->Cols()) {
679  z.Redim(this->Cols(),x.Cols());
680  }
681  }
682  if(this->Cols() == 0) {
683  z.Zero();
684  if (beta != 0) {
685  z = y;
686  z *= beta;
687  }
688  return;
689  }
690  if (beta != (float)0.) {
691  z = y;
692  }
693  if (Rows() == 0 || Cols() == 0 || x.Rows() == 0 || x.Cols() == 0) {
694  return;
695  }
696  if (!opt) {
697  cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, this->Rows(), x.Cols(), this->Cols(),
698  alpha, this->fElem, this->Rows(), x.fElem, x.Rows(), beta, z.fElem, z.Rows());
699  } else {
700  cblas_sgemm(CblasColMajor, CblasTrans, CblasNoTrans, this->Cols(), x.Cols(), this->Rows(),
701  alpha, this->fElem, this->Rows(), x.fElem, x.Rows(), beta, z.fElem, z.Rows());
702  }
703 
704 }
705 
706 template<>
707 void TPZFMatrix<std::complex<double> >::MultAdd(const TPZFMatrix<std::complex<double> > &x,const TPZFMatrix<std::complex<double> > &y, TPZFMatrix<std::complex<double> > &z,
708  const std::complex<double> alpha,const std::complex<double> beta,const int opt) const {
709 
710 #ifdef PZDEBUG
711  if ((!opt && this->Cols() != x.Rows()) || (opt && this->Rows() != x.Rows())) {
712  Error( "TPZFMatrix::MultAdd matrix x with incompatible dimensions>" );
713  return;
714  }
715  if(beta.real() != 0. && ((!opt && this->Rows() != y.Rows()) || (opt && this->Cols() != y.Rows()) || y.Cols() != x.Cols())) {
716  Error( "TPZFMatrix::MultAdd matrix y with incompatible dimensions>" );
717  return;
718  }
719 #endif
720  if(!opt) {
721  if(z.Cols() != x.Cols() || z.Rows() != this->Rows()) {
722  z.Redim(this->Rows(),x.Cols());
723  }
724  } else {
725  if(z.Cols() != x.Cols() || z.Rows() != this->Cols()) {
726  z.Redim(this->Cols(),x.Cols());
727  }
728  }
729  if(this->Cols() == 0) {
730  z.Zero();
731  }
732  if (beta.real() != 0.) {
733  z = y;
734  }
735  if (!opt) {
736  cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, this->Rows(), x.Cols(), this->Cols(),
737  &alpha, this->fElem, this->Rows(), x.fElem, x.Rows(), &beta, z.fElem, z.Rows());
738  } else {
739  cblas_zgemm(CblasColMajor, CblasTrans, CblasNoTrans, this->Cols(), x.Cols(), this->Rows(),
740  &alpha, this->fElem, this->Rows(), x.fElem, x.Rows(), &beta, z.fElem, z.Rows());
741  }
742 
743 }
744 
745 #endif // USING_LAPACK
746 
756 template <class TVar>
758  const TVar alpha,const TVar beta,const int opt) const {
759 
760  if ((!opt && this->Cols() != x.Rows()) || (opt && this->Rows() != x.Rows())) {
761  Error( "TPZFMatrix::MultAdd matrix x with incompatible dimensions>" );
762  return;
763  }
764  if(beta != (TVar)0. && ((!opt && this->Rows() != y.Rows()) || (opt && this->Cols() != y.Rows()) || y.Cols() != x.Cols())) {
765  Error( "TPZFMatrix::MultAdd matrix y with incompatible dimensions>" );
766  return;
767  }
768  if(!opt) {
769  if(z.Cols() != x.Cols() || z.Rows() != this->Rows()) {
770  z.Redim(this->Rows(),x.Cols());
771  }
772  } else {
773  if(z.Cols() != x.Cols() || z.Rows() != this->Cols()) {
774  z.Redim(this->Cols(),x.Cols());
775  }
776  }
777  if(this->Cols() == 0)
778  {
779  z.Zero();
780  }
781  unsigned numeq = opt ? this->Cols() : this->Rows();
782  int64_t rows = this->Rows();
783  int64_t cols = this->Cols();
784  int64_t xcols = x.Cols();
785  int64_t ic, c;
786  if (numeq)
787  {
788  for (ic = 0; ic < xcols; ic++) {
789  TVar *zp = &z(0,ic), *zlast = zp+numeq;
790  if(beta != (TVar)0.) {
791  const TVar *yp = &y.g(0,ic);
792  if(&z != &y) {
793  memcpy((void *)zp,(void *)yp,numeq*sizeof(TVar));
794  }
795  for(int64_t i=0; i< numeq; i++) z(i,ic) *= beta;
796 
797  } else {
798  while(zp != zlast) {
799  *zp = 0.;
800  zp ++;
801  }
802  }
803  }
804  }
805 
806  if(!(rows*cols)) return;
807 
808  for (ic = 0; ic < xcols; ic++) {
809  if(!opt) {
810  for ( c = 0; c<cols; c++) {
811  TVar * zp = &z(0,ic), *zlast = zp+rows;
812  TVar * fp = fElem +rows*c;
813  const TVar * xp = &x.g(c,ic);
814  while(zp < zlast) {
815  *zp += alpha* *fp++ * *xp;
816  zp ++;
817  }
818  }
819  } else {
820  TVar * fp = fElem, *zp = &z(0,ic);
821  for (c = 0; c<cols; c++) {
822  TVar val = 0.;
823  // bug correction philippe 5/2/97
824  // REAL * xp = &x(0,ic), xlast = xp + numeq;
825  const TVar *xp = &x.g(0,ic);
826  const TVar *xlast = xp + rows;
827  while(xp < xlast) {
828  val += *fp++ * *xp;
829  xp ++;
830  }
831  *zp += alpha *val;
832  zp ++;
833  }
834  }
835  }
836 
837 }
838 
839 /********************************/
840 /*** Operator+=( TPZFMatrix<>& ) ***/
841 template <class TVar>
843  if ( (A.Rows() != this->Rows()) || (A.Cols() != this->Cols()) )
844  Error( "Operator+= <matrixs with different dimensions>" );
845 
846  int64_t size = ((int64_t)this->Rows()) * this->Cols();
847  TVar * pm = fElem, *pmlast=pm+size;
848  TVar * pa = A.fElem;
849  while(pm < pmlast) (*pm++) += (*pa++);
850  return( *this );
851 }
852 
853 /*******************************/
854 /*** Operator-=( TPZFMatrix<>& ) ***/
855 template <class TVar>
857  if ( (A.Rows() != this->Rows()) || (A.Cols() != this->Cols()) )
858  Error( "Operator-= <matrixs with different dimensions>" );
859 
860  int64_t size = ((int64_t)this->Rows()) * this->Cols();
861  TVar * pm = fElem;
862  TVar * pa = A.fElem;
863 
864  for ( int64_t i = 0; i < size; i++ ) *pm++ -= *pa++;
865 
866  return( *this );
867 }
868 
869 #ifdef USING_LAPACK
870 template <>
871 void TPZFMatrix<double>::ZAXPY(const double alpha,const TPZFMatrix<double> &p) {
872  // //Como definir o tamanho dos vetores
873  int size = (fRow*fCol) ;
874  cblas_daxpy(size, alpha, &p.fElem[0], 1, &fElem[0], 1);
875 }
876 #endif
877 
878 template <class TVar>
879 void TPZFMatrix<TVar>::ZAXPY(const TVar alpha,const TPZFMatrix<TVar> &p) {
880 
881  TVar * pt = fElem;
882  TVar * pp = p.fElem;
883  TVar * ptlast = fElem + this->fRow*this->fCol;
884  while(pt < ptlast) *pt++ += alpha * *pp++;
885 }
886 
887 #ifdef USING_LAPACK
888 template<>
889 void TPZFMatrix<double>::TimesBetaPlusZ(const double beta,const TPZFMatrix<double> &z)
890 {
891  int size = fRow*fCol;
892  cblas_dscal(size,beta,fElem,1);
893  cblas_daxpy(size,1.,z.fElem,1,fElem,1);
894 }
895 #endif
896 
897 template<class TVar>
898 void TPZFMatrix<TVar>::TimesBetaPlusZ(const TVar beta,const TPZFMatrix<TVar> &z) {
899  // #ifdef USING_ATLAS
900  // int size = fRow*fCol;
901  // cblas_dscal(size,beta,fElem,1);
902  // cblas_daxpy(size,1.,z.fElem,1,fElem,1);
903  // #else
904 
905  TVar * pt = fElem, *ptlast = fElem + this->fRow*this->fCol;
906  TVar * pz = z.fElem;
907  // while(pt < ptlast) *pt++ *= (beta) + *pz++;
908  while(pt < ptlast) {
909  *pt *= (beta);
910  *pt++ += *pz++;
911  }
912  // #endif
913 }
914 
915 /******** Operacoes com MATRIZES GENERICAS ********/
916 
917 /******************/
918 /*** Operator = ***/
919 template <class TVar>
921  int64_t arows = A.Rows();
922  int64_t acols = A.Cols();
923  int64_t size = arows * acols;
924  if(fElem != fGiven) {
925  delete []fElem;
926  fElem = 0;
927  }
928  this->fRow = arows;
929  this->fCol = acols;
930  if(fSize < size) {
931  fElem = new TVar[ arows * acols ] ;
932  } else {
933  fElem = fGiven;
934  }
935  TVar * dst = fElem;
936  for ( int64_t c = 0; c < this->fCol; c++ )
937  for ( int64_t r = 0; r < this->fRow; r++ )
938  *dst++ = A.Get( r, c );
939  return( *this );
940 }
941 
942 
943 /******** Operacoes com valores NUMERICOS ********/
944 
945 /******************/
946 /*** Operator = ***/
947 template <class TVar>
949  int64_t size = ((int64_t)this->fRow) * this->fCol;
950  TVar * dst = fElem;
951  for ( int64_t i = 0; i < size; i++ )
952  *dst++ = value;
953  this->fDecomposed = 0;
954  return *this;
955 }
956 
957 
958 
959 /***************************/
960 /*** Operator+=( value ) ***/
961 template <class TVar>
963  int64_t size = ((int64_t)this->Rows()) * this->Cols();
964 
965  TVar * dst = fElem, *dstlast = dst+size;
966  while ( dst < dstlast ) *dst++ += value;
967  return( *this );
968 }
969 
970 
971 
972 /**************************/
973 /*** Operator+( value ) ***/
974 template <class TVar>
976  TPZFMatrix<TVar> res( *this );
977  int64_t size = ((int64_t)this->Rows()) * this->Cols();
978 
979  TVar * dst = res.fElem, *dstlast = dst+size;
980  while ( dst < dstlast )
981  *dst++ += value;
982 
983  return( res );
984 }
985 
986 template <class TVar>
988  return operator+( -val );
989 }
990 
991 
992 /**************************/
993 /*** Operator*( value ) ***/
994 
995 template <class TVar>
997 {
998  TPZFMatrix<TVar> res( *this );
999  res *= value;
1000  return( res );
1001 }
1002 
1003 /***************************/
1004 /*** Operator*=( value ) ***/
1005 template <class TVar>
1007  int64_t size = ((int64_t)this->Rows()) * this->Cols();
1008  TVar * dst = fElem, *dstlast = dst+size;
1009  while ( dst < dstlast ) *dst++ *= value;
1010  return( *this );
1011 }
1012 
1013 /**************/
1014 /*** Resize ***/
1015 template <class TVar>
1016 int TPZFMatrix<TVar>::Resize(const int64_t newRows,const int64_t newCols) {
1017  if ( newRows == this->Rows() && newCols == this->Cols() ) return( 1 );
1018  int64_t newsize = ((int64_t)newRows)*newCols;
1019  TVar * newElem;
1020  if(fGiven && fElem != fGiven && newsize <= fSize)
1021  {
1022  newElem = fGiven;
1023  } else
1024  {
1025  newElem = new TVar[ newRows * newCols ] ;
1026  }
1027  if ( newElem == NULL )
1028  Error( "Resize <memory allocation error>." );
1029 
1030  int64_t minRow = ( this->fRow < newRows ? this->fRow : newRows );
1031  int64_t minCol = ( this->fCol < newCols ? this->fCol : newCols );
1032  TVar * src;
1033  TVar * dst;
1034  int64_t r, c;
1035 
1036  for ( c = 0; c < minCol; c++ ) {
1037  // Copia as linhas da matriz antiga para a nova.
1038  // Copia os elementos de uma linha.
1039  dst = newElem + c*newRows;
1040  src = fElem + c*this->fRow;
1041  for ( r = 0; r < minRow; r++ ) *dst++ = *src++;
1042 
1043  // Se a nova linha for maior (mais colunas), preenche o
1044  // resto da linha com ZEROS.
1045  for ( ; r < newRows; r++ ) *dst++ = 0.0;
1046  }
1047 
1048  // Preenche as linha que sobrarem (se sobrarem) com ZEROS.
1049  for ( ;c < newCols; c++ )
1050  {
1051  dst = newElem + c*newRows;
1052  for (r = 0 ; r < newRows; r++ ) *dst++ = 0.0;
1053  }
1054 
1055  if (fElem && fElem != fGiven )delete[]( fElem );
1056  fElem = newElem;
1057  this->fRow = newRows;
1058  this->fCol = newCols;
1059  return( 1 );
1060 }
1061 
1062 template <class TVar>
1063 int TPZFMatrix<TVar>::Remodel(const int64_t newRows,const int64_t newCols) {
1064  if(newRows*newCols != this->fRow*this->fCol) return -1;
1065  this->fRow = newRows;
1066  this->fCol = newCols;
1067  return 1;
1068 }
1069 
1070 /********************/
1071 /*** Transpose () ***/
1072 template <class TVar>
1074  T->Resize( this->Cols(), this->Rows() );
1075  //Transposta por filas
1076  TVar * p = fElem;
1077  for ( int64_t c = 0; c < this->Cols(); c++ ) {
1078  for ( int64_t r = 0; r < this->Rows(); r++ ) {
1079  T->PutVal( c, r, *p++ );
1080  // cout<<"(r,c)= "<<r<<" "<<c<<"\n";
1081  }
1082  }
1083 }
1084 
1085 template <class TVar>
1087  TPZFMatrix<TVar> temp;
1088  Transpose(&temp);
1089  *this = temp;
1090 }
1091 
1092 #ifdef USING_LAPACK
1093 template <>
1095 
1096 
1097  if (this->fDecomposed != ENoDecompose && this->fDecomposed != ELUPivot) DebugStop();
1098 
1099  if (this->fDecomposed != ENoDecompose) {
1100  return ELUPivot;
1101  }
1102 
1103  if ( this->Rows() != this->Cols() ) {
1104  cout << "TPZFPivotMatrix::DecomposeLU ERRO : A Matriz não é quadrada" << endl;
1105  return 0;
1106  }
1107 
1108 
1109  int nRows = this->Rows();
1110  int zero = 0;
1111  float b;int info;
1112 
1113  fPivot.Resize(nRows);
1114 
1115  // int sgesv_(__CLPK_integer *__n, __CLPK_integer *__nrhs, __CLPK_real *__a,
1116  // __CLPK_integer *__lda, __CLPK_integer *__ipiv, __CLPK_real *__b,
1117  // __CLPK_integer *__ldb,
1118  // __CLPK_integer *__info) __OSX_AVAILABLE_STARTING(__MAC_10_2,
1119  // __IPHONE_4_0);
1120 
1121 
1122  sgesv_(&nRows,&zero,fElem,&nRows,&fPivot[0],&b,&nRows,&info);
1123  index = fPivot;
1124  this->fDecomposed = ELUPivot;
1125  return 1;
1126 }
1127 template <>
1129 
1130 
1131  if (this->fDecomposed != ENoDecompose && this->fDecomposed != ELUPivot) DebugStop();
1132 
1133  if (this->fDecomposed != ENoDecompose) {
1134  return ELUPivot;
1135  }
1136 
1137  if ( this->Rows() != this->Cols() ) {
1138  cout << "TPZFPivotMatrix::DecomposeLU ERRO : A Matriz não é quadrada" << endl;
1139  return 0;
1140  }
1141 
1142 
1143  int nRows = this->Rows();
1144  int zero = 0;
1145  double b;int info;
1146 
1147  fPivot.Resize(nRows);
1148 
1149  // int sgesv_(__CLPK_integer *__n, __CLPK_integer *__nrhs, __CLPK_real *__a,
1150  // __CLPK_integer *__lda, __CLPK_integer *__ipiv, __CLPK_real *__b,
1151  // __CLPK_integer *__ldb,
1152  // __CLPK_integer *__info) __OSX_AVAILABLE_STARTING(__MAC_10_2,
1153  // __IPHONE_4_0);
1154 
1155 
1156  dgesv_(&nRows,&zero,fElem,&nRows,&fPivot[0],&b,&nRows,&info);
1157  index = fPivot;
1158  this->fDecomposed = ELUPivot;
1159  return 1;
1160 }
1161 #endif //USING_LAPACK
1162 
1163 template <class TVar>
1165 
1166  if (this->fDecomposed) return 0;
1167 
1168  if ( this->Rows() != this->Cols() ) {
1169  cout << "TPZFPivotMatrix::DecomposeLU ERRO : A Matriz não é quadrada" << endl;
1170  return 0;
1171  }
1172 
1173  int64_t i,j,k;
1174  TVar sum = 0.;
1175  int64_t nRows = this->Rows();
1176  int64_t nCols = this->Cols();
1177 
1178  index.Resize(nRows);
1179  //inicializo o vetor de índices para o caso de pivotamento
1180  for (i=0;i<nRows;i++) index[i] = i;
1181 
1182  //LU
1183  for (j=0;j<nCols;j++){
1184  // cout << "line..." << j << endl;
1185  for (i=0;i<=j;i++){
1186  sum = 0.;
1187  for (k=0;k<i;k++){
1188  sum += this->Get(i,k) * this->Get(k,j);
1189  }
1190  TVar aux = this->Get(i,j);
1191  PutVal(i,j,(aux - sum));
1192  //cout << "0_A[" << i << "," << j << "]= " << Get(i,j) << endl;
1193  }
1194  //Print(cout);
1195  TVar piv = this->Get(j,j);
1196  // cout << "Pivo 1 =" << piv << endl;
1197  int64_t row = j;
1198  for (i=j+1;i<nRows;i++){
1199  sum = 0.;
1200  for (k=0;k<(j);k++){
1201  sum += this->Get(i,k) * this->Get(k,j);
1202  }
1203  TVar aux = this->Get(i,j);
1204  PutVal(i,j,(aux - sum));
1205  //cout << "1_A[" << i << "," << j << "]= " << Get(i,j) << endl;
1206 
1207  if (fabs(this->Get(i,j)) > fabs(piv)){
1208  piv = this->Get(i,j);
1209  // cout << "Pivo 2 =" << piv << endl;
1210  row = i;
1211  }
1212  }
1213  // Print(cout);
1214  if (row > j){
1215  for (k=0;k<nCols;k++){
1216  TVar aux = this->Get(j,k);
1217  PutVal(j,k,this->Get(row,k));
1218  //cout << "2_A[" << j << "," << k << "]= " << Get(j,k) << endl;
1219  PutVal(row,k,aux);
1220  //cout << "3_A[" << row << "," << k << "]= " << Get(row,k) << endl;
1221  }
1222  k = index[j];
1223  index[j] = index[row];
1224  index[row] = k;
1225  }
1226  // cout << "Pivo = " << piv << endl;
1227  for (i=j+1;i<nRows;i++){
1228  if (fabs(piv) < fabs((TVar)1e-12)) {
1229  cout << "Pivot < 1e-12. Probably matrix is singular." << endl;
1230  DebugStop();
1231  }
1232  TVar aux = this->Get(i,j) / piv;
1233  PutVal(i,j,aux);
1234  //cout << "4_A[" << i << "," << j << "]= " << Get(i,j) << endl;
1235  }
1236  //Print(cout);
1237  }
1238  this->fDecomposed = ELUPivot;
1239  return 1;
1240 }
1241 
1242 
1243 /*****************/
1244 /*** DecomposeLU ***/
1245 template <class TVar>
1246 int TPZFMatrix<TVar>::Decompose_LU(std::list<int64_t> &singular) {
1247  //return Decompose_LU();
1248 #ifndef USING_LAPACK
1249  if ( this->fDecomposed && this->fDecomposed != ELU) Error( "Decompose_LU <Matrix already Decomposed with other scheme>" );
1250 #else
1251  if ( this->fDecomposed && this->fDecomposed != ELUPivot) Error( "Decompose_LU <Matrix already Decomposed with other scheme>" );
1252 #endif
1253  if (this->fDecomposed) return 1;
1254 
1255  const int min = ( this->Cols() < (this->Rows()) ) ? this->Cols() : this->Rows();
1256  const int nrows = this->Rows();
1257  const int ncols = this->Cols();
1258 
1259  for ( int k = 0; k < min ; k++ ) {
1260  TVar pivot = GetVal(k, k);
1261  if (IsZero( pivot )){
1262  singular.push_back(k);
1263  PutVal(k,k,1.);
1264  pivot = 1.;
1265  }
1266  for ( int i = k+1; i < nrows; i++ ) {
1267  this->operator()(i,k) /= pivot;
1268  }
1269  for ( int j = k+1; j < ncols; j++ ){
1270  int i = k+1;
1271  TVar * elemPtr = &(this->operator()(i,j));
1272  TVar * ikPtr = &(this->operator()(i,k));
1273  const TVar kjVal = GetVal(k,j);
1274  for ( ; i < nrows; i++, elemPtr++, ikPtr++ ) {
1275  (*elemPtr) -= (*ikPtr)*kjVal;
1276  // this->operator()(i,j) -= GetVal( i, k )*GetVal(k,j);
1277  }
1278  }
1279  }
1280  this->fDecomposed=ELU;
1281 #ifdef USING_LAPACK
1282  fPivot.resize(nrows);
1283  for (int i=0; i<nrows; i++) {
1284  fPivot[i] = i+1;
1285  }
1286  this->fDecomposed = ELUPivot;
1287 #endif //USING_LAPACK
1288  return 1;
1289 }
1290 
1291 #ifdef USING_LAPACK
1292 template <>
1294 
1295 
1296  return this->Decompose_LU(fPivot);
1297 }
1298 template <>
1300 
1301 
1302  return this->Decompose_LU(fPivot);
1303 }
1304 #endif //USING_LAPACK
1305 
1306 template <class TVar>
1308 
1309  std::list<int64_t> fake;
1310  return this->Decompose_LU(fake);
1311 }
1312 
1313 
1314 //#ifdef _AUTODIFF
1315 //template <class TVar>
1316 //int TPZFMatrix<TVar>::Substitution(const TVar *ptr, int64_t rows, TPZFMatrix<TVar> *B) {
1317 // std::cout << __PRETTY_FUNCTION__ << " bailing out\n";
1318 // DebugStop();
1319 // return 1;
1320 //}
1321 //#else
1322 template <class TVar>
1323 int TPZFMatrix<TVar>::Substitution(const TVar *ptr, int64_t rows, TPZFMatrix<TVar> *B)
1324 {
1325  int64_t rowb = B->Rows();
1326  int64_t colb = B->Cols();
1327  if ( rowb != rows ) Error( "static::SubstitutionLU <incompatible dimensions>" );
1328  int64_t i,j;
1329  for ( i = 0; i < rowb; i++ ) {
1330  for ( int64_t col = 0; col < colb; col++ )
1331  for (j = 0; j < i; j++ )
1332  //B->PutVal( i, col, B->GetVal(i, col) - GetVal(i, j) * B->GetVal(j, col) );
1333  PUTVAL(B, rowb, i, col, GETVAL(B, rowb, i, col) - SELECTEL(ptr, rows, i, j) * GETVAL(B, rowb, j, col));
1334  }
1335 
1336  for (int64_t col=0; col<colb; col++){
1337  for ( i = rowb-1; i >= 0; i-- ) {
1338  for (j = i+1; j < rowb ; j++ )
1339  //B->PutVal( i, col, B->GetVal(i, col) - GetVal(i, j) * B->GetVal(j, col) );
1340  PUTVAL(B, rowb, i, col, GETVAL(B, rowb, i, col) - SELECTEL(ptr, rows, i, j) * GETVAL(B, rowb, j, col));
1341  if ( IsZero( SELECTEL(ptr, rows, i, i)/*GetVal(i, i)*/ ) ) {
1342  if (fabs(SELECTEL(ptr, rows, i, i)/*GetVal(i, i)*/) > fabs((TVar)0.)) {
1343  TVar tmp = GETVAL(B, rowb, i, col) - SELECTEL(ptr, rows, i, i);/*B->GetVal(i, col) - GetVal(i, i)*/
1344  if (fabs(tmp) > fabs(((TVar)1e-12))) {
1345  Error( "static::BackSub(SubstitutionLU) <Matrix is singular even after Power Plus..." );
1346  }
1347  }else Error( "static::BackSub(SubstitutionLU) <Matrix is singular" );
1348  }
1349  PUTVAL(B, rowb, i, col, GETVAL(B, rowb, i, col)/SELECTEL(ptr, rows, i, i));
1350  //B->PutVal( i, col, B->GetVal( i, col) / GetVal(i, i) );
1351  }
1352  }
1353  return( 1 );
1354 }
1355 //#endif
1356 
1357 #ifdef _AUTODIFF
1358 #include "fadType.h"
1359 #endif
1360 
1361 /****************/
1362 /*** Substitution ***/
1363 template <class TVar>
1365 #ifdef USING_LAPACK
1366  if (this->fDecomposed != ELUPivot) {
1367  Error("TPZFMatrix::Decompose_LU substitution called for a wrongly decomposed matrix");
1368  }
1369 #else
1370  if(this->fDecomposed != ELU) {
1371  Error("TPZFMatrix::Decompose_LU substitution called for a wrongly decomposed matrix");
1372  }
1373 #endif
1374  int64_t rowb = B->Rows();
1375  int64_t colb = B->Cols();
1376  int64_t row = this->Rows();
1377  if ( rowb != this->Rows() ) Error( "SubstitutionLU <incompatible dimensions>" );
1378 
1379 
1380  int64_t i,j;
1381  for ( i = 0; i < rowb; i++ ) {
1382  for ( int64_t col = 0; col < colb; col++ )
1383  for (j = 0; j < i; j++ )
1384  //B->PutVal( i, col, B->GetVal(i, col) - GetVal(i, j) * B->GetVal(j, col) );
1385  PUTVAL(B, rowb, i, col, GETVAL(B, rowb, i, col) - GETVAL(this, row, i, j) * GETVAL(B, rowb, j, col));
1386  }
1387 
1388  for (int64_t col=0; col<colb; col++){
1389  for ( i = rowb-1; i >= 0; i-- ) {
1390  for (j = i+1; j < rowb ; j++ )
1391  //B->PutVal( i, col, B->GetVal(i, col) - GetVal(i, j) * B->GetVal(j, col) );
1392  PUTVAL(B, rowb, i, col, GETVAL(B, rowb, i, col) - GETVAL(this, row, i, j) * GETVAL(B, rowb, j, col));
1393  if ( IsZero( GETVAL(this, row, i, i)/*GetVal(i, i)*/ ) ) {
1394  if (fabs(GETVAL(this, row, i, i)/*GetVal(i, i)*/) > 0.){
1395  TVar diff = GETVAL(B, rowb, i, col) - GETVAL(this, row, i, i)/*B->GetVal(i, col) - GetVal(i, i)*/;
1396  if (fabs(diff) > 1e-12){
1397  Error( "BackSub(SubstitutionLU) <Matrix is singular even after Power Plus..." );
1398  }
1399  }else Error( "BackSub(SubstitutionLU) <Matrix is singular" );
1400  }
1401  PUTVAL(B, rowb, i, col, GETVAL(B, rowb, i, col)/GETVAL(this, row, i, i));
1402  //B->PutVal( i, col, B->GetVal( i, col) / GetVal(i, i) );
1403  }
1404  }
1405  return( 1 );
1406 
1407 }
1408 
1409 
1410 #ifdef USING_LAPACK
1411 template<>
1412 int TPZFMatrix<float>::Substitution( TPZFMatrix<float> *B, const TPZVec<int> &index ) const{
1413 
1414  if(!B){
1415  PZError << __PRETTY_FUNCTION__ << "TPZFMatrix<>*B eh nulo" << endl;
1416  return 0;
1417  }
1418 
1419  TPZFMatrix<float> &b = *B;
1420 
1421  if (!this->fDecomposed){
1422  PZError << __PRETTY_FUNCTION__ << "Matriz não decomposta" << endl;
1423  return 0;
1424  }
1425 
1426  if (this->fDecomposed != ELUPivot){
1427  PZError << __PRETTY_FUNCTION__ << "\nfDecomposed != ELUPivot" << endl;
1428  }
1429 
1430  // int sgetrs_(char *__trans, __CLPK_integer *__n, __CLPK_integer *__nrhs,
1431  // __CLPK_real *__a, __CLPK_integer *__lda, __CLPK_integer *__ipiv,
1432  // __CLPK_real *__b, __CLPK_integer *__ldb,
1433  // __CLPK_integer *__info) __OSX_AVAILABLE_STARTING(__MAC_10_2,
1434  // __IPHONE_4_0);
1435  int nRows = this->Rows();
1436  char notrans = 'N';
1437  int BCols = B->Cols();
1438  int info = 0;
1439 
1440  sgetrs_(&notrans,&nRows,&BCols,fElem,&nRows,&fPivot[0],B->fElem,&nRows,&info);
1441 
1442 #ifdef PZDEBUG
1443  if(info != 0)
1444  {
1445  DebugStop();
1446  }
1447 #endif
1448 
1449  return 1;
1450 }
1451 
1452 template<>
1454 
1455  if(!B){
1456  PZError << __PRETTY_FUNCTION__ << "TPZFMatrix<>*B eh nulo" << endl;
1457  return 0;
1458  }
1459 
1460 
1461  if (!this->fDecomposed){
1462  PZError << __PRETTY_FUNCTION__ << "Matriz não decomposta" << endl;
1463  return 0;
1464  }
1465 
1466  if (this->fDecomposed != ELUPivot){
1467  PZError << __PRETTY_FUNCTION__ << "\nfDecomposed != ELUPivot" << endl;
1468  }
1469 
1470  // int sgetrs_(char *__trans, __CLPK_integer *__n, __CLPK_integer *__nrhs,
1471  // __CLPK_real *__a, __CLPK_integer *__lda, __CLPK_integer *__ipiv,
1472  // __CLPK_real *__b, __CLPK_integer *__ldb,
1473  // __CLPK_integer *__info) __OSX_AVAILABLE_STARTING(__MAC_10_2,
1474  // __IPHONE_4_0);
1475  int nRows = this->Rows();
1476  char notrans = 'N';
1477  int BCols = B->Cols();
1478  int info = 0;
1479 
1480  dgetrs_(&notrans,&nRows,&BCols,fElem,&nRows,&fPivot[0],B->fElem,&nRows,&info);
1481 
1482 #ifdef PZDEBUG
1483  if(info != 0)
1484  {
1485  DebugStop();
1486  }
1487 #endif
1488 
1489  return 1;
1490 }
1491 
1492 #endif //USING_LAPACK
1493 
1494 
1495 template<class TVar>
1497 
1498  if(!B){
1499  PZError << __PRETTY_FUNCTION__ << "TPZFMatrix<>*B eh nulo" << endl;
1500  return 0;
1501  }
1502 
1503  TPZFMatrix<TVar> &b = *B;
1504 
1505  if (!this->fDecomposed){
1506  PZError << __PRETTY_FUNCTION__ << "Matriz não decomposta" << endl;
1507  return 0;
1508  }
1509 
1510  if (this->fDecomposed != ELUPivot){
1511  PZError << __PRETTY_FUNCTION__ << "\nfDecomposed != ELUPivot" << endl;
1512  }
1513 
1514  int nRows = this->Rows();
1515 
1516  if (index.NElements() != nRows || b.Rows() != nRows)
1517  {
1518  cout << "TMatrix::Substituicao ERRO : vetores com dimensões incompativeis:\n"
1519  << "this->fIndex = " << index.NElements() << " b = " << b.Rows() << endl;
1520  return 0;
1521  }
1522 
1523  int64_t ncols = B->Cols();
1524  for(int64_t ic = 0; ic<ncols; ic++)
1525  {
1526  int64_t i,j;
1527  TVar sum = 0;
1528 
1529  TPZVec<TVar> v(nRows);
1530 
1531 
1532  for (i=0;i<nRows;i++)
1533  {
1534  v[i] = b(index[i],ic);
1535  }
1536 
1537  //Ly=b
1538  for (i=0;i<nRows;i++)
1539  {
1540  sum = 0.;
1541  for (j=0;j<(i);j++) sum +=this->Get(i,j) * v[j];
1542  v[i] -= sum;
1543  }
1544 
1545  //Ux=y
1546  for (i=(nRows-1);i>-1;i--)
1547  {
1548  sum = 0.;
1549  for (j=(i+1);j<nRows;j++) sum += this->Get(i,j) * v[j];
1550  v[i] = (v[i] - sum) / this->Get(i,i);
1551  }
1552 
1553  for (i=0;i<nRows;i++) b(i,ic) = v[i];
1554  }
1555  return 1;
1556 }
1557 
1558 #ifdef USING_LAPACK
1559 template <>
1561 
1562  return this->Substitution(B,fPivot);
1563 }
1564 template <>
1566 
1567  return this->Substitution(B,fPivot);
1568 }
1569 #endif //USING_LAPACK
1570 
1571 
1572 //NAO TESTADO
1573 template <class TVar>
1575  std::list<int64_t> fake;
1576  int res = this->Decompose_Cholesky(fake);
1577  if(fake.size()){
1578  DebugStop();
1579  }
1580  return res;
1581 }
1582 
1583 #ifdef USING_LAPACK
1584 template <>
1585 int TPZFMatrix<float>::Decompose_Cholesky(std::list<int64_t> &singular) {
1586  if ( this->fDecomposed && this->fDecomposed != ECholesky) Error( "Decompose_Cholesky <Matrix already Decomposed>" );
1587  if ( this->fDecomposed ) return ECholesky;
1588  if ( this->Rows() != this->Cols() ) Error( "Decompose_Cholesky <Matrix must be square>" );
1589  int dim=this->Dim();
1590 
1591  TPZFMatrix<float> B(*this);
1592  int nrhs = 0;
1593  float *A = fElem;
1594  char uplo = 'U';
1595  int info;
1596  // sposv_(<#char *__uplo#>, <#__CLPK_integer *__n#>, <#__CLPK_integer *__nrhs#>, <#__CLPK_real *__a#>, <#__CLPK_integer *__lda#>, <#__CLPK_real *__b#>, <#__CLPK_integer *__ldb#>, <#__CLPK_integer *__info#>)
1597  spotrf_(&uplo, &dim, A, &dim, &info);
1598  this->fDecomposed = ECholesky;
1599 
1600  if (info != 0) {
1601  DebugStop();
1602  }
1603  return 1;
1604 }
1605 template <>
1606 int TPZFMatrix<double>::Decompose_Cholesky(std::list<int64_t> &singular) {
1607  if ( this->fDecomposed && this->fDecomposed != ECholesky) Error( "Decompose_Cholesky <Matrix already Decomposed>" );
1608  if ( this->fDecomposed ) return ECholesky;
1609  if ( this->Rows() != this->Cols() ) Error( "Decompose_Cholesky <Matrix must be square>" );
1610  int dim=this->Dim();
1611 
1612  double B;
1613  int nrhs = 0;
1614  double *A = fElem;
1615  char uplo = 'U';
1616  int info;
1617  dpotrf_(&uplo, &dim, A, &dim, &info);
1618  this->fDecomposed = ECholesky;
1619 
1620  if (info != 0) {
1621  DebugStop();
1622  }
1623  return 1;
1624 }
1625 #endif //USING_LAPACK
1626 
1627 template <class TVar>
1628 int TPZFMatrix<TVar>::Decompose_Cholesky(std::list<int64_t> &singular) {
1629 
1630  if ( this->fDecomposed && this->fDecomposed != ECholesky) Error( "Decompose_Cholesky <Matrix already Decomposed>" );
1631  if ( this->fDecomposed ) return ECholesky;
1632  if ( this->Rows() != this->Cols() ) Error( "Decompose_Cholesky <Matrix must be square>" );
1633  //return 0;
1634 
1635  int dim=this->Dim();
1636 
1637  for (int i=0 ; i<dim; i++) {
1638 
1639  TVar * diagPtr = &(this->operator()(i,i));
1640  for(int k=0; k<i; k++) { //elementos da diagonal
1641  (*diagPtr) -= this->operator()(i,k)*this->operator()(i,k);
1642  }
1643 
1644 
1645  if( IsZero(*diagPtr) ){
1646  singular.push_back(i);
1647  (*diagPtr) = 1.;
1648  }
1649 
1650  (*diagPtr) = sqrt(*diagPtr);
1651 
1652  for (int j=i+1;j<dim; j++) { //elementos fora da diagonal
1653  TVar sum = 0.;
1654  {
1655  int k=0;
1656  TVar * ikPtr = &(this->operator()(k,i));//&(this->operator()(i,k));///(k,i) = (i,k) pela simetria da matriz, mas o alinhamento acelera a execucao
1657  TVar * kjPtr = &(this->operator()(k,j));
1658  for(; k<i; k++, kjPtr++, ikPtr++) {
1659  sum += (*ikPtr)*(*kjPtr);
1660  }
1661  }
1662  TVar *ijPtr = &(this->operator()( i,j ));
1663  (*ijPtr) -= sum;
1664 
1665  (*ijPtr) /= (*diagPtr);
1666  this->operator()(j,i) = (*ijPtr);
1667  }
1668  }
1669 
1670  // std::cout << __PRETTY_FUNCTION__ << std::endl;
1671  this->fDecomposed = ECholesky;
1672  return ECholesky;
1673 }
1674 
1675 template <class TVar>
1676 int TPZFMatrix<TVar>::Substitution(const TVar *ptr, int64_t rows, TPZFMatrix<TVar> *B, const TPZVec<int> &index )
1677 {
1678 
1679  if(!B){
1680  PZError << __PRETTY_FUNCTION__ << "TPZFMatrix<>*B eh nulo" << endl;
1681  return 0;
1682  }
1683 
1684  TPZFMatrix<TVar> &b = *B;
1685 
1686 
1687 
1688  if (index.NElements() != rows || b.Rows() != rows)
1689  {
1690  cout << "TMatrix::Substituicao ERRO : vetores com dimensões incompativeis:\n"
1691  << "this->fIndex = " << index.NElements() << " b = " << b.Rows() << endl;
1692  return 0;
1693  }
1694 
1695  int64_t i,j;
1696  TVar sum = 0;
1697 
1698  TPZVec<TVar> v(rows);
1699 
1700 
1701  for (i=0;i<rows;i++)
1702  {
1703  v[i] = b(index[i]);
1704  }
1705 
1706  //Ly=b
1707  for (i=0;i<rows;i++)
1708  {
1709  sum = 0.;
1710  for (j=0;j<(i);j++) sum += SELECTEL(ptr,rows,i,j) * v[j];
1711  v[i] -= sum;
1712  }
1713 
1714  //Ux=y
1715  for (i=(rows-1);i>-1;i--)
1716  {
1717  sum = 0.;
1718  for (j=(i+1);j<rows;j++) sum += SELECTEL(ptr,rows,i,j) * v[j];
1719  v[i] = (v[i] - sum) / SELECTEL(ptr,rows,i,i);
1720  }
1721 
1722  for (i=0;i<rows;i++) b(i) = v[i];
1723  return 1;
1724 }
1725 
1726 #ifdef USING_LAPACK
1727 template <>
1729 
1730  if ( this->fDecomposed && this->fDecomposed != ELDLt) {
1731  Error( "Decompose_LDLt <Matrix already Decomposed with other scheme> " );
1732  } else if(this->fDecomposed ) {
1733  return ELDLt;
1734  }
1735  if ( this->Rows()!=this->Cols() ) Error( "Decompose_LDLt <Matrix must be square>" );
1736  char uplo = 'U';
1737  int dim = Rows();
1738  int nrhs = 0;
1739  fPivot.Resize(dim,0);
1740  float B = 0.;
1741  int worksize = 3*dim;
1742  fWork.Resize(worksize);
1743  int info;
1744 
1745  if (dim == 0) {
1746  this->fDecomposed = ELDLt;
1747  this->fDefPositive = 0;
1748  return( 1 );
1749  }
1750 
1751  // ssysv_(<#char *__uplo#>, <#__CLPK_integer *__n#>, <#__CLPK_integer *__nrhs#>, <#__CLPK_real *__a#>, <#__CLPK_integer *__lda#>, <#__CLPK_integer *__ipiv#>, <#__CLPK_real *__b#>, <#__CLPK_integer *__ldb#>, <#__CLPK_real *__work#>, <#__CLPK_integer *__lwork#>, <#__CLPK_integer *__info#>)
1752 
1753  ssysv_(&uplo, &dim, &nrhs, fElem, &dim, &fPivot[0], &B, &dim, &fWork[0], &worksize, &info);
1754  fDecomposed = ELDLt;
1755  return 1;
1756 }
1757 
1758 template <>
1760 
1761  if ( this->fDecomposed && this->fDecomposed != ELDLt) {
1762  Error( "Decompose_LDLt <Matrix already Decomposed with other scheme> " );
1763  } else if(this->fDecomposed ) {
1764  return ELDLt;
1765  }
1766  if ( this->Rows()!=this->Cols() ) Error( "Decompose_LDLt <Matrix must be square>" );
1767  char uplo = 'L';
1768  int dim = Rows();
1769  int nrhs = 0;
1770  fPivot.Resize(dim,0);
1771  double B = 0.;
1772  int worksize = 3*dim;
1773  fWork.Resize(worksize);
1774  int info;
1775 
1776  if (dim == 0) {
1777  this->fDecomposed = ELDLt;
1778  this->fDefPositive = 0;
1779  return( 1 );
1780  }
1781 
1782  // ssysv_(<#char *__uplo#>, <#__CLPK_integer *__n#>, <#__CLPK_integer *__nrhs#>, <#__CLPK_real *__a#>, <#__CLPK_integer *__lda#>, <#__CLPK_integer *__ipiv#>, <#__CLPK_real *__b#>, <#__CLPK_integer *__ldb#>, <#__CLPK_real *__work#>, <#__CLPK_integer *__lwork#>, <#__CLPK_integer *__info#>)
1783 
1784  dsysv_(&uplo, &dim, &nrhs, fElem, &dim, &fPivot[0], &B, &dim, &fWork[0], &worksize, &info);
1785  fDecomposed = ELDLt;
1786  return 1;
1787 }
1788 
1789 #endif //USING_LAPACK
1790 
1791 template <class TVar>
1793 
1794  if ( this->fDecomposed && this->fDecomposed != ELDLt) {
1795  Error( "Decompose_LDLt <Matrix already Decomposed with other scheme> " );
1796  } else if(this->fDecomposed ) {
1797  return ELDLt;
1798  }
1799  if ( this->Rows()!=this->Cols() ) Error( "Decompose_LDLt <Matrix must be square>" );
1800 
1801  int64_t j,k,l,dim=this->Rows();
1802 
1803  for ( j = 0; j < dim; j++ ) {
1804  for ( k=0; k<j; k++) {
1805  PutVal( j,j,GetVal(j,j) - GetVal(k,k)*GetVal(k,j)*GetVal(k,j) );
1806  }
1807  for ( k=0; k<j; k++) {
1808  for( l=j+1; l<dim;l++) {
1809  PutVal(l,j, GetVal(l,j)-GetVal(k,k)*GetVal(j,k)*GetVal(l,k) );
1810  PutVal(j,l,GetVal(l,j) );
1811  }
1812  }
1813  TVar tmp = GetVal(j,j);
1814  if ( IsZero(tmp) ) Error( "Decompose_LDLt <Zero on diagonal>" );
1815  for( l=j+1; l<dim;l++) {
1816  PutVal(l,j, GetVal(l,j)/GetVal(j,j) ) ;
1817  PutVal(j,l, GetVal(l,j) );
1818  }
1819  }
1820  this->fDecomposed = ELDLt;
1821  this->fDefPositive = 0;
1822  return( 1 );
1823 }
1824 
1825 
1826 #ifdef USING_LAPACK
1827 
1831 template<>
1833 {
1834  if (fDecomposed == ECholesky) {
1835  // CALL strsm( 'Left', 'Upper', 'Transpose', 'Non-unit', n, nrhs,
1836  // 179 $ one, a, lda, b, ldb )
1837  char left[]= "Left", upper[] = "Upper", transpose[] = "Transpose", non_unit[] = "Non-unit";
1838  int ncol = b->Cols();
1839  int dim = Rows();
1840  // b->Print("before =",std::cout,EMathematicaInput);
1841  cblas_strsm(CblasColMajor, CblasLeft, CblasUpper, CblasTrans, CblasNonUnit, dim, ncol, 1., fElem, dim, b->fElem, dim);
1842  // TPZMatrix<float>::Subst_Forward(b);
1843  // b->Print("after =",std::cout,EMathematicaInput);
1844  return 1;
1845  }
1846  else
1847  {
1849  }
1850 }
1851 
1856 template<>
1858 {
1859  if (fDecomposed == ECholesky) {
1860  // CALL strsm( 'Left', 'Upper', 'Transpose', 'Non-unit', n, nrhs,
1861  // 179 $ one, a, lda, b, ldb )
1862  char left[]= "Left", upper[] = "Upper", transpose[] = "Transpose", non_unit[] = "Non-unit";
1863  int ncol = b->Cols();
1864  int dim = Rows();
1865  // b->Print("before =",std::cout,EMathematicaInput);
1866  cblas_dtrsm(CblasColMajor, CblasLeft, CblasUpper, CblasTrans, CblasNonUnit, dim, ncol, 1., fElem, dim, b->fElem, dim);
1867  // TPZMatrix<float>::Subst_Forward(b);
1868  // b->Print("after =",std::cout,EMathematicaInput);
1869  return 1;
1870  }
1871  else
1872  {
1874  }
1875 }
1876 
1881 template<class TVar>
1883 {
1885 }
1886 
1891 template<class TVar>
1893 {
1895 }
1896 
1897 
1898 template<>
1900 {
1901  if (fDecomposed == ECholesky) {
1902 
1903  // spotrs_(<#char *__uplo#>, <#__CLPK_integer *__n#>, <#__CLPK_integer *__nrhs#>, <#__CLPK_real *__a#>, <#__CLPK_integer *__lda#>, <#__CLPK_real *__b#>, <#__CLPK_integer *__ldb#>, <#__CLPK_integer *__info#>)
1904  // CALL strsm( 'Left', 'Upper', 'No transpose', 'Non-unit', n,
1905  // 184 $ nrhs, one, a, lda, b, ldb )
1906  char left[]= "Left", upper[] = "Upper", transpose[] = "Transpose", non_unit[] = "Non-unit";
1907  int ncol = b->Cols();
1908  int dim = Rows();
1909  int info = 0;
1910  // b->Print("before =",std::cout,EMathematicaInput);
1911  // TPZMatrix<float>::Subst_Backward(b);
1912  cblas_strsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, dim, ncol, 1., fElem, dim, b->fElem, dim);
1913  // spotrs_(upper, &dim, &ncol, fElem, &dim, b->fElem, &ncol, &info);
1914  // b->Print("after =",std::cout,EMathematicaInput);
1915 
1916  return 1;
1917 
1918  if (info != 0) {
1919  DebugStop();
1920  }
1921  }
1922  else
1923  {
1925  }
1926 }
1927 
1928 template<>
1930 {
1931  if (fDecomposed == ECholesky) {
1932 
1933  // spotrs_(<#char *__uplo#>, <#__CLPK_integer *__n#>, <#__CLPK_integer *__nrhs#>, <#__CLPK_real *__a#>, <#__CLPK_integer *__lda#>, <#__CLPK_real *__b#>, <#__CLPK_integer *__ldb#>, <#__CLPK_integer *__info#>)
1934  // CALL strsm( 'Left', 'Upper', 'No transpose', 'Non-unit', n,
1935  // 184 $ nrhs, one, a, lda, b, ldb )
1936  char left[]= "Left", upper[] = "Upper", transpose[] = "Transpose", non_unit[] = "Non-unit";
1937  int ncol = b->Cols();
1938  int dim = Rows();
1939  int info = 0;
1940  // b->Print("before =",std::cout,EMathematicaInput);
1941  // TPZMatrix<float>::Subst_Backward(b);
1942  cblas_dtrsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, dim, ncol, 1., fElem, dim, b->fElem, dim);
1943  // spotrs_(upper, &dim, &ncol, fElem, &dim, b->fElem, &ncol, &info);
1944  // b->Print("after =",std::cout,EMathematicaInput);
1945 
1946  return 1;
1947 
1948  if (info != 0) {
1949  DebugStop();
1950  }
1951  }
1952  else
1953  {
1955  }
1956 }
1957 
1962 template<>
1964 {
1965  // ssytrs_(<#char *__uplo#>, <#__CLPK_integer *__n#>, <#__CLPK_integer *__nrhs#>, <#__CLPK_real *__a#>, <#__CLPK_integer *__lda#>, <#__CLPK_integer *__ipiv#>, <#__CLPK_real *__b#>, <#__CLPK_integer *__ldb#>, <#__CLPK_integer *__info#>)
1966 
1967  if (fDecomposed != ELDLt) {
1968  DebugStop();
1969  }
1970 
1971  char uplo = 'U';
1972  int dim = Rows();
1973  int nrhs = b->Cols();
1974  float B = 0.;
1975  int info;
1976 
1977  // ssytrs_(<#char *__uplo#>, <#__CLPK_integer *__n#>, <#__CLPK_integer *__nrhs#>, <#__CLPK_real *__a#>, <#__CLPK_integer *__lda#>, <#__CLPK_integer *__ipiv#>, <#__CLPK_real *__b#>, <#__CLPK_integer *__ldb#>, <#__CLPK_integer *__info#>)
1978  ssytrs_(&uplo, &dim, &nrhs, fElem, &dim, &fPivot[0], b->fElem, &dim, &info);
1979  return 1;
1980  // return TPZMatrix<TVar>::Subst_LForward(b);
1981 }
1982 
1987 template<>
1989 {
1990 
1991  if (fDecomposed != ELDLt) {
1992  DebugStop();
1993  }
1994 
1995  char uplo = 'L';
1996  int dim = Rows();
1997  int nrhs = b->Cols();
1998  double B = 0.;
1999  int info;
2000  if (dim == 0 || nrhs == 0) {
2001  return 0;
2002  }
2003  dsytrs_(&uplo, &dim, &nrhs, fElem, &dim, &fPivot[0], b->fElem, &dim, &info);
2004  return 1;
2005  // return TPZMatrix<TVar>::Subst_LForward(b);
2006 }
2007 
2008 
2013 template<class TVar>
2015 {
2016  // ssytrs2
2018 }
2019 
2024 template<>
2026 {
2027  return 1;
2028 }
2029 
2034 template<>
2036 {
2037  return 1;
2038 }
2039 
2044 template<class TVar>
2046 {
2048 }
2049 
2054 template<>
2056 {
2057  return 1;
2058 }
2059 
2064 template<>
2066 {
2067  return 1;
2068 }
2069 
2074 template<class TVar>
2076 {
2077  return TPZMatrix<TVar>::Subst_Diag(b);
2078 }
2079 #endif //USING_LAPACK
2080 
2082 template<class TVar>
2083 TVar Dot(const TPZFMatrix<TVar> &A, const TPZFMatrix<TVar> &B) {
2084  int64_t size = (A.Rows())*A.Cols();
2085  TVar result = 0.;
2086  if(!size) return result;
2087  // #ifdef USING_ATLAS
2088  // result = cblas_ddot(size, &A.g(0,0), 1, &B.g(0,0), 1);
2089  // return result;
2090  //
2091  // #elif USING_BLAS
2092  // result = cblas_ddot(size, &A.g(0,0), 1, &B.g(0,0), 1);
2093  // return result;
2094  //
2095  // #else
2096  const TVar *fpA = &A.g(0,0), *fpB = &B.g(0,0);
2097  const TVar *fpLast = fpA+size;
2098  while(fpA < fpLast)
2099  {
2100  result += (*fpA++ * *fpB++);
2101  }
2102  return result;
2103  // #endif
2104 }
2105 
2106 template
2107 std::complex<float> Dot(const TPZFMatrix< std::complex<float> > &A, const TPZFMatrix< std::complex<float> > &B);
2108 
2109 template
2110 std::complex<double> Dot(const TPZFMatrix< std::complex<double> > &A, const TPZFMatrix< std::complex<double> > &B);
2111 
2112 template
2113 std::complex<long double> Dot(const TPZFMatrix< std::complex<long double> > &A, const TPZFMatrix< std::complex<long double> > &B);
2114 
2115 template
2116 long double Dot(const TPZFMatrix<long double> &A, const TPZFMatrix<long double> &B);
2117 
2118 template
2119 double Dot(const TPZFMatrix<double> &A, const TPZFMatrix<double> &B);
2120 
2121 template
2122 float Dot(const TPZFMatrix<float> &A, const TPZFMatrix<float> &B);
2123 
2124 template
2125 int64_t Dot(const TPZFMatrix<int64_t> &A, const TPZFMatrix<int64_t> &B);
2126 
2127 template
2128 int Dot(const TPZFMatrix<int> &A, const TPZFMatrix<int> &B);
2129 
2130 #ifdef _AUTODIFF
2131 template
2132 Fad<float> Dot(const TPZFMatrix<Fad<float> > &A, const TPZFMatrix<Fad<float> > &B);
2133 
2134 template
2136 
2137 template
2139 #endif
2140 
2141 template
2143 
2145 template <class TVar>
2146 TPZFMatrix<TVar> operator+(const TVar value, const TPZFMatrix<TVar> &A ) {
2147  return( A + value );
2148 }
2149 
2151 template <class TVar>
2152 TPZFMatrix<TVar> operator-(const TVar value, const TPZFMatrix<TVar> &A ) {
2153  return( A - value );
2154 }
2155 
2156 /************************** Private **************************/
2157 
2158 /*************/
2159 /*** Error ***/
2160 template<class TVar>
2161 int TPZFMatrix<TVar>::Error(const char *msg1,const char *msg2 ) {
2162  ostringstream out;
2163  out << "TPZFMatrix::" << msg1;
2164  if(msg2) out << msg2;
2165  out << ".\n";
2166  LOGPZ_ERROR (logger, out.str().c_str());
2167  DebugStop();
2168  return 0;
2169 }
2170 
2171 
2172 /*************/
2173 /*** Clear ***/
2174 template <class TVar>
2176  if(fElem && fElem != fGiven) delete[]( fElem );
2177  fElem = NULL;
2178  this->fRow = this->fCol = 0;
2179  return( 1 );
2180 }
2181 
2182 #ifdef _AUTODIFF
2183 template <>
2184 void TPZFMatrix<TFad<6,REAL> >::Read( TPZStream &buf, void *context ){
2185  DebugStop();
2186 }
2187 
2188 template <>
2189 void TPZFMatrix<TFad<6,REAL> >::Write( TPZStream &buf, int withclassid ) const {
2190  DebugStop();
2191 }
2192 
2193 template <>
2194 void TPZFMatrix<Fad<REAL> >::Read( TPZStream &buf, void *context ){
2195  DebugStop();
2196 }
2197 
2198 template <>
2199 void TPZFMatrix<Fad<REAL> >::Write( TPZStream &buf, int withclassid ) const {
2200  DebugStop();
2201 }
2202 #endif
2203 
2204 template <class TVar>
2205 void TPZFMatrix<TVar>::Read( TPZStream &buf, void *context ){ //ok
2206  TPZMatrix<TVar>::Read(buf,context);
2207  int64_t row = this->fRow;
2208  int64_t col = this->fCol;
2209  //this is odd, but necessary.
2210  this->fRow = this->fCol = 0;
2211  Resize(row,col);
2212  buf.Read(fElem,this->fRow*this->fCol);
2213 }
2214 
2215 //template <class TVar>
2216 //void TPZFMatrix<TVar>::Write( TPZStream &buf, int withclassid ) {
2217 // const TPZFMatrix<TVar> *cp = this;
2218 // cp->Write(buf,withclassid);
2219 // // const Write(buf, withclassid);
2220 // // TPZMatrix<TVar>::Write(buf,withclassid);
2221 // // buf.Write(fElem,this->fRow*this->fCol);
2222 //}
2223 
2224 template <class TVar>
2225 void TPZFMatrix<TVar>::Write( TPZStream &buf, int withclassid ) const { //ok
2226  TPZMatrix<TVar>::Write(buf,withclassid);
2227  buf.Write(fElem,this->fRow*this->fCol);
2228 }
2229 
2231 
2235 template<class TVar>
2236 bool TPZFMatrix<TVar>::Compare(TPZSavable *copy, bool override)
2237 {
2238  TPZFMatrix<TVar> *fmat = dynamic_cast<TPZFMatrix<TVar> *> (copy);
2239  if(!fmat) return false;
2240 
2241  bool matresult = TPZMatrix<TVar>::Compare(copy,false);
2242  int64_t nel = this->fRow*this->fCol;
2243  TVar diff=0.;
2244  int64_t numdif = 0;
2245  int64_t iel;
2246  for(iel=0; iel<nel; iel++)
2247  {
2248  if(fElem[iel] != fmat->fElem[iel])
2249  {
2250  matresult = false;
2251  numdif++;
2252  }
2253  TVar exp = fElem[iel]-fmat->fElem[iel];
2254  diff += fabs(exp);
2255  }
2256  if(!matresult)
2257  {
2258  std::stringstream sout;
2259  sout << __PRETTY_FUNCTION__ << " did not compare ";
2260  sout << " number different terms " << numdif << " number terms " << this->fRow*this->fCol;
2261  sout << " difference in norm L1 " << diff;
2262  LOGPZ_ERROR(loggerCheck,sout.str())
2263  }
2264  if(!matresult && override)
2265  {
2266  this->operator=(*fmat);
2267  }
2268  return matresult;
2269 }
2270 
2272 
2276 template<class TVar>
2277 bool TPZFMatrix<TVar>::Compare(TPZSavable *copy, bool override) const
2278 {
2279  TPZFMatrix<TVar> *fmat = dynamic_cast<TPZFMatrix<TVar> *> (copy);
2280  if(!fmat) return false;
2281 
2282  bool matresult = TPZMatrix<TVar>::Compare(copy,false);
2283  int64_t nel = this->fRow*this->fCol;
2284  TVar diff=0.;
2285  int64_t numdif = 0;
2286  int64_t iel;
2287  for(iel=0; iel<nel; iel++)
2288  {
2289  if(fElem[iel] != fmat->fElem[iel])
2290  {
2291  matresult = false;
2292  numdif++;
2293  }
2294  TVar exp = fElem[iel]-fmat->fElem[iel];
2295  diff += fabs(exp);
2296  }
2297  if(!matresult)
2298  {
2299  std::stringstream sout;
2300  sout << __PRETTY_FUNCTION__ << " did not compare ";
2301  sout << " number different terms " << numdif << " number terms " << this->fRow*this->fCol;
2302  sout << " difference in norm L1 " << diff;
2303  LOGPZ_ERROR(loggerCheck,sout.str())
2304  }
2305  if(!matresult && override)
2306  {
2307  DebugStop();
2308  }
2309  return matresult;
2310 }
2311 
2312 #ifdef _AUTODIFF
2313 template <>
2314 void TPZFMatrix<TFad<6,REAL> >::PrintStatic(const TFad<6,REAL> *ptr, int64_t rows, int64_t cols, const char *name, std::ostream& out,const MatrixOutputFormat form)
2315 {
2316  DebugStop();
2317 }
2318 #endif
2319 
2320 template <class TVar>
2321 void TPZFMatrix<TVar>::PrintStatic(const TVar *ptr, int64_t rows, int64_t cols, const char *name, std::ostream& out,const MatrixOutputFormat form){
2322 
2323  if(form == EFormatted) {
2324  out << "Writing matrix '";
2325  if(name) out << name;
2326  out << "' (" << rows << " x " << cols << "):\n";
2327 
2328  for ( int64_t row = 0; row < rows; row++) {
2329  out << "\t";
2330  for ( int64_t col = 0; col < cols; col++ ) {
2331  out << SELECTEL(ptr,rows, row, col) << " ";
2332  }
2333  out << "\n";
2334  }
2335  out << "\n";
2336  } else if (form == EInputFormat) {
2337  out << rows << " " << cols << endl;
2338  for ( int64_t row = 0; row < rows; row++) {
2339  for ( int64_t col = 0; col < cols; col++ ) {
2340  TVar val = SELECTEL(ptr,rows,row, col);
2341  if(val != (TVar)0.) out << row << ' ' << col << ' ' << val << std::endl;
2342  }
2343  }
2344  out << "-1 -1 0.\n";
2345  } else if( form == EMathematicaInput)
2346  {
2347  char number[32];
2348  out << name << "\n{ ";
2349  for ( int64_t row = 0; row < rows; row++) {
2350  out << "\n{ ";
2351  for ( int64_t col = 0; col < cols; col++ ) {
2352  TVar val = SELECTEL(ptr,rows,row, col);
2353  sprintf(number, "%16.16lf", (double)fabs(val));
2354  out << number;
2355  if(col < cols-1)
2356  out << ", ";
2357  if((col+1) % 6 == 0)out << std::endl;
2358  }
2359  out << " }";
2360  if(row < rows-1)
2361  out << ",";
2362  }
2363 
2364  out << " }\n";
2365 
2366  }
2367 
2368 }
2369 
2370 template<class TVar>
2372  return Hash("TPZFMatrix") ^ TPZMatrix<TVar>::ClassId() << 1;
2373 }
2374 
2375 template <class TVar>
2376 int TPZFMatrix<TVar>::SetSize(const int64_t newRows,const int64_t newCols) {
2377  int64_t newsize = ((int64_t)newRows)*newCols;
2378  int64_t oldsize = this->fRow*this->fCol;
2379  if(newsize == oldsize) return 1;
2380  if(fElem && fElem != fGiven)
2381  {
2382  delete []fElem;
2383  fElem = 0;
2384  }
2385  if(fGiven && newsize <= fSize)
2386  {
2387  fElem = fGiven;
2388  } else
2389  {
2390  fElem = new TVar[ newRows * newCols ] ;
2391  }
2392  if (newsize && fElem == NULL )
2393  Error( "Resize <memory allocation error>." );
2394 
2395  return( 1 );
2396 }
2397 
2398 #ifdef USING_LAPACK
2399 
2400 template <class TVar>
2401 int TPZFMatrix<TVar>::SolveEigenProblem(TPZVec < std::complex<double> > &eigenvalues)
2402 {
2403  DebugStop();
2404  return -1;
2405 }
2406 
2407 template <class TVar>
2408 int TPZFMatrix<TVar>::SolveEigenProblem(TPZVec < std::complex<double> > &eigenvalues, TPZFMatrix < std::complex<double> > &eigenvectors)
2409 {
2410  DebugStop();
2411  return -1;
2412 }
2413 
2414 template <>
2415 int TPZFMatrix<float>::SolveEigenProblem(TPZVec < std::complex<double> > &eigenvalues)
2416 {
2417  if (Rows() != Cols()) {
2418  DebugStop();
2419  }
2420  char jobvl[] = "None", jobvr[] = "None";
2421  TPZFMatrix< float > VL(Rows(),Cols()),VR(Rows(),Cols());
2422  int dim = Rows();
2423  float testwork;
2424  int lwork = 10+20*dim;
2425  int info;
2426  std::complex<float> I(0,1.);
2427  TPZVec<float> realeigen(dim,0.);
2428  TPZVec<float> imageigen(dim,0.);
2429 
2430  TPZFMatrix<float> temp(*this);
2431  TPZVec<float> work(lwork);
2432  sgeev_(jobvl, jobvr, &dim, temp.fElem, &dim, &realeigen[0], &imageigen[0], VL.fElem, &dim, VR.fElem, &dim, &work[0], &lwork, &info);
2433 
2434  if (info != 0) {
2435  DebugStop();
2436  }
2437  // VR.Print("VR = ",std::cout,EMathematicaInput);
2438 
2439  eigenvalues.Resize(dim,0.);
2440  for(int i = 0 ; i < dim ; i ++){
2441 
2442  eigenvalues[i] = realeigen[i] + I*imageigen[i];
2443  }
2444  return 1;
2445 }
2446 
2447 template <>
2448 int TPZFMatrix<float>::SolveEigenProblem(TPZVec < std::complex<double> > &eigenvalues, TPZFMatrix < std::complex<double> > &eigenvectors)
2449 {
2450  if (Rows() != Cols()) {
2451  DebugStop();
2452  }
2453  char jobvl[] = "None", jobvr[] = "Vectors";
2454  TPZFMatrix< float > VL(Rows(),Cols()),VR(Rows(),Cols());
2455  int dim = Rows();
2456  float testwork;
2457  int lwork = 10+20*dim;
2458  int info;
2459  std::complex<float> I(0,1.);
2460  TPZVec<float> realeigen(dim,0.);
2461  TPZVec<float> imageigen(dim,0.);
2462 
2463  TPZFMatrix<float> temp(*this);
2464  TPZVec<float> work(lwork);
2465  sgeev_(jobvl, jobvr, &dim, temp.fElem, &dim, &realeigen[0], &imageigen[0], VL.fElem, &dim, VR.fElem, &dim, &work[0], &lwork, &info);
2466 
2467  if (info != 0) {
2468  DebugStop();
2469  }
2470  // VR.Print("VR = ",std::cout,EMathematicaInput);
2471 
2472  eigenvectors.Redim(dim,dim);
2473  eigenvalues.Resize(dim,0.);
2474  for(int i = 0 ; i < dim ; i ++){
2475  eigenvalues[i] = realeigen[i] + I*imageigen[i];
2476  }
2477  for(int i = 0 ; i < dim ; i ++){
2478  if(imageigen[i] == 0){
2479  for( int iV = 0 ; iV < dim ; iV++ ){
2480  eigenvectors(iV,i) = VR(iV,i);
2481  }
2482  }
2483  else{
2484  for( int iV = 0 ; iV < dim ; iV++ ){
2485  eigenvectors(iV,i) = VR(iV,i) + I * VR(iV,i+1) ;
2486  eigenvectors(iV,i + 1) = VR(iV,i) - I * VR(iV,i+1) ;
2487  }
2488  i++;
2489  }
2490  }
2491 
2492  return 1;
2493 }
2494 
2495 template <>
2496 int TPZFMatrix<double>::SolveEigenProblem(TPZVec < std::complex<double> > &eigenvalues)
2497 {
2498  if (Rows() != Cols()) {
2499  DebugStop();
2500  }
2501  char jobvl[] = "None", jobvr[] = "None";
2502  TPZFMatrix< double > VL(Rows(),Cols()),VR(Rows(),Cols());
2503  int dim = Rows();
2504  double testwork;
2505  int lwork = 10+20*dim;
2506  int info;
2507  std::complex<double> I(0,1.);
2508  TPZVec<double> realeigen(dim,0.);
2509  TPZVec<double> imageigen(dim,0.);
2510 
2511  TPZFMatrix<double> temp(*this);
2512  TPZVec<double> work(lwork);
2513  dgeev_(jobvl, jobvr, &dim, temp.fElem, &dim, &realeigen[0], &imageigen[0], VL.fElem, &dim, VR.fElem, &dim, &work[0], &lwork, &info);
2514 
2515  if (info != 0) {
2516  DebugStop();
2517  }
2518  // VR.Print("VR = ",std::cout,EMathematicaInput);
2519 
2520  eigenvalues.Resize(dim,0.);
2521  for(int i = 0 ; i < dim ; i ++){
2522  eigenvalues[i] = realeigen[i] + I*imageigen[i];
2523  }
2524  return 1;
2525 }
2526 
2527 template <>
2528 int TPZFMatrix<double>::SolveEigenProblem(TPZVec < std::complex<double> > &eigenvalues, TPZFMatrix < std::complex<double> > &eigenvectors)
2529 {
2530  if (Rows() != Cols()) {
2531  DebugStop();
2532  }
2533  char jobvl[] = "None", jobvr[] = "Vectors";
2534  TPZFMatrix< double > VL(Rows(),Cols(),0.),VR(Rows(),Cols(),0.);
2535  int dim = Rows();
2536 // double testwork;
2537  int lwork = 10+50*dim;
2538  int info = 0;
2539  std::complex<double> I(0,1.);
2540  TPZVec<double> realeigen(dim,0.);
2541  TPZVec<double> imageigen(dim,0.);
2542 
2543  TPZFMatrix<double> temp(*this);
2544  TPZVec<double> work(lwork,0.);
2545  dgeev_(jobvl, jobvr, &dim, temp.fElem, &dim, &realeigen[0], &imageigen[0], VL.fElem, &dim, VR.fElem, &dim, &work[0], &lwork, &info);
2546 
2547  if (info != 0) {
2548  DebugStop();
2549  }
2550  // VR.Print("VR = ",std::cout,EMathematicaInput);
2551 
2552  eigenvectors.Redim(dim,dim);
2553  eigenvalues.Resize(dim,0.);
2554  for(int i = 0 ; i < dim ; i ++){
2555  eigenvalues[i] = realeigen[i] + I*imageigen[i];
2556  }
2557  for(int i = 0 ; i < dim ; i ++){
2558  if(imageigen[i] == 0){
2559  for( int iV = 0 ; iV < dim ; iV++ ){
2560  eigenvectors(iV,i) = VR(iV,i);
2561  }
2562  }
2563  else{
2564  double *realVRptr = VR.fElem;
2565  double *imagVRptr = VR.fElem + dim;
2566  for( int iV = 0 ; iV < dim ; iV++ ){
2567  eigenvectors(iV,i) = VR(iV,i) + I * VR(iV,i+1) ;
2568  eigenvectors(iV,i + 1) = VR(iV,i) - I * VR(iV,i+1) ;
2569  }
2570  i++;
2571  }
2572  }
2573 
2574  return 1;
2575 }
2576 
2577 template <>
2578 int TPZFMatrix<complex<double> >::SolveEigenProblem(TPZVec < std::complex<double> > &eigenvalues)
2579 {
2580  if (Rows() != Cols()) {
2581  DebugStop();
2582  }
2583  char jobvl[] = "None", jobvr[] = "Vectors";
2584  TPZFMatrix< complex<double> > VL(Rows(),Cols()),VR(Rows(),Cols());
2585  int dim = Rows();
2586  double testwork;
2587  int lwork = 10+20*dim;
2588  int info;
2589  std::complex<double> I(0,1.);
2590  TPZVec<complex<double> > eigen(dim,0.);
2591 
2592  TPZFMatrix<complex<double> > temp(*this);
2593  TPZVec<complex<double> > work(lwork);
2594  TPZVec< double > rwork( 2 * dim);
2595 
2596 
2597 
2598  zgeev_(jobvl, jobvr, &dim, (vardoublecomplex *)temp.fElem, &dim, (vardoublecomplex *)&eigen[0], (vardoublecomplex *)VL.fElem, &dim, (vardoublecomplex *)VR.fElem, &dim, (vardoublecomplex *)&work[0], &lwork, &rwork[0], &info);
2599 
2600  if (info != 0) {
2601  DebugStop();
2602  }
2603  // VR.Print("VR = ",std::cout,EMathematicaInput);
2604  eigenvalues.Resize(dim,0.);
2605  for(int i = 0 ; i < dim ; i ++){
2606  eigenvalues[i] = eigen[i];
2607  }
2608 
2609  return 1;
2610 }
2611 
2612 template <>
2613 int TPZFMatrix<complex<double> >::SolveEigenProblem(TPZVec < std::complex<double> > &eigenvalues, TPZFMatrix < std::complex<double> > &eigenvectors)
2614 {
2615  if (Rows() != Cols()) {
2616  DebugStop();
2617  }
2618  char jobvl[] = "None", jobvr[] = "Vectors";
2619  TPZFMatrix< complex<double> > VL(Rows(),Cols()),VR(Rows(),Cols());
2620  int dim = Rows();
2621  double testwork;
2622  int lwork = 10+20*dim;
2623  int info;
2624  std::complex<double> I(0,1.);
2625  TPZVec<complex<double> > eigen(dim,0.);
2626 
2627  TPZFMatrix<complex<double> > temp(*this);
2628  TPZVec<complex<double> > work(lwork);
2629  TPZVec< double > rwork( 2 * dim);
2630 
2631 #ifdef USING_MKL
2632  typedef MKL_Complex16 vardoublecomplex;
2633 #elif MACOSX
2634  typedef __CLPK_doublecomplex vardoublecomplex ;
2635 #endif
2636 
2637 
2638  zgeev_(jobvl, jobvr, &dim, (vardoublecomplex *)temp.fElem, &dim, (vardoublecomplex *)&eigen[0], (vardoublecomplex *)VL.fElem, &dim, (vardoublecomplex *)VR.fElem, &dim, (vardoublecomplex *)&work[0], &lwork, &rwork[0], &info);
2639 
2640  if (info != 0) {
2641  DebugStop();
2642  }
2643  // VR.Print("VR = ",std::cout,EMathematicaInput);
2644 
2645  eigenvectors.Redim(dim,dim);
2646  eigenvalues.Resize(dim,0.);
2647  for(int i = 0 ; i < dim ; i ++){
2648  eigenvalues[i] = eigen[i];
2649  }
2650  for(int i = 0 ; i < dim ; i ++){
2651 
2652  for( int iV = 0 ; iV < dim ; iV++ ){
2653  eigenvectors(iV,i) = VR(iV,i);
2654  }
2655 
2656  }
2657 
2658  return 1;
2659 }
2660 
2661 template <>
2662 int TPZFMatrix<complex<float> >::SolveEigenProblem(TPZVec < std::complex<double> > &eigenvalues)
2663 {
2664  if (Rows() != Cols()) {
2665  DebugStop();
2666  }
2667  char jobvl[] = "None", jobvr[] = "Vectors";
2668  TPZFMatrix< complex<float> > VL(Rows(),Cols()),VR(Rows(),Cols());
2669  int dim = Rows();
2670  double testwork;
2671  int lwork = 10+20*dim;
2672  int info;
2673  std::complex<float> I(0,1.);
2674  TPZVec<complex<float> > eigen(dim,0.);
2675 
2676  TPZFMatrix<complex<float> > temp(*this);
2677  TPZVec<complex<float> > work(lwork);
2678  TPZVec< float > rwork( 2 * dim);
2679 
2680  cgeev_(jobvl, jobvr, &dim, (varfloatcomplex *)temp.fElem, &dim, (varfloatcomplex *)&eigen[0], (varfloatcomplex *)VL.fElem, &dim, (varfloatcomplex *)VR.fElem, &dim, (varfloatcomplex *)&work[0], &lwork, &rwork[0], &info);
2681 
2682  if (info != 0) {
2683  DebugStop();
2684  }
2685  // VR.Print("VR = ",std::cout,EMathematicaInput);
2686 
2687  eigenvalues.Resize(dim,0.);
2688  for(int i = 0 ; i < dim ; i ++){
2689  eigenvalues[i] = eigen[i];
2690  }
2691  return 0;
2692 }
2693 
2694 template <>
2695 int TPZFMatrix<complex< float> >::SolveEigenProblem(TPZVec < std::complex<double> > &eigenvalues, TPZFMatrix < std::complex<double> > &eigenvectors)
2696 {
2697  if (Rows() != Cols()) {
2698  DebugStop();
2699  }
2700  char jobvl[] = "None", jobvr[] = "Vectors";
2701  TPZFMatrix< complex<float> > VL(Rows(),Cols()),VR(Rows(),Cols());
2702  int dim = Rows();
2703  double testwork;
2704  int lwork = 10+20*dim;
2705  int info;
2706  std::complex<float> I(0,1.);
2707  TPZVec<complex<float> > eigen(dim,0.);
2708 
2709  TPZFMatrix<complex<float> > temp(*this);
2710  TPZVec<complex<float> > work(lwork);
2711  TPZVec< float > rwork( 2 * dim);
2712 
2713  cgeev_(jobvl, jobvr, &dim, (varfloatcomplex *)temp.fElem, &dim, (varfloatcomplex *)&eigen[0], (varfloatcomplex *)VL.fElem, &dim, (varfloatcomplex *)VR.fElem, &dim, (varfloatcomplex *)&work[0], &lwork, &rwork[0], &info);
2714 
2715  if (info != 0) {
2716  DebugStop();
2717  }
2718  // VR.Print("VR = ",std::cout,EMathematicaInput);
2719 
2720  eigenvectors.Redim(dim,dim);
2721  eigenvalues.Resize(dim,0.);
2722  for(int i = 0 ; i < dim ; i ++){
2723  eigenvalues[i] = eigen[i];
2724  }
2725  for(int i = 0 ; i < dim ; i ++){
2726 
2727  for( int iV = 0 ; iV < dim ; iV++ ){
2728  eigenvectors(iV,i) = VR(iV,i);
2729  }
2730 
2731  }
2732 
2733  return 1;
2734 }
2735 
2736 
2737 template< class TVar>
2738 int
2739 TPZFMatrix<TVar>::SolveGeneralisedEigenProblem(TPZFMatrix<TVar> &B , TPZVec < complex<double> > &w, TPZFMatrix < complex<double> > &eigenVectors)
2740 {
2741  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <LAPACK does not support this specific data type>" );
2742  return( 0 );
2743 }
2744 template< class TVar>
2745 int
2747 {
2748  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <LAPACK does not support this specific data type>" );
2749  return( 0 );
2750 }
2751 
2752 template<>
2753 int
2754 TPZFMatrix<float>::SolveGeneralisedEigenProblem(TPZFMatrix<float> &B , TPZVec <complex<double> > &eigenvalues, TPZFMatrix < complex<double> > &eigenvectors)
2755 {
2756  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
2757  {
2758  TPZMatrix<float>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
2759  }
2760 
2761  char jobvl[] = "None", jobvr[] = "Vectors";
2762  TPZFMatrix< float > VL(Rows(),Cols()),VR(Rows(),Cols());
2763  int dim = Rows();
2764  float testwork;
2765  int lwork = 10+20*dim;
2766  int info;
2767  std::complex<float> I(0,1.);
2768  TPZVec<float> realeigen(dim,0.);
2769  TPZVec<float> imageigen(dim,0.);
2770 
2771  TPZVec<float> beta(dim);
2772 
2773  TPZFMatrix<float> temp(*this), tempB(B);
2774  TPZVec<float> work(lwork);
2775 
2776  sggev_(jobvl, jobvr, &dim, temp.fElem, &dim , tempB.fElem, &dim , &realeigen[0], &imageigen[0], &beta[0] , VL.fElem, &dim , VR.fElem, &dim, &work[0], &lwork, &info);
2777 
2778  if (info != 0) {
2779  DebugStop();
2780  }
2781  // VR.Print("VR = ",std::cout,EMathematicaInput);
2782 
2783  eigenvectors.Redim(dim,dim);
2784  eigenvalues.Resize(dim,0.);
2785  for(int i = 0 ; i < dim ; i ++){
2786  if( IsZero(beta[i])){
2787  DebugStop(); //fran: i really dont know what to do with this result
2788  }
2789  else{
2790  eigenvalues[i] = (realeigen[i] + I*imageigen[i]) / beta[i];
2791  }
2792  }
2793  for(int i = 0 ; i < dim ; i ++){
2794  if(imageigen[i] == 0){
2795  for( int iV = 0 ; iV < dim ; iV++ ){
2796  eigenvectors(iV,i) = VR(iV,i);
2797  }
2798  }
2799  else{
2800  for( int iV = 0 ; iV < dim ; iV++ ){
2801  eigenvectors(iV,i) = VR(iV,i) + I * VR(iV,i+1) ;
2802  eigenvectors(iV,i + 1) = VR(iV,i) - I * VR(iV,i+1) ;
2803  }
2804  i++;
2805  }
2806  }
2807 
2808  return 1;
2809 }
2810 
2811 
2812 template<>
2813 int
2814 TPZFMatrix<float>::SolveGeneralisedEigenProblem(TPZFMatrix<float> &B , TPZVec <complex<double> > &eigenvalues)
2815 {
2816  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
2817  {
2818  TPZMatrix<float>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
2819  }
2820 
2821  char jobvl[] = "None", jobvr[] = "None";
2822  TPZFMatrix< float > VL(Rows(),Cols()),VR(Rows(),Cols());
2823  int dim = Rows();
2824  float testwork;
2825  int lwork = 10+20*dim;
2826  int info;
2827  std::complex<float> I(0,1.);
2828  TPZVec<float> realeigen(dim,0.);
2829  TPZVec<float> imageigen(dim,0.);
2830 
2831  TPZVec<float> beta(dim);
2832 
2833  TPZFMatrix<float> temp(*this), tempB(B);
2834  TPZVec<float> work(lwork);
2835 
2836  sggev_(jobvl, jobvr, &dim, temp.fElem, &dim , tempB.fElem, &dim , &realeigen[0], &imageigen[0], &beta[0] , VL.fElem, &dim , VR.fElem, &dim, &work[0], &lwork, &info);
2837 
2838  if (info != 0) {
2839  DebugStop();
2840  }
2841  // VR.Print("VR = ",std::cout,EMathematicaInput);
2842 
2843  eigenvalues.Resize(dim,0.);
2844  for(int i = 0 ; i < dim ; i ++){
2845  if( IsZero(beta[i])){
2846  DebugStop(); //fran: i really dont know what to do with this result
2847  }
2848  else{
2849  eigenvalues[i] = (realeigen[i] + I*imageigen[i]) / beta[i];
2850  }
2851  }
2852 
2853  return 1;
2854 }
2855 template<>
2856 int
2857 TPZFMatrix<double>::SolveGeneralisedEigenProblem(TPZFMatrix<double> &B , TPZVec <complex<double> > &eigenvalues, TPZFMatrix < complex<double> > &eigenvectors)
2858 {
2859  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
2860  {
2861  TPZMatrix<float>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
2862  }
2863 
2864  char jobvl[] = "None", jobvr[] = "Vectors";
2865  TPZFMatrix< double > VL(Rows(),Cols()),VR(Rows(),Cols());
2866  int dim = Rows();
2867  float testwork;
2868  int lwork = 10+20*dim;
2869  int info;
2870  std::complex<double> I(0,1.);
2871  TPZVec<double> realeigen(dim,0.);
2872  TPZVec<double> imageigen(dim,0.);
2873 
2874  TPZVec<double> beta(dim);
2875 
2876  TPZFMatrix<double> temp(*this), tempB(B);
2877  TPZVec<double> work(lwork);
2878 
2879  dggev_(jobvl, jobvr, &dim, temp.fElem, &dim , tempB.fElem, &dim , &realeigen[0], &imageigen[0], &beta[0] , VL.fElem, &dim , VR.fElem, &dim, &work[0], &lwork, &info);
2880 
2881  if (info != 0) {
2882  DebugStop();
2883  }
2884  // VR.Print("VR = ",std::cout,EMathematicaInput);
2885 
2886  eigenvectors.Redim(dim,dim);
2887  eigenvalues.Resize(dim,0.);
2888  for(int i = 0 ; i < dim ; i ++){
2889  if( IsZero(beta[i])){
2890  DebugStop(); //fran: i really dont know what to do with this result
2891  }
2892  else{
2893  eigenvalues[i] = (realeigen[i] + I*imageigen[i]) / beta[i];
2894  }
2895  }
2896  for(int i = 0 ; i < dim ; i ++){
2897  if(imageigen[i] == 0){
2898  for( int iV = 0 ; iV < dim ; iV++ ){
2899  eigenvectors(iV,i) = VR(iV,i);
2900  }
2901  }
2902  else{
2903  for( int iV = 0 ; iV < dim ; iV++ ){
2904  eigenvectors(iV,i) = VR(iV,i) + I * VR(iV,i+1) ;
2905  eigenvectors(iV,i + 1) = VR(iV,i) - I * VR(iV,i+1) ;
2906  }
2907  i++;
2908  }
2909  }
2910 
2911  return 1;
2912 }
2913 
2914 
2915 template<>
2916 int
2918 {
2919  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
2920  {
2921  TPZMatrix<double>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
2922  }
2923 
2924  char jobvl[] = "None", jobvr[] = "None";
2925  TPZFMatrix< double > VL(Rows(),Cols()),VR(Rows(),Cols());
2926  int dim = Rows();
2927  double testwork;
2928  int lwork = 10+20*dim;
2929  int info;
2930  std::complex<double> I(0,1.);
2931  TPZVec<double> realeigen(dim,0.);
2932  TPZVec<double> imageigen(dim,0.);
2933 
2934  TPZVec<double> beta(dim);
2935 
2936  TPZFMatrix<double> temp(*this), tempB(B);
2937  TPZVec<double> work(lwork);
2938 
2939  dggev_(jobvl, jobvr, &dim, temp.fElem, &dim , tempB.fElem, &dim , &realeigen[0], &imageigen[0], &beta[0] , VL.fElem, &dim , VR.fElem, &dim, &work[0], &lwork, &info);
2940 
2941  if (info != 0) {
2942  DebugStop();
2943  }
2944  // VR.Print("VR = ",std::cout,EMathematicaInput);
2945 
2946  eigenvalues.Resize(dim,0.);
2947  for(int i = 0 ; i < dim ; i ++){
2948  if( IsZero(beta[i])){
2949  DebugStop(); //fran: i really dont know what to do with this result
2950  }
2951  else{
2952  eigenvalues[i] = (realeigen[i] + I*imageigen[i]) / beta[i];
2953  }
2954  }
2955 
2956  return 1;
2957 }
2958 
2959 template<>
2960 int
2961 TPZFMatrix<complex<float> >::SolveGeneralisedEigenProblem(TPZFMatrix<complex<float> > &B , TPZVec <complex<double> > &eigenvalues, TPZFMatrix < complex<double> > &eigenvectors)
2962 {
2963  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
2964  {
2965  TPZMatrix<float>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
2966  }
2967 
2968  char jobvl[] = "None", jobvr[] = "Vectors";
2969  TPZFMatrix< complex<float> > VL(Rows(),Cols()),VR(Rows(),Cols());
2970  int dim = Rows();
2971  float testwork;
2972  int lwork = 10+20*dim;
2973  int info;
2974  TPZVec<complex<float> > eigen(dim,0.);
2975 
2976  TPZVec<complex<float> > beta(dim);
2977 
2978  TPZFMatrix<complex<float> > temp(*this), tempB(B);
2979  TPZVec<complex<float> > work(lwork);
2980  TPZVec<float> rwork( 8 * dim );
2981 
2982  cggev_(jobvl, jobvr, &dim, (varfloatcomplex *)temp.fElem, &dim , (varfloatcomplex *)tempB.fElem, &dim , (varfloatcomplex *)&eigen[0], (varfloatcomplex *)&beta[0] , (varfloatcomplex *)VL.fElem, &dim , (varfloatcomplex *)VR.fElem, &dim, (varfloatcomplex *)&work[0], &lwork, &rwork[0], &info);
2983 
2984  if (info != 0) {
2985  DebugStop();
2986  }
2987  // VR.Print("VR = ",std::cout,EMathematicaInput);
2988 
2989  eigenvectors.Redim(dim,dim);
2990  eigenvalues.Resize(dim,0.);
2991  for(int i = 0 ; i < dim ; i ++){
2992  if( IsZero(beta[i])){
2993  DebugStop(); //fran: i really dont know what to do with this result
2994  }
2995  else{
2996  eigenvalues[i] = eigen[i] / beta[i];
2997  }
2998  }
2999  for(int i = 0 ; i < dim ; i ++){
3000  for( int iV = 0 ; iV < dim ; iV++ ){
3001  eigenvectors(iV,i) = VR(iV,i);
3002  }
3003  }
3004 
3005  return 1;
3006 }
3007 
3008 
3009 template<>
3010 int
3011 TPZFMatrix<complex<float> >::SolveGeneralisedEigenProblem(TPZFMatrix<complex<float> > &B , TPZVec <complex<double> > &eigenvalues)
3012 {
3013  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
3014  {
3015  TPZMatrix<float>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
3016  }
3017 
3018  char jobvl[] = "None", jobvr[] = "None";
3019  TPZFMatrix< complex<float> > VL(Rows(),Cols()),VR(Rows(),Cols());
3020  int dim = Rows();
3021  float testwork;
3022  int lwork = 10+20*dim;
3023  int info;
3024  TPZVec<complex<float> > eigen(dim,0.);
3025 
3026  TPZVec<complex<float> > beta(dim);
3027 
3028  TPZFMatrix<complex<float> > temp(*this), tempB(B);
3029  TPZVec<complex<float> > work(lwork);
3030  TPZVec<float> rwork( 8 * dim );
3031 
3032  cggev_(jobvl, jobvr, &dim, (varfloatcomplex *)temp.fElem, &dim , (varfloatcomplex *)tempB.fElem, &dim , (varfloatcomplex *)&eigen[0], (varfloatcomplex *)&beta[0] , (varfloatcomplex *)VL.fElem, &dim , (varfloatcomplex *)VR.fElem, &dim, (varfloatcomplex *)&work[0], &lwork, &rwork[0], &info);
3033 
3034  if (info != 0) {
3035  DebugStop();
3036  }
3037  // VR.Print("VR = ",std::cout,EMathematicaInput);
3038 
3039  eigenvalues.Resize(dim,0.);
3040  for(int i = 0 ; i < dim ; i ++){
3041  if( IsZero(beta[i])){
3042  DebugStop(); //fran: i really dont know what to do with this result
3043  }
3044  else{
3045  eigenvalues[i] = eigen[i] / beta[i];
3046  }
3047  }
3048  return 1;
3049 
3050 }
3051 
3052 template<>
3053 int
3054 TPZFMatrix<complex<double> >::SolveGeneralisedEigenProblem(TPZFMatrix<complex<double> > &B , TPZVec <complex<double> > &eigenvalues, TPZFMatrix < complex<double> > &eigenvectors)
3055 {
3056  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
3057  {
3058  TPZMatrix<double>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
3059  }
3060 
3061  char jobvl[] = "None", jobvr[] = "Vectors";
3062  TPZFMatrix< complex<double> > VL(Rows(),Cols()),VR(Rows(),Cols());
3063  int dim = Rows();
3064  float testwork;
3065  int lwork = 10+20*dim;
3066  int info;
3067  TPZVec<complex<double> > eigen(dim,0.);
3068 
3069  TPZVec<complex<double> > beta(dim);
3070 
3071  TPZFMatrix<complex<double> > temp(*this), tempB(B);
3072  TPZVec<complex<double> > work(lwork);
3073  TPZVec<double> rwork( 8 * dim );
3074 
3075  zggev_(jobvl, jobvr, &dim, (vardoublecomplex *)temp.fElem, &dim , (vardoublecomplex *)tempB.fElem, &dim , (vardoublecomplex *)&eigen[0], (vardoublecomplex *)&beta[0] , (vardoublecomplex *)VL.fElem, &dim , (vardoublecomplex *)VR.fElem, &dim, (vardoublecomplex *)&work[0], &lwork, &rwork[0], &info);
3076 
3077  if (info != 0) {
3078  DebugStop();
3079  }
3080  // VR.Print("VR = ",std::cout,EMathematicaInput);
3081 
3082  eigenvectors.Redim(dim,dim);
3083  eigenvalues.Resize(dim,0.);
3084  for(int i = 0 ; i < dim ; i ++){
3085  if( IsZero(beta[i])){
3086  DebugStop(); //fran: i really dont know what to do with this result
3087  }
3088  else{
3089  eigenvalues[i] = eigen[i] / beta[i];
3090  }
3091  }
3092  for(int i = 0 ; i < dim ; i ++){
3093  for( int iV = 0 ; iV < dim ; iV++ ){
3094  eigenvectors(iV,i) = VR(iV,i);
3095  }
3096  }
3097 
3098  return 1;
3099 }
3100 
3101 
3102 template<>
3103 int
3104 TPZFMatrix<complex<double> >::SolveGeneralisedEigenProblem(TPZFMatrix<complex<double> > &B , TPZVec <complex<double> > &eigenvalues)
3105 {
3106  if ( this->fRow != B.Rows() && this->fCol != B.Cols() )
3107  {
3108  TPZMatrix<double>::Error(__PRETTY_FUNCTION__, "SolveGeneralisedEigenProblem <Uncompatible Dimensions>" );
3109  }
3110 
3111  char jobvl[] = "None", jobvr[] = "None";
3112  TPZFMatrix< complex<double> > VL(Rows(),Cols()),VR(Rows(),Cols());
3113  int dim = Rows();
3114  float testwork;
3115  int lwork = 10+20*dim;
3116  int info;
3117  TPZVec<complex<double> > eigen(dim,0.);
3118 
3119  TPZVec<complex<double> > beta(dim);
3120 
3121  TPZFMatrix<complex<double> > temp(*this), tempB(B);
3122  TPZVec<complex<double> > work(lwork);
3123  TPZVec<double> rwork( 8 * dim );
3124 
3125  zggev_(jobvl, jobvr, &dim, (vardoublecomplex *)temp.fElem, &dim , (vardoublecomplex *)tempB.fElem, &dim , (vardoublecomplex *)&eigen[0], (vardoublecomplex *)&beta[0] , (vardoublecomplex *)VL.fElem, &dim , (vardoublecomplex *)VR.fElem, &dim, (vardoublecomplex *)&work[0], &lwork, &rwork[0], &info);
3126 
3127  if (info != 0) {
3128  DebugStop();
3129  }
3130  // VR.Print("VR = ",std::cout,EMathematicaInput);
3131 
3132  eigenvalues.Resize(dim,0.);
3133  for(int i = 0 ; i < dim ; i ++){
3134  if( IsZero(beta[i])){
3135  DebugStop(); //fran: i really dont know what to do with this result
3136  }
3137  else{
3138  eigenvalues[i] = eigen[i] / beta[i];
3139  }
3140  }
3141 
3142  return 1;
3143 
3144 }
3145 
3146 #endif // USING_LAPACK
3147 
3148 
3149 #ifdef _AUTODIFF
3150 
3151 template<>
3153 {
3154  DebugStop();
3155  TFad<6,REAL> res;
3156  return res;
3157 }
3158 template<>
3159 Fad<REAL> Norm(const TPZFMatrix<Fad<REAL> > &A)
3160 {
3161  DebugStop();
3162  Fad<REAL> res;
3163  return res;
3164 }
3165 
3166 
3167 
3168 #endif
3169 
3170 #include <complex>
3171 
3172 template class TPZFMatrix<int >;
3173 template class TPZFMatrix<int64_t >;
3174 template class TPZFMatrix<float >;
3175 template class TPZFMatrix<double >;
3176 template class TPZFMatrix<long double>;
3177 
3178 template class TPZFMatrix< std::complex<float> >;
3179 template class TPZFMatrix< std::complex<double> >;
3180 template class TPZFMatrix< std::complex<long double> >;
3181 
3182 template class TPZFMatrix<TPZFlopCounter>;
3183 
3184 template class TPZRestoreClass< TPZFMatrix<int> >;
3185 template class TPZRestoreClass< TPZFMatrix<int64_t> >;
3186 template class TPZRestoreClass< TPZFMatrix<double> >;
3187 template class TPZRestoreClass< TPZFMatrix<float> >;
3189 
3194 
3195 #ifdef _AUTODIFF
3196 #include "fad.h"
3197 template class TPZFMatrix<TFad<6,REAL> >;
3198 template class TPZFMatrix<Fad<double> >;
3199 template class TPZFMatrix<Fad<float> >;
3200 template class TPZFMatrix<Fad<long double> >;
3201 
3202 template class TPZRestoreClass<TPZFMatrix<TFad<6,REAL> >>;
3203 template class TPZRestoreClass<TPZFMatrix<Fad<double> >>;
3204 template class TPZRestoreClass<TPZFMatrix<Fad<float> >>;
3206 #endif
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
Contains declaration of the TPZSavable class which defines the interface to save and restore objects ...
TPZFMatrix< TVar > operator*(TPZFMatrix< TVar > A) const
Definition: pzfmatrix.h:535
void ZAXPY(const TVar alpha, const TPZFMatrix< TVar > &p)
Performs an ZAXPY operation being *this += alpha * p.
Definition: pzfmatrix.cpp:879
Definition: pzmatrix.h:52
bool IsZero(long double a)
Returns if the value a is close Zero as the allowable tolerance.
Definition: pzreal.h:668
int Solve_LU(TPZFMatrix< TVar > *B, std::list< int64_t > &singular)
Solves the linear system using LU method .
Definition: pzmatrix.h:900
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.
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
Definition: pzmatrix.cpp:1420
static void VerifyAxes(const TPZFMatrix< TVar > &axes)
Verify whether parameter axes is an orthogonal normalized matrix.
Definition: pzaxestools.h:29
TVar & operator()(const int64_t row, const int64_t col)
Definition: pzfmatrix.h:577
void GramSchmidt(TPZFMatrix< TVar > &Orthog, TPZFMatrix< TVar > &TransfToOrthog)
This method implements a Gram Schimidt method. this = Orthog.TransfToOrthog.
Definition: pzfmatrix.cpp:341
static int Error(const char *msg, const char *msg2=0)
Returns error messages.
Definition: pzmatrix.cpp:1402
void AddFel(TPZFMatrix< TVar > &rhs, TPZVec< int64_t > &destination)
Performs a right hand side assemblage.
Definition: pzfmatrix.cpp:209
Definition: pzparallel.h:4
TPZFMatrix< TVar > & operator*=(const TVar val)
Definition: pzfmatrix.cpp:1006
Templated vector implementation.
TPZFMatrix< TVar > & operator-=(const TPZFMatrix< TVar > &A)
Definition: pzfmatrix.cpp:856
void Transpose()
Definition: pzfmatrix.cpp:1086
MatrixOutputFormat
Defines output format.
Definition: pzmatrix.h:55
virtual int Resize(const int64_t newRows, const int64_t newCols)
Redimensions a matriz keeping the previous values.
Definition: pzmatrix.h:278
Defines PZError.
int64_t fRow
Number of rows in matrix.
Definition: pzmatrix.h:779
virtual const TVar & Get(const int64_t row, const int64_t col) const
Get value with bound checking.
Definition: pzmatrix.h:855
static int Error(const char *msg1, const char *msg2=0)
Definition: pzfmatrix.cpp:2161
virtual int Decompose_LU() override
Definition: pzfmatrix.cpp:1307
char fDecomposed
Decomposition type used to decompose the current matrix.
Definition: pzmatrix.h:783
TVar Dot(const TPZFMatrix< TVar > &A, const TPZFMatrix< TVar > &B)
Implement dot product for matrices.
Definition: pzfmatrix.cpp:2083
virtual int Subst_LBackward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is upper triangular with A(i,i)=1.
Definition: pzmatrix.cpp:1358
TPZFMatrix< TVar > & operator+=(const TPZFMatrix< TVar > &A)
Definition: pzfmatrix.cpp:842
Definition: fad.h:54
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
AutoPointerMutexArrayInit tmp
TVar * fGiven
Definition: pzfmatrix.h:432
int ClassId() const override
Routines to send and receive messages.
Definition: pzfmatrix.cpp:2371
char fDefPositive
Definite Posistiveness of current matrix.
Definition: pzmatrix.h:785
virtual const TVar & GetVal(const int64_t, const int64_t) const
Get values without bounds checking This method is faster than "Get" if DEBUG is defined.
Definition: pzmatrix.cpp:56
int64_t fSize
Definition: pzfmatrix.h:433
virtual int Decompose_LDLt() override
Decomposes the current matrix using LDLt. The current matrix has to be symmetric. "L" is lower triangular with 1.0 in its diagonal and "D" is a Diagonal matrix.
Definition: pzfmatrix.cpp:1792
TPZFMatrix< TVar > operator-(const TPZFMatrix< TVar > &A) const
Definition: pzfmatrix.cpp:303
int Zero() override
Makes Zero all the elements.
Definition: pzfmatrix.h:651
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
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
TVar * fElem
Definition: pzfmatrix.h:431
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
Implements a matrix whose nonzero elements are stored in binary tree. Matrix.
Definition: pzfmatrix.h:33
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
Definition: pzlog.h:87
Definition: tfad.h:64
Definition: pzmatrix.h:52
virtual bool Compare(TPZSavable *copy, bool override=false) override
Compare the object for identity with the object pointed to, eventually copy the object.
Definition: pzmatrix.cpp:1433
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
virtual int Subst_Diag(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is diagonal matrix.
Definition: pzmatrix.cpp:1384
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
Definition: tfadfunc.h:120
virtual TPZFMatrix & operator=(const TPZFMatrix< TVar > &A)
Generic operator with FULL matrices.
Definition: pzfmatrix.cpp:131
string res
Definition: test.py:151
static int Substitution(const TVar *ptr, int64_t rows, TPZFMatrix< TVar > *B)
Definition: pzfmatrix.cpp:1323
#define GETVAL(MAT, rows, row, col)
MACRO to get MAT(row,col) entry.
Definition: pzfmatrix.h:45
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
Definition: pzmatrix.cpp:1413
#define LOGPZ_ERROR(A, B)
Define log for errors (cout)
Definition: pzlog.h:93
static REAL val(const int number)
Definition: pzextractval.h:21
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
Definition: pzfmatrix.h:616
virtual int Subst_LForward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is lower triangular with A(i,i)=1.
Definition: pzmatrix.cpp:1333
virtual int64_t Dim() const
Returns the dimension of the matrix if the matrix is square.
Definition: pzmatrix.h:892
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
Contains TPZMatrix<TVar>class, root matrix class.
int64_t fCol
Number of cols in matrix.
Definition: pzmatrix.h:781
#define PUTVAL(MAT, rows, row, col, val)
MACRO to put value val into MAT(row,col) entry.
Definition: pzfmatrix.h:47
virtual int PutVal(const int64_t, const int64_t, const TVar &val)
Put values without bounds checking This method is faster than "Put" if DEBUG is defined.
Definition: pzmatrix.h:154
void Read(TPZStream &buf, void *context) override
read objects from the stream
Definition: pzfmatrix.cpp:2205
int Clear() override
It clears data structure.
Definition: pzfmatrix.cpp:2175
virtual void Multiply(const TPZFMatrix< TVar > &A, TPZFMatrix< TVar > &res, int opt=0) const
It mutiplies itself by TPZMatrix<TVar>A putting the result in res.
Definition: pzmatrix.cpp:1916
void TimesBetaPlusZ(const TVar beta, const TPZFMatrix< TVar > &z)
Performs an operation *this = this * beta + z.
Definition: pzfmatrix.cpp:898
int Remodel(const int64_t newRows, const int64_t wCols)
Remodel the shape of the matrix, but keeping the same dimension.
Definition: pzfmatrix.cpp:1063
This class implements floating point number associated with a counter of the operations performed wit...
Definition: pzreal.h:261
Contains declaration of the TPZAxesTools class which implements verifications over axes...
virtual 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
It computes z = beta * y + alpha * opt(this)*x but z and x can not overlap in memory.
Definition: pzfmatrix.cpp:757
Contains TPZVerySparseMatrix class which implements a matrix whose nonzero elements are stored in bin...
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ exp
Definition: tfadfunc.h:125
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
Definition: pzfmatrix.cpp:1016
virtual int Decompose_Cholesky() override
Cholesky Decomposition Optmized. for walks in the direction of the vector that composes the matrix...
Definition: pzfmatrix.cpp:1574
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
void DeterminantInverse(TVar &determinant, TPZFMatrix< TVar > &inverse)
Definition: pzfmatrix.cpp:507
std::map< std::pair< int64_t, int64_t >, TVar >::const_iterator MapEnd() const
#define SELECTEL(ptr, rows, row, col)
MACRO to get the entry of the vector (ptr[col*rows+row]) as matrix ( ptr(row,col) ) ...
Definition: pzfmatrix.h:49
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzfmatrix.cpp:2225
int SetSize(int64_t newRows, int64_t newCols)
Redimension the matrix doing nothing with the elements.
Definition: pzfmatrix.cpp:2376
This class defines the interface to save and restore objects from TPZStream objects. Persistency.
Definition: TPZSavable.h:67
static void PrintStatic(const TVar *ptr, int64_t rows, int64_t cols, const char *name, std::ostream &out, const MatrixOutputFormat form)
Definition: pzfmatrix.cpp:2321
virtual bool Compare(TPZSavable *copy, bool override=false) override
Compare the object for identity with the object pointed to, eventually copy the object.
Definition: pzfmatrix.cpp:2236
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
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
void Transpose(TPZMatrix< TVar > *const T) const override
It makes *T the transpose of current matrix.
Definition: pzfmatrix.cpp:1073
TVar & g(const int64_t row, const int64_t col) const
Definition: pzfmatrix.h:594
TPZFMatrix< TVar > operator+(const TPZFMatrix< TVar > &A) const
Definition: pzfmatrix.cpp:284
std::map< std::pair< int64_t, int64_t >, TVar >::const_iterator MapBegin() const
Implements an interface to register a class id and a restore function. Persistence.
Definition: TPZSavable.h:150
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15
int ClassId() const override
Define the class id associated with the class.
Definition: pzmatrix.h:957
virtual void Read(bool &val)
Definition: TPZStream.cpp:91
virtual int Subst_Backward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is upper triangular.
Definition: pzmatrix.cpp:1309
TPZFMatrix()
Simple constructor.
Definition: pzfmatrix.h:74
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60