Saving tensor to file

Asked by Bob Myhill

Is there a way to save a tensor to file? For example, if we have the strain rate tensor sym(grad(u1)), is there a way to output this as a pvd file in one step (such that it is readable by Paraview)? I can output each component separately without problem:

# 2D strain rate tensor
efile_pvd << project(u1[0].dx(0),FunctionSpace(mesh,"CG",2)) # E11
efile_pvd << project(0.5*(u1[1].dx(0)+u1[0].dx(1)),FunctionSpace(mesh,"CG",2)) #E12
efile_pvd << project(u1[1].dx(1),FunctionSpace(mesh,"CG",2)) #E22

# I can also create a strain rate tensor function
d = mesh.geometry().dim()
symmetry = dict(((i,j),(j,i)) for i in range(d) \
                    for j in range(d) if i > j)
Sij = project(sym(grad(u1)),TensorFunctionSpace(mesh,"CG",1,symmetry=symmetry))

# But attempting to output the values of this function yields malloc() errors
efile_pvd << Sij

Thanks,
Bob

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Bob Myhill
Solved:
Last query:
Last reply:
Revision history for this message
Johan Hake (johan-hake) said :
#1

Have you tried projecting the function to a function from a full
TensorFunctionSpace?

Johan

On Wednesday May 18 2011 06:26:02 myhill.bob wrote:
> New question #158032 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/158032
>
> Is there a way to save a tensor to file? For example, if we have the strain
> rate tensor sym(grad(u1)), is there a way to output this as a pvd file in
> one step (such that it is readable by Paraview)? I can output each
> component separately without problem:
>
> # 2D strain rate tensor
> efile_pvd << project(u1[0].dx(0),FunctionSpace(mesh,"CG",2)) # E11
> efile_pvd <<
> project(0.5*(u1[1].dx(0)+u1[0].dx(1)),FunctionSpace(mesh,"CG",2)) #E12
> efile_pvd << project(u1[1].dx(1),FunctionSpace(mesh,"CG",2)) #E22
>
>
> # I can also create a strain rate tensor function
> d = mesh.geometry().dim()
> symmetry = dict(((i,j),(j,i)) for i in range(d) \
> for j in range(d) if i > j)
> Sij =
> project(sym(grad(u1)),TensorFunctionSpace(mesh,"CG",1,symmetry=symmetry))
>
> # But attempting to output the values of this function yields malloc()
> errors efile_pvd << Sij
>
> Thanks,
> Bob

Revision history for this message
Bob Myhill (myhill.bob) said :
#2

Hi Johan,

Yes, I have. The line
>>> efile_pvd << project(sym(grad(u1)),TensorFunctionSpace(mesh,"CG",1))
produces the same malloc() memory corruption errors.

Bob

Revision history for this message
Garth Wells (garth-wells) said :
#3

On 18/05/11 17:30, Bob Myhill wrote:
> Question #158032 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/158032
>
> Status: Answered => Open
>
> Bob Myhill is still having a problem:
> Hi Johan,
>
> Yes, I have. The line
>>>> efile_pvd << project(sym(grad(u1)),TensorFunctionSpace(mesh,"CG",1))
> produces the same malloc() memory corruption errors.
>

Check that the projection works, e.g.

  eps_proj = project(sym(grad(u1)),TensorFunctionSpace(mesh,"CG",1))

and then try to output it

  efile_pvd << eps_proj

When it breaks, register a bug and post the simplest possible complete
code that reproduces the error.

Garth

> Bob
>

Revision history for this message
Bob Myhill (myhill.bob) said :
#4

I found the source of the problem, and a simple (though imperfect) solution. The bug appears when the variable
>>> efile_pvd = File("strain_rate.pvd", "compressed")

Everything works fine when
>>> efile_pvd = File("strain_rate.pvd")

I'll file a bug report.

Thank you both for your help,
Bob