CPL library — A minimal framework for coupled particle and continuum simulation,☆☆

https://doi.org/10.1016/j.cpc.2019.107068Get rights and content

Abstract

We present an open-source library for coupling particle codes, such as molecular dynamics (MD) or the discrete element method (DEM), and grid based computational fluid dynamics (CFD). The application is focused on domain decomposition coupling, where a particle and continuum software model different parts of a single simulation domain with information exchange. This focus allows a simple library to be developed, with core mapping and communication handled by just four functions. Emphasis is on scaling on supercomputers, a tested cross-language library, deployment with containers and well-documented simple examples. Building on this core, a template is provided to facilitate the user development of common features for coupling, such as averaging routines and functions to apply constraint forces. The interface code for LAMMPS and OpenFOAM is provided to both include molecular detail in a continuum solver and model fluids flowing through a granular system. Two novel development features are highlighted which will be useful in the development of the next generation of multi-scale software: (i) The division of coupled code into a smaller blocks with testing over a range of processor topologies. (ii) The use of coupled mocking to facilitate coverage of various parts of the code and allow rapid prototyping. These two features aim to help users develop coupled models in a test-driven manner and focus on the physics of the problem instead of just software development. All presented code is open-source with detailed documentation on the dedicated website (cpl-library.org) permitting useful aspects to be evaluated and adopted in other projects.

Program summary

Program Title: CPLLIBRARY

Program Files doi: http://dx.doi.org/10.17632/9dh8w97d2x.1

Licensing provisions: GPLv3

Programming languages: Fortran/C/C++/Python

External routines/libraries: Message Passing Interface (MPI)

Nature of problem: Coupling of particle and continuum software to enable simulations not possible with either code alone. In particular, handling communication and interaction of computational fluid dynamics (CFD) software with either molecular dynamics (MD) or discrete element method (DEM) solvers on high performance computing (HPC) platforms.

Solution method: A shared library with a minimal set of functions to enable coupling, together with an entire infrastructure to facilitate development of validated coupled software. This includes a minimal Python interface to encourage mock testing, libraries to help develop coupled tools along with pre-coupled examples including OpenFOAM, LAMMPS, Flowmol (Smith, 2014) and interactive plotting using wxPython and matplotlib.

Unusual features: Minimal interface with simple setup. A CPL_Mocks framework to facilitate debugging and test driven development. Communication established between independent executables using MPI_Open_Port, reducing required changes to core source code. Coupled codes track the git repository with validation through continuous integration testing and deployment on DockerHub. All communication based on MPI_Cart and MPI_Graph so optimisation is possible through MPI implementation on supercomputers.

Introduction

Coupled simulations have the potential to revolutionise science. Consider the flow inside a chemical reactor, countless molecules driven by waves of fluid; the turbulent thermodynamics in a boiling vessel; the evaporation at the wall essential to the transfer of heat; the multi-fractal structure of soil soaked in fluid, driving and seeping until the interplay causes the failure of an embankment dam; the flow of blood, cells and viruses driven by a cascade of fluid, but fundamentally governed by details at the molecular scale. It is clear that such simulations are not possible with one modelling paradigm alone; however the combination of different models is often an overwhelmingly difficult problem.

The modelling framework proposed here aims to couple computational fluid dynamics (CFD) to a particle method, either molecular dynamics (MD) or the discrete element method (DEM). Coupling two simulation tools is a very challenging software development problem. CFD simulations require appropriate choice of boundary conditions and numerical scheme [1], with appropriate stability and monotony considerations [2]. MD and DEM solvers require appropriate integration and force lists [3], choice of inter-atomic potentials, building of initial configurations and careful equilibration [4]. Coupling brings in the implementation of constraint algorithms [5], [6], [7], appropriate averaging methods [8], [9], [10] as well as domain termination [11] and particle insertion considerations [12]. Furthermore, both techniques are non-linear, making the origin of problems in either of the two codes very tricky to identify. CPLLIBRARY is a minimal framework to link two codes, with tools to enable the user to systematically test the software, allowing them to isolate and identify problems.

