{"id":4136,"date":"2022-04-28T10:22:53","date_gmt":"2022-04-28T08:22:53","guid":{"rendered":"http:\/\/ucthpc.uct.ac.za\/?p=4136"},"modified":"2025-05-13T10:17:48","modified_gmt":"2025-05-13T08:17:48","slug":"openfoam-and-singularity","status":"publish","type":"post","link":"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/","title":{"rendered":"Openfoam and Singularity"},"content":{"rendered":"<p>Singularity is a container technology that allows users and administrators to build complex software stacks inside a single file for execution. This has several benefits which include the ability to choose an operating system of their choice as well as specific versions of software dependencies. OpenFoam is one of those applications which has several dependencies and requires a specific compile environment to be successful.<\/p>\n<p>The ICTS HPC team has built a singularity container for OpenFOAM. In order to execute Openfoam commands via the SLURM scheduler, the following job script should exist.<\/p>\n<p><code><br \/>\n#!\/bin\/bash<br \/>\n#SBATCH --account=icts<br \/>\n#SBATCH --partition=ada<br \/>\n#SBATCH --nodes=1 --ntasks=4<br \/>\n#SBATCH --time=10:00:00<br \/>\n#SBATCH --job-name=\"OpenFoam\"<br \/>\n#SBATCH --mail-user=user@domain.co.za<br \/>\n#SBATCH --mail-type=BEGIN,FAIL<br \/>\n# Set this environment if your software is being called from a container<br \/>\nSINGULARITY_PATH=\/opt\/exp_soft\/singularity-containers\/openfoam<br \/>\nCONTAINER_ID=OpenFoam-2306<br \/>\nFOAM_BASHRC=\/openfoam\/bash.rc<\/p>\n<p># try to compile solver as part of a SLURM job<br \/>\nsingularity exec $SINGULARITY_PATH\/$CONTAINER_ID.sif bash -c \"source $FOAM_BASHRC && wclean\"<br \/>\nsingularity exec $SINGULARITY_PATH\/$CONTAINER_ID.sif bash -c \"source $FOAM_BASHRC && wmake\"<\/p>\n<p># Execute bashrc and OpenFoam Commands<br \/>\nsingularity exec $SINGULARITY_PATH\/$CONTAINER_ID.sif bash -c \"source $FOAM_BASHRC && blockMesh\"<br \/>\nsingularity exec $SINGULARITY_PATH\/$CONTAINER_ID.sif bash -c \"source $FOAM_BASHRC && decomposePar\"<br \/>\n<\/code><\/p>\n<p>Let&#8217;s breakdown the <code>singularity exec<\/code> section of the SLURM job script. The first command and its associated argument inform the script to execute singularity. The next section <code>$SINGULARITY_PATH\/singularity-containers\/openfoam\/OpenFoam-2306.sif<\/code> tells singularity which container to use. The final argument is the command to execute inside the container <code>bash -c \"source $FOAM_BASHRC && wclean\" <\/code> which says, execute the bash shell and inside the bash shell, run the following commands. With OpenFOAM, it is important to source the OpenFOAM bashrc to set up the environment. After sourcing the bashrc, the OpenFoam commands are executed. <\/p>\n<p>The syntax related to OpenFOAM commands specifically can be updated as you see fit. For example, the script above does not take into account the data location from which the decomposePar is used. <\/p>\n<p>Singularity containers are read-only and therefore cannot be changed. The ICTS HPC team has added \/scratch and \/home into the container as bind mounts which makes it easy for users to work with their data from within a container. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Singularity is a container technology that allows users and administrators to build complex software stacks inside a single file for execution. This has several benefits which include the ability to choose an operating system of their choice as well as specific versions of software dependencies. OpenFoam is one of those applications which has several dependencies&#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[31,32,30,27],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Openfoam and Singularity - UCT HPC<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Openfoam and Singularity - UCT HPC\" \/>\n<meta property=\"og:description\" content=\"Singularity is a container technology that allows users and administrators to build complex software stacks inside a single file for execution. This has several benefits which include the ability to choose an operating system of their choice as well as specific versions of software dependencies. OpenFoam is one of those applications which has several dependencies...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/\" \/>\n<meta property=\"og:site_name\" content=\"UCT HPC\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-28T08:22:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-13T08:17:48+00:00\" \/>\n<meta name=\"author\" content=\"Timothy Carr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Timothy Carr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/\"},\"author\":{\"name\":\"Timothy Carr\",\"@id\":\"https:\/\/ucthpc.uct.ac.za\/#\/schema\/person\/41f6cd039836d7741f2b82a7b7cfe8d0\"},\"headline\":\"Openfoam and Singularity\",\"datePublished\":\"2022-04-28T08:22:53+00:00\",\"dateModified\":\"2025-05-13T08:17:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/\"},\"wordCount\":247,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/ucthpc.uct.ac.za\/#organization\"},\"keywords\":[\"container\",\"hpc\",\"openfoam\",\"singularity\"],\"articleSection\":[\"hpc\"],\"inLanguage\":\"en-ZA\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/\",\"url\":\"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/\",\"name\":\"Openfoam and Singularity - UCT HPC\",\"isPartOf\":{\"@id\":\"https:\/\/ucthpc.uct.ac.za\/#website\"},\"datePublished\":\"2022-04-28T08:22:53+00:00\",\"dateModified\":\"2025-05-13T08:17:48+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/#breadcrumb\"},\"inLanguage\":\"en-ZA\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ucthpc.uct.ac.za\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Openfoam and Singularity\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ucthpc.uct.ac.za\/#website\",\"url\":\"https:\/\/ucthpc.uct.ac.za\/\",\"name\":\"UCT HPC\",\"description\":\"University of Cape Town High Performance Computing\",\"publisher\":{\"@id\":\"https:\/\/ucthpc.uct.ac.za\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ucthpc.uct.ac.za\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-ZA\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/ucthpc.uct.ac.za\/#organization\",\"name\":\"University of Cape Town High Performance Computing\",\"url\":\"https:\/\/ucthpc.uct.ac.za\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-ZA\",\"@id\":\"https:\/\/ucthpc.uct.ac.za\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/ucthpc.uct.ac.za\/wp-content\/uploads\/2015\/09\/logocircless.png\",\"contentUrl\":\"https:\/\/ucthpc.uct.ac.za\/wp-content\/uploads\/2015\/09\/logocircless.png\",\"width\":450,\"height\":423,\"caption\":\"University of Cape Town High Performance Computing\"},\"image\":{\"@id\":\"https:\/\/ucthpc.uct.ac.za\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/ucthpc.uct.ac.za\/#\/schema\/person\/41f6cd039836d7741f2b82a7b7cfe8d0\",\"name\":\"Timothy Carr\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-ZA\",\"@id\":\"https:\/\/ucthpc.uct.ac.za\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7e94dcf3a408e6ada008042fc29d4b15?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7e94dcf3a408e6ada008042fc29d4b15?s=96&d=mm&r=g\",\"caption\":\"Timothy Carr\"},\"sameAs\":[\"http:\/\/ucthpc.uct.ac.za\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Openfoam and Singularity - UCT HPC","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/","og_locale":"en_US","og_type":"article","og_title":"Openfoam and Singularity - UCT HPC","og_description":"Singularity is a container technology that allows users and administrators to build complex software stacks inside a single file for execution. This has several benefits which include the ability to choose an operating system of their choice as well as specific versions of software dependencies. OpenFoam is one of those applications which has several dependencies...","og_url":"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/","og_site_name":"UCT HPC","article_published_time":"2022-04-28T08:22:53+00:00","article_modified_time":"2025-05-13T08:17:48+00:00","author":"Timothy Carr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Timothy Carr","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/#article","isPartOf":{"@id":"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/"},"author":{"name":"Timothy Carr","@id":"https:\/\/ucthpc.uct.ac.za\/#\/schema\/person\/41f6cd039836d7741f2b82a7b7cfe8d0"},"headline":"Openfoam and Singularity","datePublished":"2022-04-28T08:22:53+00:00","dateModified":"2025-05-13T08:17:48+00:00","mainEntityOfPage":{"@id":"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/"},"wordCount":247,"commentCount":0,"publisher":{"@id":"https:\/\/ucthpc.uct.ac.za\/#organization"},"keywords":["container","hpc","openfoam","singularity"],"articleSection":["hpc"],"inLanguage":"en-ZA","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/","url":"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/","name":"Openfoam and Singularity - UCT HPC","isPartOf":{"@id":"https:\/\/ucthpc.uct.ac.za\/#website"},"datePublished":"2022-04-28T08:22:53+00:00","dateModified":"2025-05-13T08:17:48+00:00","breadcrumb":{"@id":"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/#breadcrumb"},"inLanguage":"en-ZA","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/ucthpc.uct.ac.za\/index.php\/2022\/04\/28\/openfoam-and-singularity\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ucthpc.uct.ac.za\/"},{"@type":"ListItem","position":2,"name":"Openfoam and Singularity"}]},{"@type":"WebSite","@id":"https:\/\/ucthpc.uct.ac.za\/#website","url":"https:\/\/ucthpc.uct.ac.za\/","name":"UCT HPC","description":"University of Cape Town High Performance Computing","publisher":{"@id":"https:\/\/ucthpc.uct.ac.za\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ucthpc.uct.ac.za\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-ZA"},{"@type":"Organization","@id":"https:\/\/ucthpc.uct.ac.za\/#organization","name":"University of Cape Town High Performance Computing","url":"https:\/\/ucthpc.uct.ac.za\/","logo":{"@type":"ImageObject","inLanguage":"en-ZA","@id":"https:\/\/ucthpc.uct.ac.za\/#\/schema\/logo\/image\/","url":"https:\/\/ucthpc.uct.ac.za\/wp-content\/uploads\/2015\/09\/logocircless.png","contentUrl":"https:\/\/ucthpc.uct.ac.za\/wp-content\/uploads\/2015\/09\/logocircless.png","width":450,"height":423,"caption":"University of Cape Town High Performance Computing"},"image":{"@id":"https:\/\/ucthpc.uct.ac.za\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/ucthpc.uct.ac.za\/#\/schema\/person\/41f6cd039836d7741f2b82a7b7cfe8d0","name":"Timothy Carr","image":{"@type":"ImageObject","inLanguage":"en-ZA","@id":"https:\/\/ucthpc.uct.ac.za\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7e94dcf3a408e6ada008042fc29d4b15?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7e94dcf3a408e6ada008042fc29d4b15?s=96&d=mm&r=g","caption":"Timothy Carr"},"sameAs":["http:\/\/ucthpc.uct.ac.za"]}]}},"_links":{"self":[{"href":"https:\/\/ucthpc.uct.ac.za\/index.php\/wp-json\/wp\/v2\/posts\/4136"}],"collection":[{"href":"https:\/\/ucthpc.uct.ac.za\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ucthpc.uct.ac.za\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ucthpc.uct.ac.za\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/ucthpc.uct.ac.za\/index.php\/wp-json\/wp\/v2\/comments?post=4136"}],"version-history":[{"count":7,"href":"https:\/\/ucthpc.uct.ac.za\/index.php\/wp-json\/wp\/v2\/posts\/4136\/revisions"}],"predecessor-version":[{"id":4967,"href":"https:\/\/ucthpc.uct.ac.za\/index.php\/wp-json\/wp\/v2\/posts\/4136\/revisions\/4967"}],"wp:attachment":[{"href":"https:\/\/ucthpc.uct.ac.za\/index.php\/wp-json\/wp\/v2\/media?parent=4136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ucthpc.uct.ac.za\/index.php\/wp-json\/wp\/v2\/categories?post=4136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ucthpc.uct.ac.za\/index.php\/wp-json\/wp\/v2\/tags?post=4136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}