Subject: [Ufl] diagonal of a tensor

From: Johan Hake <[email-masked]>
Date: Wed, 2 Nov 2011 16:12:50 -0700

Hello!

Is there an easy way to extract the diagonal of a square tensor in ufl? I know 
I can do:

  diag = as_vector([A[0][0], A[1][1]])

but it would make sense to have something like:

  diag(A), A.diag()

Johan

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Thu, 3 Nov 2011 07:38:47 +0100

There is no such operator, but it would make sense yes.

Just define it yourself for now with def diag(A), should be trivial to add
to ufl.

Martin
Den 3. nov. 2011 00.13 skrev "Johan Hake" <[email-masked]> følgende:

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

---

From: Martin Sandve Alnæs <[email-masked]>
Date: Thu, 3 Nov 2011 21:54:25 +0100

So I couldn't resist and implemented it :)

To be on the safe side because of the beta I only added
functions diag and diag_vector which use other ufl operators,
so this does not introduce any new types to UFL and does
not pose any risk for existing code.

See docstrings and tests for usage.

Martin

---

From: Johan Hake <[email-masked]>
Date: Thu, 3 Nov 2011 14:02:19 -0700

> So I couldn't resist and implemented it :)

Nice!

I knew you would not resist that one ;)

Johan

> > Just define it yourself for now with def diag(A), should be trivial to
> > add to ufl.
> > 
> > Martin
> >