Hi,<br><br>I faced a problem when I used the function PCShellSetApply to set a composite PC in Petsc 3.1. There was no problem when I compiled my code but I got the following message when I run the code.<br>------------------------------------------------------------------------------------------------------------<br>
[0]PETSC ERROR: [1]PETSC ERROR: --------------------- Error Message ------------------------------------<br>[1]PETSC ERROR: No support for this operation for this object type!<br>[1]PETSC ERROR: Matrix format mpiaij does not have a built-in PETSc direct solver!<br>
[1]PETSC ERROR: ------------------------------------------------------------------------<br>[1]PETSC ERROR: Petsc Release Version 3.1.0, Patch 8, Thu Mar 17 13:37:48 CDT 2011<br>...............................<br>[7]PETSC ERROR: MatGetFactor() line 3644 in src/mat/interface/matrix.c<br>
[7]PETSC ERROR: PCSetUp_LU() line 133 in src/ksp/pc/impls/factor/lu/lu.c<br>[7]PETSC ERROR: PCSetUp() line 795 in src/ksp/pc/interface/precon.c<br>[7]PETSC ERROR: PCApply() line 353 in src/ksp/pc/interface/precon.c<br>[7]PETSC ERROR: PCApply_Composite_Additive() line 102 in src/ksp/pc/impls/composite/composite.c<br>
[7]PETSC ERROR: PCApply() line 357 in src/ksp/pc/interface/precon.c<br>[7]PETSC ERROR: PCApplyBAorAB() line 582 in src/ksp/pc/interface/precon.c<br>[7]PETSC ERROR: GMREScycle() line 161 in src/ksp/ksp/impls/gmres/gmres.c<br>
[7]PETSC ERROR: KSPSolve_GMRES() line 241 in src/ksp/ksp/impls/gmres/gmres.c<br>[7]PETSC ERROR: KSPSolve() line 396 in src/ksp/ksp/interface/itfunc.c<br>[1]PETSC ERROR: SNES_KSPSolve() line 2944 in src/snes/interface/snes.c<br>
[1]PETSC ERROR: SNESSolve_LS() line 191 in src/snes/impls/ls/ls.c<br>[1]PETSC ERROR: SNESSolve() line 2255 in src/snes/interface/snes.c<br>..............................<br>--------------------------------------------------------------------------------------------------------------<br>
<br>I found that the function PCShellSetApply did not call the user defined function CoarseSolvePCApply (I called PCShellSetApply like this: ierr = PCShellSetApply(coarsesolve, CoarseSolvePCApply);CHKERRQ(ierr); ). Can anyone tell me what may be the problem? The related code attached.<br>
<br>-----------------------The related code-----------------------------------<br>PetscErrorCode SetupPreconditioner(JoabCtx* ctx, SNES snes)<br>{<br> JoabParameters *parameters = &ctx->parameters;<br> JoabView *view = &ctx->view;<br>
JoabGrid *grid = &ctx->grid;<br> JoabGrid *coarsegrid = &ctx->coarsegrid;<br> JoabAlgebra *algebra = &ctx->algebra;<br> JoabAlgebra *coarsealgebra = &ctx->coarsealgebra;<br><br> KSP fineksp;<br>
PC finepc, coarsepc;<br> PC asmpc;<br> PC coarsesolve;<br> Vec fineones;<br> PetscInt veclength;<br> PetscScalar *values;<br> int i;<br><br> PetscErrorCode ierr;<br> <br> PetscFunctionBegin;<br> ierr = SNESGetKSP(snes,&fineksp);CHKERRQ(ierr);<br>
ierr = KSPGetPC(fineksp,&finepc);CHKERRQ(ierr);<br> ierr = KSPCreate(PETSC_COMM_WORLD,&ctx->coarseksp);CHKERRQ(ierr);<br><br> ierr = SetMyKSPDefaults(ctx->coarseksp);CHKERRQ(ierr); <br> ierr = KSPSetFromOptions(ctx->coarseksp);CHKERRQ(ierr);<br>
ierr = KSPSetOperators(ctx->coarseksp, coarsealgebra->H, coarsealgebra->H,<br> SAME_NONZERO_PATTERN);CHKERRQ(ierr);<br> if (parameters->geometric_asm) {<br> ierr = KSPGetPC(ctx->coarseksp, &coarsepc);CHKERRQ(ierr);<br>
ierr = PCASMSetOverlap(coarsepc,0);CHKERRQ(ierr);<br> ierr = PCASMSetLocalSubdomains(coarsepc,1,&coarsegrid->df_global_asm, PETSC_NULL);CHKERRQ(ierr);<br> }<br><br> ierr = PCSetType(finepc,PCCOMPOSITE);CHKERRQ(ierr);<br>
ierr = PCCompositeAddPC(finepc,PCSHELL);CHKERRQ(ierr);<br> ierr = PCCompositeAddPC(finepc,PCASM);CHKERRQ(ierr); <br><br> /* set up asm (fine) part of two-level preconditioner */<br> ierr = PCCompositeGetPC(finepc,1,&asmpc);CHKERRQ(ierr);<br>
if (parameters->geometric_asm) {<br> ierr = PCSetType(asmpc,PCASM);CHKERRQ(ierr);<br> ierr = PCASMSetOverlap(asmpc,0);CHKERRQ(ierr);<br> ierr = PCASMSetLocalSubdomains(asmpc,1,&grid->df_global_asm, PETSC_NULL);CHKERRQ(ierr);<br>
}<br> ierr = SetMyPCDefaults(asmpc);CHKERRQ(ierr); <br> ierr = PCSetFromOptions(asmpc);CHKERRQ(ierr);<br><br> /* set up coarse solve part of two-level preconditioner */<br> ierr = PCCompositeGetPC(finepc,0,&coarsesolve);CHKERRQ(ierr);<br>
ierr = PCShellSetContext(coarsesolve,ctx);CHKERRQ(ierr);<br> ierr = PCShellSetApply(coarsesolve, CoarseSolvePCApply);CHKERRQ(ierr);<br> <br> PetscFunctionReturn(0);<br>}<br><br>PetscErrorCode CoarseSolvePCApply(PC pc, Vec xin, Vec xout)<br>
{<br> JoabCtx *ctx;<br> PetscErrorCode ierr;<br> JoabParameters *parameters;<br> JoabView *view;<br> JoabGrid *finegrid;<br> JoabGrid *coarsegrid;<br> JoabAlgebra *finealgebra;<br> JoabAlgebra *coarsealgebra;<br> PetscInt its;<br>
PetscLogDouble t1,t2,v1,v2;<br> KSPConvergedReason reason;<br><br> PetscFunctionBegin;<br> ierr = PetscPrintf(PETSC_COMM_WORLD,"Setup coarse level preconditioner.....\n");CHKERRQ(ierr);<br> ierr = PCShellGetContext(pc,(void**)&ctx);CHKERRQ(ierr);<br>
parameters = &ctx->parameters;<br> view = &ctx->view;<br> finegrid = &ctx->grid;<br> coarsegrid = &ctx->coarsegrid;<br> finealgebra = &ctx->algebra;<br> coarsealgebra = &ctx->coarsealgebra;<br>
<br> ierr = PetscGetTime(&t1);CHKERRQ(ierr);<br><br> parameters->whichlevel = COARSE_GRID;<br><br> /* restrict fine grid to coarse grid */<br> ierr = PetscGetTime(&v1);CHKERRQ(ierr);<br> ierr = VecSet(coarsealgebra->predictedShape_opt,0.0);CHKERRQ(ierr);CHKERRQ(ierr);<br>
ierr = ApplyRestriction(ctx,xin,coarsealgebra->predictedShape_opt);CHKERRQ(ierr); <br> <br> ierr = VecSet(coarsealgebra->solutionShape_opt,0.0);CHKERRQ(ierr);<br> ierr = KSPSetTolerances(ctx->coarseksp,1e-6,1e-14,PETSC_DEFAULT,1000);CHKERRQ(ierr);<br>
ierr = KSPSolve(ctx->coarseksp, coarsealgebra->predictedShape_opt, coarsealgebra->solutionShape_opt);CHKERRQ(ierr);<br><br> /* interpolate coarse grid to fine grid */<br> ierr = MatInterpolate(ctx->Interp,coarsealgebra->solutionShape_opt,xout);CHKERRQ(ierr); <br>
<br> PetscFunctionReturn(0);<br>}<br><br><br>Regards,<br>Rongliang<br><br><br>