diff --git a/Dockerfile_bionic b/Dockerfile_bionic deleted file mode 100644 index 9b9190d3..00000000 --- a/Dockerfile_bionic +++ /dev/null @@ -1,52 +0,0 @@ -# command to build: docker build --rm -f Dockerfile -t qingfengxia/freecad-daily-python3 . -# docker push qingfengxia/freecad-daily-python3:latest - -# Base OS layer: Latest Ubuntu LTS. -FROM ubuntu:18.04 - -# Use multi-stage builds: https://docs.docker.com/develop/develop-images/multistage-build/ -# rebuild on top of local image (instead of base OS layer) for quick modification, run without `--rm` -# docker build -f Dockerfile -t qingfengxia/freecad-daily-python3 . -#FROM qingfengxia/freecad-daily-python3:latest - -LABEL name="freecad-daily-python3" \ - maintainer="qingfeng.xia @ UKAEA" \ - version="0.19" \ - description="FreeCAD 0.19 python3 daily installed from PPA, version as this image building date: \ - with OpenCASCADE (libocct*-dev) python3 \ - also with Fenics 2019.1 (installed from PPA) bundled with libscotch, libhypre, OpenMPI, \ - pybind11-dev, python3-dev, numpy, scipy, matplotlib" - -USER root - -# avoid interactive timezone selection, ENV setting will affect child image -# ENV TZ=Europe/London -# RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -ARG DEBIAN_FRONTEND=noninteractive - -# you must update before any apt-get install, -# `software-properties-common` is needed to to add PPA repo -RUN apt-get update && apt-get install -y sudo git gcc g++ build-essential cmake doxygen wget apt-utils software-properties-common - -# install freecad from PPA, and also opencascade dev files -RUN add-apt-repository ppa:freecad-maintainers/freecad-daily && \ - apt-get update && \ - apt-get install -y freecad-daily-python3 libocct*-dev && apt-get upgrade -y - -# install Fenics from PPA, it should also install python3-pybind11 and OpenMPI -RUN add-apt-repository ppa:fenics-packages/fenics && \ - apt-get update && \ - apt-get install --no-install-recommends -y fenics python3-dev - -# libvtk7-dev not yet merged into this image, introducing large volume of packages -RUN apt-get update && apt-get install -y libeigen3-dev graphviz libtbb2 libtbb-dev - -# once user name has been created, it will cause error during update the image building -RUN id -u user >/dev/null 2>&1 || useradd -ms /bin/bash user - -ENV DISPLAY :0 - -# switch users, but it is not clear which user is pre-built, it should be disabled, otherwise, user can not install extra packages -#USER user - diff --git a/Dockerfile_fedora b/Dockerfile_fedora deleted file mode 100644 index 1715bbc4..00000000 --- a/Dockerfile_fedora +++ /dev/null @@ -1,77 +0,0 @@ -# rm the outdated image: docker rmi qingfengxia/ppp-fedora -# Remove all untagged images: docker rmi $(docker images | grep "^" | awk "{print $3}") -# command to build: docker build --rm -f Dockerfile_fedora -t qingfengxia/ppp-fedora . -# -# to test this image: -# git clone this project, optionally, rename it to `ppp` -# change directory to the `ppp` repo toplevel, if build folder exists, `sudo rm -rf build && mkdir build` -# docker run -ti -w /project/build/ -v $(pwd):/project/ qingfengxia/ppp-fedora bash -# before build inside docker container: git submodule update --init --recursive -# -# build package and test after install -# -# release this image -# to rename/tag the image by `docker tags` if not yet done -# docker login && docker push qingfengxia/ppp-fedora:latest - -# fedora30 has default python as python3, and opencascade 7.4 and freecad rpm - -# Base OS layer: should works for federa 30+ -FROM fedora:latest - -LABEL name="ppp-fedora" \ - maintainer="qingfeng.xia @ UKAEA" \ - version="0.3" \ - description="federa with FreeCAD python3 and opencascade 7.4 for parallel preprocessor development CI" - -# must be root user to use GITHUB_WORKSPACE -#USER root - -# avoid interactive timezone selection, ENV setting will affect child image -# ENV TZ=Europe/London -# RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - - -# you must update before any yum install or add a repo -# `dnf-cli` is needed to to add copr repo, such as FreeCAD -RUN yum install copr-cli -y && yum update -y - -# g++ 9.2 for f30 high enough, there is no need to install boost-devel -RUN yum install g++ cmake make git doxygen nano rpm-build -y -RUN yum install openmpi-devel eigen3-devel boost-devel -y - - -# export path for openmpi: export PATH=/usr/lib/openmpi/bin/ && mpicc -v - -# for OpenCASCADE, need openGL, xwindows, -# python3 and qt5 devel for parallel preproessor -# package name distinguish capital letter, while debian name is just libxmu -RUN yum install tk tcl tk-devel tcl-devel tbb tbb-devel freetype freetype-devel freeimage freeimage-devel \ - glew-devel SDL2-devel SDL2_image-devel glm-devel libXmu-devel libXi-devel \ - python3 python3-devel -y - -# optional dep -#RUN yum install qt5-devel qt5-qtwebsockets-devel qt5-qtwebsockets -y - -# Since Jan 2020, opencascade 7.4 package for fedroa 30+ is available, -# freecad 0.18.4 stable(python3 occt 7.4 is available in official repo too. -RUN dnf install opencascade-foundation opencascade-modeling opencascade-ocaf \ - opencascade-visualization opencascade-devel -y - -# opencascade-draw is not needed -# https://fedora.pkgs.org/31/fedora-updates-x86_64/opencascade-devel-7.4.0-2.fc31.i686.rpm.html - -# install FreeCAD 0.18 stable from official repo, or older version dep on fedora version -# RUN yum install freecad -y -# or install the daily build of freecad -# RUN yum install dnf-plugins-core -y && dnf copr enable @freecad/nightly -y && yum install freecad -y - - -# Copies your code file from your action repository to the filesystem path `/` of the container -COPY scripts/build_package.sh /build_package.sh - -# Code file to execute when the docker container starts up (`entrypoint.sh`) -ENTRYPOINT ["/build_package.sh"] - - - diff --git a/Dockerfile_focal b/Dockerfile_focal deleted file mode 100644 index 499d4c4c..00000000 --- a/Dockerfile_focal +++ /dev/null @@ -1,29 +0,0 @@ -# command to build: docker build --rm -f Dockerfile_focal -t ubuntu_focal . -# topup build: docker build -f Dockerfile_focal -t ubuntu_focal . -# docker push qingfengxia/ubuntu_focal:latest - -FROM ubuntu:20.04 - -LABEL name="ubuntu_focal" \ - maintainer="qingfeng.xia @ UKAEA" \ - version="0.20" \ - description="a basic C++ develop env for ubuntu" - -USER root - -#ENV DEBIAN_FRONTEND=noninteractive - -# update and install dependencies -RUN apt-get update \ - && apt-get install -y \ - software-properties-common \ - apt-utils \ - wget \ - && apt-get update \ - && apt-get install -y \ - gcc g++ make cmake libboost-dev git build-essential \ - && apt-get install -y libocct*-dev occt* python3-dev pybind11-dev libtbb-dev - -ENV DISPLAY :0 - -RUN apt-get install libx11-dev libxmu-dev libxi-dev \ No newline at end of file diff --git a/docker/Dockerfile_ppp_openmc b/docker/Dockerfile_ppp_openmc new file mode 100644 index 00000000..cb9f5b66 --- /dev/null +++ b/docker/Dockerfile_ppp_openmc @@ -0,0 +1,274 @@ +###################################### +# adapted from https://github.com/Shimwell/openmc_workshop_dependencies +# +# Changelog: 1) merge commands to improve performance +# 2) add gmsh, ppp, occ_faceter, freecad +# 3) both X11 and jupyter web interface should be supported +# 4) ssh server +# 5) base image can be selected from ubuntu:bionic (18.04), ubuntu:focal (20.04), jupyter/minimal-notebook +###################################### +# +# build with the following command +# sudo docker build -f Dockerfile_ppp_openmc -t ppp_openmc . --no-cache +# build without `--no-cache` can help recover build from where error happened if start quickly enough, +# useful when modify this Dockerfile. The drawback is lots of disk space will be used during trial-and-error process, +# It needs to reclaim by docker command afterwards. +# use --no-cache if you know there is no error in this Dockerfile, to save disk space +# USAGE: see README.md +################################################ + + +# jupyter/minimal-notebook is based on ubuntu-focal, so FROM ubuntu:focal should be working +# if you do not want jupyter-notebook, you can base on ubuntu:focal +FROM jupyter/minimal-notebook +#FROM ubuntu:focal + + +# only last CMD is working, if multiple CMD exists, interactive mode also suppress this CMD +# jupyter can create a terminal, just like ssh +# uncomment this CMD if the base image is not jupyter, assuming ssh server installation section is kept +#CMD ["/usr/sbin/sshd","-D"] + + +LABEL name="ppp_openmc" \ + maintainer="qingfeng.xia @ UKAEA" \ + version="0.3" \ + description="OpenMC, FreeCAD, parallel-preprocessor, DAGMC, MOAB, gmsh" + + +ENV DEBIAN_FRONTEND=noninteractive + + +# for local X11 forwarding, this env var gives a default value +# this can be overridden to another DISPLAY value +# by providing environment variable on docker command line `-e DISPLAY=xxx` +ENV DISPLAY :0 + +# this is required to install programs on the base image +USER root + +RUN apt-get --yes update && apt-get --yes upgrade + +# sudo is needed as the install NJOY script has a sudo make install command +RUN apt-get -y install sudo git g++ cmake build-essential wget software-properties-common + +######################################### +## if not using jupyter base docker image +######################################### +# pip install is used later, but pip3 is not installed on ubuntu base images +# this alias makes sure pip and pip3 are same +RUN if test "$NB_UID" = "" ; then \ + apt install -y python3 python3-pip python3-matplotlib python3-numpy && \ + apt-get --yes update && \ + ln -s /usr/bin/pip3 /usr/bin/pip && \ + ln -s /usr/bin/python3 /usr/bin/python; \ + fi +######################################################## + +###################### +## ubuntu:bionic only +##################### +# newer CMake version (3.12) allows us to set libraries, includes of the imported DAGMC target in CMake +# for ubuntu foal, cmake version is high enough, freecad 0.18 is in focal repository +RUN if test $(awk '/VERSION_ID=/' /etc/*-release | sed 's/VERSION_ID=//' | sed 's/\"//' | sed 's/\"$//' ) = "18.04" ; then \ + add-apt-repository ppa:freecad-maintainers/freecad-stable && \ + apt remove -y cmake && \ + pip3 install cmake==3.12; \ + fi +########################################################## + + +########################## +install QT and full graphic software stack +########################## +# install full QT software stack, to make sure matplotlib working with X11 forwarding, +# it is not needed if freecad will be installed +# RUN apt install -y python3-pyside2.qtgui + +# add apt option --no-recommended to +RUN apt update && apt install freecad -y --no-install-recommends + + + +# why non-root user is needed? because jupyter base image is used, put all files in user home +# this environment is jupyter/minimal specific +# ARG NB_USER="jovyan" +# see https://github.com/jupyter/docker-stacks/blob/master/base-notebook/Dockerfile +# if built on ubuntu:focal, build with -e NB_USER=root +USER $NB_USER + +###################### dependencies for openmc, maob, dagmc ################### +# OpenMC required packages identified from openmc travis.yml +# libnetcdf-dev is needed to allow NETCDF on MOAB which helps with tet meshes in OpenMC +RUN apt-get --yes install imagemagick hdf5-tools mpich libmpich-dev libhdf5-serial-dev libhdf5-mpich-dev libblas-dev liblapack-dev libnetcdf-dev libeigen3-dev + + +################################################################## +# MOAB Variables +ENV MOAB_BRANCH='Version5.1.0' +ENV MOAB_REPO='https://bitbucket.org/fathomteam/moab/' +ENV MOAB_INSTALL_DIR=$HOME/MOAB/ + +# MOAB Install +RUN cd $HOME && \ + mkdir MOAB && \ + cd MOAB && \ + git clone -b $MOAB_BRANCH $MOAB_REPO && \ + mkdir build && cd build && \ + cmake ../moab -DENABLE_HDF5=ON -DENABLE_MPI=off -DENABLE_NETCDF=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$MOAB_INSTALL_DIR && \ + make -j$(nproc) && \ + make install && \ + cmake ../moab -DBUILD_SHARED_LIBS=OFF && \ + make -j$(nproc) && make install && \ + rm -rf $HOME/MOAB/moab $HOME/MOAB/build + +#################################################################### +# DAGMC Variables +ENV DAGMC_BRANCH='develop' +ENV DAGMC_REPO='https://github.com/svalinn/dagmc' +ENV DAGMC_INSTALL_DIR=$HOME/DAGMC/ + +# DAGMC Install +RUN cd $HOME && \ + mkdir DAGMC && cd DAGMC && \ + git clone -b $DAGMC_BRANCH $DAGMC_REPO && \ + mkdir build && \ + cd build && \ + cmake ../dagmc -DBUILD_TALLY=ON -DCMAKE_INSTALL_PREFIX=$DAGMC_INSTALL_DIR -DMOAB_DIR=$MOAB_INSTALL_DIR && \ + make -j$(nproc) install && \ + rm -rf $HOME/DAGMC/dagmc $HOME/DAGMC/build + + +############################################### +# Clone and install NJOY2016 +RUN cd $HOME && git clone https://github.com/njoy/NJOY2016 && \ + cd NJOY2016 && mkdir build && cd build && \ + cmake -Dstatic=on .. && \ + make 2>/dev/null && \ + sudo make install && \ + cd .. && rm -rf build + + +###################### OpenMC ########################## +# /opt folder is owned by root +USER root + +# numpy is needed by openmc-python +RUN pip install --upgrade numpy matplotlib pyside2 + +# openmc should be installed to default location /usr/local/ +# so cmake can find OpenMCConfig.cmake, which is under /usr/local/lib/cmake/OpenMC +# installs OpenMC from source (latest) +RUN cd /opt && git clone https://github.com/openmc-dev/openmc.git && \ + cd /opt/openmc && git checkout develop && \ + cd /opt/openmc && mkdir build && \ + cd /opt/openmc/build && cmake -Ddagmc=ON -DDAGMC_ROOT=$DAGMC_INSTALL_DIR -DHDF5_PREFER_PARALLEL=OFF -DCMAKE_INSTALL_PREFIX=.. .. && \ + cd /opt/openmc/build && make -j$(nproc) && \ + cd /opt/openmc/build && make install + +# build and install python interface for openmc +RUN cd /opt/openmc/ && python setup.py install && \ + cd .. && rm -rf build + +## some python package is needed for openmc +RUN pip install neutronics_material_maker --user + +# Oct 2020, openmc must be installed to /opt/openmc, to install this parametric-plasma-source +RUN pip install git+https://github.com/open-radiation-sources/parametric-plasma-source.git + + +## to make sure openmc etc are on path for jupyter notebook +ENV LD_LIBRARY_PATH=$HOME/MOAB/lib:$HOME/DAGMC/lib +ENV PATH=$PATH:$HOME/MOAB/bin:/opt/openmc/bin:$HOME/DAGMC/bin + + +#################### +install ssh server +#################### +RUN apt install openssh-server nano -y + +# to enable X11 forwarding via ssh +RUN echo "ForwardX11 yes" >> /etc/ssh/ssh_config && echo "ForwardX11Trusted no" >> /etc/ssh/ssh_config + +# use UID 1001, as 1000 has been used by another user +RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1001 test + +# set password for the user test as "test" +RUN echo 'test:test' | chpasswd +RUN service ssh start + +# expose port, the default +EXPOSE 22 +################## + + +############## +## install gmsh and pygmsh +############## +RUN apt-get install -y gmsh python3-gmsh +RUN pip install pygmsh + +############################################ +## install dependencies for PPP & occ_faceter +############################################# + +# ubuntu 18.04 needs PPA to install occt and freecad +# occ_faceter needs libcgal-dev, +RUN apt-get install -y libocct*-dev occt* python3-dev pybind11-dev libtbb-dev libboost-dev libx11-dev libxmu-dev libxi-dev libcgal-dev + + +## install occ_faceter +RUN cd $HOME && git clone https://github.com/makeclean/occ_faceter.git && \ + cd occ_faceter && \ + mkdir build && cd build && \ + export MOAB_ROOT=$MOAB_INSTALL_DIR && \ + export LIBRARY_PATH=$LIBRARY_PATH:$MOAB_INSTALL_DIR/lib && \ + cmake .. -DCMAKE_INSTALL_PREFIX=/usr && \ + make && \ + make install && \ + cd .. && rm -rf build + +## install parallel-preprocessor +RUN cd $HOME && git clone https://github.com/ukaea/parallel-preprocessor.git && \ + cd parallel-preprocessor && git submodule update --init --recursive && \ + mkdir build && cd build && \ + cmake .. -DCMAKE_INSTALL_PREFIX=/usr && \ + make -j$(nproc) && \ + make install && \ + cd .. && rm -rf build + +################## +## nuclear material data for openmc +################### +# consider to split the docker image from here +# copy data into docker image could be skipped and use volume map instead +# but host folder must be mapped to /mat_dir in the container + +# installed on host, the copy into container +COPY tendl-2019-hdf5 /mat_dir + +ENV MAT_DIR=/mat_dir +ENV OPENMC_CROSS_SECTIONS=$MAT_DIR/cross_sections.xml + +## another way to install material is +# clone data repository +# RUN cd $HOME && git clone https://github.com/openmc-dev/data.git +# run script that converts ACE data to hdf5 data +#RUN python data/convert_nndc71.py --cleanup + + +################# openmc workshop ################### + +# for jupyter to work: switch to USER $NB_USER +USER $NB_USER + +RUN git clone -b develop https://github.com/ukaea/openmc_workshop +# currently there is some bug stop install parametric_plasma_source +#RUN cd openmc_workshop && pip install -r requirements.txt + +# can WORKDIR be override by command line option yes, by -w argument +WORKDIR openmc_workshop/tasks + +###################### some extra tools ########################### +RUN pip install --upgrade vtk pyansys --user + diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..9a8744fe --- /dev/null +++ b/docker/README.md @@ -0,0 +1,103 @@ +# Parallel-preprocessor in Docker + +Since binary packages are available for Ubuntu, fedora and Debian, there is no need to provide Dockerfile on each platforms, but Docker based on centos would be sufficient. + +## Readme for ppp_centos docker image + +`docker pull qingfengxia/ppp_centos` + +This is should be small image with only occt and ppp; both are compiled from source. + + +## Readme for ppp_openmc docker image + +This is a image with all open source tools for: FreeCAD + PPP + occ_faceter + gmsh + openmc workflow + +Note: this image is large, about 10 GB + +## Get the docker image + +`docker pull qingfengxia/ppp_openmc` + +https://hub.docker.com/repository/docker/qingfengxia/ppp_openmc + +The Dockerfile is here: + +The docker image is based on `jupyter/mini-notebook` , but it can be switched to `ubuntu:focal` as base image, see instruction at the end of this document for switching base image. + +## Use this image + +There are 3 ways to use this docker image, choose the one you like + +### 1. The jupyter notebook way + +`docker run --rm -p 8888:8888 ppp_openmc ` +Jupyter can create a terminal in webbrowser, just like ssh terminal. + +`-p 8888:8888` is for jupyter notebook web access +This docker image can be running in super user mode by giving `-e GRANT_SUDO=yes --user root` which gives passwordless sudo capacity, to install more software. + +Since nuclear material (tendl-2019-hdf5) has been built in, there is no need to map host folder to container like this. In case of some docker image is not built with material data, please use volume mapping such as ` -v /mnt/windata/MyData/openmc_data/tendl-2019-hdf5/:/mat_dir` for material cross section data. The host folder containing "cross-section.xml" must be mapped to `/mat_dir` + +For more details on options on `jupyter/mini-notebook` base docker image, see +https://jupyter-docker-stacks.readthedocs.io/en/latest/using/common.html + +> -e GRANT_SUDO=yes - Instructs the startup script to grant the NB_USER user passwordless sudo capability. You do not need this option to allow the user to conda or pip install additional packages. This option is useful, however, when you wish to give $NB_USER the ability to install OS packages with apt or modify other root-owned files in the container. For this option to take effect, you must run the container with --user root. (The start-notebook.sh script will su $NB_USER after adding $NB_USER to sudoers.) You should only enable sudo if you trust the user or if the container is running on an isolated host. + +### 2. X11 forwarding on local machine + +to get an interative bash shell, as ubuntu 20.04 + +```sh +docker run -it --rm -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY -h $HOSTNAME -v $HOME/.Xauthority:/home/jovyan/.Xauthority -v $PWD/:/workspace/ ppp_openmc bash +``` + +NOTE: X11 forward is not working for `root` user, so do not add this option `-e GRANT_SUDO=yes --user root `, perhaps caused by hardcoded absolute home path in `/home/jovyan/.Xauthority` + +Local X11 forwarding has been tested to work on Linux, it may works on Windows but with different environment variables passed in. +Local X11 forwarding can be quickly tested by +1) `xterm` is working without any xhost configuration, + +2) matplotlib.pyplot is working from terminal, tested by: + +`python3 -c "import matplotlib.pyplot as plt; plt.plot(); plt.show()" ` + +To understand why those arguments are needed +`-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY -h $HOSTNAME -v $HOME/.Xauthority:/home/jovyan/.Xauthority` +See https://medium.com/@l10nn/running-x11-applications-with-docker-75133178d090 + +### 3. SSH remote shell +SSH has also X11 forwarding turned on +`docker run --rm -p 2222:22 -e GRANT_SUDO=yes --user root -it ppp_openmc bash ` then start the ssh server by `sudo service ssh start ` + +This argument `-p 2222:22` map container's port 22 to host 2222 port. +To access this container by ssh: +either `ssh localhost -p 2222` or `ssh -p 22` + +see also [How to setup an ssh server within a docker container](https://phoenixnap.com/kb/how-to-ssh-into-docker-container) +rebuild the image will change ssh server public key, as the ssh server installation will generate new key pair each time. + +#### user name and password for ssh both “test” + +On Ubuntu, install the `sshpass` package, then use it like this: `sshpass -p 'YourPassword' ssh user@host` + +#### start ssh server automatically + +Automatically start the ssh server is possible by uncomment `CMD ["/usr/sbin/sshd","-D"]` in Dockerfile if **Rebuild with ubuntu:focal as the base image**. + +Currently, `CMD ["/usr/sbin/sshd","-D"]` is commented out, because it will override the jupyter’s start_notebook CMD. + +> Multiple CMD commands: In principle, there should only be one CMD command in your Dockerfile. When CMD is used multiple times, only the last instance is executed. + https://www.educative.io/edpresso/what-is-the-cmd-command-in-docker + + +### Rebuild with ubuntu:focal as the base image +change in Dockerfile before build: + 1) FROM ubuntu:focal + 2) uncomment `CMD ["/usr/sbin/sshd","-D"]` +Then build with command line, +`sudo docker build -f -e NB_USER=root Dockerfile_ppp_openmc -t ppp_openmc . --no-cache` + +Note: `-e NB_USER=root` is needed to be compatible with jupyter-notebook base image + + diff --git a/src/PPP/UniqueId.h b/src/PPP/UniqueId.h index c777a0d5..89684542 100644 --- a/src/PPP/UniqueId.h +++ b/src/PPP/UniqueId.h @@ -66,7 +66,7 @@ namespace PPP * */ const double LENGTH_SCALE = 0.01; // if the value is close to zero after scaling, regarded as zero in comparison - const static double ZERO_THRESHOLD = 1e-4; + const static double ZERO_THRESHOLD = 1; // changed from 1e-4 to 1 on Oct 2020, issue 20 /// rounding: mask out east significant bits for approximately comparison const std::uint16_t ROUND_PRECISION_MASK = 0x0008;