[petsc-users] Preconditioner in multigrid solver

Matthew Knepley knepley at gmail.com
Mon Mar 11 11:28:11 CDT 2019


On Mon, Mar 11, 2019 at 10:42 AM Pietro Benedusi via petsc-users <
petsc-users at mcs.anl.gov> wrote:

> 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:
>

Send the output of -ksp_view so we can see what the exact solver is. It
will not tell whether the matrices you set are the correct ones, but at
least we can see the solver.

Also, did you look at the residual decrease? Is  the smoother working on
every level but the finest? Is the coarse grid correction effective?

  Thanks,

     Matt


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

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190311/081504ee/attachment-0001.html>


More information about the petsc-users mailing list