Actual source code: transm.c

petsc-3.8.3 2017-12-09
Report Typos and Errors

  2:  #include <petsc/private/matimpl.h>

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

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

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

 18: PetscErrorCode MatMultAdd_Transpose(Mat N,Vec v1,Vec v2,Vec v3)
 19: {
 20:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;

 24:   MatMultTransposeAdd(Na->A,v1,v2,v3);
 25:   return(0);
 26: }

 28: PetscErrorCode MatMultTranspose_Transpose(Mat N,Vec x,Vec y)
 29: {
 30:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;

 34:   MatMult(Na->A,x,y);
 35:   return(0);
 36: }

 38: PetscErrorCode MatMultTransposeAdd_Transpose(Mat N,Vec v1,Vec v2,Vec v3)
 39: {
 40:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;

 44:   MatMultAdd(Na->A,v1,v2,v3);
 45:   return(0);
 46: }

 48: PetscErrorCode MatDestroy_Transpose(Mat N)
 49: {
 50:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;

 54:   MatDestroy(&Na->A);
 55:   PetscObjectComposeFunction((PetscObject)N,"MatTransposeGetMat_C",NULL);
 56:   PetscFree(N->data);
 57:   return(0);
 58: }

 60: PetscErrorCode MatDuplicate_Transpose(Mat N, MatDuplicateOption op, Mat* m)
 61: {
 62:   Mat_Transpose  *Na = (Mat_Transpose*)N->data;

 66:   if (op == MAT_COPY_VALUES) {
 67:     MatTranspose(Na->A,MAT_INITIAL_MATRIX,m);
 68:   } else if (op == MAT_DO_NOT_COPY_VALUES) {
 69:     MatDuplicate(Na->A,MAT_DO_NOT_COPY_VALUES,m);
 70:     MatTranspose(*m,MAT_REUSE_MATRIX,m);
 71:   } else SETERRQ(PetscObjectComm((PetscObject)N),PETSC_ERR_SUP,"MAT_SHARE_NONZERO_PATTERN not supported for this matrix type");
 72:   return(0);
 73: }

 75: PetscErrorCode MatTransposeGetMat_Transpose(Mat A,Mat *M)
 76: {
 77:   Mat_Transpose  *Aa = (Mat_Transpose*)A->data;

 80:   *M = Aa->A;
 81:   return(0);
 82: }

 84: /*@
 85:       MatTransposeGetMat - Gets the Mat object stored inside a MATTRANSPOSEMAT'

 87:    Logically collective on Mat

 89:    Input Parameter:
 90: .   A  - the MATTRANSPOSE matrix

 92:    Output Parameter:
 93: .   M - the matrix object stored inside A

 95:    Level: intermediate

 97: .seealso: MatCreateTranspose()

 99: @*/
100: PetscErrorCode MatTransposeGetMat(Mat A,Mat *M)
101: {

108:   PetscUseMethod(A,"MatTransposeGetMat_C",(Mat,Mat*),(A,M));
109:   return(0);
110: }

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

115:    Collective on Mat

117:    Input Parameter:
118: .   A  - the (possibly rectangular) matrix

120:    Output Parameter:
121: .   N - the matrix that represents A'

123:    Level: intermediate

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

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

131: @*/
132: PetscErrorCode  MatCreateTranspose(Mat A,Mat *N)
133: {
135:   PetscInt       m,n;
136:   Mat_Transpose  *Na;

139:   MatGetLocalSize(A,&m,&n);
140:   MatCreate(PetscObjectComm((PetscObject)A),N);
141:   MatSetSizes(*N,n,m,PETSC_DECIDE,PETSC_DECIDE);
142:   PetscLayoutSetUp((*N)->rmap);
143:   PetscLayoutSetUp((*N)->cmap);
144:   PetscObjectChangeTypeName((PetscObject)*N,MATTRANSPOSEMAT);

146:   PetscNewLog(*N,&Na);
147:   (*N)->data = (void*) Na;
148:   PetscObjectReference((PetscObject)A);
149:   Na->A      = A;

151:   (*N)->ops->destroy          = MatDestroy_Transpose;
152:   (*N)->ops->mult             = MatMult_Transpose;
153:   (*N)->ops->multadd          = MatMultAdd_Transpose;
154:   (*N)->ops->multtranspose    = MatMultTranspose_Transpose;
155:   (*N)->ops->multtransposeadd = MatMultTransposeAdd_Transpose;
156:   (*N)->ops->duplicate        = MatDuplicate_Transpose;
157:   (*N)->assembled             = PETSC_TRUE;

159:   PetscObjectComposeFunction((PetscObject)(*N),"MatTransposeGetMat_C",MatTransposeGetMat_Transpose);
160:   MatSetBlockSizes(*N,PetscAbs(A->cmap->bs),PetscAbs(A->rmap->bs));
161:   MatSetUp(*N);
162:   return(0);
163: }