Date: 2013-07-02T14:43:48+00:00

Actual source code: transm.c
petsc-3.4.2 2013-07-02

      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: /*@
     72:       MatCreateTranspose - Creates a new matrix object that behaves like A'

     74:    Collective on Mat

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

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

     82:    Level: intermediate

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

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

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

     98:   MatGetLocalSize(A,&m,&n);
     99:   MatCreate(PetscObjectComm((PetscObject)A),N);
    100:   MatSetSizes(*N,n,m,PETSC_DECIDE,PETSC_DECIDE);
    101:   PetscObjectChangeTypeName((PetscObject)*N,MATTRANSPOSEMAT);

    103:   PetscNewLog(*N,Mat_Transpose,&Na);
    104:   (*N)->data = (void*) Na;
    105:   PetscObjectReference((PetscObject)A);
    106:   Na->A      = A;

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

    115:   PetscLayoutSetBlockSize((*N)->rmap,A->cmap->bs);
    116:   PetscLayoutSetBlockSize((*N)->cmap,A->rmap->bs);
    117:   PetscLayoutSetUp((*N)->rmap);
    118:   PetscLayoutSetUp((*N)->cmap);
    119:   MatSetUp(*N);
    120:   return(0);
    121: }