use a local std::map with initializer to have variant specific strings

This commit is contained in:
Axel Kohlmeyer
2022-02-16 06:36:17 -05:00
parent e541f006eb
commit 47bb5f5ccd

View File

@ -37,6 +37,7 @@
#include <cmath>
#include <cstring>
#include <map>
using namespace LAMMPS_NS;
using namespace InterLayer;
@ -56,6 +57,12 @@ static const char cite_ilp[] =
" year = 2018,\n"
"}\n\n";
// to indicate which potential style was used in outputs
static std::map<int, std::string> variant_map = {
{PairILPGrapheneHBN::ILP_GrhBN, "ilp/graphene/hbn"},
{PairILPGrapheneHBN::ILP_TMD, "ilp/tmd"},
{PairILPGrapheneHBN::SAIP_METAL, "saip/metal"}};
/* ---------------------------------------------------------------------- */
PairILPGrapheneHBN::PairILPGrapheneHBN(LAMMPS *lmp) : Pair(lmp), variant(ILP_GrhBN)
@ -209,24 +216,7 @@ void PairILPGrapheneHBN::read_file(char *filename)
// open file on proc 0
if (comm->me == 0) {
std::string potential_name;
switch (variant) {
case ILP_GrhBN:
potential_name = "ilp/graphene/hbn";
break;
case ILP_TMD:
potential_name = "ilp/tmd";
break;
case SAIP_METAL:
potential_name = "saip/metal";
break;
default:
error->one(FLERR, "Unknown ILP style variant {}", variant);
}
PotentialFileReader reader(lmp, filename, potential_name, unit_convert_flag);
PotentialFileReader reader(lmp, filename, variant_map[variant], unit_convert_flag);
char *line;
// transparently convert units for supported conversions
@ -324,11 +314,15 @@ void PairILPGrapheneHBN::read_file(char *filename)
int n = -1;
for (int m = 0; m < nparams; m++) {
if (i == params[m].ielement && j == params[m].jelement) {
if (n >= 0) error->all(FLERR, "ILP potential file has duplicate entry");
if (n >= 0)
error->all(FLERR, "{} potential file {} has a duplicate entry", variant_map[variant],
filename);
n = m;
}
}
if (n < 0) error->all(FLERR, "Potential file is missing an entry");
if (n < 0)
error->all(FLERR, "{} potential file {} is missing an entry", variant_map[variant],
filename);
elem2param[i][j] = n;
cutILPsq[i][j] = params[n].rcut * params[n].rcut;
}
@ -341,8 +335,10 @@ void PairILPGrapheneHBN::read_file(char *filename)
void PairILPGrapheneHBN::init_style()
{
if (force->newton_pair == 0) error->all(FLERR, "Pair style ilp/* requires newton pair on");
if (!atom->molecule_flag) error->all(FLERR, "Pair style ilp/* requires atom attribute molecule");
if (force->newton_pair == 0)
error->all(FLERR, "Pair style {} requires newton pair on", variant_map[variant]);
if (!atom->molecule_flag)
error->all(FLERR, "Pair style {} requires atom attribute molecule", variant_map[variant]);
// need a full neighbor list, including neighbors of ghosts