<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Jed,<div><br></div><div>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 <span style="font-size: 12px;">KSPBCGS. It seems hoverer, the PC </span><span style="font-size: 12px; "> </span><span style="font-size: 12px; "> </span><span style="font-size: 12px; ">//PCSetType(pc,PCBJACOBI) </span><span style="font-size: 12px;">does not work with me. And I am not quite sure why. </span></div><div><span style="font-size: 12px;"><br></span></div><div><span style="font-size: 12px;">By the way, can you please give some suggestions on my code? I am not quite sure if I am doing the things rightly. </span></div><div><span style="font-size: 12px;"><br></span></div><div><span style="font-size: 12px;"><br></span></div><div><span style="font-size: 12px;">Many thanks,</span></div><div><span style="font-size: 12px;">Paul</span></div><div><span style="font-size: 12px; "><br></span></div><div><br></div><div><br><div><br></div><div><div apple-content-edited="true">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div style="margin: 0px; font-size: 12px; ">void petsc_init(void) {</div><div style="margin: 0px; font-size: 12px; min-height: 14px; "><br></div><div style="margin: 0px; font-size: 12px; "> vector<Cell>::iterator cit;</div><div style="margin: 0px; font-size: 12px; "> vector<int>::iterator it;</div><div style="margin: 0px; font-size: 12px; min-height: 14px; "><br></div><div style="margin: 0px; font-size: 12px; "> //Create nonlinear solver context</div><div style="margin: 0px; font-size: 12px; "> KSPCreate(PETSC_COMM_WORLD,&ksp);</div><div style="margin: 0px; font-size: 12px; min-height: 14px; "><br></div><div style="margin: 0px; font-size: 12px; "> VecCreateMPI(PETSC_COMM_WORLD,grid[gid].cellCount*nVars,grid[gid].globalCellCount*nVars,&RHS);</div><div style="margin: 0px; font-size: 12px; "> VecSetFromOptions(RHS);</div><div style="margin: 0px; font-size: 12px; "> VecDuplicate(RHS,&deltaX);</div><div style="margin: 0px; font-size: 12px; min-height: 14px; "><br></div><div style="margin: 0px; font-size: 12px; min-height: 14px; "><br></div><div style="margin: 0px; font-size: 12px; "> VecSet(RHS,0.);</div><div style="margin: 0px; font-size: 12px; "> VecSet(deltaX,0.);</div><div style="margin: 0px; font-size: 12px; min-height: 14px; "><br></div><div style="margin: 0px; font-size: 12px; "> vector<int> diagonal_nonzeros, off_diagonal_nonzeros;</div><div style="margin: 0px; font-size: 12px; "> int nextCellCount;</div><div style="margin: 0px; font-size: 12px; min-height: 14px; "><br></div><div style="margin: 0px; font-size: 12px; "> // Calculate space necessary for matrix memory allocation</div><div style="margin: 0px; font-size: 12px; "> for (cit=grid[gid].cell.begin();cit!=grid[gid].cell.end();cit++) {</div><div style="margin: 0px; font-size: 12px; "> nextCellCount=0;</div><div style="margin: 0px; font-size: 12px; "> for (it=(*cit).faces.begin();it!=(*cit).faces.end();it++) {</div><div style="margin: 0px; font-size: 12px; "> if (grid[gid].face[*it].bc==INTERNAL_FACE) {</div><div style="margin: 0px; font-size: 12px; "> nextCellCount++;</div><div style="margin: 0px; font-size: 12px; "> }</div><div style="margin: 0px; font-size: 12px; "> }</div><div style="margin: 0px; font-size: 12px; "> for (int i=0;i<nVars;++i) {</div><div style="margin: 0px; font-size: 12px; "> diagonal_nonzeros.push_back( (nextCellCount+1)*nVars);</div><div style="margin: 0px; font-size: 12px; "> off_diagonal_nonzeros.push_back( ((*cit).ghosts.size())*nVars);</div><div style="margin: 0px; font-size: 12px; "> }</div><div style="margin: 0px; font-size: 12px; "> }</div><div style="margin: 0px; font-size: 12px; min-height: 14px; "><br></div><div style="margin: 0px; font-size: 12px; "> MatCreateMPIAIJ(</div><div style="margin: 0px; font-size: 12px; "> PETSC_COMM_WORLD,</div><div style="margin: 0px; font-size: 12px; "> grid[gid].cellCount*nVars,</div><div style="margin: 0px; font-size: 12px; "> grid[gid].cellCount*nVars,</div><div style="margin: 0px; font-size: 12px; "> grid[gid].globalCellCount*nVars,</div><div style="margin: 0px; font-size: 12px; "> grid[gid].globalCellCount*nVars,</div><div style="margin: 0px; font-size: 12px; "> 0,&diagonal_nonzeros[0],</div><div style="margin: 0px; font-size: 12px; "> 0,&off_diagonal_nonzeros[0],</div><div style="margin: 0px; font-size: 12px; "> &impOP);</div><div style="margin: 0px; font-size: 12px; min-height: 14px; "><br></div><div style="margin: 0px; font-size: 12px; "> KSPSetOperators(ksp,impOP,impOP,SAME_NONZERO_PATTERN);</div><p style="margin: 0px; font-size: 12px; min-height: 14px; "> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 12px; "> KSPSetTolerances(ksp,rtol,abstol,1.e15,maxits);</div><div style="margin: 0px; font-size: 12px; "> KSPSetType(ksp, KSPBCGS);</div><div style="margin: 0px; font-size: 12px; "> //PCSetType(pc,PCBJACOBI);</div><div style="margin: 0px; font-size: 12px; "> KSPGMRESSetRestart(ksp,30);</div><div style="margin: 0px; font-size: 12px; "> KSPSetFromOptions(ksp);</div><div style="margin: 0px; font-size: 12px; min-height: 14px; "><br></div><div style="margin: 0px; font-size: 12px; "> return;</div><div style="margin: 0px; font-size: 12px; ">}</div></div></div></div></div></div></body></html>