3D plot using native FEniCS

I am trying to solve PDEs in 3D in fenics (not fenicsX).
The following code

from dolfin import *
from mshr import *
import dolfin.common.plotting as fenicsplot
import numpy as np
from matplotlib import pyplot as plt

res = 8
mesh = UnitCubeMesh(res,res,res)
plot(mesh)

produces this Error message:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-30-6bb53f29cf03> in <module>
      7 res = 8
      8 mesh = UnitCubeMesh(res,res,res)
----> 9 plot(mesh)

/usr/local/lib/python3.6/dist-packages/dolfin/common/plotting.py in plot(object, *args, **kwargs)
    436     # Plot
    437     if backend == "matplotlib":
--> 438         return _plot_matplotlib(object, mesh, kwargs)
    439     elif backend == "x3dom":
    440         return _plot_x3dom(object, kwargs)

/usr/local/lib/python3.6/dist-packages/dolfin/common/plotting.py in _plot_matplotlib(obj, mesh, kwargs)
    280     else:
    281         ax = plt.gca()
--> 282     ax.set_aspect('equal')
    283 
    284     title = kwargs.pop("title", None)

/usr/local/lib/python3.6/dist-packages/matplotlib/axes/_base.py in set_aspect(self, aspect, adjustable, anchor, share)
   1279         if (not cbook._str_equal(aspect, 'auto')) and self.name == '3d':
   1280             raise NotImplementedError(
-> 1281                 'It is not currently possible to manually set the aspect '
   1282                 'on 3D axes')
   1283 

NotImplementedError: It is not currently possible to manually set the aspect on 3D axes

I know from other posts, that people suggest to use different Python libraries, like vedo or just use Paraview instead.

Is there really no way to create 3D plots with the native FEniCS installation or Matplotlib?
How can this be the case, if FEniCS is the go-to PDE library? Isn’t solving 3D problems kind of a standard use case of such a library?

This has been fixed in the later versions of fenics, see: Error in opening 3D plots in fenics and .pvd files in Paraview 5.8.0 in Ubuntu 19.04 - #2 by dokken

Thank you for your quick response!

Does the fact that I get this error message imply, that my FEniCS Docker image is outdated?
If i remember correctly, I installed this image:
https://quay.io/repository/fenicsproject/stable?tab=tags&tag=latest

…which was suggested here:
https://fenics.readthedocs.io/projects/containers/en/latest/introduction.html

Have you called docker pull quay.Io…:latest to make sure the image is up to date.

1 Like

I ran

docker pull quay.io/fenicsproject/stable:latest

and got

latest: Pulling from fenicsproject/stable
c64513b74145: Already exists
01b8b12bad90: Already exists
...
...
4eb92b6670f4: Already exists
Digest: sha256:ea64e15a739da61be9e440261f86f02930d678ff6eb800768347a87e4975759b
Status: Image is up to date for quay.io/fenicsproject/stable:latest
quay.io/fenicsproject/stable:latest

I stopped and restarted the container and I yielded the same error message as in my first post.
What else could I have done wrong?

Try using dev:latest instead of stable:latest

1 Like

I ran

docker pull quay.io/fenicsproject/dev:latest

and then

docker run --name notebook -w /home/fenics -v $(pwd):/home/fenics/shared -d -p 127.0.0.1:8889:8889 quay.io/fenicsproject/dev 'jupyter-notebook --ip=0.0.0.0'

(as suggested here https://fenics.readthedocs.io/projects/containers/en/latest/jupyter.html). In this last step I tried to use another port (127.0.0.1:8889:8889 ), as the one used for the stable installation (127.0.0.1:8888:8888) - i don’t know whether that was necessary.

When i start a container using FEniCS dev version, i still get the error from the first post.
When i run

import dolfin as df
print (df.__version__)

i get

2019.1.0

Is 2019… the latest version? Do I have to remove the stable installation first?
Also: is it not possible to do 3D plots in the stable version? That would be very surprising to me.

Is there no way to visualize 3D simulations in FEniCS? :frowning:

Or do you recommend exporting the data and using ParaView?

The dev:latest should be 2019.2.0.dev. Please add:
:latest at the end of your initialization of the docker container, i.e. something along the lines of

docker run --name notebook -w /home/fenics -v $(pwd):/home/fenics/shared -ti -p 8888:8888 quay.io/fenicsproject/dev:latest 'jupyter-notebook --ip=0.0.0.0' 

There are also several other modules that supports dolfin functions and meshes, such as vedo: vedo.dolfin API documentation
and pyvista Read FEniCS/Dolfin Meshes — PyVista 0.34.1 documentation

1 Like

Many thanks, it worked!

Summary for everyone who faces the same problem in the future:

  1. Following LINK and the advice from @dokken I pulled the latest dev container:
docker pull quay.io/fenicsproject/dev:latest
  1. Then one runs a docker container from this image using the following command (it is @dokken 's suggestion on changing the instructions from LINK):
docker run --name notebook-dev -w /home/fenics -v $(pwd):/home/fenics/shared -d -p 127.0.0.1:8888:8888 quay.io/fenicsproject/dev:latest 'jupyter-notebook --ip=0.0.0.0'
  1. Then one can look at the list of all pulled containers to get the container ID by doing:
docker ps -a
  1. Run the following command to get the link to the Jupyter Notebooks with the FEniCS environment:
docker logs <dockerID>
1 Like