Next Article in Journal
Scaling of Droplet Breakup in High-Pressure Homogenizer Orifices. Part II: Visualization of the Turbulent Droplet Breakup
Next Article in Special Issue
Numerical Simulations of Red-Blood Cells in Fluid Flow: A Discrete Multiphysics Study
Previous Article in Journal
Impact of Various Feed Properties on the Performance of a Control System for a Multiple Dividing Wall Column Pilot Plant
Previous Article in Special Issue
Fortran Coarray Implementation of Semi-Lagrangian Convected Air Particles within an Atmospheric Model
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

How to Modify LAMMPS: From the Prospective of a Particle Method Researcher

1
School of Chemical Engineering, University of Birmingham, Birmingham B15 2TT, UK
2
Centre for Computational Engineering Sciences, Cranfield University, Bedford MK43 0AL, UK
3
Industrial Engineering Department, Petra Christian University, Surabaya 60236, Indonesia
4
Department of Mechanical and Mechatronic Engineering, Universidad Nacional de Colombia, Bogotá 111321, Colombia
5
School of Mathematics, University of Birmingham, Edgbaston, Birmingham B15 2TT, UK
6
Department of Mechanical, Materials and Manufacturing Engineering, University of Nottingham Malaysia, Jalan Broga, Semenyih 43500, Malaysia
7
Department of Materials and Engineering, Sayens-University of Burgundy, 21000 Dijon, France
*
Authors to whom correspondence should be addressed.
ChemEngineering 2021, 5(2), 30; https://doi.org/10.3390/chemengineering5020030
Submission received: 11 January 2021 / Revised: 2 April 2021 / Accepted: 26 May 2021 / Published: 13 June 2021

Abstract

:
LAMMPS is a powerful simulator originally developed for molecular dynamics that, today, also accounts for other particle-based algorithms such as DEM, SPH, or Peridynamics. The versatility of this software is further enhanced by the fact that it is open-source and modifiable by users. This property suits particularly well Discrete Multiphysics and hybrid models that combine multiple particle methods in the same simulation. Modifying LAMMPS can be challenging for researchers with little coding experience. The available material explaining how to modify LAMMPS is either too basic or too advanced for the average researcher. In this work, we provide several examples, with increasing level of complexity, suitable for researchers and practitioners in physics and engineering, who are familiar with coding without been experts. For each feature, step by step instructions for implementing them in LAMMPS are shown to allow researchers to easily follow the procedure and compile a new version of the code. The aim is to fill a gap in the literature with particular reference to the scientific community that uses particle methods for (discrete) multiphysics.

1. Introduction

LAMMPS, acronym for Large-scale Atomic/Molecular Massively Parallel Simulator, was originally written in F77 by Steve Plimpton [1] in 1993 with the goal of having a large-scale parallel classical Molecular Dynamic (MD) code. The project was a Cooperative Research and Development Agreement (CRADA) between two DOE labs (Sandia and LLNL) and three companies (Cray, Bristol Myers Squibb, and Dupont). Since the initial release LAMMPS has been improved and expanded by many researchers who implemented many mesh-free computational methods such as Perydynamics, Smoothed particle hydrodynamics (SPH), Discrete Elemet Method (DEM) and many more [2,3,4,5,6,7,8,9,10,11].
Such a large number of computational methods within the same simulator allows researchers to easily combine them for the simulation of complex phenomena. In particular, our research group has used during the years LAMMPS in a variety of settings that go from classic Molecular Dynamics [12,13,14,15,16], to Discrete Multiphysics simulations of cardiovascular flows [17,18,19,20], Modelling drug adsorption in human organs [21,22,23,24], Cavitation [25,26,27], multiphase flow containing cells or capsules [28,29,30,31], solidification/dissolution [32,33,34], material properties [35,36] and even epidemiology [37] and coupling particles methods with Artificial Intelligence [38,39,40]. An example of a Discrete Multiphysics simulation run with the basic LAMMPS’s code is shown in Appendix A.
Thanks to its modular design open source nature and its large community, LAMMPS has been conceived to be modified and expanded by adding new features. In fact, about 95% of its source code is add-on file [41]. However, this can be a tough challenge for researcher with no to little knowledge of coding. The LAMMPS user manual [41] describes the internal structure and algorithms of the code with the intent of helping researcher to expand LAMMPS. However, due to the lack of examples of implementation and validation, the document can be hard to read for user who are not programmers. In fact, the available material is either very basic [41] or requires advanced programming skills [42,43].
The aim of this work is to provide several step-by-step examples with increasing level of complexity that can fill the gap in the middle to help and encourage researchers to use LAMMPS for discrete multiphysics and expand it with new adds on to the code that could fit their needs. In fact, most of the available material focuses on Molecular Dynamics (MD) and implicitly assumes that the reader’s background is in MD rather than other particle methods such as SPH or DEM. On the contrary, this paper is dedicated to the particle community and highlights how LAMMPS can be used and modified for methods other than MD. This goal fits particularly well with the scope of this Special Issue on “Discrete Multiphysics: Modelling Complex Systems with Particle Methods” In particular, it relates to some of the topics of the Special Issue such by exploring the potential of LAMMPS for coupling particle methods, and by sharing some “tricks of the trade” on how to modify its code that cannot be found anywhere else in the literature.
In Section 2 LAMMPS structure and hierarchy are explained introducing the concept of style. Following the LAMMPS authors advice, to avoid writing a new style from scratch, Section 3, Section 4, Section 5 and Section 6 new styles are developed using existing style are as reference. Finally, in Section 7, all the steps to write a class from scratch are shown.

2. LAMMPS Structure

After initial releases in F77 and F90, LAMMPS is now written in C++, an object oriented language that allows any programmer to exploit the class programming paradigm. The declaration of a class, including the signature of the instance variables and functions (or methods), which can be accessed and used by creating an instance of that class. The data and functions within a class are called members of the class. The definition (or implementation) of a member function can be given inside or outside the class definition.
A class has private, public, and protected sections which contain the corresponding class members.
  • The private members, defined before the keyword public, cannot be accessed from outside the class. They can only be accessed by class or “friend” functions, which are declared as having access to class members, without themselves being members. All the class members are private by default.
  • The public members can be accessed from outside the class anywhere within the scope of the class object.
  • The protected members are similar to private members but they can be accessed by derived classes or child classes while private members cannot.

2.1. Inheritance

An important concepts in object-oriented programming is that of inheritance. Inheritance allows to define a class in terms of another class and the new class inherits the members of the existing class. This existing class is called the base (or parent) class, and the new class is referred to as a subclass, or child class, or derived class.
The idea of inheritance implements the “is a” relationship. For example, Mammal IS-A Animal, Dog IS-A Mammal hence Dog IS-A Animal as well.
The inheritance relationship between the parent and the derived classes is declared in the derived class with the following syntax:
Chemengineering 05 00030 i001
The type of inheritance is specified by the access-specifier, one of public, protected, or private. If the access-specifier is not used, then it is private by default, but public inheritance is commonly used: public members of the base class become public members of the derived class and protected members of the base class become protected members of the derived class. A base class’s private members are never accessible directly from a derived class, but can be accessed through calls to the public and protected members of the base class.

2.2. Virtual Function

The signature of a function f must be declared with a virtual keyword in a base class C to allow its definition (implementation), or redefinition, in a derived class D. Then, when a derived class D object is used as an element of the base class C, and f is called, the derived class’s implementation of the function is executed.
There is nothing wrong with putting the virtual in front of functions inside of the derived classes, but it is not required, unless it is known for sure that the class will not have any children who would need to override the functions of the base class. A class that declares or inherits a virtual function is called a polymorphic class.

2.3. LAMMPS Inheritance and Class Syntax

A schematic representation of the LAMMPS inheritance tree is shown in Figure 1: LAMMPS is the top-level class for the entire code, then all the core classes, highlighted in blue, inherit all the constructors, destructors, assignment operator members, friends and private members declared and defined in LAMMPS. The core classes perform LAMMPS fundamental actions. For instance, the Atom class collects and stores all the per-atom, or per-particle, data while Neighbor class builds the neighbor lists [41].
The style classes, highlighted in reds, inherit all the constructors, destructors, assignment operator members, friends and private members declared and defined in LAMMPS and in the corresponding core class. The style classes are also virtual parents class of many child classes that implement the interface defined by the parent class. For example, the fix style has around 100 child classes.
Each style is composed of a pair of files:
  • namestyle.h
    The header of the style, where the class style is defined and all the objects, methods and constructors are declared.
  • namestyle.cpp
    Where all the objects, methods and constructors declared in the class of style are defined.
When a new style is written both namestyle.h and namestyle.cpp files need to be created.
Each “family” style has its own set of methods, declared in the header and defined in the cpp file, in order to define the scope of the style. For example, the pair style are classes that set the formula(s) LAMMPS uses to compute pairwise interactions while bond style set the formula(s) to compute bond interactions between pairs of atoms [41].
Each pair style has some recurrent functions such as compute, allocate and coeff. Although the final scope of those functions can differ for different styles, they all share a similar role within the classes.
An example of a pair style, sph/taitwater, header in LAMMPS is shown in Listing 2.
Chemengineering 05 00030 i002
All the class members are defined in the cpp file. Taking sph/taitwater pair style as reference, each method declared in Listing 2 will be defined and commented in the next sections. Although this can be style-specific, the aim is to give an overview of how the methods are defined in the cpp in LAMMPS. Albeit different style has different methods, the understanding gained can be transferred into others style, as shown in Section 3 and Section 6.

