modernize by using anonymous namespace

This commit is contained in:
Axel Kohlmeyer
2025-06-29 19:33:20 -04:00
parent 47332f8e46
commit cd44539429
2 changed files with 34 additions and 32 deletions

View File

@ -75,7 +75,7 @@
#include <thread>
/* ------------------------------------------------------------------ */
namespace {
/// Struct for listing on-the-fly compression/decompression commands
struct compress_info {
/// identifier for the different compression algorithms
@ -88,7 +88,7 @@ struct compress_info {
};
// clang-format off
static const std::vector<compress_info> compress_styles = {
const std::vector<compress_info> compress_styles = {
{"", "", "", "", compress_info::NONE},
{"gz", "gzip", " > ", " -cdf ", compress_info::GZIP},
{"bz2", "bzip2", " > ", " -cdf ", compress_info::BZIP2},
@ -101,7 +101,7 @@ static const std::vector<compress_info> compress_styles = {
/* ------------------------------------------------------------------ */
static const compress_info &find_compress_type(const std::string &file)
const compress_info &find_compress_type(const std::string &file)
{
std::size_t dot = file.find_last_of('.');
if (dot != std::string::npos) {
@ -117,8 +117,8 @@ static const compress_info &find_compress_type(const std::string &file)
// set reference time stamp during executable/library init.
// should provide better resolution than using epoch, if the system clock supports it.
static auto initial_time = std::chrono::steady_clock::now();
auto initial_time = std::chrono::steady_clock::now();
}
using namespace LAMMPS_NS;
// get CPU time
@ -755,12 +755,11 @@ std::string platform::current_directory()
#if defined(_WIN32)
char *buf = new char[MAX_PATH];
if (_getcwd(buf, MAX_PATH)) { cwd = buf; }
delete[] buf;
#else
auto buf = new char[PATH_MAX];
if (::getcwd(buf, PATH_MAX)) { cwd = buf; }
delete[] buf;
#endif
delete[] buf;
return cwd;
}

View File

@ -52,10 +52,13 @@ static constexpr int CHUNK = 1024;
static constexpr int DELTA = 4; // must be 2 or larger
static constexpr int MAXBODY = 32; // max # of lines in one body
enum { NONE, APPEND, VALUE, MERGE };
// customize for new sections
namespace {
// clang-format off
static std::unordered_set<std::string> section_keywords = {
std::unordered_set<std::string> section_keywords = {
"Atoms", "Velocities", "Ellipsoids", "Lines", "Triangles", "Bodies",
"Bonds", "Angles", "Dihedrals", "Impropers",
"Masses", "Pair Coeffs", "PairIJ Coeffs", "Bond Coeffs", "Angle Coeffs",
@ -66,6 +69,17 @@ static std::unordered_set<std::string> section_keywords = {
"Atom Type Labels", "Bond Type Labels", "Angle Type Labels",
"Dihedral Type Labels", "Improper Type Labels"
};
// clang-format on
// pair style suffixes to ignore
// when matching Pair Coeffs comment to currently-defined pair style
const std::vector<const char *> suffixes = {"/cuda", "/gpu", "/opt", "/omp",
"/kk", "/coul/cut", "/coul/long", "/coul/msm",
"/coul/dsf", "/coul/debye", "/coul/charmm"};
const char *const labeltypes[] = {"Atom", "Bond", "Angle", "Dihedral", "Improper"};
} // namespace
// function to check whether a string is a known data section name
// made a static class member, so it can be called from other classes
@ -75,17 +89,6 @@ bool ReadData::is_data_section(const std::string &keyword)
return section_keywords.count(keyword) > 0;
}
enum{NONE, APPEND, VALUE, MERGE};
// pair style suffixes to ignore
// when matching Pair Coeffs comment to currently-defined pair style
static const char *suffixes[] = {"/cuda", "/gpu", "/opt", "/omp", "/kk", "/coul/cut", "/coul/long",
"/coul/msm", "/coul/dsf", "/coul/debye", "/coul/charmm", nullptr};
static const char *labeltypes[] = {"Atom", "Bond", "Angle", "Dihedral", "Improper" };
// clang-format on
/* ---------------------------------------------------------------------- */
ReadData::ReadData(LAMMPS *_lmp) : Command(_lmp), fp(nullptr), coeffarg(nullptr), lmap(nullptr)
{
@ -1178,7 +1181,7 @@ void ReadData::command(int narg, char **arg)
if (addflag != NONE) {
if (domain->triclinic) domain->x2lamda(atom->nlocal);
auto irregular = new Irregular(lmp);
auto *irregular = new Irregular(lmp);
irregular->migrate_atoms(1);
delete irregular;
if (domain->triclinic) domain->lamda2x(atom->nlocal);
@ -1194,7 +1197,7 @@ void ReadData::command(int narg, char **arg)
if (domain->nonperiodic == 2) {
if (domain->triclinic) domain->x2lamda(atom->nlocal);
domain->reset_box();
auto irregular = new Irregular(lmp);
auto *irregular = new Irregular(lmp);
irregular->migrate_atoms(1);
delete irregular;
if (domain->triclinic) domain->lamda2x(atom->nlocal);
@ -2131,7 +2134,7 @@ void ReadData::mass()
{
settypeflag = 1;
char *next;
auto buf = new char[ntypes * MAXLINE];
auto *buf = new char[ntypes * MAXLINE];
int eof = utils::read_lines_from_file(fp, ntypes, MAXLINE, buf, me, world);
if (eof) error->all(FLERR, "Unexpected end of data file");
@ -2153,7 +2156,7 @@ void ReadData::mass()
void ReadData::paircoeffs()
{
char *next;
auto buf = new char[ntypes * MAXLINE];
auto *buf = new char[ntypes * MAXLINE];
int eof = utils::read_lines_from_file(fp, ntypes, MAXLINE, buf, me, world);
if (eof) error->all(FLERR, "Unexpected end of data file");
@ -2182,7 +2185,7 @@ void ReadData::pairIJcoeffs()
char *next;
int nsq = ntypes * (ntypes + 1) / 2;
auto buf = new char[nsq * MAXLINE];
auto *buf = new char[nsq * MAXLINE];
int eof = utils::read_lines_from_file(fp, nsq, MAXLINE, buf, me, world);
if (eof) error->all(FLERR, "Unexpected end of data file");
@ -2211,7 +2214,7 @@ void ReadData::bondcoeffs()
if (!nbondtypes) return;
char *next;
auto buf = new char[nbondtypes * MAXLINE];
auto *buf = new char[nbondtypes * MAXLINE];
int eof = utils::read_lines_from_file(fp, nbondtypes, MAXLINE, buf, me, world);
if (eof) error->all(FLERR, "Unexpected end of data file");
@ -2240,7 +2243,7 @@ void ReadData::anglecoeffs(int which)
if (!nangletypes) return;
char *next;
auto buf = new char[nangletypes * MAXLINE];
auto *buf = new char[nangletypes * MAXLINE];
int eof = utils::read_lines_from_file(fp, nangletypes, MAXLINE, buf, me, world);
if (eof) error->all(FLERR, "Unexpected end of data file");
@ -2274,7 +2277,7 @@ void ReadData::dihedralcoeffs(int which)
if (!ndihedraltypes) return;
char *next;
auto buf = new char[ndihedraltypes * MAXLINE];
auto *buf = new char[ndihedraltypes * MAXLINE];
int eof = utils::read_lines_from_file(fp, ndihedraltypes, MAXLINE, buf, me, world);
if (eof) error->all(FLERR, "Unexpected end of data file");
@ -2312,7 +2315,7 @@ void ReadData::impropercoeffs(int which)
if (!nimpropertypes) return;
char *next;
auto buf = new char[nimpropertypes * MAXLINE];
auto *buf = new char[nimpropertypes * MAXLINE];
int eof = utils::read_lines_from_file(fp, nimpropertypes, MAXLINE, buf, me, world);
if (eof) error->all(FLERR, "Unexpected end of data file");
@ -2640,12 +2643,12 @@ int ReadData::style_match(const char *one, const char *two)
len1 = strlen(one);
len2 = strlen(two);
for (i = 0; suffixes[i] != nullptr; i++) {
len = strlen(suffixes[i]);
for (const auto &suffix : suffixes) {
len = strlen(suffix);
if ((delta = len1 - len) > 0)
if (strcmp(one + delta, suffixes[i]) == 0) len1 = delta;
if (strcmp(one + delta, suffix) == 0) len1 = delta;
if ((delta = len2 - len) > 0)
if (strcmp(two + delta, suffixes[i]) == 0) len2 = delta;
if (strcmp(two + delta, suffix) == 0) len2 = delta;
}
if ((len1 == 0) || (len1 == len2) || (strncmp(one, two, len1) == 0)) return 1;