<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
On Dec 18, 2020, at 6:35 PM, Salazar De Troya, Miguel <<a href="mailto:salazardetro1@llnl.gov" class="">salazardetro1@llnl.gov</a>> wrote:<br class="">
<div>
<blockquote type="cite" class=""><br class="Apple-interchange-newline">
<div class="">
<div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Verdana; font-size: 14px; 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; text-decoration: none;">
<div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Ok, I was not able to get such case to work in my firedrake-ts implementation. Maybe I am missing something in my code. I looked at the TSAdjoint paper<span class="Apple-converted-space"> </span><a href="https://arxiv.org/pdf/1912.07696.pdf" style="color: blue; text-decoration: underline;" class="">https://arxiv.org/pdf/1912.07696.pdf</a><span class="Apple-converted-space"> </span>Equation
 2.1 and at the adjoint method for the theta method (Equation 2.15) where the mass matrix is not differentiated w.r.t. the design parameter “p” and decided to ask the question.</div>
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>For notational brevity, the formula used in the paper does not assume that the mass matrix depends on the parameters p. But it can be easily extended for this case.</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Verdana; font-size: 14px; 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; text-decoration: none;">
<div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Is the actual implementation different from what is in the paper?</div>
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>The actual implementation is more general than the formula presented in the paper. Note that PETSc TS takes the ODE problem as F(U_t,U,P,t) = G(U,P,t) and does not ask for a mass matrix explicitly from users. When users provide IFunction, which is F(Udot,U,P,t),
 IJacobian (dF/dU) and IJacobianP (dF/dP) are needed by TSAdjoint to compute the sensitivities. Differentiating the mass matrix (more precisely, the term M*U_t ) is needed when you prepare the call back function IJacobianP. So if we have M(P)*U_t - f(t,U,P)
 in IFunction, IJacobianP should be M_P*U_t - f_P where U_t is provided by PETSc as an input argument.</div>
<div><br class="">
</div>
<div>Thanks,</div>
<div>Hong</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Verdana; font-size: 14px; 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; text-decoration: none;">
<div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<o:p class=""></o:p></div>
<div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<o:p class=""> </o:p></div>
<div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Thanks<o:p class=""></o:p></div>
<div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Miguel<o:p class=""></o:p></div>
<div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<o:p class=""> </o:p></div>
<div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(181, 196, 223); padding: 3pt 0in 0in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<b class=""><span style="font-size: 12pt;" class="">From:<span class="Apple-converted-space"> </span></span></b><span style="font-size: 12pt;" class="">"Zhang, Hong" <<a href="mailto:hongzhang@anl.gov" class="">hongzhang@anl.gov</a>><br class="">
<b class="">Date:<span class="Apple-converted-space"> </span></b>Friday, December 18, 2020 at 3:11 PM<br class="">
<b class="">To:<span class="Apple-converted-space"> </span></b>"Salazar De Troya, Miguel" <<a href="mailto:salazardetro1@llnl.gov" class="">salazardetro1@llnl.gov</a>><br class="">
<b class="">Cc:<span class="Apple-converted-space"> </span></b>Satish Balay via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" class="">petsc-users@mcs.anl.gov</a>><br class="">
<b class="">Subject:<span class="Apple-converted-space"> </span></b>Re: [petsc-users] Support for full jacobianP in TSSetIJacobianP<o:p class=""></o:p></span></div>
</div>
<div class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<o:p class=""> </o:p></div>
</div>
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
The current interface is general and should be applicable to this case as soon as users can provide IJacobianP, which is dF(Udot,U,P,t)/dP. Were you able to generate it in firedrake? If so, could you provide an example that I can test?<span class="Apple-converted-space"> </span><o:p class=""></o:p></div>
<div class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<o:p class=""> </o:p></div>
</div>
<div class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Thanks,<o:p class=""></o:p></div>
</div>
<div class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Hong<o:p class=""></o:p></div>
<div class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<br class="">
<br class="">
<o:p class=""></o:p></div>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class="" type="cite">
<div class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
On Dec 18, 2020, at 10:58 AM, Salazar De Troya, Miguel <<a href="mailto:salazardetro1@llnl.gov" style="color: blue; text-decoration: underline;" class="">salazardetro1@llnl.gov</a>> wrote:<o:p class=""></o:p></div>
</div>
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<o:p class=""> </o:p></div>
<div class="">
<div class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Yes, that is the case I am considering. The special case I am concerned about is as following: the heat equation in variational form and in firedrake/UFL notation is as follows: p*u_t*v*dx + inner(grad(u), grad(v))*dx = 0, where u is the temperature, u_t is
 its time derivative, v is just the test function, dx is the integration domain and p is the design parameter. If “p” were discontinuous, one can’t just factor “p” into the second term due to the divergence theorem. Meaning that p*u_t*v*dx + inner(grad(u),
 grad(v))*dx = 0 is different than u_t*v*dx + inner(1.0 / p * grad(u), grad(v))*dx = 0, which is what ideally one would obtain in order to adapt to the current interface in TSAdjoint.<o:p class=""></o:p></div>
