Sharing my experiences, How to install dolfin on Ubuntn-20.04 from source

Here, i would like to extend great thanks to Prof. Dokken. Thank your very much for your help and suggestions
After struggling with this for a couple of hours finally I got to install it.
I thinck that,especially for novices,it is difficult to install fenics form source. Because there is a lot of dependencies. And there are few documents about installing fenics form source.
I am sharing my experiences for anybody.
Here is a full step by step copy-paste each of the commands

# system information
# Ubuntu20.04
#------------------------------------First-------------------------------------------#
# Install dependecis and optional
# install dependecis availabe via apt-get
# Required: 
#          Boost, filesystem, iostreams, program_options, timer,
#          CMake, Eigen3, pkg-config, g++ and so on
#commands:
exort DEBIAN_FRONTEND=noninteractive && apt-get -qq update
apt-get -yq --with-new-pkgs -o Dpkg::Options::="--force-confold" upgrade 
apt-get -y install calng-10 cmake g++ gfortran libboost-dev libboost-filesystem-dev \
libboost-iostreams-dev 
libboost-math-dev \
libboost-program-options-dev \
libboost-system-dev \
libboost-thread-dev \
libboost-timer-dev \
libeigen3-dev \
libhdf5-mpich-dev \
liblapack-dev \
libmpich-dev \
libopenblas-dev \
ninja-build \
pkg-config \
python3-dev \
python3-matplotlib \
python3-numpy \
python3-pip \
python3-scipy \
python3-setuptools && \
#
apt-get -y install \
doxygen \
git \
graphviz \
sudo \
valgrind \
wget && \
#---------
apt-get -y install \
libglu1 \
libxcursor-dev \
libxinerama1 && \
apt-get -y install \
python3-lxml && \
#
apt-get -y install \
doxygen \
git \
graphviz \
sudo \
valgrind \
wget && \
apt-get -y install \
libglu1 \
libxcursor-dev \
libxinerama1 && \
apt-get -y install \
python3-lxml && \
apt-get clean && \

# Install Python packages (via pip)
# Packages: mpi4py, numba, h5py, meshio,pygmesh, pytest and so on
# commands:
pip3 install --no-cache-dir mpi4py numba && \
pip3 install --no-cache-dir cffi cppimport flake8 pytest pytest-xdist sphinx sphinx_rtd_theme && \
export HDF5_MPI="ON" && \
export CC=mpicc && \
pip3 install --no-cache-dir --no-binary=h5py h5py meshio pygmsh

# Dowload Install pybind11:for doflinx,  PYBIND11_VERSION=2.5.0, for Development version PYBIND11_VERSION=2.4.3
PYBIND11_VERSION=2.5.0
wget -nc --quiet https://github.com/pybind/pybind11/archive/v${PYBIND11_VERSION}.tar.gz && \
tar -xf v${PYBIND11_VERSION}.tar.gz && \
cd pybind11-${PYBIND11_VERSION} && \
mkdir build && cd build && cmake -DPYBIND11_TEST=off .. && make install

# Install KaHIP
cd /usr/local
KAHIP_VERSION=14be06c
git clone https://github.com/schulzchristian/KaHIP.git && \
cd KaHIP/ && \
git checkout $KAHIP_VERSION && \
./compile_withcmake.sh
KAHIP_ROOT=/usr/local/KaHIP   

# Download Install Gmsh SDK
cd /usr/local
GMSH_VERSION=4.6.0
wget -nc --quiet http://gmsh.info/bin/Linux/gmsh-${GMSH_VERSION}-Linux64-sdk.tgz && \
tar -xf gmsh-${GMSH_VERSION}-Linux64-sdk.tgz && \
rm gmsh-${GMSH_VERSION}-Linux64-sdk.tgz
PATH=/usr/local/gmsh-${GMSH_VERSION}-Linux64-sdk/bin:$PATH

#Add gmsh python API

PYTHONPATH=/usr/local/gmsh-${GMSH_VERSION}-Linux64-sdk/lib:$PYTHONPATH

