Merge branch 'master' into lammps-icms
Resolved Conflicts: lib/meam/Makefile.gfortran lib/poems/Makefile.g++ lib/reax/Makefile.gfortran python/lammps.py src/USER-CUDA/cuda.cpp
This commit is contained in:
@ -17,23 +17,15 @@ import types
|
||||
from ctypes import *
|
||||
import os.path
|
||||
|
||||
LMPINT = 0
|
||||
LMPDOUBLE = 1
|
||||
LMPIPTR = 2
|
||||
LMPDPTR = 3
|
||||
LMPDPTRPTR = 4
|
||||
|
||||
LOCATION = os.path.dirname(__file__)
|
||||
|
||||
class lammps:
|
||||
def __init__(self,name="",cmdlineargs=None):
|
||||
def __init__(self,name="",cmdargs=None):
|
||||
|
||||
# load liblmp.so by default
|
||||
# if name = "g++", load liblmp_g++.so
|
||||
# load liblammps.so by default
|
||||
# if name = "g++", load liblammps_g++.so
|
||||
|
||||
try:
|
||||
if not name: self.lib = CDLL("liblmp.so")
|
||||
else: self.lib = CDLL("liblmp_%s.so" % name)
|
||||
if not name: self.lib = CDLL("liblammps.so")
|
||||
else: self.lib = CDLL("liblammps_%s.so" % name)
|
||||
except:
|
||||
raise OSError,"Could not load LAMMPS dynamic library"
|
||||
|
||||
@ -42,10 +34,10 @@ class lammps:
|
||||
# no_mpi call lets LAMMPS use MPI_COMM_WORLD
|
||||
# cargs = array of C strings from args
|
||||
|
||||
if cmdlineargs:
|
||||
cmdlineargs.insert(0,"lammps.py")
|
||||
narg = len(cmdlineargs)
|
||||
cargs = (c_char_p*narg)(*cmdlineargs)
|
||||
if cmdargs:
|
||||
cmdargs.insert(0,"lammps.py")
|
||||
narg = len(cmdargs)
|
||||
cargs = (c_char_p*narg)(*cmdargs)
|
||||
self.lmp = c_void_p()
|
||||
self.lib.lammps_open_no_mpi(narg,cargs,byref(self.lmp))
|
||||
else:
|
||||
@ -68,30 +60,26 @@ class lammps:
|
||||
self.lib.lammps_command(self.lmp,cmd)
|
||||
|
||||
def extract_global(self,name,type):
|
||||
if type == LMPDOUBLE:
|
||||
self.lib.lammps_extract_global.restype = POINTER(c_double)
|
||||
ptr = self.lib.lammps_extract_global(self.lmp,name)
|
||||
return ptr[0]
|
||||
if type == LMPINT:
|
||||
if type == 0:
|
||||
self.lib.lammps_extract_global.restype = POINTER(c_int)
|
||||
ptr = self.lib.lammps_extract_global(self.lmp,name)
|
||||
return ptr[0]
|
||||
return None
|
||||
elif type == 1:
|
||||
self.lib.lammps_extract_global.restype = POINTER(c_double)
|
||||
else: return None
|
||||
ptr = self.lib.lammps_extract_global(self.lmp,name)
|
||||
return ptr[0]
|
||||
|
||||
def extract_atom(self,name,type):
|
||||
if type == LMPDPTRPTR:
|
||||
self.lib.lammps_extract_atom.restype = POINTER(POINTER(c_double))
|
||||
ptr = self.lib.lammps_extract_atom(self.lmp,name)
|
||||
return ptr
|
||||
if type == LMPDPTR:
|
||||
self.lib.lammps_extract_atom.restype = POINTER(c_double)
|
||||
ptr = self.lib.lammps_extract_atom(self.lmp,name)
|
||||
return ptr
|
||||
if type == LMPIPTR:
|
||||
if type == 0:
|
||||
self.lib.lammps_extract_atom.restype = POINTER(c_int)
|
||||
ptr = self.lib.lammps_extract_atom(self.lmp,name)
|
||||
return ptr
|
||||
return None
|
||||
elif type == 1:
|
||||
self.lib.lammps_extract_atom.restype = POINTER(POINTER(c_int))
|
||||
elif type == 2:
|
||||
self.lib.lammps_extract_atom.restype = POINTER(c_double)
|
||||
elif type == 3:
|
||||
self.lib.lammps_extract_atom.restype = POINTER(POINTER(c_double))
|
||||
else: return None
|
||||
ptr = self.lib.lammps_extract_atom(self.lmp,name)
|
||||
return ptr
|
||||
|
||||
def extract_compute(self,id,style,type):
|
||||
if type == 0:
|
||||
@ -153,18 +141,26 @@ class lammps:
|
||||
return result
|
||||
return None
|
||||
|
||||
# return total number of atoms in system
|
||||
|
||||
def get_natoms(self):
|
||||
return self.lib.lammps_get_natoms(self.lmp)
|
||||
|
||||
def get_coords(self):
|
||||
nlen = 3 * self.lib.lammps_get_natoms(self.lmp)
|
||||
coords = (c_double*nlen)()
|
||||
self.lib.lammps_get_coords(self.lmp,coords)
|
||||
return coords
|
||||
# return vector of atom properties gathered across procs, ordered by atom ID
|
||||
|
||||
# assume coords is an array of c_double, as created by get_coords()
|
||||
# could check if it is some other Python object and create c_double array?
|
||||
# constructor for c_double array can take an arg to use to fill it?
|
||||
|
||||
def put_coords(self,coords):
|
||||
self.lib.lammps_put_coords(self.lmp,coords)
|
||||
def gather_atoms(self,name,type,count):
|
||||
natoms = self.lib.lammps_get_natoms(self.lmp)
|
||||
if type == 0:
|
||||
data = ((count*natoms)*c_double)()
|
||||
self.lib.lammps_gather_atoms(self.lmp,name,type,count,data)
|
||||
elif type == 1:
|
||||
data = ((count*natoms)*c_double)()
|
||||
self.lib.lammps_gather_atoms(self.lmp,name,type,count,data)
|
||||
else: return None
|
||||
return data
|
||||
|
||||
# scatter vector of atom properties across procs, ordered by atom ID
|
||||
# assume vector is of correct type and length, as created by gather_atoms()
|
||||
|
||||
def scatter_atoms(self,name,type,count,data):
|
||||
self.lib.lammps_scatter_atoms(self.lmp,name,type,count,data)
|
||||
|
||||
Reference in New Issue
Block a user