Subject: [FEniCS-users] [Fwd: Re: tensor function]

From: Patrick Riesen <[email-masked]>
Date: Wed, 30 Sep 2009 10:58:25 +0200

sorry, something went wrong, this would be the message:

-------- Original Message --------
Subject: Re: [FEniCS-users] tensor function
Date: Wed, 30 Sep 2009 10:52:02 +0200
From: Patrick Riesen <[email-masked]>
To: Anders Logg <[email-masked]>
References: <[email-masked]> 
<20090928122033.GH2528@olorin>	<[email-masked]> 
<20090928140134.GA24982@olorin> <[email-masked]>

or maybe not..

i can not do

Function e11 = e[0][0];

i get

error: no match for 'operator[]' in
'dolfin::Function::operator[](dolfin::uint)(0u)[0]'

but i can get components doing

e11 = e[0];
e12 = e[1];
e21 = e[2];
e22 = e[3];

i suppose for dolfin 0.9.3 it is the case as described below and for
dolfin 0.9.2 the case as above therefore ?
(which is what i am still using currently)

greetings,
patrick

Patrick Riesen wrote:
> this helped to sort things out, thanks again.
> patrick
> 
> Anders Logg wrote:
>> On Mon, Sep 28, 2009 at 02:34:30PM +0200, Patrick Riesen wrote:
>>> Hi,
>>>
>>> thans for the quick response,
>>>
>>> therefore when V is the function space of the (e, v, p) element and
>>>
>>>> e[0] = (a, b)
>>>> e[1] = (c, d)
>>>> e[0][0] = a
>>>> e[0][1] = b
>>>> e[1][0] = c
>>>> e[1][1] = d
>>> therefore doing
>>>
>>> fs = new SubSpace(V,0,0)
>>>
>>> corresponds to the subspace for the two components (a, b) of the
>>> element  and not just for a, which then would be SubSpace(V,0,0,0) ?
>> Yes.
>>
>> --
>> Anders
> 
> _______________________________________________
> FEniCS-users mailing list
> [email-masked]
> http://fenics.org/mailman/listinfo/fenics-users

---

From: Patrick Riesen <[email-masked]>
Date: Wed, 30 Sep 2009 11:12:20 +0200

Hello,

I don't know if this is a problem (dolfin0.9.2):
When i was writing the TensorFunction e to a vtk-file after a solve
by just using

file << e

the results i got were absolutely nonsense. I got three components, but 
none of them made any sense. This is why i was thinking i'm doing 
something completely wrong in my equations/code,

But if i first separate all components and write them to separate files as
     Function e11 = e[0];
     Function e12 = e[1];
     Function e21 = e[2];
     Function e22 = e[3];

     fileE11 << e11;
     fileE12 << e12;
     fileE21 << e21;
     fileE22 << e22;

the solutions look reasonable (uff!..) and e12 and e21 are the same.

regards,
patrick

---

From: "Garth N. Wells" <[email-masked]>
Date: Wed, 30 Sep 2009 10:14:41 +0100

> something completely wrong in my equations/code,

VTK output of tensor functions is untested. I would be very surprised if 
it did work. Dig around in VTKFile.cpp to see if you can find the problem.

Garth

---

From: Patrick Riesen <[email-masked]>
Date: Wed, 30 Sep 2009 11:30:45 +0200

seems that the tensor function for a 2d problem doesn't get to the 
output structure for a tensor function but to that for a vector function 
because it only has rank = 1. the write out for tensor is only invoked 
for a (3x3) tensor with rank = 2.

Garth N. Wells wrote:
>> the results i got were absolutely nonsense. I got three components, 
>> but none of them made any sense. This is why i was thinking i'm doing

---

From: Anders Logg <[email-masked]>
Date: Thu, 1 Oct 2009 12:01:43 +0200

> 'dolfin::Function::operator[](dolfin::uint)(0u)[0]'

This is strange. Is e a Function? Then e[0] should also be a Function
so you should be able to index it since operator[] returns a new
Function.

--
Anders

---

From: Patrick Riesen <[email-masked]>
Date: Thu, 1 Oct 2009 12:10:44 +0200

> so you should be able to index it since operator[] returns a new

