<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks for your help Matt.<br class=""><div><blockquote type="cite" class=""><div class="">On 16. Aug 2017, at 16:17, Matthew Knepley <<a href="mailto:knepley@gmail.com" class="">knepley@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote">On Wed, Aug 16, 2017 at 8:56 AM, Maximilian Hartig<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:imilian.hartig@gmail.com" target="_blank" class="">imilian.hartig@gmail.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">Hello,<br class=""><br class="">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 class="">I tried a TSMonitor with the following code in it:<br class=""><br class="">TSGetDM(ts,&dm);<br class="">DMClone(dm,&dm_aux);<br class="">DMGetDS(dm,&prob_aux);<br class="">DMSetDS(dm_aux,prob_aux);<br class="">DMCreateGlobalVector(dm_aux,&<wbr class="">old_solution);<br class="">VecCopy(u,oldsolution);<br class="">PetscObjectCompose((<wbr class="">PetscObject) dm, “A”, (PetscObject) old_solution);<br class=""><br class="">VecDestroy(&old_solution);<br class="">DMDestroy(&dm_aux);<br class=""><br class="">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 class=""><br class="">Is there a way to access the fields of the solution for the previous timestep during the evaluation of the current residual?<br class=""></blockquote><div class=""><br class=""></div><div class="">First, I can show you how to do what you are asking for. I think you can simply</div><div class=""><br class=""></div><div class="">PetscObjectQuery((PetscObject) dm, "old_solution", (PetscObject *) &old_solution);</div><div class="">if (!old_solution) {</div><div class=""> DMCreateGlobalVector(dm, &old_solution);</div><div class=""> PetscObjectCompose((PetscObject) dm, "old_solution", old_solution);</div><div class="">}</div><div class="">VecCopy(u, oldsolution);</div></div></div></div></div></blockquote><br class=""><div>Unfortunately, this produces an error and tells me “An object cannot be composed with an object that was composed with it."</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">Second, I think a better way to do this than composition is to use</div><div class=""><br class=""></div><div class=""> DMGetNamedGlobalVector(dm, "old_solution", &old_solution);</div></div></div></div></div></blockquote><div><br class=""></div><div>Yes, this seems to work and I do not get an error while running the monitor. Also the discretisation seems to be fine. But the old solution now is not available as an auxiliary field.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">Third, I can say that I am profoundly troubled by this. This interferes with the operation of</div><div class="">the time integrator, and I cannot see a reason for this. If you are keeping track of the integral</div><div class="">of some quantity, I would update that in TSPostStep() and request that integral instead of the</div><div class="">previous solution. We do this for some non-Newtonian rheologies.</div></div></div></div></div></blockquote><div><br class=""></div><div>I have an “if” condition in my residual which I need to evaluate to determine the correct formulation for my residuals. I use actual fields to keep track of the integrals. But when I use the actual field to evaluate the “if” condition, due to the implicit nature of the solver I jump “back and forth” over that condition. I need the “if” condition to be independent from the field for which it determines the residual.</div><div>The actual application is as follows:</div><div> I have, amongst others, a displacement and a stress field.</div><div>I evaluate for my stress given a displacement increment delta u.</div><div>If the resulting stress is > yield stress, I need a plasticity formulation, if it is smaller, I can use elasticity.</div><div><br class=""></div><div>Thanks,</div><div>Max</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class=""> <span class="Apple-converted-space"> </span>Thanks,</div><div class=""><br class=""></div><div class=""> Matt</div><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">Thanks,<br class="">Max</blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>--<span class="Apple-converted-space"> </span><br class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">-- Norbert Wiener</div><div class=""><br class=""></div><div class=""><a href="http://www.caam.rice.edu/~mk51/" target="_blank" class="">http://www.caam.rice.edu/~mk51/</a></div></div></div></div></div></div></blockquote></div><br class=""></body></html>