00001 /************************************************************* 00002 lsh_mkb_intf.h - interface of the set of solvers that provide implementations 00003 to linear solver routines required by the sid_mkb solver interface package. 00004 The set currently includes direct solvers such as SuperLU, PARDISO, ViennaCL, 00005 as well as iterative solvers, with multigrid preconditioned (geometrically 00006 or algebraically) Krylow method solver (currently GMRES only) as default. 00007 The solvers use their own data structures or lad_... modules for storage 00008 of the stiffness matrix. The implementations reside in different subdirectories 00009 of lsd_mkb (with lsd_mkb_core containing multigrid preconditioned GMRES). 00010 lad_... modules additionally provides solvers with a set of linear algebra 00011 operations (see interface lah_intf.h ) to support basic operations on data 00012 structures (operations related mainly to iterative solvers). 00013 The file contains the provided interface with the headers of routines 00014 called from the FEM code 00015 00016 The solver can handle several instances of solver data, each with 00017 a different set of control parameters, system matrix, etc. 00018 Hence it can be used to solve coupled problems (also transient) 00019 with two or more finite element problems solved simultaneously 00020 00021 The actual solution phase (lsr_mkb_solve procedure) has a parameter 00022 that controls whether the solver is a distributed memory parallel solver 00023 or a standard sequential solver. In the first case the solver calls 00024 the finite element external part to perform three operations: 00025 fem_vec_norm - to compute a global (inter-processor) vector norm 00026 fem_sc_prod - to compute a global (inter-processor) scalar product 00027 fem_exchange_dofs - to exchange the values of degrees of freedom 00028 between subdomains (in overlapping Schwarz manner) 00029 For multigrid solution the solver calls the finite element part with 00030 fem_proj_sol_lev - to project solution between levels (grids) 00031 The required interface of the solver containing headers of the 00032 procedures above is defined in the file "lsh_mkb_fem_intf.h" 00033 00034 Contents (declarations of the following routines): 00035 00036 - solver management 00037 lsr_mkb_init - to create a new solver instance, read its control parameters 00038 and initialize its data structure 00039 lsr_mkb_solve - to solve a system of equations, given previously constructed 00040 system matrix, preconditioner 00041 lsr_mkb_destroy - to destroy a particular instance of the solver 00042 00043 - SM and LV management (using lah_intf.h API) 00044 lsr_mkb_create_matrix - to allocate space for a global system matrix 00045 lsr_mkb_clear_matrix - to initialize data structure of system matrix 00046 lsr_mkb_fill_assembly_table_int_ent - to create a part of the global assembly table 00047 related to one integration entity, for which 00048 lists of DOF blocks (their global positions) are provided 00049 lsr_mkb_assemble_local_stiff_mat_with_table - to assemble entries to the global 00050 stiffness matrix and the global load vector using the 00051 provided local stiffness matrix, load vector and 00052 the proper part of the global assembly table 00053 lsr_mkb_assemble_local_sm - to assemble entries to the global stiffness matrix 00054 and the global load vector using the provided local 00055 stiffness matrix and load vector 00056 lsr_mkb_free_matrix - to free space for solver data structure (system 00057 matrix, preconditioner and possibly other) 00058 00060 lsr_create_solver_structures_accel 00062 lsr_get_crs_data 00063 00064 - preconditioner management (for iterative solvers) 00065 lsr_mkb_create_precon - to create preconditioner data structures 00066 lsr_mkb_fill_precon - to prepare preconditioner by factorizing the stiffness 00067 matrix, either only diagonal blocks or block ILU(0) 00068 00069 - multigrid utility 00070 lsr_mkb_get_pdeg_coarse - to get enforced pdeg for the coarse mesh 00071 00072 // three procedures for direct solvers acting through mkb interface 00073 // IMPLEMENTED not in lss_mkb_intf but in lsd_direct_... modules... 00074 lsr_mkb_direct_init - to create a new solver instance, read its control 00075 parameters and initialize its data structure 00076 lsr_mkb_direct_create - to create a new solver instance, read its control 00077 parameters and initialize its data structure 00078 lsr_mkb_direct_solve - to solve a system of equations, given previously constructed 00079 system matrix, preconditioner 00080 lsr_mkb_direct_free - to destroy a particular instance of the direct solver 00081 lsr_mkb_direct_destroy - to destroy a particular instance of the direct solver 00082 00083 00084 History: 00085 08.2013 - Krzysztof Banas, initial version 00086 00087 *************************************************************/ 00088 00089 00090 #ifndef _lsh_mkb_intf_ 00091 #define _lsh_mkb_intf_ 00092 00093 00094 #ifdef __cplusplus 00095 extern "C" { 00096 #endif 00097 00098 // linear algebra supporting interface 00099 #include "./lah_intf.h" 00100 00101 /* Scope of calculations */ 00102 #define LSC_SOLVE 0 00103 #define LSC_RESOLVE 1 00104 00105 #define LSC_SEQUENTIAL 0 00106 #define LSC_PARALLEL 1 00107 00108 #define LSC_MAX_NUM_SOLV 10 00109 #define LSC_MAX_NUM_LEV 20 00110 00111 /* Monitoring options */ 00112 #define LSC_SILENT 0 00113 #define LSC_ERRORS 1 00114 #define LSC_INFO 2 00115 #define LSC_ALLINFO 3 00116 00117 /* storage options */ 00118 #define LSC_STORAGE_UNDEFINED LAC_STORAGE_UNDEFINED 00119 #define LSC_STORAGE_BLOCK LAC_STORAGE_BLOCK 00120 #define LSC_STORAGE_CRS LAC_STORAGE_CRS 00121 #define LSC_STORAGE_BCRS LAC_STORAGE_BCRS 00122 #define LSC_STORAGE_CRS_GENERIC LAC_STORAGE_CRS_GENERIC 00123 #define LSC_STORAGE_PETSC LAC_STORAGE_PETSC 00124 00125 /* solvers */ 00126 #define DIRECT 0 00127 #define GMRES 1 00128 #define MULTI_GMRES 2 00129 #define STANDARD_IT 10 00130 #define MULTI_GRID 20 00131 #define MKB_CORE_NS_SUPG_SOLVER 99 00132 #define MULTI_GRID_AMG 125 00133 00134 /* definition of type lst_mkb_levels - data structure for mesh levels */ 00135 /* and associated solvers and matrices */ 00136 typedef struct { 00137 // the only relevant right now 00138 int SM_and_LV_id; // identifier assigned by linear algebra package to a triple: 00139 // system matrix, rhs vector, preconditioner data structure 00140 int nrdofgl; /* total number of degrees of freedom */ 00141 // possibly known - but not used 00142 //int nr_dof_blocks; /* total number of blocks of DOFs */ 00143 //int block_size; // size of SM blocks (-1 - non-constant size of blocks) 00144 int storage_type; // indicator of storage type: CRS, BCRS, block 00145 // LSC_STORAGE_ constants defined above 00146 } lst_mkb_levels; 00147 00148 /* definition of lst_mkb_solvers - data type for multi-level iterative solver */ 00149 typedef struct { 00150 int solver_id; /* solver_id */ 00151 int solver_type; /* linear equations solver: */ 00152 /* 0 - direct solver */ 00153 /* 1 - GMRES */ 00154 /* 2 - multi-level GMRES */ 00155 /* 99 - MKB_CORE_NS_SUPG_SOLVER */ 00156 int parallel; /* parameter specifying sequential (LSC_SEQUENTIAL) */ 00157 /* or parallel (LSC_PARALLEL) execution */ 00158 int nr_levels; /* number of levels in multi-level mkb */ 00159 lst_mkb_levels level[LSC_MAX_NUM_LEV]; /* array of solver data structures */ 00160 } lst_mkb_solvers; 00161 00162 /* GLOBAL VARIABLES */ 00163 extern int lsv_mkb_nr_solvers; /* the number of solvers handled by the module */ 00164 extern int lsv_mkb_cur_solver_id; /* ID of the current solver */ 00165 extern lst_mkb_solvers lsv_mkb_solver[LSC_MAX_NUM_SOLV]; /* array of solvers */ 00166 00167 /*** Parameters ***/ 00168 00173 extern int lsr_mkb_init( /* returns: >0 - solver ID, <0 - error code */ 00174 int Solver_type, // type of solver (as defined in problem input file) 00175 int Parallel, /* parameter specifying sequential (LSC_SEQUENTIAL) */ 00176 /* or parallel (LSC_PARALLEL) execution */ 00177 int* Max_num_levels_p, /* in: number of levels for multigrid: */ 00178 /* 1 - enforce single level solver */ 00179 /* >1 - enforce the number of levels */ 00180 /* out: actual number of levels !!! */ 00181 int* Storage_type, /* in: requested storage type (NOT IMPLEMENTED YET) */ 00182 /* out: actual storage type */ 00183 char* Filename, /* in: name of the file with control parameters */ 00184 int Max_iter, /* maximal number of iterations, -1 for values from Filename */ 00185 int Error_type, /* type of error norm (stopping criterion), -1 for Filename*/ 00186 double Error_tolerance, /* value for stopping criterion, -1.0 for Filename */ 00187 int Monitoring_level /* Level of output, -1 for Filename */ 00188 ); 00189 00193 extern int lsr_mkb_destroy( 00194 int Solver_id /* in: solver ID (used to identify the subproblem) */ 00195 ); 00196 00197 00201 extern int lsr_mkb_create_matrix( 00202 /* returns: >=0 - success code, <0 - error code */ 00203 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00204 int Level_id, /* in: level ID */ 00205 int Storage_type,/* in: enforced storage type; if LSC_STORAGE_UNDEFINED */ 00206 /* storage type is taken from input files or */ 00207 /* decided by software (usually based on Block_size) */ 00208 int Nrblocks, /* in: number of DOF blocks */ 00209 int Nrdof_glob, /* in: total number of DOFs */ 00210 int Block_size, /* in: size of SM blocks (-1 - non-constant size) */ 00211 int Max_sm_size, /* in: maximal size of the stiffness matrix */ 00212 int* Nrdofbl, /* in: list of numbers of dofs in a block */ 00213 int* Posglob, /* in: list of global numbers of first dof */ 00214 int* Nroffbl, /* in: list of numbers of off diagonal blocks */ 00215 int** L_offbl /* in: list of lists of off diagonal blocks */ 00216 ); 00217 00221 extern int lsr_mkb_clear_matrix( 00222 /* returns: >=0 - success code, <0 - error code */ 00223 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00224 int Level_id, /* in: level ID */ 00225 int Comp_type /* in: indicator for the scope of computations: */ 00226 /* LSC_SOLVE - solve the system */ 00227 /* LSC_RESOLVE - resolve for the new rhs vector */ 00228 ); 00229 00235 extern int lsr_mkb_fill_assembly_table_int_ent( 00236 /* returns: >=0 - success code, <0 - error code */ 00237 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00238 int Level_id, /* in: level ID */ 00239 int Nr_dof_bl, /* in: number of global dof blocks */ 00240 /* associated with the local stiffness matrix */ 00241 int* L_bl_id, /* in: list of dof blocks' IDs */ 00242 int* L_bl_nrdof, /* in: list of blocks' numbers of dof */ 00243 int *Assembly_table_int_ent /* part of the global assembly table */ 00244 ); 00245 00252 extern int lsr_mkb_assemble_local_stiff_mat_with_table( 00253 /* returns: >=0 - success code, <0 - error code */ 00254 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00255 int Level_id, /* in: level ID */ 00256 int Comp_type, /* in: indicator for the scope of computations: */ 00257 /* LSC_SOLVE - solve the system */ 00258 /* LSC_RESOLVE - resolve for the new rhs vector */ 00259 int Nr_dof_bl, /* in: number of global dof blocks */ 00260 /* associated with the local stiffness matrix */ 00261 int* Assembly_table_int_ent, /* part of the global assembly table */ 00262 int* Local_to_global_int_ent, /* part of the global local_to_global table */ 00263 double* Stiff_mat, /* in: stiffness matrix stored columnwise */ 00264 double* Rhs_vect, /* in: rhs vector */ 00265 char* Rewr_dofs /* in: flag to rewrite or sum up entries */ 00266 /* 'T' - true, rewrite entries when assembling */ 00267 /* 'F' - false, sum up entries when assembling */ 00268 ); 00269 00275 extern int lsr_mkb_assemble_local_sm( 00276 /* returns: >=0 - success code, <0 - error code */ 00277 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00278 int Level_id, /* in: level ID */ 00279 int Comp_type, /* in: indicator for the scope of computations: */ 00280 /* LSC_SOLVE - solve the system */ 00281 /* LSC_RESOLVE - resolve for the new rhs vector */ 00282 int Nr_dof_bl, /* in: number of global dof blocks */ 00283 /* associated with the local stiffness matrix */ 00284 int* L_bl_id, /* in: list of dof blocks' IDs */ 00285 int* L_bl_nrdof, /* in: list of blocks' numbers of dof */ 00286 double* Stiff_mat, /* in: stiffness matrix stored columnwise */ 00287 double* Rhs_vect, /* in: rhs vector */ 00288 char* Rewr_dofs /* in: flag to rewrite or sum up entries */ 00289 /* 'T' - true, rewrite entries when assembling */ 00290 /* 'F' - false, sum up entries when assembling */ 00291 ); 00292 00297 extern int lsr_mkb_free_matrix( 00298 int Solver_id /* in: solver ID (used to identify the subproblem) */ 00299 ); 00300 00301 00305 extern int lsr_mkb_create_precon( /* returns: >0 number of diagonal blocks */ 00306 /* <=0 - error */ 00307 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00308 int Level_id /* in: level ID */ 00309 ); 00310 00315 extern int lsr_mkb_fill_precon( 00316 /* returns: >=0 - success code, <0 - error code */ 00317 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00318 int Level_id /* in: level ID */ 00319 ); 00320 00321 00326 extern int lsr_mkb_solve( /* returns: convergence indicator: */ 00327 /* 1 - convergence */ 00328 /* 0 - noconvergence */ 00329 /* <0 - error code */ 00330 int Solver_id, /* in: solver ID */ 00331 int Comp_type, /* in: indicator for the scope of computations: */ 00332 /* LSC_SOLVE - solve the system */ 00333 /* LSC_RESOLVE - resolve for the new right hand side */ 00334 int Ini_zero, /* in: indicator whether initial guess is zero (0/1) */ 00335 double* X, /* in: the initial guess */ 00336 /* out: the iterated solution */ 00337 double* B, /* in: the rhs vector, if NULL take rhs */ 00338 /* from block data structure */ 00339 int* Nr_iter, /* in: the maximum iterations to be performed */ 00340 /* out: actual number of iterations performed */ 00341 double* Toler, /* in: tolerance level for chosen measure */ 00342 /* out: the final value of convergence measure */ 00343 int Monitor, /* in: flag to determine monitoring level */ 00344 /* 0 - silent run, 1 - warning messages */ 00345 /* 2 - 1+restart data, 3 - 2+iteration data */ 00346 double* Conv_rate /* out: convergence rate */ 00347 ); 00348 00349 00350 // three procedures for direct solvers acting through mkb interface 00351 // IMPLEMENTED not in lss_mkb_intf but in lsd_direct_... modules... 00352 00357 extern int lsr_mkb_direct_init( /* returns: >0 - solver ID, <0 - error code */ 00358 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00359 char* Filename, /* in: name of the file with control parameters */ 00360 int Monitoring_level /* Level of output, -1 for Filename */ 00361 ); 00362 00367 extern int lsr_mkb_direct_create( /* returns: >0 - solver ID, <0 - error code */ 00368 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00369 char* Filename, /* in: name of the file with control parameters */ 00370 int Monitoring_level /* Level of output, -1 for Filename */ 00371 ); 00372 00377 extern int lsr_mkb_direct_solve( /* returns: convergence indicator: */ 00378 /* 1 - convergence */ 00379 /* 0 - noconvergence */ 00380 /* <0 - error code */ 00381 int Solver_id, /* in: solver ID */ 00382 int Comp_type, /* in: indicator for the scope of computations: */ 00383 /* LSC_SOLVE - solve the system */ 00384 /* LSC_RESOLVE - resolve for the new right hand side */ 00385 int Matrix_id, /* in: matrix ID */ 00386 int Ndof, /* in: the number of degrees of freedom */ 00387 double* X, /* in: the initial guess */ 00388 /* out: the iterated solution */ 00389 double* B, /* in: the rhs vector, if NULL take rhs */ 00390 /* from block data structure */ 00391 int Monitor /* in: flag to determine monitoring level */ 00392 /* 0 - silent run, 1 - warning messages */ 00393 /* 2 - 1+restart data, 3 - 2+iteration data */ 00394 ); 00395 00399 int lsr_mkb_direct_free( /* returns: >0 - solver ID, <0 - error code */ 00400 int Solver_id /* in: solver ID (used to identify the subproblem) */ 00401 ); 00402 00406 extern int lsr_mkb_direct_destroy( /* returns: >0 - solver ID, <0 - error code */ 00407 int Solver_id /* in: solver ID (used to identify the subproblem) */ 00408 ); 00409 00410 00412 extern int lsr_create_solver_structures_accel( /* returns: >0 - success code, <0 - error code */ 00413 int Solver_id, /* in: solver ID */ 00414 int Level_id /* in: level ID */ 00415 ); 00416 00417 00419 extern int lsr_get_crs_data( /* returns: >0 - success code, <0 - error code */ 00420 int Solver_id, /* in: solver ID */ 00421 int Level_id, /* in: level ID */ 00422 int* Nrdof_glob_p, /* output pointers: nrdof, nnz etc. - self explanatory */ 00423 int* Nnz_p, 00424 int** Crs_col_ind_p, 00425 int** Crs_row_ptr_p, 00426 double** Crs_val_p, 00427 double** Rhs_p 00428 ); 00429 00431 00435 extern int lsr_mkb_get_pdeg_coarse( // returns: enforced pdeg for the coarse mesh 00436 int Solver_id, /* in: solver ID (used to identify the subproblem) */ 00437 int Level_id /* in: level number */ 00438 ); 00439 00443 #ifdef __cplusplus 00444 } 00445 #endif 00446 00447 #endif