#!/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 ################

## Dependencies ##
## OpenMC
# sudo apt install g++ cmake libhdf5-dev libpng-dev (mpich libmpich-dev) openmpi-bin libopenmpi-dev git

## DagMC
# sudo apt install libeigen3-dev libhdf5-dev
# cd $HOME/dagmc_bld
# mkdir DAGMC
# cd DAGMC
# git clone https://github.com/svalinn/DAGMC
# cd DAGMC
# git checkout develop
# git submodule update --init
# cd $HOME/dagmc_bld/DAGMC
# ln -s DAGMC src
# mkdir bld
# cd bld
# INSTALL_PATH=$HOME/dagmc_bld/DAGMC
# cmake ../src -DMOAB_DIR=$HOME/dagmc_bld/MOAB \
#              -DBUILD_TALLY=ON \
#              -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH
# make
# make install
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/dagmc_bld/dagmc/lib

## HDF5
# cd ${BASE_DIR}
# wget -c https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.13/src/hdf5-1.8.13.tar.gz
# tar -xzvf hdf5-1.8.13.tar.gz
# cd hdf5-1.8.13
# mkdir build && cd build
# CC=${MPI_ROOT}/bin/mpicc ../configure --enable-shared \
# 			 --enable-parallel \
# 			 --prefix=${HDF5_DIR}
# ${MAKE} -j16
# ${MAKE} -j16 check
# ${MAKE} -j16 install

## MOAB
# cd $HOME/dagmc_bld
# mkdir -p MOAB/bld
# cd MOAB
# git clone https://bitbucket.org/fathomteam/moab
# cd moab
# git checkout Version5.1.0
# autoreconf -fi
# cd ..
# ln -s moab src
# cd bld
# ../src/configure --enable-optimize \
#                  --enable-shared \
#                  --disable-debug \
#                  --with-hdf5=$HOME/dagmc_bld/HDF5 \
#                  --prefix=$HOME/dagmc_bld/MOAB
# make
# make check
# make install
# export PATH=$PATH:$HOME/dagmc_bld/HDF5/bin
# export PATH=$PATH:$HOME/dagmc_bld/MOAB/bin
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/dagmc_bld/HDF5/lib
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/dagmc_bld/MOAB/lib
# which h5ls
# which mbconvert

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 .
