SWAN
In this section:
Description
According to the page of SWAN, SWAN (Simulating Waves Nearshore) is a third-generation wave model that computes random wind-generated waves in coastal regions and inland waters.
Available Versions
swan/41.31-mpi
swan/41.31-omp
swan/41.31-serial (default)
Loading the Module
# Serial version
module load swan/41.31-serial
# OpenMP version
module load swan/41.31-omp
# MPI version
module load swan/41.31-mpi
Serial Job Submission
submit_swan_serial.sh
#!/bin/bash
#SBATCH -J swan_serial
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -t 24:00:00
#SBATCH --mem=8G
export INPUT="a11refr.swn a11refr.bot a11refr.loc"
export OUTPUT="swanout"
module load swan/41.31-serial
job-nanny swansbatch.sh -input a11refr > swanout &
OpenMP Job Submission
submit_swan_omp.sh
#!/bin/bash
#SBATCH -J swan_omp
#SBATCH -N 1
#SBATCH -c 8
#SBATCH -t 24:00:00
#SBATCH --mem=16G
export INPUT="a11refr.swn a11refr.bot a11refr.loc"
export OUTPUT="swanout"
module load swan/41.31-omp
job-nanny swansbatch.sh -input a11refr -omp $SLURM_CPUS_PER_TASK > swanout &
MPI Job Submission
submit_swan_mpi.sh
#!/bin/bash
#SBATCH -J swan_mpi
#SBATCH -N 2
#SBATCH --ntasks-per-node=14
#SBATCH -t 48:00:00
#SBATCH --mem-per-cpu=2G
# Avoid memory errors in MPI processing
ulimit -l unlimited
export INPUT="a11refr.swn a11refr.bot a11ref01.spc a11refr.loc"
export OUTPUT="swanout"
module load swan/41.31-mpi
job-nanny swansbatch.sh -input a11refr -mpi $SLURM_NTASKS > swanout &
Example Input File
a11refr.swn
PROJECT 'Refraction test' 'Test 1'
SET level = 0.0
MODE STATTWOD
COORDINATES CARTESIAN
CGRID 0.0 0.0 0.0 10000.0 10000.0 100 100 CIRCLE 36 0.05 1.0
INPGRID BOTTOM 0.0 0.0 0.0 101 101 100.0 100.0 EXC -999.0
READINP BOTTOM 1.0 'a11refr.bot' 4 0 FREE
INPGRID WIND 0.0 0.0 0.0 1 1 10000.0 10000.0 EXC -999.0
READINP WIND 1.0 'a11refr.wnd' 4 0 FREE
BOUND SHAPESPEC JONSWAP 3.3 PEAK DSPR DEGREES
BOUND SEGMENT XY 0.0 5000.0 10000.0 5000.0 CONSTANT FILE 'a11ref01.spc'
WIND
FRICTION
BREAKING
TRIADS
NUMERIC STOPCriterion 0.02 DIRMOM STOP
QUANTITY ABS
BLOCK 'COMPGRID' NOHEAD 'a11refr.mat' LAYOUT 3
HS PER RTP TPS TM01 TM02 DIR DSPR WINDOW
POINTS 'a11refr.loc' FILE 'a11refr.out' 1 'out'
TABLE 'a11refr.loc' HEAD 'a11refr.tab' XP YP HS PER
TEST 1,0
COMPUTE
Bathymetry File
a11refr.bot
1.0 1.0 0.0 0.0 10.0 20.0 30.0 40.0 50.0 50.0 ...
Output Points File
a11refr.loc
1000.0 1000.0
2000.0 2000.0
3000.0 3000.0
4000.0 4000.0
5000.0 5000.0
Input Spectrum File
a11ref01.spc
36
0.05 0.00 0.000
0.05 30.0 0.100
0.05 60.0 0.200
...
Job Array for Multiple Simulations
submit_swan_array.sh
#!/bin/bash
#SBATCH -J swan_array
#SBATCH --array=1-5
#SBATCH -N 1
#SBATCH -c 8
#SBATCH -t 24:00:00
#SBATCH --mem=16G
WIND_SPEEDS=(10 15 20 25 30)
WIND=${WIND_SPEEDS[$SLURM_ARRAY_TASK_ID-1]}
export INPUT="template.swn"
export OUTPUT="wind_${WIND}/"
module load swan/41.31-omp
mkdir -p wind_${WIND}
cd wind_${WIND}
cp ../template.swn input.swn
cp ../*.bot .
cp ../*.loc .
# Modify wind speed
sed -i "s/WIND_SPEED/$WIND/g" input.swn
job-nanny swansbatch.sh -input input -omp $SLURM_CPUS_PER_TASK > swanout
Results Analysis
analyze_swan.sh
#!/bin/bash
#SBATCH -J analyze_swan
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -t 01:00:00
#SBATCH --mem=2G
# Extract wave heights from output files
for dir in wind_*/; do
wind=$(basename $dir | sed 's/wind_//')
echo "Wind speed: $wind" >> wave_heights.txt
if [ -f "${dir}a11refr.out" ]; then
awk '{print $3}' ${dir}a11refr.out | head -5 >> wave_heights.txt
fi
echo "" >> wave_heights.txt
done
# Plot with Python
cat > plot_waves.py << 'EOF'
import numpy as np
import matplotlib.pyplot as plt
# Extract data (simplified format)
winds = []
wave_heights = []
with open('wave_heights.txt', 'r') as f:
lines = f.readlines()
i = 0
while i < len(lines):
if lines[i].startswith('Wind speed'):
wind = float(lines[i].split(':')[1].strip())
heights = []
i += 1
while i < len(lines) and lines[i].strip() and not lines[i].startswith('Wind speed'):
heights.append(float(lines[i].strip()))
i += 1
winds.append(wind)
wave_heights.append(np.mean(heights))
else:
i += 1
plt.figure()
plt.plot(winds, wave_heights, 'bo-')
plt.xlabel('Wind speed (m/s)')
plt.ylabel('Significant wave height (m)')
plt.title('Wave height vs wind speed')
plt.grid(True)
plt.savefig('wave_heights.png')
EOF
python plot_waves.py
References
Documentation: https://swanmodel.sourceforge.io/online_doc/swan_use.html
Manual: https://swanmodel.sourceforge.io/download/zip/swanuse.pdf
Tutorials: https://swanmodel.sourceforge.io/tutorial/tutorial.htm
See also
OpenFOAM - CFD for other applications
SU2 - Alternative for CFD
Running Simulations - How to submit jobs