The two main application cases for CPLLIBRARY are shown graphically in Fig. 1, molecular-continuum coupling labelled (a) and overlapping DEM and continuum coupling for granular flows labelled (b). CPLLIBRARY originally focused on simulations where the domain is decomposed into two parts, as in Fig. 1 (a) a CFD and an MD region with an interface between them. This type of coupling is known as domain decomposition, an approach first applied by O’Connell [13] that has been widely adopted over the last two decades [6], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23]. Other names for this type of coupling used in the literature include geometrical coupling [24], concurrent coupling [25] or extreme scaling [26]. The two parts of the domains overlap in order to stagger the interface between them and provide a buffer to facilitate coupling. Domain decomposition coupling involves the direct exchange of mass, momentum, energy and other fields between a particle and continuum simulation, where each piece of software simulates part of the total domain [27]. Other coupling approaches are possible to link nano-scale molecular models to the macro-scale continuum, including the embedding of particle simulations into a continuum solver [28], [29] or running lower-level models to establish values for lookup tables or closure relations. These alternate approaches aim to remove elements of empiricism in higher level models, for example by calculating quantities in the MD which are then set as coefficients in the CFD, e.g. viscosity [30], [31], contact-line dynamics [32], surface tension [33] or heat flux [34]. These are outside the focus of CPLLIBRARY, which solely aims to facilitate the exchange of fields between continuum and particle simulations in the region in which they overlap.

The approach of exchanging fields is, however, applicable to granular mechanics simulations of the type shown in Fig. 1 (b), where the average of particle fields influences fluid flow features in the CFD and the resulting drag is simply applied as a force field to the particle DEM system. For this type of coupling, the theoretical foundations were set out in Anderson and Jackson (1967) [35] and is a commonly applied method for coupled fluid-granular systems with a large numbers of particles per CFD cell [36], [37], [38], [39], [40], [41], [42]. The basic premise can be considered a special case of domain-decomposition coupling in which the overlap between both codes is the whole domain. In this case, DEM and CFD model the particle and fluid parts of the granular simulation respectively.

Fig. 2 gives an overview of three types of existing coupling software. The first type of software is termed monolithic, which involves pre-packaging two pieces of software as a single application. This provides an advantage for the user as it simplifies the installation and allows a combined interface to both codes. However, a potential disadvantage is that both codes are adapted from their natural state to bring them together, so the versions are frozen at the point at which they were coupled and can no longer be used separately. Examples of monolithic codes typically occur in more applied applications, where the focus is on providing complete tools to solve engineering problems. For granular systems, open source examples include direct linking of LAMMPS-OpenFOAM [43], adaptations like SediFOAM [44] and mixed commercial open-source such as CFDEM [45].

In the second software type, libraries, all coupling is handled through shared libraries which facilitate information exchange between software. Libraries are lightweight and minimise the impact of coupling on either code, also making any exchange transparent through an explicit library call. The disadvantage is added complexity in compiling and the requirement to adapt new codes to include the libraries for each coupled application. CPLLIBRARY falls into this category. Other examples include MaMiCo [46] for Lattice Boltzmann-MD coupling and MUI [25] which allows general coupling of non-uniform grids and particle–particle coupling such as linking dissipative particle dynamics (DPD) and MD [47]. (See Fig. 2, [48], [49].)

The Final classification considered are frameworks, codes which provide a series of tools and techniques as an environment for general coupling of two or more packages. Many of these models are summarised in reviews [55], [56], [57] so they will be discussed only briefly here. The MUSCLE framework is part of pan-European projects (MAPPER) for multi-scale simulation [51]. Similarly, preCICE is a very large collaborative project, focused on fluid–solid interaction with a very comprehensive set of functionality and pre-coupled codes [54]. OASIS3 [52] aims to link various fluid projects for climate modelling. MCT [53] is a Fortran project written to link codes while MPH library allows the user to run a series of executables [58]. These frameworks aim to provide a holistic solution for multi-scale modelling and, in the longer term, may represent all-purpose solutions. However, the complexity of these frameworks can make it difficult to learn and identify the most suitable software component needed for a particular task, such as the direct topological mapping and information exchange targeted in this work.

The focus of CPLLIBRARY is direct exchange between a fluid solver and a particle solver, linking in as a lightweight library and providing direct information exchange through MPI. The key is to provide ease of implementation and testing, which in turn facilitates the use of CPLLIBRARY to enable the coupling of complex software on supercomputers with minimal knowledge of their individual coding strategy and algorithmic deployment. This manuscript outlines the key features of CPLLIBRARY in Section 2. Examples applications of CPLLIBRARY are then given in Section 3 and the four functions required in order to implement coupling are outlined. A range of validation and verification examples as well as automated tests on continuous integration (CI) platforms are discussed in the results (Section 4), followed by scaling test on supercomputers. Finally, we summarise the software in Section 5.

Section snippets

Features

As noted in a recent review [57], existing coupling tools have generally not focused on deployment, optimisation and debugging. CPLLIBRARY aims to address these shortcomings, with one-click deployment using Docker [59] containers and install scripts, along with provision of testing, debugging and visualisation tools. Together with a well-documented interface designed for collaborative development, an open-source licence, availability on version control with automated testing and minimal

Code

