Dolfin in python: How do i read data from a .pvd file and plot it?

Asked by Jens V Christiansen

Hi,

How do i read data from a .pvd file and plot it?

Say for instance the velocity solution to the stokes-iterative problem:

from dolfin import *

# Load mesh and subdomains
mesh = UnitCube(16, 16, 16)

# Define function spaces
V = VectorFunctionSpace(mesh, "CG", 2)
Q = FunctionSpace(mesh, "CG", 1)
W = V * Q

(u, p) = TrialFunctions(W)

# Load solution in VTK format
File("velocity.pvd") >> u
pfile_pvd = File("pressure.pvd")
pfile_pvd >> p

# Plot solution
plot(u)
plot(p)
interactive()
-----------------------

I get the following error:

Traceback (most recent call last):
  File "plot_solution.py", line 20, in <module>
    File("velocity.pvd") >> u
TypeError: in method 'File___rshift__', argument 2 of type 'dolfin::FunctionPlotData &'

Question information

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

If you just want plotting, open it in Paraview:
http://paraview.org/

Martin

On 10 February 2012 15:20, Jens V Christiansen
<email address hidden> wrote:
> New question #187403 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/187403
>
> Hi,
>
> How do i read data from a .pvd file and plot it?
>
> Say for instance the velocity solution to the stokes-iterative problem:
>
>
> from dolfin import *
>
> # Load mesh and subdomains
> mesh = UnitCube(16, 16, 16)
>
> # Define function spaces
> V = VectorFunctionSpace(mesh, "CG", 2)
> Q = FunctionSpace(mesh, "CG", 1)
> W = V * Q
>
> (u, p) = TrialFunctions(W)
>
> # Load solution in VTK format
> File("velocity.pvd") >> u
> pfile_pvd = File("pressure.pvd")
> pfile_pvd >> p
>
> # Plot solution
> plot(u)
> plot(p)
> interactive()
> -----------------------
>
> I get the following error:
>
> Traceback (most recent call last):
>  File "plot_solution.py", line 20, in <module>
>    File("velocity.pvd") >> u
> TypeError: in method 'File___rshift__', argument 2 of type 'dolfin::FunctionPlotData &'
>
>
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Jack Hale (jack-hale) said :
#2

*.pvd files are paraview data format, so you can import them into
Paraview http://www.paraview.org/

The plotting facilities in Paraview are far advanced of those
available in Dolfin, so I would highly recommend getting to grips with
it (most things are point-and-click).

If you really want to do what you've asked I guess its possible to
save the underlying numpy array with the nodal unknowns of u and p and
reinitialise a fresh Function object in your plotting script with the
numpy array loaded from a file, but I've never tried to do this myself
so I don't know the exact steps.

Jack

On 10 February 2012 14:20, Jens V Christiansen
<email address hidden> wrote:
> New question #187403 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/187403
>
> Hi,
>
> How do i read data from a .pvd file and plot it?
>
> Say for instance the velocity solution to the stokes-iterative problem:
>
>
> from dolfin import *
>
> # Load mesh and subdomains
> mesh = UnitCube(16, 16, 16)
>
> # Define function spaces
> V = VectorFunctionSpace(mesh, "CG", 2)
> Q = FunctionSpace(mesh, "CG", 1)
> W = V * Q
>
> (u, p) = TrialFunctions(W)
>
> # Load solution in VTK format
> File("velocity.pvd") >> u
> pfile_pvd = File("pressure.pvd")
> pfile_pvd >> p
>
> # Plot solution
> plot(u)
> plot(p)
> interactive()
> -----------------------
>
> I get the following error:
>
> Traceback (most recent call last):
>  File "plot_solution.py", line 20, in <module>
>    File("velocity.pvd") >> u
> TypeError: in method 'File___rshift__', argument 2 of type 'dolfin::FunctionPlotData &'
>
>
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Jens V Christiansen (jenschristiansen) said :
#3

Thanks! Paraview is the way to go.