00001 /************************************************************************ 00002 lah_intf.h - header for matrix storage and operations package 00003 00004 Assumption: Each matrix is stored with the corresponding preconditioner 00005 00006 00007 lar_allocate_SM_and_LV - to allocate space for stiffness matrix and load vector 00008 lar_initialize_SM_and_LV - to initialize stiffness matrix and/or load vector 00009 lar_get_storage - to compute storage of SM, LV and preconditioner 00010 lar_fill_assembly_table_int_ent - to fill a part of the global assembly table 00011 related to one integration entity, for which 00012 lists of DOF blocks (their global positions) are provided 00013 lar_assemble_SM_and_LV_with_table - to assemble entries to the global stiffness matrix 00014 and the global load vector using the provided local 00015 stiffness matrix and load vector and assembly table 00016 lar_assemble_SM_and_LV - to assemble entries to the global stiffness matrix 00017 and the global load vector using the provided local 00018 stiffness matrix and load vector 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 lar_free_SM_and_LV - to free space of matrix structure 00023 00024 lar_create_solver_structures_accel - utility to create data structures on GPU 00025 lar_get_crs_data - utility to get CRS parameters and pointers 00026 lar_compute_residual - to compute the residual of the not preconditioned 00027 system of equations, v = ( b - Ax ) 00028 lar_compute_preconditioned_residual_crs_generic - to compute the residual of the 00029 preconditioned system of equations, v = M^-1 * ( b - Ax ) 00030 where M^-1 corresponds directly to the stored preconditioner matrix 00031 lar_perform_BJ_or_GS_iterations - to perform one iteration of block Gauss- 00032 Seidel or block Jacobi algorithm, v_out = v_in + M^-1 * ( b - A * v_in ) 00033 lar_perform_rhsub - to perform forward reduction and back-substitution for ILU 00034 preconditioning 00035 00036 *************************************************************************/ 00037 00038 #ifndef _lah_crs_generic_ 00039 #define _lah_crs_generic_ 00040 00041 /*** External Parameters ***/ 00042 #define ITC_MAX_MATRICES 20 00043 00044 /*** Data types ***/ 00045 00046 typedef struct { 00047 00048 00049 /* parameters */ 00050 int Max_SM_size; /* the maximal number of dofs in a stiffness matrix */ 00051 int Nrblocks; /* total number of small blocks */ 00052 int Nrdofgl; /* total number of degrees of freedom */ 00053 int Nrdof_internal; /* internal number of degrees of freedom */ 00054 int Nnz; /* total number of non-zero elements */ 00055 int Half_bandwidth; /* FEM matrices are banded... */ 00056 00057 int *posg; 00058 00059 int Precon; 00060 int ILU_k; // number of neighborhood rings for ILU(k) 00061 00062 double *rhs; /* the global right hand side vector */ 00063 00064 /* crs matrix */ 00065 double *crs_val; 00066 int *crs_col_ind; 00067 int *crs_row_ptr; 00068 00069 /* preconditioner */ 00070 int *diag_ptr; 00071 double *diag_precon; 00072 00073 } itt_crs_generic_matrices; 00074 00075 00076 /* GLOBAL VARIABLES */ 00077 extern int itv_nr_crs_generic_matrices; /* the number of matrices managed by module */ 00078 extern int itv_cur_crs_generic_matrix_id; /* ID of the current matrix */ 00079 extern itt_crs_generic_matrices itv_crs_generic_matrices[LAC_MAX_MATRICES]; 00080 /* array of CRS matrices */ 00081 00082 00083 00084 /*--------------------------------------------------------- 00085 lar_allocate_SM_and_LV_crs_generic - to allocate space for stiffness matrix and load vector 00086 ---------------------------------------------------------*/ 00087 extern int lar_allocate_SM_and_LV_crs_generic( // returns: matrix index in itv_crs_generic_matrices array 00088 int Nrdof_glob, /* in: total number of DOFs */ 00089 int Max_SM_size, /* maximal size of element stiffness matrix */ 00090 int Nrblocks, /* in: number of DOF blocks */ 00091 int* Nrdofbl, /* in: list of numbers of dofs in a block */ 00092 int* Posglob, /* in: list of global numbers of first dof */ 00093 int* Nroffbl, /* in: list of numbers of off diagonal blocks */ 00094 // if Nroffbl[iblock]==0 - iblock is a ghost block with no rows associated with 00095 int** L_offbl /* in: list of lists of off diagonal blocks */ 00096 ); 00097 00098 00102 extern int lar_initialize_SM_and_LV_crs_generic( 00103 int Matrix_id, /* in: matrix ID */ 00104 int Scope /* in: indicator for the scope of computations: */ 00105 /* LAC_SCOPE_SM_AND_LV */ 00106 /* LAC_SCOPE_LV - do not touch SM! */ 00107 ); 00108 00112 extern double lar_get_storage_crs_generic( /* returns: storage in MB */ 00113 int Matrix_id /* in: matrix ID */ 00114 ); 00115 00121 extern int lar_fill_assembly_table_int_ent_crs_generic( 00122 /* returns: >=0 - success code, <0 - error code */ 00123 int Matrix_id, /* in: matrix ID */ 00124 int Nr_dof_bl, /* in: number of global dof blocks */ 00125 /* associated with the local stiffness matrix */ 00126 int* L_bl_id, /* in: list of dof blocks' IDs */ 00127 int* L_bl_nrdof, /* in: list of blocks' numbers of dof */ 00128 int *Assembly_table_int_ent /* part of the global assembly table */ 00129 ); 00130 00131 00132 /*------------------------------------------------------------ 00133 lar_assemble_SM_and_LV_with_table_crs_generic - to assemble entries to the global stiffness matrix 00134 and the global load vector using the provided local 00135 stiffness matrix and load vector and assembly table 00136 ------------------------------------------------------------*/ 00137 extern int lar_assemble_SM_and_LV_with_table_crs_generic( 00138 /* returns: >=0 - success code, <0 - error code */ 00139 int Matrix_id, /* in: matrix ID */ 00140 int Scope, /* in: indicator for the scope of computations: */ 00141 /* LAC_SCOPE_SM_AND_LV */ 00142 /* LAC_SCOPE_LV - do not touch SM! */ 00143 int Nr_dof_bl, /* in: number of global dof blocks */ 00144 /* associated with the local stiffness matrix */ 00145 int* Assembly_table_int_ent, /* part of the global assembly table */ 00146 int* Local_to_global_int_ent, /* part of the global local_to_global table */ 00147 double* Stiff_mat, /* in: stiffness matrix stored columnwise */ 00148 double* Rhs_vect, /* in: rhs vector */ 00149 char* Rewr_dofs /* in: flag to rewrite or sum up entries */ 00150 /* 'T' - true, rewrite entries when assembling */ 00151 /* 'F' - false, sum up entries when assembling */ 00152 ); 00153 00154 /*------------------------------------------------------------ 00155 lar_assemble_SM_and_LV_crs_generic - to assemble entries to the global stiffness matrix 00156 and the global load vector using the provided local 00157 stiffness matrix and load vector 00158 ------------------------------------------------------------*/ 00159 extern int lar_assemble_SM_and_LV_crs_generic( 00160 /* returns: >=0 - success code, <0 - error code */ 00161 int Matrix_id, /* in: matrix ID */ 00162 int Scope, /* in: indicator for the scope of computations: */ 00163 /* LAC_SCOPE_SM_AND_LV */ 00164 /* LAC_SCOPE_LV - do not touch SM! */ 00165 int Nr_dof_bl, /* in: number of global dof blocks */ 00166 /* associated with the local stiffness matrix */ 00167 int* L_bl_id, /* in: list of dof blocks' IDs */ 00168 int* L_bl_nrdof, /* in: list of blocks' numbers of dof */ 00169 double* Stiff_mat, /* in: stiffness matrix stored columnwise */ 00170 double* Rhs_vect, /* in: rhs vector */ 00171 char* Rewr_dofs /* in: flag to rewrite or sum up entries */ 00172 /* 'T' - true, rewrite entries when assembling */ 00173 /* 'F' - false, sum up entries when assembling */ 00174 ); 00175 00176 00180 extern int lar_allocate_preconditioner_crs_generic( /* returns: >0 number of diagonal blocks */ 00181 /* <=0 - error */ 00182 int Matrix_id, /* in: matrix ID */ 00183 int Precon, /* in: type of preconditioner (lah_block.h line circa 45) */ 00184 int ILU_k // in: for ILU(k) - k; 00185 ); 00186 00190 extern int lar_fill_preconditioner_crs_generic( 00191 int Matrix_id /* in: matrix ID */ 00192 ); 00193 00197 extern int lar_free_preconditioner_crs_generic( 00198 int Matrix_id /* in: matrix ID */ 00199 ); 00200 00204 extern int lar_create_solver_structures_accel_crs_generic( 00205 int Matrix_id /* in: matrix ID */ 00206 ); 00207 00211 int lar_get_crs_data_crs_generic( /* returns: >0 - success code, <0 - error code */ 00212 int Matrix_id, /* in: matrix ID */ 00213 int* Nrdof_glob_p, /* output pointers: nrdof, nnz etc. - self explanatory */ 00214 int* Nnz_p, 00215 int** Crs_col_ind_p, 00216 int** Crs_row_ptr_p, 00217 double** Crs_val_p, 00218 double** Rhs_p 00219 ); 00220 00221 /*--------------------------------------------------------- 00222 lar_free_SM_and_LV_crs_generic - to free space for a block structure 00223 ---------------------------------------------------------*/ 00224 extern int lar_free_SM_and_LV_crs_generic( 00225 int Matrix_id /* in: matrix ID */ 00226 ); 00227 00228 /*--------------------------------------------------------- 00229 lar_compute_residual_crs_generic - to compute the residual of the system of equations, 00230 v = ( b - Ax ) (used also to compute the product v = -Ax) 00231 ---------------------------------------------------------*/ 00232 extern void lar_compute_residual_crs_generic( 00233 int Matrix_id, /* in: matrix ID */ 00234 int Use_rhs, /* in: indicator whether to use RHS */ 00235 int Ini_zero, /* in: flag for zero initial guess */ 00236 int Ndof, /* in: number of unknowns (components of x) */ 00237 double* X, /* in: input vector (may be NULL if Ini_zero==0) */ 00238 double* B, /* in: the rhs vector, if NULL take rhs */ 00239 /* from block data structure ( B is not taken */ 00240 /* into account if Use_rhs!=1) */ 00241 double* V /* out: v = b-Ax */ 00242 ); 00243 00249 extern void lar_compute_preconditioned_residual_crs_generic ( 00250 int Matrix_id, /* in: matrix ID */ 00251 int Use_rhs, /* in: indicator whether to use RHS */ 00252 int Ini_zero, /* in: flag for zero initial guess */ 00253 int Ndof, /* in: number of unknowns (components of x) */ 00254 double* X, /* in: initial guess vector */ 00255 double* B, /* in: the rhs vector, if NULL take rhs */ 00256 /* from block data structure */ 00257 double* V /* out: preconditioned residual, v = M^-1*(b-Ax) */ 00258 ); 00259 00265 extern void lar_perform_BJ_or_GS_iterations_crs_generic( 00266 int Matrix_id, /* in: matrix ID */ 00267 int Use_rhs, /* in: 0 - no rhs, 1 - with rhs */ 00268 int Ini_zero, /* in: flag for zero initial guess */ 00269 int Nr_prec, /* in: number of preconditioner iterations */ 00270 int Ndof, /* in: number of unknowns (components of v*) */ 00271 double* V, /* in,out: vector of unknowns updated */ 00272 /* during the loop over subdomains */ 00273 double* B /* in: the rhs vector, if NULL take rhs */ 00274 /* from block data structure */ 00275 ); 00276 00277 00282 extern void lar_perform_rhsub_crs_generic( 00283 int Matrix_id, /* in: matrix ID */ 00284 int Ndof, /* in: number of unknowns (components of v*) */ 00285 double* V, /* in,out: vector of unknowns updated */ 00286 /* during the loop over subdomains */ 00287 double* B /* in: the rhs vector, if NULL take rhs */ 00288 /* from block data structure */ 00289 ); 00290 00291 /*--------------------------------------------------------- 00292 lar_get_SM_and_LV_crs_from_crs_generic - convert crs_generic matrix format to crs 00293 ---------------------------------------------------------*/ 00294 extern int lar_get_SM_and_LV_crs_from_crs_generic( // returns: flag - 0 if not needed delete crs matrices 00295 int Matrix_id, /* in: matrix ID */ 00296 int offset, /* in: offset in crs_row and crs_col matrix */ 00297 int** crs_row, /* out: matrix of rows in crs */ 00298 int** crs_col, /* out: matrix of column in crs */ 00299 double** crs_val, /* out: matrix of value in crs */ 00300 double** rhs /* out: rhs vector */ 00301 ); 00302 00303 #endif