[petsc-users] pctype comparison
Barry Smith
bsmith at mcs.anl.gov
Tue May 7 13:01:39 CDT 2013
On May 7, 2013, at 6:42 AM, Matthew Knepley <knepley at gmail.com> wrote:
> On Tue, May 7, 2013 at 4:49 AM, Frederik Treue <frtr at fysik.dtu.dk> wrote:
> Hi,
>
> is there any way of checking which type of PC you are using in the code?
> Ie. I want to do something like:
>
> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscObjectTypeCompare.html
>
> Matt
>
> ...
> PCType mytype;
> PC pc;
> if (PhaseOfTheMoon==waxing) {
> mytype=PCJacobi;
> } else {
> mytype=PCMG;
> }
> ...
> ierr=PCSetType(pc,mytype);CHKERRQ(ierr);
> if (mytype==PCMG) {
> ierr=PCMGSetLevels(pc,levels,PETSC_NULL);CHKERRQ(ierr);
> …
Note that also PETSc is designed to ignore options for types that are not being used. So you do not need the
if (mgtype == PCMG) { stuff at all
simply write
PCSetFromOptions(pc);
ierr=PCMGSetLevels(pc,levels,PETSC_NULL);CHKERRQ(ierr); /* will only activate if a MG PC selected
ierr =PCFactorSetLevels(pc,2); /* will only activate if a factorization based preconditioner
etc etc
Barry
> }
> ...
>
> But since mytype is apparently a pointer type, this doesn't work.
>
> /Frederik Treue
>
>
>
>
>
> --
> 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
More information about the petsc-users
mailing list