00001 00002 #ifndef LAS_NS_SUPG_PETSC_HPP 00003 #define LAS_NS_SUPG_PETSC_HPP 00004 00005 #include <map> 00006 #include <petscksp.h> 00007 #include <time.h> 00008 #include <math.h> 00009 #include "uth_intf.h" 00010 #include "uth_system.h" 00011 #include "GhostBlockAssemblingUtil.hpp" 00012 00013 #include "AMGSolverStructure.hpp" 00014 #include "ResidualBasedErrorEvaluator.hpp" 00015 #include "KnownSolutionErrorEvaluator.hpp" 00016 #include "las_petsc_intf.hpp" 00017 extern "C" { 00018 #include "../../lsd_mkb/lah_intf.h" 00019 } 00020 #include "ns_supg/MatrixUtil.hpp" 00021 #include "ns_supg/ApproximateInverseOpt.hpp" 00022 #include "ns_supg/VectorTransformationUtil.hpp" 00023 #include "ns_supg/SchurComplement.hpp" 00024 00025 00026 extern struct AMGSolverData amg_solver_data; 00027 00028 int lsr_ns_supg_ext_petsc_init( /* returns: >0 - solver ID, <0 - error code */ 00029 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00030 int Parallel, /* parameter specifying sequential (LSC_SEQUENTIAL) */ 00031 /* or parallel (LSC_PARALLEL) execution */ 00032 int* Max_num_levels_p, /* in: number of levels for multigrid: */ 00033 /* 1 - enforce single level solver */ 00034 /* >1 - enforce the number of levels */ 00035 /* out: actual number of levels !!! */ 00036 char* Filename, /* in: name of the file with control parameters */ 00037 int Max_iter, /* maximal number of iterations, -1 for values from Filename */ 00038 int Error_type, /* type of error norm (stopping criterion), -1 for Filename*/ 00039 double Error_tolerance, /* value for stopping criterion, -1.0 for Filename */ 00040 int Monitoring_level /* Level of output, -1 for Filename */ 00041 ); 00042 00043 00044 int lsr_ns_supg_ext_petsc_create_matrix( 00045 /* returns: >=0 - success code, <0 - error code */ 00046 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00047 int Level_id, /* in: level ID */ 00048 int Nrblocks, /* in: number of DOF blocks */ 00049 int Nrdof_glob, /* in: total number of DOFs */ 00050 int Max_sm_size, /* in: maximal size of the stiffness matrix */ 00051 int* Nrdofbl, /* in: list of numbers of dofs in a block */ 00052 int* Posglob, /* in: list of global numbers of first dof */ 00053 int* Nroffbl, /* in: list of numbers of off diagonal blocks */ 00054 int** L_offbl /* in: list of lists of off diagonal blocks */ 00055 ); 00056 00057 int lsr_ns_supg_ext_petsc_assemble_local_sm( 00058 /* returns: >=0 - success code, <0 - error code */ 00059 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00060 int Level_id, /* in: level ID */ 00061 int Comp_type, /* in: indicator for the scope of computations: */ 00062 /* NS_SUPG_EXT_SOLVE - solve the system */ 00063 /* NS_SUPG_EXT_RESOLVE - resolve for the new rhs vector */ 00064 int Nr_dof_bl, /* in: number of global dof blocks */ 00065 /* associated with the local stiffness matrix */ 00066 int* L_bl_id, /* in: list of dof blocks' IDs */ 00067 int* L_bl_nrdof, /* in: list of blocks' numbers of dof */ 00068 double* Stiff_mat, /* in: stiffness matrix stored columnwise */ 00069 double* Rhs_vect, /* in: rhs vector */ 00070 char* Rewr_dofs /* in: flag to rewrite or sum up entries */ 00071 /* 'T' - true, rewrite entries when assembling */ 00072 /* 'F' - false, sum up entries when assembling */ 00073 ); 00074 00075 int lsr_ns_supg_ext_petsc_assemble_local_mm( 00076 /* returns: >=0 - success code, <0 - error code */ 00077 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00078 int Level_id, /* in: level ID */ 00079 int Comp_type, /* in: indicator for the scope of computations: */ 00080 /* NS_SUPG_EXT_SOLVE - solve the system */ 00081 /* NS_SUPG_EXT_RESOLVE - resolve for the new rhs vector */ 00082 int Nr_dof_bl, /* in: number of global dof blocks */ 00083 /* associated with the local stiffness matrix */ 00084 int* L_bl_id, /* in: list of dof blocks' IDs */ 00085 int* L_bl_nrdof, /* in: list of blocks' numbers of dof */ 00086 double* Stiff_mat, /* in: stiffness matrix stored columnwise */ 00087 double* Rhs_vect, /* in: rhs vector */ 00088 char* Rewr_dofs /* in: flag to rewrite or sum up entries */ 00089 /* 'T' - true, rewrite entries when assembling */ 00090 /* 'F' - false, sum up entries when assembling */ 00091 ); 00092 00093 int lsr_ns_supg_ext_petsc_fill_precon( 00094 /* returns: >=0 - success code, <0 - error code */ 00095 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00096 int Level_id /* in: level ID */ 00097 ); 00098 00099 int lsr_ns_supg_ext_petsc_solve( /* returns: convergence indicator: */ 00100 /* 1 - convergence */ 00101 /* 0 - noconvergence */ 00102 /* <0 - error code */ 00103 int Solver_id, /* in: solver ID */ 00104 int Ndof, /* in: the number of degrees of freedom */ 00105 int Ini_zero, /* in: indicator whether initial guess is zero (0/1) */ 00106 double* X, /* in: the initial guess */ 00107 /* out: the iterated solution */ 00108 double* B, /* in: the rhs vector, if NULL take rhs */ 00109 /* from block data structure */ 00110 int* Nr_iter, /* in: the maximum iterations to be performed */ 00111 /* out: actual number of iterations performed */ 00112 double* Toler, /* in: tolerance level for chosen measure */ 00113 /* out: the final value of convergence measure */ 00114 int Monitor, /* in: flag to determine monitoring level */ 00115 /* 0 - silent run, 1 - warning messages */ 00116 /* 2 - 1+restart data, 3 - 2+iteration data */ 00117 double* Conv_rate /* out: convergence rate */ 00118 ); 00119 00120 void lsr_ns_supg_ext_petsc_compreres ( 00121 int Solver_id, /* in: pointer to solver data structure to be passed 00122 to data structure dependent routines */ 00123 int Subsystem_id, /* in: subsystem data structure to be used */ 00124 int Level_id, /* in: index of the mesh (level) */ 00125 int Control, /* in: indicator whether to compute residual (1) 00126 or matrix-vector product (0) */ 00127 int Ini_zero, /* in: flag for zero input vector X */ 00128 int Ndof, /* in: number of unknowns (components of X and V) */ 00129 double* X, /* in: input vector */ 00130 double* B, /* in: the rhs vector, if NULL take rhs */ 00131 /* from block data structure */ 00132 double* V /* out: output vector, V = M^-1 * ( B - A*X ) */ 00133 ); 00134 00135 int lsr_ns_supg_ext_petsc_free_matrix(int Solver_id); 00136 00137 int lsr_ns_supg_ext_petsc_clear_matrix(int Solver_id, int Level_id, int Comp_type); 00138 00139 double lsr_ns_supg_ext_petsc_compres(int Solver_id, double* X, int Ndof); 00140 00141 void lsr_ns_supg_ext_petsc_compres_vector(int Solver_id, int Ndof, double* X, double* B, double* V); 00142 00143 //for testing 00144 void lsr_ns_supg_ext_petsc_get_system(Mat* Avv, Mat* Avp, Mat* Apv, Mat* App, Vec* v, Vec* p); 00145 00146 #endif