Try OpenFOAM and ParaView

Motivation

I have been working on PINNs since the end of last year and have attempted two problems. I am planning to select and work on problems in the field of fluid dynamics. In fact, I am working on incompressible flow around a cylinder, but I have been stuck for a week because I can’t figure out how to relate the output of the model to the differential equations (the key part of PINNs).

I decided to learn a bit of OpenFOAM if I am going to work on the fluid dynamics area, so I installed OpenFOAM, ParaView, and tried the examples.

Sources

  1. How to Create an OpenFOAM Docker Image - was very helpful in creating an OpenFOAM docker image.

  2. ParaView - I downloaded the package for Mac from the “DOWNLOAD” page.

  3. OpenFOAM Tutorial List - Explanation of the tutorial. I couldn’t understand it from this explanation alone, and I couldn’t enter the world of OpenFOAM and ParaView.

  4. Introduction to OpenFOAM: Simulation of Planar Poiseuille Flow - By following the information here, I was able to understand a little about the world of OpenFOAM and ParaView.

  5. Raocp/PINN-laminar-flow - I am trying to work on PINNs, and this is the page I am referring to. I am stumped because I don’t understand the introduction of equations (3) and (4) in the paper here.

Installation

System configuration

My environment for testing OpenFOAM and ParaView is as follows: OpenFOAM is run on a server in a docker container, and the output is viewed from a Mac using an NFS mount, and displayed in ParaView.

SysConf

Dockerfile

I created an OpenFOAM container with the following Dockerfile, referring to sources 1.

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 ;\
        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/*


# 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

At first, when I ran the OpenFOAM tutorial as root user, the following error occurred, so I added the “foam” user creation part with reference to sources 1.

--> FOAM FATAL IO ERROR: (openfoam-2406 patch=241212)
This code should not be executed by someone with administrator rights for security reasons.

Container Execution

The container created is executed as follows, sharing data between the container and the host. Note that $(OPENFOAM_DIR) is the NFS mounted area.

export OPENFOAM_DIR=/mnt/nfs2/workspace/openfoam
sudo docker run -it --rm -v ${OPENFOAM_DIR}:/home/foam openfoam bash

Installing ParaView

From the ParaView page shown in Sources 2, I opened the download page, downloaded “ParaView-5.13.1-MPI-OSX10.15-Python3.10-x86_64.dmg” for Mac, and installed it.

Running the simulation

I thought that just running the built-in tutorial code would not be enough to understand OpenFOAM, so I actually created the necessary files myself, referring to sources 4.

Creating the mesh

In executing the Poiseuille flow assignment, I created a “try” directory, and under that directory I created system and constant directories.

Under the system directory, we created “controlDict” and “blockMeshDict”. Then, in the “try” directory, blockMesh was executed.

openfoam2406:~/try/
foam$ blockMesh
/*---------------------------------------------------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2406                                  |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
Build  : _9bfe8264-20241212 OPENFOAM=2406 patch=241212 version=2406

(omitted in the middle)

Writing polyMesh with 0 cellZones
----------------
Mesh Information
----------------
  boundingBox: (0 0 0) (0.3 0.1 0.01)
  nPoints: 2562
  nCells: 1200
  nFaces: 4880
  nInternalFaces: 2320
----------------
Patches
----------------
  patch 0 (start: 2320 size: 20) name: inlet
  patch 1 (start: 2340 size: 20) name: outlet
  patch 2 (start: 2360 size: 120) name: fixedWalls
  patch 3 (start: 2480 size: 2400) name: frontAndBack

End

openfoam2406:~/try/

The created mesh is visualized in ParaView as follows

mesh

Preparation

Create “fvSchemes” and “fvSolution” under the “system” directory. Next, create “p” and “U” under the “0” directory. Finally, create “transportProperties” under the “constant” directory. In the sources 4., “physicalProperties” was used, but in my environment, “transportProperties” worked well.

Simulation Run

openfoam2406:~/try/
foam$ icoFoam
/*---------------------------------------------------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2406                                  |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
Build  : _9bfe8264-20241212 OPENFOAM=2406 patch=241212 version=2406

(omitted in the middle)

Time = 0.5

Courant Number mean: 0.276748 max: 0.412884
smoothSolver:  Solving for Ux, Initial residual = 0.00027116, Final residual = 6.3461e-06, No Iterations 8
smoothSolver:  Solving for Uy, Initial residual = 0.322225, Final residual = 9.39342e-06, No Iterations 21
DICPCG:  Solving for p, Initial residual = 4.17235e-06, Final residual = 6.96067e-07, No Iterations 8
time step continuity errors : sum local = 6.48502e-09, global = -7.71682e-10, cumulative = -2.34105e-05
DICPCG:  Solving for p, Initial residual = 3.49567e-06, Final residual = 5.00111e-07, No Iterations 8
time step continuity errors : sum local = 4.65936e-09, global = 3.79253e-10, cumulative = -2.34101e-05
ExecutionTime = 0.63 s  ClockTime = 3 s

End

openfoam2406:~/try/
foam$ 

Now, create “try.foam” (execute “$ touch try.foam”) under “try” directory.

The directories and files created for reference is as follows.

drwxr-xr-x 2 kenji kenji 4096  1月  5 14:08 0
drwxr-xr-x 3 kenji kenji 4096  1月  5 14:02 constant
drwxr-xr-x 2 kenji kenji 4096  1月  5 14:11 system
-rw-r--r-- 1 kenji kenji    0  1月  5 13:19 tri.foam
-rw-r--r-- 1 kenji kenji   482  1月  5 14:08 0/U
-rw-r--r-- 1 kenji kenji   675  1月  5 14:05 0/p
-rw-r--r-- 1 kenji kenji   208  1月  5 14:02 constant/transportProperties
-rw-r--r-- 1 kenji kenji  1337  1月  5 12:56 system/blockMeshDict
-rw-r--r-- 1 kenji kenji   410  1月  5 12:51 system/controlDict
-rw-rw-r-- 1 kenji kenji   377  1月  5 14:11 system/fvSchemes
-rw-r--r-- 1 kenji kenji   384  1月  5 13:16 system/fvSolution

The U and p visualized in ParaView are as follows

U

p

Summary

I installed OpenFOAM and ParaView and ran the tutorial to try them out, as I was stuck with PINNs, and realized that I had made a mistake in starting with OpenFOAM and ParaView lightly.

After installing OpenFOAM and ParaView, I set up the various files for the “Poiseuille flow” simulation as an example, ran the simulation, and visualized the results. Through this process, I was able to understand a little about the sequence of steps. However, I do not have enough understanding of fluid dynamics to be able to evaluate the contents of the settings and the simulation results. I would like to deepen my understanding as much as possible.