consolidate redundant functionality into one function

This commit is contained in:
Axel Kohlmeyer
2025-07-16 07:01:07 -04:00
parent a19cb93558
commit d542651d60
17 changed files with 60 additions and 66 deletions

View File

@ -1070,6 +1070,12 @@ bool Info::has_exceptions() {
return true;
}
/** Return true if a LAMMPS package is enabled in this binary
*
* \param pkg name of package
* \return true if yes, else false
*/
bool Info::has_package(const std::string &package_name) {
for (int i = 0; LAMMPS::installed_packages[i] != nullptr; ++i) {
if (package_name == LAMMPS::installed_packages[i]) {

View File

@ -1142,19 +1142,6 @@ void _noopt LAMMPS::init_pkg_lists()
#undef REGION_CLASS
}
/** Return true if a LAMMPS package is enabled in this binary
*
* \param pkg name of package
* \return true if yes, else false
*/
bool LAMMPS::is_installed_pkg(const char *pkg)
{
for (int i=0; installed_packages[i] != nullptr; ++i)
if (strcmp(installed_packages[i],pkg) == 0) return true;
return false;
}
#define check_for_match(style,list,name) \
if (strcmp(list,#style) == 0) { \
std::map<std::string,std::string> &styles(pkg_lists-> style ## _styles); \

View File

@ -79,7 +79,6 @@ class LAMMPS {
const char *match_style(const char *style, const char *name);
static const char *installed_packages[];
static bool is_installed_pkg(const char *pkg);
static bool has_git_info();
static const char *git_commit();

View File

@ -23,6 +23,7 @@
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
#include "fmt/chrono.h"
#endif
#include "info.h"
#include "input.h"
#include "label_map.h"
#include "memory.h"
@ -449,7 +450,7 @@ std::string utils::check_packages_for_style(const std::string &style, const std:
if (pkg) {
errmsg += fmt::format(" is part of the {} package", pkg);
if (LAMMPS::is_installed_pkg(pkg))
if (Info::has_package(pkg))
errmsg += ", but seems to be missing because of a dependency";
else
errmsg += " which is not enabled in this LAMMPS binary." + utils::errorurl(10);

View File

@ -79,7 +79,7 @@ TEST(lammps_open, with_args)
TEST(lammps_open, with_kokkos)
{
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (!LAMMPS_NS::Info::has_package("KOKKOS")) GTEST_SKIP();
std::vector<char *> args = {(char *)"lammps", (char *)"-log", (char *)"none", (char *)"-echo",
(char *)"screen", (char *)"-sf", (char *)"kk"};
@ -168,7 +168,7 @@ TEST(lammps_open_no_mpi, no_screen)
TEST(lammps_open_no_mpi, with_omp)
{
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (!LAMMPS_NS::Info::has_package("OPENMP")) GTEST_SKIP();
const char *args[] = {"liblammps", "-pk", "omp", "2", "neigh", "no",
"-sf", "omp", "-log", "none", "-nocite", nullptr};
char **argv = (char **)args;

View File

@ -49,7 +49,7 @@ protected:
TEST_F(KimCommandsTest, kim)
{
if (!LAMMPS::is_installed_pkg("KIM")) GTEST_SKIP();
if (!Info::has_package("KIM")) GTEST_SKIP();
TEST_FAILURE(".*ERROR: Illegal kim command.*", command("kim"););
TEST_FAILURE(".*ERROR: Unknown kim subcommand.*", command("kim unknown"););
@ -62,7 +62,7 @@ TEST_F(KimCommandsTest, kim)
TEST_F(KimCommandsTest, kim_init)
{
if (!LAMMPS::is_installed_pkg("KIM")) GTEST_SKIP();
if (!Info::has_package("KIM")) GTEST_SKIP();
TEST_FAILURE(".*ERROR: Illegal 'kim init' command.*", command("kim init"););
TEST_FAILURE(".*ERROR: Illegal 'kim init' command.*",
@ -90,7 +90,7 @@ TEST_F(KimCommandsTest, kim_init)
TEST_F(KimCommandsTest, kim_interactions)
{
if (!LAMMPS::is_installed_pkg("KIM")) GTEST_SKIP();
if (!Info::has_package("KIM")) GTEST_SKIP();
TEST_FAILURE(".*ERROR: Illegal kim interactions command: missing argument.*",
command("kim interactions"););
@ -213,7 +213,7 @@ TEST_F(KimCommandsTest, kim_interactions)
TEST_F(KimCommandsTest, kim_param)
{
if (!LAMMPS::is_installed_pkg("KIM")) GTEST_SKIP();
if (!Info::has_package("KIM")) GTEST_SKIP();
TEST_FAILURE(".*ERROR: Illegal 'kim param' command.*", command("kim param"););
TEST_FAILURE(".*ERROR: Incorrect arguments in 'kim param' command.\n"
@ -401,8 +401,8 @@ TEST_F(KimCommandsTest, kim_param)
TEST_F(KimCommandsTest, kim_property)
{
if (!LAMMPS::is_installed_pkg("KIM")) GTEST_SKIP();
if (!LAMMPS::is_installed_pkg("PYTHON")) GTEST_SKIP();
if (!Info::has_package("KIM")) GTEST_SKIP();
if (!Info::has_package("PYTHON")) GTEST_SKIP();
if (!lmp->python->has_minimum_version(3, 6)) {
TEST_FAILURE(".*ERROR: Invalid Python version.\n"
@ -444,7 +444,7 @@ TEST_F(KimCommandsTest, kim_property)
TEST_F(KimCommandsTest, kim_query)
{
if (!LAMMPS::is_installed_pkg("KIM")) GTEST_SKIP();
if (!Info::has_package("KIM")) GTEST_SKIP();
TEST_FAILURE(".*ERROR: Illegal 'kim query' command.*", command("kim query"););
TEST_FAILURE(".*ERROR: Illegal 'kim query' command.\nThe keyword 'split' "

View File

@ -556,7 +556,7 @@ TEST_F(SimpleCommandsTest, CiteMe)
TEST_F(SimpleCommandsTest, Geturl)
{
if (!LAMMPS::is_installed_pkg("EXTRA-COMMAND")) GTEST_SKIP();
if (!Info::has_package("EXTRA-COMMAND")) GTEST_SKIP();
platform::unlink("index.html");
platform::unlink("myindex.html");
if (Info::has_curl_support()) {

View File

@ -175,7 +175,7 @@ protected:
// only run this test fixture with omp suffix if OPENMP package is installed
if (LAMMPS::is_installed_pkg("OPENMP"))
if (Info::has_package("OPENMP"))
lmp = new LAMMPS(args, MPI_COMM_WORLD);
else
GTEST_SKIP();
@ -264,7 +264,7 @@ protected:
if (Info::has_accelerator_feature("KOKKOS", "api", "openmp")) args[10] = "2";
if (LAMMPS::is_installed_pkg("KOKKOS")) {
if (Info::has_package("KOKKOS")) {
::testing::internal::CaptureStdout();
lmp = new LAMMPS(args, MPI_COMM_WORLD);
::testing::internal::GetCapturedStdout();
@ -329,7 +329,7 @@ TEST_F(LAMMPS_kokkos, InitMembers)
TEST(LAMMPS_init, OpenMP)
{
if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (!Info::has_package("OPENMP")) GTEST_SKIP();
if (platform::openmp_standard() == "OpenMP not enabled") GTEST_SKIP();
FILE *fp = fopen("in.lammps_empty", "w");

View File

@ -435,7 +435,7 @@ TEST(AngleStyle, plain)
TEST(AngleStyle, omp)
{
if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (!Info::has_package("OPENMP")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite",
@ -548,7 +548,7 @@ TEST(AngleStyle, omp)
TEST(AngleStyle, kokkos_omp)
{
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (!Info::has_package("KOKKOS")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
// test either OpenMP or Serial
if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") &&
@ -689,7 +689,7 @@ TEST(AngleStyle, kokkos_omp)
TEST(AngleStyle, numdiff)
{
if (!LAMMPS::is_installed_pkg("EXTRA-FIX")) GTEST_SKIP();
if (!Info::has_package("EXTRA-FIX")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"};

View File

@ -438,7 +438,7 @@ TEST(BondStyle, plain)
TEST(BondStyle, omp)
{
if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (!Info::has_package("OPENMP")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite",
@ -551,7 +551,7 @@ TEST(BondStyle, omp)
TEST(BondStyle, kokkos_omp)
{
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (!Info::has_package("KOKKOS")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
// test either OpenMP or Serial
if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") &&
@ -678,7 +678,7 @@ TEST(BondStyle, kokkos_omp)
TEST(BondStyle, numdiff)
{
if (!LAMMPS::is_installed_pkg("EXTRA-FIX")) GTEST_SKIP();
if (!Info::has_package("EXTRA-FIX")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"};

View File

@ -453,7 +453,7 @@ TEST(DihedralStyle, plain)
TEST(DihedralStyle, omp)
{
if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (!Info::has_package("OPENMP")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite",
@ -567,7 +567,7 @@ TEST(DihedralStyle, omp)
TEST(DihedralStyle, kokkos_omp)
{
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (!Info::has_package("KOKKOS")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
// test either OpenMP or Serial
if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") &&
@ -695,7 +695,7 @@ TEST(DihedralStyle, kokkos_omp)
TEST(DihedralStyle, numdiff)
{
if (!LAMMPS::is_installed_pkg("EXTRA-FIX")) GTEST_SKIP();
if (!Info::has_package("EXTRA-FIX")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"};

View File

@ -269,7 +269,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
TEST(FixTimestep, plain)
{
if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP();
if (!Info::has_package("MOLECULE")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
#if defined(USING_STATIC_LIBS)
if (test_config.skip_tests.count("static")) GTEST_SKIP();
@ -580,8 +580,8 @@ TEST(FixTimestep, plain)
TEST(FixTimestep, omp)
{
if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP();
if (!Info::has_package("OPENMP")) GTEST_SKIP();
if (!Info::has_package("MOLECULE")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
#if defined(USING_STATIC_LIBS)
if (test_config.skip_tests.count("static")) GTEST_SKIP();
@ -892,7 +892,7 @@ TEST(FixTimestep, omp)
TEST(FixTimestep, kokkos_omp)
{
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (!Info::has_package("KOKKOS")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
// test either OpenMP or Serial
if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") &&

View File

@ -431,7 +431,7 @@ TEST(ImproperStyle, plain)
TEST(ImproperStyle, omp)
{
if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (!Info::has_package("OPENMP")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite",
@ -545,7 +545,7 @@ TEST(ImproperStyle, omp)
TEST(ImproperStyle, kokkos_omp)
{
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (!Info::has_package("KOKKOS")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
// test either OpenMP or Serial
if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") &&
@ -670,7 +670,7 @@ TEST(ImproperStyle, kokkos_omp)
TEST(ImproperStyle, numdiff)
{
if (!LAMMPS::is_installed_pkg("EXTRA-FIX")) GTEST_SKIP();
if (!Info::has_package("EXTRA-FIX")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"};

View File

@ -117,7 +117,7 @@ TEST(MliapUnified, VersusLJMeltGhost)
TEST(MliapUnified, VersusLJMeltKokkos)
{
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (!Info::has_package("KOKKOS")) GTEST_SKIP();
// test either OpenMP or Serial
if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") &&
!Info::has_accelerator_feature("KOKKOS", "api", "openmp"))
@ -168,7 +168,7 @@ TEST(MliapUnified, VersusLJMeltKokkos)
TEST(MliapUnified, VersusLJMeltGhostKokkos)
{
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (!Info::has_package("KOKKOS")) GTEST_SKIP();
// test either OpenMP or Serial
if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp") &&
!Info::has_accelerator_feature("KOKKOS", "api", "serial"))

View File

@ -516,7 +516,7 @@ TEST(PairStyle, plain)
TEST(PairStyle, omp)
{
if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (!Info::has_package("OPENMP")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite",
@ -648,7 +648,7 @@ TEST(PairStyle, omp)
TEST(PairStyle, kokkos_omp)
{
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (!Info::has_package("KOKKOS")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
// test either OpenMP or Serial
if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") &&
@ -801,7 +801,7 @@ TEST(PairStyle, kokkos_omp)
TEST(PairStyle, gpu)
{
if (!LAMMPS::is_installed_pkg("GPU")) GTEST_SKIP();
if (!Info::has_package("GPU")) GTEST_SKIP();
if (!Info::has_gpu_device()) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
@ -899,7 +899,7 @@ TEST(PairStyle, gpu)
TEST(PairStyle, intel)
{
if (!LAMMPS::is_installed_pkg("INTEL")) GTEST_SKIP();
if (!Info::has_package("INTEL")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite",
@ -990,7 +990,7 @@ TEST(PairStyle, intel)
TEST(PairStyle, opt)
{
if (!LAMMPS::is_installed_pkg("OPT")) GTEST_SKIP();
if (!Info::has_package("OPT")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf", "opt"};

View File

@ -19,6 +19,7 @@
#include "atom_vec_line.h"
#include "atom_vec_tri.h"
#include "body.h"
#include "info.h"
#include "input.h"
#include "lammps.h"
#include "math_const.h"
@ -1146,7 +1147,7 @@ TEST_F(AtomStyleTest, sphere)
TEST_F(AtomStyleTest, ellipsoid)
{
if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP();
if (!Info::has_package("ASPHERE")) GTEST_SKIP();
BEGIN_HIDE_OUTPUT();
command("atom_style ellipsoid");
@ -1483,7 +1484,7 @@ TEST_F(AtomStyleTest, ellipsoid)
TEST_F(AtomStyleTest, line)
{
if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP();
if (!Info::has_package("ASPHERE")) GTEST_SKIP();
BEGIN_HIDE_OUTPUT();
command("dimension 2");
@ -1753,7 +1754,7 @@ TEST_F(AtomStyleTest, line)
TEST_F(AtomStyleTest, tri)
{
if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP();
if (!Info::has_package("ASPHERE")) GTEST_SKIP();
BEGIN_HIDE_OUTPUT();
command("atom_style tri");
@ -2156,7 +2157,7 @@ TEST_F(AtomStyleTest, tri)
TEST_F(AtomStyleTest, body_nparticle)
{
if (!LAMMPS::is_installed_pkg("BODY")) GTEST_SKIP();
if (!Info::has_package("BODY")) GTEST_SKIP();
BEGIN_HIDE_OUTPUT();
command("atom_style body nparticle 2 4");
@ -2724,7 +2725,7 @@ TEST_F(AtomStyleTest, body_nparticle)
TEST_F(AtomStyleTest, template)
{
if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP();
if (!Info::has_package("MOLECULE")) GTEST_SKIP();
BEGIN_HIDE_OUTPUT();
command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0");
command("atom_style template twomols");
@ -3119,7 +3120,7 @@ TEST_F(AtomStyleTest, template)
TEST_F(AtomStyleTest, template_charge)
{
if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP();
if (!Info::has_package("MOLECULE")) GTEST_SKIP();
BEGIN_HIDE_OUTPUT();
command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0");
command("atom_style hybrid template twomols charge");
@ -3547,7 +3548,7 @@ TEST_F(AtomStyleTest, template_charge)
TEST_F(AtomStyleTest, bond)
{
if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP();
if (!Info::has_package("MOLECULE")) GTEST_SKIP();
BEGIN_HIDE_OUTPUT();
command("atom_style bond");
@ -3895,7 +3896,7 @@ TEST_F(AtomStyleTest, bond)
TEST_F(AtomStyleTest, angle)
{
if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP();
if (!Info::has_package("MOLECULE")) GTEST_SKIP();
BEGIN_HIDE_OUTPUT();
command("atom_style angle");
@ -4255,8 +4256,8 @@ TEST_F(AtomStyleTest, angle)
TEST_F(AtomStyleTest, full_ellipsoid)
{
if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP();
if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP();
if (!Info::has_package("ASPHERE")) GTEST_SKIP();
if (!Info::has_package("MOLECULE")) GTEST_SKIP();
BEGIN_HIDE_OUTPUT();
command("atom_style hybrid full ellipsoid");
@ -4909,9 +4910,9 @@ TEST_F(AtomStyleTest, property_atom)
TEST_F(AtomStyleTest, oxdna)
{
if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP();
if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP();
if (!LAMMPS::is_installed_pkg("CG-DNA")) GTEST_SKIP();
if (!Info::has_package("MOLECULE")) GTEST_SKIP();
if (!Info::has_package("ASPHERE")) GTEST_SKIP();
if (!Info::has_package("CG-DNA")) GTEST_SKIP();
BEGIN_HIDE_OUTPUT();
command("atom_style hybrid bond ellipsoid oxdna");

View File

@ -676,7 +676,7 @@ TEST_F(MoleculeFileTest, labelmap)
TEST_F(MoleculeFileTest, bonds)
{
if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP();
if (!Info::has_package("MOLECULE")) GTEST_SKIP();
BEGIN_CAPTURE_OUTPUT();
command("atom_style bond");
command("region box block 0 1 0 1 0 1");
@ -727,7 +727,7 @@ TEST_F(MoleculeFileTest, bonds)
TEST_F(MoleculeFileTest, dipoles)
{
if (!LAMMPS::is_installed_pkg("DIPOLE")) GTEST_SKIP();
if (!Info::has_package("DIPOLE")) GTEST_SKIP();
BEGIN_CAPTURE_OUTPUT();
command("atom_style dipole");
command("region box block 0 1 0 1 0 1");