Merge remote-tracking branch 'github/master' into coul_tt

This commit is contained in:
Axel Kohlmeyer
2020-09-28 13:56:00 -04:00
307 changed files with 9323 additions and 5453 deletions

View File

@ -2,3 +2,7 @@
*.d
*.a
*~
liblammps.mod
simpleC
simpleCC
simpleF

View File

@ -8,16 +8,14 @@ code to perform a coupled calculation.
simple.cpp is the C++ driver
simple.c is the C driver
simple.f90 is the Fortran driver
libfwrapper.c is the Fortran-to-C wrapper
The 3 codes do the same thing, so you can compare them to see how to
drive LAMMPS from each language. See lammps/python/example/simple.py
to do something similar from Python. The Fortran driver requires an
additional wrapper library that interfaces the C interface of the
LAMMPS library to Fortran and also translates the MPI communicator
from Fortran to C.
drive LAMMPS from each language. See python/example/simple.py
to do something similar from Python. The Fortran driver requires a
Fortran module that uses the Fortran 03 ISO_C_BINDING module to
interface the LAMMPS C library functions to Fortran.
First build LAMMPS as a library (see examples/COUPLE/README), e.g.
First build LAMMPS as a library (see examples/COUPLE/README), e.g.
make mode=shlib mpi
@ -26,27 +24,23 @@ these, which include paths to the LAMMPS library interface, and
linking with FFTW (only needed if you built LAMMPS as a library with
its PPPM solver).
This builds the C++ driver with the LAMMPS library using the mpiCC
This builds the C++ driver with the LAMMPS library using the mpicxx
(C++) compiler:
mpiCC -I/home/sjplimp/lammps/src -c simple.cpp
mpiCC -L/home/sjplimp/lammps/src simple.o -llammps -lfftw -o simpleCC
mpicxx -I/home/sjplimp/lammps/src -c simple.cpp
mpicxx -L/home/sjplimp/lammps/src simple.o -llammps -o simpleCC
This builds the C driver with the LAMMPS library using the mpicc (C)
compiler:
mpicc -I/home/sjplimp/lammps/src -c simple.c
mpicc -L/home/sjplimp/lammps/src simple.o -llammps -lfftw -o simpleC
mpicc -L/home/sjplimp/lammps/src simple.o -llammps -o simpleC
This builds the Fortran wrapper and driver with the LAMMPS library
using the mpicc (C) and mpifort (Fortran) compilers, using the wrapper
in the fortran directory:
This builds the Fortran module and driver with the LAMMPS library
using the mpifort (Fortran) compilers, using the Fortran module from
the fortran directory:
cp ../fortran/libfwrapper.c .
mpicc -I/home/sjplimp/lammps/src -c libfwrapper.c
mpifort -c simple.f90
mpifort -L/home/sjplimp/lammps/src simple.o libfwrapper.o \
-llammps -lfftw -o simpleF
mpifort -L/home/sjplimp/lammps/src ../../../fortran/lammps.f90 simple.f90 -llammps -o simpleF
You then run simpleCC, simpleC, or simpleF on a parallel machine
on some number of processors Q with 2 arguments:
@ -69,10 +63,9 @@ The C driver is calling C-style routines in the src/library.cpp file
of LAMMPS. You could add any functions you wish to this file to
manipulate LAMMPS data however you wish.
The Fortran driver is using the same C-style routines, but requires an
additional wrapper to make them Fortran callable. Only a subset of the
library functions are currently wrapped, but it should be clear how to
extend the wrapper if desired.
The Fortran driver is using the Fortran 03 module which uses a derived
type with type bound subroutines. Only a small subset of the C library
functions are currently accessible through the Fortran module.
The C++ driver does the same thing, except that it instantiates LAMMPS
as an object first. Some of the functions in src/library.cpp can be

View File

