Child pages
  • OpenFOAM - Cavity Tutorial

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Load the OpenFOAM module:
    Code Block
    bash
    titlebashTerminal window
    borderStylesolidbash
    titleTerminal window
    module load openfoam
    It might be wise to note what version of OpenFOAM you are loading. This can be done by listing the different software packages available, and look for the default OpenFOAM version:
    Code Block
    bash
    titlebashTerminal window
    borderStylesolidbash
    titleTerminal window
    module avail
    This guide is written for version 2.1.1, but should apply for other versions as well (at least the 2.x.x versions of OpenFOAM).
  2. Since we don't want to write all the input files from scratch, we copy the tutorial files to a directory of your choice:
    Code Block
    bash
    titlebashTerminal window
    borderStylesolidbash
    titleTerminal window
    cp -R $FOAM_TUTORIALS/incompressible/icoFoam/cavity ./
    cd cavity
    On Vilje you have access to the folders /home/ntnu/username and /work/username. The difference is the storage quotas and how long you are allowed to have files there. On /work there is a larger quota than on /home, but the files on /work are automatically deleted after a certain time after last access.
  3. Then we need a job script to run OpenFOAM (in no cases should you run OpenFOAM on the login node, independent on the simulation size). Based on the template in Old Job Execution a small job script has been created:
    Code Block
    bash
    bash
    titleOFjob1.shbash
    #!/bin/bash
    #PBS -A nn1234k
    #PBS -N OF_tutorial_1
    #PBS -l walltime=00:01:00
    #PBS -l select=1:ncpus=1:mpiprocs=1
    
    # Load modules
    module load openfoam
    
    # Enter the directory where the user is when submitting the job
    cd $PBS_O_WORKDIR
    
    # Run OpenFOAM
    blockMesh
    icoFoam
    Create a new textfile, for example in your home directory, and give it an appropriate name. For simplicity, we assume you called this file OFjob1.sh. Copy the job script into the textfile, and replace nn1234k with your account number. The file must be made executable the usual way:
    Code Block
    bash
    titlebashTerminal window
    borderStylesolidbash
    titleTerminal window
    chmod +x OFjob1.sh
  4. Then this file can be submitted to the job queue on Vilje:
    Code Block
    bash
    titlebashTerminal window
    borderStylesolidbash
    titleTerminal window
    qsub OFjob1.sh
    When the job is finished (should be quick, depending on the queue), several folders have appeared in the directory. The names are 0.1, 0.2 etc, and they are the folders where the results from the different timesteps are stored.
  5. Run Paraview and inspect the results as described in the end of this article.

...

Our job script also needs to be modified so we create a new one, called OFjob2. Paste the following into the file (again remember to change the account number):

Code Block
bash
bash
titleOFjob2bash
#!/bin/bash
#PBS -A nn1234k
#PBS -N OF_tutorial_2
#PBS -l walltime=00:05:00
#PBS -l select=1:ncpus=32:mpiprocs=16

# Load modules
module load mpt
module load openfoam

cd $PBS_O_WORKDIR

# Run OpenFOAM
blockMesh
decomposePar -force    # Force here will overwrite any existing mesh
mpiexec_mpt icoFoam -parallel # You do not need to specify the number of MPI processes in this command
reconstructPar

...

  1. Open the system/controlDict file, and change the startFrom variable to latestTime. This tells OpenFOAM to start from the latest timestep present. Then you change the endTime variable from 0.5 to 1.0.
  2. Now we do not want to regenerate the mesh or do the decomposition again. Take the jobscript, and remove the blockMesh and decomposePar commands. Leave the reconstructPar in place. The jobscript should look like this:
    Code Block
    bash
    bash
    titleOFjob3bash
    #!/bin/bash
    #PBS -A nn1234k
    #PBS -N OF_tutorial_3
    #PBS -l walltime=00:05:00
    #PBS -l select=1:ncpus=32:mpiprocs=16
    
    # Load modules
    module load mpt
    module load openfoam
    
    cd $PBS_O_WORKDIR
    
    # Run OpenFOAM
    mpiexec_mpt icoFoam -parallel
    reconstructPar
  3. Submit the job and wait. Inspect the output file and see if the solution has reached steady-state. If no iterations has been performed on the velocity components Ux and Uy, and only a few iterations has been performed on the pressure equations, the solution has probably reached steady-state. Note that we are using a transient solver, and that the solution actually never enter a perfectly steady state (a few iterations will always be done on the pressure equation) due to the nature of fluid problems.
  4. Run Paraview and inspect the results as explained in the next page.