unit tests for has_style, style_count, and style_name; added them to docs

This commit is contained in:
Karl Hammond 2022-10-20 23:22:43 -05:00
parent 60318a5a26
commit 112d616e57
No known key found for this signature in database
3 changed files with 126 additions and 29 deletions

View File

@ -281,6 +281,9 @@ of the contents of the ``LIBLAMMPS`` Fortran interface to LAMMPS.
:f function config_accelerator: :f:func:`config_accelerator`
:f function has_gpu_device: :f:func:`has_gpu_device`
:f subroutine get_gpu_device_info: :f:func:`get_gpu_device_info`
:f function has_style: :f:func:`has_style`
:f function style_count: :f:func:`style_count`
:f function style_name: :f:func:`style_name`
:f function encode_image_flags: :f:func:`encode_image_flags`
:f subroutine decode_image_flags: :f:func:`decode_image_flags`
:f subroutine flush_buffers: :f:func:`flush_buffers`
@ -1588,6 +1591,60 @@ Procedures Bound to the lammps Derived Type
--------
.. f:function:: has_style(category, name)
Check whether a specific style has been included in LAMMPS.
.. versionadded:: TBD
This function calls :cpp:func:`lammps_has_style` to check whether the
LAMMPS library in use includes the specific style *name* associated with a
specific *category* provided as arguments. Please see
:cpp:func:`lammps_has_style` for a list of valid categories.
:p character(len=\*) category: category of the style
:p character(len=\*) name: name of the style
:r logical: ``.TRUE.`` if included, ``.FALSE.`` if not.
--------
.. f:function:: style_count(category)
Count the number of styles of *category* in the LAMMPS library.
.. versionadded:: TBD
This function counts how many styles in the provided *category* are
included in the LAMMPS library currently in use. Please see
:cpp:func:`lammps_has_style` for a list of valid categories.
:p character(len=\*) category: category of styles to count
:r integer(c_int): number of styles in *category*
--------
.. f:subroutine:: style_name(category, idx, buffer)
Look up the name of a style by index in the list of styles of a given
category in the LAMMPS library.
.. versionadded:: TBD
This function calls :cpp:func:`lammps_style_name` and copies the name of
the *category* style with index *idx* into the provided string *buffer*.
The length of *buffer* must be long enough to contain the name of the
style; if it is too short, the name will be truncated accordingly.
If *idx* is out of range, *buffer* will be the empty string and a warning
will be issued.
:p character(len=\*) category: category of styles
:p integer(c_int) idx: index of the style in the list of *category*
styles :math:`(1 \leq idx \leq \text{style count})`
:p character(len\*) buffer: string buffer to copy the name of the style
into
--------
.. f:function:: encode_image_flags(ix, iy, iz)
Encodes three integer image flags into a single imageint.

View File

@ -143,10 +143,6 @@ FUNCTION f_lammps_package_name(idx) BIND(C)
END IF
END FUNCTION f_lammps_package_name
FUNCTION f_lammps_config_accelerator(package, category, setting) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_int, c_ptr, c_size_t, c_char, &
C_F_POINTER
@ -214,3 +210,33 @@ FUNCTION f_lammps_get_gpu_info(buf_size) RESULT(info) BIND(C)
CALL lmp%get_gpu_device_info(string)
info = f2c_string(string)
END FUNCTION f_lammps_get_gpu_info
FUNCTION f_lammps_has_style(Ccategory, Cname) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_size_t, c_ptr, c_char, c_int, &
C_F_POINTER
USE keepstuff, ONLY : lmp, c_strlen
IMPLICIT NONE
TYPE(c_ptr), INTENT(IN), VALUE :: Ccategory, Cname
INTEGER(c_int) :: f_lammps_has_style
CHARACTER(LEN=1,KIND=c_char), DIMENSION(:), POINTER :: Fcategory, Fname
INTEGER(c_size_t) :: category_len, name_len, i
CHARACTER(LEN=:), ALLOCATABLE :: category, name
category_len = c_strlen(Ccategory)
name_len = c_strlen(Cname)
CALL C_F_POINTER(Ccategory, Fcategory, [category_len])
CALL C_F_POINTER(Cname, Fname, [name_len])
ALLOCATE(CHARACTER(LEN=category_len) :: category)
ALLOCATE(CHARACTER(LEN=name_len) :: name)
DO i = 1, category_len
category(i:i) = Fcategory(i)
END DO
DO i = 1, name_len
name(i:i) = Fname(i)
END DO
IF (lmp%has_style(category, name)) THEN
f_lammps_has_style = 1_c_int
ELSE
f_lammps_has_style = 0_c_int
END IF
END FUNCTION f_lammps_has_style

