Actual source code: petscfunc.h
1: #ifndef PETSCFUNC_H
2: #define PETSCFUNC_H
4: #include petscksp.h
6: /*..Low level timing routine..*/
9: /*..KSP monitoring routines..*/
10: EXTERN PetscErrorCode KSPMonitorWriteConvHist(KSP ksp,int n,double rnorm,void* ctx);
11: EXTERN PetscErrorCode KSPMonitorAmg(KSP ksp,int n,double rnorm,void* ctx);
12: EXTERN PetscErrorCode KSPMonitorWriteResVecs(KSP ksp,int n,double rnorm,void* ctx);
14: /*..KSP convergence criteria routines..*/
15: typedef struct{
16: double BNRM2;
17: int NUMNODES;
18: }CONVHIST;
20: EXTERN PetscErrorCode ConvhistCtxCreate(CONVHIST **convhist);
21: EXTERN PetscErrorCode ConvhistCtxDestroy(CONVHIST *convhist);
22: EXTERN PetscErrorCode MyConvTest(KSP ksp,int n, double rnorm, KSPConvergedReason *reason,
23: void* ctx);
25: /*..Functions defined for block preconditioners..*/
26: EXTERN PetscErrorCode ReorderSubmatrices(PC pc,int nsub,IS *row,IS *col,
27: Mat *submat,void *dummy);
28: EXTERN PetscErrorCode PrintSubMatrices(PC pc,int nsub,IS *row,IS *col,
29: Mat *submat,void *dummy);
30: EXTERN PetscErrorCode ViewSubMatrices(PC pc,int nsub,IS *row,IS *col,
31: Mat *submat,void *dummy);
32: EXTERN PetscErrorCode SamgShellPCSetUpOnFem(PC pc,int nsub,IS *row,IS *col,
33: Mat *submat,void *ctx);
34: EXTERN PetscErrorCode KSPMonitorWriteConvHistOnFem(KSP ksp,int n,double rnorm,void* ctx);
36: /*..Viewing and printing matrices and vectors..*/
37: EXTERN PetscErrorCode MyMatView(Mat mat,void *dummy);
38: EXTERN PetscErrorCode PrintMatrix(Mat mat, char* path, char* base);
39: EXTERN PetscErrorCode PrintVector(Vec vec, char* path, char* base);
40: EXTERN PetscErrorCode PrintMatrixBinary(Mat mat, char* path, char* base);
41: EXTERN PetscErrorCode PrintVectorBinary(Vec vec, char* path, char* base);
43: /*..From the MatCreateFcts collection..*/
44: EXTERN PetscErrorCode MatMatMult(Mat Fact1, Mat Fact2, Mat* Prod);
45: EXTERN PetscErrorCode MatSubstract(Mat Term1, Mat Term2, Mat* Diff);
47: /*..Structure used in the interface to RAMG..*/
48: typedef struct{
49: double *A;
50: int *IA;
51: int *JA;
52: double *U_APPROX;
53: double *RHS;
54: int *IG;
55: struct RAMG_PARAM *PARAM;
56: } RamgShellPC;
58: /*..interface to RAMG..*/
59: EXTERN PetscErrorCode RamgShellPCCreate(RamgShellPC **shell);
60: EXTERN PetscErrorCode RamgShellPCSetUp(RamgShellPC *shell, Mat pmat);
61: EXTERN PetscErrorCode RamgShellPCApply(void *ctx, Vec r, Vec z);
62: EXTERN PetscErrorCode RamgShellPCDestroy(RamgShellPC *shell);
63: EXTERN PetscErrorCode RamgGetParam(RAMG_PARAM *ramg_param);
65: /*..Structure used in the interface to SAMG..*/
66: typedef struct{
67: double *A;
68: int *IA;
69: int *JA;
70: struct SAMG_PARAM *PARAM;
71: int LEVELS; /* Number of levels created */
72: } SamgShellPC;
74: /*..Interface to SAMG..*/
75: EXTERN PetscErrorCode SamgShellPCCreate(SamgShellPC **shell);
76: EXTERN PetscErrorCode SamgShellPCSetUp(SamgShellPC *shell, Mat pmat);
77: EXTERN PetscErrorCode SamgShellPCApply(void *ctx, Vec r, Vec z);
78: EXTERN PetscErrorCode SamgShellPCDestroy(SamgShellPC *shell);
79: EXTERN PetscErrorCode SamgGetParam(SAMG_PARAM *samg_param);
81: /*..Multigrid structure for PETSc..*/
83: /*....Maximum number of levels to be used in SAMG....*/
84: #define MAX_LEVELS 25
86: typedef struct{
87: /*..Implementation notes
88: 1 - The menber A is not stored on level 1 (the finest level in SAMG
89: ordering) to avoid unnecessary memory useage.
90: */
91: KSP ksp_pre;
92: KSP ksp_post;
93: Mat A, B, C;
94: Mat Interp;
95: Vec x, b, upd_b, r, y, b_y, r_y;
96: int size; /*..Number of variables on level..*/
97: // int debug;
98: } GridCtx;
100: /*..Level 2 routine to get coarser level matrices..*/
101: EXTERN PetscErrorCode SamgGetCoarseMat(int level, int ia_shift, int ja_shift,
102: Mat* coarsemat, void* ctx);
103: /*..Level 2 routine to get interpolation operators..*/
104: EXTERN PetscErrorCode SamgGetInterpolation(int level, int iw_shift, int jw_shift,
105: Mat* interpolation, void* ctx) ;
107: /*..Parse SAMG hierarchy to PETSc..*/
108: EXTERN PetscErrorCode SamgGetGrid(int levels, int numnodes, int numnonzero,
109: GridCtx* grid, void* ctx);
110: /*..Check parsing..*/
111: EXTERN PetscErrorCode SamgCheckGalerkin(int levels, Mat A, GridCtx* grid,
112: void* ctx);
114: #endif//PETSCFUNC_H