NeoPZ
pzskylnsymmat.cpp
Go to the documentation of this file.
1 // ---------------------------------------------------------------------------
2 
3 #include "pzskylnsymmat.h"
4 
5 // ---------------------------------------------------------------------------
6 
7 //
8 // Author: Nathan Shauer.
9 //
10 // File: pzskylnsymmat
11 //
12 // Class: TPZSkylNSymMatrix
13 //
14 // Obs.: This class manages non symmetric skylyne type matrix
15 //
16 //
17 // Versao: 12 / 2011.
18 //
19 
20 #include <math.h>
21 #include <stdlib.h>
22 
23 #ifdef BLAS
24 extern "C"
25 {
26 #include <cblas.h>
27 }
28 #endif
29 
30 //const int templatedepth = 10;
31 
37 // #include <sys/timeb.h>
38 
39 #include "pzfmatrix.h"
40 #include "pzskylmat.h"
41 // #include "pzerror.h"
42 
43 #include <sstream>
44 #include "pzlog.h"
45 
46 #ifdef LOG4CXX
47 static LoggerPtr logger(Logger::getLogger("pz.matrix.tpzskylmatrix"));
48 #endif
49 
50 using namespace std;
51 
60 template <class TVar>
61 TPZSkylNSymMatrix<TVar>::TPZSkylNSymMatrix(const int64_t row, const int64_t col) : TPZRegisterClassId(&TPZSkylNSymMatrix::ClassId),
62 TPZMatrix<TVar>(row,col),
63 fElem(row + 1), fElemb(row + 1), fStorage(0), fStorageb(0)
64 {
65 
66  if (row != col) {
67  DebugStop();
68  }
69  // Inicializa a diagonal (vazia).
70  fElem.Fill(0);
71  fElemb.Fill(0);
72 }
73 
74 template <class TVar>
77 TPZMatrix<TVar>(dim, dim), fElem(dim + 1), fElemb(dim + 1), fStorage(0), fStorageb(0)
78 {
79 
80  // Inicializa a diagonal (vazia).
81  fElem.Fill(0);
82  fElemb.Fill(0);
83  InitializeElem(skyline, fStorage, fElem);
84  InitializeElem(skyline, fStorageb, fElemb);
85 }
86 
87 /* IMPLEMENTAR
88 void TPZSkylNSymMatrix::AddSameStruct(TPZSkylMatrix &B, double k)
89 {
90 #ifdef PZDEBUG
91 {
92 int size = this->fElem.NElements();
93 if (size != B.fElem.NElements())
94 {
95 PZError << "\nFATAL ERROR at " << __PRETTY_FUNCTION__ << "\n";
96 PZError.flush();
97 DebugStop();
98 }
99 for (int i = 0; i < size; i++)
100 {
101 if ((this->fElem[i]-this->fElem[0]) != (B.fElem[i] - B.fElem[0]))
102 {
103 PZError << "\nFATAL ERROR at " << __PRETTY_FUNCTION__ << "\n";
104 PZError.flush();
105 DebugStop();
106 }
107 }
108 }
109 #endif
110 
111 const int n = this->fStorage.NElements();
112 for (int i = 0; i < n; i++)
113 this->fStorage[i] += k * B.fStorage[i];
114 
115 }
116  */
117 
118 template <class TVar>
120 {
121  fElem.Fill(0);
122  fElemb.Fill(0);
123  InitializeElem(skyline, fStorage, fElem);
124  InitializeElem(skyline, fStorageb, fElemb);
125 }
126 
127 template <class TVar>
129 {
130  int64_t dim = skyline.NElements();
131  int64_t i, nelem = 0;
132  for (i = 0; i < dim; i++)
133  nelem += i - skyline[i] + 1;
134  return nelem;
135 }
136 
137 template <class TVar>
139  TPZManVector<TVar> &storage, TPZVec<TVar *> &point)
140 {
141  int64_t dim = skyline.NElements();
142  int64_t nel = NumElements(skyline);
143  storage.Resize(nel);
144  storage.Fill(0.);
145  int64_t i;
146  point.Resize(dim + 1);
147  if (dim)
148  {
149  point[0] = &storage[0];
150  point[dim] = &storage[0] + nel;
151  }
152  else
153  {
154  point[0] = 0;
155  }
156  for (i = 1; i < dim + 1; i++)
157  point[i] = point[i - 1] + (i - 1) - skyline[i - 1] + 1;
158 }
159 
163 template <class TVar>
165  const TPZSkylNSymMatrix &second, TPZVec<int> &res)
166 {
167 
168  if (first.Rows() != second.Rows())
169  {
170  cout << "ComputeMaxSkyline : incompatible dimension";
171  return;
172  }
173  int64_t i, dim = first.Rows();
174  res.Resize(dim + 1);
175 
176  for (i = 1; i < dim + 1; i++)
177  {
178 
179  int64_t aux = (first.Size(i) > second.Size(i)) ? first.Size(i) : second.Size(i);
180  res[i] = i - aux - 1;
181  }
182 }
183 
184 template <class TVar>
185 TVar & TPZSkylNSymMatrix<TVar>::operator()(const int64_t r, const int64_t c)
186 {
187  int64_t row(r), col(c);
188  if (col >= row)
189  {
190  // Indice do vetor coluna.
191  int64_t index = col - row;
192  if (index >= Size(col))
193  {
194  // Error("TPZSkylMatrix::operator()","Index out of range");
195  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "Index out of range");
196  DebugStop();
197  }
198  return fElem[col][index];
199  }
200  else
201  {
202  // Indice do vetor coluna.
203  int64_t index = row - col;
204  if (index >= Size(row))
205  {
206  // Error("TPZSkylMatrix::operator()","Index out of range");
207  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "Index out of range");
208  DebugStop();
209  }
210  return fElemb[row][index];
211  }
212 }
213 
214 template <class TVar>
215 TVar &TPZSkylNSymMatrix<TVar>::s(const int64_t row, const int64_t col)
216 {
217  return operator()(row, col);
218 }
219 
220 template <class TVar>
221 TVar & TPZSkylNSymMatrix<TVar>::operator()(const int64_t r)
222 {
223  return operator()(r, r);
224 }
225 
228 template <class TVar>
229 int TPZSkylNSymMatrix<TVar>::PutVal(const int64_t r, const int64_t c, const TVar & value)
230 {
231  // inicializando row e col para trabalhar com a triangular superior
232  int64_t row(r), col(c);
233  if (col >= row)
234  {
235  // Indice do vetor coluna.
236  int64_t index = col - row;
237  // Se precisar redimensionar o vetor.
238  if (index >= Size(col) && !IsZero(value))
239  {
240  cout << "TPZSkylMatrix::PutVal Size" << Size(col);
241  cout.flush();
242  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "Index out of range");
243  }
244  else if (index >= Size(col))
245  return 1;
246  fElem[col][index] = value;
247  // delete[]newVet;
248  }
249 
250  else if (col < row)
251  {
252  // Indice do vetor coluna.
253  int64_t index = row - col;
254  // Se precisar redimensionar o vetor.
255  if (index >= Size(row) && !IsZero(value))
256  {
257  cout << "TPZSkylMatrix::PutVal Size" << Size(col);
258  cout.flush();
259  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, "Index out of range");
260  }
261  else if (index >= Size(row))
262  return 1;
263  fElemb[row][index] = value;
264  // delete[]newVet;
265  }
266  this->fDecomposed = 0;
267 
268  return(1);
269 }
270 
271 template <class TVar>
273  TPZFMatrix<TVar> &z, const TVar alpha, const TVar beta, const int opt)const
274 {
275  // Computes z = beta * y + alpha * opt(this)*x
276  // z and x cannot overlap in memory
277  if ((!opt && this->Cols() != x.Rows()) || this->Rows() != x.Rows())
278  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,
279  " <matrixs with incompatible dimensions>");
280  if (z.Rows() != x.Rows() || z.Cols() != x.Cols())
281  z.Redim(x.Rows(), x.Cols());
282  if (x.Cols() != y.Cols() || x.Cols() != z.Cols() || x.Rows() != y.Rows()
283  || x.Rows() != z.Rows())
284  {
285  cout << "x.Cols = " << x.Cols() << " y.Cols()" << y.Cols()
286  << " z.Cols() " << z.Cols() << " x.Rows() " << x.Rows()
287  << " y.Rows() " << y.Rows() << " z.Rows() " << z.Rows() << endl;
288  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__, " incompatible dimensions\n");
289  }
290  this->PrepareZ(y, z, beta, opt);
291  int64_t rows = this->Rows();
292  int64_t xcols = x.Cols();
293  int64_t ic, r;
294  for (ic = 0; ic < xcols; ic++)
295  {
296  for (r = 0; r < rows; r++)
297  {
298  int64_t offset = Size(r);
299  TVar val = 0.;
300  const TVar *p = &x.g((r - offset + 1), ic);
301  TVar *diag, *diaglast;
302  if (opt == 0)
303  {
304  diag = fElemb[r] + offset - 1;
305  diaglast = fElemb[r];
306  }
307  else
308  {
309  diag = fElem[r] + offset - 1;
310  diaglast = fElem[r];
311  }
312  while (diag > diaglast)
313  {
314  val += *diag--**p;
315  p ++;
316  }
317  if (diag == diaglast)
318  {
319  diag = fElem[r];
320  val += *diag * *p;
321  }
322  z(r, ic) += val * alpha;
323  TVar *zp = &z((r - offset + 1), ic);
324  val = x.g(r, ic);
325  if(opt == 0)
326  {
327  diag = fElem[r] + offset - 1;
328  diaglast = fElem[r];
329  }
330  else
331  {
332  diag = fElemb[r] + offset - 1;
333  diaglast = fElemb[r];
334  }
335  while (diag > diaglast)
336  {
337  *zp += alpha * *diag--*val;
338  zp ++;
339  }
340  //z.Print("z");
341  }
342  }
343 }
344 
346 template <class TVar>
348 
349 {
350  TPZMatrix<TVar> *matrix = mat.operator->();
351  TPZSkylNSymMatrix<TVar> *skylmat = dynamic_cast<TPZSkylNSymMatrix<TVar> *>(matrix);
352  if (!skylmat) {
353  DebugStop();
354  }
355  if (fStorage.NElements() != skylmat->fStorage.NElements() || fStorageb.NElements() != skylmat->fStorageb.NElements()) {
356  DebugStop();
357  }
358  memcpy(&fStorage[0], &(skylmat->fStorage[0]) , fStorage.NElements()*sizeof(TVar));
359  memcpy(&fStorageb[0], &(skylmat->fStorageb[0]) , fStorageb.NElements()*sizeof(TVar));
360  this->fDecomposed = skylmat->fDecomposed;
361  this->fDefPositive = skylmat->fDefPositive;
362 }
363 
364 /*
365 void TPZSkylMatrix::SolveSOR(int & numiterations, const TPZFMatrix &F,
366 TPZFMatrix &result, TPZFMatrix *residual, TPZFMatrix &scratch,
367 const REAL overrelax, REAL &tol, const int FromCurrent,
368 const int direction)
369 {
370 
371 if (residual == &F)
372 {
373 cout <<
374 "TPZMatrix::SolveSOR called with residual and F equal, no solution\n";
375 return;
376 }
377 REAL res = 2 * tol + 1.; ;
378 if (residual)
379 res = Norm(*residual);
380 if (!FromCurrent)
381 {
382 result.Zero();
383 }
384 int r = Dim();
385 int c = F.Cols();
386 int i, ifirst = 0, ilast = r, iinc = 1;
387 if (direction == -1)
388 {
389 ifirst = r - 1;
390 ilast = 0;
391 iinc = -1;
392 }
393 int it;
394 for (it = 0; it < numiterations && res > tol; it++)
395 {
396 res = 0.;
397 scratch = F;
398 for (int ic = 0; ic < c; ic++)
399 {
400 if (direction == 1)
401 {
402 //
403 // compute the upper triangular part first and put into the scractch vector
404 //
405 for (i = ifirst; i != ilast; i += iinc)
406 {
407 // TPZColuna *mydiag = &fDiag[i];
408 int offset = Size(i);
409 REAL val;
410 REAL *diag;
411 REAL *diaglast = fElem[i];
412 REAL *scratchp = &scratch(i - offset + 1, ic);
413 val = result(i, ic);
414 diag = fElem[i] + offset - 1;
415 int lastid = diag - diaglast;
416 int id;
417 for (id = 0; id <= lastid; id++)
418  * (scratchp + id) -= *(diag - id) * val;
419 // codeguard fix
420 while( diag >= diaglast ) *scratchp++ -= *diag-- * val;
421 //
422 }
423 //
424 // perform the SOR operation
425 //
426 for (i = ifirst; i != ilast; i += iinc)
427 {
428 // TPZColuna *mydiag = &fDiag[i];
429 int offset = Size(i);
430 REAL val = scratch(i, ic);
431 REAL *p = &result(i - offset + 1, ic);
432 REAL *diag = fElem[i] + offset - 1;
433 REAL *diaglast = fElem[i];
434 while (diag > diaglast)
435 val -= *diag--**p++;
436 res += val * val;
437 result(i, ic) += val * overrelax / *diag;
438 }
439 }
440 else
441 {
442 //
443 // the direction is upward
444 //
445 // put the lower triangular part of the multiplication into the scratch vector
446 //
447 for (i = ifirst; i != ilast; i += iinc)
448 {
449 // TPZColuna *mydiag = &fDiag[i];
450 int offset = Size(i);
451 REAL val = scratch(i, ic);
452 REAL *p = &result(i - offset + 1, ic);
453 REAL *diag = fElem[i] + offset - 1;
454 REAL *diaglast = fElem[i];
455 while (diag > diaglast)
456 val -= *diag--**p++;
457 // res += val*val;
458 scratch(i, ic) = val;
459 }
460 //
461 // perform the SOR operation
462 //
463 for (i = ifirst; i != ilast; i += iinc)
464 {
465 // TPZColuna *mydiag = &fDiag[i];
466 int offset = Size(i);
467 // REAL val = scratch(i,ic);
468 REAL *diag;
469 REAL *diaglast = fElem[i];
470 REAL *scratchp = &scratch(i - offset + 1, ic);
471 // val= result(i,ic);
472 REAL val = scratch(i, ic);
473 val -= *diaglast * result(i, ic);
474 res += val * val;
475 val = overrelax * val / *diaglast;
476 result(i, ic) += val;
477 val = result(i, ic);
478 diag = fElem[i] + offset - 1;
479 while (diag > diaglast)
480  * scratchp++ -= *diag--*val;
481 }
482 }
483 }
484 res = sqrt(res);
485 }
486 if (residual)
487 {
488 Residual(result, F, *residual);
489 }
490 numiterations = it;
491 tol = res;
492 }
493 
494  */
495 
499 template <class TVar>
500 const TVar & TPZSkylNSymMatrix<TVar>::GetVal(const int64_t r, const int64_t c)const
501 {
502  // inicializando row e col para trabalhar com a triangular superior
503  int64_t row(r), col(c);
504  if (col >= row)
505  {
506  if (row >= this->Dim() || col >= this->Dim() || row < 0 || col < 0)
507  {
508  cout << "TPZSkylMatrix::GetVal index out of range row = " << row <<
509  " col = " << col << endl;
510  return this->gZero;
511  }
512  // Indice do vetor coluna.
513  int64_t index = col - row;
514  // TPZColuna *pCol = &fDiag[col];
515 
516  if (index < Size(col))
517  return(fElem[col][index]);
518  else
519  {
520  if (this->gZero != TVar(0.))
521  {
522  cout << "TPZSkylMatrix gZero = " << this->gZero << endl;
523  DebugStop();
524  }
525  return(this->gZero);
526  }
527  }
528 
529  if (row > col)
530  {
531  if (row >= this->Dim() || col >= this->Dim() || row < 0 || col < 0)
532  {
533  cout << "TPZSkylMatrix::GetVal index out of range row = " << row <<
534  " col = " << col << endl;
535  return this->gZero;
536  }
537  // Indice do vetor coluna.
538  int64_t index = row - col;
539  // TPZColuna *pCol = &fDiag[col];
540 
541  if (index < Size(row))
542  return(fElemb[row][index]);
543  else
544  {
545  if (this->gZero != TVar(0.))
546  {
547  cout << "TPZSkylMatrix gZero = " << this->gZero << endl;
548  DebugStop();
549  }
550  return(this->gZero);
551  }
552  }
553  return this->gZero;
554 }
555 
557 
558 template <class TVar>
559 const TVar & TPZSkylNSymMatrix<TVar>::GetValSup(const int64_t r, const int64_t c)const
560 {
561 
562  int64_t row(r), col(c);
563  int64_t index = col - row;
564 #ifdef PZDEBUG
565 
566  if (row >= this->Dim() || col >= this->Dim() || row < 0 || col < 0)
567  {
568  cout << "TPZSkylMatrix::GetVal index out of range row = " << row <<
569  " col = " << col << endl;
570  return this->gZero;
571  }
572  if (index < Size(col))
573  DebugStop();
574 
575 #endif
576  return(fElem[col][index]);
577 }
578 
579 template <class TVar>
580 const TVar & TPZSkylNSymMatrix<TVar>::GetValB(const int64_t r, const int64_t c)const
581 {
582 
583  int64_t row(r), col(c);
584  int64_t index = row - col;
585 #ifdef PZDEBUG
586 
587  if (row >= this->Dim() || col >= this->Dim() || row < 0 || col < 0)
588  {
589  cout << "TPZSkylMatrix::GetVal index out of range row = " << row <<
590  " col = " << col << endl;
591  return this->gZero;
592  }
593  if (index < Size(col))
594  DebugStop();
595 
596 #endif
597  return(fElem[row][index]);
598 }
599 
605 /*
606 
607 TPZSkylMatrix & TPZSkylMatrix:: operator = (const TPZSkylMatrix & A)
608 {
609 Clear();
610 Copy(A);
611 return(*this);
612 }
613 
614  */
615 
619 /*
620 TPZSkylMatrix TPZSkylMatrix:: operator +(const TPZSkylMatrix & A)const
621 {
622 if (Dim() != A.Dim())
623 TPZMatrix::Error(__PRETTY_FUNCTION__, "<incompatible dimensions>");
624 
625 TPZVec<int>skylinesize(Dim());
626 ComputeMaxSkyline(*this, A, skylinesize);
627 TPZSkylMatrix res(fRow, skylinesize);
628 
629 REAL *elemMax;
630 REAL *elemMin;
631 int sizeMax;
632 int sizeMin;
633 
634 for (int col = 0; col < Dim(); col++)
635 {
636 // Define o tamanho e os elementos da maior e da menor
637 // coluna.
638 if (Size(col) > A.Size(col))
639 {
640 sizeMax = Size(col);
641 elemMax = fElem[col];
642 sizeMin = A.Size(col);
643 elemMin = A.fElem[col];
644 }
645 else
646 {
647 sizeMax = A.Size(col);
648 elemMax = A.fElem[col];
649 sizeMin = Size(col);
650 elemMin = fElem[col];
651 }
652 
653 // Inicializa coluna da matriz resultado.
654 
655 // Efetua a SOMA.
656 REAL *dest = res.fElem[col];
657 int i;
658 for (i = 0; i < sizeMin; i++)
659  * dest++ = (*elemMax++) + (*elemMin++);
660 for (; i < sizeMax; i++)
661  * dest++ = *elemMax++;
662 }
663 
664 return(res);
665 }
666 
667  */
668 
672 /*
673 
674 TPZSkylMatrix TPZSkylMatrix:: operator -(const TPZSkylMatrix & A)const
675 {
676 if (Dim() != A.Dim())
677 TPZMatrix::Error(__PRETTY_FUNCTION__,
678 "operator-( TPZSkylMatrix ) <incompatible dimensions>");
679 
680 TPZVec<int>skylinesize(Dim());
681 ComputeMaxSkyline(*this, A, skylinesize);
682 TPZSkylMatrix res(fRow, skylinesize);
683 
684 for (int col = 0; col < fRow; col++)
685 {
686 // Define o tamanho e os elementos das colunas das 2 matrizes.
687 int sizeThis = Size(col);
688 REAL *elemThis = fElem[col];
689 int sizeA = A.Size(col);
690 REAL *elemA = A.fElem[col];
691 
692 // Inicializa coluna da matriz resultado.
693 
694 // Efetua a SUBTRACAO.
695 REAL *dest = res.fElem[col];
696 int i;
697 for (i = 0; (i < sizeThis) && (i < sizeA); i++)
698  * dest++ = (*elemThis++) - (*elemA++);
699 if (i == sizeA)
700 for (; i < sizeThis; i++)
701  * dest++ = *elemThis++;
702 else
703 for (; i < sizeA; i++)
704  * dest++ = -(*elemA++);
705 }
706 
707 return(res);
708 }
709 
710  */
711 
715 /*
716 TPZSkylMatrix & TPZSkylMatrix:: operator += (const TPZSkylMatrix & A)
717 {
718 if (Dim() != A.Dim())
719 TPZMatrix::Error(__PRETTY_FUNCTION__,
720 "operator+=( TPZSkylMatrix ) <incompatible dimensions>");
721 
722 TPZSkylMatrix res((*this) + A);
723  *this = res;
724 return *this;
725 }
726 
727  */
728 
732 /*
733 
734 TPZSkylMatrix & TPZSkylMatrix:: operator -= (const TPZSkylMatrix & A)
735 {
736 if (Dim() != A.Dim())
737 TPZMatrix::Error(__PRETTY_FUNCTION__,
738 "operator-=( TPZSkylMatrix ) <incompatible dimensions>");
739 
740 TPZSkylMatrix res(*this -A);
741  *this = res;
742 return *this;
743 }
744 
745  */
746 
748 //
749 // As operacoes com valores numericos sao efetuadas apenas nos
750 // elementos alocados. Em especial, as operacoes A = 0.0 e A *= 0.0
751 // desalocam todos os elementos da matriz.
752 //
753 
757 /*
758 TPZSkylMatrix TPZSkylMatrix:: operator*(const REAL value)const
759 {
760 TPZSkylMatrix res(*this);
761 
762 for (int col = 0; col < Dim(); col++)
763 {
764 // Aloca nova coluna para o resultado.
765 int colsize = Size(col);
766 // Efetua a SOMA.
767 REAL *elemRes = res.fElem[col];
768 for (int i = 0; i < colsize; i++)
769  * elemRes++ *= value;
770 }
771 
772 return(res);
773 }
774 
775  */
776 
780 /*
781 TPZSkylMatrix & TPZSkylMatrix:: operator *= (const REAL value)
782 {
783 if (IsZero(value))
784 {
785 Zero();
786 return(*this);
787 }
788 
789 int col, colmax = Dim();
790 for (col = 0; col < colmax; col++)
791 {
792 // Efetua a MULTIPLICACAO.
793 REAL *elem = fElem[col];
794 REAL *end = fElem[col + 1];
795 while (elem < end)
796  * elem++ *= value;
797 }
798 
799 fDecomposed = 0;
800 return(*this);
801 }
802 
803  */
804 
807 //
808 // Muda as dimensoes da matriz, mas matem seus valores antigos. Novas
809 // posicoes sao criadas com ZEROS.
810 //
811 
812 /*
813 int TPZSkylMatrix::Resize(int newDim, int)
814 {
815 if (newDim == Dim())
816 return(1);
817 
818 fElem.Resize(newDim + 1);
819 // Cria nova matrix.
820 
821 // Copia os elementos para a nova matriz.
822 int min = Min(newDim, Dim());
823 int i;
824 for (i = min + 1; i <= newDim; i++)
825 fElem[i] = fElem[i - 1];
826 
827 // Zera as posicoes que sobrarem (se sobrarem)
828 fStorage.Resize(fElem[newDim] - fElem[0]);
829 fRow = fCol = newDim;
830 fDecomposed = 0;
831 return(1);
832 }
833 
834  */
835 
838 //
839 // Muda as dimensoes da matriz e ZERA seus elementos.
840 //
841 
842 /*
843 int TPZSkylMatrix::Redim(int newDim, int)
844 {
845 if (newDim == Dim())
846 {
847 Zero();
848 return(1);
849 }
850 
851 Clear();
852 fElem.Resize(newDim);
853 fElem.Fill(0);
854 fRow = fCol = newDim;
855 fDecomposed = 0;
856 return(1);
857 }
858 
859 
860  */
861 
864 //
865 // Faz A= LU onde L eh triangular inferior com 1 na diagonal e U eh triangular superior
866 //
867 template <class TVar>
869 {
870  if (this->fDecomposed == ELU)
871  return 1;
872  if (this->fDecomposed)
873  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,
874  "Decompose_LU <Matrix already Decomposed>");
875 
876  TVar pivot;
877  int64_t dimension = this->Dim();
878  /* if(Dim() > 100) {
879  cout << "\nTPZSkylMatrix Cholesky decomposition Dim = " << Dim() << endl;
880  cout.flush();
881  } */
882  for (int64_t k = 0; k < dimension; k++)
883  {
884  /* if(!(k%100) && Dim() > 100) {
885  cout << k << ' ';
886  cout.flush();
887  }
888  if(!(k%1000)) cout << endl; */
889  if (Size(k) == 0)
890  {
891  PZError << "CUIDADO, A MATRIZ NAO TEM POSICOES NA LINHA " << k << "\n";
892  return(0);
893  }
894 
895  // Faz sum = SOMA( A(k,p) * A(k,p) ), p = 1, ..., k-1.
896  //
897  TVar sum = 0.0;
898  TVar *elem_k = fElem[k] + 1;
899  TVar *elem_kb = fElemb[k] + 1;
900  TVar *end_k = fElem[k] + Size(k);
901  for (; elem_k < end_k; elem_k++, elem_kb++)
902  {
903  sum += (*elem_k) * (*elem_kb);
904  }
905 
906  // Faz A(k,k) = sqrt( A(k,k) - sum ).
907  //
908 
909  pivot = fElem[k][0] - sum;
910  if (fabs(pivot) < 1.e-25)
911  {
912  cout <<
913  "TPZSkylNSymMatrix<TVar>::Decompose_LU a matrix nao e positiva definida"
914  << pivot << endl;
915  return(0);
916  }
917  // A matriz nao e' definida positiva.
918 
919  fElem[k][0] = pivot;
920 
921  // Loop para i = k+1 ... Dim().
922  //
923  int64_t i = k + 1;
924  for (int64_t j = 2; i < dimension; j++, i++)
925  {
926  // Se tiverem elementos na linha 'i' cuja coluna e'
927  // menor do que 'K'...
928  if (Size(i) > j)
929  {
930  // linha
931  // Faz sum = SOMA( A(i,p) * A(k,p) ), p = 1,..,k-1.
932  sum = 0.0;
933  TVar *elem_i = &fElem[i][j];
934  TVar *end_i = fElem[i + 1];
935  elem_k = &(fElemb[k][1]);
936  end_k = fElemb[k] + Size(k);
937  while ((elem_i < end_i) && (elem_k < end_k))
938  sum += (*elem_i++) * (*elem_k++);
939 
940  // Faz A(i,k) = (A(i,k) - sum) / A(k,k)
941  fElem[i][j - 1] = (fElem[i][j - 1] - sum);
942 
943  // coluna
944  sum = 0.0;
945  elem_i = &fElemb[i][j];
946  end_i = fElemb[i + 1];
947  elem_k = &(fElem[k][1]);
948  end_k = fElem[k] + Size(k);
949  while ((elem_i < end_i) && (elem_k < end_k))
950  sum += (*elem_i++) * (*elem_k++);
951 
952  // Faz A(i,k) = (A(i,k) - sum) / A(k,k)
953  fElemb[i][j - 1] = (fElemb[i][j - 1] - sum) / pivot;
954  }
955  else if (Size(i) == j)
956  {
957  fElemb[i][j - 1] /= pivot;
958  }
959 
960  // Se nao tiverem estes elementos, sum = 0.0.
961 
962  // Se nao existir nem o elemento A(i,k), nao faz nada.
963  }
964  // Print("decomposing");
965  }
966 
967  this->fDecomposed = ELU;
968  this->fDefPositive = 1;
969  return(1);
970 }
971 
974 //
975 // Faz Ax = b, onde A e' triangular inferior.
976 //
977 
978 /*
979 int TPZSkylMatrix::Subst_Forward(TPZFMatrix *B)const
980 {
981 if ((B->Rows() != Dim()) || fDecomposed != ECholesky)
982 TPZMatrix::Error(__PRETTY_FUNCTION__,
983 "TPZSkylMatrix::Subst_Forward not decomposed with cholesky");
984 
985 // std::cout << "SubstForward this " << (void *) this << " neq " << Dim() << " normb " << Norm(*B) << std::endl;
986 int dimension = Dim();
987 for (int j = 0; j < B->Cols(); j++)
988 {
989 int k = 0;
990 while (k < dimension && (*B)(k, j) == 0)
991 {
992 k++;
993 }
994 // std::cout << "kstart " << k << std::endl;
995 for (; k < dimension; k++)
996 {
997 // Faz sum = SOMA( A[k,i] * B[i,j] ), para i = 1, ..., k-1.
998 //
999 REAL sum = 0.0;
1000 REAL *elem_ki = fElem[k] + 1;
1001 REAL *end_ki = fElem[k + 1];
1002 REAL* BPtr = &(*B)(k, j); // (k-1,j)
1003 // for ( int i = k-1; elem_ki < end_ki; i-- )
1004 // sum += (*elem_ki++) * B->GetVal( i, j );
1005 
1006 while (elem_ki < end_ki)
1007 sum += (*elem_ki++) * (*--BPtr); // (*BPtr--)
1008 // Faz B[k,j] = (B[k,j] - sum) / A[k,k].
1009 //
1010 // B->PutVal( k, j, (B->GetVal(k, j) - sum) / row_k->pElem[0] );
1011 BPtr = &(*B)(k, j);
1012  *BPtr -= sum;
1013  *BPtr /= fElem[k][0];
1014 }
1015 }
1016 
1017 return(1);
1018 }
1019 
1020  */
1023 //
1024 // Faz Ax = b, onde A e' triangular superior.
1025 //
1026 template <class TVar>
1028 {
1029  // return TSimMatrix::Subst_Backward(B);
1030 
1031  if ((B->Rows() != this->Dim()) || this->fDecomposed != ELU)
1032  TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,
1033  "TPZSkylMatrix::Subst_Backward not decomposed with LU");
1034 
1035  // std::cout << "SubstBackward this " << (void *) this << " neq " << Dim() << " ncols " << B->Cols() << std::endl;
1036 
1037  int64_t Dimension = this->Dim();
1038  if (!Dimension)
1039  return 1; // nothing to do
1040  int64_t j;
1041  for (j = 0; j < B->Cols(); j++)
1042  {
1043  int64_t k = Dimension - 1;
1044  while (k > 0 && (*B)(k, j) == TVar(0.))
1045  {
1046  k--;
1047  }
1048  // std::cout << "kstart " << k << std::endl;
1049 
1050  for (; k > 0; k--)
1051  {
1052  // Faz sum = SOMA( A[k,i] * B[i,j] ), para i = 1, ..., k-1.
1053  //
1054  TVar val;
1055  TVar *elem_ki = fElem[k];
1056  TVar *end_ki = fElem[k + 1];
1057  TVar *BPtr = &(*B)(k, j);
1058  *BPtr /= *elem_ki++;
1059  val = *BPtr;
1060  // BPtr;
1061  // substract the column of the skyline matrix from the vector.
1062  while (elem_ki < end_ki)
1063  * --BPtr -= (*elem_ki++) * val;
1064  }
1065  }
1066  for (j = 0; j < B->Cols(); j++)
1067  (*B)(0, j) /= fElem[0][0];
1068  return(1);
1069 }
1070 
1073 //
1074 // Faz a "Forward substitution" assumindo que os elementos
1075 // da diagonal sao todos iguais a 1.
1076 //
1077 template <class TVar>
1079 {
1080  if ((B->Rows() != this->Dim()) || (this->fDecomposed != ELDLt && this->fDecomposed != ELU))
1081  return(0);
1082 
1083  int64_t dimension = this->Dim();
1084  for (int64_t k = 0; k < dimension; k++)
1085  {
1086  for (int64_t j = 0; j < B->Cols(); j++)
1087  {
1088  // Faz sum = SOMA( A[k,i] * B[i,j] ), para i = 1, ..., k-1.
1089  //
1090  TVar sum = 0.0;
1091  TVar *elem_ki = fElemb[k] + 1;
1092  TVar *end_ki = fElemb[k + 1];
1093  TVar *BPtr = &(*B)(k, j);
1094  while (elem_ki < end_ki)
1095  sum += (*elem_ki++) * (*--BPtr);
1096 
1097  // Faz B[k,j] = (B[k,j] - sum) / A[k,k].
1098  //
1099  // B->PutVal( k, j, (B->GetVal(k, j) - sum) / row_k->pElem[0] );
1100  BPtr = &(*B)(k, j);
1101  *BPtr -= sum;
1102  }
1103  }
1104  return(1);
1105 }
1106 
1109 //
1110 // Faz Ax = b, sendo que A e' assumida ser uma matriz diagonal.
1111 //
1112 
1113 /*
1114 int TPZSkylMatrix::Subst_Diag(TPZFMatrix *B)const
1115 {
1116 if ((B->Rows() != Dim()) || fDecomposed != ELDLt)
1117 return(0);
1118 int dimension = Dim();
1119 for (int j = 0; j < B->Cols(); j++)
1120 {
1121 REAL *BPtr = &(*B)(0, j);
1122 int k = 0;
1123 while (k < dimension)
1124  * BPtr++ /= *(fElem[k++]);
1125 }
1126 return(1);
1127 }
1128 
1129  */
1130 
1133 //
1134 // Faz Ax = b, onde A e' triangular superior.
1135 //
1136 
1137 /*
1138 int TPZSkylMatrix::Subst_LBackward(TPZFMatrix *B)const
1139 {
1140 // return TSimMatrix::Subst_Backward(B);
1141 
1142 if ((B->Rows() != Dim()) || !fDecomposed || fDecomposed == ECholesky)
1143 TPZMatrix::Error(__PRETTY_FUNCTION__,
1144 "TPZSkylMatrix::Subst_LBackward not decomposed properly");
1145 
1146 int Dimension = Dim();
1147 for (int k = Dimension - 1; k > 0; k--)
1148 {
1149 for (int j = 0; j < B->Cols(); j++)
1150 {
1151 // Faz sum = SOMA( A[k,i] * B[i,j] ), para i = 1, ..., k-1.
1152 //
1153 // REAL val = 0.0;
1154 REAL *elem_ki = fElem[k] + 1;
1155 REAL *end_ki = fElem[k + 1];
1156 REAL *BPtr = &(*B)(k, j);
1157 // substract the column of the skyline matrix from the vector.
1158 
1159 REAL val = *BPtr;
1160 while (elem_ki < end_ki)
1161  * --BPtr -= (*elem_ki++) * val;
1162 }
1163 }
1164 return(1);
1165 }
1166 
1167  */
1168 
1174 /*
1175 int TPZSkylMatrix::Zero()
1176 {
1177 
1178 fStorage.Fill(0.);
1179 fDecomposed = 0;
1180 fDefPositive = 0;
1181 return(1);
1182 }
1183 
1184  */
1185 
1188 /* int
1189 // ESTAVA COMENTADO NO SKYLINE SIMETRICO
1190 TPZSkylMatrix::Error(const char *msg1,const char* msg2 )
1191 {
1192 ostringstream out;
1193 out << "TPZSkylMatrix::" << msg1 << msg2 << ".\n";
1194 //pzerror.Show();
1195 LOGPZ_ERROR (logger, out.str().c_str());
1196 DebugStop();
1197 return 0;
1198 }
1199  */
1200 
1203 template <class TVar>
1205 {
1206  fStorage.Resize(0);
1207  fStorageb.Resize(0);
1208  fStorage.Shrink();
1209  fStorageb.Shrink();
1210  fElem.Resize(0);
1211  fElemb.Resize(0);
1212  this->fRow = this->fCol = 0;
1213  this->fDecomposed = 0;
1214  return(1);
1215 }
1216 
1220 template <class TVar>
1222 {
1223  int64_t dimension = A.Dim();
1224  this->fRow = this->fCol = dimension;
1225  fElem.Resize(A.fElem.NElements());
1227  fStorage = A.fStorage;
1228  fStorageb = A.fStorageb;
1229  int64_t i;
1230  TVar *firstp = 0;
1231 
1232  if (fStorage.NElements())
1233  firstp = &fStorage[0];
1234  for (i = 0; i <= dimension; i++)
1235  fElem[i] = firstp + (A.fElem[i] - A.fElem[0]);
1236 
1237  if (fStorageb.NElements())
1238  firstp = &fStorageb[0];
1239  for (i = 0; i <= dimension; i++)
1240  fElemb[i] = firstp + (A.fElemb[i] - A.fElemb[0]);
1241 
1242  this->fDecomposed = A.fDecomposed;
1243  this->fDefPositive = A.fDefPositive;
1244 }
1245 
1246 /*
1247 TPZSkylMatrix TPZSkylMatrix:: operator -()const
1248 {
1249 return operator*(-1.0);
1250 }
1251 
1252  */
1253 
1254 /* OOPAR!
1255 
1256 #ifdef OOPARLIB
1257 
1258 int TPZSkylMatrix::Unpack(TReceiveStorage *buf)
1259 {
1260 TSimMatrix::Unpack(buf);
1261 int rows;
1262 buf->UpkInt(&rows);
1263 Redim(rows, rows);
1264 int sz;
1265 for (int i = 0; i < rows; i++)
1266 {
1267 sz = fDiag[i].size;
1268 buf->UpkInt(&sz);
1269 for (int j = 0; j < sz; j++)
1270 {
1271 buf->UpkDouble(fDiag[i].pElem);
1272 }
1273 }
1274 return 1;
1275 }
1276 
1277 int TPZSkylMatrix::Pack(TSendStorage *buf)
1278 {
1279 TSimMatrix::Pack(buf);
1280 int rows = Rows();
1281 int sz;
1282 for (int i = 0; i < rows; i++)
1283 {
1284 buf->PkInt(&sz);
1285 fDiag[i].size = sz;
1286 fDiag[i].vetSize = sz;
1287 fDiag[i].pElem = new REAL[sz];
1288 for (int j = 0; j < sz; j++)
1289 {
1290 buf->PkDouble(fDiag[i].pElem);
1291 }
1292 }
1293 return 1;
1294 }
1295 
1296 TSaveable *TPZSkylMatrix::Restore(TReceiveStorage *buf)
1297 {
1298 TPZSkylMatrix *m = new TPZSkylMatrix(0);
1299 m->Unpack(buf);
1300 return m;
1301 }
1302 
1303 int TPZSkylMatrix::DerivedFrom(int64_t Classid)
1304 {
1305 return 1;
1306 return TSimMatrix::DerivedFrom(Classid);
1307 }
1308 
1309 int TPZSkylMatrix::DerivedFrom(char *classname)
1310 {
1311 if (!strcmp(ClassName(), classname))
1312 return 1;
1313 return TSimMatrix::DerivedFrom(classname);
1314 }
1315 
1316 #endif
1317  */
1318 
1319 /*
1320 
1321 void TPZSkylMatrix::DecomposeColumn(int col, int prevcol)
1322 {
1323 REAL *ptrprev; // Pointer to prev column
1324 REAL *ptrcol; // Pointer to col column
1325 int skprev, skcol; // prev and col Skyline height respectively
1326 int minline;
1327 
1328 skprev = SkyHeight(prevcol);
1329 skcol = SkyHeight(col);
1330 
1331 ptrprev = Diag(prevcol);
1332 ptrcol = Diag(col);
1333 
1334 if ((prevcol - skprev) > (col - skcol))
1335 {
1336 minline = prevcol - skprev;
1337 }
1338 else
1339 {
1340 minline = col - skcol;
1341 }
1342 if (minline > prevcol)
1343 {
1344 cout << "error condition\n";
1345 cout.flush();
1346 return;
1347 }
1348 REAL *run1 = ptrprev + (prevcol - minline);
1349 REAL *run2 = ptrcol + (col - minline);
1350 REAL sum = 0;
1351 
1352 // while(run1-ptrprev > templatedepth) {
1353 // run1-=templatedepth-1;
1354 // run2-=templatedepth-1;
1355 // sum += TemplateSum<templatedepth>(run1--,run2--);
1356 // }
1357 
1358 
1359 while (run1 != ptrprev)
1360 sum += (*run1--) * (*run2--);
1361  *run2 -= sum;
1362 if (run1 != run2)
1363 {
1364  *run2 /= *run1;
1365 }
1366 else
1367 {
1368  *run2 = sqrt(*run2);
1369 }
1370 
1371 }
1372 
1373  */
1374 
1375 /*
1376 void TPZSkylMatrix::DecomposeColumn(int col, int prevcol,
1377 std::list<int64_t> &singular)
1378 {
1379 REAL *ptrprev; // Pointer to prev column
1380 REAL *ptrcol; // Pointer to col column
1381 int skprev, skcol; // prev and col Skyline height respectively
1382 int minline;
1383 
1384 skprev = SkyHeight(prevcol);
1385 skcol = SkyHeight(col);
1386 
1387 ptrprev = Diag(prevcol);
1388 ptrcol = Diag(col);
1389 
1390 if ((prevcol - skprev) > (col - skcol))
1391 {
1392 minline = prevcol - skprev;
1393 }
1394 else
1395 {
1396 minline = col - skcol;
1397 }
1398 if (minline > prevcol)
1399 {
1400 cout << "error condition\n";
1401 cout.flush();
1402 return;
1403 }
1404 REAL *run1 = ptrprev + (prevcol - minline);
1405 REAL *run2 = ptrcol + (col - minline);
1406 REAL sum = 0;
1407 
1408 // while(run1-ptrprev > templatedepth) {
1409 // run1-=templatedepth-1;
1410 // run2-=templatedepth-1;
1411 // sum += TemplateSum<templatedepth>(run1--,run2--);
1412 // }
1413 
1414 
1415 while (run1 != ptrprev)
1416 sum += (*run1--) * (*run2--);
1417  *run2 -= sum;
1418 if (run1 != run2)
1419 {
1420  *run2 /= *run1;
1421 }
1422 else
1423 {
1424 REAL pivot = *run2;
1425 if (pivot < 1.e-10)
1426 {
1427 #ifdef LOG4CXX
1428 std::stringstream sout;
1429 sout << "equation " << col << " is singular pivot " << pivot;
1430 LOGPZ_WARN(logger, sout.str())
1431 #endif
1432 singular.push_back(col);
1433 pivot = 1.;
1434 }
1435 
1436  *run2 = sqrt(pivot);
1437 }
1438 
1439 }
1440 
1441  */
1442 
1443 /*
1444 
1445 void TPZSkylMatrix::DecomposeColumn2(int col, int prevcol)
1446 {
1447 
1448 // cout << "lcol " << lcol << " with " << lprevcol << endl;
1449 // cout.flush();
1450 // Cholesky Decomposition
1451 REAL *ptrprev; // Pointer to prev column
1452 REAL *ptrcol; // Pointer to col column
1453 int skprev, skcol; // prev and col Skyline height respectively
1454 int minline;
1455 
1456 skprev = SkyHeight(prevcol);
1457 skcol = SkyHeight(col);
1458 
1459 ptrprev = Diag(prevcol);
1460 ptrcol = Diag(col);
1461 
1462 if ((prevcol - skprev) > (col - skcol))
1463 {
1464 minline = prevcol - skprev;
1465 }
1466 else
1467 {
1468 minline = col - skcol;
1469 }
1470 if (minline > prevcol)
1471 {
1472 cout << "error condition\n";
1473 cout.flush();
1474 return;
1475 }
1476 REAL *run1 = ptrprev + 1;
1477 REAL *run2 = ptrcol + (col - prevcol) + 1;
1478 REAL *lastptr = ptrprev + prevcol - minline + 1;
1479 REAL sum = 0;
1480 REAL *modify = ptrcol + (col - prevcol);
1481 #ifndef BLAS
1482 
1483 // while(lastptr-run1 > templatedepth) {
1484 // sum += TemplateSum<templatedepth>(run1,run2);
1485 // run1+=templatedepth;
1486 // run2+=templatedepth;
1487 // }
1488 
1489 
1490 while (run1 != lastptr)
1491 sum += (*run1++) * (*run2++);
1492 
1493 // cout << "col " << col << " prevcol " << prevcol << " sum " << sum << " modify " << *modify << " ptrprev " << *ptrprev;
1494 #else
1495 int n = lastptr - run1;
1496 sum = cblas_ddot(n, run1, 1, run2, 1);
1497 #endif
1498  *modify -= sum;
1499 if (col != prevcol)
1500 {
1501  *modify /= *ptrprev;
1502 }
1503 else
1504 {
1505 if (*modify < 1.e-25)
1506 {
1507 cout <<
1508 "TPZSkylMatrix::DecomposeCholesky a matrix nao e positiva definida"
1509 << *modify << endl;
1510  *modify = 1.e-10;
1511 // return;
1512 }
1513 
1514  *modify = sqrt(*modify);
1515 }
1516 // cout << " modified " << *modify << endl;
1517 // cout.flush();
1518 
1519 }
1520 */
1521 
1522 
1523 template <class TVar>
1524 void TPZSkylNSymMatrix<TVar>::Read(TPZStream &buf, void *context )
1525 {
1526  TPZMatrix<TVar>::Read(buf, context);
1527  buf.Read( fStorage);
1528  buf.Read( fStorage);
1529  TPZVec<int> skyl(this->Rows()+1,0), skyl2(this->Rows()+1,0);
1530  buf.Read( skyl);
1531  buf.Read( skyl2);
1532  TVar *ptr = 0, *ptr2 = 0;
1533  if (this->Rows()) {
1534  ptr = &fStorage[0];
1535  ptr2 = &fStorageb[0];
1536  }
1537  fElem.Resize(this->Rows()+1);
1538  fElemb.Resize(this->Rows()+1);
1539  for (int64_t i=0; i<this->Rows()+1; i++) {
1540  fElem[i] = skyl[i] + ptr;
1541  fElemb[i] = skyl2[i] + ptr2;
1542  }
1543 }
1544 
1545 template <class TVar>
1546 void TPZSkylNSymMatrix<TVar>::Write( TPZStream &buf, int withclassid ) const
1547 {
1548  TPZMatrix<TVar>::Write(buf,withclassid);
1549  buf.Write( fStorage);
1550  buf.Write( fStorageb);
1551  TPZVec<int> skyl(this->Rows()+1,0), skyl2(this->Rows()+1,0);
1552  TVar *ptr = 0, *ptr2 = 0;
1553  if (this->Rows()) {
1554  ptr = &fStorage[0];
1555  ptr2 = &fStorageb[0];
1556  }
1557  for (int64_t i=0; i<this->Rows()+1; i++) {
1558  skyl[i] = fElem[i] - ptr;
1559  skyl2[i] = fElemb[i] - ptr2;
1560  }
1561  buf.Write( skyl);
1562  buf.Write( skyl2);
1563 }
1564 
1566 template <class TVar>
1567 void TPZSkylNSymMatrix<TVar>::AutoFill(int64_t nrow, int64_t ncol, int symmetric) {
1568 
1569  if (nrow != ncol) {
1570  DebugStop();
1571  }
1572  TPZMatrix<TVar>::Resize(nrow,nrow);
1573  // initialize the skyline
1574  TPZManVector<int64_t> skyline(this->Rows());
1575  for (int64_t i=0; i<this->Rows(); i++) {
1576  int randcol = rand()%(i+1);
1577  skyline[i] = randcol;
1578  }
1579  this->SetSkyline(skyline);
1580  int64_t i, j;
1581  TVar val;
1583  for(i=0;i<this->Rows();i++) {
1584  for(j=skyline[i];j<=i ;j++) {
1585  val = ((TVar)rand())/((TVar)RAND_MAX);
1586  if(!PutVal(i,j,val))
1587  {
1588  this->Error("AutoFill (TPZMatrix) failed.");
1589  }
1590  if (symmetric == 0) {
1591  val = ((TVar)rand())/((TVar)RAND_MAX);
1592  }
1593  if(!PutVal(j,i,val))
1594  {
1595  this->Error("AutoFill (TPZMatrix) failed.");
1596  }
1597  }
1598  }
1599  for (i=0; i<this->Rows(); i++)
1600  {
1601  TVar sum = 0.;
1602  for (j=0; j<this->Rows(); j++)
1603  {
1604  sum += this->GetVal(i,j);
1605  }
1607  if(fabs(sum) > fabs(GetVal(i,i))) { // Deve satisfazer: |Aii| > SUM( |Aij| ) sobre j != i
1608  PutVal(i,i,sum+(TVar)1.);
1609  }
1610  // To sure diagonal is not zero.
1611  if(IsZero(sum) && IsZero(GetVal(i,i)))
1612  {
1613  PutVal(i,i,1.);
1614  }
1615  }
1616 }
1617 
1618 
1619 template class TPZSkylNSymMatrix<float>;
1620 template class TPZSkylNSymMatrix<double>;
1621 template class TPZSkylNSymMatrix<long double>;
1622 
1623 template class TPZSkylNSymMatrix<std::complex<float> >;
1626 
1630 
1634 
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
virtual TVar & s(const int64_t row, const int64_t col) override
The operators check on the bounds if the DEBUG variable is defined.
const TVar & GetValB(const int64_t row, const int64_t col) const
Pega o valor abaixo da diagonal (below)
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
TVar & operator()(const int64_t row, const int64_t col)
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
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
int ClassId() const override
Return the id of the matrix defined pzmatrixid.h.
const TVar & GetValSup(const int64_t row, const int64_t col) const
Pega o valor na diagonal ou parte de cima da diagonal.
static int Error(const char *msg, const char *msg2=0)
Returns error messages.
Definition: pzmatrix.cpp:1402
clarg::argInt dimension("-d", "Matrices dimension M x M", 1000)
virtual void MultAdd(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar alpha, const TVar beta, const int opt=0) const override
It computes z = beta * y + alpha * opt(this)*x but z and x can not overlap in memory.
virtual int Resize(const int64_t newRows, const int64_t newCols)
Redimensions a matriz keeping the previous values.
Definition: pzmatrix.h:278
int64_t fRow
Number of rows in matrix.
Definition: pzmatrix.h:779
void PrepareZ(const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar beta, const int opt) const
Is an auxiliar method used by MultiplyAdd.
Definition: pzmatrix.cpp:135
char fDecomposed
Decomposition type used to decompose the current matrix.
Definition: pzmatrix.h:783
void Copy(const TPZSkylNSymMatrix &)
Implements a skyline storage format.
Definition: pzskylnsymmat.h:33
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
int Clear() override
char fDefPositive
Definite Posistiveness of current matrix.
Definition: pzmatrix.h:785
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
static TVar gZero
Initializing value to static variable.
Definition: pzmatrix.h:786
TPZSkylMatrix< REAL > matrix
Definition: numatst.cpp:255
const TVar & GetVal(const int64_t row, const int64_t col) const override
int Decompose_LU() override
TPZManVector< TVar > fStorage
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
Definition: pzvec.h:373
int PutVal(const int64_t row, const int64_t col, const TVar &element) override
void SetSkyline(const TPZVec< int64_t > &skyline)
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
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
Definition: pzmatrix.h:52
static int64_t NumElements(const TPZVec< int64_t > &skyline)
virtual void UpdateFrom(TPZAutoPointer< TPZMatrix< TVar > > mat) override
Updates the values of the matrix based on the values of the matrix.
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
string res
Definition: test.py:151
Contains TPZSkyline class which implements a skyline storage format.
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
Definition: pzmatrix.cpp:1413
static void ComputeMaxSkyline(const TPZSkylNSymMatrix &first, const TPZSkylNSymMatrix &second, TPZVec< int > &res)
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 int64_t Dim() const
Returns the dimension of the matrix if the matrix is square.
Definition: pzmatrix.h:892
void Shrink()
It reallocates storage to fit the necessary storage exactly.
Definition: pzmanvector.h:388
int64_t fCol
Number of cols in matrix.
Definition: pzmatrix.h:781
TPZVec< TVar * > fElem
int Subst_Backward(TPZFMatrix< TVar > *b) const override
TPZVec< TVar * > fElemb
void AutoFill(int64_t nrow, int64_t ncol, int symmetric)
Fill matrix storage with randomic values.
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
void Fill(const T &copy, const int64_t from=0, const int64_t numelem=-1)
Will fill the elements of the vector with a copy object.
Definition: pzvec.h:460
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
int Size(const int64_t column) const
TPZManVector< TVar > fStorageb
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
static void InitializeElem(const TPZVec< int64_t > &skyline, TPZManVector< TVar > &storage, TPZVec< TVar *> &elem)
int Subst_LForward(TPZFMatrix< TVar > *b) const override
TVar & g(const int64_t row, const int64_t col) const
Definition: pzfmatrix.h:594
Implements an interface to register a class id and a restore function. Persistence.
Definition: TPZSavable.h:150
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15
virtual void Read(bool &val)
Definition: TPZStream.cpp:91
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60
This class implements a reference counter mechanism to administer a dynamically allocated object...