SWAN

Descrição

De acordo com a página do SWAN, SWAN (Simulating Waves Nearshore) é um modelo de ondas de terceira geração que computa ondas aleatórias geradas pelo vento em regiões costeiras e águas interiores.

Versões Disponíveis

  • swan/41.31-mpi

  • swan/41.31-omp

  • swan/41.31-serial (default)

Carregando o Módulo

# Versão serial
module load swan/41.31-serial

# Versão OpenMP
module load swan/41.31-omp

# Versão MPI
module load swan/41.31-mpi

Submissão de Jobs Seriais

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 &

Submissão de Jobs OpenMP

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 &

Submissão de Jobs MPI

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

# Evitar erros de memória em processamento MPI
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 &

Exemplo de Arquivo de Entrada

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

Arquivo de Batimetria

a11refr.bot
1.0 1.0 0.0 0.0 10.0 20.0 30.0 40.0 50.0 50.0 ...

Arquivo de Pontos de Saída

a11refr.loc
1000.0 1000.0
2000.0 2000.0
3000.0 3000.0
4000.0 4000.0
5000.0 5000.0

Arquivo de Espectro de Entrada

a11ref01.spc
36
0.05 0.00 0.000
0.05 30.0 0.100
0.05 60.0 0.200
...

Job Array para Múltiplas Simulações

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 .

# Modificar velocidade do vento
sed -i "s/WIND_SPEED/$WIND/g" input.swn

job-nanny swansbatch.sh -input input -omp $SLURM_CPUS_PER_TASK > swanout

Análise de Resultados

analyze_swan.sh
#!/bin/bash
#SBATCH -J analyze_swan
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -t 01:00:00
#SBATCH --mem=2G

# Extrair alturas de onda dos arquivos de saída
for dir in wind_*/; do
    wind=$(basename $dir | sed 's/wind_//')
    echo "Velocidade do vento: $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

# Plotar com Python
cat > plot_waves.py << 'EOF'
import numpy as np
import matplotlib.pyplot as plt

# Extrair dados (formato simplificado)
winds = []
wave_heights = []

with open('wave_heights.txt', 'r') as f:
    lines = f.readlines()

i = 0
while i < len(lines):
    if lines[i].startswith('Velocidade'):
        wind = float(lines[i].split(':')[1].strip())
        heights = []
        i += 1
        while i < len(lines) and lines[i].strip() and not lines[i].startswith('Velocidade'):
            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('Velocidade do vento (m/s)')
plt.ylabel('Altura significativa (m)')
plt.title('Altura de onda vs velocidade do vento')
plt.grid(True)
plt.savefig('wave_heights.png')
EOF

python plot_waves.py

Referências

Ver também