On Wed, Sep 26, 2012 at 7:43 PM, Jinquan Zhong <span dir="ltr"><<a href="mailto:jzhong@scsolutions.com" target="_blank">jzhong@scsolutions.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Jed,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">So I need to assembled x before calling
</span><span style="font-size:10.0pt;font-family:"Courier New"">KSPSetInitialGuessNonzero().
</span><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">KSPSolve will take the assembled x as its initial guess. Correct? </span></p></div></div></blockquote><div><br></div>
<div>Yes</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> That is<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line129">129: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSetFromOptions.html#KSPSetFromOptions" target="_blank">KSPSetFromOptions</a>(ksp);<u></u><u></u></pre>
<pre style="margin-left:.5in"><u></u> <u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line131">131: </a> <span style="color:royalblue">if</span> (nonzeroguess) {<u></u><u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line132">132: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar" target="_blank">PetscScalar</a> p = .5;<u></u><u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line133">133: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecSet.html#VecSet" target="_blank">VecSet</a>(x,p);<u></u><u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line134">134: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSetInitialGuessNonzero.html#KSPSetInitialGuessNonzero" target="_blank">KSPSetInitialGuessNonzero</a>(ksp,<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PETSC_TRUE.html#PETSC_TRUE" target="_blank">PETSC_TRUE</a>);<u></u><u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line135">135: </a> }<u></u><u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line136">136: </a><u></u><u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line137">137: </a> <span style="color:firebrick">/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - </span><u></u><u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line138">138: </a><span style="color:firebrick"> Solve the linear system</span><u></u><u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line139">139: </a><span style="color:firebrick"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */</span><u></u><u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line140">140: </a> <span style="color:firebrick">/* </span><u></u><u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line141">141: </a><span style="color:firebrick"> Solve linear system</span><u></u><u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line142">142: </a><span style="color:firebrick"> */</span><u></u><u></u></pre>
<pre style="margin-left:.5in"><a name="13a052d84609f742_line143">143: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSolve.html#KSPSolve" target="_blank">KSPSolve</a>(ksp,b,x);<u></u><u></u></pre>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I don’t think the manual specifies this. I only read<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal" style="margin-left:.5in">“Tells the iterative solver that the initial guess is nonzero; otherwise
<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSP.html#KSP" target="_blank">
KSP</a> assumes the initial guess is to be zero (and thus zeros it out before solving).”<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Thanks,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Jinquan<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"></span></p><div class="im">From: <a href="mailto:petsc-users-bounces@mcs.anl.gov" target="_blank">petsc-users-bounces@mcs.anl.gov</a> [mailto:<a href="mailto:petsc-users-bounces@mcs.anl.gov" target="_blank">petsc-users-bounces@mcs.anl.gov</a>] On Behalf Of Jed Brown<br>
</div>
Sent: Wednesday, September 26, 2012 5:37 PM<br>
To: PETSc users<span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> list<div class="im"><br>
<b>Subject:</b> Re: [petsc-users] Setting initial guess for KSP solver<u></u><u></u></div></span><p></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">On Wed, Sep 26, 2012 at 7:33 PM, Jinquan Zhong <<a href="mailto:jzhong@scsolutions.com" target="_blank">jzhong@scsolutions.com</a>> wrote:<u></u><u></u></p><div><div class="h5">
<div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New""> PetscErrorCode KSPSetInitialGuessNonzero(KSP ksp,PetscBool flg)</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">does not provide the option to input x0 though.</span><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">It causes the vector X that you pass to KSPSolve to be used as the initial guess. Did you read the man page?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSetInitialGuessNonzero.html" target="_blank">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSetInitialGuessNonzero.html</a><u></u><u></u></p>
</div>
</div></div></div>
</div>
</blockquote></div><br>