Actual source code: transm.c

  1: #define PETSCMAT_DLL

 3:  #include private/matimpl.h

  5: typedef struct {
  6:   Mat A;
  7: } Mat_Transpose;

 11: PetscErrorCode MatMult_Transpose(Mat N,Vec x,Vec y)
 12: {
 13:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;

 17:   MatMultTranspose(Na->A,x,y);
 18:   return(0);
 19: }
 20: 
 23: PetscErrorCode MatMultAdd_Transpose(Mat N,Vec v1,Vec v2,Vec v3)
 24: {
 25:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;
 27: 
 29:   MatMultTransposeAdd(Na->A,v1,v2,v3);
 30:   return(0);
 31: }

 35: PetscErrorCode MatMultTranspose_Transpose(Mat N,Vec x,Vec y)
 36: {
 37:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;

 41:   MatMult(Na->A,x,y);
 42:   return(0);
 43: }
 44: 
 47: PetscErrorCode MatMultTransposeAdd_Transpose(Mat N,Vec v1,Vec v2,Vec v3)
 48: {
 49:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;
 51: 
 53:   MatMultAdd(Na->A,v1,v2,v3);
 54:   return(0);
 55: }

 59: PetscErrorCode MatDestroy_Transpose(Mat N)
 60: {
 61:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;

 65:   if (Na->A) { MatDestroy(Na->A); }
 66:   PetscFree(Na);
 67:   return(0);
 68: }
 69: 
 72: /*@
 73:       MatCreateTranspose - Creates a new matrix object that behaves like A'

 75:    Collective on Mat

 77:    Input Parameter:
 78: .   A  - the (possibly rectangular) matrix

 80:    Output Parameter:
 81: .   N - the matrix that represents A'

 83:    Level: intermediate

 85:    Notes: The transpose A' is NOT actually formed! Rather the new matrix
 86:           object performs the matrix-vector product by using the MatMultTranspose() on
 87:           the original matrix

 89: .seealso: MatCreateNormal(), MatMult(), MatMultTranspose(), MatCreate()

 91: @*/
 92: PetscErrorCode  MatCreateTranspose(Mat A,Mat *N)
 93: {
 95:   PetscInt       m,n;
 96:   Mat_Transpose  *Na;

 99:   MatGetLocalSize(A,&m,&n);
100:   MatCreate(((PetscObject)A)->comm,N);
101:   MatSetSizes(*N,n,m,PETSC_DECIDE,PETSC_DECIDE);
102:   PetscObjectChangeTypeName((PetscObject)*N,MATTRANSPOSEMAT);
103: 
104:   PetscNewLog(*N,Mat_Transpose,&Na);
105:   (*N)->data = (void*) Na;
106:   PetscObjectReference((PetscObject)A);
107:   Na->A     = A;

109:   (*N)->ops->destroy          = MatDestroy_Transpose;
110:   (*N)->ops->mult             = MatMult_Transpose;
111:   (*N)->ops->mult             = MatMult_Transpose;
112:   (*N)->ops->multtranspose    = MatMultTranspose_Transpose;
113:   (*N)->ops->multtransposeadd = MatMultTransposeAdd_Transpose;
114:   (*N)->assembled             = PETSC_TRUE;

116:   PetscMapSetBlockSize((*N)->rmap,A->cmap->bs);
117:   PetscMapSetBlockSize((*N)->cmap,A->rmap->bs);
118:   PetscMapSetUp((*N)->rmap);
119:   PetscMapSetUp((*N)->cmap);

121:   return(0);
122: }