1*dba47a55SKris Buschelman #define PETSCKSP_DLL 2*dba47a55SKris Buschelman 34b9ad928SBarry Smith /* 44b9ad928SBarry Smith Full multigrid using either additive or multiplicative V or W cycle 54b9ad928SBarry Smith */ 64b9ad928SBarry Smith #include "src/ksp/pc/impls/mg/mgimpl.h" 74b9ad928SBarry Smith 8dfbe8321SBarry Smith EXTERN PetscErrorCode MGMCycle_Private(MG *,PetscTruth*); 94b9ad928SBarry Smith 104b9ad928SBarry Smith /* 114b9ad928SBarry Smith MGFCycle_Private - Given an MG structure created with MGCreate() runs 124b9ad928SBarry Smith full multigrid. 134b9ad928SBarry Smith 144b9ad928SBarry Smith Iput Parameters: 154b9ad928SBarry Smith . mg - structure created with MGCreate(). 164b9ad928SBarry Smith 174b9ad928SBarry Smith Note: This may not be what others call full multigrid. What we 184b9ad928SBarry Smith do is restrict the rhs to all levels, then starting 194b9ad928SBarry Smith on the coarsest level work our way up generating 204b9ad928SBarry Smith initial guess for the next level. This provides an 214b9ad928SBarry Smith improved preconditioner but not a great improvement. 224b9ad928SBarry Smith */ 234b9ad928SBarry Smith #undef __FUNCT__ 244b9ad928SBarry Smith #define __FUNCT__ "MGFCycle_Private" 25dfbe8321SBarry Smith PetscErrorCode MGFCycle_Private(MG *mg) 264b9ad928SBarry Smith { 276849ba73SBarry Smith PetscErrorCode ierr; 2879416396SBarry Smith PetscInt i,l = mg[0]->levels; 294b9ad928SBarry Smith PetscScalar zero = 0.0; 304b9ad928SBarry Smith 314b9ad928SBarry Smith PetscFunctionBegin; 324b9ad928SBarry Smith /* restrict the RHS through all levels to coarsest. */ 334b9ad928SBarry Smith for (i=l-1; i>0; i--){ 344b9ad928SBarry Smith ierr = MatRestrict(mg[i]->restrct,mg[i]->b,mg[i-1]->b);CHKERRQ(ierr); 354b9ad928SBarry Smith } 364b9ad928SBarry Smith 374b9ad928SBarry Smith /* work our way up through the levels */ 384b9ad928SBarry Smith ierr = VecSet(&zero,mg[0]->x);CHKERRQ(ierr); 394b9ad928SBarry Smith for (i=0; i<l-1; i++) { 404b9ad928SBarry Smith ierr = MGMCycle_Private(&mg[i],PETSC_NULL);CHKERRQ(ierr); 414b9ad928SBarry Smith ierr = MatInterpolate(mg[i+1]->interpolate,mg[i]->x,mg[i+1]->x);CHKERRQ(ierr); 424b9ad928SBarry Smith } 434b9ad928SBarry Smith ierr = MGMCycle_Private(&mg[l-1],PETSC_NULL);CHKERRQ(ierr); 444b9ad928SBarry Smith PetscFunctionReturn(0); 454b9ad928SBarry Smith } 464b9ad928SBarry Smith 474b9ad928SBarry Smith /* 484b9ad928SBarry Smith MGKCycle_Private - Given an MG structure created with MGCreate() runs 494b9ad928SBarry Smith full Kascade MG solve. 504b9ad928SBarry Smith 514b9ad928SBarry Smith Iput Parameters: 524b9ad928SBarry Smith . mg - structure created with MGCreate(). 534b9ad928SBarry Smith 544b9ad928SBarry Smith Note: This may not be what others call Kascadic MG. 554b9ad928SBarry Smith */ 564b9ad928SBarry Smith #undef __FUNCT__ 574b9ad928SBarry Smith #define __FUNCT__ "MGKCycle_Private" 58dfbe8321SBarry Smith PetscErrorCode MGKCycle_Private(MG *mg) 594b9ad928SBarry Smith { 606849ba73SBarry Smith PetscErrorCode ierr; 6179416396SBarry Smith PetscInt i,l = mg[0]->levels; 624b9ad928SBarry Smith PetscScalar zero = 0.0; 634b9ad928SBarry Smith 644b9ad928SBarry Smith PetscFunctionBegin; 654b9ad928SBarry Smith /* restrict the RHS through all levels to coarsest. */ 664b9ad928SBarry Smith for (i=l-1; i>0; i--){ 674b9ad928SBarry Smith ierr = MatRestrict(mg[i]->restrct,mg[i]->b,mg[i-1]->b);CHKERRQ(ierr); 684b9ad928SBarry Smith } 694b9ad928SBarry Smith 704b9ad928SBarry Smith /* work our way up through the levels */ 714b9ad928SBarry Smith ierr = VecSet(&zero,mg[0]->x);CHKERRQ(ierr); 724b9ad928SBarry Smith for (i=0; i<l-1; i++) { 734b9ad928SBarry Smith if (mg[i]->eventsolve) {ierr = PetscLogEventBegin(mg[i]->eventsolve,0,0,0,0);CHKERRQ(ierr);} 7423ce1328SBarry Smith ierr = KSPSolve(mg[i]->smoothd,mg[i]->b,mg[i]->x);CHKERRQ(ierr); 754b9ad928SBarry Smith if (mg[i]->eventsolve) {ierr = PetscLogEventEnd(mg[i]->eventsolve,0,0,0,0);CHKERRQ(ierr);} 764b9ad928SBarry Smith ierr = MatInterpolate(mg[i+1]->interpolate,mg[i]->x,mg[i+1]->x);CHKERRQ(ierr); 774b9ad928SBarry Smith } 784b9ad928SBarry Smith if (mg[l-1]->eventsolve) {ierr = PetscLogEventBegin(mg[l-1]->eventsolve,0,0,0,0);CHKERRQ(ierr);} 7923ce1328SBarry Smith ierr = KSPSolve(mg[l-1]->smoothd,mg[l-1]->b,mg[l-1]->x);CHKERRQ(ierr); 804b9ad928SBarry Smith if (mg[l-1]->eventsolve) {ierr = PetscLogEventEnd(mg[l-1]->eventsolve,0,0,0,0);CHKERRQ(ierr);} 814b9ad928SBarry Smith 824b9ad928SBarry Smith PetscFunctionReturn(0); 834b9ad928SBarry Smith } 844b9ad928SBarry Smith 854b9ad928SBarry Smith 86