consolidate LAMMPS data type constants and enums and use the same names

This commit is contained in:
Axel Kohlmeyer 2023-06-10 19:23:11 -04:00
parent 0e7d91b611
commit 62b388b48f
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
11 changed files with 60 additions and 39 deletions

View File

@ -37,12 +37,13 @@
#endif
/* The following enums must be kept in sync with the equivalent enums
* or constants in python/lammps/constants.py, fortran/lammps.f90,
* tools/swig/lammps.i, and examples/COUPLE/plugin/liblammpsplugin.h */
* or constants in src/library.h, src/lmptype.h, python/lammps/constants.py,
* fortran/lammps.f90, and tools/swig/lammps.i */
/* Data type constants for extracting data from atoms, computes and fixes */
enum _LMP_DATATYPE_CONST {
LAMMPS_NONE = -1, /*!< no data type assigned (yet) */
LAMMPS_INT = 0, /*!< 32-bit integer (array) */
LAMMPS_INT_2D = 1, /*!< two-dimensional 32-bit integer array */
LAMMPS_DOUBLE = 2, /*!< 64-bit double (array) */

View File

@ -44,11 +44,12 @@ MODULE LIBLAMMPS
! Data type constants for extracting data from global, atom, compute, and fix
!
! Must be kept in sync with the equivalent declarations in
! src/library.h, python/lammps/constants.py, tools/swig/lammps.i,
! src/library.h, src/lmptype.h, python/lammps/constants.py, tools/swig/lammps.i,
! and examples/COUPLE/plugin/liblammpsplugin.h
!
! These are NOT part of the API (the part the user sees)
INTEGER(c_int), PARAMETER :: &
LAMMPS_NONE = -1, & ! no data type assigned (yet)
LAMMPS_INT = 0, & ! 32-bit integer (or array)
LAMMPS_INT_2D = 1, & ! two-dimensional 32-bit integer array
LAMMPS_DOUBLE = 2, & ! 64-bit double (or array)

View File

@ -13,7 +13,13 @@
# various symbolic constants to be used
# in certain calls to select data formats
# these must be kept in sync with the enums in src/library.h, src/lmptype.h,
# tools/swig/lammps.i, examples/COUPLE/plugin/liblammpsplugin.h,
# and the constants in fortran/lammps.f90
LAMMPS_AUTODETECT = None
LAMMPS_NONE = -1
LAMMPS_INT = 0
LAMMPS_INT_2D = 1
LAMMPS_DOUBLE = 2
@ -22,8 +28,6 @@ LAMMPS_INT64 = 4
LAMMPS_INT64_2D = 5
LAMMPS_STRING = 6
# these must be kept in sync with the enums in src/library.h, tools/swig/lammps.i,
# examples/COUPLE/plugin/liblammpsplugin.h, and the constants in fortran/lammps.f90
LMP_STYLE_GLOBAL = 0
LMP_STYLE_ATOM = 1
LMP_STYLE_LOCAL = 2

View File

@ -71,11 +71,11 @@ void DumpYAML::write_header(bigint ndump)
thermo_data += "]\n - data: [ ";
for (int i = 0; i < nfield; ++i) {
if (fields[i].type == multitype::DOUBLE)
if (fields[i].type == multitype::LAMMPS_DOUBLE)
thermo_data += fmt::format("{}, ", fields[i].data.d);
else if (fields[i].type == multitype::INT)
else if (fields[i].type == multitype::LAMMPS_INT)
thermo_data += fmt::format("{}, ", fields[i].data.i);
else if (fields[i].type == multitype::BIGINT)
else if (fields[i].type == multitype::LAMMPS_INT64)
thermo_data += fmt::format("{}, ", fields[i].data.b);
else
thermo_data += ", ";

View File

@ -442,11 +442,11 @@ void DumpNetCDF::openfile()
const int nfield = *th->get_nfield();
for (int i = 0; i < nfield; i++) {
if (fields[i].type == multitype::DOUBLE) {
if (fields[i].type == multitype::LAMMPS_DOUBLE) {
NCERRX( nc_def_var(ncid, keywords[i].c_str(), type_nc_real, 1, dims, &thermovar[i]), keywords[i].c_str() );
} else if (fields[i].type == multitype::INT) {
} else if (fields[i].type == multitype::LAMMPS_INT) {
NCERRX( nc_def_var(ncid, keywords[i].c_str(), NC_INT, 1, dims, &thermovar[i]), keywords[i].c_str() );
} else if (fields[i].type == multitype::BIGINT) {
} else if (fields[i].type == multitype::LAMMPS_INT64) {
NCERRX( nc_def_var(ncid, keywords[i].c_str(), NC_INT64, 1, dims, &thermovar[i]), keywords[i].c_str() );
}
}
@ -624,11 +624,11 @@ void DumpNetCDF::write()
int nfield = *th->get_nfield();
for (int i = 0; i < nfield; i++) {
if (filewriter) {
if (fields[i].type == multitype::DOUBLE) {
if (fields[i].type == multitype::LAMMPS_DOUBLE) {
NCERRX( nc_put_var1_double(ncid, thermovar[i], start, &fields[i].data.d), keywords[i].c_str() );
} else if (fields[i].type == multitype::INT) {
} else if (fields[i].type == multitype::LAMMPS_INT) {
NCERRX( nc_put_var1_int(ncid, thermovar[i], start, &fields[i].data.i), keywords[i].c_str() );
} else if (fields[i].type == multitype::BIGINT) {
} else if (fields[i].type == multitype::LAMMPS_INT64) {
NCERRX( nc_put_var1_bigint(ncid, thermovar[i], start, &fields[i].data.b), keywords[i].c_str() );
}
}

View File

@ -432,11 +432,11 @@ void DumpNetCDFMPIIO::openfile()
const int nfield = *th->get_nfield();
for (int i = 0; i < nfield; i++) {
if (fields[i].type == multitype::DOUBLE) {
if (fields[i].type == multitype::LAMMPS_DOUBLE) {
NCERRX( ncmpi_def_var(ncid, keywords[i].c_str(), type_nc_real, 1, dims, &thermovar[i]), keywords[i].c_str() );
} else if (fields[i].type == multitype::INT) {
} else if (fields[i].type == multitype::LAMMPS_INT) {
NCERRX( ncmpi_def_var(ncid, keywords[i].c_str(), NC_INT, 1, dims, &thermovar[i]), keywords[i].c_str() );
} else if (fields[i].type == multitype::BIGINT) {
} else if (fields[i].type == multitype::LAMMPS_INT64) {
NCERRX( ncmpi_def_var(ncid, keywords[i].c_str(), NC_INT64, 1, dims, &thermovar[i]), keywords[i].c_str() );
}
}
@ -617,11 +617,11 @@ void DumpNetCDFMPIIO::write()
int nfield = *th->get_nfield();
for (int i = 0; i < nfield; i++) {
if (filewriter) {
if (fields[i].type == multitype::DOUBLE) {
if (fields[i].type == multitype::LAMMPS_DOUBLE) {
NCERRX( ncmpi_put_var1_double(ncid, thermovar[i], start, &fields[i].data.d), keywords[i].c_str() );
} else if (fields[i].type == multitype::INT) {
} else if (fields[i].type == multitype::LAMMPS_INT) {
NCERRX( ncmpi_put_var1_int(ncid, thermovar[i], start, &fields[i].data.i), keywords[i].c_str() );
} else if (fields[i].type == multitype::BIGINT) {
} else if (fields[i].type == multitype::LAMMPS_INT64) {
NCERRX( ncmpi_put_var1_bigint(ncid, thermovar[i], start, &fields[i].data.b), keywords[i].c_str() );
}
}

View File

@ -836,11 +836,11 @@ void *lammps_last_thermo(void *handle, const char *what, int index)
} else if (strcmp(what, "data") == 0) {
if ((index < 0) || (index >= nfield)) return nullptr;
const auto &field = th->get_fields()[index];
if (field.type == multitype::INT) {
if (field.type == multitype::LAMMPS_INT) {
val = (void *) &field.data.i;
} else if (field.type == multitype::BIGINT) {
} else if (field.type == multitype::LAMMPS_INT64) {
val = (void *) &field.data.b;
} else if (field.type == multitype::DOUBLE) {
} else if (field.type == multitype::LAMMPS_DOUBLE) {
val = (void *) &field.data.d;
}

View File

@ -41,10 +41,11 @@
/** Data type constants for extracting data from atoms, computes and fixes
*
* Must be kept in sync with the equivalent constants in ``python/lammps/constants.py``,
* ``fortran/lammps.f90``, ``tools/swig/lammps.i``, and
* ``fortran/lammps.f90``, ``tools/swig/lammps.i``, ``src/lmptype.h``, and
*``examples/COUPLE/plugin/liblammpsplugin.h`` */
enum _LMP_DATATYPE_CONST {
LAMMPS_NONE = -1, /*!< no data type assigned (yet) */
LAMMPS_INT = 0, /*!< 32-bit integer (array) */
LAMMPS_INT_2D = 1, /*!< two-dimensional 32-bit integer array */
LAMMPS_DOUBLE = 2, /*!< 64-bit double (array) */

View File

@ -276,8 +276,21 @@ union ubuf {
\endverbatim
*/
struct multitype {
// same values as LAMMPS_INT, LAMMPS_DOUBLE, and LAMMPS_INT64 in library.h
enum { NONE = -1, INT = 0, DOUBLE = 2, BIGINT = 4 };
/** Data type constants for extracting data from atoms, computes and fixes
*
* This enum must be kept in sync with the corresponding enum or constants
* in ``python/lammps/constants.py``, ``fortran/lammps.f90``, ``tools/swig/lammps.i``,
* ``src/library.h``, and ``examples/COUPLE/plugin/liblammpsplugin.h`` */
enum _LMP_DATATYPE_CONST {
LAMMPS_NONE = -1, /*!< no data type assigned (yet) */
LAMMPS_INT = 0, /*!< 32-bit integer (array) */
LAMMPS_INT_2D = 1, /*!< two-dimensional 32-bit integer array */
LAMMPS_DOUBLE = 2, /*!< 64-bit double (array) */
LAMMPS_DOUBLE_2D = 3, /*!< two-dimensional 64-bit double array */
LAMMPS_INT64 = 4, /*!< 64-bit integer (array) */
LAMMPS_INT64_2D = 5, /*!< two-dimensional 64-bit integer array */
LAMMPS_STRING = 6 /*!< C-String */
};
int type;
union {
@ -286,26 +299,26 @@ struct multitype {
int64_t b;
} data;
multitype() : type(NONE) { data.d = 0.0; }
multitype() : type(LAMMPS_NONE) { data.d = 0.0; }
multitype(const multitype &) = default;
multitype(multitype &&) = default;
~multitype() = default;
multitype &operator=(const double &_d)
{
type = DOUBLE;
type = LAMMPS_DOUBLE;
data.d = _d;
return *this;
}
multitype &operator=(const int &_i)
{
type = INT;
type = LAMMPS_INT;
data.i = _i;
return *this;
}
multitype &operator=(const int64_t &_b)
{
type = BIGINT;
type = LAMMPS_INT64;
data.b = _b;
return *this;
}

View File

@ -28,9 +28,10 @@
*
* Must be kept in sync with the equivalent constants in ``src/library.h``,
* ``python/lammps/constants.py``, ``examples/COUPLE/plugin/liblammpsplugin.h``,
* and ``fortran/lammps.f90`` */
* ``src/lmptype.h``, and ``fortran/lammps.f90`` */
enum _LMP_DATATYPE_CONST {
LAMMPS_NONE =-1, /*!< no data type assigned (yet) */
LAMMPS_INT = 0, /*!< 32-bit integer (array) */
LAMMPS_INT_2D = 1, /*!< two-dimensional 32-bit integer array */
LAMMPS_DOUBLE = 2, /*!< 64-bit double (array) */

View File

@ -54,18 +54,18 @@ TEST(Types, multitype)
m[4] = -1023;
m[5] = -2.225;
EXPECT_EQ(m[0].type, multitype::BIGINT);
EXPECT_EQ(m[1].type, multitype::INT);
EXPECT_EQ(m[2].type, multitype::DOUBLE);
EXPECT_EQ(m[0].type, multitype::LAMMPS_INT64);
EXPECT_EQ(m[1].type, multitype::LAMMPS_INT);
EXPECT_EQ(m[2].type, multitype::LAMMPS_DOUBLE);
#if defined(LAMMPS_SMALLSMALL)
EXPECT_EQ(m[3].type, multitype::INT);
EXPECT_EQ(m[3].type, multitype::LAMMPS_INT);
#else
EXPECT_EQ(m[3].type, multitype::BIGINT);
EXPECT_EQ(m[3].type, multitype::LAMMPS_INT64);
#endif
EXPECT_EQ(m[4].type, multitype::INT);
EXPECT_EQ(m[5].type, multitype::DOUBLE);
EXPECT_EQ(m[6].type, multitype::NONE);
EXPECT_EQ(m[4].type, multitype::LAMMPS_INT);
EXPECT_EQ(m[5].type, multitype::LAMMPS_DOUBLE);
EXPECT_EQ(m[6].type, multitype::LAMMPS_NONE);
EXPECT_EQ(m[0].data.b, b1);
EXPECT_EQ(m[1].data.i, i1);