Actual source code: htransm.c
petsc-3.9.4 2018-09-11
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: /*@
75: MatCreateHermitianTranspose - Creates a new matrix object that behaves like A'*
77: Collective on Mat
79: Input Parameter:
80: . A - the (possibly rectangular) matrix
82: Output Parameter:
83: . N - the matrix that represents A'*
85: Level: intermediate
87: Notes: The hermitian transpose A' is NOT actually formed! Rather the new matrix
88: object performs the matrix-vector product by using the MatMultHermitianTranspose() on
89: the original matrix
91: .seealso: MatCreateNormal(), MatMult(), MatMultHermitianTranspose(), MatCreate()
93: @*/
94: PetscErrorCode MatCreateHermitianTranspose(Mat A,Mat *N)
95: {
97: PetscInt m,n;
98: Mat_HT *Na;
101: MatGetLocalSize(A,&m,&n);
102: MatCreate(PetscObjectComm((PetscObject)A),N);
103: MatSetSizes(*N,n,m,PETSC_DECIDE,PETSC_DECIDE);
104: PetscLayoutSetUp((*N)->rmap);
105: PetscLayoutSetUp((*N)->cmap);
106: PetscObjectChangeTypeName((PetscObject)*N,MATTRANSPOSEMAT);
108: PetscNewLog(*N,&Na);
109: (*N)->data = (void*) Na;
110: PetscObjectReference((PetscObject)A);
111: Na->A = A;
113: (*N)->ops->destroy = MatDestroy_HT;
114: (*N)->ops->mult = MatMult_HT;
115: (*N)->ops->multadd = MatMultAdd_HT;
116: (*N)->ops->multhermitiantranspose = MatMultHermitianTranspose_HT;
117: (*N)->ops->multhermitiantransposeadd = MatMultHermitianTransposeAdd_HT;
118: (*N)->ops->duplicate = MatDuplicate_HT;
119: (*N)->assembled = PETSC_TRUE;
121: MatSetBlockSizes(*N,PetscAbs(A->cmap->bs),PetscAbs(A->rmap->bs));
122: MatSetUp(*N);
123: return(0);
124: }