<div dir="ltr"><div dir="ltr">On Mon, Nov 14, 2022 at 7:50 PM Mohammad Ali Yaqteen <<a href="mailto:mhyaqteen@sju.ac.kr">mhyaqteen@sju.ac.kr</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg5347572724438380223">
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
I am using Eigen library to which I have to write these vector values from PETSc Vec. tdof is the length of the vector that I need and ei is the number of value in as an index:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
PetscInt ei[tdof];<br>
PetscScalar eveci[tdof];<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
for (int i = 0; i < tdof; i++)<br>
ei[i] = i;</div></div></div></blockquote><div><br></div><div>If you are running in serial, just use VecGetArrayRead().</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg5347572724438380223"><div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
if (nconv>0)
<div> {</div>
<div> eval.setZero(nconv);</div>
<div> evec.setZero(KS.rows(),nconv);</div>
<div> PetscCall(PetscPrintf(PETSC_COMM_WORLD,</div>
<div> " k ||Ax-kx||/||kx||\n"</div>
<div> " ----------------- ------------------\n"));</div>
<div><br>
</div>
<div> for (int i = 0; i < nconv; i++)</div>
<div> {</div>
<div> PetscCall(EPSGetEigenpair(eps,i,&kr,&ki,xr,xi));</div>
<div> PetscCall(EPSComputeError(eps,i,EPS_ERROR_RELATIVE,&error1));</div>
<div><br>
</div>
<div> #if defined(PETSC_USE_COMPLEX)</div>
<div> re = PetscRealPart(kr);</div>
<div> im = PetscImaginaryPart(kr);</div>
<div> #else</div>
<div> re = kr;</div>
<div> im = ki;</div>
<div> #endif</div>
<div> if (im!=0.0) PetscCall(PetscPrintf(PETSC_COMM_WORLD," %9f%+9fi %12g\n",(double)re,(double)im,(double)error1));</div>
<div> else PetscCall(PetscPrintf(PETSC_COMM_WORLD," %12f %12g\n",(double)re,(double)error1));</div>
<div> eval(i) = re;</div>
<div> VecGetValues(xr, tdof, ei, eveci);</div>
<div> for (int j = 0; j < tdof; j++)</div>
<div> {</div>
<div> evec(j, i) = eveci[j];</div>
<div> }</div>
<div> }</div>
<div> PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n"));</div>
}<br>
</div>
<div id="m_5347572724438380223signature_bookmark"></div>
<div id="m_5347572724438380223appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Thank you </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Ali</div>
<hr style="display:inline-block;width:98%">
<div id="m_5347572724438380223divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>><br>
<b>Sent:</b> Tuesday, November 15, 2022 9:43 AM<br>
<b>To:</b> Mohammad Ali Yaqteen <<a href="mailto:mhyaqteen@sju.ac.kr" target="_blank">mhyaqteen@sju.ac.kr</a>><br>
<b>Cc:</b> <a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a> <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Subject:</b> Re: [petsc-users] Reading Vectors from a PETSc Vec</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">On Mon, Nov 14, 2022 at 7:39 PM Mohammad Ali Yaqteen <<a href="mailto:mhyaqteen@sju.ac.kr" target="_blank">mhyaqteen@sju.ac.kr</a>> wrote:<br>
</div>
<div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
I am using the following procedure to read from Vec, but it keeps giving me the same values! I was told that using VecGetValues gives wrog output.
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>By who? It does not give the wrong output.</div>
<div><br>
</div>
<div>You do not show where in the code you define tdof and ei[].</div>
<div><br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
If not this, then what function should be used to read the contents of a vector?</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>I think it would be simpler for you to use VecGetArrayRead(), unless you want values from other processes.</div>
<div><br>
</div>
<div> Thanks,</div>
<div><br>
</div>
<div> Matt</div>
<div> </div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
for (int i = 0; i < nconv; i++)
<div> {</div>
<div> PetscCall(EPSGetEigenpair(eps,i,&kr,&ki,xr,xi));</div>
<div> PetscCall(EPSComputeError(eps,i,EPS_ERROR_RELATIVE,&error1));</div>
<div><br>
</div>
<div> #if defined(PETSC_USE_COMPLEX)</div>
<div> re = PetscRealPart(kr);</div>
<div> im = PetscImaginaryPart(kr);</div>
<div> #else</div>
<div> re = kr;</div>
<div> im = ki;</div>
<div> #endif</div>
<div> if (im!=0.0) PetscCall(PetscPrintf(PETSC_COMM_WORLD," %9f%+9fi %12g\n",(double)re,(double)im,(double)error1));</div>
<div> else PetscCall(PetscPrintf(PETSC_COMM_WORLD," %12f %12g\n",(double)re,(double)error1));</div>
<div> eval(i) = re;</div>
<div> VecGetValues(xr, tdof, ei, eveci);</div>
<div> for (int j = 0; j < tdof; j++)</div>
<div> {</div>
<div> evec(j, i) = eveci[j];</div>
<div> }</div>
<div> }</div>
PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\n"));<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Thank you</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Ali</div>
</div>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>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><br>
</div>
<div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>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><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>