The CPLLIBRARY interface has been refined to four main functions: one to initialise the coupled communicator, one to set up the mapping between the two solvers, one to send and one to receive. These functions and the required input arguments are shown in Fig. 4. A wider set of helper functions exist, such as CPL_get and the various CPL_mappings functions, all documented on the CPLLIBRARY website [50]. However the minimal set of functions are sufficient to get started with a coupled simulation,

Results

In this section, some current applications are outlined, before moving on to the testing and validation of CPLLIBRARY. This includes an overview of a mocking strategy applied to coupling with suggestions for best practice coupled code development. Finally, the scaling of CPLLIBRARY is presented.

Summary

A software library is presented to facilitate coupled simulation between two MPI based codes on high performance computers, where information is exchanged between part of the domain in both codes. The focus is on a minimal and simple library, with just four key routines: initialise, set up, send and receive. Simplicity is maintained by focusing the scope of application on uniform grids, a choice which allows minimal frontend scripts and provides a backend which uses just intrinsic MPI

Declaration of Competing Interest

The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

Acknowledgements

D. Dini and E. Smith acknowledge support received via the EPSRC Established Career Fellowship (EP/N025954/1). C O’Sullivan and A Sufian were funded by EPSRC grant EP/P010393/1. E. Smith would also like to acknowledge support under both the Distributed and Embedded Computational Science and Engineering program (dCSE and eCSE respectively) as well as support from an EPSRC doctoral prize fellowship. E. Ramos-Fernandez, E. Smith, D. Dini and D. J. Trevelyan would like to acknowledge the funding

References (73)

  • WagnerG. et al.

    Comp. Phys. Comms.

    (2002)
  • WerderT. et al.

    J. Comput. Phys.

    (2005)
  • AsproulisN. et al.

    Adv. Eng. Softw.

    (2012)
  • TangY.-H. et al.

    J. Comput. Phys.

    (2015)
  • AlowayyedS. et al.

    J. Comput. Sci.

    (2017)
  • RenW. et al.

    J. Comput. Phys.

    (2005)
  • TsujiY. et al.

    Powder Technol.

    (1993)
  • XuB. et al.

    Chem. Eng. Sci.

    (1997)
  • Van WachemB. et al.

    Chem. Eng. J.

    (2003)
  • KafuiK. et al.

    Chem. Eng. Sci.

    (2002)
  • FangM. et al.

    Chem. Eng. Sci.

    (2013)
  • CosdenI.A. et al.

    Comput. Phys. Comm.

    (2013)
  • SunR. et al.

    Comput. Geosci.

    (2016)
  • NeumannP. et al.

    Comput. Phys. Comm.

    (2016)
  • BungartzH.-J. et al.

    Comput. & Fluids

    (2016)
  • BorgdorffJ. et al.

    J. Parallel Distrib. Comput.

    (2013)
  • AndersonJ.A. et al.

    J. Comput. Phys.

    (2008)
  • StroblS. et al.

    J. Comput. Phys.

    (2016)
  • Jr.J.D.A.

    Computational Fluid Dynamics

    (1995)
  • HirschC.

    Numerical Computation of Internal and External Flows

    (2007)
  • VerletL.

    Phys. Rev.

    (1967)
  • ToddB.D. et al.

    Nonequilibrium Molecular Dynamics: Theory, Algorithms and Applications

    (2017)
  • O’ConnellS.T. et al.

    Phys. Rev. E

    (1995)
  • FlekkøyE.G. et al.

    Europhys. Lett.

    (2000)
  • SmithE.R. et al.

    J. Chem. Phys.

    (2015)
  • SchofieldP. et al.

    Proc. R. Soc. Lond. Ser. A Math. Phys. Eng. Sci.

    (1982)
  • ToddB.D. et al.

    Phys. Rev. E

    (1995)
  • SmithE.R.

    Phys. Fluids

    (2015)
  • KotsalisE.M. et al.

    Phys. Rev. E

    (2007)
  • Delgado-BuscalioniR. et al.

    Eur. Phys. J. Spec. Top.

    (2015)
  • O’ConnellS.

    The Development of a Molecular Dynamics - Continuum Hybrid Computation for Modeling Fluid Flows

    (1995)
  • HadjiconstantinouN.G.

    Hybrid Atomistic Continuum Formulations and the Moving Contact-Line Problem

    (1998)
  • LiJ. et al.

    Phys. Rev. E

    (1997)
  • Delgado-BuscalioniR. et al.

    Phys. Rev. E

    (2003)
  • NieX.B. et al.

    J. Fluid Mech.

    (2004)
  • FlekkøyE.G. et al.

    Phys. Rev. E

    (2005)
  • Cited by (0)

    The review of this paper was arranged by Prof. Hazel Andrew.

    ☆☆

    This paper and its associated computer program are available via the Computer Physics Communication homepage on ScienceDirect (http://www.sciencedirect.com/science/journal/00104655)

    View full text