<div dir="ltr"><div>Thank you Matthew for your answer.</div><div><br></div><div>I cannot provide an exact listing of the error as the computation is ran on a closed network but in substance it goes like this :</div><div><br></div><div>Argument out of range</div><div>Field number 0 must be in [0, 0)</div><div>.</div><div>.</div><div>.</div><div>#1 DMGetField() line 4657 in dm.c</div><div>#2 DMPlexVTKWriteAll_VTU() line 273 in plexvtu.c</div><div>#3 DMPlexVTKWriteAll() . . .</div><div>. <br></div><div>.</div><div>.</div><div><br></div><div>The HEAD of my repo is at commit # g2115eb0.</div><div>I checked the sources in PETSc and the case where a DM has no field seems to be handled so I do not understand here what it does not like ..?</div><div><br></div><div>Thanks !!!<br></div><div><br></div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><div><div><div><div>Thibault<br></div></div></div></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mar. 21 juil. 2020 à 12:53, Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Tue, Jul 21, 2020 at 6:12 AM Thibault Bridel-Bertomeu <<a href="mailto:thibault.bridelbertomeu@gmail.com" target="_blank">thibault.bridelbertomeu@gmail.com</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 dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Dear all, </div><div dir="ltr"><br></div><div>This request stems from the "How to add a source term for PETSCFV ?" thread.</div><div>Basically, I would like to output in a VTK file all the components of the gradient computed using the following piece of code (given sol is a global representation of the solution over the whole mesh described by the manager dm with a unique field fvm).</div><div><br></div><div><pre lang="c"><font face="arial, sans-serif"><span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1509" lang="c"><span> ierr</span> <span>=</span> <span>PetscFVSetComputeGradients</span><span>(</span><span>fvm</span><span>,</span><span>PETSC_TRUE</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1511" lang="c"> <span>ierr</span> <span>=</span> <span>DMConvert</span><span>(</span><span>dm</span><span>,</span> <span>DMPLEX</span><span>,</span> <span>&</span><span>plex</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1512" lang="c"> <span>ierr</span> <span>=</span> <span>DMPlexGetDataFVM</span><span>(</span><span>plex</span><span>,</span> <span>fvm</span><span>,</span> <span>&</span><span>cellGeom</span><span>,</span> <span>&</span><span>faceGeom</span><span>,</span> <span>&</span><span>gradDM</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1513" lang="c"> <span>ierr</span> <span>=</span> <span>DMCreateLocalVector</span><span>(</span><span>plex</span><span>,</span><span>&</span><span>locX</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1514" lang="c"> <span>ierr</span> <span>=</span> <span>DMPlexInsertBoundaryValues</span><span>(</span><span>plex</span><span>,</span> <span>PETSC_TRUE</span><span>,</span> <span>locX</span><span>,</span> <span>0</span><span>.</span><span>0</span><span>,</span> <span>faceGeom</span><span>,</span> <span>cellGeom</span><span>,</span> <span>NULL</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1515" lang="c"> <span>ierr</span> <span>=</span> <span>DMGlobalToLocalBegin</span><span>(</span><span>plex</span><span>,</span> <span>sol</span><span>,</span> <span>INSERT_VALUES</span><span>,</span> <span>locX</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1516" lang="c"> <span>ierr</span> <span>=</span> <span>DMGlobalToLocalEnd</span> <span>(</span><span>plex</span><span>,</span> <span>sol</span><span>,</span> <span>INSERT_VALUES</span><span>,</span> <span>locX</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1517" lang="c"> <span>ierr</span> <span>=</span> <span>DMCreateGlobalVector</span><span>(</span><span>gradDM</span><span>,</span> <span>&</span><span>grad</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1518" lang="c"> <span>ierr</span> <span>=</span> <span>DMPlexReconstructGradientsFVM</span><span>(</span><span>plex</span><span>,</span> <span>locX</span><span>,</span> <span>grad</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1519" lang="c"> <span>ierr</span> <span>=</span> <span>DMCreateLocalVector</span><span>(</span><span>gradDM</span><span>,</span> <span>&</span><span>locGrad</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1520" lang="c"> <span>ierr</span> <span>=</span> <span>DMGlobalToLocalBegin</span><span>(</span><span>gradDM</span><span>,</span> <span>grad</span><span>,</span> <span>INSERT_VALUES</span><span>,</span> <span>locGrad</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1521" lang="c"> <span>ierr</span> <span>=</span> <span>DMGlobalToLocalEnd</span><span>(</span><span>gradDM</span><span>,</span> <span>grad</span><span>,</span> <span>INSERT_VALUES</span><span>,</span> <span>locGrad</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1522" lang="c"> <span>ierr</span> <span>=</span> <span>VecDestroy</span><span>(</span><span>&</span><span>grad</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span></font></pre><pre lang="c"><font face="arial, sans-serif"><span> ierr</span> <span>=</span> <span>PetscViewerCreate</span><span>(</span><span>PetscObjectComm</span><span>((</span><span>PetscObject</span><span>)gradDM</span><span>),</span> &<span>viewer</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></font></pre><pre lang="c"><pre lang="c"><font face="arial, sans-serif"> <span>ierr</span> <span>=</span> <span>PetscSNPrintf</span><span>(</span><span>filename</span><span>,</span><span>sizeof</span> <span>filename</span><span>,</span><span>"%s-%03D-gradient.vtu"</span><span>,</span><span>user</span><span>-></span><span>outputBasename</span><span>,</span><span>stepnum</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span><span lang="c"><br></span></font></pre><pre lang="c"><font face="arial, sans-serif"><span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1345" lang="c"> <span>ierr</span> <span>=</span> <span>PetscViewerSetType</span><span>(</span><span>viewer</span><span>,</span> <span>PETSCVIEWERVTK</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span>
<span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1346" lang="c"> <span>ierr</span> <span>=</span> <span>PetscViewerFileSetName</span><span>(</span><span>viewer</span><span>,</span> <span>filename</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span></font></pre></pre></div><div><pre lang="c"><font face="arial, sans-serif"><span id="gmail-m_3366231834695069199gmail-m_5266460865620839017gmail-m_3741842111645541700gmail-LC1464" lang="c"> <span>ierr</span> <span>=</span> <span>VecView</span><span>(locGrad</span><span>,</span><span>viewer</span><span>);</span><span>CHKERRQ</span><span>(</span><span>ierr</span><span>);</span></span></font>
</pre></div><div dir="ltr"><br></div><div>I am having troubles with a few things I think but I cannot figure out how to put it together in the right order ... </div><div>(i) I am not sure whether VecView should be called with a local or a global vector</div></div></div></div></div></div></div></blockquote><div><br></div><div>Does not matter, so you can just use the global vector.</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 dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>(ii) I can see from the error log that gradDM does not have fields and thus when it goes through dmplexvtu.c it crashes and cannot write the file. I tried to add the fvm as a field, but it does not work either, it crashes on a memory corruption.</div></div></div></div></div></div></div></blockquote><div><br></div><div>Can you show the error? The above looks correct to me.</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 dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Could somebody please advise ?<br></div><div dir="ltr"><br></div><div>Thank you very much in advance,</div><div dir="ltr"><br clear="all"><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><div><div><div><div>Thibault Bridel-Bertomeu<br>—<br></div></div></div></div>Eng, MSc, PhD</div><div>Research Engineer</div><div>CEA/CESTA</div><div>33114 LE BARP</div><div>Tel.: (+33)557046924</div><div>Mob.: (+33)611025322<br></div><div>Mail: <a href="mailto:thibault.bridelbertomeu@gmail.com" target="_blank">thibault.bridelbertomeu@gmail.com</a><br></div></div></div></div></div></div></div><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 dir="ltr"><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 dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br><br></div></div></div></div></div>
</blockquote></div></div>
</blockquote></div></div></div></div></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>
</blockquote></div>