-
Notifications
You must be signed in to change notification settings - Fork 10
/
compileWaves2FoamInOpenFOAM2312
executable file
·332 lines (260 loc) · 11.4 KB
/
compileWaves2FoamInOpenFOAM2312
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash
# Run from geometricVofExt top-level directory only
cd "${0%/*}" || exit
wmake -check-dir "$WM_PROJECT_USER_DIR/modules/geometricVofExt" 2>/dev/null || {
echo "Error (${0##*/}) : not located in \$WM_PROJECT_USER_DIR/modules/geometricVofExt"
echo " Check your OpenFOAM environment and installation"
exit 1
}
findSourceDir()
{
local package subdir optRelative
case "$1" in
(-abs*)
optRelative=false
shift
;;
(-rel*)
optRelative=true
shift
;;
esac
for package in "$@"
do
subdir="$(basename "$package" | tr '[:upper:]' '[:lower:]' |\
sed -ne 's#^\([0-9]*[a-z]*\).*#\1#p')"
for check in \
"$package" \
"$subdir/$package" \
"sources/$package" \
"sources/$subdir/$package" \
;
do
if [ -d "$sourceBASE/$check" ]
then
echo "Found sources: $check" 1>&2
if [ "${optRelative:-false}" = true ]
then
echo "$check"
else
echo "$sourceBASE/$check"
fi
return 0
fi
done
done
# Fallback. Report if missing (unless none or system)
case "${1##*-}" in
(none | system)
;;
(*)
echo "Did not find ... $@" 1>&2
esac
echo "$sourceBASE/${1:-missing-package-name}"
}
#------------------------------------------------------------------------------
echo
echo "*********** Compile waves2Foam in OpenFOAM v2312 (optional) ************"
echo
#------------------------------------------------------------------------------
# Compile GSL library
echo "--------------------"
echo " Compile GSL"
echo "--------------------"
echo ""
# Download and unpack GSL
cd $WM_THIRD_PARTY_DIR
gsl_version=gsl-2.7.1
GSL_PACKAGE=${gsl_version}
[ -f ${gsl_version}.tar.gz ] || wget -nv https://ftp.gnu.org/gnu/gsl/${gsl_version}.tar.gz --no-check-certificate
[ -d ${gsl_version} ] || tar -xzf ${gsl_version}.tar.gz
# Prepare
sourceBASE="$WM_THIRD_PARTY_DIR"
buildBASE="$WM_THIRD_PARTY_DIR/build/$WM_ARCH$WM_COMPILER"
installBASE="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER"
buildBASE="$(dirname "$buildBASE")/$WM_ARCH$WM_COMPILER_ARCH"
installBASE="$(dirname "$installBASE")/$WM_ARCH$WM_COMPILER_ARCH"
GSL_SOURCE="$(findSourceDir "$GSL_PACKAGE")"
GSL_PACKAGE="$(basename "$GSL_PACKAGE")"
GSL_PREFIX="$installBASE/$GSL_PACKAGE"
optArch=64
# Build
if [ -d "$GSL_PREFIX" ]; then
echo "Already built: $GSL_PREFIX"
else
echo "Starting build: $GSL_PACKAGE"
echo
(
PKG_SOURCE="$GSL_SOURCE"
PKG_PREFIX="$GSL_PREFIX"
PKG_BUILD="$buildBASE/$GSL_PACKAGE"
cd "$PKG_SOURCE" || exit
make distclean 2>/dev/null || true
rm -rf "$PKG_BUILD"
mkdir -p "$PKG_BUILD"
cd "$PKG_BUILD" && set -x && \
"$PKG_SOURCE"/configure ABI="$optArch" \
--prefix="$PKG_PREFIX" \
--libdir="$PKG_PREFIX/lib$WM_COMPILER_LIB_ARCH" \
--enable-cxx \
&& set +x \
&& make -j $WM_NCOMPPROCS \
&& make install \
&& echo "Built: $GSL_PACKAGE"
) || {
echo "Error building: $GSL_PACKAGE"
exit 1
}
fi
# Modify $WM_PROJECT_DIR/etc/config.sh/compiler
[ -f $WM_PROJECT_DIR/etc/config.sh/compiler_backup ] || cp $WM_PROJECT_DIR/etc/config.sh/compiler $WM_PROJECT_DIR/etc/config.sh/compiler_backup
awk '
BEGIN {
in_section = 0
}
/case "\$WM_COMPILER_TYPE" in/ {
print "" $0
print "system)"
print " gmp_version=gmp-6.2.1"
print " mpfr_version=mpfr-4.1.0"
print " mpc_version=mpc-1.2.1"
print " gsl_version=gsl-2.7.1 # used by waves2Foam"
print " ;;"
in_section = 1
next
}
/ThirdParty)/ && in_section {
print
in_section = 0
next
}
!in_section {
print
}
' $WM_PROJECT_DIR/etc/config.sh/compiler_backup > $WM_PROJECT_DIR/etc/config.sh/compiler
# Modify $WM_PROJECT_DIR/etc/config.sh/settings
[ -f $WM_PROJECT_DIR/etc/config.sh/settings_backup ] || cp $WM_PROJECT_DIR/etc/config.sh/settings $WM_PROJECT_DIR/etc/config.sh/settings_backup
awk '
BEGIN {
in_section = 0
}
/case "\$WM_COMPILER_TYPE-\$WM_COMPILER" in/ {
print "" $0
print "system-Gcc)"
print " gmpDir=\"$archDir/${gmp_version}\""
print " mpfrDir=\"$archDir/${mpfr_version}\""
print " mpcDir=\"$archDir/${mpc_version}\""
print " gslDir=\"$archDir/${gsl_version}\" # used by waves2Foam"
print " _foamAddLibAuto \"$gmpDir\" && export GMP_ARCH_PATH=\"$gmpDir\""
print " _foamAddLibAuto \"$mpfrDir\" && export MPFR_ARCH_PATH=\"$mpfrDir\""
print " _foamAddLibAuto \"$mpcDir\""
print " _foamAddLibAuto \"$gslDir\""
print " ;;"
in_section = 1
next
}
/ThirdParty-Gcc\*)/ && in_section {
print
in_section = 0
next
}
!in_section {
print
}
' $WM_PROJECT_DIR/etc/config.sh/settings_backup > $WM_PROJECT_DIR/etc/config.sh/settings
# Renew env of OpenFOAM
source $WM_PROJECT_DIR/etc/bashrc
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Go to $WM_PROJECT_USER_DIR/applications/utilities and download waves2Foam
echo ""
echo "------------------------------------------"
echo " Download source code of waves2Foam"
echo "------------------------------------------"
echo ""
cd $WM_PROJECT_USER_DIR/applications/utilities
[ -d waves2Foam ] || git clone https://github.com/ogoe/waves2Foam.git
# Modify settings of LAPACK, SPARSKIT and OceanWave3D
echo ""
echo "------------------------------------------"
echo " Modify ThirdParty settings"
echo "------------------------------------------"
echo ""
echo " >> Modifiy waves2Foam/ThirdParty/settings/lapackSettings/make.inc"
[ -f $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/lapackSettings/make.inc_backup ] || cp $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/lapackSettings/make.inc $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/lapackSettings/make.inc_backup
sed -i 's/FORTRAN = gfortran -fimplicit-none -shared -fPIC/FORTRAN = gfortran -fimplicit-none -shared -fPIC -fallow-argument-mismatch/g' $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/lapackSettings/make.inc
echo " >> Modifiy waves2Foam/ThirdParty/settings/sparseSettings/makefile"
[ -f $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/sparseSettings/makefile_backup ] || cp $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/sparseSettings/makefile $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/sparseSettings/makefile_backup
sed -i 's/OPT = -c -g -shared -fPIC/OPT = -c -g -shared -fPIC -fallow-argument-mismatch/g' $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/sparseSettings/makefile
echo " >> Modifiy waves2Foam/ThirdParty/settings/oceanWave3DSettings/common.mk"
[ -f $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/oceanWave3DSettings/common.mk_backup ] || cp $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/oceanWave3DSettings/common.mk $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/oceanWave3DSettings/common.mk_backup
sed -i 's/DBFLAGS = -pg -g -O0 -fPIC -fbounds-check -ffpe-trap=invalid,zero,overflow -ffree-line-length-none /DBFLAGS = -pg -g -O0 -fPIC -fbounds-check -ffpe-trap=invalid,zero,overflow -ffree-line-length-none -fallow-argument-mismatch/g' $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/oceanWave3DSettings/common.mk
sed -i 's/OPTFLAGS = -O3 -fPIC -ffpe-trap=invalid,zero,overflow -ffree-line-length-none -fstack-protector-all/OPTFLAGS = -O3 -fPIC -ffpe-trap=invalid,zero,overflow -ffree-line-length-none -fstack-protector-all -fallow-argument-mismatch/g' $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/oceanWave3DSettings/common.mk
sed -i 's/SHLIBFLAGS = -shared -O2 -fPIC -fbounds-check -ffpe-trap=invalid,zero,overflow -ffree-line-length-none -fstack-protector-all/SHLIBFLAGS = -shared -O2 -fPIC -fbounds-check -ffpe-trap=invalid,zero,overflow -ffree-line-length-none -fstack-protector-all -fallow-argument-mismatch/g' $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/ThirdParty/settings/oceanWave3DSettings/common.mk
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Compile waves2Foam/ThirdParty
echo ""
echo "------------------------------------------"
echo " Compile ThirdParty"
echo "------------------------------------------"
echo ""
echo " >> Modifiy bin/bashrc.org"
sed -i "s|export WAVES_GSL_INCLUDE=\/usr\/include|export WAVES_GSL_INCLUDE=$GSL_PREFIX\/include|g" $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/bin/bashrc.org
sed -i "s|export WAVES_GSL_LIB=\/usr\/lib64|export WAVES_GSL_LIB=$GSL_PREFIX\/lib64|g" $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/bin/bashrc.org
cd waves2Foam && . ./bin/bashrc.org
( cd ThirdParty; ./Allwmake )
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Compile waves2Foam/src
echo ""
echo "------------------------------------------"
echo " Compile library"
echo "------------------------------------------"
echo ""
cd src
[ -d waves2FoamSampling2312 ] || cp -r waves2FoamSampling2206 waves2FoamSampling2312
sed -i 's/globalIndices_\[seti\].reset(coords.size(), globalIndex::gatherOnly{});/globalIndices_\[seti\].reset(globalIndex::gatherOnly{}, coords.size());/g' $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2FoamSampling2312/surfaceElevation/sampledSurfaceElevation.C
[ -f Allwmake_backup ] || cp Allwmake Allwmake_backup
awk '
BEGIN {
in_section = 0
}
/ elif [ "$WM_PROJECT_VERSION_NUMBER" -lt "2206" ]/ {
print "" $0
print " then"
print " (cd waves2FoamSampling1712 ; wmake libso)"
print " elif [ \"$WM_PROJECT_VERSION_NUMBER\" -lt \"2312\" ]"
print " then"
print " (cd waves2FoamSampling2206 ; wmake libso)"
print " else"
print " (cd waves2FoamSampling2312 ; wmake libso)"
in_section = 1
next
}
/fi/ && in_section {
print
in_section = 0
next
}
!in_section {
print
}
' Allwmake_backup > Allwmake
./Allwmake
cd ../
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Compile waves2Foam
echo ""
echo "-----------------------------------------------"
echo " Compile solvers and remaining utilities"
echo "-----------------------------------------------"
echo ""
[ -d ./applications/solvers/solvers2312_PLUS ] || cp -r ./applications/solvers/solvers2206_PLUS ./applications/solvers/solvers2312_PLUS
./Allwmake
#------------------------------------------------------------------------------
echo
echo "********************************* Done *********************************"
echo
#------------------------------------------------------------------------------