Skip to content

Setting up Fenics together with FreeCAD

joha2 edited this page Feb 11, 2017 · 6 revisions

Setting up Fenics together with FreeCAD

Anaconda

...

Docker Image

Introduction

Since fenics is shipped in its most recent version through a docker image, it is useful to know how to setup a docker image which is derived from the fenics one and which also provides the ability to compile FreeCAD.

The following description is a quick and dirty setup for the mentioned docker image. If it does not work for you, please let us know.

Fenics docker image and own docker file

First of all according to the fenics docs (modify your docker image), you have to set up your own Dockerfile in a directory of your choice:

 cd /your/path
 touch Dockerfile
 vim Dockerfile

in the following example Dockerfile there are all dependencies from the FreeCAD development documentation listed. Notice that there are other dependencies which could help you to identify malfunctions and debug e.g. graphics functionality in your new image:

FROM quay.io/fenicsproject/stable:latest
USER root
RUN apt-get -qq update && \
    apt-get -y upgrade && \
    apt-get -y install git && \
    apt-get -y install build-essential && \
    apt-get -y install cmake libtool && \
    apt-get -y install python-matplotlib && \
    apt-get -y install python && \
    apt-get -y install libcoin80-dev && \
    apt-get -y install libsoqt4-dev libxerces-c-dev libboost-dev libboost-filesystem-dev libboost-regex-dev libboost-program-options-dev libboost-signals-dev libboost-thread-dev libboost-python-dev libqt4-dev libqt4-opengl-dev qt4-dev-tools python-dev python-pyside pyside-tools && \
    apt-get -y install libeigen3-dev libqtwebkit-dev libshiboken-dev libpyside-dev libode-dev swig libzipios++-dev libfreetype6 libfreetype6-dev && \
    apt-get -y install liboce-foundation-dev liboce-modeling-dev  liboce-ocaf-dev  liboce-visualization-dev liboce-ocaf-lite-dev && \
    apt-get -y install libsimage-dev checkinstall python-pivy python-qt4 doxygen && \
    apt-get -y install libspnav-dev && \
    apt-get -y install python-scipy
RUN apt-get -y install gmsh netgen tetgen calculix-ccx calculix-ccx-doc calculix-ccx-test
RUN apt-get -y install vtk6 libvtk6-dev libmed-dev libmedc-dev x11-apps mesa-utils && \
    apt-get clean && \
    ln -s /usr/bin/vtk6 /usr/bin/vtk && \
    rm -rf /tmp/* /var/tmp/*
USER root

(TODO tidy up Dockerfile). After writing the Dockerfile you have to build a new image from it. Therefore cd into the appropriate directory and perform

 docker build .

(This may take a while.) Congratulations. You just set up your own FreeCAD developement compatible fenics image.

Docker run script

(maybe this could also be achieved by using the fenicsproject script) After this you have to set up a docker run script to start a container from your newly generated image. The following run script works for a Ubuntu 14.04 LTS. Some of the switches are stolen from the fenicsproject script. Please see there for further reference. (TODO: improve for other platforms and tidy up)

#!/bin/bash

HOST_UID=$(id -u)
HOST_GID=$(id -g)
CHANGE_UID_GID="--env HOST_UID=${HOST_UID} --env HOST_GID=${HOST_GID}"

docker run -ti $CHANGE_UID_GID -e DISPLAY=$DISPLAY --env="QT_X11_NO_MITSHM=1" -v /tmp/.X11-unix:/tmp/.X11-unix -w /home/fenics/shared/ -v $(pwd):/home/fenics/shared/ --device=/dev/console --device=/dev/dri/ $1

The first environment variables are due to non-correct owner rights of the shared files by docker. The second variable makes the DISPLAY variable available for the docker container. For using of X11 apps you maybe have to enter xhost + into to your terminal before. (Be careful: there may be security issues.) The third argument is necessary to allow QT access to some X11 internals (see the references). With the -v switches there are some memory volumes available to your docker container. E.g. the shared directory (which is the current working directory) or the X11-unix sockets. The -w switch sets the working directory within the container. The --device switches make some devices available to the container (/dev/console to use screen, /dev/dri to use the graphics card, which is necessary for FreeCAD). The $1 is the command line argument which should be the number or tag of your image listed in docker images. Note that you can show your containers with docker ps -a and maybe delete them with docker rm <container number>. Further it is also possible to delete images with docker rmi <image number>.

Setting permissions correctly

You have to change the following permissions correctly (777 is more than enough and introduces security issues):

  • /dev/console
  • /dev/dri/card0

Compiling FreeCAD

Now enter your docker container with your newly written run script and get FreeCAD from github. For compiling FreeCAD on various platforms please read the help http://www.freecadweb.org/wiki/index.php?title=Online_Help_Toc in the section "Developing applications for FreeCAD"

Congratulations. Now you should be able to contribute to the genericSolver project.

Using the same container later again

Every time you run the run script from above, docker starts a new container. But this is not necessary in general: If you have the fenicsproject script installed, then just perform a docker ps -a to list all containers with their appropriate names:

CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                       PORTS               NAMES
840753c99111        acc1c5fc9bd1                           "/sbin/my_init --q..."   14 hours ago        Exited (127) 2 seconds ago                       dazzling_beaver

In this case the container 840753c99111 from image acc1c5fc9bd1 has the name dazzling_beaver and can be used by fenicsproject start dazzling_beaver.

References