Close

OpenFOAM for macOS

The packaged distributions of OpenFOAM-dev for Ubuntu can be installed directly on macOS (operating system for Mac computers) using Canonical Multipass.  Multipass creates cloud-style virtual machines (VM) running Ubuntu for macOS (and Windows and Linux). It provides a simple command line interface (CLI) to create and manage VM instances from a macOS terminal.  An Ubuntu instance can then be created, in which OpenFOAM can be installed using our Ubuntu packages. Graphical applications, in particular ParaView, can be run from within the instance through a remote desktop accessed by an RDP (remote desktop protocol) client.

Note: If graphical applications fail on Multipass with RDP, do not report the issue to its producer Kitware, as they do not officially support ParaView on Multipass.  For any problems with the instructions below, go to the OpenFOAM Issue Tracking system.

Installing Multipass on macOS

Canonical provides a guide to Install Multipass on macOS which provides different installation options.  The following steps provide condensed instructions for installing via a terminal in macOS.  (Multipass runs via a terminal anyway, so you may as well start where you mean to end)

  • Open a terminal in macOS (Launchpadterminal)
  • Download the multipass installer by pasting the following command in the terminal
    curl -JLO https://multipass.run/download/macos
  • Wait until the pkg file is downloaded, e.g. multipass-1.13.1+mac-Darwin.pkg
  • Install the package with the following command (which uses the * wildcard, instead of the exact pkg file name)
    sudo installer -pkg ./multipass*.pkg -target /
  • The multipass application should now be installed

Using Multipass

The multipass application runs from within the macOS terminal; it can be tested by listing all its commands in the terminal

multipass help

Instances can be listed, and summary information provided, by the following commands, respectively:

multipass list
multipass info

Launch an Ubuntu instance

An instance requires allocation of hardware resources, namely CPU, memory (RAM) and disk space.  The CPU and memory (in bytes) of the Mac can be found by pasting the following command in the terminal (or from “About this Computer”)

sysctl -h hw.physicalcpu hw.memsize

Instances should not consume all the available resources since some resources are required by the host (mac)OS.  The multipass performance guidance recommends leaving two CPU threads and at least 4 GB to the host OS.  So for a machine with 8 CPU cores and 8 GB memory, we might allocate 6 cores and 4 GB to the instance.  Disk space depends on the demands of the CFD and the other use of the machine. 

We recommend launching an instance with Ubuntu 22.04 LTS (jammy).  If we wish to allocate 100 GB of disk space, we can launch the instance with the following command:

multipass launch -c 6 -m 4G -d 100G -n openfoam jammy

where:

  • -c 6  specifies 6 cores;
  • -m 4G specifies 4 GB of memory;
  • -d 100G specifies 100 GB of disk space;
  • -n openfoam creates the instance with the name openfoam;
  • jammy specifies the Ubuntu version.

The instance openfoam should now start.

Installing OpenFOAM

Once the instance is running, the user can check the details with the multipass list and multipass info commands.  The user should open a shell (terminal) on the Ubuntu instance (named openfoam) by the following command.

multipass shell openfoam

The packaged distributions of OpenFOAM on Ubuntu Linux can be installed from within the Linux shell. Packages are provided by the OpenFOAM download repository (dl.openfoam.org).  Instructions for the following versions of OpenFOAM, packaged for Ubuntu, are available including “User Configuration” and “Getting Started”.

Graphical Applications

OpenFOAM applications, e.g. blockMesh, foamRun etc., can now run from the Ubuntu shell on the multipass instance. However, graphical applications, notably ParaView, cannot be opened (effectively) from the shell.   Instead, a remote desktop client can connect to the instance and provide a full Ubuntu graphical desktop.  To enable this, the instance requires the necessary desktop and an RDP (remote desktop protocol) software to be installed as follows:

sudo apt -y install ubuntu-desktop xrdp

This software can take some time to install.  Once installed, a password needs to be set for the ubuntu user with the following command

sudo passwd ubuntu

The user is prompted to enter and re-enter a password of their choice.  After setting the password, exit the shell by typing exit or logout, which returns the user back to the macOS shell in the terminal.  Before installing the remote desktop client (below), get the IP address of the instance from multipass.  The address has the form 123.456.78.90 and can be obtained by running multipass list; the following command provides the IP address precisely:

multipass list | grep openfoam | awk '{print $3}'

Remote Desktop Installation/Configuration

An RDP client software application now needs to be installed on the macOS.  Multipass recommends Microsoft Remote Desktop, which can be installed for free from the App Store.  Once installed, open the RDP client which presents a window with a button prompting the user to Add PC.  Click the button and in the configuration panel enter the following:

  • PC Name: the IP address from above, e.g. 123.456.78.90;
  • User AccountAdd user account with username: ubuntu and the password set previously;
  • Display Tab Start session in full screen (recommended for ease of use);
  • Click Save.

A PC is then saved in the RDP client, labelled with its IP address and username.

Running the Remote Desktop

Launch the desktop from the RDP client, by selecting the PC → right mouse click → connect.  A dialogue may appear, stating that the RDP client cannot identify the computer because it is not running Windows.  Ignore the message and click connect.

The Ubuntu desktop should open with minimal menus and possibly no visible dock.  The dock will appear by selecting Activities at the top left of the desktop.  It is recommended to add a terminal application to the dock by typing terminal in the search bar and opening the application.  Once opened, the user can select Activities again, go to the dock → terminalright mouse click → Add to favourites.  The user can now use OpenFOAM with graphical applications in its native Linux environment.