Actual source code: htransm.c
petsc-3.7.3 2016-08-01
2: #include <petsc/private/matimpl.h> /*I "petscmat.h" I*/
4: typedef struct {
5: Mat A;
6: } Mat_HT;
10: PetscErrorCode MatMult_HT(Mat N,Vec x,Vec y)
11: {
12: Mat_HT *Na = (Mat_HT*)N->data;
16: MatMultHermitianTranspose(Na->A,x,y);
17: return(0);
18: }
22: PetscErrorCode MatMultAdd_HT(Mat N,Vec v1,Vec v2,Vec v3)
23: {
24: Mat_HT *Na = (Mat_HT*)N->data;
28: MatMultHermitianTransposeAdd(Na->A,v1,v2,v3);
29: return(0);
30: }
34: PetscErrorCode MatMultHermitianTranspose_HT(Mat N,Vec x,Vec y)
35: {
36: Mat_HT *Na = (Mat_HT*)N->data;
40: MatMult(Na->A,x,y);
41: return(0);
42: }
46: PetscErrorCode MatMultHermitianTransposeAdd_HT(Mat N,Vec v1,Vec v2,Vec v3)
47: {
48: Mat_HT *Na = (Mat_HT*)N->data;
52: MatMultAdd(Na->A,v1,v2,v3);
53: return(0);
54: }
58: PetscErrorCode MatDestroy_HT(Mat N)
59: {
60: Mat_HT *Na = (Mat_HT*)N->data;
64: MatDestroy(&Na->A);
65: PetscFree(N->data);
66: return(0);
67: }
71: PetscErrorCode MatDuplicate_HT(Mat N, MatDuplicateOption op, Mat* m)
72: {
73: Mat_HT *Na = (Mat_HT*)N->data;
77: if (op == MAT_COPY_VALUES) {
78: MatHermitianTranspose(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: MatHermitianTranspose(*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: }
88: /*@
89: MatCreateHermitianTranspose - Creates a new matrix object that behaves like A'*
91: Collective on Mat
93: Input Parameter:
94: . A - the (possibly rectangular) matrix
96: Output Parameter:
97: . N - the matrix that represents A'*
99: Level: intermediate
101: Notes: The hermitian transpose A' is NOT actually formed! Rather the new matrix
102: object performs the matrix-vector product by using the MatMultHermitianTranspose() on
103: the original matrix
105: .seealso: MatCreateNormal(), MatMult(), MatMultHermitianTranspose(), MatCreate()
107: @*/
108: PetscErrorCode MatCreateHermitianTranspose(Mat A,Mat *N)
109: {
111: PetscInt m,n;
112: Mat_HT *Na;
115: MatGetLocalSize(A,&m,&n);
116: MatCreate(PetscObjectComm((PetscObject)A),N);
117: MatSetSizes(*N,n,m,PETSC_DECIDE,PETSC_DECIDE);
118: PetscLayoutSetUp((*N)->rmap);
119: PetscLayoutSetUp((*N)->cmap);
120: PetscObjectChangeTypeName((PetscObject)*N,MATTRANSPOSEMAT);
122: PetscNewLog(*N,&Na);
123: (*N)->data = (void*) Na;
124: PetscObjectReference((PetscObject)A);
125: Na->A = A;
127: (*N)->ops->destroy = MatDestroy_HT;
128: (*N)->ops->mult = MatMult_HT;
129: (*N)->ops->multadd = MatMultAdd_HT;
130: (*N)->ops->multhermitiantranspose = MatMultHermitianTranspose_HT;
131: (*N)->ops->multhermitiantransposeadd = MatMultHermitianTransposeAdd_HT;
132: (*N)->ops->duplicate = MatDuplicate_HT;
133: (*N)->assembled = PETSC_TRUE;
135: MatSetBlockSizes(*N,PetscAbs(A->cmap->bs),PetscAbs(A->rmap->bs));
136: MatSetUp(*N);
137: return(0);
138: }