# Run OpenFOAM codes on Curnagl

### Script to run OpenFOAM code

##### **<span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW163764707 BCX2">You are </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">using</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">OpenFOAM</span><span class="NormalTextRun SCXW163764707 BCX2"> on </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">your</span><span class="NormalTextRun SCXW163764707 BCX2"> computer and </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">you</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">need</span><span class="NormalTextRun SCXW163764707 BCX2"> more </span><span class="NormalTextRun ContextualSpellingAndGrammarErrorV2Themed SCXW163764707 BCX2">ressources. </span></span><span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">Let’s</span><span class="NormalTextRun SCXW163764707 BCX2"> g</span><span class="NormalTextRun SCXW163764707 BCX2">o on </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">Curnagl</span><span class="NormalTextRun SCXW163764707 BCX2">!</span></span><span class="EOP SCXW163764707 BCX2" data-ccp-props="{"201341983":0,"335559739":160,"335559740":259}" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;"> </span>**

<span class="EOP SCXW163764707 BCX2" data-ccp-props="{"201341983":0,"335559739":160,"335559740":259}" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;"><span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">OpenFOAM</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">is</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">usually</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">u</span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">sing</span><span class="NormalTextRun SCXW163764707 BCX2"> MPI. </span></span>Here is a bash script to run <span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">your</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">parallelized</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">OpenFOAM</span> <span class="NormalTextRun SCXW163764707 BCX2">code</span></span>. <span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW163764707 BCX2">NTASKS </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">should</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">be</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">replaced</span><span class="NormalTextRun SCXW163764707 BCX2"> by the </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">number</span><span class="NormalTextRun SCXW163764707 BCX2"> of processors </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">you</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">want</span><span class="NormalTextRun SCXW163764707 BCX2"> to use </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">in </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">your</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">OpenFOAM</span><span class="NormalTextRun SCXW163764707 BCX2"> code.</span> It is good practice to put your OpenFOAM code in a bash file instead of calling OpenFOAM commands right into the sbatch file.  
For instance, create <span class="NormalTextRun SCXW163764707 BCX2"><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2"><span class="TextRun SCXW20241963 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW20241963 BCX2">`openfoam.sh`</span></span></span></span> in which you call your OpenFOAM code (replace commands with yours):</span>  
</span>

```bash
!/bin/bash
# First command
decomposepar ...
# Second command, if you are using a parallel command, CALL IT WITH SRUN COMMAND
srun snappyHexMesh -parallel ...
```

Then, create a sbatch file to run your OpenFOAM bash file on Curnagl:

```bash
#!/bin/bash -l 

#SBATCH --job-name openfoam  
#SBATCH --output openfoam.out 

#SBATCH --partition cpu 
#SBATCH --nodes 1  
#SBATCH --ntasks NTASKS 
#SBATCH --cpus-per-task 1 
#SBATCH --mem 8G  
#SBATCH --time 00:30:00
#SBATCH --export NONE

module purge
module load gcc/10.4.0 mvapich2/2.3.7 openfoam/2206 

export SLURM_EXPORT_ENV=ALL

# RUN YOUR BASH OPENFOAM CODE HERE
bash ./openfoam.sh
```

