Subject: [UFL-dev] abs

From: "Garth N. Wells" <[email-masked]>
Date: Wed, 31 Dec 2008 19:46:03 +0000

Since FFC is about to move to UFL, I guess this is the best place to ask 
  certain questions now ;).

Will UFL support the absolute value of sums, e.g.

   vector = VectorElement("Lagrange", "tetrahedron", 1)
   scalar = Element("Lagrange", "tetrahedron", 1)
   v = TestFunction(scalar)
   u = Function(vector)
   n = Function(vector)

   L =  v*abs(inner(u, n))*ds

This would be useful for upwinding fluxes.

Garth

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Thu, 1 Jan 2009 16:43:24 +0100

UFL supports absolute values of any scalar expression.

Martin

On Wed, Dec 31, 2008 at 8:46 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: Thu, 01 Jan 2009 16:01:47 +0000

> UFL supports absolute values of any scalar expression.

Very good. It's not currently supported by FFC.

Garth

---

From: Anders Logg <[email-masked]>
Date: Thu, 1 Jan 2009 17:54:28 +0100

> UFL supports absolute values of any scalar expression.

What about vectors/tensors?

Perhaps we could add a mechanism for applying scalar-to-scalar
operators to all elements of a tensor (like .* etc in MATLAB).

Maybe something like this:

  _.abs(expression)

We can have a module named _ that contains special versions of all
operators.

-- 
Anders

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Thu, 1 Jan 2009 19:21:28 +0100

> We can have a module named _ that contains special versions of all

With current features, this can be expressed like:

as_tensor(abs(expression[i,j]), (i,j))

But in the case of abs, abs(expression) should be fine.

Martin

---

From: Anders Logg <[email-masked]>
Date: Thu, 1 Jan 2009 19:25:03 +0100

> as_tensor(abs(expression[i,j]), (i,j))

Nice. That should be enough.

-- 
Anders

---

From: Marie Rognes <[email-masked]>
Date: Fri, 02 Jan 2009 16:00:13 +0100

> Very good. It's not currently supported by FFC.

It is, it is just called 'modulus'.  Overriding the python builtin 
caused some issues a while back...

-- 
Marie E. Rognes
Ph.D Fellow, 
Centre of Mathematics for Applications, 
University of Oslo
http://folk.uio.no/meg

---

From: "Garth N. Wells" <[email-masked]>
Date: 02 Jan 2009 15:14:07 +0000

On Jan 2 2009, Marie Rognes wrote:

>It is, it is just called 'modulus'.  

Not for sums, unfortunatly.

Garth

Overriding the python builtin

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Fri, 2 Jan 2009 16:22:49 +0100

> caused some issues a while back...

The right way to override abs(foo) in Python is to implement
__abs__(self) in FooType. Don't know if that helps.

Martin

---

From: Marie Rognes <[email-masked]>
Date: Fri, 02 Jan 2009 16:25:43 +0100

> Not for sums, unfortunatly.

Ah, now I see. (The ffc "test-for-a-sum" is a bit dodgy though.)