[petsc-users] Preconditioner in multigrid solver
Pietro Benedusi
pietro.benedusi at usi.ch
Mon Mar 11 09:42:21 CDT 2019
Dear Petsc team,
I have a question about the setting up of a multigrid solver.
I would like yo use a PCG smoother, preconditioned with a mass matrix, just on the fine level.
But when add the line for preconditioning the CG with the mass matrix my MG diverges.
I have implemented the same solver in MATLAB and it converges fine. Also the operators in PETSc are the same and the PCG applied directly on the problem (without MG) works the same in both PETSC and MATLAB.
This is what I do in PETSC for 2 levels:
KSP space_solver;
ierr = KSPCreate(PETSC_COMM_WORLD,&space_solver);CHKERRQ(ierr);
ierr = KSPSetTolerances(space_solver,1e-8,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT);CHKERRQ(ierr);
ierr = KSPSetOperators(space_solver, K, K);CHKERRQ(ierr);
ierr = KSPSetNormType(space_solver, KSP_NORM_UNPRECONDITIONED );CHKERRQ(ierr);
ierr = KSPSetType(space_solver,KSPRICHARDSON);CHKERRQ(ierr);
ierr = KSPSetFromOptions(space_solver);CHKERRQ(ierr);
ierr = KSPSetUp(space_solver);CHKERRQ(ierr);
PC pcmg;
ierr = KSPGetPC(space_solver, &pcmg);
ierr = PCSetType(pcmg, PCMG);
ierr = PCMGSetLevels(pcmg,levels, NULL);CHKERRQ(ierr);
ierr = PCMGSetGalerkin(pcmg,PC_MG_GALERKIN_BOTH);CHKERRQ(ierr);
// smoothers
for (int i = 1; i < levels; ++i)
{
KSP smoother;
ierr = PCMGGetSmoother(pcmg, i, &smoother);CHKERRQ(ierr);
ierr = KSPSetType(smoother, KSPCG);CHKERRQ(ierr);
ierr = KSPSetOperators(smoother, K, M);CHKERRQ(ierr);
// ierr = KSPSetUp(smoother);CHKERRQ(ierr);
ierr = KSPSetTolerances(smoother,1e-12,PETSC_DEFAULT,PETSC_DEFAULT,s_p);CHKERRQ(ierr);
ierr = KSPSetNormType(smoother, KSP_NORM_NONE);CHKERRQ(ierr);
PC sm;
ierr = KSPGetPC(smoother, &sm);CHKERRQ(ierr);
ierr = PCSetType(sm, PCLU);CHKERRQ(ierr);
ierr = PCMGSetInterpolation(pcmg, i, interpolation_operators[i-1]);CHKERRQ(ierr);
}
I think there is a problem with the PETSc syntax, because I checked everything else and it is fine.
Do you any ideas?
Thank you very much!
Best,
Pietro
~~~~~~~~~~~~
Pietro Benedusi
Numerical Simulation in Science,
Medicine and Engineering research group
ICS, Institute of Computational Science
USI, Università della Svizzera Italiana
Via Giuseppe Buffi, 13
CH - 6900 Lugano
benedp at usi.ch<mailto:benedp at usi.ch>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190311/22b601ad/attachment.html>
More information about the petsc-users
mailing list