@ -19,11 +19,11 @@
in.lammps = LAMMPS input script
See README for compilation instructions */
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "mpi.h"
#include "lammps/library.h" /* this is a LAMMPS include file */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
#include "library.h" /* this is a LAMMPS include file */
int main(int narg, char **arg)
{
@ -72,7 +72,7 @@ int main(int narg, char **arg)
all LAMMPS procs call lammps_command() on the line */
void *lmp = NULL;
if (lammps == 1) lammps_open(0,NULL,comm_lammps,&lmp);
if (lammps == 1) lmp = lammps_open(0,NULL,comm_lammps,NULL);
int n;
char line[1024];
@ -124,10 +124,10 @@ int main(int narg, char **arg)
/* use commands_string() and commands_list() to invoke more commands */
char *strtwo = "run 10\nrun 20";
const char *strtwo = "run 10\nrun 20";
if (lammps == 1) lammps_commands_string(lmp,strtwo);
char *cmds[2];
const char *cmds[2];
cmds[0] = "run 10";
cmds[1] = "run 20";
if (lammps == 1) lammps_commands_list(lmp,2,cmds);

View File

@ -25,10 +25,10 @@
#include <mpi.h>
// these are LAMMPS include files
#include <lammps/lammps.h>
#include <lammps/input.h>
#include <lammps/atom.h>
#include <lammps/library.h>
#include "lammps.h"
#include "input.h"
#include "atom.h"
#include "library.h"
using namespace LAMMPS_NS;
@ -135,10 +135,10 @@ int main(int narg, char **arg)
// use commands_string() and commands_list() to invoke more commands
char *strtwo = (char *) "run 10\nrun 20";
const char *strtwo = (char *) "run 10\nrun 20";
if (lammps == 1) lammps_commands_string(lmp,strtwo);
char *cmds[2];
const char *cmds[2];
cmds[0] = (char *) "run 10";
cmds[1] = (char *) "run 20";
if (lammps == 1) lammps_commands_list(lmp,2,cmds);

View File

@ -18,13 +18,14 @@
! See README for compilation instructions
PROGRAM f_driver
USE mpi
USE liblammps
IMPLICIT NONE
INCLUDE 'mpif.h'
INTEGER, PARAMETER :: fp=20
INTEGER :: n, narg, ierr, me, nprocs, natoms
INTEGER :: lammps, nprocs_lammps, comm_lammps
INTEGER (kind=8) :: ptr
INTEGER :: color, nprocs_lammps, comm_lammps
TYPE(LAMMPS) :: lmp
REAL (kind=8), ALLOCATABLE :: x(:)
REAL (kind=8), PARAMETER :: epsilon=0.1
@ -58,14 +59,14 @@ PROGRAM f_driver
END IF
END IF
lammps = 0
color = 0
IF (me < nprocs_lammps) THEN
lammps = 1
color = 1
ELSE
lammps = MPI_UNDEFINED
color = MPI_UNDEFINED
END IF
CALL mpi_comm_split(MPI_COMM_WORLD,lammps,0,comm_lammps,ierr)
CALL mpi_comm_split(MPI_COMM_WORLD,color,0,comm_lammps,ierr)
! open LAMMPS input script on rank zero
@ -81,7 +82,7 @@ PROGRAM f_driver
! (could just send it to proc 0 of comm_lammps and let it Bcast)
! all LAMMPS procs call lammps_command() on the line */
IF (lammps == 1) CALL lammps_open(comm_lammps,ptr)
IF (color == 1) lmp=lammps(comm=comm_lammps)
n = 0
DO
@ -99,7 +100,7 @@ PROGRAM f_driver
CALL mpi_bcast(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
IF (n == 0) EXIT
CALL mpi_bcast(line,n,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
IF (lammps == 1) CALL lammps_command(ptr,line,n)
IF (color == 1) CALL lmp%command(line(1:n))
END DO
CLOSE(UNIT=fp)
@ -109,27 +110,27 @@ PROGRAM f_driver
! put coords back into LAMMPS
! run a single step with changed coords */
IF (lammps == 1) THEN
CALL lammps_command(ptr,'run 10',6)
IF (color == 1) THEN
CALL lmp%command('run 10')
CALL lammps_get_natoms(ptr,natoms)
natoms = NINT(lmp%get_natoms())
ALLOCATE(x(3*natoms))
! these calls are commented out, b/c libfwrapper.c
! needs to be updated to use gather_atoms and scatter_atoms
!CALL lammps_gather_atoms(ptr,'x',1,3,x);
!CALL lammps_gather_atoms(ptr,'x',1,3,x)
!x(1) = x(1) + epsilon
!CALL lammps_scatter_atoms(ptr,'x',1,3,x);
!CALL lammps_scatter_atoms(ptr,'x',1,3,x)
DEALLOCATE(x)
CALL lammps_command(ptr,'run 1',5);
CALL lmp%command('run 1')
END IF
! free LAMMPS object
IF (lammps == 1) CALL lammps_close(ptr);
IF (color == 1) CALL lmp%close()
! close down MPI

View File

@ -1,7 +1,7 @@
configuration {
step 200
dt 2.000000e+00
version 2018-11-16
version 2020-07-07
}
colvar {

View File

@ -1,7 +1,7 @@
configuration {
step 100
dt 2.000000e+00
version 2018-11-16
version 2020-07-07
}
colvar {

View File

@ -1,7 +1,7 @@
configuration {
step 300
dt 2.000000e+00
version 2018-11-16
version 2020-07-07
}
colvar {

View File

@ -1,7 +1,7 @@
configuration {
step 100
dt 2.000000e+00
version 2018-11-16
version 2020-07-07
}
colvar {

View File

@ -23,12 +23,12 @@ from lammps import lammps
def end_of_step_callback(lmp):
L = lammps(ptr=lmp)
t = L.extract_global("ntimestep", 0)
t = L.extract_global("ntimestep")
print("### END OF STEP ###", t)
def post_force_callback(lmp, v):
L = lammps(ptr=lmp)
t = L.extract_global("ntimestep", 0)
t = L.extract_global("ntimestep")
print("### POST_FORCE ###", t)
"""

View File

@ -35,14 +35,13 @@ def post_force_callback(lmp, v):
#mylist = L.get_neighlist(0)
mylist = L.find_pair_neighlist("lj/cut", request=0)
print(pid_prefix, mylist)
nlocal = L.extract_global("nlocal", 0)
nghost = L.extract_global("nghost", 0)
ntypes = L.extract_global("ntypes", 0)
mass = L.numpy.extract_atom_darray("mass", ntypes+1)
atype = L.numpy.extract_atom_iarray("type", nlocal+nghost)
x = L.numpy.extract_atom_darray("x", nlocal+nghost, dim=3)
v = L.numpy.extract_atom_darray("v", nlocal+nghost, dim=3)
f = L.numpy.extract_atom_darray("f", nlocal+nghost, dim=3)
nlocal = L.extract_global("nlocal")
nghost = L.extract_global("nghost")
mass = L.numpy.extract_atom("mass")
atype = L.numpy.extract_atom("type", nelem=nlocal+nghost)
x = L.numpy.extract_atom("x", nelem=nlocal+nghost, dim=3)
v = L.numpy.extract_atom("v", nelem=nlocal+nghost, dim=3)
f = L.numpy.extract_atom("f", nelem=nlocal+nghost, dim=3)
for iatom, numneigh, neighs in mylist:
print(pid_prefix, "- {}".format(iatom), x[iatom], v[iatom], f[iatom], " : ", numneigh, "Neighbors")

View File

@ -1,12 +1,12 @@
from __future__ import print_function
import lammps
from lammps import lammps, LAMMPS_INT, LAMMPS_DOUBLE
import ctypes
import traceback
import numpy as np
class LAMMPSFix(object):
def __init__(self, ptr, group_name="all"):
self.lmp = lammps.lammps(ptr=ptr)
self.lmp = lammps(ptr=ptr)
self.group_name = group_name
class LAMMPSFixMove(LAMMPSFix):
@ -39,19 +39,18 @@ class NVE(LAMMPSFixMove):
assert(self.group_name == "all")
def init(self):
dt = self.lmp.extract_global("dt", 1)
ftm2v = self.lmp.extract_global("ftm2v", 1)
self.ntypes = self.lmp.extract_global("ntypes", 0)
dt = self.lmp.extract_global("dt")
ftm2v = self.lmp.extract_global("ftm2v")
self.ntypes = self.lmp.extract_global("ntypes")
self.dtv = dt
self.dtf = 0.5 * dt * ftm2v
def initial_integrate(self, vflag):
nlocal = self.lmp.extract_global("nlocal", 0)
mass = self.lmp.numpy.extract_atom_darray("mass", self.ntypes+1)
atype = self.lmp.numpy.extract_atom_iarray("type", nlocal)
x = self.lmp.numpy.extract_atom_darray("x", nlocal, dim=3)
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
f = self.lmp.numpy.extract_atom_darray("f", nlocal, dim=3)
mass = self.lmp.numpy.extract_atom("mass")
atype = self.lmp.numpy.extract_atom("type")
x = self.lmp.numpy.extract_atom("x")
v = self.lmp.numpy.extract_atom("v")
f = self.lmp.numpy.extract_atom("f")
for i in range(x.shape[0]):
dtfm = self.dtf / mass[int(atype[i])]
@ -59,11 +58,10 @@ class NVE(LAMMPSFixMove):
x[i,:] += self.dtv * v[i,:]
def final_integrate(self):
nlocal = self.lmp.extract_global("nlocal", 0)
mass = self.lmp.numpy.extract_atom_darray("mass", self.ntypes+1)
atype = self.lmp.numpy.extract_atom_iarray("type", nlocal)
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
f = self.lmp.numpy.extract_atom_darray("f", nlocal, dim=3)
mass = self.lmp.numpy.extract_atom("mass")
atype = self.lmp.numpy.extract_atom("type")
v = self.lmp.numpy.extract_atom("v")
f = self.lmp.numpy.extract_atom("f")
for i in range(v.shape[0]):
dtfm = self.dtf / mass[int(atype[i])]
@ -77,19 +75,19 @@ class NVE_Opt(LAMMPSFixMove):
assert(self.group_name == "all")
def init(self):
dt = self.lmp.extract_global("dt", 1)
ftm2v = self.lmp.extract_global("ftm2v", 1)
self.ntypes = self.lmp.extract_global("ntypes", 0)
dt = self.lmp.extract_global("dt")
ftm2v = self.lmp.extract_global("ftm2v")
self.ntypes = self.lmp.extract_global("ntypes")
self.dtv = dt
self.dtf = 0.5 * dt * ftm2v
self.mass = self.lmp.numpy.extract_atom_darray("mass", self.ntypes+1)
self.mass = self.lmp.numpy.extract_atom("mass")
def initial_integrate(self, vflag):
nlocal = self.lmp.extract_global("nlocal", 0)
atype = self.lmp.numpy.extract_atom_iarray("type", nlocal)
x = self.lmp.numpy.extract_atom_darray("x", nlocal, dim=3)
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
f = self.lmp.numpy.extract_atom_darray("f", nlocal, dim=3)
nlocal = self.lmp.extract_global("nlocal")
atype = self.lmp.numpy.extract_atom("type")
x = self.lmp.numpy.extract_atom("x")
v = self.lmp.numpy.extract_atom("v")
f = self.lmp.numpy.extract_atom("f")
dtf = self.dtf
dtv = self.dtv
mass = self.mass
@ -102,13 +100,12 @@ class NVE_Opt(LAMMPSFixMove):
x[:,d] += dtv * v[:,d]
def final_integrate(self):
nlocal = self.lmp.extract_global("nlocal", 0)
mass = self.lmp.numpy.extract_atom_darray("mass", self.ntypes+1)
atype = self.lmp.numpy.extract_atom_iarray("type", nlocal)
v = self.lmp.numpy.extract_atom_darray("v", nlocal, dim=3)
f = self.lmp.numpy.extract_atom_darray("f", nlocal, dim=3)
nlocal = self.lmp.extract_global("nlocal")
mass = self.lmp.numpy.extract_atom("mass")
atype = self.lmp.numpy.extract_atom("type")
v = self.lmp.numpy.extract_atom("v")
f = self.lmp.numpy.extract_atom("f")
dtf = self.dtf
dtv = self.dtv
mass = self.mass
dtfm = dtf / np.take(mass, atype)