xref: /petsc/src/mat/impls/shell/shell.h (revision 326b75730a5af0b195df366d5ee217732c498605)
1 #pragma once
2 
3 #include <petsc/private/matimpl.h>
4 #include <petsc/private/vecimpl.h>
5 
6 struct _MatShellOps {
7   /*   3 */ PetscErrorCode (*mult)(Mat, Vec, Vec);
8   /*   5 */ PetscErrorCode (*multtranspose)(Mat, Vec, Vec);
9   /*  17 */ PetscErrorCode (*getdiagonal)(Mat, Vec);
10   /*  43 */ PetscErrorCode (*copy)(Mat, Mat, MatStructure);
11   /*  60 */ PetscErrorCode (*destroy)(Mat);
12   /* 121 */ PetscErrorCode (*multhermitiantranspose)(Mat, Vec, Vec);
13 };
14 
15 struct _n_MatShellMatFunctionList {
16   PetscErrorCode (*symbolic)(Mat, Mat, Mat, void **);
17   PetscErrorCode (*numeric)(Mat, Mat, Mat, void *);
18   PetscErrorCode (*destroy)(void *);
19   MatProductType ptype;
20   char          *composedname; /* string to identify routine with double dispatch */
21   char          *resultname;   /* result matrix type */
22 
23   struct _n_MatShellMatFunctionList *next;
24 };
25 typedef struct _n_MatShellMatFunctionList *MatShellMatFunctionList;
26 
27 typedef struct {
28   struct _MatShellOps ops[1];
29 
30   /* The user will manage the scaling and shifts for the MATSHELL, not the default */
31   PetscBool managescalingshifts;
32 
33   /* support for MatScale, MatShift and MatMultAdd */
34   PetscScalar vscale, vshift;
35   Vec         dshift;
36   Vec         left, right;
37   Vec         left_work, right_work;
38   Vec         left_add_work, right_add_work;
39 
40   /* support for MatAXPY */
41   Mat              axpy;
42   PetscScalar      axpy_vscale;
43   Vec              axpy_left, axpy_right;
44   PetscObjectState axpy_state;
45 
46   /* support for ZeroRows/Columns operations */
47   IS         zrows;
48   IS         zcols;
49   Vec        zvals;
50   Vec        zvals_w;
51   VecScatter zvals_sct_r;
52   VecScatter zvals_sct_c;
53 
54   /* MatMat operations */
55   MatShellMatFunctionList matmat;
56 
57   /* user defined context */
58   PetscContainer ctxcontainer;
59 } Mat_Shell;
60 
61 PETSC_INTERN PetscErrorCode MatAssemblyEnd_Shell(Mat X, MatAssemblyType assembly);
62 PETSC_INTERN PetscErrorCode MatShellSetContext_Immutable(Mat X, void *ctx);
63 PETSC_INTERN PetscErrorCode MatShellSetContextDestroy_Immutable(Mat X, PetscErrorCode (*f)(void *));
64 PETSC_INTERN PetscErrorCode MatShellSetManageScalingShifts_Immutable(Mat X);
65