Skip to content

Installation and Run

SWAN can be installed and run on various platforms, including Windows, Linux, and macOS. The installation process typically involves downloading the SWAN source code or pre-compiled binaries from the official SWAN website or repository, followed by setting up the necessary environment variables. User can access the materials from following link and download the suitable version for their operating system.

Windows

  1. Download the Windows installer from the SWAN website.

  2. Run the installer and follow the on-screen instructions to complete the installation.

  3. Set up environment variables if necessary.

  4. Important note = SWAN on Windows usually works in serial mode (only using one CPU core). For parallel simulation, consider using Linux or WSL2.

Linux

  1. Install supporting libraries and compilers (e.g., gfortran).
    sudo apt-get install wget nano gfortran m4 build-essential
    
  2. Choose compilers
    export FC=gfortran
    
  3. Download desired SWAN version
    wget https://swanmodel.sourceforge.net/download/zip/swan4145.tar.gz
    
  4. Extract and navigate to the extracted directory
    tar -xvzf swan4145.tar.gz && cd swan4145
    
  5. Build using OMP (OpenMP) for parallel processing
    perl switch.pl -unix _.ftn _.ftn90
    
  6. Start compiling
    make config
    
  7. Compiling OMP

    make omp
    

  8. During the installation process, users may encounter an issue in the compilation step (make config).

  9. This issue can be resolved by modifying the macros.inc to include the flag -fallow-argument-mismatch in the FFLAGS section. This flag allows for more flexibility in argument matching during compilation, which can help resolve compatibility issues with certain Fortran compilers.

  10. Turn the swanrun file executable by using the command below:

    chmod +x swanrun swan.exe
    

  11. Move the swanrun and swan.exe files to the desired working directory where the user wants to run the SWAN model.

  12. To run the SWAN model, user need to make sure that the required files such as input files (wind and bathymetry), configuration/namelist file (.swn), initial and boundary condition files (if available) are in the same directory as the swanrun or swan.exe file. Then, execute the following command in the terminal or command prompt:

    ./swanrun -input [your_namelist_file] -omp [number_of_cores]
    

Error Compilation
Figure 4. Error during SWAN compilation step.
Solution of Error
Figure 5. Solution for SWAN compilation error, user need to add -fallow-argument-mismatch.

Important note = If user install in cluster or HPC, usually user are not allowed to run the model directly in the login node like in point 12. So, to run the SWAN model user need to use sbatch script to create a job. An example of sbatch script for running SWAN in cluster or HPC environment is provided below:

#!/bin/bash
#SBATCH --job-name=swantest
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=24
#SBATCH --exclusive

module load mpi/2021.5.1
module load compiler/2022.0.2

time srun ./swanrun -input [your_namelist_file] -omp $SLURM_CPUS_PER_TASK

echo "Job completed successfully."

exit 0

Credits of installation = Javier Rodriguez