Actual source code: transm.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  2: #include <petsc/private/matimpl.h>          /*I "petscmat.h" I*/

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

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

 16:   MatMultTranspose(Na->A,x,y);
 17:   return(0);
 18: }

 22: PetscErrorCode MatMultAdd_Transpose(Mat N,Vec v1,Vec v2,Vec v3)
 23: {
 24:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;

 28:   MatMultTransposeAdd(Na->A,v1,v2,v3);
 29:   return(0);
 30: }

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

 40:   MatMult(Na->A,x,y);
 41:   return(0);
 42: }

 46: PetscErrorCode MatMultTransposeAdd_Transpose(Mat N,Vec v1,Vec v2,Vec v3)
 47: {
 48:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;

 52:   MatMultAdd(Na->A,v1,v2,v3);
 53:   return(0);
 54: }

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

 64:   MatDestroy(&Na->A);
 65:   PetscFree(N->data);
 66:   return(0);
 67: }

 71: PetscErrorCode MatDuplicate_Transpose(Mat N, MatDuplicateOption op, Mat* m)
 72: {
 73:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;

 77:   if (op == MAT_COPY_VALUES) {
 78:     MatTranspose(Na->A,MAT_INITIAL_MATRIX,m);
 79:   } else if (op == MAT_DO_NOT_COPY_VALUES) {
 80:     MatDuplicate(Na->A,MAT_DO_NOT_COPY_VALUES,m);
 81:     MatTranspose(*m,MAT_REUSE_MATRIX,m);
 82:   } else SETERRQ(PetscObjectComm((PetscObject)N),PETSC_ERR_SUP,"MAT_SHARE_NONZERO_PATTERN not supported for this matrix type");
 83:   return(0);
 84: }


 89: /*@
 90:       MatCreateTranspose - Creates a new matrix object that behaves like A'

 92:    Collective on Mat

 94:    Input Parameter:
 95: .   A  - the (possibly rectangular) matrix

 97:    Output Parameter:
 98: .   N - the matrix that represents A'

100:    Level: intermediate

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

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

108: @*/
109: PetscErrorCode  MatCreateTranspose(Mat A,Mat *N)
110: {
112:   PetscInt       m,n;
113:   Mat_Transpose  *Na;

116:   MatGetLocalSize(A,&m,&n);
117:   MatCreate(PetscObjectComm((PetscObject)A),N);
118:   MatSetSizes(*N,n,m,PETSC_DECIDE,PETSC_DECIDE);
119:   PetscLayoutSetUp((*N)->rmap);
120:   PetscLayoutSetUp((*N)->cmap);
121:   PetscObjectChangeTypeName((PetscObject)*N,MATTRANSPOSEMAT);

123:   PetscNewLog(*N,&Na);
124:   (*N)->data = (void*) Na;
125:   PetscObjectReference((PetscObject)A);
126:   Na->A      = A;

128:   (*N)->ops->destroy          = MatDestroy_Transpose;
129:   (*N)->ops->mult             = MatMult_Transpose;
130:   (*N)->ops->multadd          = MatMultAdd_Transpose;
131:   (*N)->ops->multtranspose    = MatMultTranspose_Transpose;
132:   (*N)->ops->multtransposeadd = MatMultTransposeAdd_Transpose;
133:   (*N)->ops->duplicate        = MatDuplicate_Transpose;
134:   (*N)->assembled             = PETSC_TRUE;

136:   MatSetBlockSizes(*N,PetscAbs(A->cmap->bs),PetscAbs(A->rmap->bs));
137:   MatSetUp(*N);
138:   return(0);
139: }