<div class="gmail_quote">On Sun, Jun 10, 2012 at 12:10 AM, Nakib Haider Protik <span dir="ltr"><<a href="mailto:nprot048@uottawa.ca" target="_blank">nprot048@uottawa.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div id=":37y">I am working on a Poisson Solver and ran into a problem using the<br>
multigrid preconditioner. I am using petsc-3.0.0-p12. </div></blockquote><div><br></div><div>Please upgrade to petsc-3.3</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div id=":37y">Here's the relevant<br>
section of the code:<br>
<br>
////////////////////Solver Stuff////////////////////<br>
    KSPCreate(PETSC_COMM_WORLD, &ksp);<br>
    KSPSetType(ksp, KSPGMRES);<br>
<br>
    KSPSetFromOptions(ksp);<br>
<br>
    KSPGetPC(ksp, &pc);<br>
    PCSetType(pc, PCMG);<br>
    PCMGSetLevels(pc, 2, PETSC_NULL);<br>
    PCMGSetType(pc, PC_MG_MULTIPLICATIVE);<br>
    PCMGSetCycleType(pc, PC_MG_CYCLE_V);<br>
    MatDuplicate(A, MAT_COPY_VALUES, &P);<br>
    PCMGSetCyclesOnLevel(pc, 0, 1);<br>
    PCMGSetCyclesOnLevel(pc, 1, 1);<br>
    PCMGGetCoarseSolve(pc, &ksp);<br>
    PCMGGetSmoother(pc, 0, &ksp);<br>
    PCMGSetResidual(pc, 0, PCMGDefaultResidual, P);<br>
    PCMGSetRestriction(pc, 1, P);<br>
    PCMGSetInterpolation(pc, 1, P);<br>
    PCMGSetRestriction(pc, 1, P);<br>
    PCMGSetResidual(pc, 1, PCMGDefaultResidual, P);<br>
<br>
    //Code breaks if I use the next line. Why?<br>
    //It worked fine in the 1d case.<br>
    //PCMGGetSmoother(pc, 1, &ksp);<br></div></blockquote><div><br></div><div>This overwrites the "ksp" variable</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div id=":37y">
<br>
<br>
    KSPSetOperators(ksp, A, P, DIFFERENT_NONZERO_PATTERN);<br>
    //KSPSetOperators( ksp, A, A, SAME_NONZERO_PATTERN );<br>
    //KSPSetOperators( ksp, A, A, SAME_PRECONDITIONER );<br>
    KSPSetFromOptions(ksp);<br>
    KSPSolve(ksp, breal, xreal_harm);<br>
    KSPSolve(ksp, bimag, ximag_harm);</div></blockquote></div><br><div>which you use in place of the "fine grid" problem here.</div><div><br></div><div>It probably accidentally works in 1D because the "smoother" involved ILU which is equivalent to LU for a 1D problem.</div>