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