2.3.1. Constructor

Any class usually include a member function called constructors. The constructor is mechanically invoked when an object of the class is created. This allows the class to initialise members or allocate storage. Unlike the other member of the class, the constructor name must match the name of the class and it does not have a return type.
Chemengineering 05 00030 i003

2.3.2. Destructor

The role of destructors is to de-allocate the allocated dynamic memory, see Section 2.3.8, being mechanically invoked just before the end of the class lifetime. Similarly to constructors, destructors does not have a return type and have the same name as the class name with a tilde ( ) prefix.
Chemengineering 05 00030 i004

2.3.3. compute

compute is virtual member of the pair style and is one of the most relevant functions in a number of classes in LAMMPS. For instance, in pair style classes is used to compute pairwise interaction of the specific pair style. This can seen in the commented Listing 5, where the force applied on a pair of neighboring particles is derived using the Tait equation, lines 131–151. In compute all the local parameters needed to compute the pairwise interaction are declared and defined within the method.
Chemengineering 05 00030 i005a
Chemengineering 05 00030 i005b
Chemengineering 05 00030 i005c
Chemengineering 05 00030 i005d

2.3.4. settings

settings is a public void function that reads the input script checking that all the arguments of the pair style are declared. If arguments are present, settings stores them so they can be used by compute. Examples for no arguments pair style and arguments pair style input script with the corresponding settings are listed below:
  • No arguments pair style: sph/taitwater
    As described in the SPH for LAMMPS manual [6], the command line to invoke the sph/taitwater pair style is shown in Listing 6.
    Chemengineering 05 00030 i006
    In this pair style there is just a string defining the pair style, sph/taitwater, with no arguments. For this reason in settings, Listing 7, when the if statement is true (number of arguments other than zero) an error is produced.
    Chemengineering 05 00030 i007
  • Arguments pair syle: sph/rhosum
    As described in the SPH for LAMMPS manual [6], the command line to invoke the sph/rhosum pair style is shown in Listing 8.
    Chemengineering 05 00030 i008
    In this pair style there is a string defining the pair style, sph/rhosum, plus one argument, Nstep. For this reason in settings, Listing 9, when the if statement is true (number of arguments other than one) an error is produced. When the if statement is false settings assigns the value of Nstep in the variable nstep, line 5, by using the inumeric function defined in the force class.
Chemengineering 05 00030 i009

2.3.5. coeff

Similar to setting, coeff is a public void function that reads and set the coefficients used in by compute of the pair style. For each i j pair is possible to set different coefficients. The coefficients are passed in the input file with the command line pair coeff, see Listing 10. As before, examples for different pair coeff input script and the corresponding coeff are listed below:
  • sph/taitwater
    As described in the SPH for LAMMPS manual [6], the command line to invoke sph/taitwater pair coeff is shown in Listing 10.
    Chemengineering 05 00030 i010
    In total there are six arguments. Thus, in coeff, Listing 11, when if statement is true (number of arguments other than six) an error is produced. When the if statement is false coeff assigns the type of particles I and J plus the value of rho_0, c_0, alpha and h in from the string to the variables by using the numeric function defined in force class. At last, within the double for loop from line 19 to 32, the variables are assigned for each particles.
    Chemengineering 05 00030 i011
  • sph/rhosum
    As described in the SPH for LAMMPS manual [6], the syntax to invoke the command is shown in Listing 12.
    Chemengineering 05 00030 i012
    In this case there are three arguments. Thus, in the coeff, Listing 13, when the if statement is true (number of arguments other than six) an error is produced. When the error is not produced function assigns the type of particles I and J plus the value of h in the string to the variable cut_one, line 11, by using bounds and numeric function defined in force class. At last, within the double for loop from line 14 to 20, the variables are assigned for each particles.
    Chemengineering 05 00030 i013

2.3.6. init_one

init_one check if all the pair coefficients for a given i j pair have been assigned. If they were assigned the methods ensure the symmetry of the matrix.
Chemengineering 05 00030 i014

2.3.7. single

In single the force and energy of a single pairwise interaction, or single bond or angle (in case of bond or angle style), between two atoms is evalutated. The method is specifically invoked by the command line compute pair/local (or compute bond/local) to calculate properties of individual pair, or bond, interactions [41].
Chemengineering 05 00030 i015

2.3.8. allocate

allocate is a protected void function that allocates dynamic memory. The dynamic memory allocation is used when the amount of memory needed depends on user input. As explained before, at the end of the lifetime of the class, the destructors will de-allocate the memory the memory used by allocate.
Chemengineering 05 00030 i016

3. Kelvin–Voigt Bond Style

We can use what we learned in the previous section to generate a new dissipative bond potential that can be used to model viscoelastic materials. The Kelvin–Voigt model [44] is used to model viscoelastic material as a purely viscous damper and purely elastic spring connected in parallel as shown in Figure 2.
Since the two components of the model are arranged in parallel, the strain in each component is identical:
ε t o t = ε s p r i n g = ε d a m p e r .
On the other hand, the total stress σ t o t will be split into σ s p r i n g and σ d a m p e r to have ε s p r i n g = ε d a m p e r . Thus we have
σ t o t = σ s p r i n g + σ d a m p e r .
Combining Equations (1) and (2) with the constitutive relation for both the spring and the dumper, σ s p r i n g = k ε and σ d a m p e r = b ε ˙ , is possible to write that
σ = k ε ( t ) + b d ε ( t ) d t = k ε ( t ) + b ε ˙ ,
where k is the elastic modulus and b is the coefficient of viscosity. Equation (3) relates stress to strain and strain rate for a Kelvin–Voigt material [44].
Similarly to bond test to write a new pair style called bond kv we take the bond harmonic pair style as reference. The new pair style is declared and initialised in bond_kv.h and bond_kv.cpp saved in the /src/MOLECULE directory and its hierarchy is shown in Figure 3.

3.1. Validation

The bond kv pair style has been validated by Sahputra et al. [45] in their Discrete Multiphysics model for encapsulate particles with a soft outer shell.

3.2. bond_kv.cpp

All the functions will be the same as in the reference bond harmonic. However, in our new bond kv, we need to substitute the “BondHarmonic” text by a new “BondKv” text, as can be seen in Listings 17 and 18. Form now on, when we show a side-by-side comparison between the reference and the modified file, we highlight in yellow the modified lines and in red the deleted lines.
Chemengineering 05 00030 i017a
Chemengineering 05 00030 i017b
Chemengineering 05 00030 i018
Compared to the bond harmonic we are introducing a new parameter, b, from the input file. For this reason we need to modify destructor, compute, allocate, coeff, write_restart and read_restart. Following the order of function initialisation, see Listing 18, the destructor is modified as shown in Listing 20.
Chemengineering 05 00030 i019
Chemengineering 05 00030 i020
The next function to modify is compute. The strain rate, ε ˙ , can also be seen as the speed of deformation. To use it within the new pair style we need to declared and initialised the velocities of each particles, see Listing 22.
Chemengineering 05 00030 i021
Chemengineering 05 00030 i022
Moreover, inside the loop for (n = 0; n < nbondlist; n++) of the original compute, we need to add a new set of lines between the lines to calculate the spring force and the lines to calculate force and energy increment. Those lines calculate velocities and directions to compute the dashpot forces, see Listing 23.
Now is possible to write the new expression of the force applied to pair of atoms.
Chemengineering 05 00030 i023
Chemengineering 05 00030 i024
Chemengineering 05 00030 i025
With the introduction of a new parameter in the pair style we need to make a new dynamic memory allocation by modifying allocate.
Chemengineering 05 00030 i026
Chemengineering 05 00030 i027
The viscosity of the damper, b, is given by the user in the input file. For this reason, we also need to modify coeff.
Chemengineering 05 00030 i028
Chemengineering 05 00030 i029
This pair style also has the write_restart and read_restart functions that have to be modified. They basically, write and read geometry file that can be used as a support file in the input file.
Chemengineering 05 00030 i030
Chemengineering 05 00030 i031a
Chemengineering 05 00030 i031b

3.3. bond_kv.h

In the header of the new pair style we need to substitute the “BondHarmonic” text by a new “BondKv” text as well as declare a new protected member in the class, the pointer to b.
Chemengineering 05 00030 i032
Chemengineering 05 00030 i033a
Chemengineering 05 00030 i033b

3.4. Invoking kv Pair Style

Now the new pair style is completed. To run LAMMPS with the new style we need to compile it and then invoke it by writing the command lines in shown in Listing 34 in the input file.
Chemengineering 05 00030 i034

4. Noble–Abel Stiffened-Gas Pair Style

