PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
bootstrap_install.sh
Go to the documentation of this file.
1#!/usr/bin/env bash
2set -euo pipefail
3
4SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
6
7INSTALL_PETSC=0
8SKIP_SYSTEM_DEPS=0
9PETSC_VERSION="3.20.3"
10PETSC_PREFIX="${HOME}/software"
11PETSC_ARCH="arch-linux-c-debug"
12PYTHON_BIN=""
13
14usage() {
15 cat <<'EOF'
16Usage: scripts/bootstrap_install.sh [options]
17
18Automates local PICurv setup:
191) installs base system dependencies (Debian/Ubuntu),
202) installs required Python packages,
213) optionally installs PETSc with DMSwarm,
224) verifies PETSc + DMSwarm visibility,
235) builds PICurv binaries.
24
25Options:
26 --install-petsc Build/install PETSc from source.
27 --petsc-version <ver> PETSc version tag (default: 3.20.3).
28 --petsc-prefix <dir> Parent directory for PETSc source/build.
29 --petsc-arch <arch> PETSc arch name (default: arch-linux-c-debug).
30 --python-bin <path> Python interpreter to use.
31 --skip-system-deps Skip apt package installation.
32 -h, --help Show this help.
33
34Examples:
35 scripts/bootstrap_install.sh
36 scripts/bootstrap_install.sh --install-petsc
37EOF
38}
39
40log() {
41 printf '[INFO] %s\n' "$*"
42}
43
44die() {
45 printf '[ERROR] %s\n' "$*" >&2
46 exit 1
47}
48
49require_cmd() {
50 command -v "$1" >/dev/null 2>&1 || die "Required command '$1' is missing."
51}
52
53while [[ $# -gt 0 ]]; do
54 case "$1" in
55 --install-petsc) INSTALL_PETSC=1; shift ;;
56 --skip-system-deps) SKIP_SYSTEM_DEPS=1; shift ;;
57 --petsc-version) PETSC_VERSION="${2:?missing value for --petsc-version}"; shift 2 ;;
58 --petsc-prefix) PETSC_PREFIX="${2:?missing value for --petsc-prefix}"; shift 2 ;;
59 --petsc-arch) PETSC_ARCH="${2:?missing value for --petsc-arch}"; shift 2 ;;
60 --python-bin) PYTHON_BIN="${2:?missing value for --python-bin}"; shift 2 ;;
61 -h|--help) usage; exit 0 ;;
62 *) die "Unknown option: $1" ;;
63 esac
64done
65
66if [[ -z "${PYTHON_BIN}" ]]; then
67 if command -v python3.10 >/dev/null 2>&1; then
68 PYTHON_BIN="python3.10"
69 else
70 PYTHON_BIN="python3"
71 fi
72fi
73
74require_cmd "${PYTHON_BIN}"
75require_cmd git
76
77if [[ "${SKIP_SYSTEM_DEPS}" -eq 0 ]]; then
78 require_cmd apt-get
79 log "Installing base system dependencies (Debian/Ubuntu)..."
80 sudo apt-get update
81 sudo apt-get install -y \
82 build-essential gfortran mpich git make pkg-config \
83 libx11-dev python3 python3-pip python3-venv
84fi
85
86log "Installing Python dependencies with ${PYTHON_BIN}..."
87"${PYTHON_BIN}" -m pip install --upgrade pip
88"${PYTHON_BIN}" -m pip install pyyaml numpy
89
90if [[ "${INSTALL_PETSC}" -eq 1 ]]; then
91 require_cmd mpicc
92 PETSC_SRC="${PETSC_PREFIX}/petsc-${PETSC_VERSION}"
93 mkdir -p "${PETSC_PREFIX}"
94
95 if [[ ! -d "${PETSC_SRC}" ]]; then
96 log "Cloning PETSc v${PETSC_VERSION} into ${PETSC_SRC}..."
97 git clone -b "v${PETSC_VERSION}" https://gitlab.com/petsc/petsc.git "${PETSC_SRC}"
98 else
99 log "Using existing PETSc source at ${PETSC_SRC}."
100 fi
101
102 log "Configuring PETSc with DMSwarm support..."
103 pushd "${PETSC_SRC}" >/dev/null
104 ./configure --PETSC_ARCH="${PETSC_ARCH}" \
105 --with-cc=mpicc --with-cxx=mpicxx --with-fc=mpif90 \
106 --download-fblaslapack --download-metis --download-parmetis \
107 --with-dmswarm=1 --with-debugging=1
108 make all
109 make check
110 popd >/dev/null
111
112 export PETSC_DIR="${PETSC_SRC}"
113 export PETSC_ARCH="${PETSC_ARCH}"
114fi
115
116if [[ -z "${PETSC_DIR:-}" || -z "${PETSC_ARCH:-}" ]]; then
117 die "PETSC_DIR and PETSC_ARCH must be set (or use --install-petsc)."
118fi
119
120PETSC_CONF="${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h"
121PETSC_DMSWARM_HEADER="${PETSC_DIR}/include/petscdmswarm.h"
122[[ -f "${PETSC_CONF}" ]] || die "PETSc config not found: ${PETSC_CONF}"
123[[ -f "${PETSC_DMSWARM_HEADER}" ]] || die "DMSwarm header not found: ${PETSC_DMSWARM_HEADER}"
124
125log "Verified PETSc config and DMSwarm header."
126
127log "Building PICurv binaries..."
128cd "${REPO_ROOT}"
129"${PYTHON_BIN}" ./scripts/picurv build
130
131[[ -x "${REPO_ROOT}/bin/simulator" ]] || die "Missing binary: bin/simulator"
132[[ -x "${REPO_ROOT}/bin/postprocessor" ]] || die "Missing binary: bin/postprocessor"
133[[ -x "${REPO_ROOT}/bin/picurv" ]] || die "Missing binary: bin/picurv"
134
135log "Bootstrap complete."
136log "Run: ./bin/picurv --help"