Actual source code: htransm.c
petsc-3.12.5 2020-03-29
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 MatAXPY_HT(Mat Y,PetscScalar a,Mat X,MatStructure str)
85: {
86: Mat_HT *Ya = (Mat_HT*)Y->data;
87: Mat_HT *Xa = (Mat_HT*)X->data;
88: Mat M = Ya->A;
89: Mat N = Xa->A;
93: MatAXPY(M,a,N,str);
94: return(0);
95: }
97: PetscErrorCode MatHermitianTransposeGetMat_HT(Mat N,Mat *M)
98: {
99: Mat_HT *Na = (Mat_HT*)N->data;
102: *M = Na->A;
103: return(0);
104: }
106: /*@
107: MatHermitianTransposeGetMat - Gets the Mat object stored inside a MATTRANSPOSEMAT
109: Logically collective on Mat
111: Input Parameter:
112: . A - the MATTRANSPOSE matrix
114: Output Parameter:
115: . M - the matrix object stored inside A
117: Level: intermediate
119: .seealso: MatCreateHermitianTranspose()
121: @*/
122: PetscErrorCode MatHermitianTransposeGetMat(Mat A,Mat *M)
123: {
130: PetscUseMethod(A,"MatHermitianTransposeGetMat_C",(Mat,Mat*),(A,M));
131: return(0);
132: }
134: /*@
135: MatCreateHermitianTranspose - Creates a new matrix object that behaves like A'*
137: Collective on Mat
139: Input Parameter:
140: . A - the (possibly rectangular) matrix
142: Output Parameter:
143: . N - the matrix that represents A'*
145: Level: intermediate
147: Notes:
148: The hermitian transpose A' is NOT actually formed! Rather the new matrix
149: object performs the matrix-vector product by using the MatMultHermitianTranspose() on
150: the original matrix
152: .seealso: MatCreateNormal(), MatMult(), MatMultHermitianTranspose(), MatCreate()
154: @*/
155: PetscErrorCode MatCreateHermitianTranspose(Mat A,Mat *N)
156: {
158: PetscInt m,n;
159: Mat_HT *Na;
162: MatGetLocalSize(A,&m,&n);
163: MatCreate(PetscObjectComm((PetscObject)A),N);
164: MatSetSizes(*N,n,m,PETSC_DECIDE,PETSC_DECIDE);
165: PetscLayoutSetUp((*N)->rmap);
166: PetscLayoutSetUp((*N)->cmap);
167: PetscObjectChangeTypeName((PetscObject)*N,MATTRANSPOSEMAT);
169: PetscNewLog(*N,&Na);
170: (*N)->data = (void*) Na;
171: PetscObjectReference((PetscObject)A);
172: Na->A = A;
174: (*N)->ops->destroy = MatDestroy_HT;
175: (*N)->ops->mult = MatMult_HT;
176: (*N)->ops->multadd = MatMultAdd_HT;
177: (*N)->ops->multhermitiantranspose = MatMultHermitianTranspose_HT;
178: (*N)->ops->multhermitiantransposeadd = MatMultHermitianTransposeAdd_HT;
179: (*N)->ops->duplicate = MatDuplicate_HT;
180: (*N)->ops->getvecs = MatCreateVecs_HT;
181: (*N)->ops->axpy = MatAXPY_HT;
182: (*N)->assembled = PETSC_TRUE;
184: PetscObjectComposeFunction((PetscObject)(*N),"MatHermitianTransposeGetMat_C",MatHermitianTransposeGetMat_HT);
185: MatSetBlockSizes(*N,PetscAbs(A->cmap->bs),PetscAbs(A->rmap->bs));
186: MatSetUp(*N);
187: return(0);
188: }