1 #ifndef lint 2 static char vcid[] = "$Id: matrix.c,v 1.139 1996/02/10 16:04:58 bsmith Exp bsmith $"; 3 #endif 4 5 /* 6 This is where the abstract matrix operations are defined 7 */ 8 9 #include "petsc.h" 10 #include "matimpl.h" /*I "mat.h" I*/ 11 #include "vec/vecimpl.h" 12 #include "pinclude/pviewer.h" 13 #include "draw.h" 14 15 /*@C 16 MatGetReordering - Gets a reordering for a matrix to reduce fill or to 17 improve numerical stability of LU factorization. 18 19 Input Parameters: 20 . mat - the matrix 21 . type - type of reordering, one of the following: 22 $ ORDER_NATURAL - Natural 23 $ ORDER_ND - Nested Dissection 24 $ ORDER_1WD - One-way Dissection 25 $ ORDER_RCM - Reverse Cuthill-McGee 26 $ ORDER_QMD - Quotient Minimum Degree 27 28 Output Parameters: 29 . rperm - row permutation indices 30 . cperm - column permutation indices 31 32 Options Database Keys: 33 To specify the ordering through the options database, use one of 34 the following 35 $ -mat_order natural, -mat_order nd, -mat_order 1wd, 36 $ -mat_order rcm, -mat_order qmd 37 38 Notes: 39 If the column permutations and row permutations are the same, 40 then MatGetReordering() returns 0 in cperm. 41 42 The user can define additional orderings; see MatReorderingRegister(). 43 44 .keywords: matrix, set, ordering, factorization, direct, ILU, LU, 45 fill, reordering, natural, Nested Dissection, 46 One-way Dissection, Cholesky, Reverse Cuthill-McGee, 47 Quotient Minimum Degree 48 49 .seealso: MatGetReorderingTypeFromOptions(), MatReorderingRegister() 50 @*/ 51 int MatGetReordering(Mat mat,MatOrdering type,IS *rperm,IS *cperm) 52 { 53 int ierr; 54 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 55 if (!mat->assembled) SETERRQ(1,"MatGetReordering:Not for unassembled matrix"); 56 57 if (!mat->ops.getreordering) {*rperm = 0; *cperm = 0; return 0;} 58 PLogEventBegin(MAT_GetReordering,mat,0,0,0); 59 ierr = MatGetReorderingTypeFromOptions(0,&type); CHKERRQ(ierr); 60 ierr = (*mat->ops.getreordering)(mat,type,rperm,cperm); CHKERRQ(ierr); 61 PLogEventEnd(MAT_GetReordering,mat,0,0,0); 62 return 0; 63 } 64 65 /*@C 66 MatGetRow - Gets a row of a matrix. You MUST call MatRestoreRow() 67 for each row that you get to ensure that your application does 68 not bleed memory. 69 70 Input Parameters: 71 . mat - the matrix 72 . row - the row to get 73 74 Output Parameters: 75 . ncols - the number of nonzeros in the row 76 . cols - if nonzero, the column numbers 77 . vals - if nonzero, the values 78 79 Notes: 80 This routine is provided for people who need to have direct access 81 to the structure of a matrix. We hope that we provide enough 82 high-level matrix routines that few users will need it. 83 84 For better efficiency, set cols and/or vals to zero if you do not 85 wish to extract these quantities. 86 87 .keywords: matrix, row, get, extract 88 89 .seealso: MatRestoreRow() 90 @*/ 91 int MatGetRow(Mat mat,int row,int *ncols,int **cols,Scalar **vals) 92 { 93 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 94 if (!mat->assembled) SETERRQ(1,"MatGetRow:Not for unassembled matrix"); 95 return (*mat->ops.getrow)(mat,row,ncols,cols,vals); 96 } 97 98 /*@C 99 MatRestoreRow - Frees any temporary space allocated by MatGetRow(). 100 101 Input Parameters: 102 . mat - the matrix 103 . row - the row to get 104 . ncols, cols - the number of nonzeros and their columns 105 . vals - if nonzero the column values 106 107 .keywords: matrix, row, restore 108 109 .seealso: MatGetRow() 110 @*/ 111 int MatRestoreRow(Mat mat,int row,int *ncols,int **cols,Scalar **vals) 112 { 113 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 114 if (!mat->assembled) SETERRQ(1,"MatRestoreRow:Not for unassembled matrix"); 115 if (!mat->ops.restorerow) return 0; 116 return (*mat->ops.restorerow)(mat,row,ncols,cols,vals); 117 } 118 /*@ 119 MatView - Visualizes a matrix object. 120 121 Input Parameters: 122 . mat - the matrix 123 . ptr - visualization context 124 125 Notes: 126 The available visualization contexts include 127 $ STDOUT_VIEWER_SELF - standard output (default) 128 $ STDOUT_VIEWER_WORLD - synchronized standard 129 $ output where only the first processor opens 130 $ the file. All other processors send their 131 $ data to the first processor to print. 132 133 The user can open alternative vistualization contexts with 134 $ ViewerFileOpenASCII() - output to a specified file 135 $ ViewerFileOpenBinary() - output in binary to a 136 $ specified file; corresponding input uses MatLoad() 137 $ DrawOpenX() - output nonzero matrix structure to 138 $ an X window display 139 $ ViewerMatlabOpen() - output matrix to Matlab viewer. 140 $ Currently only the sequential dense and AIJ 141 $ matrix types support the Matlab viewer. 142 143 The user can call ViewerFileSetFormat() to specify the output 144 format of ASCII printed objects (when using STDOUT_VIEWER_SELF, 145 STDOUT_VIEWER_WORLD and ViewerFileOpenASCII). Available formats include 146 $ FILE_FORMAT_DEFAULT - default, prints matrix contents 147 $ FILE_FORMAT_MATLAB - Matlab format 148 $ FILE_FORMAT_IMPL - implementation-specific format 149 $ (which is in many cases the same as the default) 150 $ FILE_FORMAT_INFO - basic information about the matrix 151 $ size and structure (not the matrix entries) 152 $ FILE_FORMAT_INFO_DETAILED - more detailed information about the 153 $ matrix structure 154 155 .keywords: matrix, view, visualize, output, print, write, draw 156 157 .seealso: ViewerFileSetFormat(), ViewerFileOpenASCII(), DrawOpenX(), 158 ViewerMatlabOpen(), ViewerFileOpenBinary(), MatLoad() 159 @*/ 160 int MatView(Mat mat,Viewer ptr) 161 { 162 int format, ierr, rows, cols,nz, nzalloc, mem; 163 FILE *fd; 164 char *cstring; 165 PetscObject vobj = (PetscObject) ptr; 166 167 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 168 if (!mat->assembled) SETERRQ(1,"MatView:Not for unassembled matrix"); 169 170 if (!ptr) { /* so that viewers may be used from debuggers */ 171 ptr = STDOUT_VIEWER_SELF; vobj = (PetscObject) ptr; 172 } 173 ierr = ViewerFileGetFormat_Private(ptr,&format); CHKERRQ(ierr); 174 ierr = ViewerFileGetPointer(ptr,&fd); CHKERRQ(ierr); 175 if (vobj->cookie == VIEWER_COOKIE && 176 (format == FILE_FORMAT_INFO || format == FILE_FORMAT_INFO_DETAILED) && 177 (vobj->type == ASCII_FILE_VIEWER || vobj->type == ASCII_FILES_VIEWER)) { 178 MPIU_fprintf(mat->comm,fd,"Matrix Object:\n"); 179 ierr = MatGetType(mat,PETSC_NULL,&cstring); CHKERRQ(ierr); 180 ierr = MatGetSize(mat,&rows,&cols); CHKERRQ(ierr); 181 MPIU_fprintf(mat->comm,fd," type=%s, rows=%d, cols=%d\n",cstring,rows,cols); 182 if (mat->ops.getinfo) { 183 ierr = MatGetInfo(mat,MAT_GLOBAL_SUM,&nz,&nzalloc,&mem); CHKERRQ(ierr); 184 MPIU_fprintf(mat->comm,fd," total: nonzeros=%d, allocated nonzeros=%d\n",nz,nzalloc); 185 } 186 } 187 if (mat->view) {ierr = (*mat->view)((PetscObject)mat,ptr); CHKERRQ(ierr);} 188 return 0; 189 } 190 /*@C 191 MatDestroy - Frees space taken by a matrix. 192 193 Input Parameter: 194 . mat - the matrix 195 196 .keywords: matrix, destroy 197 @*/ 198 int MatDestroy(Mat mat) 199 { 200 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 201 return (*mat->destroy)((PetscObject)mat); 202 } 203 /*@ 204 MatValidMatrix - Returns 1 if a valid matrix else 0. 205 206 Input Parameter: 207 . m - the matrix to check 208 209 .keywords: matrix, valid 210 @*/ 211 int MatValidMatrix(Mat m) 212 { 213 if (!m) return 0; 214 if (m->cookie != MAT_COOKIE) return 0; 215 return 1; 216 } 217 218 /*@ 219 MatSetValues - Inserts or adds a block of values into a matrix. 220 These values may be cached, so MatAssemblyBegin() and MatAssemblyEnd() 221 MUST be called after all calls to MatSetValues() have been completed. 222 223 Input Parameters: 224 . mat - the matrix 225 . v - a logically two-dimensional array of values 226 . m, indexm - the number of rows and their global indices 227 . n, indexn - the number of columns and their global indices 228 . addv - either ADD_VALUES or INSERT_VALUES, where 229 $ ADD_VALUES - adds values to any existing entries 230 $ INSERT_VALUES - replaces existing entries with new values 231 232 Notes: 233 By default the values, v, are row-oriented and unsorted. 234 See MatSetOptions() for other options. 235 236 Calls to MatSetValues() with the INSERT_VALUES and ADD_VALUES 237 options cannot be mixed without intervening calls to the assembly 238 routines. 239 240 .keywords: matrix, insert, add, set, values 241 242 .seealso: MatSetOptions(), MatAssemblyBegin(), MatAssemblyEnd() 243 @*/ 244 int MatSetValues(Mat mat,int m,int *idxm,int n,int *idxn,Scalar *v, 245 InsertMode addv) 246 { 247 int ierr; 248 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 249 250 if (mat->assembled) { 251 mat->was_assembled = PETSC_TRUE; 252 mat->assembled = PETSC_FALSE; 253 mat->same_nonzero = PETSC_TRUE; 254 } 255 256 PLogEventBegin(MAT_SetValues,mat,0,0,0); 257 ierr = (*mat->ops.setvalues)(mat,m,idxm,n,idxn,v,addv);CHKERRQ(ierr); 258 PLogEventEnd(MAT_SetValues,mat,0,0,0); 259 return 0; 260 } 261 262 /*@ 263 MatGetValues - Gets a block of values from a matrix. 264 265 Input Parameters: 266 . mat - the matrix 267 . v - a logically two-dimensional array for storing the values 268 . m, indexm - the number of rows and their global indices 269 . n, indexn - the number of columns and their global indices 270 271 Notes: 272 The user must allocate space (m*n Scalars) for the values, v. 273 The values, v, are then returned in a row-oriented format, 274 analogous to that used by default in MatSetValues(). 275 276 .keywords: matrix, get, values 277 278 .seealso: MatGetRow(), MatGetSubmatrix(), MatGetSubmatrices(), MatSetValues() 279 @*/ 280 int MatGetValues(Mat mat,int m,int *idxm,int n,int *idxn,Scalar *v) 281 { 282 int ierr; 283 284 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 285 if (!mat->assembled) SETERRQ(1,"MatGetValues:Not for unassembled matrix"); 286 287 PLogEventBegin(MAT_GetValues,mat,0,0,0); 288 ierr = (*mat->ops.getvalues)(mat,m,idxm,n,idxn,v); CHKERRQ(ierr); 289 PLogEventEnd(MAT_GetValues,mat,0,0,0); 290 return 0; 291 } 292 293 /* --------------------------------------------------------*/ 294 /*@ 295 MatMult - Computes matrix-vector product. 296 297 Input Parameters: 298 . mat - the matrix 299 . x - the vector to be multilplied 300 301 Output Parameters: 302 . y - the result 303 304 .keywords: matrix, multiply, matrix-vector product 305 306 .seealso: MatMultTrans(), MatMultAdd(), MatMultTransAdd() 307 @*/ 308 int MatMult(Mat mat,Vec x,Vec y) 309 { 310 int ierr; 311 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 312 PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE);PETSCVALIDHEADERSPECIFIC(y,VEC_COOKIE); 313 if (!mat->assembled) SETERRQ(1,"MatMult:Not for unassembled matrix"); 314 if (x == y) SETERRQ(1,"MatMult:x and y must be different vectors"); 315 316 PLogEventBegin(MAT_Mult,mat,x,y,0); 317 ierr = (*mat->ops.mult)(mat,x,y); CHKERRQ(ierr); 318 PLogEventEnd(MAT_Mult,mat,x,y,0); 319 return 0; 320 } 321 /*@ 322 MatMultTrans - Computes matrix transpose times a vector. 323 324 Input Parameters: 325 . mat - the matrix 326 . x - the vector to be multilplied 327 328 Output Parameters: 329 . y - the result 330 331 .keywords: matrix, multiply, matrix-vector product, transpose 332 333 .seealso: MatMult(), MatMultAdd(), MatMultTransAdd() 334 @*/ 335 int MatMultTrans(Mat mat,Vec x,Vec y) 336 { 337 int ierr; 338 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 339 PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(y,VEC_COOKIE); 340 if (!mat->assembled) SETERRQ(1,"MatMultTrans:Not for unassembled matrix"); 341 if (x == y) SETERRQ(1,"MatMultTrans:x and y must be different vectors"); 342 343 PLogEventBegin(MAT_MultTrans,mat,x,y,0); 344 ierr = (*mat->ops.multtrans)(mat,x,y); CHKERRQ(ierr); 345 PLogEventEnd(MAT_MultTrans,mat,x,y,0); 346 return 0; 347 } 348 /*@ 349 MatMultAdd - Computes v3 = v2 + A * v1. 350 351 Input Parameters: 352 . mat - the matrix 353 . v1, v2 - the vectors 354 355 Output Parameters: 356 . v3 - the result 357 358 .keywords: matrix, multiply, matrix-vector product, add 359 360 .seealso: MatMultTrans(), MatMult(), MatMultTransAdd() 361 @*/ 362 int MatMultAdd(Mat mat,Vec v1,Vec v2,Vec v3) 363 { 364 int ierr; 365 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);PETSCVALIDHEADERSPECIFIC(v1,VEC_COOKIE); 366 PETSCVALIDHEADERSPECIFIC(v2,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(v3,VEC_COOKIE); 367 if (!mat->assembled) SETERRQ(1,"MatMultAdd:Not for unassembled matrix"); 368 369 PLogEventBegin(MAT_MultAdd,mat,v1,v2,v3); 370 if (v1 == v3) SETERRQ(1,"MatMultAdd:v1 and v3 must be different vectors"); 371 ierr = (*mat->ops.multadd)(mat,v1,v2,v3); CHKERRQ(ierr); 372 PLogEventEnd(MAT_MultAdd,mat,v1,v2,v3); 373 return 0; 374 } 375 /*@ 376 MatMultTransAdd - Computes v3 = v2 + A' * v1. 377 378 Input Parameters: 379 . mat - the matrix 380 . v1, v2 - the vectors 381 382 Output Parameters: 383 . v3 - the result 384 385 .keywords: matrix, multiply, matrix-vector product, transpose, add 386 387 .seealso: MatMultTrans(), MatMultAdd(), MatMult() 388 @*/ 389 int MatMultTransAdd(Mat mat,Vec v1,Vec v2,Vec v3) 390 { 391 int ierr; 392 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); PETSCVALIDHEADERSPECIFIC(v1,VEC_COOKIE); 393 PETSCVALIDHEADERSPECIFIC(v2,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(v3,VEC_COOKIE); 394 if (!mat->assembled) SETERRQ(1,"MatMultTransAdd:Not for unassembled matrix"); 395 if (!mat->ops.multtransadd) SETERRQ(PETSC_ERR_SUP,"MatMultTransAdd"); 396 if (v1 == v3) SETERRQ(1,"MatMultTransAdd:v1 and v2 must be different vectors"); 397 398 PLogEventBegin(MAT_MultTransAdd,mat,v1,v2,v3); 399 ierr = (*mat->ops.multtransadd)(mat,v1,v2,v3); CHKERRQ(ierr); 400 PLogEventEnd(MAT_MultTransAdd,mat,v1,v2,v3); 401 return 0; 402 } 403 /* ------------------------------------------------------------*/ 404 /*@ 405 MatGetInfo - Returns information about matrix storage (number of 406 nonzeros, memory). 407 408 Input Parameters: 409 . mat - the matrix 410 411 Output Parameters: 412 . flag - flag indicating the type of parameters to be returned 413 $ flag = MAT_LOCAL: local matrix 414 $ flag = MAT_GLOBAL_MAX: maximum over all processors 415 $ flag = MAT_GLOBAL_SUM: sum over all processors 416 . nz - the number of nonzeros 417 . nzalloc - the number of allocated nonzeros 418 . mem - the memory used (in bytes) 419 420 .keywords: matrix, get, info, storage, nonzeros, memory 421 @*/ 422 int MatGetInfo(Mat mat,MatInfoType flag,int *nz,int *nzalloc,int *mem) 423 { 424 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 425 if (!mat->ops.getinfo) SETERRQ(PETSC_ERR_SUP,"MatGetInfo"); 426 return (*mat->ops.getinfo)(mat,flag,nz,nzalloc,mem); 427 } 428 /* ----------------------------------------------------------*/ 429 /*@ 430 MatLUFactor - Performs in-place LU factorization of matrix. 431 432 Input Parameters: 433 . mat - the matrix 434 . row - row permutation 435 . col - column permutation 436 . f - expected fill as ratio of original fill. 437 438 .keywords: matrix, factor, LU, in-place 439 440 .seealso: MatLUFactorSymbolic(), MatLUFactorNumeric(), MatCholeskyFactor() 441 @*/ 442 int MatLUFactor(Mat mat,IS row,IS col,double f) 443 { 444 int ierr; 445 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 446 if (!mat->ops.lufactor) SETERRQ(PETSC_ERR_SUP,"MatLUFactor"); 447 if (!mat->assembled) SETERRQ(1,"MatLUFactor:Not for unassembled matrix"); 448 449 PLogEventBegin(MAT_LUFactor,mat,row,col,0); 450 ierr = (*mat->ops.lufactor)(mat,row,col,f); CHKERRQ(ierr); 451 PLogEventEnd(MAT_LUFactor,mat,row,col,0); 452 return 0; 453 } 454 /*@ 455 MatILUFactor - Performs in-place ILU factorization of matrix. 456 457 Input Parameters: 458 . mat - the matrix 459 . row - row permutation 460 . col - column permutation 461 . f - expected fill as ratio of original fill. 462 . level - number of levels of fill. 463 464 Note: probably really only in-place when level is zero. 465 .keywords: matrix, factor, ILU, in-place 466 467 .seealso: MatILUFactorSymbolic(), MatLUFactorNumeric(), MatCholeskyFactor() 468 @*/ 469 int MatILUFactor(Mat mat,IS row,IS col,double f,int level) 470 { 471 int ierr; 472 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 473 if (!mat->ops.ilufactor) SETERRQ(PETSC_ERR_SUP,"MatILUFactor"); 474 if (!mat->assembled) SETERRQ(1,"MatILUFactor:Not for unassembled matrix"); 475 476 PLogEventBegin(MAT_ILUFactor,mat,row,col,0); 477 ierr = (*mat->ops.ilufactor)(mat,row,col,f,level); CHKERRQ(ierr); 478 PLogEventEnd(MAT_ILUFactor,mat,row,col,0); 479 return 0; 480 } 481 482 /*@ 483 MatLUFactorSymbolic - Performs symbolic LU factorization of matrix. 484 Call this routine before calling MatLUFactorNumeric(). 485 486 Input Parameters: 487 . mat - the matrix 488 . row, col - row and column permutations 489 . f - expected fill as ratio of the original number of nonzeros, 490 for example 3.0; choosing this parameter well can result in 491 more efficient use of time and space. 492 493 Output Parameter: 494 . fact - new matrix that has been symbolically factored 495 496 Options Database Key: 497 $ -mat_lu_fill <f>, where f is the fill ratio 498 499 Notes: 500 See the file $(PETSC_DIR)/Performace for additional information about 501 choosing the fill factor for better efficiency. 502 503 .keywords: matrix, factor, LU, symbolic, fill 504 505 .seealso: MatLUFactor(), MatLUFactorNumeric(), MatCholeskyFactor() 506 @*/ 507 int MatLUFactorSymbolic(Mat mat,IS row,IS col,double f,Mat *fact) 508 { 509 int ierr,flg; 510 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 511 if (!fact) SETERRQ(1,"MatLUFactorSymbolic:Missing factor matrix argument"); 512 if (!mat->ops.lufactorsymbolic) SETERRQ(PETSC_ERR_SUP,"MatLUFactorSymbolic"); 513 if (!mat->assembled) SETERRQ(1,"MatLUFactorSymbolic:Not for unassembled matrix"); 514 515 ierr = OptionsGetDouble(PETSC_NULL,"-mat_lu_fill",&f,&flg); CHKERRQ(ierr); 516 PLogEventBegin(MAT_LUFactorSymbolic,mat,row,col,0); 517 ierr = (*mat->ops.lufactorsymbolic)(mat,row,col,f,fact); CHKERRQ(ierr); 518 PLogEventEnd(MAT_LUFactorSymbolic,mat,row,col,0); 519 return 0; 520 } 521 /*@ 522 MatLUFactorNumeric - Performs numeric LU factorization of a matrix. 523 Call this routine after first calling MatLUFactorSymbolic(). 524 525 Input Parameters: 526 . mat - the matrix 527 . row, col - row and column permutations 528 529 Output Parameters: 530 . fact - symbolically factored matrix that must have been generated 531 by MatLUFactorSymbolic() 532 533 Notes: 534 See MatLUFactor() for in-place factorization. See 535 MatCholeskyFactorNumeric() for the symmetric, positive definite case. 536 537 .keywords: matrix, factor, LU, numeric 538 539 .seealso: MatLUFactorSymbolic(), MatLUFactor(), MatCholeskyFactor() 540 @*/ 541 int MatLUFactorNumeric(Mat mat,Mat *fact) 542 { 543 int ierr,flg; 544 545 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 546 if (!fact) SETERRQ(1,"MatLUFactorNumeric:Missing factor matrix argument"); 547 if (!mat->ops.lufactornumeric) SETERRQ(PETSC_ERR_SUP,"MatLUFactorNumeric"); 548 if (!mat->assembled) SETERRQ(1,"MatLUFactorNumeric:Not for unassembled matrix"); 549 550 PLogEventBegin(MAT_LUFactorNumeric,mat,*fact,0,0); 551 ierr = (*mat->ops.lufactornumeric)(mat,fact); CHKERRQ(ierr); 552 PLogEventEnd(MAT_LUFactorNumeric,mat,*fact,0,0); 553 ierr = OptionsHasName(PETSC_NULL,"-mat_view_draw",&flg); CHKERRQ(ierr); 554 if (flg) { 555 Draw win; 556 ierr = DrawOpenX((*fact)->comm,0,0,0,0,300,300,&win); CHKERRQ(ierr); 557 ierr = MatView(*fact,(Viewer)win); CHKERRQ(ierr); 558 ierr = DrawSyncFlush(win); CHKERRQ(ierr); 559 ierr = DrawDestroy(win); CHKERRQ(ierr); 560 } 561 return 0; 562 } 563 /*@ 564 MatCholeskyFactor - Performs in-place Cholesky factorization of a 565 symmetric matrix. 566 567 Input Parameters: 568 . mat - the matrix 569 . perm - row and column permutations 570 . f - expected fill as ratio of original fill 571 572 Notes: 573 See MatLUFactor() for the nonsymmetric case. See also 574 MatCholeskyFactorSymbolic(), and MatCholeskyFactorNumeric(). 575 576 .keywords: matrix, factor, in-place, Cholesky 577 578 .seealso: MatLUFactor(), MatCholeskyFactorSymbolic(), MatCholeskyFactorNumeric() 579 @*/ 580 int MatCholeskyFactor(Mat mat,IS perm,double f) 581 { 582 int ierr; 583 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 584 if (!mat->ops.choleskyfactor) SETERRQ(PETSC_ERR_SUP,"MatCholeskyFactor"); 585 if (!mat->assembled) SETERRQ(1,"MatCholeskyFactor:Not for unassembled matrix"); 586 587 PLogEventBegin(MAT_CholeskyFactor,mat,perm,0,0); 588 ierr = (*mat->ops.choleskyfactor)(mat,perm,f); CHKERRQ(ierr); 589 PLogEventEnd(MAT_CholeskyFactor,mat,perm,0,0); 590 return 0; 591 } 592 /*@ 593 MatCholeskyFactorSymbolic - Performs symbolic Cholesky factorization 594 of a symmetric matrix. 595 596 Input Parameters: 597 . mat - the matrix 598 . perm - row and column permutations 599 . f - expected fill as ratio of original 600 601 Output Parameter: 602 . fact - the factored matrix 603 604 Notes: 605 See MatLUFactorSymbolic() for the nonsymmetric case. See also 606 MatCholeskyFactor() and MatCholeskyFactorNumeric(). 607 608 .keywords: matrix, factor, factorization, symbolic, Cholesky 609 610 .seealso: MatLUFactorSymbolic(), MatCholeskyFactor(), MatCholeskyFactorNumeric() 611 @*/ 612 int MatCholeskyFactorSymbolic(Mat mat,IS perm,double f,Mat *fact) 613 { 614 int ierr; 615 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 616 if (!fact) SETERRQ(1,"MatCholeskyFactorSymbolic:Missing factor matrix argument"); 617 if (!mat->ops.choleskyfactorsymbolic)SETERRQ(PETSC_ERR_SUP,"MatCholeskyFactorSymbolic"); 618 if (!mat->assembled) SETERRQ(1,"MatCholeskyFactorSymbolic:Not for unassembled matrix"); 619 620 PLogEventBegin(MAT_CholeskyFactorSymbolic,mat,perm,0,0); 621 ierr = (*mat->ops.choleskyfactorsymbolic)(mat,perm,f,fact); CHKERRQ(ierr); 622 PLogEventEnd(MAT_CholeskyFactorSymbolic,mat,perm,0,0); 623 return 0; 624 } 625 /*@ 626 MatCholeskyFactorNumeric - Performs numeric Cholesky factorization 627 of a symmetric matrix. Call this routine after first calling 628 MatCholeskyFactorSymbolic(). 629 630 Input Parameter: 631 . mat - the initial matrix 632 633 Output Parameter: 634 . fact - the factored matrix 635 636 .keywords: matrix, factor, numeric, Cholesky 637 638 .seealso: MatCholeskyFactorSymbolic(), MatCholeskyFactor(), MatLUFactorNumeric() 639 @*/ 640 int MatCholeskyFactorNumeric(Mat mat,Mat *fact) 641 { 642 int ierr; 643 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 644 if (!fact) SETERRQ(1,"MatCholeskyFactorNumeric:Missing factor matrix argument"); 645 if (!mat->ops.choleskyfactornumeric) SETERRQ(PETSC_ERR_SUP,"MatCholeskyFactorNumeric"); 646 if (!mat->assembled) SETERRQ(1,"MatCholeskyFactorNumeric:Not for unassembled matrix"); 647 648 PLogEventBegin(MAT_CholeskyFactorNumeric,mat,*fact,0,0); 649 ierr = (*mat->ops.choleskyfactornumeric)(mat,fact); CHKERRQ(ierr); 650 PLogEventEnd(MAT_CholeskyFactorNumeric,mat,*fact,0,0); 651 return 0; 652 } 653 /* ----------------------------------------------------------------*/ 654 /*@ 655 MatSolve - Solves A x = b, given a factored matrix. 656 657 Input Parameters: 658 . mat - the factored matrix 659 . b - the right-hand-side vector 660 661 Output Parameter: 662 . x - the result vector 663 664 .keywords: matrix, linear system, solve, LU, Cholesky, triangular solve 665 666 .seealso: MatSolveAdd(), MatSolveTrans(), MatSolveTransAdd() 667 @*/ 668 int MatSolve(Mat mat,Vec b,Vec x) 669 { 670 int ierr; 671 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 672 PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE); 673 if (x == b) SETERRQ(1,"MatSolve:x and y must be different vectors"); 674 if (!mat->factor) SETERRQ(1,"MatSolve:Unfactored matrix"); 675 676 if (!mat->ops.solve) SETERRQ(PETSC_ERR_SUP,"MatSolve"); 677 PLogEventBegin(MAT_Solve,mat,b,x,0); 678 ierr = (*mat->ops.solve)(mat,b,x); CHKERRQ(ierr); 679 PLogEventEnd(MAT_Solve,mat,b,x,0); 680 return 0; 681 } 682 683 /* @ 684 MatForwardSolve - Solves L x = b, given a factored matrix, A = LU. 685 686 Input Parameters: 687 . mat - the factored matrix 688 . b - the right-hand-side vector 689 690 Output Parameter: 691 . x - the result vector 692 693 Notes: 694 MatSolve() should be used for most applications, as it performs 695 a forward solve followed by a backward solve. 696 697 .keywords: matrix, forward, LU, Cholesky, triangular solve 698 699 .seealso: MatSolve(), MatBackwardSolve() 700 @ */ 701 int MatForwardSolve(Mat mat,Vec b,Vec x) 702 { 703 int ierr; 704 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 705 PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE); 706 if (x == b) SETERRQ(1,"MatForwardSolve:x and y must be different vectors"); 707 if (!mat->factor) SETERRQ(1,"MatForwardSolve:Unfactored matrix"); 708 if (!mat->ops.forwardsolve) SETERRQ(PETSC_ERR_SUP,"MatForwardSolve"); 709 710 PLogEventBegin(MAT_ForwardSolve,mat,b,x,0); 711 ierr = (*mat->ops.forwardsolve)(mat,b,x); CHKERRQ(ierr); 712 PLogEventEnd(MAT_ForwardSolve,mat,b,x,0); 713 return 0; 714 } 715 716 /* @ 717 MatBackwardSolve - Solves U x = b, given a factored matrix, A = LU. 718 719 Input Parameters: 720 . mat - the factored matrix 721 . b - the right-hand-side vector 722 723 Output Parameter: 724 . x - the result vector 725 726 Notes: 727 MatSolve() should be used for most applications, as it performs 728 a forward solve followed by a backward solve. 729 730 .keywords: matrix, backward, LU, Cholesky, triangular solve 731 732 .seealso: MatSolve(), MatForwardSolve() 733 @ */ 734 int MatBackwardSolve(Mat mat,Vec b,Vec x) 735 { 736 int ierr; 737 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 738 PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE); 739 if (x == b) SETERRQ(1,"MatBackwardSolve:x and b must be different vectors"); 740 if (!mat->factor) SETERRQ(1,"MatBackwardSolve:Unfactored matrix"); 741 if (!mat->ops.backwardsolve) SETERRQ(PETSC_ERR_SUP,"MatBackwardSolve"); 742 743 PLogEventBegin(MAT_BackwardSolve,mat,b,x,0); 744 ierr = (*mat->ops.backwardsolve)(mat,b,x); CHKERRQ(ierr); 745 PLogEventEnd(MAT_BackwardSolve,mat,b,x,0); 746 return 0; 747 } 748 749 /*@ 750 MatSolveAdd - Computes x = y + inv(A)*b, given a factored matrix. 751 752 Input Parameters: 753 . mat - the factored matrix 754 . b - the right-hand-side vector 755 . y - the vector to be added to 756 757 Output Parameter: 758 . x - the result vector 759 760 .keywords: matrix, linear system, solve, LU, Cholesky, add 761 762 .seealso: MatSolve(), MatSolveTrans(), MatSolveTransAdd() 763 @*/ 764 int MatSolveAdd(Mat mat,Vec b,Vec y,Vec x) 765 { 766 Scalar one = 1.0; 767 Vec tmp; 768 int ierr; 769 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);PETSCVALIDHEADERSPECIFIC(y,VEC_COOKIE); 770 PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE); 771 if (x == b) SETERRQ(1,"MatSolveAdd:x and b must be different vectors"); 772 if (!mat->factor) SETERRQ(1,"MatSolveAdd:Unfactored matrix"); 773 774 PLogEventBegin(MAT_SolveAdd,mat,b,x,y); 775 if (mat->ops.solveadd) { 776 ierr = (*mat->ops.solveadd)(mat,b,y,x); CHKERRQ(ierr); 777 } 778 else { 779 /* do the solve then the add manually */ 780 if (x != y) { 781 ierr = MatSolve(mat,b,x); CHKERRQ(ierr); 782 ierr = VecAXPY(&one,y,x); CHKERRQ(ierr); 783 } 784 else { 785 ierr = VecDuplicate(x,&tmp); CHKERRQ(ierr); 786 PLogObjectParent(mat,tmp); 787 ierr = VecCopy(x,tmp); CHKERRQ(ierr); 788 ierr = MatSolve(mat,b,x); CHKERRQ(ierr); 789 ierr = VecAXPY(&one,tmp,x); CHKERRQ(ierr); 790 ierr = VecDestroy(tmp); CHKERRQ(ierr); 791 } 792 } 793 PLogEventEnd(MAT_SolveAdd,mat,b,x,y); 794 return 0; 795 } 796 /*@ 797 MatSolveTrans - Solves A' x = b, given a factored matrix. 798 799 Input Parameters: 800 . mat - the factored matrix 801 . b - the right-hand-side vector 802 803 Output Parameter: 804 . x - the result vector 805 806 .keywords: matrix, linear system, solve, LU, Cholesky, transpose 807 808 .seealso: MatSolve(), MatSolveAdd(), MatSolveTransAdd() 809 @*/ 810 int MatSolveTrans(Mat mat,Vec b,Vec x) 811 { 812 int ierr; 813 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 814 PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE); 815 if (!mat->factor) SETERRQ(1,"MatSolveTrans:Unfactored matrix"); 816 if (x == b) SETERRQ(1,"MatSolveTrans:x and b must be different vectors"); 817 if (!mat->ops.solvetrans) SETERRQ(PETSC_ERR_SUP,"MatSolveTrans"); 818 819 PLogEventBegin(MAT_SolveTrans,mat,b,x,0); 820 ierr = (*mat->ops.solvetrans)(mat,b,x); CHKERRQ(ierr); 821 PLogEventEnd(MAT_SolveTrans,mat,b,x,0); 822 return 0; 823 } 824 /*@ 825 MatSolveTransAdd - Computes x = y + inv(trans(A)) b, given a 826 factored matrix. 827 828 Input Parameters: 829 . mat - the factored matrix 830 . b - the right-hand-side vector 831 . y - the vector to be added to 832 833 Output Parameter: 834 . x - the result vector 835 836 .keywords: matrix, linear system, solve, LU, Cholesky, transpose, add 837 838 .seealso: MatSolve(), MatSolveAdd(), MatSolveTrans() 839 @*/ 840 int MatSolveTransAdd(Mat mat,Vec b,Vec y,Vec x) 841 { 842 Scalar one = 1.0; 843 int ierr; 844 Vec tmp; 845 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);PETSCVALIDHEADERSPECIFIC(y,VEC_COOKIE); 846 PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE); 847 if (x == b) SETERRQ(1,"MatSolveTransAdd:x and b must be different vectors"); 848 if (!mat->factor) SETERRQ(1,"MatSolveTransAdd:Unfactored matrix"); 849 850 PLogEventBegin(MAT_SolveTransAdd,mat,b,x,y); 851 if (mat->ops.solvetransadd) { 852 ierr = (*mat->ops.solvetransadd)(mat,b,y,x); CHKERRQ(ierr); 853 } 854 else { 855 /* do the solve then the add manually */ 856 if (x != y) { 857 ierr = MatSolveTrans(mat,b,x); CHKERRQ(ierr); 858 ierr = VecAXPY(&one,y,x); CHKERRQ(ierr); 859 } 860 else { 861 ierr = VecDuplicate(x,&tmp); CHKERRQ(ierr); 862 PLogObjectParent(mat,tmp); 863 ierr = VecCopy(x,tmp); CHKERRQ(ierr); 864 ierr = MatSolveTrans(mat,b,x); CHKERRQ(ierr); 865 ierr = VecAXPY(&one,tmp,x); CHKERRQ(ierr); 866 ierr = VecDestroy(tmp); CHKERRQ(ierr); 867 } 868 } 869 PLogEventEnd(MAT_SolveTransAdd,mat,b,x,y); 870 return 0; 871 } 872 /* ----------------------------------------------------------------*/ 873 874 /*@ 875 MatRelax - Computes one relaxation sweep. 876 877 Input Parameters: 878 . mat - the matrix 879 . b - the right hand side 880 . omega - the relaxation factor 881 . flag - flag indicating the type of SOR, one of 882 $ SOR_FORWARD_SWEEP 883 $ SOR_BACKWARD_SWEEP 884 $ SOR_SYMMETRIC_SWEEP (SSOR method) 885 $ SOR_LOCAL_FORWARD_SWEEP 886 $ SOR_LOCAL_BACKWARD_SWEEP 887 $ SOR_LOCAL_SYMMETRIC_SWEEP (local SSOR) 888 $ SOR_APPLY_UPPER, SOR_APPLY_LOWER - applies 889 $ upper/lower triangular part of matrix to 890 $ vector (with omega) 891 $ SOR_ZERO_INITIAL_GUESS - zero initial guess 892 . shift - diagonal shift 893 . its - the number of iterations 894 895 Output Parameters: 896 . x - the solution (can contain an initial guess) 897 898 Notes: 899 SOR_LOCAL_FORWARD_SWEEP, SOR_LOCAL_BACKWARD_SWEEP, and 900 SOR_LOCAL_SYMMETRIC_SWEEP perform seperate independent smoothings 901 on each processor. 902 903 Application programmers will not generally use MatRelax() directly, 904 but instead will employ the SLES/PC interface. 905 906 Notes for Advanced Users: 907 The flags are implemented as bitwise inclusive or operations. 908 For example, use (SOR_ZERO_INITIAL_GUESS | SOR_SYMMETRIC_SWEEP) 909 to specify a zero initial guess for SSOR. 910 911 .keywords: matrix, relax, relaxation, sweep 912 @*/ 913 int MatRelax(Mat mat,Vec b,double omega,MatSORType flag,double shift, 914 int its,Vec x) 915 { 916 int ierr; 917 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 918 PETSCVALIDHEADERSPECIFIC(b,VEC_COOKIE); PETSCVALIDHEADERSPECIFIC(x,VEC_COOKIE); 919 if (!mat->ops.relax) SETERRQ(PETSC_ERR_SUP,"MatRelax"); 920 if (!mat->assembled) SETERRQ(1,"MatRelax:Not for unassembled matrix"); 921 922 PLogEventBegin(MAT_Relax,mat,b,x,0); 923 ierr =(*mat->ops.relax)(mat,b,omega,flag,shift,its,x); CHKERRQ(ierr); 924 PLogEventEnd(MAT_Relax,mat,b,x,0); 925 return 0; 926 } 927 928 /* 929 Default matrix copy routine. 930 */ 931 int MatCopy_Basic(Mat A,Mat B) 932 { 933 int ierr,i,rstart,rend,nz,*cwork; 934 Scalar *vwork; 935 936 ierr = MatZeroEntries(B); CHKERRQ(ierr); 937 ierr = MatGetOwnershipRange(A,&rstart,&rend); CHKERRQ(ierr); 938 for (i=rstart; i<rend; i++) { 939 ierr = MatGetRow(A,i,&nz,&cwork,&vwork); CHKERRQ(ierr); 940 ierr = MatSetValues(B,1,&i,nz,cwork,vwork,INSERT_VALUES); CHKERRQ(ierr); 941 ierr = MatRestoreRow(A,i,&nz,&cwork,&vwork); CHKERRQ(ierr); 942 } 943 ierr = MatAssemblyBegin(B,FINAL_ASSEMBLY); CHKERRQ(ierr); 944 ierr = MatAssemblyEnd(B,FINAL_ASSEMBLY); CHKERRQ(ierr); 945 return 0; 946 } 947 948 /*@C 949 MatCopy - Copys a matrix to another matrix. 950 951 Input Parameters: 952 . A - the matrix 953 954 Output Parameter: 955 . B - where the copy is put 956 957 Notes: 958 MatCopy() copies the matrix entries of a matrix to another existing 959 matrix (after first zeroing the second matrix). A related routine is 960 MatConvert(), which first creates a new matrix and then copies the data. 961 962 .keywords: matrix, copy, convert 963 964 .seealso: MatConvert() 965 @*/ 966 int MatCopy(Mat A,Mat B) 967 { 968 int ierr; 969 PETSCVALIDHEADERSPECIFIC(A,MAT_COOKIE);PETSCVALIDHEADERSPECIFIC(B,MAT_COOKIE); 970 if (!A->assembled) SETERRQ(1,"MatCopy:Not for unassembled matrix"); 971 972 PLogEventBegin(MAT_Copy,A,B,0,0); 973 if (A->ops.copy) { 974 ierr = (*A->ops.copy)(A,B); CHKERRQ(ierr); 975 } 976 else { /* generic conversion */ 977 ierr = MatCopy_Basic(A,B); CHKERRQ(ierr); 978 } 979 PLogEventEnd(MAT_Copy,A,B,0,0); 980 return 0; 981 } 982 983 /*@C 984 MatConvert - Converts a matrix to another matrix, either of the same 985 or different type. 986 987 Input Parameters: 988 . mat - the matrix 989 . newtype - new matrix type. Use MATSAME to create a new matrix of the 990 same type as the original matrix. 991 992 Output Parameter: 993 . M - pointer to place new matrix 994 995 Notes: 996 MatConvert() first creates a new matrix and then copies the data from 997 the first matrix. A related routine is MatCopy(), which copies the matrix 998 entries of one matrix to another already existing matrix context. 999 1000 .keywords: matrix, copy, convert 1001 1002 .seealso: MatCopy() 1003 @*/ 1004 int MatConvert(Mat mat,MatType newtype,Mat *M) 1005 { 1006 int ierr; 1007 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1008 if (!M) SETERRQ(1,"MatConvert:Bad new matrix address"); 1009 if (!mat->assembled) SETERRQ(1,"MatConvert:Not for unassembled matrix"); 1010 1011 PLogEventBegin(MAT_Convert,mat,0,0,0); 1012 if (newtype == mat->type || newtype == MATSAME) { 1013 if (mat->ops.convertsametype) { /* customized copy */ 1014 ierr = (*mat->ops.convertsametype)(mat,M,COPY_VALUES); CHKERRQ(ierr); 1015 } 1016 } 1017 else if (mat->ops.convert) { /* customized conversion */ 1018 ierr = (*mat->ops.convert)(mat,newtype,M); CHKERRQ(ierr); 1019 } 1020 else { /* generic conversion */ 1021 ierr = MatConvert_Basic(mat,newtype,M); CHKERRQ(ierr); 1022 } 1023 PLogEventEnd(MAT_Convert,mat,0,0,0); 1024 return 0; 1025 } 1026 1027 /*@ 1028 MatGetDiagonal - Gets the diagonal of a matrix. 1029 1030 Input Parameters: 1031 . mat - the matrix 1032 1033 Output Parameters: 1034 . v - the vector for storing the diagonal 1035 1036 .keywords: matrix, get, diagonal 1037 @*/ 1038 int MatGetDiagonal(Mat mat,Vec v) 1039 { 1040 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE);PETSCVALIDHEADERSPECIFIC(v,VEC_COOKIE); 1041 if (!mat->assembled) SETERRQ(1,"MatGetDiagonal:Not for unassembled matrix"); 1042 if (mat->ops.getdiagonal) return (*mat->ops.getdiagonal)(mat,v); 1043 SETERRQ(PETSC_ERR_SUP,"MatGetDiagonal"); 1044 } 1045 1046 /*@C 1047 MatTranspose - Computes an in-place or out-of-place transpose of a matrix. 1048 1049 Input Parameters: 1050 . mat - the matrix to transpose 1051 1052 Output Parameters: 1053 . B - the transpose (or pass in PETSC_NULL for an in-place transpose) 1054 1055 .keywords: matrix, transpose 1056 @*/ 1057 int MatTranspose(Mat mat,Mat *B) 1058 { 1059 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1060 if (!mat->assembled) SETERRQ(1,"MatTranspose:Not for unassembled matrix"); 1061 if (mat->ops.transpose) return (*mat->ops.transpose)(mat,B); 1062 SETERRQ(PETSC_ERR_SUP,"MatTranspose"); 1063 } 1064 1065 /*@ 1066 MatEqual - Compares two matrices. Returns 1 if two matrices are equal. 1067 1068 Input Parameters: 1069 . mat1 - the first matrix 1070 . mat2 - the second matrix 1071 1072 Returns: 1073 Returns 1 if the matrices are equal; returns 0 otherwise. 1074 1075 .keywords: matrix, equal, equivalent 1076 @*/ 1077 int MatEqual(Mat mat1,Mat mat2) 1078 { 1079 PETSCVALIDHEADERSPECIFIC(mat1,MAT_COOKIE); PETSCVALIDHEADERSPECIFIC(mat2,MAT_COOKIE); 1080 if (!mat1->assembled) SETERRQ(1,"MatEqual:Not for unassembled matrix"); 1081 if (!mat2->assembled) SETERRQ(1,"MatEqual:Not for unassembled matrix"); 1082 if (mat1->ops.equal) return (*mat1->ops.equal)(mat1,mat2); 1083 SETERRQ(PETSC_ERR_SUP,"MatEqual"); 1084 } 1085 1086 /*@ 1087 MatDiagonalScale - Scales a matrix on the left and right by diagonal 1088 matrices that are stored as vectors. Either of the two scaling 1089 matrices can be null. 1090 1091 Input Parameters: 1092 . mat - the matrix to be scaled 1093 . l - the left scaling vector 1094 . r - the right scaling vector 1095 1096 .keywords: matrix, scale 1097 @*/ 1098 int MatDiagonalScale(Mat mat,Vec l,Vec r) 1099 { 1100 int ierr; 1101 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1102 if (!mat->ops.scale) SETERRQ(PETSC_ERR_SUP,"MatDiagonalScale"); 1103 if (l) PETSCVALIDHEADERSPECIFIC(l,VEC_COOKIE); 1104 if (r) PETSCVALIDHEADERSPECIFIC(r,VEC_COOKIE); 1105 if (!mat->assembled) SETERRQ(1,"MatDiagonalScale:Not for unassembled matrix"); 1106 1107 PLogEventBegin(MAT_Scale,mat,0,0,0); 1108 ierr = (*mat->ops.diagonalscale)(mat,l,r); CHKERRQ(ierr); 1109 PLogEventEnd(MAT_Scale,mat,0,0,0); 1110 return 0; 1111 } 1112 1113 /*@ 1114 MatScale - Scales a matrix by a number. 1115 1116 Input Parameters: 1117 . mat - the matrix to be scaled 1118 . a - the number 1119 1120 Note: the name of this routine MUST change. 1121 .keywords: matrix, scale 1122 @*/ 1123 int MatScale(Scalar *a,Mat mat) 1124 { 1125 int ierr; 1126 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1127 if (!mat->ops.scale) SETERRQ(PETSC_ERR_SUP,"MatScale"); 1128 if (!mat->assembled) SETERRQ(1,"MatScale:Not for unassembled matrix"); 1129 1130 PLogEventBegin(MAT_Scale,mat,0,0,0); 1131 ierr = (*mat->ops.scale)(a,mat); CHKERRQ(ierr); 1132 PLogEventEnd(MAT_Scale,mat,0,0,0); 1133 return 0; 1134 } 1135 1136 /*@ 1137 MatNorm - Calculates various norms of a matrix. 1138 1139 Input Parameters: 1140 . mat - the matrix 1141 . type - the type of norm, NORM_1, NORM_2, NORM_FROBENIUS, NORM_INFINITY 1142 1143 Output Parameters: 1144 . norm - the resulting norm 1145 1146 .keywords: matrix, norm, Frobenius 1147 @*/ 1148 int MatNorm(Mat mat,NormType type,double *norm) 1149 { 1150 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1151 if (!norm) SETERRQ(1,"MatNorm:bad addess for value"); 1152 if (!mat->assembled) SETERRQ(1,"MatNorm:Not for unassembled matrix"); 1153 if (mat->ops.norm) return (*mat->ops.norm)(mat,type,norm); 1154 SETERRQ(PETSC_ERR_SUP,"MatNorm:Not for this matrix type"); 1155 } 1156 1157 /*@ 1158 MatAssemblyBegin - Begins assembling the matrix. This routine should 1159 be called after completing all calls to MatSetValues(). 1160 1161 Input Parameters: 1162 . mat - the matrix 1163 . type - type of assembly, either FLUSH_ASSEMBLY or FINAL_ASSEMBLY 1164 1165 Notes: 1166 MatSetValues() generally caches the values. The matrix is ready to 1167 use only after MatAssemblyBegin() and MatAssemblyEnd() have been called. 1168 Use FLUSH_ASSEMBLY when switching between ADD_VALUES and SetValues; use 1169 FINAL_ASSEMBLY for the final assembly before the matrix is used. 1170 1171 .keywords: matrix, assembly, assemble, begin 1172 1173 .seealso: MatAssemblyEnd(), MatSetValues() 1174 @*/ 1175 int MatAssemblyBegin(Mat mat,MatAssemblyType type) 1176 { 1177 int ierr; 1178 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1179 PLogEventBegin(MAT_AssemblyBegin,mat,0,0,0); 1180 if (mat->ops.assemblybegin){ierr = (*mat->ops.assemblybegin)(mat,type);CHKERRQ(ierr);} 1181 PLogEventEnd(MAT_AssemblyBegin,mat,0,0,0); 1182 return 0; 1183 } 1184 1185 /*@ 1186 MatAssemblyEnd - Completes assembling the matrix. This routine should 1187 be called after all calls to MatSetValues() and after MatAssemblyBegin(). 1188 1189 Input Parameters: 1190 . mat - the matrix 1191 . type - type of assembly, either FLUSH_ASSEMBLY or FINAL_ASSEMBLY 1192 1193 Options Database Keys: 1194 $ -mat_view_draw : Draw nonzero structure of matrix at conclusion of MatEndAssembly(), 1195 using MatView() and DrawOpenX(). 1196 $ -mat_view_info : Prints info on matrix. 1197 $ -mat_view_info_detailed: More detailed information. 1198 $ -mat_view : Prints matrix out in ascii. 1199 $ -mat_view_matlab : Prints matrix out suitable for Matlab(TM). 1200 $ -display <name> : Set display name (default is host) 1201 $ -draw_pause <sec> : Set number of seconds to pause after display 1202 1203 Note: 1204 MatSetValues() generally caches the values. The matrix is ready to 1205 use only after MatAssemblyBegin() and MatAssemblyEnd() have been called. 1206 Use FLUSH_ASSEMBLY when switching between ADD_VALUES and SetValues; use 1207 FINAL_ASSEMBLY for the final assembly before the matrix is used. 1208 1209 .keywords: matrix, assembly, assemble, end 1210 1211 .seealso: MatAssemblyBegin(), MatSetValues() 1212 @*/ 1213 int MatAssemblyEnd(Mat mat,MatAssemblyType type) 1214 { 1215 int ierr,flg; 1216 static int inassm = 0; 1217 1218 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1219 inassm++; 1220 PLogEventBegin(MAT_AssemblyEnd,mat,0,0,0); 1221 if (mat->ops.assemblyend) {ierr = (*mat->ops.assemblyend)(mat,type); CHKERRQ(ierr);} 1222 mat->assembled = PETSC_TRUE; mat->num_ass++; 1223 PLogEventEnd(MAT_AssemblyEnd,mat,0,0,0); 1224 1225 if (inassm == 1) { 1226 ierr = OptionsHasName(PETSC_NULL,"-mat_view_info",&flg); CHKERRQ(ierr); 1227 if (flg) { 1228 Viewer viewer; 1229 ierr = ViewerFileOpenASCII(mat->comm,"stdout",&viewer);CHKERRQ(ierr); 1230 ierr = ViewerFileSetFormat(viewer,FILE_FORMAT_INFO,0);CHKERRQ(ierr); 1231 ierr = MatView(mat,viewer); CHKERRQ(ierr); 1232 ierr = ViewerDestroy(viewer); CHKERRQ(ierr); 1233 } 1234 ierr = OptionsHasName(PETSC_NULL,"-mat_view_info_detailed",&flg); CHKERRQ(ierr); 1235 if (flg) { 1236 Viewer viewer; 1237 ierr = ViewerFileOpenASCII(mat->comm,"stdout",&viewer);CHKERRQ(ierr); 1238 ierr = ViewerFileSetFormat(viewer,FILE_FORMAT_INFO_DETAILED,0);CHKERRQ(ierr); 1239 ierr = MatView(mat,viewer); CHKERRQ(ierr); 1240 ierr = ViewerDestroy(viewer); CHKERRQ(ierr); 1241 } 1242 ierr = OptionsHasName(PETSC_NULL,"-mat_view",&flg); CHKERRQ(ierr); 1243 if (flg) { 1244 Viewer viewer; 1245 ierr = ViewerFileOpenASCII(mat->comm,"stdout",&viewer);CHKERRQ(ierr); 1246 ierr = MatView(mat,viewer); CHKERRQ(ierr); 1247 ierr = ViewerDestroy(viewer); CHKERRQ(ierr); 1248 } 1249 ierr = OptionsHasName(PETSC_NULL,"-mat_view_matlab",&flg); CHKERRQ(ierr); 1250 if (flg) { 1251 Viewer viewer; 1252 ierr = ViewerFileOpenASCII(mat->comm,"stdout",&viewer);CHKERRQ(ierr); 1253 ierr = ViewerFileSetFormat(viewer,FILE_FORMAT_MATLAB,"M");CHKERRQ(ierr); 1254 ierr = MatView(mat,viewer); CHKERRQ(ierr); 1255 ierr = ViewerDestroy(viewer); CHKERRQ(ierr); 1256 } 1257 ierr = OptionsHasName(PETSC_NULL,"-mat_view_draw",&flg); CHKERRQ(ierr); 1258 if (flg) { 1259 Draw win; 1260 ierr = DrawOpenX(mat->comm,0,0,0,0,300,300,&win); CHKERRQ(ierr); 1261 ierr = MatView(mat,(Viewer)win); CHKERRQ(ierr); 1262 ierr = DrawSyncFlush(win); CHKERRQ(ierr); 1263 ierr = DrawDestroy(win); CHKERRQ(ierr); 1264 } 1265 } 1266 inassm--; 1267 return 0; 1268 } 1269 1270 /*@ 1271 MatCompress - Tries to store the matrix in as little space as 1272 possible. May fail if memory is already fully used, since it 1273 tries to allocate new space. 1274 1275 Input Parameters: 1276 . mat - the matrix 1277 1278 .keywords: matrix, compress 1279 @*/ 1280 int MatCompress(Mat mat) 1281 { 1282 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1283 if (mat->ops.compress) return (*mat->ops.compress)(mat); 1284 return 0; 1285 } 1286 /*@ 1287 MatSetOption - Sets a parameter option for a matrix. Some options 1288 may be specific to certain storage formats. Some options 1289 determine how values will be inserted (or added). Sorted, 1290 row-oriented input will generally assemble the fastest. The default 1291 is row-oriented, nonsorted input. 1292 1293 Input Parameters: 1294 . mat - the matrix 1295 . option - the option, one of the following: 1296 $ ROW_ORIENTED 1297 $ COLUMN_ORIENTED, 1298 $ ROWS_SORTED, 1299 $ COLUMNS_SORTED, 1300 $ NO_NEW_NONZERO_LOCATIONS, 1301 $ YES_NEW_NONZERO_LOCATIONS, 1302 $ SYMMETRIC_MATRIX, 1303 $ STRUCTURALLY_SYMMETRIC_MATRIX, 1304 $ NO_NEW_DIAGONALS, 1305 $ YES_NEW_DIAGONALS, 1306 $ and possibly others. 1307 1308 Notes: 1309 Some options are relevant only for particular matrix types and 1310 are thus ignored by others. Other options are not supported by 1311 certain matrix types and will generate an error message if set. 1312 1313 If using a Fortran 77 module to compute a matrix, one may need to 1314 use the column-oriented option (or convert to the row-oriented 1315 format). 1316 1317 NO_NEW_NONZERO_LOCATIONS indicates that any add or insertion 1318 that will generate a new entry in the nonzero structure is ignored. 1319 What this means is if memory is not allocated for this particular 1320 lot, then the insertion is ignored. For dense matrices, where 1321 the entire array is allocated, no entries are ever ignored. 1322 1323 .keywords: matrix, option, row-oriented, column-oriented, sorted, nonzero 1324 @*/ 1325 int MatSetOption(Mat mat,MatOption op) 1326 { 1327 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1328 if (mat->ops.setoption) return (*mat->ops.setoption)(mat,op); 1329 return 0; 1330 } 1331 1332 /*@ 1333 MatZeroEntries - Zeros all entries of a matrix. For sparse matrices 1334 this routine retains the old nonzero structure. 1335 1336 Input Parameters: 1337 . mat - the matrix 1338 1339 .keywords: matrix, zero, entries 1340 1341 .seealso: MatZeroRows() 1342 @*/ 1343 int MatZeroEntries(Mat mat) 1344 { 1345 int ierr; 1346 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1347 if (!mat->ops.zeroentries) SETERRQ(PETSC_ERR_SUP,"MatZeroEntries"); 1348 1349 PLogEventBegin(MAT_ZeroEntries,mat,0,0,0); 1350 ierr = (*mat->ops.zeroentries)(mat); CHKERRQ(ierr); 1351 PLogEventEnd(MAT_ZeroEntries,mat,0,0,0); 1352 return 0; 1353 } 1354 1355 /*@ 1356 MatZeroRows - Zeros all entries (except possibly the main diagonal) 1357 of a set of rows of a matrix. 1358 1359 Input Parameters: 1360 . mat - the matrix 1361 . is - index set of rows to remove 1362 . diag - pointer to value put in all diagonals of eliminated rows. 1363 Note that diag is not a pointer to an array, but merely a 1364 pointer to a single value. 1365 1366 Notes: 1367 For the AIJ matrix formats this removes the old nonzero structure, 1368 but does not release memory. For the dense and block diagonal 1369 formats this does not alter the nonzero structure. 1370 1371 The user can set a value in the diagonal entry (or for the AIJ and 1372 row formats can optionally remove the main diagonal entry from the 1373 nonzero structure as well, by passing a null pointer as the final 1374 argument). 1375 1376 .keywords: matrix, zero, rows, boundary conditions 1377 1378 .seealso: MatZeroEntries(), MatGetSubMatrix(), MatGetSubMatrixInPlace() 1379 @*/ 1380 int MatZeroRows(Mat mat,IS is, Scalar *diag) 1381 { 1382 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1383 if (!mat->assembled) SETERRQ(1,"MatZeroRows:Not for unassembled matrix"); 1384 if (mat->ops.zerorows) return (*mat->ops.zerorows)(mat,is,diag); 1385 SETERRQ(PETSC_ERR_SUP,"MatZeroRows"); 1386 } 1387 1388 /*@ 1389 MatGetSize - Returns the numbers of rows and columns in a matrix. 1390 1391 Input Parameter: 1392 . mat - the matrix 1393 1394 Output Parameters: 1395 . m - the number of global rows 1396 . n - the number of global columns 1397 1398 .keywords: matrix, dimension, size, rows, columns, global, get 1399 1400 .seealso: MatGetLocalSize() 1401 @*/ 1402 int MatGetSize(Mat mat,int *m,int* n) 1403 { 1404 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1405 if (!m || !n) SETERRQ(1,"MatGetSize:Bad address for result"); 1406 return (*mat->ops.getsize)(mat,m,n); 1407 } 1408 1409 /*@ 1410 MatGetLocalSize - Returns the number of rows and columns in a matrix 1411 stored locally. This information may be implementation dependent, so 1412 use with care. 1413 1414 Input Parameters: 1415 . mat - the matrix 1416 1417 Output Parameters: 1418 . m - the number of local rows 1419 . n - the number of local columns 1420 1421 .keywords: matrix, dimension, size, local, rows, columns, get 1422 1423 .seealso: MatGetSize() 1424 @*/ 1425 int MatGetLocalSize(Mat mat,int *m,int* n) 1426 { 1427 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1428 if (!m || !n) SETERRQ(1,"MatGetLocalSize:Bad address for result"); 1429 return (*mat->ops.getlocalsize)(mat,m,n); 1430 } 1431 1432 /*@ 1433 MatGetOwnershipRange - Returns the range of matrix rows owned by 1434 this processor, assuming that the matrix is laid out with the first 1435 n1 rows on the first processor, the next n2 rows on the second, etc. 1436 For certain parallel layouts this range may not be well-defined. 1437 1438 Input Parameters: 1439 . mat - the matrix 1440 1441 Output Parameters: 1442 . m - the first local row 1443 . n - one more then the last local row 1444 1445 .keywords: matrix, get, range, ownership 1446 @*/ 1447 int MatGetOwnershipRange(Mat mat,int *m,int* n) 1448 { 1449 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1450 if (!m || !n) SETERRQ(1,"MatGetOwnershipRange:Bad address for result"); 1451 if (mat->ops.getownershiprange) return (*mat->ops.getownershiprange)(mat,m,n); 1452 SETERRQ(PETSC_ERR_SUP,"MatGetOwnershipRange"); 1453 } 1454 1455 /*@ 1456 MatILUFactorSymbolic - Performs symbolic ILU factorization of a matrix. 1457 Uses levels of fill only, not drop tolerance. Use MatLUFactorNumeric() 1458 to complete the factorization. 1459 1460 Input Parameters: 1461 . mat - the matrix 1462 . row - row permutation 1463 . column - column permutation 1464 . fill - number of levels of fill 1465 . f - expected fill as ratio of the original number of nonzeros, 1466 for example 3.0; choosing this parameter well can result in 1467 more efficient use of time and space. 1468 1469 Output Parameters: 1470 . fact - new matrix that has been symbolically factored 1471 1472 Options Database Key: 1473 $ -mat_ilu_fill <f>, where f is the fill ratio 1474 1475 Notes: 1476 See the file $(PETSC_DIR)/Performace for additional information about 1477 choosing the fill factor for better efficiency. 1478 1479 .keywords: matrix, factor, incomplete, ILU, symbolic, fill 1480 1481 .seealso: MatLUFactorSymbolic(), MatLUFactorNumeric() 1482 @*/ 1483 int MatILUFactorSymbolic(Mat mat,IS row,IS col,double f,int fill,Mat *fact) 1484 { 1485 int ierr,flg; 1486 1487 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1488 if (fill < 0) SETERRQ(1,"MatILUFactorSymbolic:Levels of fill negative"); 1489 if (!fact) SETERRQ(1,"MatILUFactorSymbolic:Fact argument is missing"); 1490 if (!mat->ops.ilufactorsymbolic) SETERRQ(PETSC_ERR_SUP,"MatILUFactorSymbolic"); 1491 if (!mat->assembled) SETERRQ(1,"MatILUFactorSymbolic:Not for unassembled matrix"); 1492 1493 ierr = OptionsGetDouble(PETSC_NULL,"-mat_ilu_fill",&f,&flg); CHKERRQ(ierr); 1494 PLogEventBegin(MAT_ILUFactorSymbolic,mat,row,col,0); 1495 ierr = (*mat->ops.ilufactorsymbolic)(mat,row,col,f,fill,fact); CHKERRQ(ierr); 1496 PLogEventEnd(MAT_ILUFactorSymbolic,mat,row,col,0); 1497 return 0; 1498 } 1499 1500 /*@ 1501 MatIncompleteCholeskyFactorSymbolic - Performs symbolic incomplete 1502 Cholesky factorization for a symmetric matrix. Use 1503 MatCholeskyFactorNumeric() to complete the factorization. 1504 1505 Input Parameters: 1506 . mat - the matrix 1507 . perm - row and column permutation 1508 . fill - levels of fill 1509 . f - expected fill as ratio of original fill 1510 1511 Output Parameter: 1512 . fact - the factored matrix 1513 1514 Note: Currently only no-fill factorization is supported. 1515 1516 .keywords: matrix, factor, incomplete, ICC, Cholesky, symbolic, fill 1517 1518 .seealso: MatCholeskyFactorNumeric(), MatCholeskyFactor() 1519 @*/ 1520 int MatIncompleteCholeskyFactorSymbolic(Mat mat,IS perm,double f,int fill, 1521 Mat *fact) 1522 { 1523 int ierr; 1524 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1525 if (fill < 0) SETERRQ(1,"MatIncompleteCholeskyFactorSymbolic:Fill negative"); 1526 if (!fact) SETERRQ(1,"MatIncompleteCholeskyFactorSymbolic:Missing fact argument"); 1527 if (!mat->ops.incompletecholeskyfactorsymbolic) 1528 SETERRQ(PETSC_ERR_SUP,"MatIncompleteCholeskyFactorSymbolic"); 1529 if (!mat->assembled) 1530 SETERRQ(1,"MatIncompleteCholeskyFactorSymbolic:Not for unassembled matrix"); 1531 1532 PLogEventBegin(MAT_IncompleteCholeskyFactorSymbolic,mat,perm,0,0); 1533 ierr = (*mat->ops.incompletecholeskyfactorsymbolic)(mat,perm,f,fill,fact);CHKERRQ(ierr); 1534 PLogEventEnd(MAT_IncompleteCholeskyFactorSymbolic,mat,perm,0,0); 1535 return 0; 1536 } 1537 1538 /*@C 1539 MatGetArray - Returns a pointer to the element values in the matrix. 1540 This routine is implementation dependent, and may not even work for 1541 certain matrix types. 1542 1543 Input Parameter: 1544 . mat - the matrix 1545 1546 Output Parameter: 1547 . v - the location of the values 1548 1549 Fortran Note: 1550 The Fortran interface is slightly different from that given below. 1551 See the users manual and petsc/src/mat/examples for details. 1552 1553 .keywords: matrix, array, elements, values 1554 @*/ 1555 int MatGetArray(Mat mat,Scalar **v) 1556 { 1557 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1558 if (!v) SETERRQ(1,"MatGetArray:Bad input, array pointer location"); 1559 if (!mat->ops.getarray) SETERRQ(PETSC_ERR_SUP,"MatGetArraye"); 1560 return (*mat->ops.getarray)(mat,v); 1561 } 1562 1563 /*@C 1564 MatGetSubMatrix - Extracts a submatrix from a matrix. If submat points 1565 to a valid matrix, it may be reused. 1566 1567 Input Parameters: 1568 . mat - the matrix 1569 . irow, icol - index sets of rows and columns to extract 1570 . scall - either MAT_INITIAL_MATRIX or MAT_REUSE_MATRIX 1571 1572 Output Parameter: 1573 . submat - the submatrix 1574 1575 Notes: 1576 MatGetSubMatrix() can be useful in setting boundary conditions. 1577 1578 Use MatGetSubMatrices() to extract multiple submatrices. 1579 1580 .keywords: matrix, get, submatrix, boundary conditions 1581 1582 .seealso: MatZeroRows(), MatGetSubMatrixInPlace(), MatGetSubMatrices() 1583 @*/ 1584 int MatGetSubMatrix(Mat mat,IS irow,IS icol,MatGetSubMatrixCall scall,Mat *submat) 1585 { 1586 int ierr; 1587 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1588 if (scall == MAT_REUSE_MATRIX) { 1589 PETSCVALIDHEADERSPECIFIC(*submat,MAT_COOKIE); 1590 } 1591 if (!mat->ops.getsubmatrix) SETERRQ(PETSC_ERR_SUP,"MatGetSubMatrix"); 1592 if (!mat->assembled) SETERRQ(1,"MatGetSubMatrix:Not for unassembled matrix"); 1593 1594 PLogEventBegin(MAT_GetSubMatrix,mat,irow,icol,0); 1595 ierr = (*mat->ops.getsubmatrix)(mat,irow,icol,scall,submat); CHKERRQ(ierr); 1596 PLogEventEnd(MAT_GetSubMatrix,mat,irow,icol,0); 1597 return 0; 1598 } 1599 1600 /*@C 1601 MatGetSubMatrices - Extracts several submatrices from a matrix. If submat 1602 points to an array of valid matrices, it may be reused. 1603 1604 Input Parameters: 1605 . mat - the matrix 1606 . irow, icol - index sets of rows and columns to extract 1607 1608 Output Parameter: 1609 . submat - the submatrices 1610 1611 Note: 1612 Use MatGetSubMatrix() for extracting a sinble submatrix. 1613 1614 .keywords: matrix, get, submatrix, submatrices 1615 1616 .seealso: MatGetSubMatrix() 1617 @*/ 1618 int MatGetSubMatrices(Mat mat,int n, IS *irow,IS *icol,MatGetSubMatrixCall scall, 1619 Mat **submat) 1620 { 1621 int ierr; 1622 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1623 if (!mat->ops.getsubmatrices) SETERRQ(PETSC_ERR_SUP,"MatGetSubMatrices"); 1624 if (!mat->assembled) SETERRQ(1,"MatGetSubMatrices:Not for unassembled matrix"); 1625 1626 PLogEventBegin(MAT_GetSubMatrices,mat,0,0,0); 1627 ierr = (*mat->ops.getsubmatrices)(mat,n,irow,icol,scall,submat); CHKERRQ(ierr); 1628 PLogEventEnd(MAT_GetSubMatrices,mat,0,0,0); 1629 return 0; 1630 } 1631 1632 /*@ 1633 MatGetSubMatrixInPlace - Extracts a submatrix from a matrix, returning 1634 the submatrix in place of the original matrix. 1635 1636 Input Parameters: 1637 . mat - the matrix 1638 . irow, icol - index sets of rows and columns to extract 1639 1640 .keywords: matrix, get, submatrix, boundary conditions, in-place 1641 1642 .seealso: MatZeroRows(), MatGetSubMatrix() 1643 @*/ 1644 int MatGetSubMatrixInPlace(Mat mat,IS irow,IS icol) 1645 { 1646 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1647 if (!mat->assembled) SETERRQ(1,"MatGetSubMatrixInPlace:Not for unassembled matrix"); 1648 1649 if (!mat->ops.getsubmatrixinplace) SETERRQ(PETSC_ERR_SUP,"MatGetSubmatrixInPlace"); 1650 return (*mat->ops.getsubmatrixinplace)(mat,irow,icol); 1651 } 1652 1653 /*@ 1654 MatIncreaseOverlap - Given a set of submatrices indicated by index sets, 1655 replaces the index by larger ones that represent submatrices with more 1656 overlap. 1657 1658 Input Parameters: 1659 . mat - the matrix 1660 . n - the number of index sets 1661 . is - the array of pointers to index sets 1662 . ov - the additional overlap requested 1663 1664 .keywords: matrix, overlap, Schwarz 1665 1666 .seealso: MatGetSubMatrices() 1667 @*/ 1668 int MatIncreaseOverlap(Mat mat,int n, IS *is, int ov) 1669 { 1670 int ierr; 1671 PETSCVALIDHEADERSPECIFIC(mat,MAT_COOKIE); 1672 if (!mat->assembled) SETERRQ(1,"MatIncreaseOverlap:Not for unassembled matrix"); 1673 1674 if (ov == 0) return 0; 1675 if (!mat->ops.increaseoverlap) SETERRQ(PETSC_ERR_SUP,"MatIncreaseOverlap"); 1676 PLogEventBegin(MAT_IncreaseOverlap,mat,0,0,0); 1677 ierr = (*mat->ops.increaseoverlap)(mat,n,is,ov); CHKERRQ(ierr); 1678 PLogEventEnd(MAT_IncreaseOverlap,mat,0,0,0); 1679 return 0; 1680 } 1681 1682 /*@ 1683 MatPrintHelp - Prints all the options for the matrix. 1684 1685 Input Parameter: 1686 . mat - the matrix 1687 1688 Options Database Keys: 1689 $ -help, -h 1690 1691 .keywords: mat, help 1692 1693 .seealso: MatCreate(), MatCreateXXX() 1694 @*/ 1695 int MatPrintHelp(Mat mat) 1696 { 1697 static int called = 0; 1698 MPI_Comm comm = mat->comm; 1699 1700 if (!called) { 1701 MPIU_printf(comm,"General matrix options:\n"); 1702 MPIU_printf(comm," -mat_view_info : view basic matrix info during MatAssemblyEnd()\n"); 1703 MPIU_printf(comm," -mat_view_info_detailed : view detailed matrix info during MatAssemblyEnd()\n"); 1704 MPIU_printf(comm," -mat_view_draw : draw nonzero matrix structure during MatAssemblyEnd()\n"); 1705 MPIU_printf(comm," -draw_pause <sec> : set seconds of display pause\n"); 1706 MPIU_printf(comm," -display <name> : set alternate display\n"); 1707 called = 1; 1708 } 1709 if (mat->ops.printhelp) (*mat->ops.printhelp)(mat); 1710 return 0; 1711 } 1712 1713