OpenFOAM Installation ‐ macOS - openfoam-ICL-UC/openfoam_intro_EN GitHub Wiki

macOS

We will install a pre-compiled version of OpenFOAM in a Docker container. On Mac, there is no need to install a graphical interface for the Terminal, as you can use the Mac Terminal app directly.

Pre-installation

Open the Mac Terminal app to install:

Command line tools:

xcode-select --install

Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Installing Docker on macOS

Docker is similar to a virtual machine but faster and lighter as it doesn't require installing a full OS within a virtual machine. Docker uses containers installed on the current OS through the Docker program, which utilizes OS components to run the desired program, in this case, OpenFOAM. To learn more about Docker and how it works, you can review the tutorials on the "Get started Pages"

Additionally, this tutorial explains in more detail the steps described here for installing OpenFOAM in Docker.

The official instructions for Docker installation on macOS can be found on the next page.

Installing Docker Desktop on MAC

Installing Visual Studio Code on macOS

Visual Studio Code is a code development environment that can be used for multiple languages. It is highly optimized and has become the standard in scientific programming. The editor's capabilities can be extended with extensions.

Installing Visual Studio Code is straightforward by entering the following line in the Mac Terminal app.

brew install --cask visual-studio-code

Installing OpenFOAM Docker

OpenCFD Ltd. uses Docker Hub to distribute containers with pre-packaged, pre-compiled versions of OpenFOAM (latest version 2406) for Linux, macOS, and Windows. These containers allow binaries compiled on one OS to run on another OS without significant performance loss. The available OpenFOAM image uses the latest version of Ubuntu LTS.

The image ending in "-default" it is the just-give-me-everything image, which includes the OpenFOAM tutorials.

Follow the instructions in the developmet OpenFOAM page to complete the installation.

Installing OpenFOAM Docker

Installing ParaView

ParaView is visualization software for computational mechanics simulation results. This software is not installed by default in OpenFOAM, and it is necessary to visualize and analyze the results.

Installing paraview is straightforward by entering the following line in the Mac Terminal app.

brew install --cask paraview

Using OpenFOAM and testing OpenFOAM + ParaView installation

  1. To access OpenFOAM functionalities from the terminal, you must start the image with the OpenFOAM environment.

First, open Docker from the Applications folder.

Then, open the Terminal app.

cd "directory where openfoam-docker is located"

./openfoam2306-run

If you can execute this command, an interactive shell with the OpenFOAM environment will open, and your terminal will change to openfoam$.

  1. From the OpenFOAM page, navigate to the pitzDaily tutorial folder of pimpleFoam and download the tutorial to the openfoam-docker directory.

Then, in the Terminal app, change the directory.

cd openfoam-master-tutorials-incompressible-pimpleFoam-RAS-pitzDaily/tutorials/incompressible/pimpleFoam/RAS/pitzDaily/

  1. Generate the computational grid:

blockMesh

  1. Run the pimpleFoam solver for unsteady incompressible flow:

pimpleFoam

Many numbers will appear in the terminal, representing information for each iteration of the algorithm. Wait between 30 seconds and 2 minutes until the algorithm finishes. You will see the message "End". If you type the command

ls

A list of files in the directory will be displayed, and you will notice a series of folders numbered from 0.01 to 0.3. These folders contain the simulation results, i.e., pressure and velocity as a function of space for each time step where the solution was saved. To visualize these results, use ParaView.

  1. ParaView is used natively on macOS to connect to the folders containing the case solution. First, use an OpenFOAM function that converts the solution files to VTK format.

foamToVTK

This generates a new folder in the case directory named "VTK", containing a series of files in VTK format (.vtm, .vtu, .vtp) for each saved time step of the solution.

Alternatively, you can create a blank file that will allow ParaView to connect to the folders containing the case solution.

touch foam.foam

Then, open the ParaView app and load the VTK files (or the blank foam.foam file) from the case folder.

paraview foam.foam

  1. In ParaView, a window will open, initially showing nothing.

ParaView view when opened

To display the solution, click the "Apply" button. If the simulation has been executed correctly, you will see the following pressure profile on a 2-D mesh. This profile represents the pressure after 0.01 seconds of simulation.

Pressure profile after 0.1 seconds of simulation for the pitzDaily case.

Congratulations! You have successfully completed your OpenFOAM installation.