Merge remote-tracking branch 'origin/master' into refactor-table-reading
This commit is contained in:
134
src/force.cpp
134
src/force.cpp
@ -231,7 +231,7 @@ void Force::setup()
|
||||
create a pair style, called from input script or restart file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Force::create_pair(const char *style, int trysuffix)
|
||||
void Force::create_pair(const std::string &style, int trysuffix)
|
||||
{
|
||||
delete [] pair_style;
|
||||
if (pair) delete pair;
|
||||
@ -251,13 +251,12 @@ void Force::create_pair(const char *style, int trysuffix)
|
||||
return sflag = 0 for no suffix added, 1 or 2 for suffix1/2 added
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Pair *Force::new_pair(const char *style, int trysuffix, int &sflag)
|
||||
Pair *Force::new_pair(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
sflag = 1;
|
||||
char estyle[256];
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix);
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
if (pair_map->find(estyle) != pair_map->end()) {
|
||||
PairCreator pair_creator = (*pair_map)[estyle];
|
||||
return pair_creator(lmp);
|
||||
@ -265,8 +264,7 @@ Pair *Force::new_pair(const char *style, int trysuffix, int &sflag)
|
||||
}
|
||||
if (lmp->suffix2) {
|
||||
sflag = 2;
|
||||
char estyle[256];
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix2);
|
||||
std::string estyle = style + "/" + lmp->suffix2;
|
||||
if (pair_map->find(estyle) != pair_map->end()) {
|
||||
PairCreator pair_creator = (*pair_map)[estyle];
|
||||
return pair_creator(lmp);
|
||||
@ -275,7 +273,7 @@ Pair *Force::new_pair(const char *style, int trysuffix, int &sflag)
|
||||
}
|
||||
|
||||
sflag = 0;
|
||||
if (strcmp(style,"none") == 0) return NULL;
|
||||
if (style == "none") return NULL;
|
||||
if (pair_map->find(style) != pair_map->end()) {
|
||||
PairCreator pair_creator = (*pair_map)[style];
|
||||
return pair_creator(lmp);
|
||||
@ -304,17 +302,17 @@ Pair *Force::pair_creator(LAMMPS *lmp)
|
||||
return NULL if no match or if nsub=0 and multiple sub-styles match
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Pair *Force::pair_match(const char *word, int exact, int nsub)
|
||||
Pair *Force::pair_match(const std::string &word, int exact, int nsub)
|
||||
{
|
||||
int iwhich,count;
|
||||
|
||||
if (exact && strcmp(pair_style,word) == 0) return pair;
|
||||
if (exact && (word == pair_style)) return pair;
|
||||
else if (!exact && utils::strmatch(pair_style,word)) return pair;
|
||||
else if (utils::strmatch(pair_style,"^hybrid")) {
|
||||
PairHybrid *hybrid = (PairHybrid *) pair;
|
||||
count = 0;
|
||||
for (int i = 0; i < hybrid->nstyles; i++)
|
||||
if ((exact && strcmp(hybrid->keywords[i],word) == 0) ||
|
||||
if ((exact && (word == hybrid->keywords[i])) ||
|
||||
(!exact && utils::strmatch(hybrid->keywords[i],word))) {
|
||||
iwhich = i;
|
||||
count++;
|
||||
@ -349,7 +347,7 @@ char *Force::pair_match_ptr(Pair *ptr)
|
||||
create a bond style, called from input script or restart file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Force::create_bond(const char *style, int trysuffix)
|
||||
void Force::create_bond(const std::string &style, int trysuffix)
|
||||
{
|
||||
delete [] bond_style;
|
||||
if (bond) delete bond;
|
||||
@ -363,13 +361,12 @@ void Force::create_bond(const char *style, int trysuffix)
|
||||
generate a bond class, fist with suffix appended
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Bond *Force::new_bond(const char *style, int trysuffix, int &sflag)
|
||||
Bond *Force::new_bond(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
sflag = 1;
|
||||
char estyle[256];
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix);
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
if (bond_map->find(estyle) != bond_map->end()) {
|
||||
BondCreator bond_creator = (*bond_map)[estyle];
|
||||
return bond_creator(lmp);
|
||||
@ -378,8 +375,7 @@ Bond *Force::new_bond(const char *style, int trysuffix, int &sflag)
|
||||
|
||||
if (lmp->suffix2) {
|
||||
sflag = 2;
|
||||
char estyle[256];
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix2);
|
||||
std::string estyle = style + "/" + lmp->suffix2;
|
||||
if (bond_map->find(estyle) != bond_map->end()) {
|
||||
BondCreator bond_creator = (*bond_map)[estyle];
|
||||
return bond_creator(lmp);
|
||||
@ -388,7 +384,7 @@ Bond *Force::new_bond(const char *style, int trysuffix, int &sflag)
|
||||
}
|
||||
|
||||
sflag = 0;
|
||||
if (strcmp(style,"none") == 0) return NULL;
|
||||
if (style == "none") return NULL;
|
||||
if (bond_map->find(style) != bond_map->end()) {
|
||||
BondCreator bond_creator = (*bond_map)[style];
|
||||
return bond_creator(lmp);
|
||||
@ -413,13 +409,13 @@ Bond *Force::bond_creator(LAMMPS *lmp)
|
||||
return ptr to current bond class or hybrid sub-class if matches style
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Bond *Force::bond_match(const char *style)
|
||||
Bond *Force::bond_match(const std::string &style)
|
||||
{
|
||||
if (strcmp(bond_style,style) == 0) return bond;
|
||||
if (style == bond_style) return bond;
|
||||
else if (strcmp(bond_style,"hybrid") == 0) {
|
||||
BondHybrid *hybrid = (BondHybrid *) bond;
|
||||
for (int i = 0; i < hybrid->nstyles; i++)
|
||||
if (strcmp(hybrid->keywords[i],style) == 0) return hybrid->styles[i];
|
||||
if (style == hybrid->keywords[i]) return hybrid->styles[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -428,7 +424,7 @@ Bond *Force::bond_match(const char *style)
|
||||
create an angle style, called from input script or restart file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Force::create_angle(const char *style, int trysuffix)
|
||||
void Force::create_angle(const std::string &style, int trysuffix)
|
||||
{
|
||||
delete [] angle_style;
|
||||
if (angle) delete angle;
|
||||
@ -442,13 +438,12 @@ void Force::create_angle(const char *style, int trysuffix)
|
||||
generate an angle class
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Angle *Force::new_angle(const char *style, int trysuffix, int &sflag)
|
||||
Angle *Force::new_angle(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
sflag = 1;
|
||||
char estyle[256];
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix);
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
if (angle_map->find(estyle) != angle_map->end()) {
|
||||
AngleCreator angle_creator = (*angle_map)[estyle];
|
||||
return angle_creator(lmp);
|
||||
@ -457,8 +452,7 @@ Angle *Force::new_angle(const char *style, int trysuffix, int &sflag)
|
||||
|
||||
if (lmp->suffix2) {
|
||||
sflag = 2;
|
||||
char estyle[256];
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix);
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
if (angle_map->find(estyle) != angle_map->end()) {
|
||||
AngleCreator angle_creator = (*angle_map)[estyle];
|
||||
return angle_creator(lmp);
|
||||
@ -467,7 +461,7 @@ Angle *Force::new_angle(const char *style, int trysuffix, int &sflag)
|
||||
}
|
||||
|
||||
sflag = 0;
|
||||
if (strcmp(style,"none") == 0) return NULL;
|
||||
if (style == "none") return NULL;
|
||||
if (angle_map->find(style) != angle_map->end()) {
|
||||
AngleCreator angle_creator = (*angle_map)[style];
|
||||
return angle_creator(lmp);
|
||||
@ -488,18 +482,17 @@ Angle *Force::angle_creator(LAMMPS *lmp)
|
||||
return new T(lmp);
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
return ptr to current angle class or hybrid sub-class if matches style
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Angle *Force::angle_match(const char *style)
|
||||
Angle *Force::angle_match(const std::string &style)
|
||||
{
|
||||
if (strcmp(angle_style,style) == 0) return angle;
|
||||
else if (strcmp(angle_style,"hybrid") == 0) {
|
||||
if (style == angle_style) return angle;
|
||||
else if (utils::strmatch(angle_style,"^hybrid")) {
|
||||
AngleHybrid *hybrid = (AngleHybrid *) angle;
|
||||
for (int i = 0; i < hybrid->nstyles; i++)
|
||||
if (strcmp(hybrid->keywords[i],style) == 0) return hybrid->styles[i];
|
||||
if (style == hybrid->keywords[i]) return hybrid->styles[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -508,7 +501,7 @@ Angle *Force::angle_match(const char *style)
|
||||
create a dihedral style, called from input script or restart file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Force::create_dihedral(const char *style, int trysuffix)
|
||||
void Force::create_dihedral(const std::string &style, int trysuffix)
|
||||
{
|
||||
delete [] dihedral_style;
|
||||
if (dihedral) delete dihedral;
|
||||
@ -522,13 +515,12 @@ void Force::create_dihedral(const char *style, int trysuffix)
|
||||
generate a dihedral class
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Dihedral *Force::new_dihedral(const char *style, int trysuffix, int &sflag)
|
||||
Dihedral *Force::new_dihedral(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
sflag = 1;
|
||||
char estyle[256];
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix);
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
if (dihedral_map->find(estyle) != dihedral_map->end()) {
|
||||
DihedralCreator dihedral_creator = (*dihedral_map)[estyle];
|
||||
return dihedral_creator(lmp);
|
||||
@ -537,8 +529,7 @@ Dihedral *Force::new_dihedral(const char *style, int trysuffix, int &sflag)
|
||||
|
||||
if (lmp->suffix2) {
|
||||
sflag = 2;
|
||||
char estyle[256];
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix2);
|
||||
std::string estyle = style + "/" + lmp->suffix2;
|
||||
if (dihedral_map->find(estyle) != dihedral_map->end()) {
|
||||
DihedralCreator dihedral_creator = (*dihedral_map)[estyle];
|
||||
return dihedral_creator(lmp);
|
||||
@ -547,7 +538,7 @@ Dihedral *Force::new_dihedral(const char *style, int trysuffix, int &sflag)
|
||||
}
|
||||
|
||||
sflag = 0;
|
||||
if (strcmp(style,"none") == 0) return NULL;
|
||||
if (style == "none") return NULL;
|
||||
if (dihedral_map->find(style) != dihedral_map->end()) {
|
||||
DihedralCreator dihedral_creator = (*dihedral_map)[style];
|
||||
return dihedral_creator(lmp);
|
||||
@ -572,13 +563,13 @@ Dihedral *Force::dihedral_creator(LAMMPS *lmp)
|
||||
return ptr to current angle class or hybrid sub-class if matches style
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Dihedral *Force::dihedral_match(const char *style)
|
||||
Dihedral *Force::dihedral_match(const std::string &style)
|
||||
{
|
||||
if (strcmp(dihedral_style,style) == 0) return dihedral;
|
||||
else if (strcmp(dihedral_style,"hybrid") == 0) {
|
||||
if (style == dihedral_style) return dihedral;
|
||||
else if (utils::strmatch(dihedral_style,"^hybrid")) {
|
||||
DihedralHybrid *hybrid = (DihedralHybrid *) dihedral;
|
||||
for (int i = 0; i < hybrid->nstyles; i++)
|
||||
if (strcmp(hybrid->keywords[i],style) == 0) return hybrid->styles[i];
|
||||
if (style == hybrid->keywords[i]) return hybrid->styles[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -587,7 +578,7 @@ Dihedral *Force::dihedral_match(const char *style)
|
||||
create an improper style, called from input script or restart file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Force::create_improper(const char *style, int trysuffix)
|
||||
void Force::create_improper(const std::string &style, int trysuffix)
|
||||
{
|
||||
delete [] improper_style;
|
||||
if (improper) delete improper;
|
||||
@ -601,13 +592,12 @@ void Force::create_improper(const char *style, int trysuffix)
|
||||
generate a improper class
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Improper *Force::new_improper(const char *style, int trysuffix, int &sflag)
|
||||
Improper *Force::new_improper(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
sflag = 1;
|
||||
char estyle[256];
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix);
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
if (improper_map->find(estyle) != improper_map->end()) {
|
||||
ImproperCreator improper_creator = (*improper_map)[estyle];
|
||||
return improper_creator(lmp);
|
||||
@ -616,8 +606,7 @@ Improper *Force::new_improper(const char *style, int trysuffix, int &sflag)
|
||||
|
||||
if (lmp->suffix2) {
|
||||
sflag = 2;
|
||||
char estyle[256];
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix2);
|
||||
std::string estyle = style + "/" + lmp->suffix2;
|
||||
if (improper_map->find(estyle) != improper_map->end()) {
|
||||
ImproperCreator improper_creator = (*improper_map)[estyle];
|
||||
return improper_creator(lmp);
|
||||
@ -626,7 +615,7 @@ Improper *Force::new_improper(const char *style, int trysuffix, int &sflag)
|
||||
}
|
||||
|
||||
sflag = 0;
|
||||
if (strcmp(style,"none") == 0) return NULL;
|
||||
if (style == "none") return NULL;
|
||||
if (improper_map->find(style) != improper_map->end()) {
|
||||
ImproperCreator improper_creator = (*improper_map)[style];
|
||||
return improper_creator(lmp);
|
||||
@ -651,13 +640,13 @@ Improper *Force::improper_creator(LAMMPS *lmp)
|
||||
return ptr to current improper class or hybrid sub-class if matches style
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Improper *Force::improper_match(const char *style)
|
||||
Improper *Force::improper_match(const std::string &style)
|
||||
{
|
||||
if (strcmp(improper_style,style) == 0) return improper;
|
||||
else if (strcmp(improper_style,"hybrid") == 0) {
|
||||
if (style == improper_style) return improper;
|
||||
else if (utils::strmatch(improper_style,"^hybrid")) {
|
||||
ImproperHybrid *hybrid = (ImproperHybrid *) improper;
|
||||
for (int i = 0; i < hybrid->nstyles; i++)
|
||||
if (strcmp(hybrid->keywords[i],style) == 0) return hybrid->styles[i];
|
||||
if (style == hybrid->keywords[i]) return hybrid->styles[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -666,7 +655,7 @@ Improper *Force::improper_match(const char *style)
|
||||
new kspace style
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Force::create_kspace(const char *style, int trysuffix)
|
||||
void Force::create_kspace(const std::string &style, int trysuffix)
|
||||
{
|
||||
delete [] kspace_style;
|
||||
if (kspace) delete kspace;
|
||||
@ -684,13 +673,12 @@ void Force::create_kspace(const char *style, int trysuffix)
|
||||
generate a kspace class
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
KSpace *Force::new_kspace(const char *style, int trysuffix, int &sflag)
|
||||
KSpace *Force::new_kspace(const std::string &style, int trysuffix, int &sflag)
|
||||
{
|
||||
if (trysuffix && lmp->suffix_enable) {
|
||||
if (lmp->suffix) {
|
||||
sflag = 1;
|
||||
char estyle[256];
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix);
|
||||
std::string estyle = style + "/" + lmp->suffix;
|
||||
if (kspace_map->find(estyle) != kspace_map->end()) {
|
||||
KSpaceCreator kspace_creator = (*kspace_map)[estyle];
|
||||
return kspace_creator(lmp);
|
||||
@ -699,8 +687,7 @@ KSpace *Force::new_kspace(const char *style, int trysuffix, int &sflag)
|
||||
|
||||
if (lmp->suffix2) {
|
||||
sflag = 1;
|
||||
char estyle[256];
|
||||
snprintf(estyle,256,"%s/%s",style,lmp->suffix2);
|
||||
std::string estyle = style + "/" + lmp->suffix2;
|
||||
if (kspace_map->find(estyle) != kspace_map->end()) {
|
||||
KSpaceCreator kspace_creator = (*kspace_map)[estyle];
|
||||
return kspace_creator(lmp);
|
||||
@ -709,7 +696,7 @@ KSpace *Force::new_kspace(const char *style, int trysuffix, int &sflag)
|
||||
}
|
||||
|
||||
sflag = 0;
|
||||
if (strcmp(style,"none") == 0) return NULL;
|
||||
if (style == "none") return NULL;
|
||||
if (kspace_map->find(style) != kspace_map->end()) {
|
||||
KSpaceCreator kspace_creator = (*kspace_map)[style];
|
||||
return kspace_creator(lmp);
|
||||
@ -737,9 +724,9 @@ KSpace *Force::kspace_creator(LAMMPS *lmp)
|
||||
return NULL if no match
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
KSpace *Force::kspace_match(const char *word, int exact)
|
||||
KSpace *Force::kspace_match(const std::string &word, int exact)
|
||||
{
|
||||
if (exact && strcmp(kspace_style,word) == 0) return kspace;
|
||||
if (exact && (word == kspace_style)) return kspace;
|
||||
else if (!exact && utils::strmatch(kspace_style,word)) return kspace;
|
||||
return NULL;
|
||||
}
|
||||
@ -750,20 +737,15 @@ KSpace *Force::kspace_match(const char *word, int exact)
|
||||
if sflag = 1/2, append suffix or suffix2 to style
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Force::store_style(char *&str, const char *style, int sflag)
|
||||
void Force::store_style(char *&str, const std::string &style, int sflag)
|
||||
{
|
||||
if (sflag) {
|
||||
char estyle[256];
|
||||
if (sflag == 1) snprintf(estyle,256,"%s/%s",style,lmp->suffix);
|
||||
else snprintf(estyle,256,"%s/%s",style,lmp->suffix2);
|
||||
int n = strlen(estyle) + 1;
|
||||
str = new char[n];
|
||||
strcpy(str,estyle);
|
||||
} else {
|
||||
int n = strlen(style) + 1;
|
||||
str = new char[n];
|
||||
strcpy(str,style);
|
||||
}
|
||||
std::string estyle = style;
|
||||
|
||||
if (sflag == 1) estyle += std::string("/") + lmp->suffix;
|
||||
else if (sflag == 2) estyle += std::string("/") + lmp->suffix2;
|
||||
|
||||
str = new char[estyle.size()+1];
|
||||
strcpy(str,estyle.c_str());
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user