8#ifndef OPENFPM_NUMERICS_SRC_SOLVERS_PETSC_SOLVER_ASM_AMG_TO_DO_HPP_
9#define OPENFPM_NUMERICS_SRC_SOLVERS_PETSC_SOLVER_ASM_AMG_TO_DO_HPP_
17 void try_solve_complex_bj(Mat & A_,
const Vec & b_, Vec & x_)
19 PETSC_SAFE_CALL(KSPSetTolerances(ksp,rtol,abstol,dtol,5));
20 PETSC_SAFE_CALL(KSPSetConvergenceTest(ksp,KSPConvergedSkip,NULL,NULL));
22 solve_complex(A_,b_,x_);
31 void try_solve_ASM(Mat & A_,
const Vec & b_, Vec & x_)
33 PETSC_SAFE_CALL(KSPSetTolerances(ksp,rtol,abstol,dtol,5));
34 for (
size_t i = 0 ; i < solvs.size() ; i++)
36 setSolver(solvs.get(i).c_str());
39 PETSC_SAFE_CALL(KSPSetConvergenceTest(ksp,KSPConvergedSkip,NULL,NULL));
53 void solve_complex(Mat & A_,
const Vec & b_, Vec & x_)
66 PETSC_SAFE_CALL(MatGetSize(A_,&row,&col));
67 PETSC_SAFE_CALL(MatGetLocalSize(A_,&row_loc,&col_loc));
72 PCSetType(pc,PCBJACOBI);
73 PETSC_SAFE_CALL(KSPSetType(ksp,KSPGMRES));
77 PetscMalloc1(m,&blks);
78 for (
size_t i = 0 ; i < m ; i++) blks[i] = row_loc;
80 PCBJacobiSetLocalBlocks(pc,m,blks);
86 PCBJacobiGetSubKSP(pc,&nlocal,&first,&subksp);
88 for (
size_t i = 0; i < nlocal; i++)
90 KSPGetPC(subksp[i],&subpc);
92 PCSetType(subpc,PCLU);
95 KSPSetType(subksp[i],KSPPREONLY);
123 auto & v_cl = create_vcluster();
124 if (try_solve ==
true)
127 solError err = statSolutionError(A_,b_,x_);
129 if (v_cl.getProcessUnitID() == 0)
131 std::cout <<
"Method: " << s_type <<
" " <<
" pre-conditoner: " << PCJACOBI <<
" iterations: " << err.
its << std::endl;
132 std::cout <<
"Norm of error: " << err.
err_norm <<
" Norm infinity: " << err.
err_inf << std::endl;
138 void solve_ASM(Mat & A_,
const Vec & b_, Vec & x_)
140 PETSC_SAFE_CALL(KSPSetType(ksp,s_type));
148 PETSC_SAFE_CALL(MatGetSize(A_,&row,&col));
149 PETSC_SAFE_CALL(MatGetLocalSize(A_,&row_loc,&col_loc));
154 PETSC_SAFE_CALL(KSPSetOperators(ksp,A_,A_));
157 PETSC_SAFE_CALL(KSPGetPC(ksp,&pc));
158 PETSC_SAFE_CALL(PCSetType(pc,PCASM));
167 PCASMSetOverlap(pc,5);
170 PetscInt nlocal,first;
196 PCASMGetSubKSP(pc,&nlocal,&first,&subksp);
202 for (
size_t i = 0 ; i < nlocal ; i++)
204 KSPGetPC(subksp[i],&subpc);
206 PCFactorSetLevels(subpc,5);
207 PCSetType(subpc,PCILU);
208 KSPSetType(subksp[i],KSPRICHARDSON);
209 KSPSetTolerances(subksp[i],1.e-3,0.1,PETSC_DEFAULT,PETSC_DEFAULT);
214 if (try_solve ==
true)
217 PETSC_SAFE_CALL(KSPMonitorSet(ksp,monitor,&vres,NULL));
220 PETSC_SAFE_CALL(KSPSetConvergenceTest(ksp,KSPConvergedSkip,NULL,NULL));
226 PETSC_SAFE_CALL(KSPSolve(ksp,b_,x_));
228 KSPConvergedReason reason;
229 KSPGetConvergedReason(ksp,&reason);
231 std::cout <<
"Reason: " << reason << std::endl;
233 auto & v_cl = create_vcluster();
237 solError err = statSolutionError(A_,b_,x_);
239 if (v_cl.getProcessUnitID() == 0)
241 std::cout <<
"Method: " << s_type <<
" " <<
" pre-conditoner: " << PCJACOBI <<
" iterations: " << err.
its << std::endl;
242 std::cout <<
"Norm of error: " << err.
err_norm <<
" Norm infinity: " << err.
err_inf << std::endl;
248 void solve_AMG(Mat & A_,
const Vec & b_, Vec & x_)
251 PETSC_SAFE_CALL(KSPSetType(ksp,KSPRICHARDSON));
261 PETSC_SAFE_CALL(MatGetSize(A_,&row,&col));
262 PETSC_SAFE_CALL(MatGetLocalSize(A_,&row_loc,&col_loc));
267 PETSC_SAFE_CALL(KSPSetOperators(ksp,A_,A_));
270 PETSC_SAFE_CALL(KSPGetPC(ksp,&pc));
274 PETSC_SAFE_CALL(PCSetType(pc,PCHYPRE));
276 PCFactorSetShiftType(pc, MAT_SHIFT_NONZERO);
277 PCFactorSetShiftAmount(pc, PETSC_DECIDE);
278 PCHYPRESetType(pc,
"boomeramg");
279 MatSetBlockSize(A_,4);
280 PetscOptionsSetValue(
"-pc_hypre_boomeramg_print_statistics",
"2");
281 PetscOptionsSetValue(
"-pc_hypre_boomeramg_max_iter",
"1000");
282 PetscOptionsSetValue(
"-pc_hypre_boomeramg_nodal_coarsen",
"true");
283 PetscOptionsSetValue(
"-pc_hypre_boomeramg_relax_type_all",
"SOR/Jacobi");
284 PetscOptionsSetValue(
"-pc_hypre_boomeramg_coarsen_type",
"Falgout");
285 PetscOptionsSetValue(
"-pc_hypre_boomeramg_cycle_type",
"W");
286 PetscOptionsSetValue(
"-pc_hypre_boomeramg_max_levels",
"20");
287 PetscOptionsSetValue(
"-pc_hypre_boomeramg_vec_interp_variant",
"0");
288 KSPSetFromOptions(ksp);
292 if (try_solve ==
true)
295 PETSC_SAFE_CALL(KSPMonitorSet(ksp,monitor,&vres,NULL));
298 PETSC_SAFE_CALL(KSPSetConvergenceTest(ksp,KSPConvergedSkip,NULL,NULL));
302 PETSC_SAFE_CALL(KSPSolve(ksp,b_,x_));
304 auto & v_cl = create_vcluster();
308 solError err = statSolutionError(A_,b_,x_);
310 if (v_cl.getProcessUnitID() == 0)
312 std::cout <<
"Method: " << s_type <<
" " <<
" pre-conditoner: " << PCJACOBI <<
" iterations: " << err.
its << std::endl;
313 std::cout <<
"Norm of error: " << err.
err_norm <<
" Norm infinity: " << err.
err_inf << std::endl;
322 void solve_Krylov_simple(Mat & A_,
const Vec & b_, Vec & x_)
324 PETSC_SAFE_CALL(KSPSetType(ksp,s_type));
332 PETSC_SAFE_CALL(MatGetSize(A_,&row,&col));
333 PETSC_SAFE_CALL(MatGetLocalSize(A_,&row_loc,&col_loc));
338 PETSC_SAFE_CALL(KSPSetOperators(ksp,A_,A_));
341 PETSC_SAFE_CALL(KSPGetPC(ksp,&pc));
345 PETSC_SAFE_CALL(PCSetType(pc,PCHYPRE));
347 PCFactorSetShiftType(pc, MAT_SHIFT_NONZERO);
348 PCFactorSetShiftAmount(pc, PETSC_DECIDE);
349 PCHYPRESetType(pc,
"boomeramg");
350 MatSetBlockSize(A_,4);
351 PetscOptionsSetValue(
"-pc_hypre_boomeramg_print_statistics",
"2");
352 PetscOptionsSetValue(
"-pc_hypre_boomeramg_max_iter",
"1000");
353 PetscOptionsSetValue(
"-pc_hypre_boomeramg_nodal_coarsen",
"true");
354 PetscOptionsSetValue(
"-pc_hypre_boomeramg_relax_type_all",
"SOR/Jacobi");
355 PetscOptionsSetValue(
"-pc_hypre_boomeramg_coarsen_type",
"Falgout");
356 PetscOptionsSetValue(
"-pc_hypre_boomeramg_cycle_type",
"W");
357 PetscOptionsSetValue(
"-pc_hypre_boomeramg_max_levels",
"10");
358 KSPSetFromOptions(ksp);
361 if (try_solve ==
true)
364 PETSC_SAFE_CALL(KSPMonitorSet(ksp,monitor,&vres,NULL));
367 PETSC_SAFE_CALL(KSPSetConvergenceTest(ksp,KSPConvergedSkip,NULL,NULL));
371 PETSC_SAFE_CALL(KSPSolve(ksp,b_,x_));
373 auto & v_cl = create_vcluster();
377 solError err = statSolutionError(A_,b_,x_);
379 if (v_cl.getProcessUnitID() == 0)
381 std::cout <<
"Method: " << s_type <<
" " <<
" pre-conditoner: " << PCJACOBI <<
" iterations: " << err.
its << std::endl;
382 std::cout <<
"Norm of error: " << err.
err_norm <<
" Norm infinity: " << err.
err_inf << std::endl;
392 PCASMCreateSubdomains2D(128,128,4,4,1,1,&Nsub,&is,&is_local);
395 if (create_vcluster().getProcessUnitID() == 1)
396 ISView(is_local[1],PETSC_VIEWER_STDOUT_SELF);
It contain statistic of the error of the calculated solution.
PetscReal err_inf
infinity norm of the error
PetscInt its
Number of iterations.
PetscReal err_norm
L1 norm of the error.