In the SPH framework is possible to determine all the particles properties by solving the particle form of the continuity equation [6,26]
d ρ i d t = j m j v i j j W i j ;
the momentum equation [6,26]
m i d v i d t = j m i m j P i ρ i + P i ρ i + Π i j j W i j ;
and the energy conservation equation [6,26]
m i d e i d t = 1 2 j m i m j P i ρ i + P i ρ i + Π i j : v i j j W i j j m i m j ρ i ρ j ( κ i + κ j ) ( T i T j ) r i j 2 r ij · j W i j .
However, to be able to solve this set of equations an Equation of State (EOS) linking the pressure P and the density ρ is needed [46]. In the user-SPH package of LAMMPS one EOS is used for the liquid (Tait’s EOS) and one for gas phase (ideal gas EOS). In this section we will implement a new EOS for the liquid phase. Note that with similar steps is also possible to implement a new gas EOS.
Le Métayer and Saurel [47] combined the “Noble–Abel” and the “Stiffened-Gas” EOS proposing a new EOS called Noble–Abel Stiffened-Gas (NASG), suitable for multiphase flow. The expression of the EOS does not change with the phase considered. For each phases, the pressure and temperature are calculated as function of density and specific internal energy, e.g.,
P ( ρ , e ) = ( γ 1 ) ( e q ) 1 ρ b γ P ,
and temperature-wise
T ( ρ , e ) = e q C v 1 ρ b P C v ,
where P, ρ , e, and q are, respectively, the pressure, the density, the specific internal energy, and the heat bond of the corresponding phase. γ , P , q, and b are constant coefficients that defines the thermodynamic properties of the fluid.
For this new pair style, called sph/nasgliquid, we take as a reference the sph/taitwater pair style declared and initialised in pair_sph_taitwater.h and pair_sph_taitwater.cpp files in the directory /src/USER-SPH. All the files regarding sph/nasgliquid must be saved in the /src/USER-SPH directory and its hierarchy is shown in Figure 4.

4.1. Validation

The sph/nasgliquid pair style has validated by Albano and Alexiadis [26] to study the Rayleigh collapse of an empty cavity.

4.2. pair_sph_nasgliquid.cpp

All the functions will be the same as in the reference sph/taitwater. However, in our new sph/nasgliquid, we need to substitute the “PairSPHTaitwater” text in “PairSPHNasgliquid”, as can be seen in Listings 35 and 36.
Chemengineering 05 00030 i035a
Chemengineering 05 00030 i035b
Chemengineering 05 00030 i036
For the sph/nasgliquid we need to pass a total of 12 arguments from the input file, while they were only six for sph/taitwater. For this reason we need to modify destructor, compute, allocate, settings and coeff. Following the order of function initialisation, see Listing 36, the destructor is modified as shown in Listing 38.
Chemengineering 05 00030 i037
Chemengineering 05 00030 i038a
Chemengineering 05 00030 i038b
In the NASG EOS the pressure is function of both density, ρ , and internal energy, e. For this reason, we need to declare more pointers and variables in compute compared to the reference pair style, see line 6 and 20 in Listing 40.
Chemengineering 05 00030 i039
Chemengineering 05 00030 i040
Another modification for compute regards the expression of the force applied to the i-th, see Listing 42, and j-th, see Listing 44, particle.
Chemengineering 05 00030 i041
Chemengineering 05 00030 i042
Chemengineering 05 00030 i043
Chemengineering 05 00030 i044
With the introduction of a new parameter in the pair style we need to make a new dynamic memory allocation by modifying allocate.
Chemengineering 05 00030 i045
Chemengineering 05 00030 i046a
Chemengineering 05 00030 i046b
The 12 arguments used in the pair style are passed by the used in the input file. For this reason, we also have to modify coeff.
Chemengineering 05 00030 i047
Chemengineering 05 00030 i048a
Chemengineering 05 00030 i048b

4.3. pair_sph_nasgliquid.h

In the header of the new pair style we need to substitute the “PairSPHTaitwater” text in “PairSPHNasgliquid” as well as declare new protected members in the class, the pointers to the new arguments.
Chemengineering 05 00030 i049
Chemengineering 05 00030 i050a
Chemengineering 05 00030 i050b

4.4. Invoking Sph/Nasgliquid Pair Style

Now the new pair style is completed. To run LAMMPS with the new style we need to compile it and then invoke it by writing the command lines shown in Listing 51 in the input file.
Chemengineering 05 00030 i051

5. Multiphase (Liquid–Gas) Heat Exchange Pair Style

In LAMMPS thermal conductivity between SPH particles is enabled using the sph/heatconduction pair style inside the user-SPH package. However, the pair style is designed only for mono phase fluid where the thermal conductivities is constant ( κ i = κ ). When more than one phase is present, the heat conduction at the interface can be implemented by using [6,26]
m i d e i d t = j m i m j ρ i ρ j ( κ i + κ j ) ( T i T j ) r i j 2 r ij · j W i j .
In the new pair style, called sph/heatgasliquid, one phase is assumed to be liquid with an initial temperature of T l , 0 and the other is assumed to be and ideal gas. Each time-step the temperature of the fluid is updated as [26].
T l = T l , 0 + E l E l , 0 C p , l ,
where T l , 0 is the reference temperature, E 0 the internal energy in [J], E l internal energy [J] at the current time step and C p , l is heat capacity of the fluid in [J K−1]. The temperature of the gas is updated following the ideal EOS [26].
T g = M M ( γ 1 ) e g R ,
where M M is the molar mass [kg kmol−1], e g is the specific internal energy in [J kg−1], γ is the heat capacity ratio and R is the ideal gas constant in [J K−1 kmol−1]. Generally the choice of the reference states E l , 0 is arbitrary, but if the Equation of State (EOS) used for the phase is function of both density and internal energy of the reference state will be determined by the EOS.
In the sph/heatgasliquid pair style is important to check if the i-th and j-th particles are liquid or gas phase to apply either Equation (10) or Equation (11). This “phase check” is explained in Section 5.2 compute function is modified.
For the energy balance the new pair style needs T l , 0 , E l , 0 , C p , l and κ l for the liquid phase and κ g for the gas phase. Moreover, for the phase check, the particle types of each phases must be specified. All this informations is passed by the user in the in the input file.
The reference pair style is sph/heatconduction. It is declared and initialised in the pair_sph_heatconduction.cpp pair_sph_heatconduction.cpp files in the directory /src/USER-SPH. All the files regarding sph/heatgasliquid must be saved in the /src/USER-SPH directory and its hierarchy is shown in Figure 5.

5.1. Validation

The sph/heatgasliquid pair style has validated by Albano and Alexiadis [26] to study the role of the heat diffusion in for a gas filled Rayleigh collapse in water.

5.2. pair_sph_heatgasliquid.cpp

All the functions will be the same as in the reference sph/heatconduction. However, in our new sph/heatgasliquid, we need to substitute the “PairSPHHeatConduction” text in “PairSPHHeatgasliquid”, as can be seen in Listings 52 and 53.
Chemengineering 05 00030 i052
Chemengineering 05 00030 i053
For the sph/heatgasliquid we need to pass a total of nine arguments from the input file, while they were only seven for sph/heatconduction. For this reason we need to modify destructor, compute, allocate, settings and coeff. Following the order of function initialisation, see Listing 53, the destructor is modified by removing the heat diffusion coefficient, line 6 in Listing 54.
Chemengineering 05 00030 i054
Chemengineering 05 00030 i055
To compute Equation (6) we need to declare more variables in compute compared to the reference pair style, see line 4 in Listing 57.
Chemengineering 05 00030 i056
Chemengineering 05 00030 i057
Another important modification is to add the phase check inside compute. The phase check has to be implemented for both the i-th particle and the j-th particle inside the loop over neighbours, for (ii = 0; ii < inum; ii++) in the reference pair style. The phase check for the i-th particle starts after the assignment of imass, line 3 of Listing 58.
Chemengineering 05 00030 i058
Similarly, for the j-th the phase check start at line 3 of Listing 59.
Chemengineering 05 00030 i059
The last change in compute is to implement the change in internal energy as shown in Equation (9).
Chemengineering 05 00030 i060
Chemengineering 05 00030 i061
With the introduction of new arguments in the pair style we need to make a new dynamic memory allocation by modifying allocate.
Chemengineering 05 00030 i062
Chemengineering 05 00030 i063
The nine arguments used in the pair style are passed by the user in the input file. For this reason, we also have to modify coeff.
Chemengineering 05 00030 i064a
Chemengineering 05 00030 i064b
Chemengineering 05 00030 i065

5.3. pair_sph_heatgasliquid.h

In the header of the new pair style we need to substitute the “PairSPHHeatConduction” text in “PairSPHHeatgasliquid” and declare new protected members in the class.
Chemengineering 05 00030 i066
Chemengineering 05 00030 i067

5.4. Invoking Sph/Heatgasliquid Pair Style

Now the new pair style is completed. To run LAMMPS with the new style we need to compile it and then invoke it by writing the command lines shown in Listing 68 in the input file.
Chemengineering 05 00030 i068

