Skip to content

Instantly share code, notes, and snippets.

@pshriwise
Created August 18, 2022 04:37
Show Gist options
  • Save pshriwise/c852bf9f1e9212bc715522369333f0fa to your computer and use it in GitHub Desktop.
Save pshriwise/c852bf9f1e9212bc715522369333f0fa to your computer and use it in GitHub Desktop.
Script for building Cardinal & Aurora with same MOOSE installation. All dependencies use the HDF5 version from MOOSE
#!/bin/bash
# stop script on returned error code
set -e
# SCRIPT PARAMETERS
topdir=$HOME/aurora_build
compile_cores=20
# GLOBAL VARS
REBUILD_ALL="NO"
### HELPER FUNCTIONS ###
# Function with double-check before removing directories
cautious_rm() {
while true; do
read -p "Okay to remove $@? (y/n) " yn
case $yn in
[Yy]* ) rm -rf $@; break;;
[Nn]* ) echo "Skipping removal of $@"; break;;
* ) echo "Please answer yes or no.";;
esac
done
}
# Function to check whether or not the
# build directory should be entirely cleaned out
check_clean () {
if [ -d $1 ]; then
while true; do
read -p "Clear out old build directory ("$1")? (y/n) " yn
case $yn in
[Yy]* ) cautious_rm $1; mkdir -p $1; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
}
# Function to check whether all packages should be rebuilt.
# Sets global `REBUILD_ALL` variable.
check_rebuild_all() {
while true; do
read -p "Rebuild all packages? (y/n) " yn
case $yn in
[Yy]* ) REBUILD_ALL="YES"; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
}
# Function to check for rebuild of a particular package
# Args: <package_directory> <package_name>
# Returns: 1 if rebuild, 1 if not
check_rebuild() {
# if all packages are being rebuilt, skip the query
# and remove the package directory for rebuild
if [ "$REBUILD_ALL" = "YES" ]; then
if [ -d $1 ]; then cautious_rm $1; fi
return 0
fi
# if the package directory exists, check to
# see if it should be removed and rebuilt
if [ -d $1 ]; then
while true; do
read -p "Rebuild "$2"? (y/n) " yn
case $yn in
[Yy]* ) cautious_rm $1; return 0; break;;
[Nn]* ) return 1; break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
return 0
}
### START OF REAL WORK ###
# check whether or not all packages
# should be rebuilt
export MOOSE_JOBS=$compile_cores
# check w/ user if all packages should be rebuilt
check_rebuild_all
# check if the build dir should be cleaned out entirely
check_clean $topdir
# create build dir if needed
if [ ! -d $topdir ]; then
mkdir -p $topdir
fi
# create install location for aurora deps if needed
if [ ! -d $topdir/opt ]; then
mkdir $topdir/opt
fi
# export variables relevant to MOOSE build
echo "export MPICH_FC=gfortran" >> $topdir/env.sh
echo "export CC=mpicc" >> $topdir/env.sh
echo "export CXX=mpicxx" >> $topdir/env.sh
echo "export FC=mpif90" >> $topdir/env.sh
echo "export NEKRS_HOME=$topdir/cardinal/install" >> $topdir/env.sh
echo "export MOOSE_DIR=$topdir/cardinal/contrib/moose/" >> $topdir/env.sh
source $topdir/env.sh
# build MOOSE via Cardinal's repo
rebuild_cardinal=1
if check_rebuild $topdir/cardinal "MOOSE/Cardinal"; then
rebuild_cardinal=0
cd $topdir
git clone https://github.com/neams-th-coe/cardinal
cd $topdir/cardinal
./scripts/get-dependencies.sh
unset HDF5_ROOT
# build petsc
cd $topdir/cardinal/contrib/moose
./scripts/update_and_rebuild_petsc.sh
#build libmesh
./scripts/update_and_rebuild_libmesh.sh
fi
# set HDF5 location for remainder of script
echo "export HDF5_ROOT=$topdir/cardinal/contrib/moose/petsc/arch-moose" >> $topdir/env.sh
source $topdir/env.sh
# set PETSC location
echo "export PETSC_DIR=$topdir/cardinal/contrib/moost/petsc/" $topdir/env.sh
source $topdir/env.sh
# build cardinal if needed, the OpenMC built with this should use the HDF5 from PETSC
if $rebuild_cardinal; then
# build cardinal
cd $topdir/cardinal
make -j$compile_cores
fi
# build MOAB
if check_rebuild $topdir/moab "moab"; then
cd $topdir
git clone https://bitbucket.org/fathomteam/moab
cd moab
# need to use this version so autoreconf works
git checkout 5.4.0
autoreconf -fi
mkdir bld
cd bld
../configure --prefix=$topdir/opt \
--enable-shared \
--enable-optimize \
--disable-debug \
--with-hdf5=$HDF5_ROOT
make -j $compile_cores
make check
make install
fi
# TODO: shouldn't need this
# echo "export LD_LIBRARY_PATH=$HDF5_ROOT/lib:$LD_LIBRARY_PATH" >> $topdir/env.sh
# source $topdir/env.sh
# build Embree
if check_rebuild $topdir/embree "Embree"; then
cd $topdir
git clone https://github.com/embree/embree.git
cd embree
git checkout v3.6.1
mkdir bld
cd bld
cmake .. \
-DCMAKE_INSTALL_PREFIX=$topdir/opt \
-DCMAKE_CXX_COMPILER=$CXX \
-DCMAKE_C_COMPILER=$CC \
-DEMBREE_TASKING_SYSTEM=INTERNAL \
-DEMBREE_ISPC_SUPPORT=0 \
-DEMBREE_TUTORIALS=OFF
make -j $compile_cores
make install
fi
# build DoubleDown
if check_rebuild $topdir/double-down "Double-Down"; then
cd $topdir
git clone https://github.com/pshriwise/double-down
cd double-down
mkdir bld
cd bld
cmake .. \
-DCMAKE_INSTALL_PREFIX=$topdir/opt \
-DMOAB_DIR=/home/moab \
-DEMBREE_DIR=$topdir/opt
make -j $compile_cores
make install
fi
# build DAGMC
if check_rebuild $topdir/dagmc "DAGMC"; then
cd $topdir
git clone https://github.com/svalinn/dagmc
cd dagmc
git checkout develop
mkdir bld
cd bld
cmake .. \
-DCMAKE_INSTALL_PREFIX=$topdir/opt \
-DMOAB_DIR=$topdir/opt \
-DDOUBLE_DOWN=on \
-DDOUBLE_DOWN_DIR=$topdir/opt/lib/cmake/dd \
-DBUILD_TALLY=ON
make -j $compile_cores
# make test
make install
fi
# build OpenMC
if check_rebuild $topdir/openmc "OpenMC"; then
cd $topdir
git clone https://github.com/openmc-dev/openmc.git
cd openmc
git checkout develop
mkdir bld
cd bld
cmake .. \
-DCMAKE_INSTALL_PREFIX=$topdir/opt \
-DCMAKE_PREFIX_PATH=$topdir/opt \
-DCMAKE_BUILD_TYPE=Release \
-DOPENMC_USE_DAGMC=on \
-DOPENMC_USE_MPI=on \
-DDAGMC_DIR=/PATH-TO-DAGMC/
make -j $compile_cores
make -j $compile_cores install
fi
echo "export PATH=$topdir/opt/bin:$PATH" >> $topdir/env.sh
source $topdir/env.sh
# build Aurora
if check_rebuild $topdir/aurora "Aurora"; then
cd $topdir
git clone https://github.com/aurora-multiphysics/aurora
cd aurora/openmc/
make -j $compile_cores
cd unit
make -j $compile_cores
cd ../../
make -j $compile_cores
cd unit
make -j $compile_cores
cd $topdir/aurora/data
tar xvf endfb71_hdf5.tgz
fi
# OpenMC cross sections for Aurora testing
echo "export OPENMC_CROSS_SECTIONS=$topdir/aurora/data/endfb71_hdf5/cross_sections.xml" >> $topdir/env.sh
source $topdir/env.sh
# MOOSE python module for testing
echo "export PYTHONPATH=$topdir/cardinal/contrib/moose/python:$PYTHONPATH" >> $topdir/env.sh
source $topdir/env.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment