How to form a tensor from scalar functions (for output to VTK file)

Asked by Nasser Mohieddin Abukhdeir

Hello:
    I have a possibly unique problem, we are solving a PDE with a symmetric+traceless 2-rank tensor as the dependent variable. My understanding is that FEniCS implements symmetric tensor operations, but not traceless. Thus we formulation the variational form using the components of the tensor.
    The problem now is that we cannot use standard FEniCS I/O to output the data to a VTK file. While we could output the individual components and work with them in that way, it would be much more simple for us to somehow project the 5 scalar functions to a single tensor function. Here is a summary of what we are doing:

SS = FunctionSpace(mesh, 'CG', degree)
MS = MixedFunctionSpace([SS, SS, SS, SS, SS])

# Define trial and test functions
dQ = TrialFunction(MS)
v = TestFunction(MS)

# Define functions
Q0 = Function(MS) # past/known solution
Q = Function(MS) # current solution

q110,q220,q210,q310,q320 = Q0
q11,q22,q21,q31,q32 = Q
v11,v22,v21,v31,v32 = v

...

file1 << (Q.split()[0],t)
file2 << (Q.split()[1],t)
file3 << (Q.split()[3],t)
# we would like to replace this with a single line file<<(Q,t)

Thanks for any help or suggestions.

Nasser

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Martin Sandve Alnæs (martinal) said :
#1

On 14 June 2012 22:36, Nasser Mohieddin Abukhdeir
<email address hidden> wrote:
> Question #200469 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/200469
>
> Description changed to:
> Hello:
>    I have a possibly unique problem, we are solving a PDE with a symmetric+traceless 2-rank tensor as the dependent variable. My understanding is that FEniCS implements symmetric tensor operations, but not traceless. Thus we formulation the variational form using the components of the tensor.
>    The problem now is that we cannot use standard FEniCS I/O to output the data to a VTK file. While we could output the individual components and work with them in that way, it would be much more simple for us to somehow project the 5 scalar functions to a single tensor function. Here is a summary of what we are doing:
>
> SS = FunctionSpace(mesh, 'CG', degree)
> MS = MixedFunctionSpace([SS, SS, SS, SS, SS])
>
> # Define trial and test functions
> dQ = TrialFunction(MS)
> v  = TestFunction(MS)
>
> # Define functions
> Q0   = Function(MS)  # past/known solution
> Q   = Function(MS)  # current solution
>
> q110,q220,q210,q310,q320 = Q0
> q11,q22,q21,q31,q32 = Q
> v11,v22,v21,v31,v32 = v
>
> ...
>
> file1 << (Q.split()[0],t)
> file2 << (Q.split()[1],t)
> file3 << (Q.split()[3],t)
> # we would like to replace this with a single line file<<(Q,t)
>
>
> Thanks for any help or suggestions.
>
> Nasser

Not sure exactly how your tensor should look like, but try this:

# Build a tensor valued UFL expression from scalar components
Q2 = as_tensor( ( (0, Q[0], Q[1]), (Q[2], 0, Q[3]), (Q[4], Q[5], 0) ) )

# Project tensor valued expression into tensor element space
T = TensorElement(mesh, 'CG', degree)
Q3 = project(Q2, T) # Of course this will cost you a solve

Alternatively, you can copy the subvectors for each component
from the vector of Q into the vector of a Function(T). Subcomponents
are stored in contiguous blocks. This will not work in parallell though.

Martin

Can you help with this problem?

Provide an answer of your own, or ask Nasser Mohieddin Abukhdeir for more information if necessary.

To post a message you must log in.