Simulation of eigenvalue optimization.
In this article I provide a source code similar to the one that have been used to perform the simulations in this project. The original source code was too messy to be shared and useful to anybody, but thanks to the joint work of Gregoire Allaire, Charles Dapogny, Florian Feppon and Pascal Frey, I am able to provide a way cleaner code. Indeed, they put online code examples for shape and topology optimization written in FreeFem and Python, called SOTuto.
This little library uses FreeFem to solve the Finite Element stuff and articulates the different FreeFem scripts by calling them via Python. Whereas it can seem a bit complex in the begining since there is a lot of different files for each project, it quickly become easy to modify the existing files to adapt to your favorite problem. That is exactly what I did in this project.
Installation and setup
You can find the source code of the project here. You will have to install Python and FreeFem first. Make sure that FreeFem has been added to your PATH variable by typing FreeFem++ -? in you favorite terminal. You should obtain something like
FreeFem++ - version 4.12 (Tue Dec 6 19:14:11 CET 2022 - git v4.12) 64bits License: LGPL 3+ (https://www.gnu.org/licenses/lgpl-3.0.en.html) Usage: FreeFem++ [FreeFEM arguments] filename [script arguments] FreeFEM arguments: -f: [filename] script file name -v: [verbosity] level of FreeFEM output (0 - 1000000) ...
Once you installation is ok, you have to clone the git repository.
To do this, first make sure you have Git installed on your computer by typing git in the terminal. Then go in the folder you want to
download the sources, open a terminal inside it and type
git clone https://github.com/EloiMartinet/NeumannFreeFem.git
You should now see a new folder named NeumannFreeFem. Go inside it by typing
cd NeumannFreeFem
You will find a folder named sources. This is where all the scripts necessary are.
Finally, to visualize the results, you will need a software called Medit. You can download it on the webpage of the author as well as the documentation.
Run the project
To run the project, you just have to type
python3 sources/main.py
This will create a new folder named res in the NeumannFreeFem one. When the optimization is finished (which may
take several minutes), you can visualize the results by typing
medit res/step -a 1 1000
This command tells medit to animate all the files named res/step.*.mesh and res/step.*.sol. When the medit window opens
press m to make the colors appear and l to hide the mesh. Finally, right click and in the menu go
to Animate > Play Sequence. You should see the different iterations of the algorithm, like this :
File structure and roles
In the source folder, the file that articulates all the other ones together is main.py. The configuration of the project can be changed in the file path.py where you can control the mesh size, number of iterations, gradient step size, regularization parameters etc.
I will surely do a more detailed tutorial on this when I wil have more time.