View File

@ -25,7 +25,7 @@ char* f_lammps_package_name(int);
int f_lammps_config_accelerator(const char*, const char*, const char*);
int f_lammps_has_gpu();
char* f_lammps_get_gpu_info(size_t);
int f_lammps_has_style();
int f_lammps_has_style(const char*, const char*);
int f_lammps_style_count();
int f_lammps_style_name();
}
@ -58,61 +58,57 @@ protected:
TEST_F(LAMMPS_configuration, version)
{
EXPECT_LT(20200917, f_lammps_version());
EXPECT_EQ(lmp->num_ver, f_lammps_version());
EXPECT_LT(20200917, f_lammps_version());
EXPECT_EQ(lmp->num_ver, f_lammps_version());
};
TEST_F(LAMMPS_configuration, MPI_support)
{
#ifdef MPI_STUBS
EXPECT_EQ(f_lammps_mpi_support(), 0);
EXPECT_EQ(f_lammps_mpi_support(), 0);
#else
EXPECT_EQ(f_lammps_mpi_support(), 1);
EXPECT_EQ(f_lammps_mpi_support(), 1);
#endif
};
TEST_F(LAMMPS_configuration, gzip_support)
{
EXPECT_EQ(f_lammps_gzip_support(), Info::has_gzip_support());
EXPECT_EQ(f_lammps_gzip_support(), Info::has_gzip_support());
}
TEST_F(LAMMPS_configuration, png_support)
{
EXPECT_EQ(f_lammps_png_support(), Info::has_png_support());
EXPECT_EQ(f_lammps_png_support(), Info::has_png_support());
}
TEST_F(LAMMPS_configuration, jpeg_support)
{
EXPECT_EQ(f_lammps_jpeg_support(), Info::has_jpeg_support());
EXPECT_EQ(f_lammps_jpeg_support(), Info::has_jpeg_support());
}
TEST_F(LAMMPS_configuration, ffmpeg_support)
{
EXPECT_EQ(f_lammps_ffmpeg_support(), Info::has_ffmpeg_support());
EXPECT_EQ(f_lammps_ffmpeg_support(), Info::has_ffmpeg_support());
}
TEST_F(LAMMPS_configuration, has_exceptions)
{
EXPECT_EQ(f_lammps_has_exceptions(), Info::has_exceptions());
EXPECT_EQ(f_lammps_has_exceptions(), Info::has_exceptions());
}
TEST_F(LAMMPS_configuration, has_package)
{
std::vector<std::string> pkg_name = {"ADIOS","ASPHERE","ATC","AWPMD","BOCS",
"BODY", "BPM", "BROWNIAN", "CG-DNA", "CLASS2", "COLLOID", "COLVARS",
"COMPRESS", "CORESHELL", "DEPEND", "DIELECTRIC", "DIFFRACTION", "DIPOLE",
"DPD-BASIC", "DPD-MESO", "DPD-REACT", "DPD-SMOOTH", "DRUDE", "EFF",
"ELECTRODE", "EXTRA-COMPUTE", "EXTRA-DUMP", "EXTRA-FIX",
"EXTRA-MOLECULE", "EXTRA-PAIR", "FEP", "GPU", "GRANULAR", "H5MD",
"INTEL", "INTEL/TEST", "INTERLAYER", "KIM", "KOKKOS", "KSPACE",
"LATBOLTZ", "LATTE", "MACHDYN", "MAKE", "MAKE/MACHINES", "MAKE/MINE",
"MAKE/OPTIONS", "MANIFOLD", "MANYBODY", "MC", "MDI", "MEAM", "MESONT",
"MGPT", "MISC", "ML-HDNNP", "ML-IAP", "ML-PACE", "ML-QUIP", "ML-RANN",
"ML-SNAP", "MOFFF", "MOLECULE", "MOLFILE", "MPIIO", "MSCG", "NETCDF",
"OPENMP", "OPT", "ORIENT", "PERI", "PHONON", "PLUGIN", "PLUMED", "POEMS",
"PTM", "PYTHON", "QEQ", "QMMM", "QTB", "REACTION", "REAXFF", "REPLICA",
"RIGID", "SCAFACOS", "SHOCK", "SMTBQ", "SPH", "SPIN", "SRD", "STUBS",
"TALLY", "UEF", "VORONOI", "VTK", "YAFF", "CG-SPICA", "AMOEBA"};
std::vector<std::string> pkg_name = {"ADIOS","ASPHERE","ATC","AWPMD","BOCS","BODY","BPM",
"BROWNIAN","CG-DNA","CLASS2","COLLOID","COLVARS","COMPRESS","CORESHELL","DEPEND",
"DIELECTRIC","DIFFRACTION","DIPOLE","DPD-BASIC","DPD-MESO","DPD-REACT","DPD-SMOOTH","DRUDE",
"EFF","ELECTRODE","EXTRA-COMPUTE","EXTRA-DUMP","EXTRA-FIX","EXTRA-MOLECULE","EXTRA-PAIR",
"FEP","GPU","GRANULAR","H5MD","INTEL","INTEL/TEST","INTERLAYER","KIM","KOKKOS","KSPACE",
"LATBOLTZ","LATTE","MACHDYN","MAKE","MAKE/MACHINES","MAKE/MINE","MAKE/OPTIONS","MANIFOLD",
"MANYBODY","MC","MDI","MEAM","MESONT","MGPT","MISC","ML-HDNNP","ML-IAP","ML-PACE","ML-QUIP",
"ML-RANN","ML-SNAP","MOFFF","MOLECULE","MOLFILE","MPIIO","MSCG","NETCDF","OPENMP","OPT",
"ORIENT","PERI","PHONON","PLUGIN","PLUMED","POEMS","PTM","PYTHON","QEQ","QMMM","QTB",
"REACTION","REAXFF","REPLICA","RIGID","SCAFACOS","SHOCK","SMTBQ","SPH","SPIN","SRD","STUBS",
"TALLY","UEF","VORONOI","VTK","YAFF","CG-SPICA","AMOEBA"};
for (int i = 0; i < pkg_name.size(); i++)
EXPECT_EQ(f_lammps_has_package(pkg_name[i].c_str()),
@ -201,4 +197,22 @@ TEST_F(LAMMPS_configuration, get_gpu_info)
}
};
TEST_F(LAMMPS_configuration, has_style)
{
std::vector<std::string> category = {"atom","integrate","minimize","pair",
"bond","angle","dihedral","improper","kspace","fix","compute","region",
"dump","command"};
Info info(lmp);
for (int c = 0; c < category.size(); c++)
{
std::vector<std::string> name = info.get_available_styles(category[c]);
for (int s = 0; s < name.size(); s++)
{
EXPECT_EQ(f_lammps_has_style(category[c].c_str(),
name[s].c_str()), info.has_style(category[c], name[s]));
}
}
EXPECT_EQ(f_lammps_has_style("atom","none"), 0);
};
} // namespace LAMMPS_NS