Subject: [Ufl] grad() w.r. to a coefficient

From: Patrick Riesen <[email-masked]>
Date: Tue, 6 Jul 2010 14:25:27 +0200

hello,

i want to take the gradient of a coefficient with respect to some other 
quantity than the spatial coordinates (i.e. some other coefficient).

i tried to construct a custom operator derived from diff() and the 
SpatialCoordinate/Derivative classes in ufl but after some point beyond 
my knowledge it always gets evaluated to zero by FFC then stops 
compiling with FFC : division by zero!

does somebody of you experts know an approach to this?

many thanks and best regards,
patrick

---

From: "Garth N. Wells" <[email-masked]>
Date: Tue, 06 Jul 2010 13:29:59 +0100

> does somebody of you experts know an approach to this?

Did you try using 'variable'?

     . . .
     v  = variable(v)
     f  = v*v
     df = diff(f, v)	

Garth

> _______________________________________________
> Mailing list: https://launchpad.net/~ufl
> Post to : [email-masked]
> Unsubscribe : https://launchpad.net/~ufl
> More help : https://help.launchpad.net/ListHelp

---

From: Patrick Riesen <[email-masked]>
Date: Tue, 6 Jul 2010 15:07:05 +0200

> Did you try using 'variable'?
yes, but if f is a coefficient and not an expression of v, this won't 
work, i.e.,

f = Coefficient(element)
f = variable(f)
v = SpatialCoordinates(cell)
v = variable(v)
df = diff(f, v)

will end up as Type Zero, although this is equivalent to grad(f). that's 
the one case, and it v = Coefficient(element) as well, it will also be zero.
if would be nice if where not zero :-)

patrick

---

From: Kristian Oelgaard <[email-masked]>
Date: Tue, 6 Jul 2010 14:25:19 +0100

On 6 July 2010 14:07, Patrick Riesen <[email-masked]> wrote:
> yes, but if f is a coefficient and not an expression of v, this won't work,
> i.e.,
>
> f = Coefficient(element)
> f = variable(f)
> will end up as Type Zero, although this is equivalent to grad(f). that's the
> one case, and it v = Coefficient(element) as well, it will also be zero.

The first example I get although I don't know why it does not work at
the moment, but it could be a bug. The second case where v is a
coefficient I don't get.
If f(x) = x**2, then df/dy = 0, I think that makes sense. Perhaps what
you want (or is trying to do) is described in this blueprint?

https://blueprints.launchpad.net/ufl/+spec/function-derivatoves

Kristian

---

From: Patrick Riesen <[email-masked]>
Date: Tue, 6 Jul 2010 15:52:48 +0200

Kristian Oelgaard wrote:
>>> � �. . .
>>> � �v �= variable(v)
>>> � �f �= v*v
>>> � �df = diff(f, v)
> If f(x) = x**2, then df/dy = 0, I think that makes sense. 

yes, but if f is a coefficient, i.e., it is a eulerian quantity f=f(x), 
and df/dx is the spatial gradient, ufl computes this from either 
grad(f) or f.dx(i) or Dx(f,i).

but the vector of spatial coordinates x is
hidden in ufl. i would like to do something like f.dx(v[i]), i.e. 
compute df_i/dv_j where v represents some other coordinates, possibly 
given by another coefficient?

Perhaps what
>> Post to � � : [email-masked]
>> More help � : https://help.launchpad.net/ListHelp
>>

---

From: Kristian Oelgaard <[email-masked]>
Date: Tue, 6 Jul 2010 15:05:31 +0100

On 6 July 2010 14:52, Patrick Riesen <[email-masked]> wrote:
>>> work,
>>> the
> yes, but if f is a coefficient, i.e., it is a eulerian quantity f=f(x), and
> df/dx is the spatial gradient, ufl computes this from either grad(f) or
> f.dx(i) or Dx(f,i).
>
> hidden in ufl. i would like to do something like f.dx(v[i]), i.e. compute
> df_i/dv_j where v represents some other coordinates, possibly given by
> another coefficient?

My bad for choosing 'x' in my example. The point I was trying to make
is simply that if UFL does not know that a given expression depend on
a variable, then taking derivatives w.r.t. this variable will always
turn out zero:

f(v) = 5*v --> d_f/d_foo = 0.

Did you take a look at the blueprint I linked to?

Kristian

---

From: Patrick Riesen <[email-masked]>
Date: Tue, 6 Jul 2010 16:32:00 +0200

> Did you take a look at the blueprint I linked to?

yes, if it got it correctly  i would define

dfdX = Function(element)
f = Function(element, gradient=dfdX)

and dfdX must come from another form, where i have other spatial 
coordinates (say X, ).

i don't know how x (the spatial coordinates) are represented in ufl, but 
  if they are somehow indexed and acessible, one could define a new 
Grad(f, X[i]) / f.dx(X[i]) , where the partial derivative of f is 
computed with respect to component X[i] instead of spatial variable 
component i as in f.dx(i).

patrick

---

From: Kristian Oelgaard <[email-masked]>
Date: Tue, 6 Jul 2010 16:02:05 +0100

On 6 July 2010 15:32, Patrick Riesen <[email-masked]> wrote:
>>> and
> and dfdX must come from another form, where i have other spatial coordinates
> (say X, ).

Yes, something like that. Note that it is a blueprint and AFAIK nobody
is about to implement it in the near future.

Kristian

> i don't know how x (the spatial coordinates) are represented in ufl, but  if
> they are somehow indexed and acessible, one could define a new Grad(f, X[i])
> / f.dx(X[i]) , where the partial derivative of f is computed with respect to
> component X[i] instead of spatial variable component i as in f.dx(i).
>
> patrick
>
>>
>> Kristian
>>
>>> Perhaps what
>>>>