00001 /* lah_intf.h - header for matrix storage and operations package */ 00002 /* Assumption: Each matrix is stored with the corresponding preconditioner */ 00003 00004 /* 00005 lar_allocate_SM_and_LV - to allocate space for stiffness matrix and load vector 00006 lar_initialize_SM_and_LV - to initialize stiffness matrix and/or load vector 00007 lar_get_storage - to compute storage of SM, LV and preconditioner 00008 lar_fill_assembly_table_int_ent - to fill a part of the global assembly table 00009 related to one integration entity, for which 00010 lists of DOF blocks (their global positions) are provided 00011 lar_assemble_SM_and_LV_with_table - to assemble entries to the global stiffness matrix 00012 and the global load vector using the provided local 00013 stiffness matrix and load vector and assembly table 00014 lar_assemble_SM_and_LV - to assemble entries to the global stiffness matrix 00015 and the global load vector using the provided local 00016 stiffness matrix and load vector 00017 lar_free_SM_and_LV - to free space of matrix structure 00018 00019 lar_allocate_preconditioner - to allocate space for preconditioner 00020 lar_fill_preconditioner - to fill preconditioner 00021 lar_free_preconditioner - to free space of preconditioner structure 00022 00023 lar_create_solver_structures_accel - utility to create data structures on GPU 00024 lar_get_crs_data - utility to get CRS parameters and pointers 00025 lar_compute_residual - to compute the residual of the not preconditioned 00026 system of equations, v = ( b - Ax ) 00027 lar_compute_preconditioned_residual - to compute the residual of the 00028 preconditioned system of equations, v = M^-1 * ( b - Ax ) 00029 where M^-1 corresponds directly to the stored preconditioner matrix 00030 lar_perform_BJ_or_GS_iterations - to perform one iteration of block Gauss- 00031 Seidel or block Jacobi algorithm, v_out = v_in + M^-1 * ( b - A * v_in ) 00032 lar_perform_rhsub - to perform forward reduction and back-substitution for ILU 00033 preconditioning 00034 00035 00036 */ 00037 00038 #ifndef _lah_intf_ 00039 #define _lah_intf_ 00040 00041 00042 /*** Constants ***/ 00043 #define LAC_SCOPE_LV 1 00044 #define LAC_SCOPE_SM 2 00045 #define LAC_SCOPE_SM_AND_LV 0 // default 00046 00047 /* preconditioners-smoothers !!! MUST BE THE SAME AS IN SOLVER PACKAGE */ 00048 #define NO_PRECON 0 00049 #define BLOCK_JACOBI 1 00050 #define BLOCK_GS 2 00051 #define ADD_SCHWARZ 3 00052 #define MULTI_ILU 4 00053 #define BLOCK_ILU 5 00054 00055 /* BLAS and LAPACK names with or without underscore */ 00056 #ifdef WITHOUT_ 00057 #define ddot_ ddot 00058 #define dnrm2_ dnrm2 00059 #define dscal_ dscal 00060 #define dcopy_ dcopy 00061 #define daxpy_ daxpy 00062 #define dgemv_ dgemv 00063 #define dgetrf_ dgetrf 00064 #define dgetrs_ dgetrs 00065 #define drot_ drot 00066 #define drotg_ drotg 00067 #define dtrsv_ dtrsv 00068 #endif 00069 00070 /* storage options */ 00071 #define LAC_STORAGE_UNDEFINED -1 00072 #define LAC_STORAGE_BLOCK 1 00073 #define LAC_STORAGE_CRS 2 00074 #define LAC_STORAGE_BCRS 3 00075 #define LAC_STORAGE_CRS_GENERIC 4 00076 #define LAC_STORAGE_PETSC 5 00077 00078 typedef struct { 00079 int Storage_type; // one of types above 00080 int Internal_matrix_id; // matrix ID in storage implementation module 00081 } lat_matrices; 00082 00083 #define LAC_MAX_MATRICES 20 00084 /* GLOBAL VARIABLES */ 00085 extern int lav_nr_matrices; /* the number of solvers in the problem */ 00086 extern int lav_cur_matrix_id; /* ID of the current problem */ 00087 extern lat_matrices lav_matrices[LAC_MAX_MATRICES]; /* array of solvers */ 00088 00092 extern int lar_allocate_SM_and_LV( // returns: matrix index in lav_matrices array 00093 int Storage_type,/* in: enforced storage type; if LAC_STORAGE_UNDEFINED */ 00094 /* storage type is taken from input files or */ 00095 /* decided by software (usually based on Block_size) */ 00096 int solver_type, /* in: solver id ==0 - direct, >0 iterative */ 00097 int Nrdof_glob, /* in: total number of DOFs */ 00098 int Max_SM_size, /* maximal size of element stiffness matrix */ 00099 int Nrblocks, /* in: number of DOF blocks */ 00100 int Block_size, /* in: size of SM blocks (-1 - non-constant size) */ 00101 int* Nrdofbl, /* in: list of numbers of dofs in a block */ 00102 int* Posglob, /* in: list of global numbers of first dof */ 00103 int* Nroffbl, /* in: list of numbers of off diagonal blocks */ 00104 int** L_offbl /* in: list of lists of off diagonal blocks */ 00105 ); 00106 00110 extern int lar_initialize_SM_and_LV( 00111 int Matrix_id, /* in: matrix ID */ 00112 int Scope /* in: indicator for the scope of computations: */ 00113 /* LAC_SCOPE_SM_AND_LV */ 00114 /* LAC_SCOPE_LV - do not touch SM! */ 00115 ); 00116 00120 extern double lar_get_storage( /* returns: storage in MB */ 00121 int Matrix_id /* in: matrix ID */ 00122 ); 00123 00129 extern int lar_fill_assembly_table_int_ent( 00130 /* returns: >=0 - success code, <0 - error code */ 00131 int Matrix_id, /* in: matrix ID */ 00132 int Nr_dof_bl, /* in: number of global dof blocks */ 00133 /* associated with the local stiffness matrix */ 00134 int* L_bl_id, /* in: list of dof blocks' IDs */ 00135 int* L_bl_nrdof, /* in: list of blocks' numbers of dof */ 00136 int *Assembly_table_int_ent /* part of the global assembly table */ 00137 ); 00138 00139 00140 /*------------------------------------------------------------ 00141 lar_assemble_SM_and_LV_with_table - to assemble entries to the global stiffness matrix 00142 and the global load vector using the provided local 00143 stiffness matrix and load vector and assembly table 00144 ------------------------------------------------------------*/ 00145 extern int lar_assemble_SM_and_LV_with_table( 00146 /* returns: >=0 - success code, <0 - error code */ 00147 int Matrix_id, /* in: matrix ID */ 00148 int Scope, /* in: indicator for the scope of computations: */ 00149 /* LAC_SCOPE_SM_AND_LV */ 00150 /* LAC_SCOPE_LV - do not touch SM! */ 00151 int Nr_dof_bl, /* in: number of global dof blocks */ 00152 /* associated with the local stiffness matrix */ 00153 int* Assembly_table_int_ent, /* part of the global assembly table */ 00154 int* Local_to_global_int_ent, /* part of the global local_to_global table */ 00155 double* Stiff_mat, /* in: stiffness matrix stored columnwise */ 00156 double* Rhs_vect, /* in: rhs vector */ 00157 char* Rewr_dofs /* in: flag to rewrite or sum up entries */ 00158 /* 'T' - true, rewrite entries when assembling */ 00159 /* 'F' - false, sum up entries when assembling */ 00160 ); 00161 00167 extern int lar_assemble_SM_and_LV( 00168 /* returns: >=0 - success code, <0 - error code */ 00169 int Matrix_id, /* in: matrix ID */ 00170 int Scope, /* in: indicator for the scope of computations: */ 00171 /* LAC_SCOPE_SM_AND_LV */ 00172 /* LAC_SCOPE_LV - do not touch SM! */ 00173 int Nr_dof_bl, /* in: number of global dof blocks */ 00174 /* associated with the local stiffness matrix */ 00175 int* L_bl_id, /* in: list of dof blocks' IDs */ 00176 int* L_bl_nrdof, /* in: list of blocks' numbers of dof */ 00177 double* Stiff_mat, /* in: stiffness matrix stored columnwise */ 00178 double* Rhs_vect, /* in: rhs vector */ 00179 char* Rewr_dofs /* in: flag to rewrite or sum up entries */ 00180 /* 'T' - true, rewrite entries when assembling */ 00181 /* 'F' - false, sum up entries when assembling */ 00182 ); 00183 00187 extern int lar_create_solver_structures_accel( 00188 int Matrix_id /* in: matrix ID */ 00189 ); 00190 00194 int lar_get_crs_data( /* returns: >0 - success code, <0 - error code */ 00195 int Matrix_id, /* in: matrix ID */ 00196 int* Nrdof_glob_p, /* output pointers: nrdof, nnz etc. - self explanatory */ 00197 int* Nnz_p, 00198 int** Crs_col_ind_p, 00199 int** Crs_row_ptr_p, 00200 double** Crs_val_p, 00201 double** Rhs_p 00202 ); 00203 00207 extern int lar_free_SM_and_LV( 00208 int Matrix_id /* in: matrix ID */ 00209 ); 00210 00211 00215 extern int lar_allocate_preconditioner( /* returns: >0 number of diagonal blocks */ 00216 /* <=0 - error */ 00217 int Matrix_id, /* in: matrix ID */ 00218 int Precon, /* in: type of preconditioner (lah_block.h line circa 45) */ 00219 int Second_arg // in: for ILU(k) - k; 00220 // for all other: Block_type for preconditioner blocks */ 00221 ); 00222 00226 extern int lar_fill_preconditioner( 00227 int Matrix_id /* in: matrix ID */ 00228 ); 00229 00233 extern int lar_free_preconditioner( 00234 int Matrix_id /* in: matrix ID */ 00235 ); 00236 00237 00242 extern void lar_compute_residual ( 00243 int Matrix_id, /* in: matrix ID */ 00244 int Use_rhs, /* in: indicator whether to use RHS */ 00245 int Ini_zero, /* in: flag for zero initial guess */ 00246 int Ndof, /* in: number of unknowns (components of x) */ 00247 double* X, /* in: initial guess vector */ 00248 double* B, /* in: the rhs vector, if NULL take rhs */ 00249 /* from block data structure */ 00250 double* V /* out: residual, v = ( b-Ax ) */ 00251 ); 00252 00253 // TODO ? 00259 /* extern void lar_compute_preconditioned_residual ( */ 00260 /* int Matrix_id, /\* in: matrix ID *\/ */ 00261 /* int Use_rhs, /\* in: indicator whether to use RHS *\/ */ 00262 /* int Ini_zero, /\* in: flag for zero initial guess *\/ */ 00263 /* int Ndof, /\* in: number of unknowns (components of x) *\/ */ 00264 /* double* X, /\* in: initial guess vector *\/ */ 00265 /* double* B, /\* in: the rhs vector, if NULL take rhs *\/ */ 00266 /* /\* from block data structure *\/ */ 00267 /* double* V /\* out: preconditioned residual, v = M^-1*(b-Ax) *\/ */ 00268 /* ); */ 00269 00275 extern void lar_perform_BJ_or_GS_iterations( 00276 int Matrix_id, /* in: matrix ID */ 00277 int Use_rhs, /* in: 0 - no rhs, 1 - with rhs */ 00278 int Ini_zero, /* in: flag for zero initial guess */ 00279 int Nr_prec, /* in: number of preconditioner iterations */ 00280 int Ndof, /* in: number of unknowns (components of v*) */ 00281 double* V, /* in,out: vector of unknowns updated */ 00282 /* during the loop over subdomains */ 00283 double* B /* in: the rhs vector, if NULL take rhs */ 00284 /* from block data structure */ 00285 ); 00286 00287 00292 extern void lar_perform_rhsub( 00293 int Matrix_id, /* in: matrix ID */ 00294 int Ndof, /* in: number of unknowns (components of v*) */ 00295 double* V, /* in,out: vector of unknowns updated */ 00296 /* during the loop over subdomains */ 00297 double* B /* in: the rhs vector, if NULL take rhs */ 00298 /* from block data structure */ 00299 ); 00300 00301 00305 extern int lar_get_SM_and_LV_crs( // returns: flag - 0 if not needed delete crs matrices 00306 int Matrix_id, /* in: matrix ID */ 00307 int offset, /* in: offset in crs_row and crs_col matrix */ 00308 int** crs_row, /* out: matrix of rows in crs */ 00309 int** crs_col, /* out: matrix of column in crs */ 00310 double** crs_val, /* out: matrix of value in crs */ 00311 double** rhs /* out: rhs vector */ 00312 ); 00313 00314 00315 #endif