← Back to team overview

ufl team mailing list archive

Re: [HG UFL] Added support for this syntax:

 

On Wed, Apr 8, 2009 at 1:36 AM, Garth N. Wells <gnw20@xxxxxxxxx> wrote:
>
>
> UFL wrote:
>> One or more new changesets pushed to the primary ufl repository.
>> A short summary of the last three changesets is included below.
>>
>> changeset:   811:b96d2bbe8284a7255ca510c2fbb35b1445f85a11
>> tag:         tip
>> user:        "Martin Sandve Alnæs <martinal@xxxxxxxxx>"
>> date:        Tue Apr 07 14:50:30 2009 +0200
>> files:       doc/manual/chapters/formlanguage.tex ufl/operators.py
>> description:
>> Added support for this syntax:
>>
>> x = cell.x
>> Df = diff(f, x)
>>
>> Note that
>>   diff(f, x) == grad(f).T
>
> This definition of grad is counter-intuitive to me and likely to lead to
> errors on the part of the users. Why has it been defined this way?

This definition of grad(f) or this definition of diff(f, x)?

FFC and UFL defines grad(f) differently, but my
commit note meant that I'd rather change diff
since diff(f, x) becomes inconsistent with grad(f).
I simply forgot to consider diff(a,b) with both
a and b tensors when I initially defined diff...


--- Short summary of arguments:

The UFL definition of grad is
  grad(u)[ij] = du_j / dx_i

The FFC definition of grad is
  grad(u)[ij] = du_i / dx_j

The UFL definition:
A) follows directly from the use of \nabla\cdot u, \nabla\otimes u,
\nabla\cross u to mean div u, grad u, curl u.
B) is consistent with the common convection term "v . grad u", written
dot(v, grad(u))
C) is consistent with the common anisotropic diffusion term "M grad
u", written M*grad(u)


--- Argument A:

The definition of grad, div and curl in UFL is consistent with the notation

  div u = \nabla \cdot u
  grad u = \nabla \otimes u = \nabla u
  curl u = \nabla \times u

where nabla is the vector of [d/dx, d/dy]
and the dot, outer and cross products are
defined exactly as between other quantities:

  v \cdot u
  v \otimes u
  v \times u

(Nobody disagrees about the curl or cross product,
it's just here to show the consistency of this notation.
The same goes for the definition of the divergence
of a tensor of rank 2 or more, since it follows from
the definition of the gradient if we require the identity
laplace u = div grad u.)


--- Argument B:

How would you write a convection term? I would argue that

  u . grad v

is the most common way.

The definition of grad(u) in UFL is such that the convection term

  u . grad v

is written

  dot(u, grad(v))

Using the FFC definition of grad, the convection term would be

  dot(grad(v), u)
  grad(v)*u

which corresponds to a less common notation

  grad(v) u

for the convection term. (Note that using dot is required if v is a scalar).

(I've heard the question "how do I write the convection term"
several times from new users of FFC.)


In conclusion the FFC definition of grad(u) is not compatible with the
common expression "u . grad(u)".


--- Argument C:

How would you write an anisotropic diffusion term? I would argue that

  div(M grad u)

is the most common way. (M is a rank 2 conductivity tensor.)

The definition of grad(u) in UFL is such that the anisotropic gradient term

  A  =  M grad u

where u is a vector or scalar, is written

  A  =  M*grad(u)

which is consistent with

  B  =  grad(u)
  A  =  M*B

and means

  A_ij  =  sum_k M_ik B_kj  =  sum_k M_ik  du_j/dx_k

from which it follows that we must have

  grad(u)[k,j]  =  B_kj  =  du_j/dx_k

for the notation "A  =  M grad u" to work out.


To write this anisotropic gradient using the FFC definition,
it would have to be written something like this:

  A = grad(u) M^T
  A = M grad(u)^T

(the transpose of M could of course be defined away).
Or how would you write it?


Using the FFC definition of grad(u), trying to write the term

  A = M grad(u)

would turn into:

  B = grad(u)
  B_ij = du_i/dx_j # FFC definition

  A = M * B
  A_ij = sum_k M_ik B_kj # standard matrix-matrix product

  A_ij = sum_k M_ik du_k/dx_j # not the intended answer!


In conclusion, the FFC definition of grad(u) is not compatible with
the common expression "M grad(u)".


--- Argument D:

I convinced Anders about this more than a year ago :-)


These two ways to define grad is a collision of historical traditions
in big branches of science. No matter what is chosen someone will
disagree, because they've been trained to see one as the right choice.

>From what I've understood:
The UFL definition of grad is common in the traditions of fluid mechanics.
The FFC definition of grad is common in the traditions of solid mechanics.
However, I have class notes from a summer school in Graz where
Ogden and Holzapfel used different definitions for solid mechanics.
And I've seen fluid mechanics papers writing grad(u) v instead of v . grad u.

However, I'm not convinced that this is just a definition.
I argue from consistency of notation and common ways to write
common PDE terms that the UFL way is the way we should use.

Martin


References