Subject: [UFL-dev] [HG UFL] Added support for this syntax:

From: [email-masked] (UFL)
Date: Tue, 7 Apr 2009 14:48:44 +0200 (CEST)

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 <[email-masked]>"
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
because of the way diff is defined.
Thus diff(f,x) is the same as the FFC grad.
If we want to change this, it touches a lot
of places in AD code, so that won't happen now.

changeset:   810:26c85777f73b6aefbbfc941917afeee3d9bb1bae
parent:      809:dda5f025bbd7c50f3c4fb011a09de9f0b086a385
parent:      808:cbcd4657e7762c62dfb92305b85f8a3fbf6331eb
user:        "Martin Sandve Alnæs <[email-masked]>"
date:        Tue Apr 07 14:40:52 2009 +0200
files:       
description:
merge

changeset:   809:dda5f025bbd7c50f3c4fb011a09de9f0b086a385
parent:      805:6238f8a25e47e1b55dbbf5f52cda4fe22c35c097
user:        "Martin Sandve Alnæs <[email-masked]>"
date:        Tue Apr 07 14:40:43 2009 +0200
files:       doc/manual/chapters/formlanguage.tex doc/manual/ufl-user-manual.tex
description:
Work on manual.

----------------------------------------------------------------------
For more details, visit http://www.fenics.org/hg/ufl

---

From: Anders Logg <[email-masked]>
Date: Tue, 7 Apr 2009 17:17:33 +0200

> of places in AD code, so that won't happen now.

How should the Navier-Stokes convective term be expressed in UFL?

I guess one needs to write

  grad(u).T*u

?

-- 
Anders

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Tue, 7 Apr 2009 17:19:42 +0200

> I guess one needs to write

Like you write it on paper:

w . grad u = dot(w, grad(u))

And:

w . grad u . v = dot(dot(w, grad(u)), v)

Martin

---

From: Anders Logg <[email-masked]>
Date: Tue, 7 Apr 2009 18:40:53 +0200

> w . grad u . v = dot(dot(w, grad(u)), v)

Yes, but does 

  grad(u).T*u

also work?

-- 
Anders

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Tue, 7 Apr 2009 18:42:28 +0200

Yes.

grad(u).T*u
=
dot(grad(u).T, u)
=
dot(u, grad(u))

Martin

On Tue, Apr 7, 2009 at 6:40 PM, Anders Logg <[email-masked]> wrote:
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAknbghQACgkQTuwUCDsYZdFqkQCZAVkYKk1Hejw+hw28NYsWwSgk
> JWMAmwXQsB9KNXiyV+lMwjdPnDOJKjPK
> =o2NS
> -----END PGP SIGNATURE-----
>
>

---

From: Anders Logg <[email-masked]>
Date: Tue, 7 Apr 2009 18:46:07 +0200

ok.

Is this documented in the manual? It made me confused the first time I
saw it. Otherwise it's a good example to add.

-- 
Anders

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Tue, 7 Apr 2009 19:01:02 +0200

It is documented now, I wrote about it today. Not everything is
documented though. That's a major point of the next release.

Martin

On Tue, Apr 7, 2009 at 6:46 PM, Anders Logg <[email-masked]> wrote:
> iEYEARECAAYFAknbg08ACgkQTuwUCDsYZdExcACdF8SJey+K3tbiJiB1Q61uEG2n
> 1nAAmwYK17m+8GgWJg9HuTjKP1Bp03Yl
> =BuoJ

---

From: "Garth N. Wells" <[email-masked]>
Date: Wed, 08 Apr 2009 07:36:07 +0800

UFL wrote:
> user:        "Martin Sandve AlnÃ¦s <[email-masked]>"

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?

Garth

> user:        "Martin Sandve AlnÃ¦s <[email-masked]>"
> user:        "Martin Sandve AlnÃ¦s <[email-masked]>"
> ------------------------------------------------------------------------
> 
> _______________________________________________
> UFL-dev mailing list
> [email-masked]
> http://fenics.org/mailman/listinfo/ufl-dev

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Wed, 8 Apr 2009 11:09:48 +0200

> 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