How to Compile and Execute Custom OpenFOAM Code on cloudHPC.cloud

Published by Ruggero Poletto on

One of the greatest strengths of OpenFOAM is its open architecture. Whether you are developing a novel turbulence model, crafting a tailored boundary condition, or building a brand-new solver from scratch, OpenFOAM gives you total freedom to extend C++ classes to fit your research or industrial needs.

However, moving custom C++ code from a local development machine to a cloud HPC environment often raises questions: How do I compile my custom libraries on the remote node? Do I need to set up complex environment variables or remote SSH build scripts?

At cloudHPC.cloud, weโ€™ve made custom compilation completely zero-config. Our native execution scriptsโ€”covering both Foundation (openFoam-ofXX) and OpenCFD (openFoam-vXXXX) releasesโ€”automatically detect, compile, and link your custom libraries before launching your simulation.

Here is how to structure your case and leverage this automated compilation pipeline.

Folder Structure: How to Pack Your Custom Code

To run a case with custom code, simply place your custom C++ folders directly inside your root OpenFOAM case directory, alongside standard system folders like 0/, constant/, and system/. You can also include a root-level Allwmake script if you want to control the exact build order of multiple libraries.

Here is an overview of how your directory structure should look:

Plaintext

myCustomCase/
โ”œโ”€โ”€ Allwmake                      <-- (Optional) Master Build Script at Root
โ”œโ”€โ”€ 0/
โ”œโ”€โ”€ constant/
โ”œโ”€โ”€ system/
โ”‚   โ””โ”€โ”€ controlDict
โ”œโ”€โ”€ myCustomSolver/               <-- Custom Solver Source Folder
โ”‚   โ”œโ”€โ”€ Make/
โ”‚   โ”‚   โ”œโ”€โ”€ files
โ”‚   โ”‚   โ””โ”€โ”€ options
โ”‚   โ”œโ”€โ”€ myCustomSolver.C
โ”‚   โ””โ”€โ”€ Allwmake                  <-- (Optional) Folder-Level Build Script
โ””โ”€โ”€ myCustomBoundaryCondition/     <-- Custom Library Source Folder
    โ”œโ”€โ”€ Make/
    โ”‚   โ”œโ”€โ”€ files
    โ”‚   โ””โ”€โ”€ options
    โ””โ”€โ”€ myCustomBC.C

Key Structure Rules:

  1. Root-Level Allwmake (Highest Priority): If present directly in myCustomCase/, the script executes this file first to handle top-level project compilation.
  2. Place Subfolders at Root Level: Put your custom solver or library directories directly inside the main project directory.
  3. Standard OpenFOAM Make/ Directory: Ensure each custom subfolder includes a standard Make/ directory containing files and options.
  4. FOAM_USER_APPBIN or FOAM_USER_LIBBIN Output: Make sure your Make/files targets the user directory (e.g., $FOAM_USER_APPBIN for applications or $FOAM_USER_LIBBIN for libraries) so the compiled binary lands in a location accessible by OpenFOAM.

How the Cloud Compiler Script Works Behind the Scenes

When you submit your case via the portal or the cloudHPCexec CLI, our automated script (foam-exec) initializes and scans your project workspace before running the solver.

Key Compilation Hierarchy: The script checks for a master Allwmake file at the root level first. If found, it executes it immediately. Afterwards, it iterates through all subdirectories (like myCustomSolver/) to compile individual components using their local Allwmake or wmake setup.

