Developing¶
Some notes about the implementation that could be of interest.
Code structure¶
The basic structure of the src folder is:
main.F90: main program. parse command line and dispatch to the corresponding toolssimulation.f90: type and routines that performs a simulationmoves.f90: interface to moves with helper routines for custom moves. Translations are implemented as well.spemoves.f90: implementation of builtin special-or-not moves (swaps, NPT etc…)core: defined base types (state: particle list, boxes etc…), helpers, trajectories…inc: files to include (to allow inlining, though one may say that IPO is enough)nrg: contains the builtin potentials, energy calculation and interfacesanalysis: contains modules to perform analysis. The usual interface of these modules is subroutinesinit,update,finish,output,free.tools: implementation of tools that are called from the command-line.
Energy calculations¶
The main interface is in src/nrg/nrg.F90. It
dispatches the energy calculations (nrg_1p for 1 particle, nrg_box for
a box) according to the algorithm (standard or celldec) and the box
type (generic, cubic etc…)
The potentials are
in potential_name.F90 files, where potential_name can be
yukawa, yukawa2, none, fennel.
In these files we have the definition of potentials, and of core functions
(potent_r, potent_r2, potent_r).
that will be used in the implementation of nrg_* routines.
Towards the end of these files we have the line:
#include "nrgimp.f90"
nrgimp.f90 contains:
- functions
nrg_1pandnrg_boxthat dispatches to all nrg_1p_ALGORITHM_BOX, nrg_box_ALGORITHM_BOX. - then a set of defines (essentially generating the function names and replacing
DIST_MIby the specialize functions). Each time a nrg_ALGORITHM.f90 file is included. Repeated for each ALGORITHM.
The nrg_ALGORITHM.f90 files (nrg_standard.f90, nrg_celldec.f90) implements
nrg_1p and nrg_box that uses generic core functions. This tricks allows
to easily lift the energy calculations for each potential, and for each algorithm,
and boxtypes.
One should note that potential files containes, at the end of type and variable definitions, the line:
#include "nrgprivs.f90"
This is necessary to make the functions included later private, so that they do not conflict with the ones of other modules.
The file nrgprivs.f90 and nrgimp.f90 are actually generated by the script gennrgimp.py.
They can be left untouched unless one wants to add another algorithm or box type.