<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Feb 12, 2017 at 3:21 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Feb 12, 2017, at 11:30 AM, Gideon Simpson <<a href="mailto:gideon.simpson@gmail.com">gideon.simpson@gmail.com</a>> wrote:<br>
><br>
> I’ve begun working on implementing a projected time stepping method for solving y’ = f(y), where g(y(t)) is an invariant of the flow.  Per a previous email exchange, it was suggested that I use TSSetPostStep to perform the projection routine, calling TSGetSolution obtain the current iterate, which will be corrected with the projection.  However, I noticed two things:<br>
><br>
> 1.  The documentation for TSGetSolution says "This vector not changed until the solution at the next timestep has been calculated.”  Does that mean that if I make a change to the solution in a PostStep function, it won’t be captured until the next step?<br>
<br>
</span>   No.<br>
<span class=""><br>
>  What happens at the final time step?<br>
<br>
</span>   Your function should still get called.<br>
<span class=""><br>
><br>
> 2.  The projection is nonlinear, requiring the use of a SNES.  I had originally thought that I would create/configure/destroy the SNES within the main routine of the code, and pass this to the PostStep through a user data structure.  However, the TSSetPostStep function seems to only take functions which are exclusively functions of the TS.  Likewise, I would need to create a residual vector, r, for the SNESSetFunction.  Is there a way to pass these data structures, so that they can be reused. or would they have to be created/destroyed within the PostStep function at each iterate?  How costly would that be?<br>
<br>
</span>   After you create the SNES and the TS call PetscObjectCompose() to attach the SNES to the TS then inside your post-step you can use PetscObjectQuery() or if you want to pass in more than a SNES use PetscContainerCreate().<br></blockquote><div><br></div><div>An alternative to what Barry suggests, which will definitely work, is to use the DM.</div><div><br></div><div>  DMCreateShell(comm, &dm);</div><div>  DMSetApplicationContext(dm, ctx);</div><div>  TSSetDM(ts, dm);</div><div><br></div><div>In your function</div><div><br></div><div>  TSGetDM(ts, &dm);</div><div>  DMGetApplicationContext(dm, &ctx);</div><div><br></div><div>I prefer this to the Container route.</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">
><br>
><br>
> -gideon<br>
><br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">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></div>