Introduction
As mentioned in a recent posting, I am conducting a tutorial on flow around a 2-dimensional cylinder. While conducting this tutorial, I was unable to use pyFoamPlotWatcher.py and gnuplot in my environment. In this post, I summarize how to improve them.
Sources
- Vortex shedding by Joel Guerrero 2D - tutorial referenced from this page, is in progress.
- PyFoam memo - At first, I thought about downloading the latest tar file and installing it, referring to this page, but decided to simply do a pip install.
- X11 Forwarding GUI apps run on remote Docker via SSH - This page describes the procedure for X11 forwarding. The Docker startup command was helpful.
- Drawing GUI apps on Docker via host/remote - An article describing X11 Forwarding, with instructions for connecting from a Mac.
- XQuartz.org - I installed XQuartz from here.
Things that didn’t work
pyFoamPlotWatcher.py
In c2, the next command line at step 3. This is the part where the residuals are plotted on-the-fly from the log file during the simulation. Error that pyFoamPlotWatcher.py does not exist.
$ pyFoamPlotWatcher.py log.icofoam
gnuplot
In c2, the next command line at step 4; the part where the force coefficients are plotted on-the-fly using gnuplot scripts0/plot_coeffs. The container I initially created did not contain gnuplot.
$ gnuplot scripts0/plot_coeffs
Approach to Measures
pyFoam installation
For the pyFoamPlotWatcher.py problem, I thought I should install pyFoamPlotWatcher.py, and upon investigation found that it was included in pyFoam, so I decided to install pyFoam. I found source 2. and thought about installing it from a tar file, but decided to install it with pip.
gnuplot installation
The gnuplot command was not included in the container, so I decided to install it in the container. Thinking about how to display X11 apps running in a remote container on the terminal at hand (Mac), I researched X11 Forwarding and decided to support it by referring to sources 3. and 4.
Specific measures
Dockerfile
The following sections were added from previous to install gnuplot, python, and to install PyFoam with pip.
FROM ubuntu:22.04
# Install any extra things we might need
RUN apt-get update \
&& apt-get install -y \
vim \
ssh \
sudo \
wget \
software-properties-common ;\
rm -rf /var/lib/apt/lists/*
RUN apt-get update \
&& apt-get install -y \
lv \
htop \
neofetch \
curl \
git \
gnuplot \
python3.11-dev \
python3-pip ;\
rm -rf /var/lib/apt/lists/*
RUN curl https://dl.openfoam.com/add-debian-repo.sh | bash
RUN apt-get update \
&& apt-get install -y openfoam2406-default ;\
rm -rf /var/lib/apt/lists/*
# Python / pip
RUN ln -s $(which python3.11) /usr/bin/python
# Install python packages used so far
RUN pip install --upgrade pip setuptools \
&& pip install PyFoam
# Create a new user called foam
RUN useradd --user-group --create-home --shell /bin/bash foam ;\
echo "foam ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
USER foam
WORKDIR /home/foam
RUN echo "source /usr/lib/openfoam/openfoam2406/etc/bashrc" >> ~/.bashrc
X11 Forwarding (Mac client side)
X server installed
In order to display X11 applications (including gnuplot) on the Mac client side, X server and Xquarts were installed. The installation was done by downloading the installation package for Mac from source 5.
Setting the DISPLAY variable
Before making an ssh connection, set the DISPLAY variable in the Mac terminal.
% export DISPLAY=:0
If you have the x server running on your Mac, then after the above setup, typing xeyes in the terminal will launch the xeyes app on your Mac screen.
ssh connection with -Y option
% ssh -Y 192.168.11.3
The IP address above is the server on which the OpenFOAM container is running.
X11 Forwarding (container running on server)
Start the container (container name is openfoam) created from the above Dockerfile with the following shell script.
export OPENFOAM_DIR=/mnt/nfs2/workspace/openfoam
sudo docker run \
-it \
--rm \
-e DISPLAY=$DISPLAY \
--net host \
-v ${OPENFOAM_DIR}:/home/foam \
-v $HOME/.Xauthority:/home/foam/.Xauthority \
openfoam
The meaning of each parameter is understood as follows. Inherit the DISPLAY variable with “-e DISPLAY=$DISPLAY”. “--net host” shares the host’s network settings with the container. X11 protocol can be used on the container side by “-v $HOME/.Xauthority:/home/foam/.Xauthority”.
plot_coeffs modified
When I run plot_coeffs in gunuplot, I get the following error message.
$ gnuplot scripts0/plot_coeffs
"scripts0/plot_coeffs" line 9: warning: Cannot find or open file "postProcessing/forceCoeffs_object/0/forceCoeffs.dat"
"scripts0/plot_coeffs" line 9: No data in plot
“forceCoeffs.dat” existed in “~/sol_postProcessing/forceCoeffs_object/0”, so modified two parts of the “postProcessing/” into “sol_postProcessing/”.
Execution result image
plot residuals
plot continuity
plot forceCoeffs
Summary
The content of this post was not about OpenFOAM features, but more about the infrastructure related to OpenFOAM. It has become useful for future use of OpenFOAM.
In the process of making this improvement, I was able to learn about X Forwarding, which is to display the screen of an x11 application running in a container running on a remote machine on the screen of the PC at hand (in my case, Mac).