Update pair nb3b harmonic
This commit is contained in:
@ -30,10 +30,11 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "tokenizer.h"
|
||||||
|
#include "potential_file_reader.h"
|
||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
|
|
||||||
#define MAXLINE 1024
|
|
||||||
#define DELTA 4
|
#define DELTA 4
|
||||||
#define SMALL 0.001
|
#define SMALL 0.001
|
||||||
#define PI 3.141592653589793238462643383279
|
#define PI 3.141592653589793238462643383279
|
||||||
@ -283,92 +284,37 @@ double PairNb3bHarmonic::init_one(int i, int j)
|
|||||||
|
|
||||||
void PairNb3bHarmonic::read_file(char *file)
|
void PairNb3bHarmonic::read_file(char *file)
|
||||||
{
|
{
|
||||||
int params_per_line = 6;
|
|
||||||
char **words = new char*[params_per_line+1];
|
|
||||||
|
|
||||||
memory->sfree(params);
|
memory->sfree(params);
|
||||||
params = NULL;
|
params = nullptr;
|
||||||
nparams = maxparam = 0;
|
nparams = maxparam = 0;
|
||||||
|
|
||||||
// open file on proc 0
|
// open file on proc 0
|
||||||
|
|
||||||
FILE *fp = NULL;
|
|
||||||
if (comm->me == 0) {
|
if (comm->me == 0) {
|
||||||
fp = force->open_potential(file);
|
PotentialFileReader reader(lmp, file, "nb3b/harmonic");
|
||||||
if (fp == NULL) {
|
char * line;
|
||||||
char str[128];
|
|
||||||
snprintf(str,128,"Cannot open nb3b/harmonic potential file %s",file);
|
|
||||||
error->one(FLERR,str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// read each set of params from potential file
|
while(line = reader.next_line(NPARAMS_PER_LINE)) {
|
||||||
// one set of params can span multiple lines
|
try {
|
||||||
// store params if all 3 element tags are in element list
|
ValueTokenizer values(line, " \t\n\r\f");
|
||||||
|
|
||||||
int n,nwords,ielement,jelement,kelement;
|
std::string iname = values.next_string();
|
||||||
char line[MAXLINE],*ptr;
|
std::string jname = values.next_string();
|
||||||
int eof = 0;
|
std::string kname = values.next_string();
|
||||||
|
|
||||||
while (1) {
|
|
||||||
if (comm->me == 0) {
|
|
||||||
ptr = fgets(line,MAXLINE,fp);
|
|
||||||
if (ptr == NULL) {
|
|
||||||
eof = 1;
|
|
||||||
fclose(fp);
|
|
||||||
} else n = strlen(line) + 1;
|
|
||||||
}
|
|
||||||
MPI_Bcast(&eof,1,MPI_INT,0,world);
|
|
||||||
if (eof) break;
|
|
||||||
MPI_Bcast(&n,1,MPI_INT,0,world);
|
|
||||||
MPI_Bcast(line,n,MPI_CHAR,0,world);
|
|
||||||
|
|
||||||
// strip comment, skip line if blank
|
|
||||||
|
|
||||||
if ((ptr = strchr(line,'#'))) *ptr = '\0';
|
|
||||||
nwords = utils::count_words(line);
|
|
||||||
if (nwords == 0) continue;
|
|
||||||
|
|
||||||
// concatenate additional lines until have params_per_line words
|
|
||||||
|
|
||||||
while (nwords < params_per_line) {
|
|
||||||
n = strlen(line);
|
|
||||||
if (comm->me == 0) {
|
|
||||||
ptr = fgets(&line[n],MAXLINE-n,fp);
|
|
||||||
if (ptr == NULL) {
|
|
||||||
eof = 1;
|
|
||||||
fclose(fp);
|
|
||||||
} else n = strlen(line) + 1;
|
|
||||||
}
|
|
||||||
MPI_Bcast(&eof,1,MPI_INT,0,world);
|
|
||||||
if (eof) break;
|
|
||||||
MPI_Bcast(&n,1,MPI_INT,0,world);
|
|
||||||
MPI_Bcast(line,n,MPI_CHAR,0,world);
|
|
||||||
if ((ptr = strchr(line,'#'))) *ptr = '\0';
|
|
||||||
nwords = utils::count_words(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nwords != params_per_line)
|
|
||||||
error->all(FLERR,"Incorrect format in nb3b/harmonic potential file");
|
|
||||||
|
|
||||||
// words = ptrs to all words in line
|
|
||||||
|
|
||||||
nwords = 0;
|
|
||||||
words[nwords++] = strtok(line," \t\n\r\f");
|
|
||||||
while ((words[nwords++] = strtok(NULL," \t\n\r\f"))) continue;
|
|
||||||
|
|
||||||
// ielement,jelement,kelement = 1st args
|
// ielement,jelement,kelement = 1st args
|
||||||
// if all 3 args are in element list, then parse this line
|
// if all 3 args are in element list, then parse this line
|
||||||
// else skip to next entry in file
|
// else skip to next entry in file
|
||||||
|
int ielement, jelement, kelement;
|
||||||
|
|
||||||
for (ielement = 0; ielement < nelements; ielement++)
|
for (ielement = 0; ielement < nelements; ielement++)
|
||||||
if (strcmp(words[0],elements[ielement]) == 0) break;
|
if (iname == elements[ielement]) break;
|
||||||
if (ielement == nelements) continue;
|
if (ielement == nelements) continue;
|
||||||
for (jelement = 0; jelement < nelements; jelement++)
|
for (jelement = 0; jelement < nelements; jelement++)
|
||||||
if (strcmp(words[1],elements[jelement]) == 0) break;
|
if (jname == elements[jelement]) break;
|
||||||
if (jelement == nelements) continue;
|
if (jelement == nelements) continue;
|
||||||
for (kelement = 0; kelement < nelements; kelement++)
|
for (kelement = 0; kelement < nelements; kelement++)
|
||||||
if (strcmp(words[2],elements[kelement]) == 0) break;
|
if (kname == elements[kelement]) break;
|
||||||
if (kelement == nelements) continue;
|
if (kelement == nelements) continue;
|
||||||
|
|
||||||
// load up parameter settings and error check their values
|
// load up parameter settings and error check their values
|
||||||
@ -382,18 +328,29 @@ void PairNb3bHarmonic::read_file(char *file)
|
|||||||
params[nparams].ielement = ielement;
|
params[nparams].ielement = ielement;
|
||||||
params[nparams].jelement = jelement;
|
params[nparams].jelement = jelement;
|
||||||
params[nparams].kelement = kelement;
|
params[nparams].kelement = kelement;
|
||||||
params[nparams].k_theta = atof(words[3]);
|
params[nparams].k_theta = values.next_double();
|
||||||
params[nparams].theta0 = atof(words[4]);
|
params[nparams].theta0 = values.next_double();
|
||||||
params[nparams].cutoff = atof(words[5]);
|
params[nparams].cutoff = values.next_double();
|
||||||
|
} catch (TokenizerException & e) {
|
||||||
|
error->one(FLERR, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
if (params[nparams].k_theta < 0.0 || params[nparams].theta0 < 0.0 ||
|
if (params[nparams].k_theta < 0.0 || params[nparams].theta0 < 0.0 ||
|
||||||
params[nparams].cutoff < 0.0)
|
params[nparams].cutoff < 0.0)
|
||||||
error->all(FLERR,"Illegal nb3b/harmonic parameter");
|
error->one(FLERR,"Illegal nb3b/harmonic parameter");
|
||||||
|
|
||||||
nparams++;
|
nparams++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delete [] words;
|
MPI_Bcast(&nparams, 1, MPI_INT, 0, world);
|
||||||
|
MPI_Bcast(&maxparam, 1, MPI_INT, 0, world);
|
||||||
|
|
||||||
|
if(comm->me != 0) {
|
||||||
|
params = (Param *) memory->srealloc(params,maxparam*sizeof(Param), "pair:params");
|
||||||
|
}
|
||||||
|
|
||||||
|
MPI_Bcast(params, maxparam*sizeof(Param), MPI_BYTE, 0, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|||||||
@ -34,6 +34,8 @@ class PairNb3bHarmonic : public Pair {
|
|||||||
double init_one(int, int);
|
double init_one(int, int);
|
||||||
void init_style();
|
void init_style();
|
||||||
|
|
||||||
|
static const int NPARAMS_PER_LINE = 6;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct Param {
|
struct Param {
|
||||||
double k_theta, theta0, cutoff;
|
double k_theta, theta0, cutoff;
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
#include "MANYBODY/pair_tersoff_zbl.h"
|
#include "MANYBODY/pair_tersoff_zbl.h"
|
||||||
#include "MANYBODY/pair_gw.h"
|
#include "MANYBODY/pair_gw.h"
|
||||||
#include "MANYBODY/pair_gw_zbl.h"
|
#include "MANYBODY/pair_gw_zbl.h"
|
||||||
|
#include "MANYBODY/pair_nb3b_harmonic.h"
|
||||||
|
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ const int LAMMPS_NS::PairTersoffMODC::NPARAMS_PER_LINE;
|
|||||||
const int LAMMPS_NS::PairTersoffZBL::NPARAMS_PER_LINE;
|
const int LAMMPS_NS::PairTersoffZBL::NPARAMS_PER_LINE;
|
||||||
const int LAMMPS_NS::PairGW::NPARAMS_PER_LINE;
|
const int LAMMPS_NS::PairGW::NPARAMS_PER_LINE;
|
||||||
const int LAMMPS_NS::PairGWZBL::NPARAMS_PER_LINE;
|
const int LAMMPS_NS::PairGWZBL::NPARAMS_PER_LINE;
|
||||||
|
const int LAMMPS_NS::PairNb3bHarmonic::NPARAMS_PER_LINE;
|
||||||
|
|
||||||
class PotenialFileReaderTest : public ::testing::Test {
|
class PotenialFileReaderTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
@ -85,7 +87,7 @@ TEST_F(PotenialFileReaderTest, Tersoff) {
|
|||||||
|
|
||||||
TEST_F(PotenialFileReaderTest, TersoffMod) {
|
TEST_F(PotenialFileReaderTest, TersoffMod) {
|
||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
PotentialFileReader reader(lmp, "Si.tersoff.mod", "Tersoff");
|
PotentialFileReader reader(lmp, "Si.tersoff.mod", "Tersoff/Mod");
|
||||||
::testing::internal::GetCapturedStdout();
|
::testing::internal::GetCapturedStdout();
|
||||||
|
|
||||||
auto line = reader.next_line(PairTersoffMOD::NPARAMS_PER_LINE);
|
auto line = reader.next_line(PairTersoffMOD::NPARAMS_PER_LINE);
|
||||||
@ -94,7 +96,7 @@ TEST_F(PotenialFileReaderTest, TersoffMod) {
|
|||||||
|
|
||||||
TEST_F(PotenialFileReaderTest, TersoffModC) {
|
TEST_F(PotenialFileReaderTest, TersoffModC) {
|
||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
PotentialFileReader reader(lmp, "Si.tersoff.modc", "Tersoff");
|
PotentialFileReader reader(lmp, "Si.tersoff.modc", "Tersoff/ModC");
|
||||||
::testing::internal::GetCapturedStdout();
|
::testing::internal::GetCapturedStdout();
|
||||||
|
|
||||||
auto line = reader.next_line(PairTersoffMODC::NPARAMS_PER_LINE);
|
auto line = reader.next_line(PairTersoffMODC::NPARAMS_PER_LINE);
|
||||||
@ -103,7 +105,7 @@ TEST_F(PotenialFileReaderTest, TersoffModC) {
|
|||||||
|
|
||||||
TEST_F(PotenialFileReaderTest, TersoffZBL) {
|
TEST_F(PotenialFileReaderTest, TersoffZBL) {
|
||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
PotentialFileReader reader(lmp, "SiC.tersoff.zbl", "Tersoff");
|
PotentialFileReader reader(lmp, "SiC.tersoff.zbl", "Tersoff/ZBL");
|
||||||
::testing::internal::GetCapturedStdout();
|
::testing::internal::GetCapturedStdout();
|
||||||
|
|
||||||
auto line = reader.next_line(PairTersoffZBL::NPARAMS_PER_LINE);
|
auto line = reader.next_line(PairTersoffZBL::NPARAMS_PER_LINE);
|
||||||
@ -121,13 +123,22 @@ TEST_F(PotenialFileReaderTest, GW) {
|
|||||||
|
|
||||||
TEST_F(PotenialFileReaderTest, GWZBL) {
|
TEST_F(PotenialFileReaderTest, GWZBL) {
|
||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
PotentialFileReader reader(lmp, "SiC.gw.zbl", "GWZBL");
|
PotentialFileReader reader(lmp, "SiC.gw.zbl", "GW/ZBL");
|
||||||
::testing::internal::GetCapturedStdout();
|
::testing::internal::GetCapturedStdout();
|
||||||
|
|
||||||
auto line = reader.next_line(PairGWZBL::NPARAMS_PER_LINE);
|
auto line = reader.next_line(PairGWZBL::NPARAMS_PER_LINE);
|
||||||
ASSERT_EQ(utils::count_words(line), PairGWZBL::NPARAMS_PER_LINE);
|
ASSERT_EQ(utils::count_words(line), PairGWZBL::NPARAMS_PER_LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(PotenialFileReaderTest, Nb3bHarmonic) {
|
||||||
|
::testing::internal::CaptureStdout();
|
||||||
|
PotentialFileReader reader(lmp, "MOH.nb3b.harmonic", "NB3B Harmonic");
|
||||||
|
::testing::internal::GetCapturedStdout();
|
||||||
|
|
||||||
|
auto line = reader.next_line(PairNb3bHarmonic::NPARAMS_PER_LINE);
|
||||||
|
ASSERT_EQ(utils::count_words(line), PairNb3bHarmonic::NPARAMS_PER_LINE);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
MPI_Init(&argc, &argv);
|
MPI_Init(&argc, &argv);
|
||||||
|
|||||||
Reference in New Issue
Block a user