Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
fenicsx [2023/03/24 13:28] – created bdatta1 | fenicsx [2024/04/18 10:33] (current) – [Learning FEniCSx] bdatta1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== What is FEniCSx ===== | + | ===== FEniCSx ===== |
- | FEniCSx is an open source multi-platform computing environment to solve partial differential equations using finite element method. FEniCSx supports parallel computing with Python and C++ interface. FEniCSx is comprised of the libraries UFL, Basix, FFCx and DOLFINx which are the build blocks of it. To learn more about FEniCSx: https:// | + | FEniCSx is an open-source multi-platform computing environment to solve partial differential equations using the finite element method. FEniCSx supports parallel computing with Python and C++ interface. FEniCSx is comprised of the libraries UFL, Basix, FFCx, and DOLFINx which are the build blocks of it. To learn more about FEniCSx: |
- | The FEniCS project originally started in 2003 and was known as FEniCS. In 2020, the developers released a new version of the library and renamed FEniCS as FEniCSx. The latest stable version of legacy FEniCS was released | + | The FEniCS project originally started in 2003 and was known as FEniCS. In 2020, the developers released a new version of the library and renamed FEniCS as FEniCSx. The latest stable version of legacy FEniCS was released |
- | Both FEniCSx and FEniCS are available on Linux, macOS, and Windows. You can download and install it in different ways. Check out the options here for FEniCSx: https:// | + | Both FEniCSx and FEniCS are available on Linux, macOS, and Windows. You can download and install it in different ways. Check out the options here for FEniCSx: |
- | ===== Installation on Windows ===== | + | |
+ | ==== Installation on Windows ===== | ||
This step in only applicable if you are using Windows. You will have to set up Windows Subsystem for Linux (WSL) to use Anaconda based installation of FEniCSx and legacy FEniCS. WSL is a virtual Linux environment within Windows which allows you to use Linux command line tools and GUI applications (GUI is natively supported on Windows 11). If you are on macOS or Linux, you can skip this step. If you are on Windows and already have installed WSL, it still might be interesting to download the recommended applications/ | This step in only applicable if you are using Windows. You will have to set up Windows Subsystem for Linux (WSL) to use Anaconda based installation of FEniCSx and legacy FEniCS. WSL is a virtual Linux environment within Windows which allows you to use Linux command line tools and GUI applications (GUI is natively supported on Windows 11). If you are on macOS or Linux, you can skip this step. If you are on Windows and already have installed WSL, it still might be interesting to download the recommended applications/ | ||
- | ===== Get your tools ready first ===== | + | ==== Get your tools ready first ===== |
==== PowerShell 7 ==== | ==== PowerShell 7 ==== | ||
Line 17: | Line 18: | ||
Microsoft Windows already comes with Windows PowerShell 5.1, but the modern edition of PowerShell 7 is more powerful and available on different operating systems. To learn more about this, check this: https:// | Microsoft Windows already comes with Windows PowerShell 5.1, but the modern edition of PowerShell 7 is more powerful and available on different operating systems. To learn more about this, check this: https:// | ||
- | * Install the App Installer from Microsoft App Store. That will enable the '' | + | - Install the App Installer from Microsoft App Store. That will enable the '' |
- | + | | |
- | * Open the default Windows PowerShell 5.1 as **administrator** from the Windows Start menu, then do the following: | + | - We do not recommend installing the '' |
- | < | + | |
- | + | ||
- | * This command will return the available PowerShell versions to install. We do not recommend installing the '' | + | |
- | < | + | |
==== Windows Terminal ==== | ==== Windows Terminal ==== | ||
Line 29: | Line 26: | ||
Windows Terminal is a command line tool, available on **Microsoft Store** (https:// | Windows Terminal is a command line tool, available on **Microsoft Store** (https:// | ||
- | ===== Windows Subsystem for Linux (WSL) ===== | + | ==== Windows Subsystem for Linux (WSL) ===== |
The current stable version for Windows Subsystem for Linux is WSL2 and this is the default installation. | The current stable version for Windows Subsystem for Linux is WSL2 and this is the default installation. | ||
- | + | - Open PowerShell 7.X.Y (your current installation version) as **administrator** using the Terminal app from the Windows Start menu and then type the following command: < | |
- | * Open PowerShell 7.X.Y (your current installation version) as **administrator** using the Terminal app from the Windows Start menu and then type the following command: | + | $ wsl --list --online </ |
- | < | + | |
- | This command will show you currently available Linux distributions on Windows. | + | |
- | + | $ sudo apt update && sudo apt upgrade | |
- | * Install the latest LTS version of Ubuntu which is Ubuntu 22.04.02 LTS. | + | |
- | < | + | |
- | + | ||
- | It will ask you to create an user account and set a password. The installation process is fast and straightforward. Once Ubuntu in WSL is installed, you can use it similar to a regular Ubuntu distribution. To run Ubuntu, open it from the Terminal application option. If this is your first time using Linux, you can familiarize yourself with some commands and operations from here: https:// | + | |
- | + | ||
- | * We will now update the Ubuntu distribution and install two packages for WSL virtual display settings. | + | |
- | < | + | |
$ sudo apt install xvfb libgl1-mesa-glx </ | $ sudo apt install xvfb libgl1-mesa-glx </ | ||
+ | - The first command will ask your password. Proceed as needed. To open Windows like file explorer from Ubuntu, type: < | ||
+ | - You can open the WSL home directory and browse, copy, and move files like Windows. Once you have installed Ubuntu in WSL and VS Code, you can follow these tutorials to get yourself more familiarized with the VS Code environments and capabilities in WSL: https:// | ||
- | * The first command will ask your password. Proceed as needed. To open Windows like file explorer from Ubuntu, type: | + | ==== Anaconda on Linux (WSL) and macOS ===== |
- | < | + | |
- | + | ||
- | * You can open the WSL home directory and browse, copy, and move files like Windows. Once you have installed Ubuntu in WSL and VS Code, you can follow these tutorials to get yourself more familiarized with the VS Code environments and capabilities in WSL: https:// | + | |
- | + | ||
- | To use packages and libraries install in WSL, start VS Code from Ubuntu terminal. | + | |
- | + | ||
- | ===== Anaconda on Linux (WSL) and macOS ===== | + | |
- | + | ||
- | If this is the first time you are using Python, then seat back, it is going to get confusing like this xkcd comic. Even if you are experienced in Python, you might find this interesting. | + | |
+ | If this is the first time you are using Python, then seat back, it is going to get confusing like this xkcd comic. Even if you are experienced in Python, you might find this interesting (https:// | ||
Most of the Python based libraries and packages often depend on other libraries and packages (called dependencies). Installing the right version of those packages and maintaining them is often a complex task even for experienced developers. So, we will use a popular Python distribution, | Most of the Python based libraries and packages often depend on other libraries and packages (called dependencies). Installing the right version of those packages and maintaining them is often a complex task even for experienced developers. So, we will use a popular Python distribution, | ||
+ | - This step is only for macOS. We will install '' | ||
+ | (base) $ xcode-select --install </ | ||
+ | - Download Anaconda from here based on your operating system and architecture: | ||
+ | - For WSL, you will download the installation script. Open Ubuntu terminal and use the following command to copy this script from your Windows Downloads folder to WSL home directory: < | ||
+ | - Once it is downloaded to the home directory, you can run the following command on Ubuntu terminal for installation: | ||
+ | - Please make sure to use the version you downloaded. It will ask you to read the license agreement and your permission for installation. Proceed as needed. Close the Ubuntu terminal and open it back, you will see the base environment for Anaconda is now available. This is how your terminal is going to look like: < | ||
+ | (base) $ </ | ||
+ | - Check out these operations and commands for using Conda: https:// | ||
- | * This step is only for macOS. We will install '' | + | ==== FEniCSx on Linux and macOS ===== |
- | < | + | |
- | + | ||
- | * Download Anaconda from here based on your operating system and architecture: | + | |
- | + | ||
- | * For WSL, you will download the installation script. Open Ubuntu terminal and use the following command to copy this script from your Windows Downloads folder to WSL home directory: | + | |
- | < | + | |
- | + | ||
- | * '' | + | |
- | < | + | |
- | + | ||
- | * Please make sure to use the version you downloaded. It will ask you to read the license agreement and your permission for installation. Proceed as needed. Close the Ubuntu terminal and open it back, you will see the base environment for Anaconda is now available. This is how your terminal is going to look like: | + | |
- | < | + | |
- | + | ||
- | * Check out these operations and commands for using Conda: https:// | + | |
- | + | ||
- | ===== FEniCSx on Linux and macOS ===== | + | |
As of March 2023, the latest stable release of '' | As of March 2023, the latest stable release of '' | ||
- | * Once Anaconda is properly installed, create an environment for FEniCSx. In addition to the '' | + | - Once Anaconda is properly installed, create an environment for FEniCSx. In addition to the '' |
- | < | + | (base) |
(base) | (base) | ||
- | (fenicsx) $ conda install -c conda-forge fenics-dolfinx mpich pyvista matplotlib cycler </ | + | (fenicsx) $ conda install -c conda-forge fenics-dolfinx mpich pyvista matplotlib cycler </ |
- | + | | |
- | '' | + | (fenicsx) $ conda deactivate |
- | + | ||
- | * To uninstall FEniCSx packages from Anaconda (Only do this step whenever you need to uninstall/ re-install the package), you will have to uninstall everything within the environment. Before you proceed to uninstall check if FEniCSx environment is active in the terminal. If it is active, then deactivate it first and proceed to uninstall the packages. | + | |
- | < | + | |
(base) | (base) | ||
- | (base) | + | (base) |
- | It will ask your permission; proceed as needed. FEniCSx should be completely uninstalled now. | + | ==== Legacy FEniCS on Linux and macOS (optional) ===== |
- | + | ||
- | ===== Legacy FEniCS on Linux and macOS (optional) ===== | + | |
A lots of the tutorials, examples, and published codes are still written in legacy FEniCS. So, you may want to install the legacy version in case you want to run codes written in legacy FEniCS. | A lots of the tutorials, examples, and published codes are still written in legacy FEniCS. So, you may want to install the legacy version in case you want to run codes written in legacy FEniCS. | ||
- | * Installation process is similar to FEniCSx. Since higher order mesh wasn’t a feature for legacy FEniCS, we are skipping the installation of '' | + | - Installation process is similar to FEniCSx. Since higher order mesh wasn’t a feature for legacy FEniCS, we are skipping the installation of '' |
- | < | + | (base) |
(base) | (base) | ||
(fenics) $ conda install -c conda-forge fenics matplotlib cycler </ | (fenics) $ conda install -c conda-forge fenics matplotlib cycler </ | ||
- | + | - Uninstallations procedure for FEniCS (only follow this step if you want to uninstall, skip otherwise) from Anaconda is similar to the FEniCSx package. < | |
- | * Uninstallations procedure for FEniCS (only follow this step if you want to uninstall, skip otherwise) from Anaconda is similar to the FEniCSx package. | + | (fenics) $ conda deactivate |
- | < | + | |
(base) | (base) | ||
(base) | (base) | ||
+ | ==== An alternative way to install on Ubuntu (not recommended) ===== | ||
- | ===== An alternative way to install on Ubuntu (not recommended) ===== | + | - On Ubuntu, we can also install FEniCSx using '' |
- | + | $ sudo add-apt-repository ppa: | |
- | * On Ubuntu, we can also install FEniCSx using '' | + | |
- | < | + | |
$ sudo apt update | $ sudo apt update | ||
$ sudo apt install fenicsx </ | $ sudo apt install fenicsx </ | ||
- | + | - To uninstall (Only do this step whenever you need to uninstall/ re-install the package) FEniCSx using '' | |
- | * To uninstall (Only do this step whenever you need to uninstall/ re-install the package) FEniCSx using '' | + | $ sudo apt remove fenicsx |
- | < | + | |
$ sudo apt remove --auto-remove fenicsx | $ sudo apt remove --auto-remove fenicsx | ||
$ sudo apt purge fenicsx | $ sudo apt purge fenicsx | ||
- | $ sudo apt purge --auto-remove fenicsx </ | + | $ sudo apt purge --auto-remove fenicsx </ |
- | Legacy FEniCS can be installed using this approach as well. Please make sure to use '' | + | ==== Visual Studio Code (optional but recommended) ===== |
- | + | ||
- | ===== Visual Studio Code (optional but recommended) ===== | + | |
Visual Studio Code is a cross-platform code editor from Microsoft. You can install different extensions within VS Code to enable features for code development such as remote SSH, debugging, compiling, etc. If you have another favorite IDE (e.g., Spyder or PyCharm) or code editor (e.g., Sublime text, Atom, Notepad++) you like to use, you can configure it yourself. | Visual Studio Code is a cross-platform code editor from Microsoft. You can install different extensions within VS Code to enable features for code development such as remote SSH, debugging, compiling, etc. If you have another favorite IDE (e.g., Spyder or PyCharm) or code editor (e.g., Sublime text, Atom, Notepad++) you like to use, you can configure it yourself. | ||
- | * Download VS Code from here: https:// | + | - Download VS Code from here: https:// |
- | If you want to open an empty file in your current working directory using VS Code, then type: | + | |
- | < | + | - To open a file using VS Code from the terminal, go to the directory from terminal and type: < |
+ | - Once installed, add the extension packs for Python, Remote Development, | ||
- | * To open a file using VS Code from the terminal, go to the directory from terminal and type: | + | ==== Test your FEniCSx installation ===== |
- | < | + | |
- | + | ||
- | * Once installed, add the extension packs for Python, Remote Development, | + | |
- | + | ||
- | ===== Test your FEniCSx installation ===== | + | |
We will now demonstrate how to run a simple FEniCSx example code here using VS Code. If you open Ubuntu or macOS terminal now, you will see the '' | We will now demonstrate how to run a simple FEniCSx example code here using VS Code. If you open Ubuntu or macOS terminal now, you will see the '' | ||
- | | + | |
- | * Activate the '' | + | |
- | < | + | |
- | + | (fenicsx) $ mkdir fenicsx-code | |
- | * Now you should see: | + | |
- | < | + | |
- | + | ||
- | * In case you close your terminal and reopen it, you will see the '' | + | |
- | < | + | |
(fenicsx) $ cd fenicsx-code </ | (fenicsx) $ cd fenicsx-code </ | ||
- | + | - For macOS, you can follow the same procedure to create directory. For any operating system, you can create directory somewhere else as well. Open a new file using VS Code from the Ubuntu terminal: < | |
- | * For macOS, you can follow the same procedure to create directory. For any operating system, you can create directory somewhere else as well. Open a new file using VS Code from the Ubuntu terminal: | + | |
- | < | + | |
- | + | ||
- | * Copy the following python code and save the file as '' | + | |
- | <code python> | + | |
import os | import os | ||
import numpy | import numpy | ||
Line 247: | Line 200: | ||
u_plotter.save_graphic(' | u_plotter.save_graphic(' | ||
</ | </ | ||
+ | - Now run the python code from the Ubuntu terminal: < | ||
+ | - This should return the calculated error of the finite element solution and save '' | ||
- | * Now run the python code from the Ubuntu terminal: | + | ==== A few more settings ===== |
- | < | + | |
- | (fenicsx) $ python3 poisson.py | + | |
- | </ | + | |
- | + | ||
- | * This should save '' | + | |
- | + | ||
- | ===== A few more settings ===== | + | |
If this is the first time you are setting up Python and Anaconda on macOS or WSL, you may need to follow a few more steps for smooth operation. If you have done used Anaconda + VS Code combination before, you might find some of these steps redundant. | If this is the first time you are setting up Python and Anaconda on macOS or WSL, you may need to follow a few more steps for smooth operation. If you have done used Anaconda + VS Code combination before, you might find some of these steps redundant. | ||
- | * We will now install a few more Python packages to run FEniCSx code interactively from VS Code. | + | - We will now install a few more Python packages to run FEniCSx code interactively from VS Code. < |
- | < | + | |
(fenicsx) $ conda install -c anaconda ipykernel ipywidgets | (fenicsx) $ conda install -c anaconda ipykernel ipywidgets | ||
(fenicsx) $ pip install trame | (fenicsx) $ pip install trame | ||
- | </ | + | </ |
- | + | | |
- | * '' | + | |
- | To use mesh generating software, Gmsh, Python interface library for Gmsh, PyGmsh, and mesh converted library, meshio, install the following: | + | |
- | < | + | |
(fenicsx) $ pip install --upgrade gmsh | (fenicsx) $ pip install --upgrade gmsh | ||
(fenicsx) $ pip install pygmsh | (fenicsx) $ pip install pygmsh | ||
- | (fenicsx) $ pip install meshio | + | (fenicsx) $ pip install meshio |
- | </ | + | - We will primary use VS Code + Python for FEniCSx. If you use VS Code + Python for other tasks, you may not want to set '' |
+ | - This will return all the environments within Anaconda. Copy the directory for '' | ||
+ | - On macOS, go to **Code > Settings > Settings > Extensions > Python**. Scroll down to **Default Interpreter Path** and enter '' | ||
+ | - On Windows or Linux, go to **File > Preferences > Settings > Extensions > Python**. Scroll down to **Default Interpreter Path**, click on **Also modified in Remote**, and enter '' | ||
+ | - For both macOS and WSL, scroll down further and check on the boxes for **Terminal: Activate Environment** and **Terminal: Execute In File Dir** options. These will ensure your Python environment is active and you are launching Python in the working directory when running codes from VS Code. \\ \\ | ||
+ | - This step is only for WSL. If you want to save the PyVista plots in '' | ||
+ | - Add the following block in your '' | ||
+ | export DISPLAY=: | ||
+ | export PYVISTA_OFF_SCREEN=true | ||
+ | Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & | ||
+ | sleep 1 </ | ||
+ | - Save the file and close it. Close and restart your Ubuntu terminal. | ||
+ | - When you re-open Ubuntu or macOS terminal, you will notice '' | ||
+ | - Save the file and close it. Restart your terminal. Now you should see '' | ||
+ | - This will return the following on your terminal: < | ||
- | Gmsh is an open source mesh generation tool, available on Linux, macOS, and Windows. Gmsh has API for C++, Python, Julia, etc. PyGmsh is a package built on top of Gmsh’s Python API to make mesh generation more convenient. Meshio is a package which can convert meshing files (to and from) in different formats. | + | ==== Known issues |
- | + | ||
- | * We will primary use VS Code + Python for FEniCSx. If you use VS Code + Python for other tasks, you may not want to set '' | + | |
- | < | + | |
- | (fenicsx) $ conda info --envs | + | |
- | </ | + | |
- | + | ||
- | * This will return all the environments within Anaconda. Copy the directory for '' | + | |
- | < | + | |
- | (fenicsx) $ code . | + | |
- | </ | + | |
- | + | ||
- | * On macOS, go to **Code > Settings > Settings > Extensions > Python**. Scroll down to **Default Interpreter Path** and enter '' | + | |
- | + | ||
- | * On Windows or Linux, go to **File > Preferences > Settings > Extensions > Python**. Scroll down to **Default Interpreter Path**, click on **Also modified in Remote**, and enter '' | + | |
- | + | ||
- | * For both macOS and WSL, scroll down further and check on the boxes for **Terminal: Activate Environment** and **Terminal: Execute In File Dir** options. These will ensure your Python environment is active and you are launching Python in the working directory when running codes from VS Code. | + | |
- | + | ||
- | * This step is only for WSL. If you want to save the PyVista plots in '' | + | |
- | < | + | |
- | (fenicsx) $ code ~/.bashrc | + | |
- | </ | + | |
- | + | ||
- | * Add the following block in your '' | + | |
- | < | + | |
- | export DISPLAY=:99.0 | + | |
- | export PYVISTA_OFF_SCREEN=true | + | |
- | Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & | + | |
- | sleep 1 | + | |
- | </ | + | |
- | + | ||
- | * Save the file and close it. Close and restart your Ubuntu terminal. | + | |
- | When you re-open Ubuntu or macOS terminal, you will notice '' | + | |
- | < | + | |
- | conda activate fenicsx | + | |
- | </ | + | |
- | + | ||
- | * Save the file and close it. Restart your terminal. Now you should see '' | + | |
- | < | + | |
- | (fenicsx) $ conda deactivate | + | |
- | </ | + | |
- | + | ||
- | * This will return the following on your terminal: | + | |
- | < | + | |
- | (base) $ | + | |
- | </ | + | |
- | ===== Known issues with PyVista | + | - PyVista plot window needs to be closed before proceeding to the next action (saving the file or plotting another image). To take screenshot on Windows (or WSL), use '' |
+ | - WSL on Windows 10 lacks native X-11 forwarding support. When the code is run from the terminal or a Python file from VS Code, plotting through '' | ||
+ | - If you are running the Python code interactively from VS Code on WSL, it can show the interactive plot within the Jupyter notebook environment but it has trouble saving the screenshot as '' | ||
+ | - PyVista | ||
- | * PyVista plot window needs to be closed before proceeding to the next action (saving the file or plotting another image). To take screenshot on Windows (or WSL), use '' | + | ==== Learning FEniCSx ==== |
- | * WSL on Windows 10 lacks native X-11 forwarding support. When the code is run from the terminal or a Python file from VS Code, plotting through '' | + | Since FEniCSx was released very recently, there aren't many tutorial or resources available based on FEniCSx. Please check the first two web resources which demonstrates some wonderful problems using FEniCSx. On the other hand, legacy FEniCS has numerous hands-on tutorials, books, and lecture series available. Fortunately, most of the concepts and APIs are similar between FEniCS and FEniCSx, so it shouldn't be hard to use those resources. In addition, FEniCSx developers are active in responding questions and concerns. |
- | | + | |
+ | - Numerical tours of computational mechanics with FEniCSx: https:// | ||
+ | - FEniCSx demos on the official site: https:// | ||
+ | - Legacy FEniCS demos on the official site: https:// | ||
+ | - Logg, Anders, Kent-Andre Mardal, and Garth Wells, eds. Automated solution of differential equations by the finite element method: The FEniCS book. Vol. 84. Springer Science & Business Media, 2012. (https:// | ||
+ | - Langtangen, Hans Petter, | ||
+ | - Courses offered using FEniCS: https:// | ||
- | * PyVista has trouble rendering higher order ($p \ge 2$) Quadrilateral and Hexahedron elements. For 2nd order Hexahedron element, it renders Tetrahedron. Visualization in ParaView works properly. | ||