</div>
<div class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
 <o:p class=""></o:p></div>
</div>
<div class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Thanks<o:p class=""></o:p></div>
</div>
<div class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Miguel<o:p class=""></o:p></div>
</div>
<div class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
 <o:p class=""></o:p></div>
</div>
<div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(181, 196, 223); padding: 3pt 0in 0in;" class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<b class=""><span style="font-size: 12pt;" class="">From:<span class="apple-converted-space"> </span></span></b><span style="font-size: 12pt;" class="">"Zhang, Hong" <<a href="mailto:hongzhang@anl.gov" style="color: blue; text-decoration: underline;" class="">hongzhang@anl.gov</a>><br class="">
<b class="">Date:<span class="apple-converted-space"> </span></b>Thursday, December 17, 2020 at 7:25 PM<br class="">
<b class="">To:<span class="apple-converted-space"> </span></b>"Salazar De Troya, Miguel" <<a href="mailto:salazardetro1@llnl.gov" style="color: blue; text-decoration: underline;" class="">salazardetro1@llnl.gov</a>><br class="">
<b class="">Cc:<span class="apple-converted-space"> </span></b>Satish Balay via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" style="color: blue; text-decoration: underline;" class="">petsc-users@mcs.anl.gov</a>><br class="">
<b class="">Subject:<span class="apple-converted-space"> </span></b>Re: [petsc-users] Support for full jacobianP in TSSetIJacobianP</span><o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
 <o:p class=""></o:p></div>
</div>
</div>
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Hi Miguel,<span class="apple-converted-space"> </span><o:p class=""></o:p></div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
 <o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Thank you for the nice work. I do not understand what you propose to do here. What is the obstacle to using current TSSetIJacobianP() for the corner case you mentioned? Are you considering a case in which the mass matrix is parameterized, e.g. M(p) udot - f(t,u)
 = g(t,u) ?<o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
 <o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Thanks,<o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Hong<span class="apple-converted-space"> </span><o:p class=""></o:p></div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<br class="">
<br class="">
<br class="">
<o:p class=""></o:p></div>
</div>
<blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class="" type="cite">
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
On Dec 17, 2020, at 3:38 PM, Salazar De Troya, Miguel via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" style="color: blue; text-decoration: underline;" class="">petsc-users@mcs.anl.gov</a>> wrote:<o:p class=""></o:p></div>
</div>
</div>
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
 <o:p class=""></o:p></div>
</div>
<div class="">
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="ES" class="">Hello,</span><o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="ES" class=""> </span><o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
I am working on hooking up TSAdjoint with pyadjoint through the firedrake-ts interface (<a href="https://github.com/IvanYashchuk/firedrake-ts" style="color: blue; text-decoration: underline;" class=""><span style="color: rgb(5, 99, 193);" class="">https://github.com/IvanYashchuk/firedrake-ts</span></a>).
 I have done most of the implementation and now I am just testing for corner cases. One of them is when the design variable is multiplying the first derivative term. It would be the case ofF(Udot,U,P,t) = G(U,P,t) in<span class="apple-converted-space"> </span><a href="https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/Sensitivity/TSSetIJacobianP.html" style="color: blue; text-decoration: underline;" class=""><span style="color: rgb(5, 99, 193);" class="">https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/Sensitivity/TSSetIJacobianP.html</span></a><span class="apple-converted-space"> </span>.
 I imagine that one could think of refactoring the “P” in the left hand side to the right hand side, but this is not trivial when “P” is a discontinuous field over the domain. I think it would be better to include the case of F(Udot,U,P,t) = G(U,P,t) in TSSetIJacobianP
 and I am volunteering to do it. Given the current implementation of TSAdjoint, is this something feasible?<o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
 <o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Thanks<o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Miguel<o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
 <o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="ES" style="font-size: 9pt; font-family: Consolas;" class="">Miguel A. Salazar de Troya</span><o:p class=""></o:p></div>
</div>
</div>
<div class="">
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span style="font-size: 9pt; font-family: Consolas;" class="">Postdoctoral Researcher, Lawrence Livermore National Laboratory</span><o:p class=""></o:p></div>
</div>
</div>
</div>
<div class="">
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span style="font-size: 9pt; font-family: Consolas;" class="">B141</span><o:p class=""></o:p></div>
</div>
</div>
</div>
<div class="">
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span style="font-size: 9pt; font-family: Consolas;" class="">Rm: 1085-5</span><o:p class=""></o:p></div>
</div>
</div>
</div>
<div class="">
<div class="">
<div style="margin-left: 0.5in;" class="">
<div style="margin: 0in 0in 0in 0.5in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span style="font-size: 9pt; font-family: Consolas;" class="">Ph: 1(925) 422-6411</span></div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</body>
</html>