Day 9-11 Mesoscale: Introduction

Welcome to the Advanced Course on Mesoscale Modelling: we hope you will find it enjoyable and instructive. We have tried to produce a set of lectures and practical computing exercises which will teach you about the basic ideas of mesoscopic methods, their advantages (and disadvantages) and how to use them.

There are two sets of practical exercises provided in the form of Jupyter notebooks: one set on Dissipative Particle Dynamics (DPD) and the other on lattice Boltzmann (LB, or LBE for Lattice Boltzmann Equation). These exercises involving running both custom codes and the general-purpose mesoscale modelling package DL_MESO, mostly on your own laptops inside the Jupyter notebooks, although one part of the second DPD exercise requires you to run DL_MESO on SCARF. All the information to complete the exercises, links to download the notebooks, codes and input files etc. are available via the webpages.

You will need to make sure your laptop has GNU Make and Fortran, C and C++ compilers installed. All of these are readily available in Linux distributions (including WSL2 inside Windows) and on macOS via MacPorts or Homebrew: for the compilers, a recent version of the GCC compiler set should suffice, but make sure it includes gfortran and g++ as Fortran and C++ compilers.

The Python modules you will need to run the Jupyter notebooks other than those supplied with Python itself are:

  • numpy

  • docopt

  • tqdm

  • matplotlib

  • scikit-image

  • vtk

These should all be installable using pip - the exact command to install a Python module will depend on how Python is installed on your laptop, but:

python3 -m pip install numpy docopt tqdm matplotlib scikit-image vtk

is likely to work. You will also need to install the visualisation programs VMD and Paraview.

While we suggest completing the DPD exercises before the LBE exercises based on the order in which we teach the methods, students can tackle the exercises in any order that best suits their own learning objectives (e.g. if they want to concentrate on LBE over DPD).

Slides on the DPD exercises with additional hints on completing them are available to download.

More information about DL_MESO and its mesoscopic simulation methods - as well as the molecular dynamics program DL_POLY and its force-field creator DL_FIELD - can be found in the DL_Software Digital Guide. We have also included two appendices: one on the derivation of the Boltzmann equation and another on fluid mechanics. You may wish to browse any or all of these while waiting for your calculations to finish!

Please register to use DL_MESO, especially if you wish to use it after the Summer School for your research.

Hints on programming/hacking in C

The LBE exercises involve working with a couple of C codes written especially for them: compiling, running and making small modifications. The introductions to Modern Fortran and Python will hold you in good stead as far as general programming is concerned - e.g. how to render a formula - but there are a few things to remember when making changes to codes written in C.

  1. We can include system and user-defined header files with lines beginning #include, and define fixed constant values using #define lines.

  2. Functions, subroutines, for loops and if blocks are contained inside braces { and }, e.g.

for (count = 0;count < T; count++)
{         printf("%d\n",count);
            DirichletBoundaryApply1();
            propagate         ();
            Calc_obs          ();
      collide                 ();
}
  1. Functions and subroutines can either be void (no type) or be a variable type (e.g. int, float, double): if the latter, a value must be returned somewhere in the function and certainly before the end, e.g.

return 0;
  1. All C programs need to include a function called main. The function call for main can include arguments about the command-line used to launch the program: argc gives the number of arguments (including the executable command) and argv provides character strings of those arguments.

  2. Apart from for loops and if blocks, all statements - including calls to subroutines and functions - must have a semi-colon ; at the end of the line.

  3. You can either put comments between /* and */ (that can span several lines), or use two slashes // to put a comment that lasts for the remainder of a single line, e.g.

/* This is a comment */

// This is another comment
i = 0; // And here's another one

/* This is yet another comment
   that started on the line above
   and finishes on this line */
  1. As a programming shortcut, you can use a mathematical symbol immediately before an equals sign = to apply a change to the variable preceding it, e.g.

x = x + 2; // or ..
x += 2;
  1. You can increment (or decrement) a variable by using ++ (--) [1], e.g.

count++; // does the same as count = count + 1;
count--; // does the same as count = count - 1;
  1. Array indices in C start with 0 by default and finish with N-1: similar to Python, but unlike Fortran where (most of the time) they start with 1 and finish with N.

Caveat: The above is not meant as a complete guide to C programming, but it may be enough to help you with the exercises.