GEFENOL Summer School on Statistical Physics and Complex Systems
Hard particle models in 2D: From soft matter to granular media
Practical session - 10 July 2026
MONTE CARLO CODE FOR HARD-RECTANGLE FLUID HRb.f90 (fortran), HRb_fast.py (python),
This code performs a Monte Carlo simulation of a fluid of hard rectangles confined into a circular cavity. It is written in fortran language. The code reads in parameters from a file HRb.par, and maybe also from HRb.inp, and outputs a number of files containing different quantities.
To compile the code use the gnu fortran compiler. In Linux:
$ gfortran -o HRb.x HRb.f90
To run:
$ ./HRb.x
In python:
$ python HRb_fast.py
The code will run until completion.
Adjust the procedure to your system and configuration.
The input HRb.par file contains the following lines (this is an example):
0
200
3, 1
0.5
100
0.1, 0.1
The first line contains an initialization code. If 0, the initial particle configuration is created by the program. If 1, the particle configuration is read in from the HRb.inp file.
The second line is the number of particles (up to a maximum of 2000).
The third line contains the sizes of the particles (L and D. Note that D is not taken to be unity, as the code was originally written for mixtures. Just set D=1).
The fourth line is the target packing fraction. In either of the input modalities the program can reach a target packing fraction, which is set here. Note that target packing fractions larger than 0.6 may be extremely difficult to reach from a previously spatially disordered configuration. Other strategies are necessary here (e.g. starting from a perfectly ordered configuration with all particles pointing up).
The output files are the following:
HRb.pl0: particle corner coordinates for initial configuration (for visualization)
HRb.rho: radial density profile
HRb.psi: radial angular profile
HRb.pl1: particle corner coordinates for final configuration (for visualization)
HRb.out: particle coordinates for final configuration
HRb.inp: particle coordinates of configuration with η=0.55
To initialize from an already equilibrated configuration, use 1 as an initialization flag and rename
HRb.out to HRb.inp, and change the target packing fraction value if desired.
The code does not calculate the global or local order parameters. It may be a great exercise for you!
To visualize the final particle configuration, use gnuplot with the following commands:
gnuplot> set size square
gnuplot> p 'HRb.pl1' w l
You can use a similar graphical software.
2026, E. Velasco and Y. Martínez-Ratón