6. Full Stationary Fix Style

In LAMMPS a fix style is any operation that is applied to the system, usually to a group of particles, during time stepping or minimisation used to alter some property of the sytem [41]. There are hundreds of fixes defined in LAMMPS and new ones can be added. Usually fixes are used for time integration, force constraints, boundary conditions and diagnostics.
In the user-sph package in LAMMPS there is the so called meso/stationary fix used to set boundary condition. With meso/stationary is possible to fix position and velocity for a group of particles, walls as example, but internal energy and density will be updated. In some cases, it is useful to have a fully stationary conditions that maintains constant also the energy and the density. For this new fix, called meso/fullstationary, we take as a reference the meso/stationary fix declared and initialised in fix_meso_stationary.h and fix_meso_stationary.cpp files in the directory /src/USER-SPH. All the files regarding meso/fullstationary must be saved in the /src/USER-SPH directory and its hierarchy is shown in Figure 6.

6.1. Validation

The meso/fullstationary has been used in the validation of the new viscosity class to set the boundary condition of a constant asymmetric heated walls, see Section 7.2.

6.2. fix_meso_fullstationary.cpp

All the functions will be the same as in the reference meso/stationary. However, in our new fullstationary, we need to substitute the “FixMesoStationary” text in “FixMesoFullStationary”, as can be seen in Listings 69 and 70.
Chemengineering 05 00030 i069a
Chemengineering 05 00030 i069b
Chemengineering 05 00030 i070
For the meso/fullstationary we need to modify two function: initial_integrate, see Listing 72 line 16 and 17, and final_integrate, see Listing 74 line 14 and 15.
Chemengineering 05 00030 i071
Chemengineering 05 00030 i072
Chemengineering 05 00030 i073
Chemengineering 05 00030 i074

6.3. fix_mes_fullstationary.h

In the header of the new fix we need to substitute the “FixMesoStationary” text in “FixMesoFullStationary”.
Chemengineering 05 00030 i075
Chemengineering 05 00030 i076a
Chemengineering 05 00030 i076b

6.4. Invoking Meso/Fullstationary Fix

Now the new fix is completed. To run LAMMPS with the new style we need to compile it and then invoke it by writing the command lines shown in Listing 77 in the input file.
Chemengineering 05 00030 i077

7. Viscosity Class

Viscosity in the SPH method has been addressed with different solutions [46]. Shock waves, for example, have been a challenge to model due to the arise of numerical oscillations around the shocked region. Monaghan solved this problem with the introduction of the so-called Monaghan artificial viscosity [48]. Artificial viscosity is still used nowadays for energy dissipation and to prevent unphysical penetration for particles approaching each other [25,49]. The SPH package of LAMMPS uses the following artificial viscosity expression [6], within the sph/idealgas and sph/taitwater pair style.
Π i j = α h c i + c j ρ i + ρ j v i j · r i j r i j 2 + ϵ h 2 ,
where α is the dimensionless dissipation factor, c i and c j are the speed of sound of particle i and j. The dissipation factor, α , can be linked with the real viscosity in term of [6]
α = 8 μ c h ρ ,
where c is the speed of sound, ρ the density, μ the dynamic viscosity and h the smoothing length.
The artificial viscosity approach performs well at a high Reynolds number but better solutions are available for laminar flow: Morris et al. [50] approximated and implemented the viscosity momentum term for SPH. The same solution can be found in the sph/taitwater/morris pair style with the expression [6].
j m i m j ( μ i + μ j ) v i j ρ i ρ j 1 r i j W i j r i ,
where μ is the real dynamic viscosity.
In LAMMPS both the dissipation factor and the dynamic viscosity are treated as a constant between a pair of particles when they interact within the smoothing length. In this section we want to make the viscosity a per atom property instead of a pair property only existing within a pair style. Moreover, five temperature dependent viscosity models are added. For this example, no reference file is used; a new class, Viscosity, is implemented in LAMMPS from scratch and its hierarchy is shown in Figure 7.

7.1. Temperature Dependant Viscosity

In literature multiples empirical models that correlate viscosity with temperature are available [51,52,53]. In the new viscosity class five different viscosity models have been implemented:
1.
Andrade’s equation [54]
μ = A e x p B T + C T + D T 2 ,
where μ is the viscosity in [Kg m−1 s−1], T is the static temperature in Kelvin, A, B, C and D are fluid-dependent dimensional coefficients available in literature.
2.
Arrhenius viscosity by Raman [55,56]
μ = C 1 e x p C 2 / T ,
where μ is the dynamic viscosity in [Kg m−1 s−1], T is the temperature in Kelvin, C 1 and C 2 are fluid-dependent dimensional coefficients available in literature.
3.
Sutherland’s viscosity [57,58] for gas phase
Sutherland’s law can be expressed as:
μ = C 1 T 3 / 2 T + C 2 ,
where μ is the viscosity in [Kg m−1 s−1], T is the static temperature in Kelvin, C 1 and C 2 are dimensional coefficients.
4.
Power-Law viscosity law [57] for gas phase
A power-law viscosity law with two coefficients has the form:
μ = B T n ,
where μ is the viscosity in [Kg m−1 s−1], T is the static temperature in Kelvin, and B is a dimensional coefficient.
5.
Constant viscosity
With constant viscosity both dissipation factor and dynamic viscosity will be constant during the simulation.
When the artificial viscosity is used the dissipation factor of Equation (12) is defined as the arithmetic mean of the dissipation factors of i-th particle and j-th particle.
α i j = 4 h μ i c i ρ i + μ j c j ρ j ,
where α i j is the dissipation factor of the particles pair i and j.

7.2. Validation

In order to validate the new Viscosity class, we will study the effect of asymmetrically heating walls in a channel flow, and more specifically the effect on the velocity field of the fluid. The data obtained with our model will be compared with the analytical solution obtained by Sameen and Govindarajan [59].
The water flows between two walls in the x-direction with periodic conditions. The walls are set at different temperatures T c o l d and T h o t , see Figure 8. Both water and walls are modelled as fluid following the tait EOS. The physical properties of the walls are set constant throughout the simulation using the full stationary conditions described in Section 6.
To match the condition used by Sameen and Govindarajan we set the cold wall temperature to T c o l d = 295 K and the temperature dependence of the dynamic viscosity described by the Arrhenius model, Equation (16), with C 1 = 0.000183 [Ns m−2] and C 2 = 1879.9 K [59]. To describe the asymmetric heating Sameen and Govindarajan introduced the parameter m, defined as:
m = μ c o l d μ r e f
where μ r e f = μ h o t is the viscosity at the hot wall in the case of asymmetric heating and μ c o l d is the viscosity at the cold wall. By combining (16) and (20), with the given T c o l d , is possible to express the temperature difference of the walls Δ T as function of m.
Figure 9 shows the viscosity trend for different values of m and the corresponding Δ T . Sometimes, in particle methods, instantaneous data can be noisy (scattered) as can be seen from the blue circles of both Figure 9 and Figure 10.
In all the cases considered, the model is in good agreement with the work of Sameen and Govindarajan.
Figure 10 shows the dimensionless velocity trend for different values of m.
Again, the model is in good agreement with the analytical solution of Sameen and Govindarajan always laying within the velocity scattered points. In both our model and in the analytical solution the maximum of the velocity shifts to the right as m increases. We can conclude that our model is in good agreement with the literature, showing the typical viscosity and velocity profiles for asymmetric heating confirming the correct functionality of the new viscosity class.

7.3. New Abstract Class: Viscosity

To implement the new viscosity model a new abstract class has been created, called Viscosity. The class has no attribute, and one virtual method: compute_visc, that is used to compute the viscosity using one of the Equations (15)–(18). As usual, the Viscosity class is divided in two files, see Listings 78 and 79. As it is an abstract class, it cannot be instantiated. It is used as a base, a mold, to implement the viscosity models. All implemented viscosity classes, such as the ones implementing the Arrhenius viscosity or the Sutherland viscosity, will inherit from this class.
Chemengineering 05 00030 i078
Chemengineering 05 00030 i079a
Chemengineering 05 00030 i079b
This type of base class is called an interface, though as the code is written in C++, there is no actual difference in the implementation. The difference is only in concepts.
This structure allows for a very simple procedure to add a new viscosity type to LAMMPS, as one doesn’t have to go through all of the code everytime a new viscosity type is implemented. All that is required is to implement a new viscosity class inheriting from the Viscosity abstract class and modify the add_viscosity function. The details of the changes required for those two actions are detailed later in this section.
Another structure one might think of to implement the viscosity abstract base class would be a template. Indeed, templates are more efficient than inherited classes as inherited classes create additional virtual calls when calling the class’s methods. However, the choice of which viscosity should be called is made at runtime, and not at compile time, which means the abstract base class would be a better fit. When runtime polymorphism is needed, the structure preferred is an abstract base class.
The abstract class is not the most efficient implementation, but it allows for simplicity of use, which is important considering most of LAMMPS users are not programmers. In this work, we have chosen to sacrifice a bit of efficiency to gain ease of use.

7.4. Implementing a New Viscosity Class

