Reason for two ksp objects: Multigrid and Domain Decomposition in PETSc Barry Smith PETSc Developer
pg 28: //Use same pre and post smoother MGGetSmoother(pc,int level,KSP *ksp); //Use different pre and post smoother MGGetSmootherDown(pc,int level,KSP *dksp); MGGetSmootherUp(pc,int level,KSP *uksp); I was trying to use the second in my code. I would be greatly helped if you could tell me where exactly my code goes wrong. As for the "accidental" correctness of the 1d code, here's where I found the prototype: http://lists.mcs.anl.gov/pipermail/petsc-users/2011-May/008793.html If my question does not abide by the regulations of this mailing list, or if you are not obliged to answers questions of this kind, please let me know. I am not looking for free lessons on c, but thanks for the link. Despite the rude reply, thank you for taking the time. > On Sun, Jun 10, 2012 at 3:49 PM, Nakib Haider Protik > <nprot048 at uottawa.ca>wrote: > >> Thank you very much for the reply. Here's a change that works for the 2D >> case: >> >> ////////////////////MG Solver Stuff//////////////////// >> KSPCreate(PETSC_COMM_WORLD, &ksp); >> KSPSetType(ksp, KSPGMRES); >> >> KSPCreate(PETSC_COMM_WORLD, &kspu); >> KSPSetType(kspu, KSPGMRES); >> > > Why do you have two KSPs here? > > >> >> KSPGetPC(ksp, &pc); >> KSPGetPC(kspu, &pc); >> > > Why? > > >> >> PCSetType(pc, PCMG); >> PCMGSetLevels(pc, 2, PETSC_NULL); >> PCMGSetType(pc, PC_MG_MULTIPLICATIVE); >> PCMGSetCycleType(pc, PC_MG_CYCLE_V); >> MatDuplicate(A, MAT_COPY_VALUES, &P); >> PCMGSetCyclesOnLevel(pc, 0, 1); >> PCMGSetCyclesOnLevel(pc, 1, 1); >> PCMGGetCoarseSolve(pc, &ksp); >> PCMGGetSmootherDown(pc, 0, &ksp); >> PCMGGetSmootherUp(pc, 1, &kspu);//(*)// >> > > Okay, clearly you need to learn how variables work in C. Here is a free > resource. > > http://c.learncodethehardway.org/book/ > > (Any other resource will also do.) When you are comfortable with the > language, we can revisit your code. > > >> PCMGSetInterpolation(pc, 1, P); >> PCMGSetRestriction(pc, 1, P); >> PCMGSetResidual(pc, 0, PCMGDefaultResidual, P); >> PCMGSetResidual(pc, 1, PCMGDefaultResidual, P); >> KSPSetOperators(ksp, A, P, SAME_NONZERO_PATTERN); >> KSPSetFromOptions(ksp); >> KSPSolve(ksp, breal, xreal_harm); >> KSPSolve(ksp, bimag, ximag_harm); >> ////////////////////////////////////////////////////////// >> >> Do you think this is working again because of some accident? Without the >> step marked with a //(*)//, the code works too. >> > -- Nakib
