We need to have an editor for writing any kind of code for computations. A good editor makes the life much easier. There are very simple yet powerful editors, using colors and brackets matching to help you to write correctly, for example
Gedit (all OSes) https://wiki.gnome.org/Apps/Gedit
Notepad++ (only Windows) https://notepad-plus-plus.org/
Of course there are more sophisticated and very elegant editors (allowing to do crazy nice editing as well as really helping to write by showing variables and so on), for example
Sublime (all OSes) https://www.sublimetext.com/
Atom (all OSes) https://atom.io/
Visual Studio (all OSes) https://code.visualstudio.com/Download
A modern way of using new apps or softwares is to start them in a container. A container is technically a self running system (normally a small Linux machine) with all necessary installations and setups have been realized. The good part of a container is that the user does not install anything to the system, but downloads a huge container and runs this in the computer. The prominent container is docker, see more details under Docker web site. We will use FEniCS in a docker container such that first Docker Desktop needs to be installed,
Windows https://desktop.docker.com/win/stable/Docker%20Desktop%20Installer.exe
MacOS https://desktop.docker.com/mac/stable/Docker.dmg
Linux is where also Docker container is created such that there is not a Docker Desktop but a Docker Engine version to install . For example, step-by-step instruction for Ubuntu version https://docs.docker.com/engine/install/ubuntu/
After installing, open a PowerShell (windows), shell or terminal (linux, macos) and type
docker version
to check the version as well as type
docker run hello-world
for verifying if the docker can connect, pull a container, and print into the shell hello world!
For the direct problem, we will use finite element method. There are commercial software solutions, yet it is often challenging to implement state-of-the-art algorithms. One of the superior development as an open-source project is FEniCS and we will use it in this course.
In order to download the latest stable version of FEniCs, type in the shell
docker pull ghcr.io/scientificcomputing/fenics:2024-02-19
This will take a couple of minutes, since a huge container of many MBs are downloaded. For starting FEniCS, run in the shell
docker run -ti ghcr.io/scientificcomputing/fenics:2024-02-19
A short welcoming message like that
# FEniCS stable version image
Welcome to FEniCS/stable!
If necessary, use "ctrl + c" to get back the control. Then there is a prompt where you can run FEniCS
fenics@0521831b5f28:~$
Before @ sign, fenics is the username inside the container. It is basically a Ubuntu OS (operating system) with FEniCS installed on it. After the @ sign the number 0521831b5f28 is the CONTAINER ID that Docker has assigned. This ID is unique to the installed computer within the container and will be different in each one's own system. All Linux commands are useful
ls
for seeing a list of the directory
ls -all
for more details
pwd
to show the present working directory
cd
for changing directory
rm
to remove a file.
Use the command
exit
for exiting the container and going back to the shell of the OS.
The container is an isolated system from the OS (operating system) such that no harm can be made to the original system. In other words, we need to link directories between the OS and the container for a possible exchange. Otherwise, the container cannot read or write to the files present in the OS.
Open the PowerShell and change the directory to the current (desired) directory for linking, for example a directory on the desktop in windows (username is "johndoe" as an example)
cd C:\Users\johndoe\Desktop\compreal
Windows users may need to manually add this directory in docker.
Open Docker: Setting > Resources > File sharing > manually add the directory
In Linux (Ubuntu, Fedora, MacOS) open a terminal and use for the user "johndoe"
cd /home/johndoe/Desktop/compreal
By using mkdir this directory can be created first (or using Windows Explorer, MacOS Finder and mouse clicks).
Now, being in the current directory, run the below command for sharing files between the OS and the container
Windows:
docker run -ti -v ${PWD}:/home/fenics/shared ghcr.io/scientificcomputing/fenics:2024-02-19
Linux (Ubuntu, Fedora, RedHat, OpenSUSE, ...):
docker run -ti -v ${pwd}:/home/fenics/shared ghcr.io/scientificcomputing/fenics:2024-02-19
Linux (MacOS):
docker run -ti -v $(pwd):/home/fenics/shared ghcr.io/scientificcomputing/fenics:2024-02-19
Then, the present working directory (pwd) that is the directory compreal in the Desktop will be the same as the shared directory. If {PWD} is not working, (PWD) may do the job, or the whole directory can be written directly. This means that whatever change we do in shared within the container is also changed in the directory compreal and vice versa. Now, let us change directory to the shared
cd /home/fenics/shared
and create a new file helloworld.py in the Optimization directory with the sophisticated content
print('hello world!')
and then run it in python
python3 helloworld.py
The code is up and running in a FEniCS container in the shell.
This container is an operating system (it is a Ubuntu OS) and any software may be installed. We will need to use matplotlib and tex for coding and plotting. Installing is done by using sudo (super user do) and then apt (this is the repository where all packages are listed). Simply run first
apt update
for getting the current list of packages from the internet. Then use
apt install python3-matplotlib texlive texlive-latex-extra python3-sklearn libglu1-mesa cm-super dvipng
all these will be downloaded and installing in the correct position. Now we can run different codes. The benefit of docker is that once you close the container, all changes are lost. So it is difficult to brake the system. But this also means that once we exit this container, then all installed packages are lost. In order to commit these changes, open another powershell. Now we have two shells. On one the container is running and on the other shell we can get the info of this container by running
docker ps
which gives us the running container's ID. Use this ID to commit the changes
docker commit ID ghcr.io/scientificcomputing/fenics:2024-02-19
It is also possible to create a new image (another 2 GB will be used)
docker commit ID mynewcontainer
After committing to the existing image or creating a new image, we can exit the container and start again next time from the new image
Windows:
docker run -ti -v ${PWD}:/home/fenics/shared mynewcontainer
Linux (Ubuntu, Fedora, RedHat, OpenSUSE, ...):
docker run -ti -v ${pwd}:/home/fenics/shared mynewcontainer
Linux (MacOS):
docker run -ti -v $(pwd):/home/fenics/shared mynewcontainer
Every time a new container will be started, whatever is saved in the shared directory will remain. The rest of changes will be erased unless we commit them to the image.
Probably the best visualization tool for results is ParaView that we also heavily use in this course, see installation details in all operating systems.
A modern computer aided design (CAD) software, mesh can be exported in FEniCS compatible xml file, use the instructions to download on the web site freecad.org
Another CAD software is Salome, the mesh is exported as a med file and then converted by a python file, see instructions how to install on the web site https://www.salome-platform.org/
For running the med to h5 converter, gmsh (Linux version) needs to be downloaded from here https://gmsh.info/ and extracted next to the converter python file in the shared folder in docker. Then in the converter file the line with
needs to be amended with the version downloaded. In this way, running the converter
python3 convert_med2h5.py meshfromsalome.med
with the argument of Salome generated med will create a h5 file used in some examples.
*********************************************************** https://readthedocs.org/projects/fenics-containers/downloads/pdf/latest/
https://fenicsproject.discourse.group/
Other installation methods:
Useful Links:
https://fenicsproject.org/download/
https://fenicsproject.org/download/