Subject: [UFL-dev] Automatic differentiation

From: "Garth N. Wells" <[email-masked]>
Date: Sat, 06 Jun 2009 21:34:25 +0100

I've used the UFL automatic differentiation for a primal problem, and it 
worked great. Now I'd like to try it for the Cahn-Hilliard demo which is 
a mixed method. I'd like to do:

    a1 = derivative(L1, k1, dk) + derivative(L1, c1, dc)

but I get the below error. Is there are trick for mixed elements?

Garth

Traceback (most recent call last):
   File "/usr/local/bin/ffc", line 186, in <module>
     sys.exit(main(sys.argv[1:]))
   File "/usr/local/bin/ffc", line 130, in main
     execfile(script, {})
   File "CahnHilliard2D.py", line 68, in <module>
     a1 = derivative(L1, k1, dk) + derivative(L1, c1, dc)
   File "/usr/local/lib/python2.6/dist-packages/ufl/formoperators.py", 
line 142, in derivative
     functions, basis_functions = _handle_derivative_arguments(function, 
basis_function)
   File "/usr/local/lib/python2.6/dist-packages/ufl/formoperators.py", 
line 128, in _handle_derivative_arguments
     functions       = Tuple(*functions)
UnboundLocalError: local variable 'functions' referenced before assignment

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Sun, 7 Jun 2009 22:58:15 +0200

I'll take a look at improving the error message and checking,
but try this (if I understand what you're trying to do correctly):

kc = Function(mixed_element)
k1, c1 = split(kc)
dkc = TrialFunction(mixed_element)
dk, dc = split(dkc)

...
a1 = derivative(L1, kc, dkc)

Martin

On Sat, Jun 6, 2009 at 10:34 PM, Garth N. Wells<[email-masked]> wrote:
> _______________________________________________
> UFL-dev mailing list
> [email-masked]
> http://fenics.org/mailman/listinfo/ufl-dev
>

---

From: "Garth N. Wells" <[email-masked]>
Date: Mon, 08 Jun 2009 15:13:53 +0100

> a1 = derivative(L1, kc, dkc)

Thanks. I managed to figure it out and it's now used in the  DOLFIN 
Cahn-Hilliard demo.

Garth

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Tue, 9 Jun 2009 10:46:45 +0200

> Thanks. I managed to figure it out and it's now used in the  DOLFIN

Great. It doesn't seem to be checked in though.

Martin

---

From: "Garth N. Wells" <[email-masked]>
Date: Tue, 09 Jun 2009 09:52:06 +0100

> Great. It doesn't seem to be checked in though.

Oops. I've just pushed it.

Garth