4SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
10PETSC_PREFIX="${HOME}/software"
11PETSC_ARCH="arch-linux-c-debug"
16Usage: scripts/bootstrap_install.sh [options]
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.
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.
35 scripts/bootstrap_install.sh
36 scripts/bootstrap_install.sh --install-petsc
41 printf '[INFO] %s\n' "$*"
45 printf '[ERROR] %s\n' "$*" >&2
50 command -v "$1" >/dev/null 2>&1 || die "Required command '$1' is missing."
53while [[ $# -gt 0 ]]; do
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" ;;
66if [[ -z "${PYTHON_BIN}" ]]; then
67 if command -v python3.10 >/dev/null 2>&1; then
68 PYTHON_BIN="python3.10"
74require_cmd "${PYTHON_BIN}"
77if [[ "${SKIP_SYSTEM_DEPS}" -eq 0 ]]; then
79 log "Installing base system dependencies (Debian/Ubuntu)..."
81 sudo apt-get install -y \
82 build-essential gfortran mpich git make pkg-config \
83 libx11-dev python3 python3-pip python3-venv
86log "Installing Python dependencies with ${PYTHON_BIN}..."
87"${PYTHON_BIN}" -m pip install --upgrade pip
88"${PYTHON_BIN}" -m pip install pyyaml numpy
90if [[ "${INSTALL_PETSC}" -eq 1 ]]; then
92 PETSC_SRC="${PETSC_PREFIX}/petsc-${PETSC_VERSION}"
93 mkdir -p "${PETSC_PREFIX}"
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}"
99 log "Using existing PETSc source at ${PETSC_SRC}."
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
112 export PETSC_DIR="${PETSC_SRC}"
113 export PETSC_ARCH="${PETSC_ARCH}"
116if [[ -z "${PETSC_DIR:-}" || -z "${PETSC_ARCH:-}" ]]; then
117 die "PETSC_DIR and PETSC_ARCH must be set (or use --install-petsc)."
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}"
125log "Verified PETSc config and DMSwarm header."
127log "Building PICurv binaries..."
129"${PYTHON_BIN}" ./scripts/picurv build
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"
135log "Bootstrap complete."
136log "Run: ./bin/picurv --help"