00001 00002 #ifndef _lah_bcrs_ 00003 #define _lah_bcrs_ 00004 00005 #ifdef __cplusplus 00006 extern "C" { 00007 #endif 00008 /*** CONSTANTS ***/ 00009 00010 // assumption: stiffness matrix is composed of blocks with CONSTANT size 00011 // BLS = const > 1 00012 // TODO: passed from compilation options 00013 #define BLS 4 00014 00015 #define ITC_MAX_MATRICES 20 00016 00017 /*** Data types ***/ 00018 00019 typedef struct { 00020 00021 /* parameters */ 00022 int Max_SM_size; /* the maximal number of dofs in a stiffness matrix */ 00023 int Nrblocks; /* total number of small blocks */ 00024 int Nrdofgl; /* total number of degrees of freedom */ 00025 int Nrbl_internal; /* number of internal row block */ 00026 int Nr_sm_blocks; 00027 int Half_bandwidth; 00028 int Max_nrneig; // maximal number of neighbors for a single block 00029 int Precon; // preconditioner 00030 int ILU_k; // number of neighborhood rings for ILU(k) 00031 int ILU_nr_sm_blocks; 00032 int ILU_half_bandwidth; 00033 00034 double *rhs; /* the global right hand side vector */ 00035 00036 /* bcrs matrix */ 00037 double *block_val; 00038 int *block_col_ind; 00039 int *block_row_ptr; 00040 00041 /* block diagonal preconditioner */ 00042 int *block_diag_ptr; 00043 double *block_diag_precon; 00044 int *block_diag_ips; 00045 00046 /* ILU decomposition of stiffness matrix */ 00047 int *ilu_diag_ptr; 00048 double *ilu_val; 00049 int *ilu_col_ind; 00050 int *ilu_row_ptr; 00051 00052 double *pivots; 00053 00054 } itt_bcrs_matrices; 00055 00056 00057 /* GLOBAL VARIABLES */ 00058 extern int itv_nr_bcrs_matrices; /* the number of solvers in the problem */ 00059 extern int itv_cur_bcrs_matrix_id; /* ID of the current problem */ 00060 extern itt_bcrs_matrices itv_bcrs_matrices[ITC_MAX_MATRICES]; /* array of solvers */ 00061 00062 00063 00064 /*--------------------------------------------------------- 00065 lar_allocate_SM_and_LV_bcrs - to allocate space for stiffness matrix and load vector 00066 ---------------------------------------------------------*/ 00067 extern int lar_allocate_SM_and_LV_bcrs( // returns: matrix index in itv_matrices array 00068 int Nrdof_glob, /* in: total number of DOFs */ 00069 int Max_SM_size, /* maximal size of element stiffness matrix */ 00070 int Block_size, /* in: size of SM blocks (-1 - non-constant size) */ 00071 int* Nroffbl, /* in: list of numbers of off diagonal blocks */ 00072 // if Nroffbl[iblock]<=0 - iblock is a ghost block with no rows associated 00073 int** L_offbl /* in: list of lists of off diagonal blocks */ 00074 ); 00075 00076 00080 extern int lar_initialize_SM_and_LV_bcrs( 00081 int Matrix_id, /* in: matrix ID */ 00082 int Scope /* in: indicator for the scope of computations: */ 00083 /* LAC_SCOPE_SM_AND_LV */ 00084 /* LAC_SCOPE_LV - do not touch SM! */ 00085 ); 00086 00090 extern double lar_get_storage_bcrs( /* returns: storage in MB */ 00091 int Matrix_id /* in: matrix ID */ 00092 ); 00093 00099 extern int lar_fill_assembly_table_int_ent_bcrs( 00100 /* returns: >=0 - success code, <0 - error code */ 00101 int Matrix_id, /* in: matrix ID */ 00102 int Nr_dof_bl, /* in: number of global dof blocks */ 00103 /* associated with the local stiffness matrix */ 00104 int* L_bl_id, /* in: list of dof blocks' IDs */ 00105 int* L_bl_nrdof, /* in: list of blocks' numbers of dof */ 00106 int *Assembly_table_int_ent /* part of the global assembly table */ 00107 ); 00108 00109 00110 /*------------------------------------------------------------ 00111 lar_assemble_SM_and_LV_with_table_bcrs - to assemble entries to the global stiffness matrix 00112 and the global load vector using the provided local 00113 stiffness matrix and load vector and assembly table 00114 ------------------------------------------------------------*/ 00115 extern int lar_assemble_SM_and_LV_with_table_bcrs( 00116 /* returns: >=0 - success code, <0 - error code */ 00117 int Matrix_id, /* in: matrix ID */ 00118 int Scope, /* in: indicator for the scope of computations: */ 00119 /* LAC_SCOPE_SM_AND_LV */ 00120 /* LAC_SCOPE_LV - do not touch SM! */ 00121 int Nr_dof_bl, /* in: number of global dof blocks */ 00122 /* associated with the local stiffness matrix */ 00123 int* Assembly_table_int_ent, /* part of the global assembly table */ 00124 int* Local_to_global_int_ent, /* part of the global local_to_global table */ 00125 double* Stiff_mat, /* in: stiffness matrix stored columnwise */ 00126 double* Rhs_vect, /* in: rhs vector */ 00127 char* Rewr_dofs /* in: flag to rewrite or sum up entries */ 00128 /* 'T' - true, rewrite entries when assembling */ 00129 /* 'F' - false, sum up entries when assembling */ 00130 ); 00131 00132 00133 /*------------------------------------------------------------ 00134 lar_assemble_SM_and_LV_bcrs - to assemble entries to the global stiffness matrix 00135 and the global load vector using the provided local 00136 stiffness matrix and load vector 00137 ------------------------------------------------------------*/ 00138 extern int lar_assemble_SM_and_LV_bcrs( 00139 /* returns: >=0 - success code, <0 - error code */ 00140 int Matrix_id, /* in: matrix ID */ 00141 int Scope, /* in: indicator for the scope of computations: */ 00142 /* LAC_SCOPE_SM_AND_LV */ 00143 /* LAC_SCOPE_LV - do not touch SM! */ 00144 int Nr_dof_bl, /* in: number of global dof blocks */ 00145 /* associated with the local stiffness matrix */ 00146 int* L_bl_id, /* in: list of dof blocks' IDs */ 00147 int* L_bl_nrdof, /* in: list of blocks' numbers of dof */ 00148 double* Stiff_mat, /* in: stiffness matrix stored columnwise */ 00149 double* Rhs_vect, /* in: rhs vector */ 00150 char* Rewr_dofs /* in: flag to rewrite or sum up entries */ 00151 /* 'T' - true, rewrite entries when assembling */ 00152 /* 'F' - false, sum up entries when assembling */ 00153 ); 00154 00158 extern int lar_allocate_preconditioner_bcrs( /* returns: >0 number of diagonal blocks */ 00159 /* <=0 - error */ 00160 int Matrix_id, /* in: matrix ID */ 00161 int Precon, /* in: type of preconditioner (lah_block.h line circa 45) */ 00162 int ILU_k // in: for ILU(k) - k; 00163 ); 00164 00168 extern int lar_fill_preconditioner_bcrs( 00169 int Matrix_id /* in: matrix ID */ 00170 ); 00171 00175 extern int lar_free_preconditioner_bcrs( 00176 int Matrix_id /* in: matrix ID */ 00177 ); 00178 00179 /*--------------------------------------------------------- 00180 lar_free_SM_and_LV_bcrs - to free space for a block structure 00181 ---------------------------------------------------------*/ 00182 extern int lar_free_SM_and_LV_bcrs( 00183 int Matrix_id /* in: matrix ID */ 00184 ); 00185 00186 00187 /*--------------------------------------------------------- 00188 lar_compute_residual_bcrs - to compute the residual of the system of equations, 00189 v = ( b - Ax ) (used also to compute the product v = -Ax) 00190 ---------------------------------------------------------*/ 00191 extern void lar_compute_residual_bcrs( 00192 int Matrix_id, /* in: matrix ID */ 00193 int Use_rhs, /* in: indicator whether to use RHS */ 00194 int Ini_zero, /* in: flag for zero initial guess */ 00195 int Ndof, /* in: number of unknowns (components of x) */ 00196 double* X, /* in: input vector (may be NULL if Ini_zero==0) */ 00197 double* B, /* in: the rhs vector, if NULL take rhs */ 00198 /* from block data structure ( B is not taken */ 00199 /* into account if Use_rhs!=1) */ 00200 double* V /* out: v = b-Ax */ 00201 ); 00202 00208 extern void lar_compute_preconditioned_residual_bcrs ( 00209 int Matrix_id, /* in: matrix ID */ 00210 int Use_rhs, /* in: indicator whether to use RHS */ 00211 int Ini_zero, /* in: flag for zero initial guess */ 00212 int Ndof, /* in: number of unknowns (components of x) */ 00213 double* X, /* in: initial guess vector */ 00214 double* B, /* in: the rhs vector, if NULL take rhs */ 00215 /* from block data structure */ 00216 double* V /* out: preconditioned residual, v = M^-1*(b-Ax) */ 00217 ); 00218 00224 extern void lar_perform_BJ_or_GS_iterations_bcrs( 00225 int Matrix_id, /* in: matrix ID */ 00226 int Use_rhs, /* in: 0 - no rhs, 1 - with rhs */ 00227 int Ini_zero, /* in: flag for zero initial guess */ 00228 int Nr_prec, /* in: number of preconditioner iterations */ 00229 int Ndof, /* in: number of unknowns (components of v*) */ 00230 double* V, /* in,out: vector of unknowns updated */ 00231 /* during the loop over subdomains */ 00232 double* B /* in: the rhs vector, if NULL take rhs */ 00233 /* from block data structure */ 00234 ); 00235 00236 00241 extern void lar_perform_rhsub_bcrs( 00242 int Matrix_id, /* in: matrix ID */ 00243 int Ndof, /* in: number of unknowns (components of v*) */ 00244 double* V, /* in,out: vector of unknowns updated */ 00245 /* during the loop over subdomains */ 00246 double* B /* in: the rhs vector, if NULL take rhs */ 00247 /* from block data structure */ 00248 ); 00249 00250 00251 /*--------------------------------------------------------- 00252 lar_get_SM_and_LV_crs_from_bcrs - convert bcrs matrix format to crs 00253 ---------------------------------------------------------*/ 00254 extern int lar_get_SM_and_LV_crs_from_bcrs( // returns: flag - 0 if not needed delete crs matrices 00255 int Matrix_id, /* in: matrix ID */ 00256 int offset, /* in: offset in crs_row and crs_col matrix */ 00257 int** crs_row, /* out: matrix of rows in crs */ 00258 int** crs_col, /* out: matrix of column in crs */ 00259 double** crs_val, /* out: matrix of value in crs */ 00260 double** rhs /* out: rhs vector */ 00261 ); 00262 00263 00264 00266 extern int lar_util_chk_list_bcrs( /* returns: */ 00267 /* >0 - position on the list */ 00268 /* 0 - not found on the list */ 00269 int Num, /* number to be checked */ 00270 int* List, /* list of numbers */ 00271 int Ll /* length of the list */ 00272 ); 00273 00274 #ifdef __cplusplus 00275 } 00276 #endif 00277 00278 #endif