Conda envirment configuration and FEniCS/FEniCSx installation on Ubuntu

In this blog post, I provide the steps and code for my personal installation of the Conda environment, along with methods for installing FEniCS and FEniCSx, as well as my personal understanding of the installation process.
💻The operation below were conducted on a laptop equipped with an Intel 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz 2.30 GHz CPU and 16.0 GB of RAM. The operating system is Ubuntu 22.04 installed on Virtual Box 7 based on Windows 10 Professional, with 8192MB of memory and 8 processors allocated, and 64MB of video memory.
Git installation1️⃣
First, we need to make sure that we already installed git. Git is a very useful tool in verson control, and it is a basis for Github. Normally, new version Ubuntu comes with Git installed. But we can also use following code to make it sure.
sudo apt-get install git
Conda installation2️⃣
The next step is to install anaconda. As instruction in README.md, we can also use miniconda or other preferred Anaconda-like variants. We can get the newest anaconda by [link].
Then we can copy the file Anaconda3-2023.09-0-Linux-x86_64.sh to the root directory(/home/zli2022). Then open a terminal and enter the following command:
bash Anaconda3-2023.09-0-Linux-x86_64.sh
After the installation is complete, enter in the terminal:
sudo gedit ~/.bashrc
Add at the end of the pop-up file:
export PATH="/home/zli2022/anaconda3/bin:$PATH"
Save the file, close the file and enter in the terminal:
source ~/.bashrc
Till now, we finished intalling anaconda3 in linux. After restarting the terminal, the word (base) will appear before the user name. This is because the base environment of anaconda has started automatically. We can use the following command to turn off the base environment automatic startup.
Always turn off base environment auto-start
conda config --set auto_activate_base false
Only close the base environment that was started this time (in fact, any environment that has been entered can be closed)
conda deactivate
We can create our conda environments and customize them:
Create conda envionment with file path
conda create --prefix /home/zli2022/DDFenics/ddfenics
Then we can activate the conda environment:
conda activate /home/zli2022/DDFenics/ddfenics
We can also install ipykernel and meshio package by following commands:
conda install ipykernel
pip install meshio
Create conda envionment on root directory
conda create -n fenics-env
conda activate fenics-env
Installation of FEniCS3️⃣
The latest version of legacy FEniCS (2019.1.0) was released in April 2019.[ref1]
In other blog posts on our website (Gradient damage models as phase-field models of brittle fracture), we use FEniCS 2018.1.0, but in the Coupled Problems and Data-driven Mechanics projects, we have used FEniCSx. Discussion about this new version is in the next section.
When running notebooks (.ipynb), we can use a pre-configured Conda environment. For instance, in VS Code (already installed in Ubuntu), by selecting different kernel cores, we can further customize our Conda environment using the following code:
conda install -c conda-forge fenics
Or we can directly install by apt(Ubuntu):
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:fenics-packages/fenics
sudo apt-get update
sudo apt-get install --no-install-recommends fenics
sudo apt-get dist-upgrade
In 2018, work started on FEniCSx: the new version of the FEniCS library. FEniCSx has a number of major improvements over the legacy library, including support for a wide range of cell types and elements, memory parallelisation, and complex number support, as well as a large number of improvements to the overall library design. FEniCSx is comprised of the libraries UFL, Basix, FFCx and DOLFINx. The latest version of FEniCSx (0.7) was released in October 2023.[ref1]
Installation of FEniCSx4️⃣
FEniCSx is a popular open-source computing platform for solving partial differential equations (PDEs). FEniCSx enables users to quickly translate scientific models into efficient finite element code. With the high-level Python and C++ interfaces to FEniCSx, it is easy to get started, but FEniCSx offers also powerful capabilities for more experienced programmers. FEniCSx runs on a multitude of platforms ranging from laptops to high-performance clusters.[ref1]
It is easier to install FEniCSx by Binary distributions (container images, conda, Ubuntu packages etc.).[ref2]
Conda
To install the latest stable release of the Python interface, with pyvista support for visualisation, using conda:
conda create -n fenicsx-env
conda activate fenicsx-env
conda install -c conda-forge fenics-dolfinx mpich pyvista
Please remind yourself before we install FEniCSx in this way, that we need to make sure we already have the latest version conda, we can easily check by:
conda deactivate
conda update conda
Ubuntu packages
The Ubuntu PPA contains binary packages of the FEniCSx components. To install:
add-apt-repository ppa:fenics-packages/fenics
apt update
apt install fenicsx
Initialization of notebook on Linux5️⃣
We can use Jupyter-lab on Linux for compiling .ipynb file.
conda install -c conda-forge jupyterlab
Then we can run our notebook by:
jupyter-lab VI-notes.ipynb