-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_cantera.sh
291 lines (234 loc) · 8.92 KB
/
get_cantera.sh
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
#!/usr/bin/env bash
###############################################################################
# Download paths for Sundials and Cantera
###############################################################################
cantera_page="https://github.com/Cantera/cantera.git"
sundials_page="https://computation.llnl.gov/projects/sundials/download"
###############################################################################
# Libraries versions and files
###############################################################################
cantera_version="2.4.0"
sundials_version="2.7.0"
sundials_file="sundials-${sundials_version}.tar.gz"
###############################################################################
# Absolute path definitions
###############################################################################
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
makefile_in="${DIR}/Makefile.in"
external_dir="${DIR}/external"
cantera_dir="${external_dir}/cantera"
sundials_dir="${cantera_dir}/sundials"
###############################################################################
# Retrieve and compile Sundials
#
# FOR 3.1.0 IN THE FUTURE!
# cmake \
# -DCMAKE_INSTALL_PREFIX="$1" \
# -DSUNDIALS_INDEX_TYPE="int32_t" \
# -DBLAS_ENABLE="ON" \
# -DLAPACK_ENABLE="ON" \
# -DBLAS_LIBRARIES="${blas}" \
# -DLAPACK_LIBRARIES="${blas}" \
# -DCMAKE_C_FLAGS="-fPIC -O3" \
# "../sundials-${sundials_version}"
###############################################################################
function get_sundials()
{
prefix=$1
if [[ -f "${prefix}/lib/libsundials_ida.a" ]]; then
echo "************************************************************"
echo "Found Sundials already installed"
return
fi
echo "****************************************************************"
echo "Trying to retrieve Sundials ${sundials_file}"
if [[ ! -f "${sundials_file}" ]]; then
wget "${sundials_page}/${sundials_file}"
tar xzf "${sundials_file}"
fi
echo "****************************************************************"
echo "Moving to Sundials 'builddir' ${sundials_dir}"
if [[ -d "${sundials_dir}" ]]; then
rm -rf "${sundials_dir}"
fi
mkdir "${sundials_dir}"
cd "${sundials_dir}"
echo "****************************************************************"
echo "Configuring Sundials for $2"
if [[ "$2" == "Nix" ]]; then
blas_toggle="ON"
blas=$(ldconfig -p | grep openblas | tail -1 | awk '{ print $4 }')
else
blas_toggle="OFF"
blas=""
fi
echo "****************************************************************"
echo "Generating Sundials make files"
# NOTE: examples are incompatible with Cygwin.
cmake \
-DCMAKE_INSTALL_PREFIX="$1" \
-DEXAMPLES_ENABLE="OFF" \
-DLAPACK_ENABLE="${blas_toggle}" \
-DLAPACK_LIBRARIES="${blas}" \
-DCMAKE_C_FLAGS="-fPIC -O3 --std=c99" \
-DBUILD_ARKODE="OFF" \
-DBUILD_KINSOL="OFF" \
-DBUILD_SHARED_LIBRARIES="OFF" \
-DBUILD_STATIC_LIBRARIES="ON" \
"../sundials-${sundials_version}"
echo "****************************************************************"
echo "Building Sundials"
make install;
cd "${cantera_dir}"
}
###############################################################################
# Cygwin specific steps (Linux users must do manually!)
# https://github.com/FPGAwars/apio/issues/143
###############################################################################
function cygwin_helper()
{
export PATH="~/.local/bin:${PATH}"
export SCONS_LIB_DIR="~/.local/lib/python3.6/site-packages/scons-3.0.1"
/usr/bin/pip3 install --upgrade pip
/usr/bin/pip3 install --user scons
/usr/bin/pip3 install --user Cython
/usr/bin/pip3 install --user matplotlib
/usr/bin/pip3 install --user pandas
sed -i "s|#! /usr/bin/env python|#! /usr/bin/env python3|g" ~/.local/bin/scons
}
###############################################################################
# Default build steps
###############################################################################
function header()
{
machine_os=$1
prefix=$2
cxx_flags=$3
echo "****************************************************************"
echo "Running from ${machine_os}"
echo "Installing to ${prefix}"
if [[ "${machine_os}" == "Nix" ]]; then
shared="_shared"
openblas="-lopenblas"
python="python"
else
shared=""
openblas=""
python="python3"
fi
echo "****************************************************************"
echo "Creating ${makefile_in}"
echo "# File generated by get_cantera.sh." > ${makefile_in}
echo "PYTHON := ${python}" >> ${makefile_in}
echo "OPTIONS := ${cxx_flags}" >> ${makefile_in}
echo "BLAS_LAPACK := ${openblas}" >> ${makefile_in}
echo "LIB_SUNDIALS := -L${prefix}/lib -lsundials_ida -lsundials_nvecserial" >> ${makefile_in}
echo "INC_SUNDIALS := -I${prefix}/include" >> ${makefile_in}
echo "LIB_CANTERA := -L${prefix}/lib -lcantera${shared}" >> ${makefile_in}
echo "INC_CANTERA := -I${prefix}/include" >> ${makefile_in}
echo "LIB_SELF := -LCanteraPFR/lib" >> ${makefile_in}
echo "INC_SELF := -ICanteraPFR/include" >> ${makefile_in}
echo "LIBRARIES := \$(LIB_CANTERA) \$(LIB_SUNDIALS) \$(LIB_SELF) \$(BLAS_LAPACK)" >> ${makefile_in}
echo "INCLUDES := \$(INC_CANTERA) \$(INC_SUNDIALS) \$(INC_SELF)" >> ${makefile_in}
echo "****************************************************************"
echo "Appending ~/.bashrc"
echo ${LD_LIBRARY_PATH} | grep -q "${prefix}"
if [[ "$?" != "0" ]]; then
echo "export LD_LIBRARY_PATH=\"${prefix}/lib:\${LD_LIBRARY_PATH}\"" >> ~/.bashrc
else
echo "Already in LD_LIBRARY_PATH: ${prefix}"
fi
echo "source ${prefix}/bin/setup_cantera" >> ~/.bashrc
get_sundials "${prefix}" "${machine_os}"
}
###############################################################################
# Nix build
###############################################################################
function build_on_nix()
{
machine_os=Nix
prefix="${external_dir}/${machine_os}"
cxx_flags="-g -O3 -std=c++11"
header "${machine_os}" "${prefix}" "${cxx_flags}"
scons clean
scons build \
prefix=${prefix} \
python_package="none" \
python3_package="full" \
f90_interface="y" \
googletest="submodule" \
system_eigen="n" \
system_fmt="n" \
system_sundials="y" \
sundials_include="${prefix}/include" \
sundials_libdir="${prefix}/lib" \
blas_lapack_libs="openblas" \
cxx_flags="${cxx_flags}";
}
###############################################################################
# Win build
###############################################################################
function build_on_win()
{
machine_os=Win
prefix="${external_dir}/${machine_os}"
cxx_flags="-g -O3 -std=c++11 -U__STRICT_ANSI__"
header "${machine_os}" "${prefix}" "${cxx_flags}"
cygwin_helper
scons clean
scons build \
prefix=${prefix} \
python_package="none" \
python3_package="full" \
f90_interface="y" \
googletest="submodule" \
system_eigen="n" \
system_fmt="n" \
system_sundials="y" \
sundials_include="${prefix}/include" \
sundials_libdir="${prefix}/lib" \
cxx_flags="${cxx_flags}";
# FIXME path to blas_lapack_libs="openblas" \
}
###############################################################################
# Main install routine
###############################################################################
function get_cantera()
{
uname_out="$(uname -s)"
echo "****************************************************************"
echo "Trying to retrieve Cantera"
if [[ ! -d ${external_dir} ]]; then
mkdir ${external_dir}
fi
cd ${external_dir}
if [[ ! -d ${cantera_dir} ]]; then
git clone --recursive ${cantera_page}
fi
cd ${cantera_dir}
git checkout tags/v${cantera_version}
git submodule update
echo "****************************************************************"
echo "Starting build"
case "${uname_out}" in
Linux*|Darwin*)
build_on_nix;
;;
CYGWIN*|MINGW*)
build_on_win;
;;
*)
echo "Unsupported system: ${uname_out}"
exit -1
esac
scons test;
scons install;
echo "Now run 'source ~/.bashrc' to refresh environment"
}
###############################################################################
# Call main install routine
###############################################################################
get_cantera
###############################################################################
# EOF
###############################################################################