69 namespace it = Input::Type;
73 "Absolute residual tolerance.")
75 "Relative residual tolerance (to initial error).")
77 "Maximum number of outer iterations of the linear solver.");
101 if ( solver == NULL )
xprintf(
PrgErr,
"Structure solver not allocated.\n");
125 if (solver->use_last_sol && (solver->type == PETSC_SOLVER)) {
126 xprintf(UsrErr,"Can not reuse last solution, when using an internal solver.");
130 double solver_accuracy= OptGetDbl("Solver","Solver_accuracy","1.0e-7");
131 solver->max_it= OptGetInt("Solver", "max_it", "200" );
132 solver->r_tol= OptGetDbl("Solver", "r_tol", "-1" );
133 if (solver->r_tol < 0) solver->r_tol=solver_accuracy;
134 solver->a_tol= OptGetDbl("Solver", "a_tol", "1.0e-9" );
136 if (solver->type == ISOL) {
137 solver->isol_params=(ISOL_params *)malloc(sizeof(ISOL_params));
138 isol_params_init(solver->isol_params);
151 #define TEST_TYPE(name_str,id) if ( strcmpi( solver->name, name_str ) == 0 ) solver->type = (id);
182 #define SET_GENERIC_CALL sprintf( cmdline, "%s %s",solver->executable,solver->params.c_str())
183 #define SET_MATLAB_CALL sprintf( cmdline, "matlab -r solve" )
185 char cmdline[ 1024 ];
187 ASSERT( NONULL( solver ),
"NULL 'solver' argument.\n");
188 ASSERT( NONULL( system ),
"NULL 'system' argument.\n");
191 switch (solver->
type) {
228 void (*write_sys)(
Solver *),
void (*read_sol)(
Solver *) )
239 xprintf(
Msg,
"Writing files for solver... ");
240 (*write_sys)(solver);
244 sprintf( cmd,
"copy /Y ../%s ", solver->
ctrl_file );
251 "Start solver of linear equations manually:\n\n%s\n\n"
252 "Press ENTER when calculation finished.\n" );
256 "BEGIN OF SOLVER'S MESSAGES\n");
259 strcat(cmd,
" 2>&1 | tee ../flow_extern_solver.log");
264 (*read_sol)( solver );
274 xprintf(
Msg,
"END OF MESSAGES OF THE SOLVER\n\n");
323 KSPConvergedReason Reason;
325 const char *petsc_dflt_opt;
326 const char *petsc_str;
341 petsc_dflt_opt=
"-ksp_type cg -pc_type nn -nn_coarse_pc_factor_mat_solver_package mumps -is_localD_pc_factor_mat_solver_package mumps -is_localN_pc_factor_mat_solver_package mumps";
344 petsc_dflt_opt=
"-ksp_type minres -pc_type nn -nn_coarse_pc_factor_mat_solver_package mumps -is_localD_pc_factor_mat_solver_package mumps -is_localN_pc_factor_mat_solver_package mumps";
346 petsc_dflt_opt=
"-ksp_type bcgs -pc_type nn -nn_coarse_pc_factor_mat_solver_package mumps -is_localD_pc_factor_mat_solver_package mumps -is_localN_pc_factor_mat_solver_package mumps";
351 petsc_dflt_opt=
"-ksp_type cg -pc_type nn -nn_coarse_pc_factor_mat_solver_package mumps -is_localD_pc_factor_mat_solver_package mumps -is_localN_pc_factor_mat_solver_package mumps";
354 petsc_dflt_opt=
"-ksp_type minres -pc_type nn -nn_coarse_pc_factor_mat_solver_package mumps -is_localD_pc_factor_mat_solver_package mumps -is_localN_pc_factor_mat_solver_package mumps";
356 petsc_dflt_opt=
"-ksp_type bcgs -pc_type nn -nn_coarse_pc_factor_mat_solver_package mumps -is_localD_pc_factor_mat_solver_package mumps -is_localN_pc_factor_mat_solver_package mumps";
366 petsc_dflt_opt=
"-ksp_type bcgs -ksp_diagonal_scale_fix -pc_type asm -pc_asm_overlap 4 -sub_pc_type ilu -sub_pc_factor_levels 3 -sub_pc_factor_fill 6.0";
370 petsc_dflt_opt=
"-ksp_type bcgs -ksp_diagonal_scale_fix -pc_type asm -pc_asm_overlap 4 -sub_pc_type ilu -sub_pc_factor_levels 3";
376 petsc_dflt_opt=
"-ksp_type cg -pc_type ilu -pc_factor_levels 3 -ksp_diagonal_scale_fix -pc_factor_shift_positive_definite -pc_factor_fill 6.0";
378 petsc_dflt_opt=
"-ksp_type bcgs -pc_type ilu -pc_factor_levels 5 -ksp_diagonal_scale_fix";
382 if (solver->
params ==
"") petsc_str=petsc_dflt_opt;
383 else petsc_str=solver->
params.c_str();
388 PetscOptionsInsertString(petsc_str);
391 MatSetOption(sys->
get_matrix(), MAT_USE_INODES, PETSC_FALSE);
453 KSPCreate(PETSC_COMM_WORLD,&System);
455 KSPSetTolerances(System, solver->
r_tol, solver->
a_tol, PETSC_DEFAULT,PETSC_DEFAULT);
456 KSPSetFromOptions(System);
460 KSPGetConvergedReason(System,&Reason);
461 KSPGetIterationNumber(System,&nits);
464 xprintf(
Msg,
"convergence reason %d, number of iterations is %d\n", Reason, nits);
511 fconf =
xfopen(
"isol.conf",
"wt" );
512 xfprintf( fconf,
"mat_file = matrix.dat\n" );
513 xfprintf( fconf,
"mat_fmt = coo\n" );
514 xfprintf( fconf,
"rhs_file = rhs.dat\n" );
516 xfprintf( fconf,
"mat_id_off = 0\n" );
517 xfprintf( fconf,
"mat_symmetrize = 1\n" );
518 xfprintf( fconf,
"sol0_file = 0\n" );
519 xfprintf( fconf,
"sol_file = solution.dat\n" );
535 xfprintf( fconf,
"ilu_cpiv = %d ! do not use at the moment, needs some fixing!\n",
538 xprintf(
PrgErr,
"Sorry, ilu_dskip parameter is not supported.\n");
568 out =
xfopen(
"solve.m",
"wt" );
569 xfprintf( out,
"load matrix.dat\n" );
570 xfprintf( out,
"a = spconvert( matrix )\n" );
573 xfprintf( out,
"sol = a \\ rhs\n" );
574 xfprintf( out,
"save solution.dat sol -ascii -double\n" );
600 out = xfopen( "matrix.dat", "wt" );
601 xfprintf( out, "%d %d %d\n", mtx->size, mtx->size, nnz);
603 for( mi = 1; mi <= mtx->size; mi++ )
604 for( ; ji < mtx->i[mi] ; ji++ )
605 xfprintf( out, "%d %d %.16lg\n",mi,mtx->j[ji] + 1, mtx->a[ ji ] );
608 out = xfopen( "rhs.dat", "wt" );
609 for( mi = 0; mi < mtx->size; mi++ ) xfprintf( out, "%.16lg\n", mtx->vb[ mi ] );
624 in =
xfopen(
"solution.dat",
"rt" );
627 for( mi = 0; mi < sys->
size(); mi++ )
631 solution[mi] = value;
636 sys -> set_whole_solution( solution );
int use_last_sol
Use last known solution? (should be in water module)
char * stop_crit
Stoping criterion.
char * name
Name of the solver.
static void write_sys_isol(struct Solver *solver)
Write down input for ISOL.
char keep_files
Keep or remove solver files?
int xfclose(FILE *stream)
FCLOSE WITH ERROR HANDLING.
Wrappers for linear systems based on MPIAIJ and MATIS format.
static Input::Type::AbstractRecord input_type
static void write_sys_matlab(struct Solver *solver)
MATLAB call functions.
int xremove(const char *fname)
DELETE a FILE with error handling.
static Input::Type::Record input_type_petsc
int xfprintf(FILE *out, const char *fmt,...)
FPRINTF WITH ERROR HANDLING.
static Input::Type::Record input_type_bddc
double ilu_droptol
drop tolerance
int stop_check
Stop check.
#define ADD_CALLS(n_calls)
Increase number of calls in actual timer.
double a_tol
Absolute tolerance.
I/O functions with filename storing, able to track current line in opened file. All standard stdio fu...
char manual_run
Run solver manualy ?
void solver_petsc(Solver *solver)
char * scaling
Scaling method.
static void isol_params_init(ISOL_params *par)
ISOL calling functions.
#define TEST_TYPE(name_str, id)
Set solver type from its name.
char use_ctrl_file
User provided control file ?
void solve_system(struct Solver *solver, struct LinSys *system)
Solves a given linear system.
const Vec & get_solution()
int xmkdir(const char *s)
MKDIR WITH ERROR HANDLING.
void solver_init(Solver *solver, Input::AbstractRecord in_rec)
Initialize a solver structure.
#define START_TIMER(tag)
Starts a timer with specified tag.
int restart
num of iter. of restart of GMRES
int max_it
solver parameters
virtual const Vec * get_rhs()
static void solver_set_type(struct Solver *solver)
Support classes for parallel programing.
SolverType type
type of the solver
static void clean_directory(void)
Clean temporary directory of external solver.
static void write_matlab_linsys(LinSys *mtx, int nz)
Write MATLAB system.
double r_tol
Relative tolerance.
int xchdir(const char *s)
CHDIR WITH ERROR HANDLING.
double be_tol
Backward error tolerance.
Abstract linear system class.
bool is_positive_definite()
#define END_TIMER(tag)
Ends a timer with specified tag.
static void RunExtern(struct Solver *solver, char *cmdline, void(*write_sys)(struct Solver *), void(*read_sol)(struct Solver *))
static void read_sol_matlab(struct Solver *solver)
Read MATLAB solution into solver->LinSys->vx.
char * precond
Type od preconditioning.
virtual const Mat * get_matrix()
string params
Solver's comamnd line parameters.
int xfscanf(FILE *in, const char *fmt,...)
FSCANF WITH ERROR HANDLING.
ISOL_params * isol_params
optional ISOL parameters
int xsystem(const char *cmd)
SYSTEM with err handling.
const char * ctrl_file
Name of control file.
FILE * xfopen(const std::string &fname, const char *mode)
char * method
Iteration method.
struct LinSys * LinSys
System to solve.