<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Mar 12, 2016 at 8:34 PM, Emil Constantinescu <span dir="ltr"><<a href="mailto:emconsta@mcs.anl.gov" target="_blank">emconsta@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">I also find it useful to go through one of the simple examples available for TS: <a href="http://www.mcs.anl.gov/petsc/petsc-current/src/ts/examples/tutorials/index.html" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/petsc-current/src/ts/examples/tutorials/index.html</a> (ex8 may be a good start).<br>
<br>
As Barry suggested, you need to implement IFunction and IJacobian. The argument "u" is S_o, S_w, and p stacked together and "u_t" their corresponding time derivatives. The rest is calculus, but following an example usually helps a lot in the beginning.<br></blockquote><div><br></div><div>Are you guys saying that IFunction and IJacobian are enough to do the adjoint system as well?</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">
Out of curiosity, what is the application?<span class="HOEnZb"><font color="#888888"><br>
<br>
Emil</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
On 3/12/16 3:19 PM, Barry Smith wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
This is only a starting point, Jed and Emil can fix my mistakes and provide additional details.<br>
<br>
<br>
In your case you will not provide a TSSetRHSFunction and TSSetRHSJacobian since everything should be treated implicitly as a DAE.<br>
<br>
First move everything in the three equations to the left side and then differentiate through the \partial/\partial t so that it only applies to the S_o, S_w, and p. For example for the first equation using the product rule twice you get something like<br>
<br>
\phi( p ) \rho_o( p ) \partial S_o/ \partial t + phi( p ) S_o \partial \rho_o( p ) \partial t + \rho_o( p ) S_o \partial \phi( p ) \partial t - F_o = 0<br>
<br>
\phi( p ) \rho_o( p ) \partial S_o/ \partial t + phi( p ) S_o \rho_o'(p) \partial p \partial t + \rho_o( p ) S_o \phi'( p ) \partial p \partial t - F_o = 0<br>
<br>
The two vector arguments to your IFunction are exactly the S_o, S_w, and p and \partial S_o/ \partial t , \partial S_w/ \partial t, and \partial p/ \partial t so it is immediate to code up your IFunction once you have the analytic form above<br>
<br>
For the IJacobian and the "shift business" just remember that dF/dU means take the derivative of the IFunction with respect to S_o, S_w, and p treating the \partial S_o/ \partial t , \partial S_w/ \partial t, and \partial p/ \partial t as if they were independent of S_o, S_w, and p. For the dF/dU_t that means taking the derivate with respect to the \partial S_o/ \partial t , \partial S_w/ \partial t, and \partial p/ \partial t treating the S_o, S_w, and p as independent of \partial S_o/ \partial t , \partial S_w/ \partial t, and \partial p/ \partial t. Then you just need to form the sum of the two parts with the a "shift" scaling dF/dU + a*dF/dU_t<br>
<br>
For the third equation everything is easy. dF/dS_o = 1 dF/dS_w = 1 dF/dp = 0 dF/d (\partial S_o)/\partial t = 0 (\partial S_w)/\partial t = 0 (\partial p)/\partial t = 0<br>
<br>
Computations for the first two equations are messy but straightforward. For example for the first equation dF/dS_o = phi( p ) \rho_o'(p) \partial p \partial t + \rho_o( p ) \phi'( p ) \partial p + dF_o/dS_o and dF/d (\partial S_o)/\partial t) = \phi( p ) \rho_o( p )<br>
<br>
<br>
Barry<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Mar 12, 2016, at 12:04 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<br>
<br>
On Sat, Mar 12, 2016 at 5:41 AM, Max la Cour Christensen <<a href="mailto:mlcch@dtu.dk" target="_blank">mlcch@dtu.dk</a>> wrote:<br>
<br>
Hi guys,<br>
<br>
We are making preparations to implement adjoint based optimisation in our in-house oil and gas reservoir simulator. Currently our code uses PETSc's DMPlex, Vec, Mat, KSP and PC. We are still not using SNES and TS, but instead we have our own backward Euler and Newton-Raphson implementation. Due to the upcoming implementation of adjoints, we are considering changing the code and begin using TS and SNES.<br>
<br>
After examining the PETSc manual and examples, we are still not completely clear on how to apply TS to our system of PDEs. In a simplified formulation, it can be written as:<br>
<br>
\partial( \phi( p ) \rho_o( p ) S_o )/ \partial t = F_o(p,S)<br>
\partial( \phi( p ) \rho_w( p ) S_w )/ \partial t = F_w(p,S)<br>
S_o + S_w = 1,<br>
<br>
where p is the pressure,<br>
\phi( p ) is a porosity function depending on pressure,<br>
\rho_x( p ) is a density function depending on pressure,<br>
S_o is the saturation of oil,<br>
S_g is the saturation of gas,<br>
t is time,<br>
F_x(p,S) is a function containing fluxes and source terms. The primary variables are p, S_o and S_w.<br>
<br>
We are using a lowest order Finite Volume discretisation.<br>
<br>
Now for implementing this in TS (with the prospect of later using TSAdjoint), we are not sure if we need all of the functions: TSSetIFunction, TSSetRHSFunction, TSSetIJacobian and TSSetRHSJacobian and what parts of the equations go where. Especially we are unsure of how to use the concept of a shifted jacobian (TSSetIJacobian).<br>
<br>
Any advice you could provide will be highly appreciated.<br>
<br>
Barry and Emil,<br>
<br>
I am also interested in this, since I don't know how to do it.<br>
<br>
Thanks,<br>
<br>
Matt<br>
<br>
Many thanks,<br>
Max la Cour Christensen<br>
PhD student, Technical University of Denmark<br>
<br>
<br>
<br>
--<br>
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<br>
</blockquote>
<br>
</blockquote>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="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>