24 fNumberOfStencilPointers = 0;
31 cerr <<
"TPZStencilMatrix(int rows,int cols)\n";
38 for(
int i=0; i<fNumberOfStencilPointers; i++)
delete fMystencils[i];
41 fNumberOfStencilPointers = 0;
42 delete fStencilNumbers;
48 cerr <<
"~TPZStencilMatrix()\n";
69 if( whatsthis !=
this || row < ir ) {
71 for( ir=ix=0; ir<row; ir++) {
72 stenindex = fStencilNumbers[ir];
73 st = fMystencils[stenindex];
78 for( ; ir<row; ir++) {
79 stenindex = fStencilNumbers[ir];
80 st = fMystencils[stenindex];
87 st = fMystencils[fStencilNumbers[row]];
94 int numintegers = *ia++;
95 int *ialast = ia+numintegers;
97 if ( ix+(*ia++) == col )
return *a;
114 const TVar alpha,
const TVar beta,
const int opt)
const {
118 int r = (opt) ? Cols() : Rows();
120 TVar *zp = &(z(0,0)), *zlast = zp+r;
121 const TVar *yp = &(y.
GetVal(0,0));
124 memcpy(zp,yp,r*
sizeof(REAL));
127 TVar *zp = &(z(0,0)), *zlast = zp+r;
135 for(
int ir=0; ir<fRows; ir++) {
136 int stenindex = fStencilNumbers[ir];
143 int numintegers = *ia++;
144 int *ialast = ia+numintegers;
147 const TVar *xp = &(x.
GetVal(ix,0));
149 val += *(xp+((*ia++)));
152 z(ir,0) += alpha*val*(*a);
160 for(ir=0; ir<fRows; ir++) {
161 MPStencil *st = fMystencils[fStencilNumbers[ir]];
167 int numintegers = *ia++;
168 int *ialast = ia + numintegers;
169 TVar xval = alpha*x.
GetVal(ir,0)*(*a);
171 z((ix+(*ia++)),0) += xval;
191 out <<
"\nTStencilMatrix Print: " << title <<
'\n' 192 <<
"\tRows = " << fRows <<
'\n' 193 <<
"\tColumns = " << fCols <<
'\n';
195 for(
int ir=0; ir<fNumberOfStencilPointers; ir++) {
201 out <<
"\nStencil " << ir
202 <<
", increment " << st->
fInc <<
", " 203 << nitems <<
" items\n";
208 int numintegers = *ia;
209 out <<
'\t' << *ia++ <<
'\t' << *a <<
'\n';
210 int *ialast = ia+numintegers;
212 out <<
'\t' << *ia++ <<
'\n';
220 if(fStencilNumbers) {
221 out <<
"\nIndex\tStencil number\n";
222 out <<
"-----\t--------------\n";
223 for(
int i=0; i<fRows; i++) {
224 out << i <<
'\t' << fStencilNumbers[i] <<
'\n';
241 fDiag =
new REAL[Rows()];
242 for(
int ir=0; ir<fRows; ir++) {
243 MPStencil *st = fMystencils[fStencilNumbers[ir]];
248 cout <<
"TPZStencilMatrix::ComputeDiagonal " 249 "Computing the diagonal of a nonsquare matrix?";
253 int numintegers = *ia++;
254 int *ialast = ia+numintegers;
271 const TVar overrelax, TVar &
tol,
272 const int FromCurrent,
const int direction ) {
274 if(!fDiag) ComputeDiagonal();
275 int irStart = 0,irLast = fRows,irInc = 1;
281 if(!FromCurrent) x.
Zero();
284 for(iteration=0; iteration<numiterations && eqres >=
tol; iteration++) {
287 while(ir != irLast) {
288 int stenindex = fStencilNumbers[ir];
294 TVar xnewval=rhs.
GetVal(ir,0);
296 int numintegers = *ia++;
297 int *ialast = ia+numintegers;
301 val -= *(xp+(*ia++));
307 eqres += xnewval*xnewval;
308 x(ir,0) += overrelax*(xnewval/fDiag[ir]);
314 numiterations = iteration;
315 if(residual) Residual(x,rhs,*residual);
330 if(stencilnumber < 0)
return;
331 if(stencilnumber >= fNumberOfStencilPointers)
332 IncreaseStencilPointers(stencilnumber);
333 if(fMystencils[stencilnumber])
delete fMystencils[stencilnumber];
334 fMystencils[stencilnumber] =
new MPStencil(inc,IA,A);
339 int newnum = fNumberOfStencilPointers+10;
340 if(newnum < numsten) newnum = numsten+1;
342 memcpy(newptr,fMystencils,
sizeof(
MPStencil *)*fNumberOfStencilPointers);
343 int i=fNumberOfStencilPointers;
344 while(i< newnum) newptr[i++] = 0;
346 fMystencils = newptr;
347 fNumberOfStencilPointers = newnum;
353 if(fStencilNumbers)
delete fStencilNumbers;
354 fStencilNumbers =
new int[fRows];
355 memcpy(fStencilNumbers,stencilnumber,
sizeof(
int)*fRows);
371 fNumberOfItems += *IAPtr +1;
375 fIA =
new int[fNumberOfItems];
376 fA =
new TVar[fNumberOfItems];
377 memcpy(fIA,IA,
sizeof(
int)*fNumberOfItems);
378 memcpy(fA,A,
sizeof(TVar)*fNumberOfItems);
void IncreaseStencilPointers(int stencilnumber)
Implements a sparse matrix defined by a stencil. Matrix.
MPStencil(int inc, int *IA, TVar *A)
MatrixOutputFormat
Defines output format.
Contains TPZStencilMatrix class which implements a sparse matrix defined by a stencil. Purpose: Defines operations on sparse matrices stored by stencils. Solvers: SOR and SSOR.
REAL val(STATE &number)
Returns value of the variable.
void SolveSOR(int &numiterations, const TPZFMatrix< TVar > &rhs, TPZFMatrix< TVar > &x, TPZFMatrix< TVar > *residual, TPZFMatrix< TVar > &scratch, const TVar overrelax, TVar &tol, const int FromCurrent=0, const int direction=1)
int Zero() override
Makes Zero all the elements.
Contains TPZMatrixclass which implements full matrix (using column major representation).
TPZStencilMatrix(int rows, int cols)
sets up the StencilMatrix based on the stencil
virtual const TVar & GetVal(const int row, const int col) const
Get the matrix entry at (row,col) without bound checking.
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
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
computes
Full matrix class. Matrix.
void SetStencil(int stencilnumber, int inc, int *IA, TVar *A)
initiates Stencil number "stencilnumber" with the data
void SetNodeStencils(int *stencilnumber)
associates the given stencil number with each row
virtual void Print(const char *title, std::ostream &out=std::cout, const MatrixOutputFormat form=EFormatted) const
Print the matrix along with a identification title.
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.
virtual ~TPZStencilMatrix()