<p class="callout info"><span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">Please<span class="NormalTextRun SCXW163764707 BCX2"> note </span>that<span class="NormalTextRun SCXW163764707 BCX2"> running </span>your parallelized OpenFOAM<span class="NormalTextRun SCXW163764707 BCX2"> code </span>should<span class="NormalTextRun SCXW163764707 BCX2"> not </span>be performed<span class="NormalTextRun SCXW163764707 BCX2"> via </span><span class="NormalTextRun SCXW163764707 BCX2"> <span class="TextRun SCXW20241963 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW20241963 BCX2">`mpirun`</span></span> but </span><span class="NormalTextRun SCXW163764707 BCX2"> <span class="TextRun SCXW20241963 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW20241963 BCX2">`srun`</span></span>.</span><span class="EOP SCXW163764707 BCX2" data-ccp-props="{"201341983":0,"335559739":160,"335559740":259}" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;"> </span>For a complete MPI overview on Curnagl, please refer to [compiling and running MPI codes](https://wiki.unil.ch/ci/books/service-de-calcul-haute-performance-%28hpc%29/page/compiling-and-running-mpi-codes "compiling and running MPI codes") wiki.</span></span></p>

###   


### How do I transfer my OpenFOAM code to Curnagl ?

<span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW163764707 BCX2">Y</span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">ou</span><span class="NormalTextRun SCXW163764707 BCX2"> can</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">upload</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">your</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">OpenFOAM</span><span class="NormalTextRun SCXW163764707 BCX2"> code </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">thanks</span><span class="NormalTextRun SCXW163764707 BCX2"> to </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">FileZilla</span><span class="NormalTextRun SCXW163764707 BCX2"> or copy and paste data to the cluster </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">thank</span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">s</span><span class="NormalTextRun SCXW163764707 BCX2"> to the </span><span class="NormalTextRun SCXW163764707 BCX2"><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2"><span class="TextRun SCXW20241963 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW20241963 BCX2">`scp` </span></span></span>command.</span></span><span class="EOP SCXW163764707 BCX2" data-ccp-props="{"201341983":0,"335559739":160,"335559740":259}" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;"> </span>

<span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun ContextualSpellingAndGrammarErrorV2Themed SCXW163764707 BCX2">Example:</span><span class="NormalTextRun SCXW163764707 BCX2"> I </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">want</span><span class="NormalTextRun SCXW163764707 BCX2"> to copy test.py to </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">Curnagl</span></span><span class="EOP SCXW163764707 BCX2" data-ccp-props="{"201341983":0,"335559739":160,"335559740":259}" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;">. I run the following command:  
</span>

<span class="EOP SCXW163764707 BCX2" data-ccp-props="{"201341983":0,"335559739":160,"335559740":259}" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;"><span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW163764707 BCX2"><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2"><span class="TextRun SCXW20241963 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW20241963 BCX2">`scp test.py <a class="Hyperlink SCXW163764707 BCX2" href="mailto:username@curnagl.dcsr.unil.ch:/YOUR_PATH_ON_CURNAGL%60" rel="noreferrer noopener" style="text-decoration: none; color: inherit;" target="_blank"><span class="TextRun Underlined SCXW163764707 BCX2" data-contrast="none" lang="FR-FR" style="color: rgb(5, 99, 193); font-size: 11pt; text-decoration: underline; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><username>@curnagl.dcsr.unil.ch:/YOUR_PATH_ON_CURNAGL</span></a>`</span></span></span></span></span></span>

<span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">Where <span class="EOP SCXW163764707 BCX2" data-ccp-props="{"201341983":0,"335559739":160,"335559740":259}" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;"><span class="NormalTextRun SCXW163764707 BCX2"><span class="TextRun SCXW20241963 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW20241963 BCX2">`<a class="Hyperlink SCXW163764707 BCX2" href="mailto:username@curnagl.dcsr.unil.ch:/YOUR_PATH_ON_CURNAGL%60" rel="noreferrer noopener" style="text-decoration: none; color: inherit;" target="_blank"><span class="TextRun Underlined SCXW163764707 BCX2" data-contrast="none" lang="FR-FR" style="color: rgb(5, 99, 193); font-size: 11pt; text-decoration: underline; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR">YOUR_PATH_ON_CURNAGL</span></a>`</span></span></span></span></span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">is</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">something</span><span class="NormalTextRun SCXW163764707 BCX2"> like <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2"><span class="EOP SCXW163764707 BCX2" data-ccp-props="{"201341983":0,"335559739":160,"335559740":259}" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;"><span class="TextRun SCXW20241963 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW20241963 BCX2">`<a class="Hyperlink SCXW163764707 BCX2" href="mailto:username@curnagl.dcsr.unil.ch:/YOUR_PATH_ON_CURNAGL%60" rel="noreferrer noopener" style="text-decoration: none; color: inherit;" target="_blank"><span class="TextRun Underlined SCXW163764707 BCX2" data-contrast="none" lang="FR-FR" style="color: rgb(5, 99, 193); font-size: 11pt; text-decoration: underline; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR">/users/username/work/my_folder</span></a>`.</span></span></span></span></span></span>

<span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW163764707 BCX2">In </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">these</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">commands</span><span class="NormalTextRun SCXW163764707 BCX2">, do not </span><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">forget</span><span class="NormalTextRun SCXW163764707 BCX2"> to change<span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2"><span class="EOP SCXW163764707 BCX2" data-ccp-props="{"201341983":0,"335559739":160,"335559740":259}" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;"><span class="TextRun SCXW20241963 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW20241963 BCX2"> `<a class="Hyperlink SCXW163764707 BCX2" href="mailto:username@curnagl.dcsr.unil.ch:/YOUR_PATH_ON_CURNAGL%60" rel="noreferrer noopener" style="text-decoration: none; color: inherit;" target="_blank"><span class="TextRun Underlined SCXW163764707 BCX2" data-contrast="none" lang="FR-FR" style="color: rgb(5, 99, 193); font-size: 11pt; text-decoration: underline; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><username></span></a>`</span></span></span></span> </span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">with</span> <span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">yours</span><span class="NormalTextRun SCXW163764707 BCX2">.</span></span>

<p class="callout info"><span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">**This transfer can be done for any file type: .py, .csv, .h, images...** </span></span></p>

<p class="callout info"><span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">**To copy a folder, use the command <span class="NormalTextRun SCXW163764707 BCX2"> <span class="TextRun SCXW20241963 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW20241963 BCX2">`scp -r`.</span></span></span>**</span></span></p>

<p class="callout info"><span class="TextRun SCXW163764707 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SpellingErrorV2Themed SCXW163764707 BCX2">**<span class="NormalTextRun SCXW163764707 BCX2"><span class="TextRun SCXW20241963 BCX2" data-contrast="auto" lang="FR-FR" style="font-size: 11pt; line-height: 19.425px; font-family: Calibri, 'Calibri_EmbeddedFont', 'Calibri_MSFontService', sans-serif;" xml:lang="FR-FR"><span class="NormalTextRun SCXW20241963 BCX2">For more details, refer to [transfer files to/from Curnagl](https://wiki.unil.ch/ci/books/high-performance-computing-hpc/page/transfer-files-tofrom-curnagl "transfer files to/from Curnagl") wiki.</span></span></span>**</span></span></p>