Here is the updated step-by-step logic the system executes:

                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Upload Case & Launch Script   โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
                                  โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚  Detect OpenFOAM Version  โ”‚
                    โ”‚   & Source Environment    โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
                                  โ–ผ
                /โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\
               / Is 'Allwmake' present at ROOT level \
               \__________________โ”ฌ__________________/
                                 / \
                         YES    /   \    NO
                               /     \
                              โ–ผ       โ–ผ
       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
       โ”‚ Execute ./Allwmake      โ”‚  โ”‚ Iterate through Root Subfolders โ”‚
       โ”‚ Log: Allwmake.log       โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                   โ”‚
                    โ”‚                                โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                      โ”‚
                                      โ–ผ
                 /โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\
                / Does subfolder contain 'Allwmake'?\
                \_________________โ”ฌ_________________/
                                 / \
                         YES    /   \    NO
                               /     \
                              โ–ผ       โ–ผ
       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
       โ”‚ Execute ./Allwmake      โ”‚  โ”‚ Does folder contain 'Make/'?    โ”‚
       โ”‚ Log: folder_comp.log    โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                   โ”‚
                    โ”‚                                โ–ผ
                    โ”‚               /โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\
                    โ”‚              / Is 'Make/' present in subfolder?  \
                    โ”‚              \_________________โ”ฌ_________________/
                    โ”‚                               / \
                    โ”‚                       YES    /   \    NO
                    โ”‚                             /     \
                    โ”‚                            โ–ผ       โ–ผ
                    โ”‚             โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚             โ”‚ Auto-patch FOAM_APPBIN    โ”‚ โ”‚ Skip folder  โ”‚
                    โ”‚             โ”‚ Execute 'wmake .'         โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                    โ”‚             โ”‚ Log: folder_comp.log      โ”‚        โ”‚
                    โ”‚             โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚
                    โ”‚                            โ”‚                     โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                       โ”‚
                                       โ–ผ
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                         โ”‚ Execution Phase          โ”‚
                         โ”‚ Launch Main Solver       โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The Automated Compilation Protocol:

  1. Environment Setup: The system sources the specific OpenFOAM environment (bashrc and RunFunctions) for your chosen version.
  2. Step 1 โ€” Root-Level Check: The script checks if an Allwmake file exists directly inside the case root directory (myCustomCase/Allwmake). If found, it runs this master script first.
  3. Step 2 โ€” Subfolder Iteration: Next, the script loops over every sub-folder in your case root directory.
  4. Strategy A โ€” Local Allwmake Detection: If a subfolder (e.g., myCustomSolver/) contains an Allwmake script, the runner makes it executable and runs ./Allwmake, directing output to a dedicated log file (<folder>_compilation.log).
  5. Strategy B โ€” Automatic wmake Fallback: If no local Allwmake file exists in the subfolder, but a Make/ directory is detected, the script automatically:
    • Safely patches references to default system bins to ensure binaries build inside the user sandbox (FOAM_USER_APPBIN).
    • Runs wmake . directly.
    • Outputs compilation warnings and errors to <folder>_compilation.log for easy debugging.
  6. Solver Execution: Once all custom components are successfully compiled and linked, the script moves on to parallel decomposition and launches your main simulation.

Pro-Tips for Smooth Custom Code Execution

  • Include Custom Libraries in controlDict: If you are compiling a custom boundary condition, function object, or thermophysical model, remember to list the resulting library in your system/controlDict using the libs keyword:Plaintextlibs ( "libmyCustomBC.so" );
  • Check Your Logs: If your solver fails to start due to a missing library or application error, check Allwmake.log or <foldername>_compilation.log in your case directory to inspect the gcc/wmake compiler messages.
  • Avoid Pre-Compiled Binaries: Do not upload local .so or binary files compiled on your workstation, as glibc or compiler version mismatches between Linux builds can cause segmentation faults. Let cloudHPC build fresh, natively optimized binaries on the execution node!

Ready to Run Your Custom OpenFOAM Solvers?

Whether you are sweeping parameters with standard solvers or compiling complex user extensions, cloudHPC.cloud provides the automated infrastructure you need to get fast, reliable results without managing hardware clusters.

๐Ÿš€ Upload your case and custom code today at cloudhpc.cloud

#OpenFOAM #CFD #Simulation #HPC #CloudComputing #CPP #CustomCode #FluidDynamics #Automation


CloudHPC is a HPC provider to run engineering simulations on the cloud. CloudHPC provides from 1 to 224 vCPUs for each process in several configuration of HPC infrastructure - both multi-thread and multi-core. Current software ranges includes several CAE, CFD, FEA, FEM software among which OpenFOAM, FDS, Blender and several others.

New users benefit of a FREE trial of 300 vCPU/Hours to be used on the platform in order to test the platform, all each features and verify if it is suitable for their needs


Categories: OpenFOAM