Nguyen Lab Wiki

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
fenicsx [2023/03/24 16:04] – [Windows Subsystem for Linux (WSL)] bdatta1fenicsx [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://fenicsproject.org.+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, FFCxand DOLFINx which are the build blocks of it. To learn more about FEniCSx: [[https://fenicsproject.org]].
  
-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 on April 2019 and its barely updated. But many tutorials and legacy codes are perhaps written in legacy FEniCS. So you may want to install a version of it. We will demonstrate installing both versions on multiple different platforms here.+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 in April 2019 and it'barely updated. But many tutorials and legacy codes are perhaps written in legacy FEniCS. So you may want to install a version of it. We will demonstrate installing both versions on multiple different platforms here
 + 
 +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://github.com/FEniCS/dolfinx]] and here for legacy FEniCS: [[https://fenicsproject.org/download/archive/]]. For both versions, our preferred approach is to install them via Anaconda.
  
-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://github.com/FEniCS/dolfinx and here for legacy FEniCS: https://fenicsproject.org/download/archive/. For both versions, our preferred approach is to install them via Anaconda. 
  
 ==== Installation on Windows ===== ==== Installation on Windows =====
Line 43: Line 44:
 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, Anaconda, to manage all the Python based libraries and relevant dependencies. Anaconda uses conda package manager and works well with pip (Python’s default package manager). Installation of Anaconda comes with popular Python packages such as NumPy, SciPy, Matplotlib, and <//insert hundred other packages here//>. It also comes with Jupyter Notebook and Spyder IDE. Anaconda also has a minimalist version, called Miniconda, which is light weight because it only includes the conda manager and a few packages. We strongly recommend installing Anaconda 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, Anaconda, to manage all the Python based libraries and relevant dependencies. Anaconda uses conda package manager and works well with pip (Python’s default package manager). Installation of Anaconda comes with popular Python packages such as NumPy, SciPy, Matplotlib, and <//insert hundred other packages here//>. It also comes with Jupyter Notebook and Spyder IDE. Anaconda also has a minimalist version, called Miniconda, which is light weight because it only includes the conda manager and a few packages. We strongly recommend installing Anaconda
  
-  - This step is only for macOS. We will install ''%%xcode%%'' command line tools to enable basic development libraries and features. On macOS terminal, type: <code> (base) $ xcode-select --install </code> +  - This step is only for macOS. We will install ''%%xcode%%'' command line tools to enable basic development libraries and features. On macOS terminal, type: <code> 
-  - Download Anaconda from here based on your operating system and architecture: https://www.anaconda.com/products/distribution. On macOS, you can download the graphical installer and install it like every other software by following the on-screen instructions. Details of the installation procedure is available here: https://docs.anaconda.com/anaconda/install/mac-os/. Alternatively, you can download the installation script and using command line to install Anaconda like Linux.  +(base) $ xcode-select --install </code> 
-  - 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: <code>$ wget https://repo.anaconda.com/archive/Anaconda3-2023.03-Linux-x86_64.sh </code> +  - Download Anaconda from here based on your operating system and architecture: https://www.anaconda.com/products/distribution. On macOS, you can download the graphical installer and install it like every other software by following the on-screen instructions. Details of the installation procedure is available here: https://docs.anaconda.com/anaconda/install/mac-os/. Alternatively, you can download the installation script and using command line to install Anaconda like Linux. \\ \\ 
-  - ''%%Anaconda3-2023.03-Linux-x86_644%%'' is the latest version of Anaconda available at the time this guide is being written. Check the available versions here: https://repo.anaconda.com/archive. Replace it wish the version you downloaded for installation. Once it is copied in the home directory, you can run the following command on Ubuntu terminal for installation: <code>$ bash Anaconda3-2022.10-Linux-x86_64.sh </code> +  - 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: <code>$ wget https://repo.anaconda.com/archive/Anaconda3-2023.03-Linux-x86_64.sh </code> ''%%Anaconda3-2023.03-Linux-x86_644%%'' is the latest version of Anaconda available at the time this guide is being written. Check the available versions here: https://repo.anaconda.com/archive. Replace it wish the version you downloaded 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: <code> (base) $  </code>+  - Once it is downloaded to the home directory, you can run the following command on Ubuntu terminal for installation: <code>$ bash Anaconda3-2022.10-Linux-x86_64.sh </code> 
 +  - 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: <code> 
 +(base) $  </code>
   - Check out these operations and commands for using Conda: https://docs.conda.io/projects/conda/en/4.6.0/_downloads/52a95608c49671267e40c689e0bc00ca/conda-cheatsheet.pdf   - Check out these operations and commands for using Conda: https://docs.conda.io/projects/conda/en/4.6.0/_downloads/52a95608c49671267e40c689e0bc00ca/conda-cheatsheet.pdf
  
Line 54: Line 57:
 As of March 2023, the latest stable release of ''%%dolfinx%%'' available via Anaconda is 0.6. If you build FEniCSx from the source, you can perhaps install 0.7. As of March 2023, the latest stable release of ''%%dolfinx%%'' available via Anaconda is 0.6. If you build FEniCSx from the source, you can perhaps install 0.7.
  
-  - Once Anaconda is properly installed, create an environment for FEniCSx. In addition to the ''%%dolfinx%%'' library, we will install ''%%mpich%%'', ''%%pyvista%%'', ''%%matplotlib%%'', and ''%%cycler%%'',. ''%%mpich%%'' allows parallel processing of different operations within FEniCSx and the other three packages are used for quick visualization. Standard installation of Anaconda already comes with these three packages but we will still need to install them inside the FEniCSx environment. <code>+  - Once Anaconda is properly installed, create an environment for FEniCSx. In addition to the ''%%dolfinx%%'' library, we will install ''%%mpich%%'', ''%%pyvista%%'', ''%%matplotlib%%'', and ''%%cycler%%''Parallel processing library ''%%mpich%%'' allows different multi-processor operations within FEniCSx and the other three packages are used for quick visualization. Standard installation of Anaconda already comes with these three packages but we will still need to install them inside the FEniCSx environment. <code>
 (base)    $ conda create -n fenicsx (base)    $ conda create -n fenicsx
 (base)    $ conda activate fenicsx (base)    $ conda activate fenicsx
Line 198: Line 201:
 </code> </code>
   - Now run the python code from the Ubuntu terminal: <code>(fenicsx) $ python3 poisson.py </code>    - Now run the python code from the Ubuntu terminal: <code>(fenicsx) $ python3 poisson.py </code> 
-  - This should save ''%%.h5%%'' and ''%%.xdmf%%'' files with the results and save the mesh and contour plot of the primary variable ''%%.pdf%%'' files in the working directory.+  - This should return the calculated error of the finite element solution and save ''%%.h5%%'' and ''%%.xdmf%%'' files with the results and save the mesh and contour plot of the primary variable ''%%.pdf%%'' files in the working directory.
  
 ==== A few more settings ===== ==== A few more settings =====
Line 233: Line 236:
   - 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 ''%%PyVista%%'' will not show the plot unless X-11 server is configured somehow. It can save the plot as ''%%.pdf, .eps, .svg, .tex, .ps%%'' file using ''%%save_graphic()%%'' function or as ''%%.png%%'' file as ''%%plotter.screenshot()%%'' function. This might not be an issue on Windows 11 as WSL natively supports X-11 forwarding (not tested yet). \\ \\   - 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 ''%%PyVista%%'' will not show the plot unless X-11 server is configured somehow. It can save the plot as ''%%.pdf, .eps, .svg, .tex, .ps%%'' file using ''%%save_graphic()%%'' function or as ''%%.png%%'' file as ''%%plotter.screenshot()%%'' function. This might not be an issue on Windows 11 as WSL natively supports X-11 forwarding (not tested yet). \\ \\
   - 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 ''%%.png%%'' file with ''%%show_edges=True%%'' option. Best is to use the ''%%save_graphic()%%'' function and save it ''%%.pdf, .eps, .svg, .tex, .ps%%'' file. \\ \\   - 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 ''%%.png%%'' file with ''%%show_edges=True%%'' option. Best is to use the ''%%save_graphic()%%'' function and save it ''%%.pdf, .eps, .svg, .tex, .ps%%'' file. \\ \\
-  - 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.+  - PyVista has trouble rendering higher order (2nd order or higher) Quadrilateral and Hexahedron elements. For 2nd order Hexahedron element, it renders Tetrahedron. Visualization in ParaView works properly. 
 + 
 +==== Learning FEniCSx ==== 
 + 
 +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. 
 + 
 +  - The FEniCx tutorial: https://jsdokken.com/dolfinx-tutorial/ 
 +  - Numerical tours of computational mechanics with FEniCSx: https://bleyerj.github.io/comet-fenicsx/index.html 
 +  - FEniCSx demos on the official site: https://docs.fenicsproject.org/dolfinx/main/python/demos.html 
 +  - Legacy FEniCS demos on the official site: https://fenicsproject.org/olddocs/dolfin/1.3.0/python/demo/index.html 
 +  - 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://doi.org/10.1007/978-3-642-23099-8) 
 +  - Langtangen, Hans Petter, and Anders Logg. Solving PDEs in python: the FEniCS tutorial I. Springer Nature, 2017. (https://doi.org/10.1007/978-3-319-52462-7) 
 +  - Courses offered using FEniCS: https://fenicsproject.org/pub/course/lectures/ 
  
DokuWiki CC Attribution-Share Alike 4.0 International