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_ 00039 #define _lah_crs_ 00040 00041 /*** External Parameters ***/ 00042 00043 #define ITC_MAX_MATRICES 20 00044 00045 #ifdef __cplusplus 00046 extern "C" { 00047 #endif 00048 00049 /*** Data types ***/ 00050 00051 typedef struct { 00052 00053 /* parameters */ 00054 int Max_SM_size; /* the maximal number of dofs in a stiffness matrix */ 00055 int Nrdofgl; /* total number of degrees of freedom */ 00056 int Nrdof_internal; /* internal number of degrees of freedom */ 00057 int Nnz; /* total number of non-zero elements */ 00058 int Half_bandwidth; /* FEM matrices are banded... */ 00059 00060 int Precon; // lad_ modules store preconditioner matrices as well 00061 int ILU_k; // number of neighborhood rings for ILU(k) 00062 00063 double *rhs; /* the global right hand side vector */ 00064 00065 /* crs matrix */ 00066 double *crs_val; 00067 int *crs_col_ind; 00068 int *crs_row_ptr; 00069 00070 /* diagonal preconditioner */ 00071 int *diag_ptr; 00072 double *diag_precon; 00073 00074 } itt_crs_matrices; 00075 00076 00077 /* GLOBAL VARIABLES */ 00078 extern int itv_nr_crs_matrices; /* the number of solvers in the problem */ 00079 extern int itv_cur_crs_matrix_id; /* ID of the current problem */ 00080 extern itt_crs_matrices itv_crs_matrices[ITC_MAX_MATRICES]; /* array of solvers */ 00081 00082 00083 00084 /*--------------------------------------------------------- 00085 lar_allocate_SM_and_LV_crs - to allocate space for stiffness matrix and load vector 00086 ---------------------------------------------------------*/ 00087 extern int lar_allocate_SM_and_LV_crs( // returns: matrix index in itv_crs_matrices array 00088 int Nrdof_glob, /* in: total number of DOFs */ 00089 int Max_SM_size, /* maximal size of element stiffness matrix */ 00090 int* Nroffbl, /* in: list of numbers of off diagonal blocks */ 00091 // if Nroffbl[iblock]==0 - iblock is a ghost block with no rows associated with 00092 int** L_offbl /* in: list of lists of off diagonal blocks */ 00093 ); 00094 00095 00099 extern int lar_initialize_SM_and_LV_crs( 00100 int Matrix_id, /* in: matrix ID */ 00101 int Scope /* in: indicator for the scope of computations: */ 00102 /* LAC_SCOPE_SM_AND_LV */ 00103 /* LAC_SCOPE_LV - do not touch SM! */ 00104 ); 00105 00109 extern double lar_get_storage_crs( /* returns: storage in MB */ 00110 int Matrix_id /* in: matrix ID */ 00111 ); 00112 00118 extern int lar_fill_assembly_table_int_ent_crs( 00119 /* returns: >=0 - success code, <0 - error code */ 00120 int Matrix_id, /* in: matrix ID */ 00121 int Nr_dof_bl, /* in: number of global dof blocks */ 00122 /* associated with the local stiffness matrix */ 00123 int* L_bl_id, /* in: list of dof blocks' IDs */ 00124 int* L_bl_nrdof, /* in: list of blocks' numbers of dof */ 00125 int *Assembly_table_int_ent /* part of the global assembly table */ 00126 ); 00127 00128 00129 /*------------------------------------------------------------ 00130 lar_assemble_SM_and_LV_with_table_crs - to assemble entries to the global stiffness matrix 00131 and the global load vector using the provided local 00132 stiffness matrix and load vector and assembly table 00133 ------------------------------------------------------------*/ 00134 extern int lar_assemble_SM_and_LV_with_table_crs( 00135 /* returns: >=0 - success code, <0 - error code */ 00136 int Matrix_id, /* in: matrix ID */ 00137 int Scope, /* in: indicator for the scope of computations: */ 00138 /* LAC_SCOPE_SM_AND_LV */ 00139 /* LAC_SCOPE_LV - do not touch SM! */ 00140 int Nr_dof_bl, /* in: number of global dof blocks */ 00141 /* associated with the local stiffness matrix */ 00142 int* Assembly_table_int_ent, /* part of the global assembly table */ 00143 int* Local_to_global_int_ent, /* part of the global local_to_global table */ 00144 double* Stiff_mat, /* in: stiffness matrix stored columnwise */ 00145 double* Rhs_vect, /* in: rhs vector */ 00146 char* Rewr_dofs /* in: flag to rewrite or sum up entries */ 00147 /* 'T' - true, rewrite entries when assembling */ 00148 /* 'F' - false, sum up entries when assembling */ 00149 ); 00150 00151 /*------------------------------------------------------------ 00152 lar_assemble_SM_and_LV_crs - to assemble entries to the global stiffness matrix 00153 and the global load vector using the provided local 00154 stiffness matrix and load vector 00155 ------------------------------------------------------------*/ 00156 extern int lar_assemble_SM_and_LV_crs( 00157 /* returns: >=0 - success code, <0 - error code */ 00158 int Matrix_id, /* in: matrix ID */ 00159 int Scope, /* in: indicator for the scope of computations: */ 00160 /* LAC_SCOPE_SM_AND_LV */ 00161 /* LAC_SCOPE_LV - do not touch SM! */ 00162 int Nr_dof_bl, /* in: number of global dof blocks */ 00163 /* associated with the local stiffness matrix */ 00164 int* L_bl_id, /* in: list of dof blocks' IDs */ 00165 int* L_bl_nrdof, /* in: list of blocks' numbers of dof */ 00166 double* Stiff_mat, /* in: stiffness matrix stored columnwise */ 00167 double* Rhs_vect, /* in: rhs vector */ 00168 char* Rewr_dofs /* in: flag to rewrite or sum up entries */ 00169 /* 'T' - true, rewrite entries when assembling */ 00170 /* 'F' - false, sum up entries when assembling */ 00171 ); 00172 00173 00177 extern int lar_allocate_preconditioner_crs( /* returns: >0 number of diagonal blocks */ 00178 /* <=0 - error */ 00179 int Matrix_id, /* in: matrix ID */ 00180 int Precon, /* in: type of preconditioner (lah_block.h line circa 45) */ 00181 int ILU_k // in: for ILU(k) - k; 00182 ); 00183 00187 extern int lar_fill_preconditioner_crs( 00188 int Matrix_id /* in: matrix ID */ 00189 ); 00190 00194 extern int lar_free_preconditioner_crs( 00195 int Matrix_id /* in: matrix ID */ 00196 ); 00197 00201 extern int lar_create_solver_structures_accel_crs( 00202 int Matrix_id /* in: matrix ID */ 00203 ); 00204 00208 extern int lar_get_crs_data_crs( /* returns: >0 - success code, <0 - error code */ 00209 int Matrix_id, /* in: matrix ID */ 00210 int* Nrdof_glob_p, /* output pointers: nrdof, nnz etc. - self explanatory */ 00211 int* Nnz_p, 00212 int** Crs_col_ind_p, 00213 int** Crs_row_ptr_p, 00214 double** Crs_val_p, 00215 double** Rhs_p 00216 ); 00217 00218 /*--------------------------------------------------------- 00219 lar_free_SM_and_LV_crs - to free space for a block structure 00220 ---------------------------------------------------------*/ 00221 extern int lar_free_SM_and_LV_crs( 00222 int Matrix_id /* in: matrix ID */ 00223 ); 00224 00225 /*--------------------------------------------------------- 00226 lar_compute_residual_crs - to compute the residual of the system of equations, 00227 v = ( b - Ax ) (used also to compute the product v = -Ax) 00228 ---------------------------------------------------------*/ 00229 extern void lar_compute_residual_crs( 00230 int Matrix_id, /* in: matrix ID */ 00231 int Use_rhs, /* in: indicator whether to use RHS */ 00232 int Ini_zero, /* in: flag for zero initial guess */ 00233 int Ndof, /* in: number of unknowns (components of x) */ 00234 double* X, /* in: input vector (may be NULL if Ini_zero==0) */ 00235 double* B, /* in: the rhs vector, if NULL take rhs */ 00236 /* from block data structure ( B is not taken */ 00237 /* into account if Use_rhs!=1) */ 00238 double* V /* out: v = b-Ax */ 00239 ); 00240 00246 extern void lar_compute_preconditioned_residual_crs( 00247 int Matrix_id, /* in: matrix ID */ 00248 int Use_rhs, /* in: indicator whether to use RHS */ 00249 int Ini_zero, /* in: flag for zero initial guess */ 00250 int Ndof, /* in: number of unknowns (components of x) */ 00251 double* X, /* in: initial guess vector */ 00252 double* B, /* in: the rhs vector, if NULL take rhs */ 00253 /* from block data structure */ 00254 double* V /* out: preconditioned residual, v = M^-1*(b-Ax) */ 00255 ); 00256 00262 extern void lar_perform_BJ_or_GS_iterations_crs( 00263 int Matrix_id, /* in: matrix ID */ 00264 int Use_rhs, /* in: 0 - no rhs, 1 - with rhs */ 00265 int Ini_zero, /* in: flag for zero initial guess */ 00266 int Nr_prec, /* in: number of preconditioner iterations */ 00267 int Ndof, /* in: number of unknowns (components of v*) */ 00268 double* V, /* in,out: vector of unknowns updated */ 00269 /* during the loop over subdomains */ 00270 double* B /* in: the rhs vector, if NULL take rhs */ 00271 /* from block data structure */ 00272 ); 00273 00274 00279 extern void lar_perform_rhsub_crs( 00280 int Matrix_id, /* in: matrix ID */ 00281 int Ndof, /* in: number of unknowns (components of v*) */ 00282 double* V, /* in,out: vector of unknowns updated */ 00283 /* during the loop over subdomains */ 00284 double* B /* in: the rhs vector, if NULL take rhs */ 00285 /* from block data structure */ 00286 ); 00287 00288 /*--------------------------------------------------------- 00289 lar_get_SM_and_LV_crs_from_crs - convert crs matrix format to crs 00290 ---------------------------------------------------------*/ 00291 extern int lar_get_SM_and_LV_crs_from_crs( // returns: flag - 0 if not needed delete crs matrices 00292 int Matrix_id, /* in: matrix ID */ 00293 int offset, /* in: offset in crs_row and crs_col matrix */ 00294 int** crs_row, /* out: matrix of rows in crs */ 00295 int** crs_col, /* out: matrix of column in crs */ 00296 double** crs_val, /* out: matrix of value in crs */ 00297 double** rhs /* out: rhs vector */ 00298 ); 00299 00300 00301 /*--------------------------------------------------------- 00302 lar_crs_clear_matrix - to clear rhs and crs vectors 00303 ---------------------------------------------------------*/ 00304 extern int lar_crs_clear_matrix( 00305 int Matrix_id /* in: matrix ID */ 00306 ); 00307 00308 00309 #ifdef __cplusplus 00310 } 00311 #endif 00312 00313 #endif