#!/bin/bash

BASE_DIR=/opt/

##### DOWNLOAD DATA #####
mkdir -p $BASE_DIR/xdata && cd $BASE_DIR/xdata

wget -c -O endfb71.tar.xz https://anl.box.com/shared/static/9igk353zpy8fn9ttvtrqgzvw1vtejoz6.xz
tar -xf endfb71.tar.xz

wget -c -O endfb80.tar.xz https://anl.box.com/shared/static/uhbxlrx7hvxqw27psymfbhi7bx7s6u6a.xz
tar -xf endfb80.tar.xz

wget -c -O jeff33.tar.xz https://anl.box.com/shared/static/4jwkvrr9pxlruuihcrgti75zde6g7bum.xz
tar -xf jeff33.tar.xz

wget -c -O lib80x.tar.xz https://anl.box.com/shared/static/nd7p4jherolkx4b1rfaw5uqp58nxtstr.xz
tar -xf lib80x.tar.xz

wget -c -O fendl32.tar.xz https://anl.box.com/shared/static/3cb7jetw7tmxaw6nvn77x6c578jnm2ey.xz
tar -xf fendl32.tar.xz

wget -c -O endfb-vii.1-hdf5/chain_endfb71_pwr.xml https://anl.box.com/shared/static/os1u896bwsbopurpgas72bi6aij2zzdc.xml
wget -c -O endfb-vii.1-hdf5/chain_endfb71_sfr.xml https://anl.box.com/shared/static/9058zje1gm0ekd93hja542su50pccvj0.xml

wget -c -O endfb-viii.0-hdf5/chain_endfb80_pwr.xml  https://anl.box.com/shared/static/nyezmyuofd4eqt6wzd626lqth7wvpprr.xml
wget -c -O endfb-viii.0-hdf5/chain_endfb80_sfr.xml https://anl.box.com/shared/static/x3kp739hr5upmeqpbwx9zk9ep04fnmtg.xml

mkdir casl_deplete
wget -c -O casl_deplete/chain_casl_pwr.xml https://anl.box.com/shared/static/3nvnasacm2b56716oh5hyndxdyauh5gs.xml
wget -c -O casl_deplete/chain_casl_sfr.xml https://anl.box.com/shared/static/9fqbq87j0tx4m6vfl06pl4ccc0hwamg9.xml

#########################

module load gcc/10.2.0
module load openmpi/4.1.4
module load python/miniconda23.5.2
source /share/apps/python/miniconda23.5.2/etc/profile.d/conda.sh
conda info --envs
conda create -n openmc-env
conda activate openmc-env
conda install -c conda-forge openmc (nodagmc_nompi_py311h86d942f_0)
conda list
conda search openmc
conda search openmc --channel conda-forge
echo $OPENMC_CROSS_SECTIONS
python --version

## ADD %env OPENMC_CROSS_SECTIONS /opt/xdata/endfb-vii.1-hdf5/cross_sections.xml
##     to the top of any Notebook files you use

openmc -g -n 1000000 -s 32 -t -e problem



########## INSTALL OPENMC FROM SOURCE ################

module load gcc/8.1.0 openmpi/4.1.4 cmake/3.26.3 git/2.42.0 python/3.11.5

git clone --recurse-submodules https://github.com/openmc-dev/openmc.git

cd openmc
git checkout v0.13.3

mkdir build && cd build

HDF5_ROOT=/share/apps/hdf5-withmpi/gcc/8.1.0/openmpi/4.1.4 \
cmake .. -DOPENMC_USE_OPENMP=on -DOPENMC_USE_MPI=on -DHDF5_PREFER_PARALLEL=on \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/openmc

make -j24
make -j24 install

cd ..
MPICC=${MPI_ROOT}/bin/mpicc pip3 install mpi4py

CC=/share/apps/openmpi/4.1.4/gcc/8.1.0/bin/mpicc HDF5_MPI=ON \
HDF5_DIR=/share/apps/hdf5-withmpi/gcc/8.1.0/openmpi/4.1.4 \
pip3 install --no-binary=h5py h5py

PATH=${HOME}/openmc/bin:${PATH}
PATH=${PATH}/.local/bin:${PATH}
export PATH

pip3 install .
