Skip to content

Commit 1dc2c14

Browse files
committed
Add swan src code and docker files
1 parent 1f14736 commit 1dc2c14

File tree

7 files changed

+177
-0
lines changed

7 files changed

+177
-0
lines changed

docker/.env

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SWAN_VERSION=4141
2+
MPICH_VERSION=3.3.1
3+
HDF5_MAJOR_VERSION=1.13
4+
HDF5_MINOR_VERSION=3
5+
NETCDF_C_VERSION=4.9.0
6+
NETCDF_FORTRAN_VERSION=4.6.0

docker/compose.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
services:
2+
3+
swansrc:
4+
image: oceanum/swan:${SWAN_VERSION}
5+
build:
6+
context: ./swan
7+
dockerfile: Dockerfile
8+
tags:
9+
- oceanum/swan:latest
10+
args:
11+
SWAN_VERSION: $SWAN_VERSION
12+
MPICH_VERSION: $MPICH_VERSION
13+
HDF5_MAJOR_VERSION: $HDF5_MAJOR_VERSION
14+
HDF5_MINOR_VERSION: $HDF5_MINOR_VERSION
15+
NETCDF_C_VERSION: $NETCDF_C_VERSION
16+
NETCDF_FORTRAN_VERSION: $NETCDF_FORTRAN_VERSION

docker/swan/Dockerfile

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
FROM ubuntu:20.04
2+
3+
LABEL maintainer "CSIRO <[email protected]>"
4+
5+
ARG MPICH_VERSION
6+
ARG HDF5_MAJOR_VERSION
7+
ARG HDF5_MINOR_VERSION
8+
ARG NETCDF_C_VERSION
9+
ARG NETCDF_FORTRAN_VERSION
10+
ARG SWAN_VERSION
11+
12+
ENV SWAN_VERSION=$SWAN_VERSION
13+
ENV HDF5_VERSION=$HDF5_MAJOR_VERSION.$HDF5_MINOR_VERSION
14+
ENV BUILD_DIR=/tmp/build
15+
ENV INSTALL_DIR=/usr/local
16+
ENV DEBIAN_FRONTEND noninteractive
17+
18+
RUN echo "-------------------- Install system libraries --------------------" & \
19+
apt update && apt install -y --no-install-recommends \
20+
autoconf \
21+
automake \
22+
ca-certificates \
23+
cmake \
24+
make \
25+
gcc \
26+
gfortran \
27+
git \
28+
g++ \
29+
ninja-build \
30+
patch \
31+
wget \
32+
zlib1g-dev && \
33+
apt clean && \
34+
rm -rf /var/lib/apt/lists/*
35+
36+
37+
#==========================================
38+
# Model build dependencies
39+
#==========================================
40+
41+
WORKDIR $BUILD_DIR
42+
RUN echo "-------------------- Build MPICH --------------------" && \
43+
wget http://www.mpich.org/static/downloads/$MPICH_VERSION/mpich-$MPICH_VERSION.tar.gz && \
44+
tar zxvf mpich-$MPICH_VERSION.tar.gz && \
45+
cd $BUILD_DIR/mpich-$MPICH_VERSION && \
46+
./configure --prefix=$INSTALL_DIR --enable-shared=no --enable-static=yes && \
47+
make && \
48+
make install && \
49+
ldconfig $INSTALL_DIR/lib && \
50+
cd .. && \
51+
rm -rf $BUILD_DIR/mpich-$MPICH_VERSION
52+
53+
WORKDIR $BUILD_DIR
54+
RUN echo "-------------------- Build HDF5 --------------------" && \
55+
wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-$HDF5_MAJOR_VERSION/hdf5-$HDF5_VERSION/src/hdf5-$HDF5_VERSION.tar.gz && \
56+
tar zxvf hdf5-$HDF5_VERSION.tar.gz && \
57+
cd $BUILD_DIR/hdf5-$HDF5_VERSION && \
58+
./configure --prefix=$INSTALL_DIR --enable-fortran --enable-cxx --enable-hl && \
59+
make && \
60+
make install && \
61+
ldconfig $INSTALL_DIR/lib && \
62+
cd .. && \
63+
rm -rf $BUILD_DIR/hdf5-$HDF5_VERSION
64+
65+
WORKDIR $BUILD_DIR
66+
RUN echo "-------------------- Build NETCDF4-C --------------------" && \
67+
wget https://downloads.unidata.ucar.edu/netcdf-c/$NETCDF_C_VERSION/netcdf-c-$NETCDF_C_VERSION.tar.gz && \
68+
tar zxvf netcdf-c-$NETCDF_C_VERSION.tar.gz && \
69+
cd $BUILD_DIR/netcdf-c-$NETCDF_C_VERSION && \
70+
./configure --prefix=$INSTALL_DIR --disable-dap --enable-shared --enable-static --disable-v2 && \
71+
make && \
72+
make install && \
73+
nc-config --all && \
74+
ldconfig $INSTALL_DIR/lib && \
75+
cd .. && \
76+
rm -rf $BUILD_DIR/netcdf-c-$NETCDF_C_VERSION
77+
78+
WORKDIR $BUILD_DIR
79+
RUN echo "-------------------- Build NETCDF4-FORTRAN --------------------" && \
80+
wget https://downloads.unidata.ucar.edu/netcdf-fortran/$NETCDF_FORTRAN_VERSION/netcdf-fortran-$NETCDF_FORTRAN_VERSION.tar.gz && \
81+
tar zxvf netcdf-fortran-$NETCDF_FORTRAN_VERSION.tar.gz && \
82+
cd $BUILD_DIR/netcdf-fortran-$NETCDF_FORTRAN_VERSION && \
83+
./configure --prefix=$INSTALL_DIR --enable-shared --enable-static && \
84+
make && \
85+
make install && \
86+
nf-config --all && \
87+
ldconfig $INSTALL_DIR/lib && \
88+
cd .. && \
89+
rm -rf $BUILD_DIR/netcdf-fortran-$NETCDF_FORTRAN_VERSION
90+
91+
92+
#==========================================
93+
# Model build
94+
#==========================================
95+
# cmake configuration files are provided in the new swan gitlab but tags / releases
96+
# are currently not available in that repo. Previous releases of the model are also
97+
# not available in sourceforge. Hense this will use the cmake configs from gitlab to
98+
# define the build environment but wil use tagged versions of the source code copied
99+
# from sourceforge and stored in rompy so versions can be tracked.
100+
101+
WORKDIR $BUILD_DIR
102+
ADD src-$SWAN_VERSION/swan$SWAN_VERSION.tar.gz .
103+
RUN echo "-------------------- Build SWAN --------------------" && \
104+
git clone --depth 1 https://gitlab.tudelft.nl/citg/wavemodels/swan.git && \
105+
cd swan && \
106+
mv src src-git && \
107+
mv ../swan$SWAN_VERSION src && \
108+
cp -r src-git/hcat src-git/CMakeLists.txt src-git/*.cmake src/ && \
109+
mkdir build && \
110+
cd build && \
111+
cmake .. -GNinja -DNETCDF=ON -DMPI=ON && \
112+
cmake --build . && \
113+
cmake --install . --prefix $INSTALL_DIR && \
114+
cd ../../ && \
115+
rm -rf $BUILD_DIR/swan
116+
117+
118+
#==========================================
119+
# Test model with mpi and netcdf output
120+
#==========================================
121+
ADD tests/refrac.tar.gz $BUILD_DIR
122+
WORKDIR $BUILD_DIR/refrac
123+
RUN ln -s a11refr.swn INPUT && \
124+
sed -i 's/a11ref01.spc/a11ref01.nc/g' INPUT && \
125+
mpiexec -n 2 swan.exe && \
126+
ncdump -h a11ref01.nc && \
127+
cd .. && \
128+
rm -rf $BUILD_DIR/refrac
129+
130+
131+
WORKDIR /home
132+
RUN rm -rf $BUILD_DIR

docker/swan/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SWAN model docker
2+
3+
4+
This image builds the [SWAN wave model](https://swanmodel.sourceforge.io/) with netcdf and mpich support using gfortran. The image uses the cmake configuration files available in the new [gitlab repository](https://gitlab.tudelft.nl/citg/wavemodels/swan) but installs a local copy of the source code given previous releases are currently not available in either sourceforge or gitlab swan repositories.
5+
6+
The following structure is expected in order to build an specific version of SWAN, for instance version 4141:
7+
8+
src-4141
9+
10+
├── `swan4141.tar.gz`
11+
12+
├── `patch41.41.A`
13+
14+
├── `patch41.41.B`
15+
16+
└── ...
17+
18+
where `swan4141.tar.gz` is the tarball for this release downloaded from sourceforge and the patch files `A`, `B`, etc are the patch files to apply (patching is currently not implemented in the docker build).
19+
20+
SWAN is instaled inside the docker at */usr/local/bin/swan.exe*.
21+
22+
Versions for SWAN and some other building tools are specified in the *.env* file next to *compose.yaml*.

docker/swan/src-4141/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Source code and patch files for SWAN version 41.41

docker/swan/src-4141/swan4141.tar.gz

902 KB
Binary file not shown.

docker/swan/tests/refrac.tar.gz

24.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)