<div class="gmail_quote">On Sun, Jun 10, 2012 at 8:32 PM, 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">
Here's the code with the changes you suggested followed by the terminal<br>
output:<br>
<br>
KSPCreate(PETSC_COMM_WORLD, &ksp);<br>
//KSPCreate(PETSC_COMM_WORLD, &cksp);<br>
//KSPCreate(PETSC_COMM_WORLD, &uksp);<br>
//KSPCreate(PETSC_COMM_WORLD, &dksp);<br>
<br>
//KSPSetType(ksp, KSPGMRES);<br>
//KSPSetType(cksp, KSPGMRES);<br>
//KSPSetType(uksp, KSPGMRES);<br>
//KSPSetType(dksp, KSPGMRES);<br>
<br>
KSPGetPC(ksp, &pc);<br>
//KSPGetPC(cksp, &pc);<br>
//KSPGetPC(uksp, &pc);<br>
//KSPGetPC(dksp, &pc);<br>
<div class="im"><br>
KSPSetFromOptions(ksp);<br>
<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>
<br>
</div> //PCMGGetCoarseSolve(pc, &cksp);<br>
//PCMGGetSmootherDown(pc, 0, &dksp);<br>
//PCMGGetSmootherUp(pc, 1, &uksp);<br>
<div class="im"><br>
PCMGSetInterpolation(pc, 1, P);<br>
PCMGSetRestriction(pc, 1, P);<br>
PCMGSetResidual(pc, 0, PCMGDefaultResidual, P);<br>
PCMGSetResidual(pc, 1, PCMGDefaultResidual, P);<br></div></blockquote><div><br></div><div>^^ I already explained that these lines are semantically incorrect. You are using the matrix P in different places that do not make sense.</div>
<div><br></div><div>You have not set an operator for the smoother and you haven't set a vector. You have to do at least one of those if you want to use the "advanced" PCMG interface.</div><div><br></div><div>
<br></div><div>Before trying anything else, install petsc-3.3 and read through this example.</div><div><br></div><div><a href="http://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/examples/tutorials/ex45.c.html">http://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/examples/tutorials/ex45.c.html</a></div>
<div><br></div><div>Compile it and run it with</div><div><br></div><div>./ex45 -da_refine 3 -ksp_monitor -pc_type mg -ksp_view</div><div><br></div><div>Read through the output and understand what algorithm it is using.</div>
<div><br></div><div>Run with -help and look at the options starting with "-pc_mg" and "-mg_levels".</div><div><br></div><div>Change the algorithm using command line parameters.</div><div><br></div><div>
Then, and only then, consider using the low-level PCMG interface directly.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<br>
</div><div class="im"> KSPSetOperators(ksp, A, P, SAME_NONZERO_PATTERN);<br>
KSPSolve(ksp, breal, xreal_harm);<br>
KSPSolve(ksp, bimag, ximag_harm);<br>
<br>
</div>[0]PETSC ERROR: --------------------- Error Message<br>
------------------------------------<br>
[0]PETSC ERROR: Null argument, when expecting valid pointer!<br>
[0]PETSC ERROR: Null Object: Parameter # 1!<br>
[0]PETSC ERROR:<br>
------------------------------------------------------------------------<br>
[0]PETSC ERROR: Petsc Release Version 3.0.0, Patch 12, Tue Mar 16 23:20:08<br>
CDT 2010<br></blockquote><div><br></div><div>I have asked you several times to upgrade to petsc-3.3. Please do that now, before you write back to this list.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
[0]PETSC ERROR: See docs/changes/index.html for recent updates.<br>
[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>
[0]PETSC ERROR: See docs/index.html for manual pages.<br>
[0]PETSC ERROR:<br>
------------------------------------------------------------------------<br>
[0]PETSC ERROR: ./3dPoissonSolver-cyl-test on a linux-gnu named nakib-F82Q<br>
by nakib Sun Jun 10 21:30:04 2012<br>
[0]PETSC ERROR: Libraries linked from<br>
/home/nakib/petsc-3.0.0-p12/linux-gnu-c-debug/lib<br>
[0]PETSC ERROR: Configure run at Wed May 9 13:44:03 2012<br>
[0]PETSC ERROR: Configure options --with-cc=gcc --with-fc=gfortran<br>
--download-f-blas-lapack=1 --download-mpich=1 --with-shared=0<br>
[0]PETSC ERROR:<br>
------------------------------------------------------------------------<br>
[0]PETSC ERROR: MatGetVecs() line 7098 in src/mat/interface/matrix.c<br>
[0]PETSC ERROR: KSPGetVecs() line 820 in src/ksp/ksp/interface/iterativ.c<br>
[0]PETSC ERROR: PCSetUp_MG() line 465 in src/ksp/pc/impls/mg/mg.c<br>
[0]PETSC ERROR: PCSetUp() line 794 in src/ksp/pc/interface/precon.c<br>
[0]PETSC ERROR: KSPSetUp() line 237 in src/ksp/ksp/interface/itfunc.c<br>
[0]PETSC ERROR: KSPSolve() line 353 in src/ksp/ksp/interface/itfunc.c<br>
[0]PETSC ERROR: --------------------- Error Message<br>
------------------------------------<br>
[0]PETSC ERROR: Null argument, when expecting valid pointer!<br>
[0]PETSC ERROR: Null Object: Parameter # 1!<br>
[0]PETSC ERROR:<br>
------------------------------------------------------------------------<br>
[0]PETSC ERROR: Petsc Release Version 3.0.0, Patch 12, Tue Mar 16 23:20:08<br>
CDT 2010<br>
[0]PETSC ERROR: See docs/changes/index.html for recent updates.<br>
[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>
[0]PETSC ERROR: See docs/index.html for manual pages.<br>
[0]PETSC ERROR:<br>
------------------------------------------------------------------------<br>
[0]PETSC ERROR: ./3dPoissonSolver-cyl-test on a linux-gnu named nakib-F82Q<br>
by nakib Sun Jun 10 21:30:04 2012<br>
[0]PETSC ERROR: Libraries linked from<br>
/home/nakib/petsc-3.0.0-p12/linux-gnu-c-debug/lib<br>
[0]PETSC ERROR: Configure run at Wed May 9 13:44:03 2012<br>
[0]PETSC ERROR: Configure options --with-cc=gcc --with-fc=gfortran<br>
--download-f-blas-lapack=1 --download-mpich=1 --with-shared=0<br>
[0]PETSC ERROR:<br>
------------------------------------------------------------------------<br>
[0]PETSC ERROR: MatGetVecs() line 7098 in src/mat/interface/matrix.c<br>
[0]PETSC ERROR: KSPGetVecs() line 820 in src/ksp/ksp/interface/iterativ.c<br>
[0]PETSC ERROR: PCSetUp_MG() line 465 in src/ksp/pc/impls/mg/mg.c<br>
[0]PETSC ERROR: PCSetUp() line 794 in src/ksp/pc/interface/precon.c<br>
[0]PETSC ERROR: KSPSetUp() line 237 in src/ksp/ksp/interface/itfunc.c<br>
[0]PETSC ERROR: KSPSolve() line 353 in src/ksp/ksp/interface/itfunc.c<br>
<br>
The code converges to the wrong solution too.<br></blockquote><div><br></div><div>The error above is fatal, the solver is not configured correctly. You are supposed to catch the error (you can use the CHKERRQ macro).</div>
<div><br></div></div>