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 the STFC cloud environment (apart from part of one DPD exercise on SCARF), although they can also be downloaded and run on your own laptops or desktops. All the information to complete the exercises, links to download the notebooks, codes and input files etc. are available via the webpages.
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 will already be installed in the STFC cloud environment, but if you want to run the notebooks on your own computer, these modules and the visualisation programs VMD and Paraview need to be installed.
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). That said, you will need to download the DPD exercises first to grant the last LBE exercise access to DL_MESO.
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.
We can include system and user-defined header files with lines beginning
#include
, and define fixed constant values using#define
lines.Functions, subroutines,
for
loops andif
blocks are contained inside braces{
and}
, e.g.
for (count = 0;count < T; count++)
{ printf("%d\n",count);
DirichletBoundaryApply1();
propagate ();
Calc_obs ();
collide ();
}
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;
All C programs need to include a function called
main
.Apart from
for
loops andif
blocks, all statements - including calls to subroutines and functions - must have a semi-colon;
at the end of the line.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 */
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;
You can increment (or decrement) a variable by using
++
(--
) [1], e.g.
count++; // does the same as count = count + 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.