Actual source code: htransm.c
petsc-3.11.4 2019-09-28
2: #include <petsc/private/matimpl.h>
4: typedef struct {
5: Mat A;
6: } Mat_HT;
8: PetscErrorCode MatMult_HT(Mat N,Vec x,Vec y)
9: {
10: Mat_HT *Na = (Mat_HT*)N->data;
14: MatMultHermitianTranspose(Na->A,x,y);
15: return(0);
16: }
18: PetscErrorCode MatMultAdd_HT(Mat N,Vec v1,Vec v2,Vec v3)
19: {
20: Mat_HT *Na = (Mat_HT*)N->data;
24: MatMultHermitianTransposeAdd(Na->A,v1,v2,v3);
25: return(0);
26: }
28: PetscErrorCode MatMultHermitianTranspose_HT(Mat N,Vec x,Vec y)
29: {
30: Mat_HT *Na = (Mat_HT*)N->data;
34: MatMult(Na->A,x,y);
35: return(0);
36: }
38: PetscErrorCode MatMultHermitianTransposeAdd_HT(Mat N,Vec v1,Vec v2,Vec v3)
39: {
40: Mat_HT *Na = (Mat_HT*)N->data;
44: MatMultAdd(Na->A,v1,v2,v3);
45: return(0);
46: }
48: PetscErrorCode MatDestroy_HT(Mat N)
49: {
50: Mat_HT *Na = (Mat_HT*)N->data;
54: MatDestroy(&Na->A);
55: PetscFree(N->data);
56: return(0);
57: }
59: PetscErrorCode MatDuplicate_HT(Mat N, MatDuplicateOption op, Mat* m)
60: {
61: Mat_HT *Na = (Mat_HT*)N->data;
65: if (op == MAT_COPY_VALUES) {
66: MatHermitianTranspose(Na->A,MAT_INITIAL_MATRIX,m);
67: } else if (op == MAT_DO_NOT_COPY_VALUES) {
68: MatDuplicate(Na->A,MAT_DO_NOT_COPY_VALUES,m);
69: MatHermitianTranspose(*m,MAT_INPLACE_MATRIX,m);
70: } else SETERRQ(PetscObjectComm((PetscObject)N),PETSC_ERR_SUP,"MAT_SHARE_NONZERO_PATTERN not supported for this matrix type");
71: return(0);
72: }
74: PetscErrorCode MatCreateVecs_HT(Mat N,Vec *r, Vec *l)
75: {
76: Mat_HT *Na = (Mat_HT*)N->data;
80: MatCreateVecs(Na->A,l,r);
81: return(0);
82: }
84: PetscErrorCode MatHermitianTransposeGetMat_HT(Mat N,Mat *M)
85: {
86: Mat_HT *Na = (Mat_HT*)N->data;
89: *M = Na->A;
90: return(0);
91: }
93: /*@
94: MatHermitianTransposeGetMat - Gets the Mat object stored inside a MATTRANSPOSEMAT
96: Logically collective on Mat
98: Input Parameter:
99: . A - the MATTRANSPOSE matrix
101: Output Parameter:
102: . M - the matrix object stored inside A
104: Level: intermediate
106: .seealso: MatCreateHermitianTranspose()
108: @*/
109: PetscErrorCode MatHermitianTransposeGetMat(Mat A,Mat *M)
110: {
117: PetscUseMethod(A,"MatHermitianTransposeGetMat_C",(Mat,Mat*),(A,M));
118: return(0);
119: }
121: /*@
122: MatCreateHermitianTranspose - Creates a new matrix object that behaves like A'*
124: Collective on Mat
126: Input Parameter:
127: . A - the (possibly rectangular) matrix
129: Output Parameter:
130: . N - the matrix that represents A'*
132: Level: intermediate
134: Notes:
135: The hermitian transpose A' is NOT actually formed! Rather the new matrix
136: object performs the matrix-vector product by using the MatMultHermitianTranspose() on
137: the original matrix
139: .seealso: MatCreateNormal(), MatMult(), MatMultHermitianTranspose(), MatCreate()
141: @*/
142: PetscErrorCode MatCreateHermitianTranspose(Mat A,Mat *N)
143: {
145: PetscInt m,n;
146: Mat_HT *Na;
149: MatGetLocalSize(A,&m,&n);
150: MatCreate(PetscObjectComm((PetscObject)A),N);
151: MatSetSizes(*N,n,m,PETSC_DECIDE,PETSC_DECIDE);
152: PetscLayoutSetUp((*N)->rmap);
153: PetscLayoutSetUp((*N)->cmap);
154: PetscObjectChangeTypeName((PetscObject)*N,MATTRANSPOSEMAT);
156: PetscNewLog(*N,&Na);
157: (*N)->data = (void*) Na;
158: PetscObjectReference((PetscObject)A);
159: Na->A = A;
161: (*N)->ops->destroy = MatDestroy_HT;
162: (*N)->ops->mult = MatMult_HT;
163: (*N)->ops->multadd = MatMultAdd_HT;
164: (*N)->ops->multhermitiantranspose = MatMultHermitianTranspose_HT;
165: (*N)->ops->multhermitiantransposeadd = MatMultHermitianTransposeAdd_HT;
166: (*N)->ops->duplicate = MatDuplicate_HT;
167: (*N)->ops->getvecs = MatCreateVecs_HT;
168: (*N)->assembled = PETSC_TRUE;
170: PetscObjectComposeFunction((PetscObject)(*N),"MatHermitianTransposeGetMat_C",MatHermitianTransposeGetMat_HT);
171: MatSetBlockSizes(*N,PetscAbs(A->cmap->bs),PetscAbs(A->rmap->bs));
172: MatSetUp(*N);
173: return(0);
174: }