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 = &amp;ctx-&gt;parameters;<br>  JoabView *view = &amp;ctx-&gt;view;<br>
  JoabGrid *grid = &amp;ctx-&gt;grid;<br>  JoabGrid *coarsegrid = &amp;ctx-&gt;coarsegrid;<br>  JoabAlgebra *algebra = &amp;ctx-&gt;algebra;<br>  JoabAlgebra *coarsealgebra = &amp;ctx-&gt;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,&amp;fineksp);CHKERRQ(ierr);<br>
  ierr = KSPGetPC(fineksp,&amp;finepc);CHKERRQ(ierr);<br>  ierr = KSPCreate(PETSC_COMM_WORLD,&amp;ctx-&gt;coarseksp);CHKERRQ(ierr);<br><br>  ierr = SetMyKSPDefaults(ctx-&gt;coarseksp);CHKERRQ(ierr); <br>  ierr = KSPSetFromOptions(ctx-&gt;coarseksp);CHKERRQ(ierr);<br>
  ierr = KSPSetOperators(ctx-&gt;coarseksp, coarsealgebra-&gt;H, coarsealgebra-&gt;H,<br>               SAME_NONZERO_PATTERN);CHKERRQ(ierr);<br>  if (parameters-&gt;geometric_asm) {<br>    ierr = KSPGetPC(ctx-&gt;coarseksp, &amp;coarsepc);CHKERRQ(ierr);<br>
    ierr = PCASMSetOverlap(coarsepc,0);CHKERRQ(ierr);<br>    ierr = PCASMSetLocalSubdomains(coarsepc,1,&amp;coarsegrid-&gt;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,&amp;asmpc);CHKERRQ(ierr);<br>
  if (parameters-&gt;geometric_asm) {<br>    ierr = PCSetType(asmpc,PCASM);CHKERRQ(ierr);<br>    ierr = PCASMSetOverlap(asmpc,0);CHKERRQ(ierr);<br>    ierr = PCASMSetLocalSubdomains(asmpc,1,&amp;grid-&gt;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,&amp;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,&quot;Setup coarse level preconditioner.....\n&quot;);CHKERRQ(ierr);<br>  ierr = PCShellGetContext(pc,(void**)&amp;ctx);CHKERRQ(ierr);<br>
  parameters = &amp;ctx-&gt;parameters;<br>  view = &amp;ctx-&gt;view;<br>  finegrid = &amp;ctx-&gt;grid;<br>  coarsegrid = &amp;ctx-&gt;coarsegrid;<br>  finealgebra = &amp;ctx-&gt;algebra;<br>  coarsealgebra = &amp;ctx-&gt;coarsealgebra;<br>
<br>  ierr = PetscGetTime(&amp;t1);CHKERRQ(ierr);<br><br>  parameters-&gt;whichlevel = COARSE_GRID;<br><br>  /* restrict fine grid to coarse grid */<br>  ierr = PetscGetTime(&amp;v1);CHKERRQ(ierr);<br>  ierr = VecSet(coarsealgebra-&gt;predictedShape_opt,0.0);CHKERRQ(ierr);CHKERRQ(ierr);<br>
  ierr = ApplyRestriction(ctx,xin,coarsealgebra-&gt;predictedShape_opt);CHKERRQ(ierr); <br>  <br>  ierr = VecSet(coarsealgebra-&gt;solutionShape_opt,0.0);CHKERRQ(ierr);<br>  ierr = KSPSetTolerances(ctx-&gt;coarseksp,1e-6,1e-14,PETSC_DEFAULT,1000);CHKERRQ(ierr);<br>
  ierr = KSPSolve(ctx-&gt;coarseksp, coarsealgebra-&gt;predictedShape_opt, coarsealgebra-&gt;solutionShape_opt);CHKERRQ(ierr);<br><br>  /* interpolate coarse grid to fine grid */<br>  ierr = MatInterpolate(ctx-&gt;Interp,coarsealgebra-&gt;solutionShape_opt,xout);CHKERRQ(ierr); <br>
<br>  PetscFunctionReturn(0);<br>}<br><br><br>Regards,<br>Rongliang<br><br><br>