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

Plot blank with Ubuntu 14.04 Fenics1.6

0 votes

Hi! I'm new to Ubuntu and Fenics and got problems with the display of my plot. Is there any special Program I have to install to get the plot to show up with command plot()? It's mostly empty or sometimes filled with glibberish. I already tried ParaViewer but that didn't really worked out either. I want to plot u[0] and u[1] for different times.
Or is my code not working at all?

# Create mesh and define function space
nx = 120
xmax = 1
mesh = IntervalMesh(nx, 0, xmax)

V = FunctionSpace(mesh, 'Lagrange', degree=1)
W=V*V


# Define const
D= 0.0005
Dc= 0.45
lamb= 30.0
alpha= 0.1
h= 10.0
k= 0.01
cM= 40.0

# Define boundary condition n=c=1 on the right side for x=1
class BoundaryRight1(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary and \
            (near(x[0], 1.0))

boundaryRight = BoundaryRight()
bsc = DirichletBC(V, 1.0, boundaryRight)

# Initial condition for t=0 x<1
n0=0
c0=0
u0_function= Expression(("n0", "c0"), n0=n0, c0=c0, element = W.ufl_element())

u0= Function(W)
u0.interpolate(u0_function)

#Def functions
def g (n):
 return (n*(1.0+alpha**2.0))/(n**2.0+alpha**2.0)

B =(1.0+cM**2.0-2.0*h*cM)/((1.0-cM)**2.0)

def s (c):
    return ((2.0*cM*(h-B)*c)/(cM**2.0+c**2.0))+B

# Vectors for saving 
uk = Function(W)
uk.vector()[:]=u0.vector()
ut = Function(W)
ut.vector()[:]=ut.vector()

#saving time dependant solutions
f = File("solution/AK.pvd")
# timesteps
dt=0.3
t=0
T=50.0
while t <= T:   
    t = t + dt
    v = TestFunction(W)
    u = Function(W)
    du= TrialFunction(W)    


    F1 = (1.0/dt * (u[0] - ut[0])-s(u[1])*(2-u[0])*u[0]+u[0])*v[0]*dx \
        + D*inner(nabla_grad (u[0]), nabla_grad (v[0]))*dx



    F2 = (1.0/dt * (u[1] - ut[1]) -lamb*g(u[0]) +lamb*u[1])*v[1]*dx \
        +inner(Dc*nabla_grad (u[1]), nabla_grad (v[1]))*dx


    F=F1+F2

    u.vector()[:]=uk.vector()

    J=derivative(F,u,du)

    # Solver
    problem = NonlinearVariationalProblem(F, u, bsc, J)
    solver  = NonlinearVariationalSolver(problem)
    solver.solve()

    f << u

plot(u[0])
interactive()
asked Jan 13, 2016 by gashi FEniCS Novice (130 points)
edited Jan 13, 2016 by chris_richardson

Maybe you have problems with your graphic card drivers? Does glxgears work? It should display a set of rotating gears. You need to install the mesa-utils package to install glxgears.

Thanks for the reply! glxgears is working fine, but I already had some issues with my graphic card. For matlab I have to use " -softwareopengl" to plot, is there anything similar to Fenics? I can't even plot the minimum examples..

FEniCS uses VTK to plot. Can you try some of the examples from the vtk-examples package? For instance, try to run python /usr/share/vtk/Tutorial/Step5/Python/Cone5.py.

I didn't find the exact folder you are describing, but I tried this example,
http://www.vtk.org/Wiki/VTK/Examples/Python/GeometricObjects/Display/Cone

and it failed. I installed VTK with "sudo apt-get install libvtk5-dev python-vtk"

Try installing the vtk-examples package: sudo apt-get install vtk-examples. Then try to run python /usr/share/vtk/Tutorial/Step5/Python/Cone5.py.

How did you install FEniCS?

Okay, the Cone5 example didn't worked either, just got an completely black box. I installed Fenics like described on the homepage with the ppa and "sudo apt-get install fenics"

Ok, then there is clearly something wrong on your side. Have you installed additional drivers? Once you have the VTK examples working, then plotting in FEniCS should also work fine.

I already checked for drivers but didn't find anything suitable. I got a out of the box Ubuntu notebook. Maybe there is a problem with my graphic card?
Thanks for your support!

I am having the exact same problem. Are there any updates?

I am running Linux Mint 17.2 (Ubuntu 14.04.3 LTS) on a Lenovo X1 (gen3) with Intel HD5500 graphics; glxgears is working but vtk-examples (and FEniCS plotting) is not.

1 Answer

0 votes

I am using paraview to view my vtk plots. When loading a .pvd file the name at Coloring is set to 'f_123'(f_random number). I sometimes get following problem, at the next time step the Coloring seems to have another name, for example 'f_146' but paraview selects 'solid color' at coloring and does not show any solution. maybe check if coloring is set correctly at different time steps?

I got this problem when using your example code

putting 'u = Function(W)' out of the while loop fixes this problem

u = Function(W)
while t <= T:
    .....

function stops resetting the name in paraview, maybe this helps anyone

answered Mar 21, 2016 by tobiasj FEniCS Novice (170 points)
...