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

How to use Fenics with Python

+1 vote

I have some trouble getting started with Fenics and Python:

  1. I run Fenics with Docker and run one of the demos with "python ~/demo/documented/bcs/python/demo_bcs.py . Everything seems to work, BUT I do not get any visualisation. The plot(...) command at the end of the demo does not seem to have any effect. That holds for all demos I tested.

  2. I'd like to use my Python IDE (PyCharm) for development. So first of all, I'll have to mount the directory into the Fenics VM, I think I know how to do that. But is there also a way to access the Python installation inside Fenics?

  3. When I do an installation from source, will I then get a "native" installation without the Docker VM that uses (for example) the native Python on my system? (And will the build be as painful as for example with Trilinos? ;-) )

The questions might seem a bit stupid, but in the beginning it's often difficult until one has some idea about the system. So a few hints would be VERY helpful and save a lot of time :-)

asked Oct 12, 2016 by mibieri FEniCS Novice (130 points)

1 Answer

0 votes

Some comments:

  1. Visualization (graphics) don't work within the docker container, you need to export your results to a shared folder and use tools like Paraview or VisIt for post processing. Or you can try to use a Jupyter notebook. Also, apparently X11 can be enabled on linux systems: click

  2. I don't know PyCharm, but I assume you'd need to install it inside the docker container, so they use the same python version and PyCharm can access the modules. Which leaves you without a GUI (if PyCharm has one and IF the X11 trick above doesn't work. You can install anything you want inside the container from the ubuntu repositories with apt-get). I tried this for vim (or jedi-vim) and the modules of a FEniCS hashdist build, but couldn't..

  3. You can try to install fenics into your system python (maybe using the hashdist build), but expect compiling from source to be painful(!!). Maybe you could use virtualenvs, if PyCharm supports this. It's nice to have fenics in an isolated environment, the trouble of manual compilation and the inconveniences of a fenics "system installation" just for your IDE is imho not justified.

answered Oct 15, 2016 by dajuno FEniCS User (4,140 points)

Thanks for that answer.

What I do not completely understand: Does Fenics use a modified version of the Python interpreter or can I use it like any other Python binding?

Or, more generally asking, is there a document that exactly describes how a Fenics environment looks internally? There's a good tutorial and there are several installation instructions, but I still do not understand what the concept behind an installation is.

It consists basically of the Dolfin core package (solvers in C++ & python interface; list of dependencies here) and several pure python packages (FFC, UFL, FIAT, Instant).
Python 2.7 is a requirement and not provided by fenics. When you compile from source you can install the python packages into your system's lib/python/site-packages, or inside a virtual environment, for example.
In the docker build, the system (ubuntu) python is used. With hashdist, python is installed separately.
You can have a look at the hashdist build (has a good documentation on the downloads page), too, to get a better idea of what's needed.

There is a technical description of FEniCS and its dependencies here: dx.doi.org/10.11588/ans.2015.100.20553
And of course in the FEniCS book.

...