I have a Function for a mixed problem with a tensor, vector, scalar field as

Function evp;

extracting the fields as

Function e = evp[0];
Function v = evp[1];
Function p = evp[2];

is fine. then taking components from e=(a, b; c, d) as above as

Function a = e[0][0] did not work and produces the error.

but i can do

Function a = e[0]
Function b = e[1] etc..

and b and c where the same because its a symmetric tensor.

patrick

>> ------------------------------------------------------------------------
>>

---

From: Kristian Oelgaard <[email-masked]>
Date: Thu, 01 Oct 2009 11:42:12 +0200

> and b and c where the same because its a symmetric tensor.

I think this is related to the poor support for tensor elements/functions in FFC
(and DOLFIN and UFC). Try saving the following code in a *.ufl file and play
around with it:

P1 = FiniteElement("Lagrange", triangle, 1)
P0 = TensorElement("Discontinuous Lagrange", triangle, 0, (2, 2))

PM = P1+P0

f = Function(PM)
print "f: ", f

#p = f[0]
#t = f[1] # This will make t[0][0] crash
p, t = split(f)

print "p: ", p
print "t: ", t

t0 = t[0][0]

print "t0: ", t0

as you'll see the components in the tensor function are made up from the
components in f accessed by single indices which are offset by 1 due to the
scalar function. This is the source of your problems I think.

Kristian

---

From: Patrick Riesen <[email-masked]>
Date: Thu, 1 Oct 2009 13:30:05 +0200

> scalar function. This is the source of your problems I think.

yeah, i see that..
but actually i had the tensor element appearing first, so if you just try

PM = P0+P1

then you get no offset....

patrick

---

From: Kristian Oelgaard <[email-masked]>
Date: Thu, 01 Oct 2009 12:40:23 +0200

> then you get no offset....

Sure, but that wasn't really my point. The components in the tensor is still
represented by indexing the function 'f' using a single index.

Kristian

---

From: Patrick Riesen <[email-masked]>
Date: Thu, 1 Oct 2009 14:32:16 +0200

> represented by indexing the function 'f' using a single index.
aha, but so the function f is the mixed element with the 1st subelement 
of a tensor being also a special mixed element and the 2nd subelement a 
scalar element and all stored on the same single index level. so 
accessing components in dolfin c++ using

 >>>>>> t11 = t[0];
 >>>>>> t12 = t[1];
 >>>>>> t21 = t[2];
 >>>>>> t22 = t[3];

is ok, but maybe not as intended because of this issue?

---

From: Kristian Oelgaard <[email-masked]>
Date: Thu, 01 Oct 2009 13:38:19 +0200

> is ok, but maybe not as intended because of this issue?

Exactly, that's how I expect things to work with the current lack of proper
support for tensor functions.
However, the output issue w.r.t. tensor functions *should* be solved now, but
we'll see tonight.

Kristian

---

From: "Riesen Patrick" <[email-masked]>
Date: Thu, 1 Oct 2009 18:20:28 +0200

Hi Kristian

The VTK tensor output in dolfin is still messed up because now the number of components obtained by

  // Get number of components
  uint dim = 1;
  for (uint i = 0; i < rank; i++)
    dim *= element.value_dimension(i);

returns 16 instead of 4. The ffc code for generating value_dimension() might also need a hack..., i'm sorry :-(

patrick

---

From: Kristian Oelgaard <[email-masked]>
Date: Fri, 02 Oct 2009 08:54:25 +0200

> also need a hack..., i'm sorry :-(

I was afraid that something like this would happen. Fixing this will require
quite a bit of work I'm afraid and then we might still run into problems.
I think it will be better to simply implement support for tensor elements, but
that will not happen in a foreseeable future.
Saving the components of the tensor individually is your best option for now.

Kristian

---

From: Patrick Riesen <[email-masked]>
Date: Fri, 2 Oct 2009 10:55:31 +0200

> Saving the components of the tensor individually is your best option for now.

that's ok for me. you can also revert the hack in ffc to keep things 
straight, if that's preferable.
for dolfin, you may want to report it and notify that one needs to 
output each component individually as a workaround ...

best,
patrick