Actual source code: petscfunc.h
1: #ifndef PETSCFUNC_H
2: #define PETSCFUNC_H
4: #include petscksp.h
6: /*..Low level timing routine..*/
7: extern "C" float dtime_(float*);
9: /*..KSP monitoring routines..*/
10: extern int KSPMonitorWriteConvHist(KSP ksp,int n,double rnorm,void* ctx);
11: extern int KSPMonitorAmg(KSP ksp,int n,double rnorm,void* ctx);
12: extern int 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 int ConvhistCtxCreate(CONVHIST **convhist);
21: extern int ConvhistCtxDestroy(CONVHIST *convhist);
22: extern int MyConvTest(KSP ksp,int n, double rnorm, KSPConvergedReason *reason,
23: void* ctx);
25: /*..Functions defined for block preconditioners..*/
26: extern int ReorderSubmatrices(PC pc,int nsub,IS *row,IS *col,
27: Mat *submat,void *dummy);
28: extern int PrintSubMatrices(PC pc,int nsub,IS *row,IS *col,
29: Mat *submat,void *dummy);
30: extern int ViewSubMatrices(PC pc,int nsub,IS *row,IS *col,
31: Mat *submat,void *dummy);
32: extern int SamgShellPCSetUpOnFem(PC pc,int nsub,IS *row,IS *col,
33: Mat *submat,void *ctx);
34: extern int KSPMonitorWriteConvHistOnFem(KSP ksp,int n,double rnorm,void* ctx);
36: /*..Viewing and printing matrices and vectors..*/
37: extern int MyMatView(Mat mat,void *dummy);
38: extern int PrintMatrix(Mat mat, char* path, char* base);
39: extern int PrintVector(Vec vec, char* path, char* base);
40: extern int PrintMatrixBinary(Mat mat, char* path, char* base);
41: extern int PrintVectorBinary(Vec vec, char* path, char* base);
43: /*..From the MatCreateFcts collection..*/
44: extern int MatMatMult(Mat Fact1, Mat Fact2, Mat* Prod);
45: extern int 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 int RamgShellPCCreate(RamgShellPC **shell);
60: extern int RamgShellPCSetUp(RamgShellPC *shell, Mat pmat);
61: extern int RamgShellPCApply(void *ctx, Vec r, Vec z);
62: extern int RamgShellPCDestroy(RamgShellPC *shell);
63: extern int 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 int SamgShellPCCreate(SamgShellPC **shell);
76: extern int SamgShellPCSetUp(SamgShellPC *shell, Mat pmat);
77: extern int SamgShellPCApply(void *ctx, Vec r, Vec z);
78: extern int SamgShellPCDestroy(SamgShellPC *shell);
79: extern int 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 int SamgGetCoarseMat(int level, int ia_shift, int ja_shift,
102: Mat* coarsemat, void* ctx);
103: /*..Level 2 routine to get interpolation operators..*/
104: extern int SamgGetInterpolation(int level, int iw_shift, int jw_shift,
105: Mat* interpolation, void* ctx) ;
107: /*..Parse SAMG hierarchy to PETSc..*/
108: extern int SamgGetGrid(int levels, int numnodes, int numnonzero,
109: GridCtx* grid, void* ctx);
110: /*..Check parsing..*/
111: extern int SamgCheckGalerkin(int levels, Mat A, GridCtx* grid,
112: void* ctx);
114: #endif//PETSCFUNC_H