In this section the steps to implement one of Equations (15)–(18) are shown, using the four parameter exponential viscosity as an example.
A new class is created that inherits from the Viscosity abstract class. The new class have as much attributes as the viscosity type has parameters. In this example that means four, as shown in the header in Listing 80.
Chemengineering 05 00030 i080
The constructor therefore should take as arguments the four parameters of the Andrade’s equation and initialise the class’s attributes with those values. The last step is to implement the compute_visc method so it returns the value of the viscosity at the given temperature. The implementation of both those functions is shown in Listing 81.
Chemengineering 05 00030 i081
Similar steps have to be taken to implement the classes corresponding to the other viscosity models, see the Supplementary material.

7.5. Processing the Viscosity in the Atom Class

In the header of the Atom class we need to include the new viscosity class and declare a new set of public members.
Chemengineering 05 00030 i082
Chemengineering 05 00030 i083
We add two new attributes in the USER-SPH section of the Atom attribute lists: viscosity, a pointer to a Viscosity object and viscosities, a pointer to an array containing the values of dynamic viscosities for all atoms at the current time step.
Chemengineering 05 00030 i084
Chemengineering 05 00030 i085
We want to be able to choose which type of viscosity is being used in the simulation from the input file, using a new command called viscosity. Let’s discuss the implementation of this feature. First we need to define the viscosity command. This is done by modifying the execute_command method of the Input class. We then define a new function called add_viscosity, whose declaration is shown in Listing 86 and definition in Listing 87. This function will have to be modified each time one wants to create a new viscosity class. In add_viscosity, the element arg[0] is the string representing the type of viscosity. For each viscosity class, the method performs the following procedure:
  • It checks which type of viscosity is asked to be created using the function strcmp on arg[0] (for Andrade’s viscosity it corresponds to line 3 of Listing 87)
  • It checks if the number of arguments is coherent with the number of parameter of the viscosity type (line 4–5)
  • It scans the coefficients of that viscosity type (line 6–10)
  • It creates the appropriate viscosity and initializes the Viscosity attribute (line 11).
This process should be followed for any new implementation.
Chemengineering 05 00030 i086
Chemengineering 05 00030 i087a
Chemengineering 05 00030 i087b
All headers of the new viscosity types implemented in the add_viscosity function need to be included in the Atom class, see Listing 88.
Chemengineering 05 00030 i088
The viscosity attribute is initialised to NULL in the constructor, see Listing 89.
Chemengineering 05 00030 i089
In the destructor of the Atom class, we add a line to delete the viscosity attribute, see Listing 90.
Chemengineering 05 00030 i090
The extract function is modified to process the viscosity attribute, see Listing 91.
Chemengineering 05 00030 i091

7.6. Using compute_Visc in SPH Pair Styles: Tait Water Implementation

The dynamic viscosity is used to compute the artificial viscosity force, that is used in the compute function of the following SPH pair style: sph/idealgas, sph/lj, sph/taitwater and sph/taitwater/morris. In this section the steps to implement compute_visc in sph/taitwater are shown, the others required a similar procedure.
The first function to modify is the destructor, as we don’t have to allocate the viscosity parameter anymore.
Chemengineering 05 00030 i092
Chemengineering 05 00030 i093a
Chemengineering 05 00030 i093b
For the same reason as the destructor we need to modify allocate.
Chemengineering 05 00030 i094
Chemengineering 05 00030 i095
Inside the compute function of the sph/taitwater pair style we need to declare a new set of variables. Where e is the energy and c v the heat capacity, now needed to calculate the temperature and thus the viscosity.
Chemengineering 05 00030 i096
The next modification is inside the loop over the j-th atom when the force induced by the artificial viscosity is calculated inside the pair’s compute function.
The dynamic viscosities μ i and μ j are calculated for each atoms, using the formula implemented in the compute_visc method. The temperature for the i-th atom is obtained using T i = e i / c v i . It is important to note that using such expression for the energy balance prevents the reference state of the internal energy to be set at 0.
The constant viscosity matrix element is replaced by the formula defined in Equation (19), see Listings 97 and 98.
Chemengineering 05 00030 i097
Chemengineering 05 00030 i098
Viscosity is now a per atom property, this means that we don’t have to pass its value then the pair style is invoked. For this reason we need to delete the viscosity related lines inside coeff.
Chemengineering 05 00030 i099a
Chemengineering 05 00030 i099b
Chemengineering 05 00030 i100
The last modification is in init_one. Again, we delete lines related to the former viscosity attribute.
Chemengineering 05 00030 i101
Chemengineering 05 00030 i102

7.7. Running the New Software with Mpirun

At this stage, the software is designed to only run in serial. Changes need to be made to make it run with Message Passing Interface (MPI). This will allow the software to run in parallel: some computations being independent from each other, they can be performed at the same time. Instead of using one processor for a long time, we will use multiple processors for a shorter period. The simulation will therefore take more computing resources but will take a lot shorter to compute. The original SPH module can already be run with MPI however as we have modified the code that is no longer true. We need to make additional changes to the software. All those changes are located in the Atom Vec Meso class of the SPH module.
In LAMMPS, the different MPI processes have to communicate with each other as the computations they perform are not completely independent from each other. They need data from other processes in order to perform their own calculations. They communicate with each other using a buffer that will contain all the necessary data. The buffer is simply an array that we will fill with the data. The different methods for packing and unpacking this buffer are defined in the Atom Vec Meso class. We need to add a new data to transmit: the calculated viscosity.
The first thing to do is to increase the size of the buffers in their initialisation so they can accept the viscosity value, an example is shown in Listings 103 and 104.
Chemengineering 05 00030 i103
Chemengineering 05 00030 i104a
Chemengineering 05 00030 i104b
Then, we added the relevant elements of the attribute viscosities to the buffer in all the methods handling buffers, an example is shown in Listings 105 and 106.
Chemengineering 05 00030 i105
Chemengineering 05 00030 i106
After making those changes for all the methods in the class, the software can be run using mpirun.

7.8. Invoking, Selecting and Computing a Viscosity Object

To compute the new viscosity a new argument was added to the compute command: viscosities. This allows the user to use the compute command to output the dynamic viscosity to the dump file. This can be done by the following command:
Chemengineering 05 00030 i107
The implementation of this feature is simple, as it is very similar to other compute argument implementation. All that needs to be done is to modify another compute’s implementation, such as compute_meso_rho_atom so it processes the variable viscosities instead of rho.
The viscosity used in the simulation can be invoked in the input file, using the following command:
Chemengineering 05 00030 i108
The type of viscosity can be chosen from the following list:
  • FourParameterExp: the four parameter exponential viscosity law.
  • SutherlandViscosityLaw: the Sutherland viscosity law.
  • PowerLawGas: the power viscosity law for gases.
  • Arrhenius: the Arrhenius viscosity law.
  • Constant: a constant viscosity.
For example, to invoke the four parameter exponential viscosity, we can write in the input file:
Chemengineering 05 00030 i109
As stated earlier, this list can easily be extended by the user by modifying the add_viscosity function defined earlier.

8. Conclusions

Particle methods are very versatile and can be applied in a variety of applications, ranging from modelling of molecules to the simulation of galaxies. Their power is even amplified when they are coupled together within a discrete multiphysics framework. This versatility matches well with LAMMPS, which is a particle simulator, whose open-source code can be extended with new functionalities. However, modifying LAMMPS can be challenging for researchers with little coding experience and the available support material on how to modify LAMMPS is either too basic or too advanced for the average researcher. Moreover, most of the available material focuses on MD; while the aim of this paper is to support researchers that use other particle methods such as SPH or DEM.
In this work, we present several examples, explained step-by-step and with increasing level of complexity. We begin with simple cases and concluding with more complex ones: Section 3 shows the implementation of the Kelvin–Voigt bond style used to model encapsulate particles with a soft outer shell and validated validated by simulating spherical homogeneous linear elastic and viscoelastic particles [45]; Section 7 show how to implement a new per-atom temperature dependant viscosity property and is validated finding the same viscosity and velocity trend shown by Sameen and Govindarajan [59] in their analytical solution for a channel flow in a asymmetrical heating walls.
The work perfectly fits in the “Discrete Multiphysics: Modelling Complex Systems with Particle Methods” special issue by sharing some in dept know-how and “trick and trades” developed by our group in years of use of LAMMPS. In fact, the aim is to support, in several ways, researchers that use computational particle methods. Often researchers tend to write their own code. The advantage of this approach is that the code is well understood by the researcher and, therefore, easily extendible. However, this sometimes implies reinventing the wheel and countless hours of debugging. Familiarity with a code like LAMMPS, which has an active community of practice and is periodically enriched with new features would be beneficial to this type of researchers allowing them to save considerable time. In the long term, there is another advantage. Modules written for in-house code are hardly sharable. At the moment, the largest portion of the LAMMPS community is dedicated to MD. While this article was under review, for instance, a new book dedicated to modifying LAMMPS came out [60]. However, it focuses only on MD and it does not mention other discrete methods like SPH or DEM. Instead, the aim of this paper is to make LAMMPS more accessible for the Discrete Multiphysics community facilitating sharing reusable code among practitioners in this field.

