forked from lijiext/lammps
Add way of getting correct ctypes integer type for bigint, tagint, and imageint
This commit is contained in:
parent
09bb687918
commit
0b5a2e199d
|
@ -32,6 +32,13 @@ import select
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
def get_ctypes_int(size):
|
||||||
|
if size == 4:
|
||||||
|
return c_int32
|
||||||
|
elif size == 8:
|
||||||
|
return c_int64
|
||||||
|
return c_int
|
||||||
|
|
||||||
class MPIAbortException(Exception):
|
class MPIAbortException(Exception):
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
self.message = message
|
self.message = message
|
||||||
|
@ -165,6 +172,11 @@ class lammps(object):
|
||||||
# optional numpy support (lazy loading)
|
# optional numpy support (lazy loading)
|
||||||
self._numpy = None
|
self._numpy = None
|
||||||
|
|
||||||
|
# set default types
|
||||||
|
self.c_bigint = get_ctypes_int(self.extract_setting("bigint"))
|
||||||
|
self.c_tagint = get_ctypes_int(self.extract_setting("tagint"))
|
||||||
|
self.c_imageint = get_ctypes_int(self.extract_setting("imageint"))
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self.lmp and self.opened:
|
if self.lmp and self.opened:
|
||||||
self.lib.lammps_close(self.lmp)
|
self.lib.lammps_close(self.lmp)
|
||||||
|
@ -239,6 +251,13 @@ class lammps(object):
|
||||||
ptr = self.lib.lammps_extract_atom(self.lmp,name)
|
ptr = self.lib.lammps_extract_atom(self.lmp,name)
|
||||||
return ptr
|
return ptr
|
||||||
|
|
||||||
|
# extract lammps type byte sizes
|
||||||
|
|
||||||
|
def extract_setting(self, name):
|
||||||
|
if name: name = name.encode()
|
||||||
|
self.lib.lammps_extract_atom.restype = c_int
|
||||||
|
return int(self.lib.lammps_extract_setting(self.lmp,name))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def numpy(self):
|
def numpy(self):
|
||||||
if not self._numpy:
|
if not self._numpy:
|
||||||
|
|
Loading…
Reference in New Issue