Running oomph-lib anywhere (in docker)

Oomph-lib is an open-source C++ finite-element library, a great versatile tool for 2 and 3-dimensional fluid and solid mechanical modelling. However, it is currently developed on Linux systems. While it is possible to run it on OSX, the setup isn’t trivial. Docker is a container solution, where programs are run in containers, which are isolated from the operating system but share its resources. In contrast to a virtual machine, a container only uses RAM and CPU when needed and releases it again when it has finished running the task at hand.  From the docker website:

Developers use Docker to eliminate “works on my machine” problems when collaborating on code with co-workers.

Let’s setup oomph-lib on docker! Images are specified enviroments in which programmes can be run. For example, our images will need to contain both gcc as well as svn. Containers are running instances of an image that allow code execution. However, containers are isolated environments that have no persistent storage. As we will want to save our code changes, we will need to work with docker mounts or volumes, a mechanism for persistent storage.

Before continuing, you need to install Docker

1. Build Ubuntu image with the necessary libraries to run oomph lib

The Dockerfile defines what libraries are installed in a container. Place this in a file called Dockerfile in an empty folder with the name oomphbase.

FROM ubuntu
RUN apt-get update && \
 apt-get install -y --no-install-recommends \
 autoconf \
 automake \
 dpkg-dev \
 g++ \
 gcc \
 libbz2-dev \
 libtool \
 make \
 gfortran \
 subversion\
 git \
 python \
 python-dev \ 
 python-pip \
 python-virtualenv \
 emacs; 

CMD [ "sh", "-c", "bash"]

Build this image with the following command (when in the same directory)

docker build -t oomphbase

2. Start a container based on this image with a mount point to store the library

I have setup an empty folder at /Users/edgar/oomph-lib, amend as appropriate for your system.

docker run -d -it --name oomph --mount =bind,source=/Users/edgar/oomph-lib,target=/oomph-lib oomphbase:latest

3. Check that it is mounted correctly

docker inspect oomph

In the output you should find details on the mounting

"Mounts": 
  [ { "Type": "bind", 
      "Source": "/Users/edgar/oomph-lib", 
      "Destination": "/oomph-lib", 
      "Mode": "", 
      "RW": true, 
      "Propagation": "rprivate" } 
  ],

4. Get a Bash terminal

Attach a bash terminal to the docker container (you can attach as many terminals as you like with this command)

docker exec -i -t oomph /bin/bash

You should now be in the terminal of the Docker container.

5. Download and build oomph-lib

Run the following commands. This will take a while. Refer to the omph-lib page for any problems.

cd oomph-lib; svn checkout svn://oomph-lib.maths.man.ac.uk/release/trunk .

After download, run either the interactive or non-interactive script to build the library

./autogen.sh
./non_interactive_autogen.sh

At this point, you should have a ready installed oomph-lib library on your machine!

6. Optional: Run self-tests

It will take quite some time to run the self-tests

make check -k

Expected output

======================================================================
All 854 compiled test[s] passed successfully.

See /oomph-lib/self_test/analyse_self_tests/validation.log for details.

mpi_run_command_length: 0 Don't have mpi compiler... 
===========================================================

 

 

Left as an exercise to the reader

You can expose the X11 socket so that you can use graphical software, such as emacs or Paraview, in a Docker container. As the files are in a mount point of your system, it is also possible to modify them with an editor from your OS, just watch out for file ending problems.

For emacs, there is a guide how to do it here.

Leave a Reply

Your email address will not be published. Required fields are marked *