<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Hello Matthew, <br></div><div class="gmail_default" style="font-family:verdana,sans-serif">The same happened for:<br><br>PetscReal loc[] = { 0.0, 2.0, 1.0,<br> 1.0, -2.0, -3.0,<br> -1.0, 1.0, 2.0};<br>PetscReal b_array[] = { -8.0, <br> 0.0,<br> 3.0};<br><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">And this time I checked the matrix to be non-singular(determinant=1). I am again getting (inf, inf, inf) as the solution. <br><br>On running with -ksp_converged_reason the following message comes: <br>Linear solve did not converge due to DIVERGED_PCSETUP_FAILED iterations 0<br>PCSETUP_FAILED due to FACTOR_NUMERIC_ZEROPIVOT<br><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">I am once again appending the whole code for reference.<br><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Thanks.<br>---------<br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br>static char help[] = "KSP try.\n\n";<br><br><br>#include "petsc.h"<br>#include "petscksp.h"<br><br>int main(int argc, char *argv[])<br>{ <br> /// matrix creation variables.<br> PetscInt *idxm = new PetscInt[3];<br> PetscInt *idxn = new PetscInt[3];<br> PetscReal loc[] = { 0.0, 2.0, 1.0,<br> 1.0, -2.0, -3.0,<br> -1.0, 1.0, 2.0};<br> PetscReal b_array[] = { -8.0, <br> 0.0,<br> 3.0};<br> PetscInt i;<br> KSP ksp; <br> <br> /// Declaring the vectors<br> Vec x, b;<br><br> // Declaring matrices<br> Mat A;<br><br> PetscInitialize(&argc,&argv,(char*)0,help);<br> // Creating vectors<br> VecCreateSeq(PETSC_COMM_SELF, 3, &x);<br> VecCreateSeq(PETSC_COMM_SELF, 3, &b);<br> // Creating matrix<br> MatCreateSeqAIJ(PETSC_COMM_SELF, 3, 3, 3, NULL, &A);<br> // Creating the indices<br> for(i=0; i<3; i++) {<br> idxm[i] = i;<br> idxn[i] = i;<br> }<br> // Assembling the vector b and x<br> VecSetValues(b, 3, idxm, b_array, INSERT_VALUES);<br> VecAssemblyBegin(b);<br> VecAssemblyEnd(b);<br> <br> //Assembling the Matrix <br> MatSetValues(A, 3, idxm, 3, idxn, loc, INSERT_VALUES);<br> MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);<br> MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);<br><br> // KSP related operations<br> KSPCreate(PETSC_COMM_SELF, &ksp);<br> KSPSetType(ksp, KSPGMRES);<br> KSPSetOperators(ksp, A, A);<br> KSPSetFromOptions(ksp);<br> KSPSolve(ksp,b,x);<br> KSPDestroy(&ksp);<br><br> VecView(x, PETSC_VIEWER_STDOUT_SELF);<br><br> PetscFinalize();<br> return 0;<br></div><div class="gmail_default" style="font-family:verdana,sans-serif">}//End of file<br></div><div class="gmail_default" style="font-family:verdana,sans-serif">--------<br></div><div class="gmail_default" style="font-family:verdana,sans-serif"> <br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Apr 8, 2017 at 7:01 PM, Matthew Knepley <span dir="ltr"><<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Sat, Apr 8, 2017 at 8:26 AM, Kaushik Kulkarni <span dir="ltr"><<a href="mailto:kaushikggg@gmail.com" target="_blank">kaushikggg@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto">I guess there is a miscalculation:</div><div>2*row1 + row2 = (4, 0, 0)</div></div></blockquote><div><br></div></span><div>You are right here, but I think it is still rank deficient.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto">Thanks,</div><div dir="auto">Kaushik<br><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">On Apr 8, 2017 6:52 PM, "Matthew Knepley" <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<br type="attribution"><blockquote class="m_1653976974455295151m_4105581865856356402quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="m_1653976974455295151m_4105581865856356402quoted-text">On Sat, Apr 8, 2017 at 6:54 AM, Kaushik Kulkarni <span dir="ltr"><<a href="mailto:kaushikggg@gmail.com" target="_blank">kaushikggg@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-family:verdana,sans-serif">Hello,<br></div><div style="font-family:verdana,sans-serif">I just started with PETSc and was trying the KSP Solvers. I was trying for the problem - <br><br>int main(int argc, char *argv[])<br>{ <br> /// matrix creation variables.<br> PetscInt *idxm = new PetscInt[3];<br> PetscInt *idxn = new PetscInt[3];<br></div></div></blockquote><div><br></div></div><div>Note that the problem below is rank deficient (2 * row 1 + row 2 = 0). Its not clear to me whether b is</div><div>in the range space of the operator.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div class="m_1653976974455295151m_4105581865856356402elided-text"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-family:verdana,sans-serif"> PetscReal loc[] = { 1.0, -2.0, -6.0,<br> <wbr> 2.0, 4.0, 12.0,<br> <wbr> 1.0, -4.0,-12.0};<br> PetscReal b_array[] = { 12.0, <br> -17.0,<br> 22.0};<br> PetscInt i;<br> KSP ksp; <br> <br> /// Declaring the vectors<br> Vec x, b;<br><br> // Declaring matrices<br> Mat A;<br><br> PetscInitialize(&argc,&argv,(c<wbr>har*)0,help);<br> // Creating vectors<br> VecCreateSeq(PETSC_COMM_SELF, 3, &x);<br> VecCreateSeq(PETSC_COMM_SELF, 3, &b);<br> // Creating matrix<br> MatCreateSeqAIJ(PETSC_COMM_SEL<wbr>F, 3, 3, 3, NULL, &A);<br> // Creating the indices<br> for(i=0; i<3; i++) {<br> idxm[i] = i;<br> idxn[i] = i;<br> }<br> // Assembling the vector b and x<br> VecSetValues(b, 3, idxm, b_array, INSERT_VALUES);<br> VecAssemblyBegin(b);<br> VecAssemblyEnd(b);<br> <br> //Assembling the Matrix <br> MatSetValues(A, 3, idxm, 3, idxn, loc, INSERT_VALUES);<br> MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);<br> MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);<br><br> // KSP related operations<br> KSPCreate(PETSC_COMM_SELF, &ksp);<br> KSPSetType(ksp, KSPGMRES);<br> KSPSetOperators(ksp, A, A);<br> KSPSetFromOptions(ksp);<br> KSPSolve(ksp,b,x);<br> KSPDestroy(&ksp);<br><br> VecView(x, PETSC_VIEWER_STDOUT_SELF);<br><br> PetscFinalize();<br> return 0;<br>}<br><br></div><div style="font-family:verdana,sans-serif">But the obtained solution is found out to be- (inf, inf, inf).<br><br></div><div style="font-family:verdana,sans-serif">I wanted to know whether I am doing something wrong or is the problem inherently not solvable using GMRES. Currently I am running the code in a sequential manner(no parallelism intended).<br><br></div><div style="font-family:verdana,sans-serif">Thank you. <br clear="all"></div></div>
</blockquote></div></div><font color="#888888"><br><br clear="all"><span class="m_1653976974455295151HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_1653976974455295151m_4105581865856356402m_2936315764055467821gmail_signature" data-smartmail="gmail_signature">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</font></span></font></div></div>
</blockquote></div><br></div></div></div>
</blockquote></div></div></div><div><div class="h5"><br><br clear="all"><div><br></div>-- <br><div class="m_1653976974455295151gmail_signature" data-smartmail="gmail_signature">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</div></div></div></div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><span style="color:rgb(153,153,153)"><font size="1"><span style="font-family:monospace,monospace"><span><div><div dir="ltr"><span><div><div dir="ltr"><span><div><div dir="ltr"><div><div dir="ltr"><span><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><span><div><div dir="ltr"><span><div><div dir="ltr"><span><div><div dir="ltr"><div><div dir="ltr"><span><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><span><div><div dir="ltr"><span><div><div dir="ltr"><span><div><div dir="ltr"><div><div dir="ltr"><span><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font size="1"><span style="font-family:monospace,monospace"><span><div><div dir="ltr"><span><div><div dir="ltr"><span><div><div dir="ltr"><div><div dir="ltr"><span><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font size="1"><span style="font-family:monospace,monospace"><span><div><div dir="ltr"><span><div><div dir="ltr"><span><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr">Kaushik Kulkarni<br>Fourth Year Undergraduate</div><div dir="ltr">Department of Mechanical Engineering<br>Indian Institute of Technology Bombay</div><div dir="ltr">Mumbai, India<br><a href="https://kaushikcfd.github.io/About/" target="_blank">https://kaushikcfd.github.io/About/</a><br></div><div>+91-9967687150</div></div></div></div></div></span></div></div></span></div></div></span></span></font></div></div></div></div></div></div></div></div></div></div></span></div></div></div></div></span></div></div></span></div></div></span></span></font></div></div></div></div></div></div></div></div></span></div></div></div></div></span></div></div></span></div></div></span></div></div></div></div></div></div></span></div></div></div></div></span></div></div></span></div></div></span></div></div></div></div></div></div></div></div></span></div></div></div></div></span></div></div></span></div></div></span></span></font></span></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div>