/*@ MatDiagonalSet - Computes Y = Y + D, where D is a diagonal matrix that is represented as a vector. Or Y[i,i] = D[i] if InsertMode is INSERT_VALUES. Input Parameters: + Y - the input matrix . D - the diagonal matrix, represented as a vector - i - INSERT_VALUES or ADD_VALUES Neighbor-wise Collective on Mat and Vec Level: intermediate .keywords: matrix, add, shift, diagonal .seealso: MatShift() @*/ PetscErrorCode MatDiagonalSet(Mat Y,Vec D,InsertMode is) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(Y,MAT_CLASSID,1); PetscValidHeaderSpecific(D,VEC_CLASSID,2); if (Y->ops->diagonalset) { ierr = (*Y->ops->diagonalset)(Y,D,is);CHKERRQ(ierr); } else { ierr = MatDiagonalSet_Default(Y,D,is);CHKERRQ(ierr); } PetscFunctionReturn(0); }
/*@ MatDiagonalSet - Computes Y = Y + D, where D is a diagonal matrix that is represented as a vector. Or Y[i,i] = D[i] if InsertMode is INSERT_VALUES. Input Parameters: + Y - the input matrix . D - the diagonal matrix, represented as a vector - i - INSERT_VALUES or ADD_VALUES Neighbor-wise Collective on Mat and Vec Notes: If the matrix Y is missing some diagonal entries this routine can be very slow. To make it fast one should initially fill the matrix so that all diagonal entries have a value (with a value of zero for those locations that would not have an entry). Level: intermediate .keywords: matrix, add, shift, diagonal .seealso: MatShift() @*/ PetscErrorCode MatDiagonalSet(Mat Y,Vec D,InsertMode is) { PetscErrorCode ierr; PetscInt matlocal,veclocal; PetscFunctionBegin; PetscValidHeaderSpecific(Y,MAT_CLASSID,1); PetscValidHeaderSpecific(D,VEC_CLASSID,2); ierr = MatGetLocalSize(Y,&matlocal,NULL);CHKERRQ(ierr); ierr = VecGetLocalSize(D,&veclocal);CHKERRQ(ierr); if (matlocal != veclocal) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Number local rows of matrix %D does not match that of vector for diagonal %D",matlocal,veclocal); if (Y->ops->diagonalset) { ierr = (*Y->ops->diagonalset)(Y,D,is);CHKERRQ(ierr); } else { ierr = MatDiagonalSet_Default(Y,D,is);CHKERRQ(ierr); } PetscFunctionReturn(0); }