<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Aug 16, 2017 at 8:56 AM, Maximilian Hartig <span dir="ltr"><<a href="mailto:imilian.hartig@gmail.com" target="_blank">imilian.hartig@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I have a problem with several fields that I solve with PetscFE and TS. I now need to access the solution from the previous timestep to compute the residual for the current timestep.<br>
I tried a TSMonitor with the following code in it:<br>
<br>
TSGetDM(ts,&dm);<br>
DMClone(dm,&dm_aux);<br>
DMGetDS(dm,&prob_aux);<br>
DMSetDS(dm_aux,prob_aux);<br>
DMCreateGlobalVector(dm_aux,&<wbr>old_solution);<br>
VecCopy(u,oldsolution);<br>
PetscObjectCompose((<wbr>PetscObject) dm, “A”, (PetscObject) old_solution);<br>
<br>
VecDestroy(&old_solution);<br>
DMDestroy(&dm_aux);<br>
<br>
hoping that it would create an auxiliary field that I could access in the evaluation of the residual. It did that but messed with the discretisation of the initial problem in some way. So I figure that adding auxiliary fields to a dm after having fed it to a TS context is not something you should be doing.<br>
<br>
Is there a way to access the fields of the solution for the previous timestep during the evaluation of the current residual?<br></blockquote><div><br></div><div>First, I can show you how to do what you are asking for. I think you can simply</div><div><br></div><div>PetscObjectQuery((PetscObject) dm, "old_solution", (PetscObject *) &old_solution);</div><div>if (!old_solution) {</div><div>  DMCreateGlobalVector(dm, &old_solution);</div><div>  PetscObjectCompose((PetscObject) dm, "old_solution", old_solution);</div><div>}</div><div>VecCopy(u, oldsolution);</div><div><br></div><div>Second, I think a better way to do this than composition is to use</div><div><br></div><div>  DMGetNamedGlobalVector(dm, "old_solution", &old_solution);</div><div><br></div><div>Third, I can say that I am profoundly troubled by this. This interferes with the operation of</div><div>the time integrator, and I cannot see a reason for this. If you are keeping track of the integral</div><div>of some quantity, I would update that in TSPostStep() and request that integral instead of the</div><div>previous solution. We do this for some non-Newtonian rheologies.</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks,<br>
Max</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><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.caam.rice.edu/~mk51/" target="_blank">http://www.caam.rice.edu/~mk51/</a><br></div></div></div>
</div></div>