[petsc-users] the specific preconditioner

huaibao zhang paulhuaizhang at gmail.com
Fri Nov 21 08:18:58 CST 2014


Hi Jed,

I have a specific question regarding the attached my initialization function.  Previously I used  KSPSetType(ksp,KSPFGMRES) solver, and I would like to see if there is some improvement using the other choices like KSPBCGS. It seems hoverer, the PC         //PCSetType(pc,PCBJACOBI)  does  not work with me. And I am not quite sure why. 

By the way, can you please give some suggestions on my code? I am not quite sure if I am doing the things rightly. 


Many thanks,
Paul




void petsc_init(void) {

        vector<Cell>::iterator cit;
        vector<int>::iterator it;

        //Create nonlinear solver context
        KSPCreate(PETSC_COMM_WORLD,&ksp);

        VecCreateMPI(PETSC_COMM_WORLD,grid[gid].cellCount*nVars,grid[gid].globalCellCount*nVars,&RHS);
        VecSetFromOptions(RHS);
        VecDuplicate(RHS,&deltaX);


        VecSet(RHS,0.);
        VecSet(deltaX,0.);

        vector<int> diagonal_nonzeros, off_diagonal_nonzeros;
        int nextCellCount;

        // Calculate space necessary for matrix memory allocation
        for (cit=grid[gid].cell.begin();cit!=grid[gid].cell.end();cit++) {
                nextCellCount=0;
                for (it=(*cit).faces.begin();it!=(*cit).faces.end();it++) {
                        if (grid[gid].face[*it].bc==INTERNAL_FACE) {
                                nextCellCount++;
                        }
                }
                for (int i=0;i<nVars;++i) {
                        diagonal_nonzeros.push_back( (nextCellCount+1)*nVars);
                        off_diagonal_nonzeros.push_back( ((*cit).ghosts.size())*nVars);
                }
        }

        MatCreateMPIAIJ(
                        PETSC_COMM_WORLD,
                        grid[gid].cellCount*nVars,
                        grid[gid].cellCount*nVars,
                        grid[gid].globalCellCount*nVars,
                        grid[gid].globalCellCount*nVars,
                        0,&diagonal_nonzeros[0],
                        0,&off_diagonal_nonzeros[0],
                        &impOP);

        KSPSetOperators(ksp,impOP,impOP,SAME_NONZERO_PATTERN);
                                                                                                                                                                   
        KSPSetTolerances(ksp,rtol,abstol,1.e15,maxits);
        KSPSetType(ksp, KSPBCGS);
        //PCSetType(pc,PCBJACOBI);
        KSPGMRESSetRestart(ksp,30);
        KSPSetFromOptions(ksp);

        return;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20141121/41702894/attachment.html>


More information about the petsc-users mailing list