Actual source code: transm.c
petsc-3.5.4 2015-05-23
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: PetscLayoutSetUp((*N)->rmap);
102: PetscLayoutSetUp((*N)->cmap);
103: PetscObjectChangeTypeName((PetscObject)*N,MATTRANSPOSEMAT);
105: PetscNewLog(*N,&Na);
106: (*N)->data = (void*) Na;
107: PetscObjectReference((PetscObject)A);
108: Na->A = A;
110: (*N)->ops->destroy = MatDestroy_Transpose;
111: (*N)->ops->mult = MatMult_Transpose;
112: (*N)->ops->multadd = MatMultAdd_Transpose;
113: (*N)->ops->multtranspose = MatMultTranspose_Transpose;
114: (*N)->ops->multtransposeadd = MatMultTransposeAdd_Transpose;
115: (*N)->assembled = PETSC_TRUE;
117: MatSetBlockSizes(*N,PetscAbs(A->cmap->bs),PetscAbs(A->rmap->bs));
118: MatSetUp(*N);
119: return(0);
120: }