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 );