This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Fenics and Paraview

0 votes

Hello together.

first of all, sorry for this question... perhaps it sounds easy for most of you.
I wrote this little programm to solve a poisson problem:

from dolfin import *

n = 50
mesh = UnitSquareMesh(n, n)
V = FunctionSpace(mesh, "Lagrange", 1)

def boundary(x):
    return x[0] < DOLFIN_EPS or x[1] < DOLFIN_EPS 
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)

r   = Expression("1.", degree=1)

f = Expression("10.", degree=1)

w = TrialFunction(V)
v = TestFunction(V)
a = inner(grad(w), grad(v))*dx
L = f*v*dx + r*v*ds

A = assemble(a)
l = assemble(L)

bc.apply(A)
bc.apply(l)

y = Function(V)
solve(A, y.vector(), l)

file = File('Poisson.pvd')
file << mesh
file << y

Now I want to export the vtu-file on Paraview.
If I open it with Paraview. I receive an 2D heatmap of my solution.
How is it possible to get it into 3D?

Thank you

asked Dec 26, 2016 by MatheMagie FEniCS Novice (250 points)
edited Dec 26, 2016 by MatheMagie

Hi, under Filters look for Warp by Scalar.

Hi MiroK,

thank you! But if I do it like this, it is not the right relation.
x- and y- axis are [0,1] and my z-values are 0.0 to 0.820.
so it should be something like a cuboid in which the data
are plotted. But it is way to flat. Is there a trick to change it.

Sorry, but Paraview is totally new to me.

Regards

and one more question.
I created an .pvd-file in my programm, but in each file I found:

<PointData  Scalars="f_2518"> 
<DataArray  type="Float64"  Name="f_2518"  format="ascii">
</PointData> 

so I need to change the "Scalars" and "Name" to the same,
if I want to plot them over time.
Is there an possibility in the python-code in the programm to
set the same name in each .vtu-file?

To change the name of your function you can do something like this:

y = Function(V, name="my_name")
solve(A, y.vector(), l)
file = File('Poisson.pvd')
file << y

perfect, thanks

I'm using Paraview as well. As a workaround for such simple problems you may compute your Problem in 3D by changing "UnitSquareMesh" to "UnitCubeMesh". The boundary conditions should be still fine in my opinion, otherwise you need to adjust them. Now Paraview has 3D data and you can extract a 2D Slice from the 3D Cube and visualize in 3D.
PS: Of course this is totally inefficient and not a solution for larger problems.

...