RETURN
Simulation
May 2024

OpenFoam-Foundation on Qarnot Cloud

OpenFoam-foundation is the go to open source software for Computational Fluid Dynamics (CFD) simulations. While it is mostly used for fluid simulations, it also has solvers for all kinds of physics. Running your OpenFoam-foundation simulation on Qarnot is as easy as uploading your case and launching a script. Here’s a walk-through of the different steps.

Versions

The test case uses OpenFoam-foundation 11, but there are many versions available on Qarnot, which are given in the following table. To choose one, simply change the value of DOCKER_TAG in the script used to launch the calculation.

If you are interested in another version, please send us an email at qlab@qarnot.com.

Prerequisites

Before launching the case, please ensure that the following prerequisites have been met.

Test case

This test case is based on the motorbike tutorial simulation. The test case presented as follow is based on the motorbike 11 case. It contains the mesh and case setup files.

Download it, unzip it and move the folder MOTORBIKE-11 to an "input" folder.

Launching the case

After downloaded the motorbike case, you should be able to launch your computation in the two ways presented below (batch or ssh mode).

1 - Batch Mode

run-openfoam-foundation.py

#!/usr/bin/env python

# Import the Qarnot SDK
import qarnot
import os

# Create a connection, from which all other objects will be derived
# Enter client token here

conn = qarnot.connection.Connection(client_token="MY_SECRET_TOKEN")

# -------------------------------------------------------------------------- #
NB_NODES = 2
# -------------------------------------------------------------------------- #

# Create a task
task = conn.create_task("OpenFOAM Tests",
                        "openfoam-foundation", NB_NODES)


# Create the input bucket and synchronize with a local folder
# Insert a local folder directory
input_bucket = conn.retrieve_or_create_bucket("openfoam-in")
input_bucket.sync_directory("input")

# Attach the bucket to the task
task.resources.append(input_bucket)

# Create a result bucket and attach it to the task
task.results = conn.create_bucket("openfoam-out")

task.constants['OPENFOAM_INPUT_DIRECTORY_NAME'] = 'MOTORBIKE-11'
task.constants['RUN_SCRIPT'] = "MOTORBIKE-11/Allrun"
task.constants['DOCKER_TAG'] = "11"

# Define checkpoint
task.snapshot(60)

# Submit the task
task.submit()

To launch this script, simply copy the preceding code in a Python script, put at the same level as the input folder and execute python3 run-openfoam-foundation.py & in your terminal. Be sure you have copied your authentication token in the script (instead of <MY_SECRET_TOKEN>) to be able to launch the task on Qarnot.

Your test case will be automatically launched using the RUN_SCRIPT path command set in the run-openfoam-foundation.py script.

2 - Ssh Mode

run-openfoam-foundation-ssh.py

#!/usr/bin/env python

# Import the Qarnot SDK
import qarnot
import os

# Create a connection, from which all other objects will be derived
# Enter client token here

conn = qarnot.connection.Connection(client_token="MY_SECRET_TOKEN")

# -------------------------------------------------------------------------- #
NB_NODES = 2
# -------------------------------------------------------------------------- #

# Create a task
task = conn.create_task("OpenFOAM-SSH Test",
                        "openfoam-foundation-ssh", NB_NODES)


# Create the input bucket and synchronize with a local folder
# Insert a local folder directory
input_bucket = conn.create_bucket("openfoam-in")
input_bucket.sync_directory("input")

# Attach the bucket to the task
task.resources.append(input_bucket)

# Create a result bucket and attach it to the task
task.results = conn.create_bucket("openfoam-out")

task.constants['DOCKER_TAG'] = "11"
task.constants['DOCKER_SSH'] = ''

# Define checkpoint
task.snapshot(60)

# Submit the task
task.submit()

# The following will print the state of the task to your console
# It will also print the command to connect through ssh to the task when it's ready
LAST_STATE = ''
SSH_TUNNELING_DONE = False
while not SSH_TUNNELING_DONE:
    if task.state != LAST_STATE:
        LAST_STATE = task.state
        print(f"** {LAST_STATE}")

    # Wait for the task to be FullyExecuting
    if task.state == 'FullyExecuting':
        # If the ssh connexion was not done yet and the list active_forward is available (len!=0)
        forward_list = task.status.running_instances_info.per_running_instance_info[0].active_forward
        if not SSH_TUNNELING_DONE and len(forward_list) != 0:
            ssh_forward_port = forward_list[0].forwarder_port
            ssh_forward_host = forward_list[0].forwarder_host
            cmd = f"ssh -o StrictHostKeyChecking=no openfoam@{ssh_forward_host} -p {ssh_forward_port}"
            print(cmd)
            SSH_TUNNELING_DONE = True

    # Display errors on failure
    if task.state == 'Failure':
        print(f"** Errors: {task.errors[0]}")
        SSH_TUNNELING_DONE = True

The script presented below allows you to connect your container thanks to the ssh protocol.

To launch it, simply copy the preceding code in a Python script, put it at the same level as the input folder and set your ssh key in the DOCKER_SSH parameters. Be sure you have copied your authentication token in the script (instead of "MY_SECRET_TOKEN") to be able to launch the task on Qarnot.
Execute python3 run-openfoam-foundation-ssh.py & in your terminal.
You now should be able to connect the host by following the printed information on your console.

/!\ Please note you have to use the user openfoam to launch your case.

Your test case is available in /share.
Go to the /share directory and you now are able to run your test case with the command set in the RUN_SCRIPT variable.
cd /share
bash MOTORBIKE-11/Allrun

To know more about the parameters available, refers to the parameters section.

Results

At any given time, you can monitor the status of your task on the general web interface Console. The following figure shows a successful OpenFoam demo simulation on Qarnot’s console.

You should also now have a result folder in the output bucket and on your computer containing all the numerical results. You can open the motorbike.foam file to view the results in Paraview or any other viewer. You can also use our Paraview Web implementation to view the results online if needed.

Available parameters :

Wrapping up

That’s it! If you have any questions, please contact qlab@qarnot.com and we will help you with pleasure!

Return

Our articles