<div dir="ltr"><div><div>Dear all,<br>I'm trying to reuse an operator for the linear system multiple times with different RHS. <br>But it seems that the RHS is not changed in the KSP object. Here is the code to illustrate what I'm doing:<br>
<br>Vec mX[3], mB[3]; //Solving Ax=b for 3 different RHS.<br>...<br>ierr = KSPSetComputeOperators(mKsp,computeMatrix,this);CHKERRQ(ierr);<br>ierr = KSPSetDM(mKsp,mDa);CHKERRQ(ierr);<br>ierr = KSPSetFromOptions(mKsp);CHKERRQ(ierr);<br>
<br>for(int i = 0; i<3; ++i) {<br> mBComponent = i; //sets different component for RHS.<br> ierr = KSPSetComputeRHS(mKsp,computeRhs,this);CHKERRQ(ierr);<br> ierr = KSPSetDM(mKsp,mDa);CHKERRQ(ierr);<br>
ierr = KSPSolve(mKsp,NULL,NULL);CHKERRQ(ierr);<br> ierr = KSPGetSolution(mKsp,&mX[i]);CHKERRQ(ierr);<br> ierr = KSPGetRhs(mKsp,&mB[i]);CHKERRQ(ierr);<br> }<br> <br></div><div>What I expect is to have three different solutions in mX array for the different Rhs computed by computeRhs function. However, the result when I see using VecView is that the Rhs mB[0], mB[1] and mB[2] are all identical (which should not have been the case). And mX also has three identical vectors as solution.<br>
</div>What am I doing wrong here ?<br><br></div><div></div><div><br></div><div>Thanks,<br>Bishesh<br></div><br></div>