This is a showcase of a recent project I worked on with colleagues from our mathematics department. In addition to describing the mathematical techniques we used, I want to demonstrate how mathematics can be used to gain insight in real life situations.
I have tried to make this post as accessible as possible. If you are interested in the details; a paper is under way and as soon as a preprint is finished, I will make it available here as well.
The municipality of a small German city approached us regarding the following issue. Nitric oxides are air polluting chemicals emitted by motor vehicles and are, among others, harmful to the ozone layer. In a framework of measures to reduce the air pollution, the municipality had decided to install photovoltaic asphalt, asphalt coated with a special substance that actively converts nitric oxides like $\textrm{NO}$ and $\textrm{NO}_2$ to nitrate ($\textrm{NO}_3^-$), which clings to the surface of the asphalt until the rain washes it away. Because these nitrates are not airborne, air pollution is reduced.
Due to extensive measurements, there was a lot of information available on $\textrm{NO}$ concentration prior to, as well as after the installation of the new asphalt.
Their question was if we could estimate the influence of the different environmental measures in this particular scenario, to help them make future decisions based on a validated approach. To answer this question, we created a mathematical model that incorporated the major elements that play a role in this process, so that different scenarios could be explored and emission reducing measures could be compared.
Read MoreAnts are funny creatures. In spite of their (seemingly) limited cognitive and sensory abilities, they are able to build large complex structures, fight off enemy colonies, and collectively carry large objects.
Ants are able to communicate by giving off pheromones, a chemical that triggers a reaction once picked up by another ant. One of the ways pheromones come into play is when ants spread out to forage for food. Once they find a food source, they carry it back to the nest, all the while leaving a pheromone trail that will lead other ants to the same location. Because of the way the pheromone is deposited, ants are able to construct the shortest route to the food source without prior information about the layout of their environment.
Although inherently a biological question, various mathematicians have tried to express this behaviour in mathematical structures, and not without success. I implemented one of these concepts in Python. You can download it here.
Read MoreTo support my research in crowd dynamics models, I am developing a simulation framework: Mercurial. The aim is to simplify the testing of new models and see how they perform in different scenarios. At this stage, the framework is still a prototype, but I try to keep it as accessible and maintainable as possible.
Mercurial is written in Python 3. This makes for rapid prototyping, but can become a computational burden if not designed with caution. Therefore, almost all intensive computations are vectorised using the NumPy library or are deferred to a lower level implementation in Fortran.
In the rest of this post I describe the structure of the simulation. Information on how to install and use it can be found here.
Read MoreThis is the first post in a series of entries on the modelling of crowd dynamics.
In this post I give a short introduction into a topic of my research: crowd dynamics. Crowd dynamics is a very multidisciplinary field of research; contributions come from a great many fields in social science and natural science. I will be sticking to my background and focus mainly on mathematical, physical and computer-science aspects. For the interested reader I have included links to Wikipedia pages of related concepts.
Crowd dynamics is the term used for describing the behaviour and interaction of groups of people moving in a certain environment. The main goal of crowd dynamics research is to identify the factors that control these dynamics (analysis), and to be able to predict crowd motion in new scenarios (simulation).
As you can imagine, crowd simulation serves many purposes, like
The dynamics of crowds vary from situation to situation. Pedestrians in traffic have different goals and therefore different patterns than people in shopping malls. Compare across cultures, and you will find even more diversity. This makes the modelling and simulation of crowds a challenge that requires more than just a mathematical understanding of how people move from A to B.
Read MoreIPython is an alternative to the default Python interpreter. It was created to make scripting and prototyping in the programs in the Python language more easy and has gradually developed new technologies to improve Python, as well as other programming languages. Some of its key features are syntax highlighting and tab completion for variables, modules and files in an interactive Python session, and notebooks that allow a mixture of code, output, and descriptions (see for instance this one).
You can install IPython through your package manager (e.g. pip
or conda
).
IPython has loads of options. Although it is well documented, the manual is so long I postponed reading it for years.
Now that I did, I decided it was time to share the highlights that improved my workflow.
I recently finished a Python module for computing weighted or generalized distance transforms (available here. I needed it for the motion planner in my crowd simulation Mercurial and I couldn’t find it online, so I implemented it in Fortran so F2PY could wrap it for me. This post goes into details of the algorithm and how to use the module.
Read MoreThis post elaborates on a couple of ways to install Python libraries Numpy/Scipy/Matplotlib for Linux and Mac. This is something I seem to have to do every so often, and although the process should be straightforward, the details elude me each time. May this serve as a reminder to future me (and others).
Note: For all platforms (including Windows) it is possible to install compiled binaries as well. I won’t go into this here, because I prefer the use of package managers. They take care of compiling the software, putting it in the right place and updating so you don’t have to worry about it.
Read MoreNo formulas or commands in this post. Instead, I uploaded a couple of video clips I recorded in various places, showcasing dynamics in different kinds of populations. They are a bit amateurish, but they should be able to demonstrate the complexity present in population dynamics. Each scenario has a bit of context describing a mathematical model associated with it.
The first clip was shot in the Shibuya crossing in Tokyo, Japan. It is known for being one of the most crowded intersections in the world. Two special features of the crossing: it has more than 4 lanes, and the traffic lights give way to pedestrians from all directions at the same time.
Looking at the video, the pedestrians barely seem to be hindered by the multitude of conflicting directions.
Read MoreThis notebook provides a demonstration of the Finite Element Method, a technique to obtain a numerical solution of a partial differential equation. This is by no means a complete introduction, but serves more as a numerical example of how the technique works in practice. For more detail on the mathematics behind it, there are numerous books and resources online; for open-source implementations, you can check out FEniCS, DUNE, deal.II and many others.
We are looking for the solution to the partial differential equation
on a domain $\Omega$. Here, $\Delta$ is the Laplace operator and $f$ is a known function. We assume that on the boundary of our domain $\partial \Omega$, $u$ takes value $0$.
Read MoreA while back, I discovered a couple of command-line image manipulation tools: ImageMagick and FFmpeg. They fit nicely in my simulation development workflow, and take a lot of pain out of reproducing graphic output. Put the commands in a script, and it’s easy to re-obtain images and movies after running simulations with different parameters.
To use convert
, install the ImageMagick toolbox. For ffmpeg
, install the FFmpeg library. On Ubuntu:
sudo apt-get install imagemagick
sudo apt-get install ffmpeg
Binaries are also available for Windows and Mac.
Below follows a list of examples I find useful. All commands are valid bash
/zsh
.
In a previous post, I discussed extending: how to build custom Fortran modules you can run in a Python script. If you just want to post-process or plot your Fortran results, you can opt to simply output your data in a readable format, so that you can read it in other languages (e.g. Python, Matlab, C++).
This post lists three ways to output Fortran data: the quick way, the classic way, and the sustainable way.
Read MoreIf you use Python for scientific programming you’ll probably find that as long as you can use NumPy, SciPy, and other optimized libraries, scripts can be developed and executed swiftly.
The routines from these libraries are often composed in low-level programming languages (like C or assembly), avoiding the overhead from the dynamic and interpreted nature of Python.
However, it can happen that some of the algorithms you are implementing require operations not supported in these libraries. For example: if you use NumPy, but run into an algorithm that is difficult to expressed in a vectorized form, you might have to resort to pure Python. This can become a huge bottleneck in the execution of your script.
It is possible to create your own Python module from a lower-level programming language. This is called extending Python. This means you write the bottleneck algorithm in the low-level language, compile it in a Python-friendly way and use it in your script like any other module. This post shows how to use the tool F2PY from SciPy to create an extension from Fortran.
Read MoreRecently, I wrote something about my graduation project. Part of this project was the development of a simulation framework, Mercurial. The goal of Mercurial is to facilitate the implementation of different hybrid particle simulation methods, and to test them on simple but existing use cases with different environments. You can find the code on GitHub here, together with instructions on how to use it.
If you are interested in the structure of the code, check this post. This simulation was also used in my research internship at LOC7000, to evaluate evacuation scenarios on Dutch music festival Lowlands and see if the safety measures could be analyzed in a quantitative manner.
The framework is built in Python. The simulation creates an environment from a scene file and reads in the parameters from a configuration file. Alternatively, a simple drawing tool is included to create new environments.
Read MoreIn the first post on my blog, I return to the graduation project I did during my master’s: Large-scale multiscale particle models in inhomogeneous domains: modelling and implementation. I wrote the thesis at the Eindhoven University of Technology (The Netherlands) and was supervised by Adrian Muntean and Andrei Jalba. You can download the report here.
To support the analysis and investigate how the model holds up in practice, we developed a simulation framework in Python, called Mercurial. You can find it on GitHub here. More details about the simulation are found in this post.
Read Moresubscribe via RSS