[firedrake] Problem with Jacobian
Lawrence Mitchell
lawrence.mitchell at imperial.ac.uk
Thu Nov 5 10:29:40 GMT 2015
> On 5 Nov 2015, at 10:26, Stephan Kramer <s.kramer at imperial.ac.uk> wrote:
>
> On 05/11/15 10:08, Lawrence Mitchell wrote:
>>
>>> On 5 Nov 2015, at 09:49, Buesing, Henrik <HBuesing at eonerc.rwth-aachen.de> wrote:
>>>
>>> Dear all,
>>>
>>> I’m having a variable Sw, which I calculate pointwise in a routine calc_Sw (see attachment). This variable depends on my primary unknown h: Sw = (h-hn)/(hw-hn) (hn,hw known values).
>>>
>>> But now it seems like automatic differentiation for this routine does not work. I’m getting zero entries for the Jacobian, whereas d(Sw)/dh = 1.0 should hold.
>>
>> Yes, this is because the AD doesn't know about the relationship between Sw and dh. UFL has a facility for this, but I notice we don't expose it in firedrake (however, it is straightforward to do):
>>
>>
>> We want
>>
>> derivative(F, u)
>>
>> But F contains a coefficient, S, whose derivative wrt u is 1.0 (however, they are not symbolically related in a way UFL understands). So we build a mapping from this coefficient to its derivative wrt u:
>>
>> coefficient_derivatives = {S: 1.0}
>>
>> and then pass this additional information to the derivative call.
>>
>> derivative(F, u, coefficient_derivatives=coefficient_derivatives)
>>
>> Firedrake uses the UFL derivative function, but does not expose this extra argument in the interface. It is straightforward to alter the definition in firedrake/ufl_expr.py to take this extra argument and pass it through. If this works for you, do you want to propose a patch that adds this functionality?
>>
>> Cheers,
>>
>> Lawrence
>>
>
> Are you sure the problem isn't that he needs bounds for his solve? AFAICS dS/dh=0 for h<hw or h>hn. Otherwise shouldn't rewriting this with conditionals have worked? Henrik, I presume you are looking for a solution hw<h<hn ?
I didn't think hard about this, I simply considered that there's a functional relationship which UFL doesn't know about if you just pass in unrelated coefficients.
Lawrence
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mailman.ic.ac.uk/pipermail/firedrake/attachments/20151105/ea219a29/attachment.sig>
More information about the firedrake
mailing list