Supplementary Materials

The codes used in this work are freely available under the GNU General Public License v3 and can be downloaded from the University of Birmingham repository (http://edata.bham.ac.uk/560/).

Author Contributions

Conceptualization, A.A. (Andrea Albano) and A.A. (Alessio Alexiadis); methodology, A.A. (Andrea Albano); validation, A.A. (Andrea Albano), E.l.G., A.D., I.H.S. and A.R.; writing—original draft preparation, A.A. (Andrea Albano), E.l.G., A.D., I.H.S.; writing—review and editing, A.A. (Andrea Albano), A.A. (Alessio Alexiadis), C.A.D.-D., X.S., K.C.N. and M.A.; supervision, A.A. (Alessio Alexiadis), A.R. and I.M.; funding acquisition, A.A. (Alessio Alexiadis). All authors have read and agreed to the published version of the manuscript.

Funding

This work was supported by the US office of Naval Research Global (ONRG) under NICOP Grant N62909-17-1-2051.

Acknowledgments

The authors would like to thank Prof Albano (University of Pisa) for his advice and comments. The computations described in this paper were performed using the University of Birmingham’s BlueBEAR HPC service, which provides a High Performance Computing service to the University’s research community. See http://www.birmingham.ac.uk/bear for more details.

Conflicts of Interest

The authors declare no conflict of interest.

Abbreviations

The following abbreviations are used in this manuscript:
MSMolecular Dynamics
DMPDiscrete MultiPhysics
SPHSmoothed Particle Hydrodynamics
LAMMPSLarge-scale Atomic/Molecular Massively Parallel Simulator
EOSEquation Of State
LSMLattice Spring Model

Appendix A. An Example of Discrete Multiphysics Simulation in LAMMPS

In this section we present a simple case of DMP simulation with LAMMPS. It is an explanatory example deliberately simple for illustrative purposes. It involves only a small number of particles. Sensitivity analysis of the results with the model resolution or other numerical parameters are beyond the scope of this example and not carried out.
The geometry is a 2D tube with an elastic membrane at one end (Figure A1). The tube contains a liquid simulated with the SPH model, Tait EOS and Morris viscosity. The wall is simulated with stationary particles and the membrane with the LSM using Hookean springs. In Figure A1, the liquid particles are red, the wall particles blue and the membrane particles yellow. During the simulation, the fluid is subjected to a force in the x-direction that pushed the particles against the membrane. Because the membrane is elastic, it stretches inflating the right end of the tube like a balloon. The resolution of the membrane is ten times higher than the fluid. This ensures that, as the membrane stretches, fluid particles do not ‘leak’ in the gaps formed between two consecutive membrane particles. The Lennard Jones potential, truncated to consider only the repulsive part, is used to avoid compenetration between solid and liquid particles. A weaker Lennard Jones potential is used as ‘artificial pressure’ to avoid excessive compression of the fluid particles.
The initial data file (data.initial) for the geometry was create according to LAMMPS’ rules for formatting the Data File [41] and is shared as additional material. In Data File, the fluid particles are called type 1, the wall particles type 2 and the membrane particles type 3. Here we focus on the input file (membrane.lmp), which is also shared in its entirety as additional material. We do not discuss LAMMPS syntax (the reader can refer to LAMMPS User’s Guide for this [41]), but only on specific parts of the input file that concern the DMP implementation.
Figure A1. The inflating balloon simulation.
Figure A1. The inflating balloon simulation.
Chemengineering 05 00030 g0a1
The first section of the input file determines the dimensionality of the problem (2D), the boundary conditions (periodic), the units used (SI), the type of potential used in the simulation (atom_style ) and the input file that contains the initial position of all the particles
Chemengineering 05 00030 i110
The crucial line for DMP simulations is the hybrid keyword of the atom_style, which allows for combining different particle models. The keyword meso refers to the SPH model and bond, in the case under consideration, to the LSM. The angle keyword corresponds to angular springs, but, as it will be clear later, it is not used in this simulation.
The following section contains several variables that are going to be used later on. In particular, the initial particle distance is dL and their mass m. The resolution of the membrane is Nt times higher than the fluid. The initial distance between membrane particle is therefore db=dL/Nt and their mass mM=m/Nt.
Chemengineering 05 00030 i111a
Chemengineering 05 00030 i111b
The section below identifies particles type 1 as a group called fluid, particles type 2 as a group called wall and particles type 3 as a group called membrane. The mass of type 3 particles is assigned (the mass of type 1, 2 was assigned in the data.initial file). The density of all particle is also assigned based on the value rho defined previously.
Chemengineering 05 00030 i112
The next section defines the pair potentials for non-bonded particles. In this simulation, we use different styles together (keyword hybrid/overlay). The sph/taitwater/morris pair style, which is used for all pair interactions except 2-2 (i.e., wall particles with themselves); and the Lennard Jones potential lj/cut, which, as explained above, is used both as ’artificial pressure’ and to avoid compenetration of solid and fluid particles.
Chemengineering 05 00030 i113
After the non-bonded potentials, the script assigns the harmonic potential, with Hook constant kB and equilibrium distance dB, to the bonded particles (i.e., the membrane). All pairs of bonded particles are assigned in the data.initial file.
Chemengineering 05 00030 i114
The next section assigns several parameters that determine how the Newton equation of motion is solved numerically. The force fmax is added to all fluid particle in the x-direction, and an artificial viscosity is added for stability reasons.
Chemengineering 05 00030 i115
The last commands determine the value and the number of timesteps used in the simulation plus a variety of computations for output and other purposes that are not discussed here (the reader can refer to the User’s Guide).
Chemengineering 05 00030 i116

Appendix B. How to Compile LAMMPS

LAMMPS is build as a library and executable [41] either by using GNU make [61] or a build environment with CMake [62]. In this appendix LAMMPS will be compiled only using make and it is compiled in BlueBEAR. For more details of the compiling process in LAMMPS refer to the user manual [41].
To compile LAMMPS in your own directory you can follow those steps
1.
Download the file from here. Select the code you want, click the “Download Now” button, and your browser should download a gzipped tar file. Save the file in your directory on BlueBEAR
2.
Unpack the file with the following command line command prompt:
Chemengineering 05 00030 i117
3.
Before compiling is important to set up the environment, with BlueBEAR
Chemengineering 05 00030 i118
4.
Enter in the /src directory in your new LAMMPS directory. The src directory directory contains the C++ source and header files for LAMMPS. It also contains a top-level Makefile and a MAKE sub-directory with low-level Makefile.* files for many systems and machines.
5.
Type the following command to compile a serial version of LAMMPS: Chemengineering 05 00030 i119 or a multi-threaded (parallel) version of LAMMPS: Chemengineering 05 00030 i120
If you get no errors and an executable file lmp_mpi is produced.
6.
Depending on the features you need, you will have to install same packages in your compiled LAMMPS. Is possible to check which packages is installed in your compiled LAMMPS by typing
Chemengineering 05 00030 i121
It is possible to install the packages you need with the command line Chemengineering 05 00030 i122 or un-install them with Chemengineering 05 00030 i123
More make commands are explained in LAMMPS user manual [41]. After the installation of the desired packages you need to compile it again (step 5).

References

  1. Plimpton, S. Fast Parallel Algorithms for Short-Range Molecular Dynamics; Technical Report; Sandia National Labs.: Albuquerque, NM, USA, 1993.
  2. Plimpton, S.; Pollock, R.; Stevens, M. Particle-Mesh Ewald and rRESPA for Parallel Molecular Dynamics Simulations. In Proceedings of the Eighth SIAM Conference on Parallel Processing for Scientific Computing, Minneapolis, MN, USA, 14–17 March 1997. [Google Scholar]
  3. Auhl, R.; Everaers, R.; Grest, G.S.; Kremer, K.; Plimpton, S.J. Equilibration of long chain polymer melts in computer simulations. J. Chem. Phys. 2003, 119, 12718–12728. [Google Scholar] [CrossRef] [Green Version]
  4. Parks, M.L.; Lehoucq, R.B.; Plimpton, S.J.; Silling, S.A. Implementing peridynamics within a molecular dynamics code. Comput. Phys. Commun. 2008, 179, 777–783. [Google Scholar] [CrossRef] [Green Version]
  5. Petersen, M.K.; Lechman, J.B.; Plimpton, S.J.; Grest, G.S.; Veld, P.J.; Schunk, P. Mesoscale hydrodynamics via stochastic rotation dynamics: Comparison with Lennard-Jones fluid. J. Chem. Phys. 2010, 132, 174106. [Google Scholar] [CrossRef] [PubMed]
  6. Ganzenmüller, G.C.; Steinhauser, M.O.; Van Liedekerke, P.; Leuven, K.U. The implementation of Smooth Particle Hydrodynamics in LAMMPS. Paul Van Liedekerke Kathol. Univ. Leuven 2011, 1, 1–26. [Google Scholar]
  7. Jaramillo-Botero, A.; Su, J.; Qi, A.; Goddard III, W.A. Large-scale, long-term nonadiabatic electron molecular dynamics for describing material properties and phenomena in extreme environments. J. Comput. Chem. 2011, 32, 497–512. [Google Scholar] [CrossRef]
  8. Coleman, S.; Spearot, D.; Capolungo, L. Virtual diffraction analysis of Ni [0 1 0] symmetric tilt grain boundaries. Model. Simul. Mater. Sci. Eng. 2013, 21, 055020. [Google Scholar] [CrossRef]
  9. Singraber, A.; Behler, J.; Dellago, C. Library-based LAMMPS implementation of high-dimensional neural network potentials. J. Chem. Theory Comput. 2019, 15, 1827–1840. [Google Scholar] [CrossRef] [PubMed]
  10. Ng, K.; Alexiadis, A.; Chen, H.; Sheu, T. A coupled Smoothed Particle Hydrodynamics-Volume Compensated Particle Method (SPH-VCPM) for Fluid Structure Interaction (FSI) modelling. Ocean Eng. 2020, 218, 107923. [Google Scholar] [CrossRef]
  11. Daraio, D.; Villoria, J.; Ingram, A.; Alexiadis, A.; Stitt, E.H.; Munnoch, A.L.; Marigo, M. Using Discrete Element method (DEM) simulations to reveal the differences in the γ-Al2O3 to α-Al2O3 mechanically induced phase transformation between a planetary ball mill and an attritor mill. Miner. Eng. 2020, 155, 106374. [Google Scholar] [CrossRef]
  12. Qiao, G.; Lasfargues, M.; Alexiadis, A.; Ding, Y. Simulation and experimental study of the specific heat capacity of molten salt based nanofluids. Appl. Therm. Eng. 2017, 111, 1517–1522. [Google Scholar] [CrossRef]
  13. Qiao, G.; Alexiadis, A.; Ding, Y. Simulation study of anomalous thermal properties of molten nitrate salt. Powder Technol. 2017, 314, 660–664. [Google Scholar] [CrossRef]
  14. Anagnostopoulos, A.; Navarro, H.; Alexiadis, A.; Ding, Y. Wettability of NaNO3 and KNO3 on MgO and Carbon Surfaces—Understanding the Substrate and the Length Scale Effects. J. Phys. Chem. C 2020, 124, 8140–8152. [Google Scholar] [CrossRef]
  15. Sahputra, I.H.; Alexiadis, A.; Adams, M.J. Effects of Moisture on the Mechanical Properties of Microcrystalline Cellulose and the Mobility of the Water Molecules as Studied by the Hybrid Molecular Mechanics–Molecular Dynamics Simulation Method. J. Polym. Sci. Part B Polym. Phys. 2019, 57, 454–464. [Google Scholar] [CrossRef] [Green Version]
  16. Sahputra, I.H.; Alexiadis, A.; Adams, M.J. Temperature dependence of the Young’s modulus of polymers calculated using a hybrid molecular mechanics–molecular dynamics method. J. Phys. Condens. Matter 2018, 30, 355901. [Google Scholar] [CrossRef]
  17. Mohammed, A.M.; Ariane, M.; Alexiadis, A. Using Discrete Multiphysics Modelling to Assess the Effect of Calcification on Hemodynamic and Mechanical Deformation of Aortic Valve. ChemEngineering 2020, 4, 48. [Google Scholar] [CrossRef]
  18. Ariane, M.; Vigolo, D.; Brill, A.; Nash, F.; Barigou, M.; Alexiadis, A. Using Discrete Multi-Physics for studying the dynamics of emboli in flexible venous valves. Comput. Fluids 2018, 166, 57–63. [Google Scholar] [CrossRef]
  19. Ariane, M.; Wen, W.; Vigolo, D.; Brill, A.; Nash, F.; Barigou, M.; Alexiadis, A. Modelling and simulation of flow and agglomeration in deep veins valves using discrete multi physics. Comput. Biol. Med. 2017, 89, 96–103. [Google Scholar] [CrossRef] [PubMed]
  20. Ariane, M.; Allouche, M.H.; Bussone, M.; Giacosa, F.; Bernard, F.; Barigou, M.; Alexiadis, A. Discrete multi-physics: A mesh-free model of blood flow in flexible biological valve including solid aggregate formation. PLoS ONE 2017, 12, e0174795. [Google Scholar] [CrossRef] [Green Version]
  21. Schütt, M.; Stamatopoulos, K.; Simmons, M.; Batchelor, H.; Alexiadis, A. Modelling and simulation of the hydrodynamics and mixing profiles in the human proximal colon using Discrete Multiphysics. Comput. Biol. Med. 2020, 121, 103819. [Google Scholar] [CrossRef] [PubMed]
  22. Alexiadis, A.; Stamatopoulos, K.; Wen, W.; Batchelor, H.; Bakalis, S.; Barigou, M.; Simmons, M. Using discrete multi-physics for detailed exploration of hydrodynamics in an in vitro colon system. Comput. Biol. Med. 2017, 81, 188–198. [Google Scholar] [CrossRef] [PubMed]
  23. Ariane, M.; Kassinos, S.; Velaga, S.; Alexiadis, A. Discrete multi-physics simulations of diffusive and convective mass transfer in boundary layers containing motile cilia in lungs. Comput. Biol. Med. 2018, 95, 34–42. [Google Scholar] [CrossRef]
  24. Ariane, M.; Sommerfeld, M.; Alexiadis, A. Wall collision and drug-carrier detachment in dry powder inhalers: Using DEM to devise a sub-scale model for CFD calculations. Powder Technol. 2018, 334, 65–75. [Google Scholar] [CrossRef]
  25. Albano, A.; Alexiadis, A. Interaction of Shock Waves with Discrete Gas Inhomogeneities: A Smoothed Particle Hydrodynamics Approach. Appl. Sci. 2019, 9, 5435. [Google Scholar] [CrossRef] [Green Version]
  26. Albano, A.; Alexiadis, A. A smoothed particle hydrodynamics study of the collapse for a cylindrical cavity. PLoS ONE 2020, 15, e0239830. [Google Scholar] [CrossRef]
  27. Albano, A.; Alexiadis, A. Non-Symmetrical Collapse of an Empty Cylindrical Cavity Studied with Smoothed Particle Hydrodynamics. Appl. Sci. 2021, 11, 3500. [Google Scholar] [CrossRef]
  28. Alexiadis, A. The discrete multi-hybrid system for the simulation of solid-liquid flows. PLoS ONE 2015, 10, e0124678. [Google Scholar] [CrossRef] [Green Version]
  29. Alexiadis, A. A new framework for modelling the dynamics and the breakage of capsules, vesicles and cells in fluid flow. Procedia IUTAM 2015, 16, 80–88. [Google Scholar] [CrossRef] [Green Version]
  30. Alexiadis, A. A smoothed particle hydrodynamics and coarse-grained molecular dynamics hybrid technique for modelling elastic particles and breakable capsules under various flow conditions. Int. J. Numer. Methods Eng. 2014, 100, 713–719. [Google Scholar] [CrossRef]
  31. Rahmat, A.; Barigou, M.; Alexiadis, A. Deformation and rupture of compound cells under shear: A discrete multiphysics study. Phys. Fluids 2019, 31, 051903. [Google Scholar] [CrossRef]
  32. Alexiadis, A.; Ghraybeh, S.; Qiao, G. Natural convection and solidification of phase-change materials in circular pipes: A SPH approach. Comput. Mater. Sci. 2018, 150, 475–483. [Google Scholar] [CrossRef]
  33. Rahmat, A.; Barigou, M.; Alexiadis, A. Numerical simulation of dissolution of solid particles in fluid flow using the SPH method. Int. J. Numer. Methods Heat Fluid Flow 2019, 30, 290–307. [Google Scholar] [CrossRef]
  34. Rahmat, A.; Meng, J.; Emerson, D.; Wu, C.Y.; Barigou, M.; Alexiadis, A. A practical approach for extracting mechanical properties of microcapsules using a hybrid numerical model. Microfluid. Nanofluidics 2021, 25, 1–17. [Google Scholar] [CrossRef]
  35. Ruiz-Riancho, I.N.; Alexiadis, A.; Zhang, Z.; Hernandez, A.G. A Discrete Multi-Physics Model to Simulate Fluid Structure Interaction and Breakage of Capsules Filled with Liquid under Coaxial Load. Processes 2021, 9, 354. [Google Scholar] [CrossRef]
  36. Sanfilippo, D.; Ghiassi, B.; Alexiadis, A.; Hernandez, A.G. Combined Peridynamics and Discrete Multiphysics to Study the Effects of Air Voids and Freeze-Thaw on the Mechanical Properties of Asphalt. Materials 2021, 14, 1579. [Google Scholar] [CrossRef]
  37. Alexiadis, A.; Albano, A.; Rahmat, A.; Yildiz, M.; Kefal, A.; Ozbulut, M.; Bakirci, N.; Garzón-Alvarado, D.; Duque-Daza, C.; Eslava-Schmalbach, J. Simulation of pandemics in real cities: Enhanced and accurate digital laboratories. Proc. R. Soc. A 2021, 477, 20200653. [Google Scholar] [CrossRef]
  38. Alexiadis, A. Deep Multiphysics and Particle–Neuron Duality: A Computational Framework Coupling (Discrete) Multiphysics and Deep Learning. Appl. Sci. 2019, 9, 5369. [Google Scholar] [CrossRef] [Green Version]
  39. Alexiadis, A. Deep multiphysics: Coupling discrete multiphysics with machine learning to attain self-learning in-silico models replicating human physiology. Artif. Intell. Med. 2019, 98, 27–34. [Google Scholar] [CrossRef]
  40. Alexiadis, A.; Simmons, M.; Stamatopoulos, K.; Batchelor, H.; Moulitsas, I. The duality between particle methods and artificial neural networks. Sci. Rep. 2020, 10, 1–7. [Google Scholar] [CrossRef]
  41. Sandia Corporation LAMMPS Users Manual. 2003. Available online: https://lammps.sandia.gov/doc/Developer.pdf (accessed on 11 January 2021).
  42. Plimpton. LAMMPS Developer Guide. Available online: https://lammps.sandia.gov/doc/Developer.pdf (accessed on 11 January 2021).
  43. Plimpton, S.J. Modifying & Extending LAMMPS; Technical Report; Sandia National Lab. (SNL-NM): Albuquerque, NM, USA, 2014.
  44. Flügge, W. Viscoelasticity; Springer Science & Business Media: Berlin/Heidelberg, Germany, 2013. [Google Scholar]
  45. Sahputra, I.H.; Alexiadis, A.; Adams, M.J. A Coarse Grained Model for Viscoelastic Solids in Discrete Multiphysics Simulations. ChemEngineering 2020, 4, 30. [Google Scholar] [CrossRef]
  46. Liu, M.; Liu, G. Smoothed particle hydrodynamics (SPH): An overview and recent developments. Arch. Comput. Methods Eng. 2010, 17, 25–76. [Google Scholar] [CrossRef] [Green Version]
  47. Le Métayer, O.; Saurel, R. The Noble-Abel stiffened-gas equation of state. Phys. Fluids 2016, 28, 046102. [Google Scholar] [CrossRef] [Green Version]
  48. Monaghan, J.J.; Gingold, R.A. Shock simulation by the particle method SPH. J. Comput. Phys. 1983, 52, 374–389. [Google Scholar] [CrossRef]
  49. Lattanzio, J.; Monaghan, J.; Pongracic, H.; Schwarz, M. Controlling penetration. SIAM J. Sci. Stat. Comput. 1986, 7, 591–598. [Google Scholar] [CrossRef]
  50. Morris, J.P.; Fox, P.J.; Zhu, Y. Modeling low Reynolds number incompressible flows using SPH. J. Comput. Phys. 1997, 136, 214–226. [Google Scholar] [CrossRef]
  51. Cornelissen, J.; Waterman, H. The viscosity temperature relationship of liquids. Chem. Eng. Sci. 1955, 4, 238–246. [Google Scholar] [CrossRef]
  52. Seeton, C.J. Viscosity–temperature correlation for liquids. Tribol. Lett. 2006, 22, 67–78. [Google Scholar] [CrossRef]
  53. Stanciu, I. A new viscosity-temperature relationship for vegetable oil. J. Pet. Technol. Altern. Fuels 2012, 3, 19–23. [Google Scholar] [CrossRef]
  54. Gutmann, F.; Simmons, L. The temperature dependence of the viscosity of liquids. J. Appl. Phys. 1952, 23, 977–978. [Google Scholar] [CrossRef]
  55. De Guzman, J. Relation between fluidity and heat of fusion. Anales Soc. Espan. Fis. Quim 1913, 11, 353–362. [Google Scholar]
  56. Raman, C. A theory of the viscosity of liquids. Nature 1923, 111, 532–533. [Google Scholar] [CrossRef]
  57. Chapman, S.; Cowling, T.G.; Burnett, D. The Mathematical Theory of Non-Uniform Gases: An Account of the Kinetic Theory of Viscosity, Thermal Conduction and Diffusion in Gases; Cambridge University Press: Cambridge, UK, 1990. [Google Scholar]
  58. Rathakrishnan, E. Theoretical Aerodynamics; John Wiley & Sons: Hoboken, NJ, USA, 2013. [Google Scholar]
  59. Sameen, A.; Govindarajan, R. The effect of wall heating on instability of channel flow. J. Fluid Mech. 2007, 577, 417–442. [Google Scholar] [CrossRef] [Green Version]
  60. Mubin, S.; Li, J. Extending and Modifying LAMMPS; Packt Publishing Ltd.: Birmingham, UK, 2021. [Google Scholar]
  61. Project, G. Make-GNU Project-Free Software Fondation. Available online: https://www.gnu.org/software/make/ (accessed on 14 October 2020).
  62. Martin, K.; Hoffman, B. Mastering CMake: A Cross-Platform Build System; Kitware: Clifton Park, NY, USA, 2010. [Google Scholar]
Figure 1. Class hierarchy within LAMMPS source code.
Figure 1. Class hierarchy within LAMMPS source code.
Chemengineering 05 00030 g001
Figure 2. Schematic representation of Kelvin–Voigt model [44].
Figure 2. Schematic representation of Kelvin–Voigt model [44].
Chemengineering 05 00030 g002
Figure 3. Class hierarchy of the new bond style.
Figure 3. Class hierarchy of the new bond style.
Chemengineering 05 00030 g003
Figure 4. Class hierarchy of the new bond style.
Figure 4. Class hierarchy of the new bond style.
Chemengineering 05 00030 g004
Figure 5. Class hierarchy of the new pair style.
Figure 5. Class hierarchy of the new pair style.
Chemengineering 05 00030 g005
Figure 6. Class hierarchy of the new fix style.
Figure 6. Class hierarchy of the new fix style.
Chemengineering 05 00030 g006
Figure 7. Class hierarchy of the new class.
Figure 7. Class hierarchy of the new class.
Chemengineering 05 00030 g007
Figure 8. Geometry of the simulation.
Figure 8. Geometry of the simulation.
Chemengineering 05 00030 g008
Figure 9. Dimensionless viscosity profile for different m = μ c o l d / μ r e f . Blue circles are the instantaneous data in the x direction, the orange curve is the trend curve extrapolated from the instantaneous data, yellow circles are obtained form the analytical solution from Sameen and Govindarajan [59].
Figure 9. Dimensionless viscosity profile for different m = μ c o l d / μ r e f . Blue circles are the instantaneous data in the x direction, the orange curve is the trend curve extrapolated from the instantaneous data, yellow circles are obtained form the analytical solution from Sameen and Govindarajan [59].
Chemengineering 05 00030 g009
Figure 10. Dimensionless velocity profile for different m = μ c o l d / μ r e f . Blue circles are the instantaneous data in the x direction, the orange curve is the trend curve extrapolated from the instantaneous data, yellow circles are obtained form the analytical solution from Sameen and Govindarajan [59].
Figure 10. Dimensionless velocity profile for different m = μ c o l d / μ r e f . Blue circles are the instantaneous data in the x direction, the orange curve is the trend curve extrapolated from the instantaneous data, yellow circles are obtained form the analytical solution from Sameen and Govindarajan [59].
Chemengineering 05 00030 g010
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

Albano, A.; le Guillou, E.; Danzé, A.; Moulitsas, I.; Sahputra, I.H.; Rahmat, A.; Duque-Daza, C.A.; Shang, X.; Ching Ng, K.; Ariane, M.; et al. How to Modify LAMMPS: From the Prospective of a Particle Method Researcher. ChemEngineering 2021, 5, 30. https://doi.org/10.3390/chemengineering5020030

AMA Style

Albano A, le Guillou E, Danzé A, Moulitsas I, Sahputra IH, Rahmat A, Duque-Daza CA, Shang X, Ching Ng K, Ariane M, et al. How to Modify LAMMPS: From the Prospective of a Particle Method Researcher. ChemEngineering. 2021; 5(2):30. https://doi.org/10.3390/chemengineering5020030

Chicago/Turabian Style

Albano, Andrea, Eve le Guillou, Antoine Danzé, Irene Moulitsas, Iwan H. Sahputra, Amin Rahmat, Carlos Alberto Duque-Daza, Xiaocheng Shang, Khai Ching Ng, Mostapha Ariane, and et al. 2021. "How to Modify LAMMPS: From the Prospective of a Particle Method Researcher" ChemEngineering 5, no. 2: 30. https://doi.org/10.3390/chemengineering5020030

APA Style

Albano, A., le Guillou, E., Danzé, A., Moulitsas, I., Sahputra, I. H., Rahmat, A., Duque-Daza, C. A., Shang, X., Ching Ng, K., Ariane, M., & Alexiadis, A. (2021). How to Modify LAMMPS: From the Prospective of a Particle Method Researcher. ChemEngineering, 5(2), 30. https://doi.org/10.3390/chemengineering5020030

Article Metrics

Back to TopTop