Since you set the DM inactive the PCSetUp_MG() has no code to compute the coarser grid operators. You need to either
1) provide a DMKSPSetComputeOperators () function that will compute the operator for all levels or 2) run with -pc_mg_galerkin to have the coarse grid operators computed by multiplying the fine grid operator by the restriction/interpolation. Barry On Nov 14, 2013, at 7:49 PM, Michele Rosso <[email protected]> wrote: > Hi, > > I am solving a Poisson equation (cell-centered discretization) with > multigrid. > I am using a 2D version of ksp/ksp/examples/tutorials/ex34.c as a reference. > The following code performs the same calculations as ex34: > > call PetscInitialize(PETSC_NULL_CHARACTER,ierr) > > call DMDACreate2d(PETSC_COMM_WORLD, DMDA_BOUNDARY_NONE, > DMDA_BOUNDARY_NONE,& > & DMDA_STENCIL_STAR, 16, 16, PETSC_DECIDE, PETSC_DECIDE, & > & 1, 1, PETSC_NULL_INTEGER, PETSC_NULL_INTEGER,da,ierr) > call DMDASetInterpolationType(da, DMDA_Q0, ierr); > call DMCreateGlobalVector(da,b,ierr) > call create_rhs(da,b) > call DMCreateMatrix(da,'aij',A,ierr) > call create_matrix(da,A) > call VecDuplicate(b,x,ierr) > > ! Create solver > call KSPCreate(PETSC_COMM_WORLD,solver,ierr) > call KSPSetDM(solver,da,ierr) > call KSPSetDMActive(solver,PETSC_FALSE,ierr) > call KSPSetOperators(solver,A,A,SAME_NONZERO_PATTERN,ierr) > call KSPSetType(solver,'cg',ierr) > call KSPSetNormType(solver,KSP_NORM_UNPRECONDITIONED,ierr) > call KSPSetFromOptions(solver,ierr) > call KSPSolve(solver,b,x,ierr) > > rerr = error(da,x) > > call PetscFinalize(ierr) > > > Both ex34 and my code produce exactly the same results except when I run with > > -ksp_view -ksp_monitor_true_residual -ksp_converged_reason -ksp_type cg > -pc_type mg -pc_mg_levels 4 > > In this case my code results in the following error, despite KSPSetDMActive > is used after KSPSetDM: > > [0]PETSC ERROR: --------------------- Error Message > ------------------------------------ > [0]PETSC ERROR: Object is in wrong state! > [0]PETSC ERROR: You called KSPSetDM() but did not use > DMKSPSetComputeOperators() or KSPSetDMActive(dm,PETSC_FALSE);! > [0]PETSC ERROR: > ------------------------------------------------------------------------ > [0]PETSC ERROR: Petsc Release Version 3.4.3, Oct, 15, 2013 > [0]PETSC ERROR: See docs/changes/index.html for recent updates. > [0]PETSC ERROR: See docs/faq.html for hints about trouble shooting. > [0]PETSC ERROR: See docs/index.html for manual pages. > [0]PETSC ERROR: > ------------------------------------------------------------------------ > [0]PETSC ERROR: ./test on a linux-gnu-dbg named enterprise-A by mic Thu Nov > 14 17:38:23 2013 > [0]PETSC ERROR: Libraries linked from /opt/petsc/petsc-3.4.3/linux-gnu-dbg/lib > [0]PETSC ERROR: Configure run at Tue Oct 29 22:43:45 2013 > [0]PETSC ERROR: Configure options --known-mpi-shared="0 " --known-memcmp-ok > --with-debugging="1 " --with-fortran-datatypes --with-shared-libraries=0 > --with-dynamic-loading=0 --with-mpi-compilers="1 " --download-blacs="1 " > --download-superlu_dist="1 " --download-metis="1 " --download-parmetis="1 " > --download-ml=1 PETSC_ARCH=linux-gnu-dbg > [0]PETSC ERROR: > ------------------------------------------------------------------------ > [0]PETSC ERROR: KSPSetUp() line 230 in > /opt/petsc/petsc-3.4.3/src/ksp/ksp/interface/itfunc.c > [0]PETSC ERROR: PCSetUp_MG() line 730 in > /opt/petsc/petsc-3.4.3/src/ksp/pc/impls/mg/mg.c > [0]PETSC ERROR: PCSetUp() line 890 in > /opt/petsc/petsc-3.4.3/src/ksp/pc/interface/precon.c > [0]PETSC ERROR: KSPSetUp() line 278 in > /opt/petsc/petsc-3.4.3/src/ksp/ksp/interface/itfunc.c > [0]PETSC ERROR: KSPSolve() line 399 in > /opt/petsc/petsc-3.4.3/src/ksp/ksp/interface/itfunc.c > > > Am I missing anything? > Thank you, > > Michele > > > > > > >