# Dowload Install PETSc 
mkdir /usr/locs/petsc
export PETSC_DIR=/usr/local/petsc
cd /usr/local/petsc
apt-get -qq update
apt-get -y install bison flex
PETSC_VERSION=3.13.3
wget -nc --quiet http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-lite-${PETSC_VERSION}.tar.gz -O petsc-${PETSC_VERSION}.tar.gz
tar -xf petsc-${PETSC_VERSION}.tar.gz -C ${PETSC_DIR} --strip-components 1
PETSC_SLEPC_OPTFLAGS="-O2 -march=sandybridge"
PETSC_SLEPC_DEBUGGING="no"
python3 ./configure \
PETSC_ARCH=linux-gnu-real-64 \
--COPTFLAGS=${PETSC_SLEPC_OPTFLAGS} \
--CXXOPTFLAGS=${PETSC_SLEPC_OPTFLAGS} \
--FOPTFLAGS=${PETSC_SLEPC_OPTFLAGS} \
--with-64-bit-indices=yes \
--with-debugging=${PETSC_SLEPC_DEBUGGING} \
--with-fortran-bindings=no \
--with-shared-libraries \
--download-hypre \
--download-mumps \
--download-ptscotch \
--download-scalapack \
--download-suitesparse \
--download-superlu_dist \
--with-scalar-type=real && \
make PETSC_DIR=/usr/local/petsc PETSC_ARCH=linux-gnu-real-64 all

# Download Install SLEPc
mkdir /user/local/slepc
cd /usr/local/slepc
SLEPCC_DIR=/usr/local/slepc
export SLEPC_VERSION=3.13.3
wget -nc --quiet https://slepc.upv.es/download/distrib/slepc-${SLEPC_VERSION}.tar.gz -O slepc-${SLEPC_VERSION}.tar.gz && \
tar -xf slepcdd-${SLEPC_VERSION}.tar.gz -C ${SLEPC_DIR} --strip-components 1
PETSC_ARCH=linux-gnu-real-64 && \
python3 ./configure && \
make

# Install petsc4py and slepc4py 
PETSC_ARCH=linux-gnu-real-64 pip3 install --no-cache-dir petsc4py==${PETSC4PY_VERSION} slepc4py==${SLEPC4PY_VERSION}

#------------------set environment variable----------------------------------------#
sudo vim /etc/profile

#In file profile: please input

export OPENBLAS_NUM_THREADS=1
export PATH=/usr/local/gmsh-4.6.0-Linux64-sdk/bin:$PATH
export OPENBLAS_VERBOSE=0
export KAHIP_ROOT=/usr/local/KaHIP
export PETSC_DIR=/usr/local/petsc
export SLEPC_DIR=/usr/local/slepc
export PKG_CONFIG_PATH=/usr/local/dolfinx-real/lib/pkgconfig:$PKG_CONFIG_PATH
export PETSC_ARCH=linux-gnu-real-64
export LD_LIBRARY_PATH=/usr/local/dolfinx-real/lib:$LD_LIBRARY_PATH
export PYTHONPATH=/usr/local/gmsh-4.6.0-Linux64-sdk/lib:$PYTHONPATH
export PYTHONPATH=/usr/local/dolfinx-real/lib/python3.8/dist-packages:$PYTHONPATH

#And save (wq)

source /etc/profile

# You can check the environment variable, using the follown command

env

#--------------------------Sceond--------------------------------------------------#
# Download and Install fenics from source
mkdir /home/wangzh/fenics
cd /home/wangzh/fenics
git clone https://github.com/FEniCS/fiat.git
git clone https://bitbucket.org/fenics-project/dijitso
git clone https://github.com/FEniCS/ufl.git
git clone https://bitbucket.org/fenics-project/ffc
git clone https://bitbucket.org/fenics-project/dolfin
git clone https://bitbucket.org/fenics-project/mshr
cd fiat    && pip3 install . && cd ..
cd dijitso && pip3 install . && cd ..
cd ufl     && pip3 install . && cd ..
cd ffc     && pip3 install . && cd ..
mkdir dolfin/build && cd dolfin/build && cmake .. && make install && cd ../..
cd dolfin/python && pip3 install . && cd ../..

Please be careful, there may be some printing errors here.
If you have any questions in advance, please feel free to contact at anytime.

Zhihai Wang

Best regards

1 Like