forked from lijiext/lammps
add unit conversion to vashishta pair style
This commit is contained in:
parent
b0319c2e70
commit
43276c8387
|
@ -45,6 +45,7 @@ PairVashishta::PairVashishta(LAMMPS *lmp) : Pair(lmp)
|
|||
restartinfo = 0;
|
||||
one_coeff = 1;
|
||||
manybody_flag = 1;
|
||||
unit_convert_flag = utils::get_supported_conversions(utils::ENERGY);
|
||||
|
||||
nelements = 0;
|
||||
elements = NULL;
|
||||
|
@ -361,9 +362,15 @@ void PairVashishta::read_file(char *file)
|
|||
// open file on proc 0
|
||||
|
||||
if (comm->me == 0) {
|
||||
PotentialFileReader reader(lmp, file, "Vashishta");
|
||||
PotentialFileReader reader(lmp, file, "Vashishta", unit_convert_flag);
|
||||
char * line;
|
||||
|
||||
// transparently convert units for supported conversions
|
||||
|
||||
int unit_convert = reader.get_unit_convert();
|
||||
double conversion_factor = utils::get_conversion_factor(utils::ENERGY,
|
||||
unit_convert);
|
||||
|
||||
while((line = reader.next_line(NPARAMS_PER_LINE))) {
|
||||
try {
|
||||
ValueTokenizer values(line);
|
||||
|
@ -412,6 +419,14 @@ void PairVashishta::read_file(char *file)
|
|||
params[nparams].r0 = values.next_double();
|
||||
params[nparams].bigc = values.next_double();
|
||||
params[nparams].costheta = values.next_double();
|
||||
|
||||
if (unit_convert) {
|
||||
params[nparams].bigh *= conversion_factor;
|
||||
params[nparams].bigd *= conversion_factor;
|
||||
params[nparams].bigw *= conversion_factor;
|
||||
params[nparams].bigb *= conversion_factor;
|
||||
}
|
||||
|
||||
} catch (TokenizerException & e) {
|
||||
error->one(FLERR, e.what());
|
||||
}
|
||||
|
|
|
@ -40,7 +40,9 @@ const double ev_convert = utils::get_conversion_factor(utils::ENERGY, utils::MET
|
|||
// 1atm in bar
|
||||
const double p_convert = 1.01325;
|
||||
// relative error for comparing numbers
|
||||
const double rel_error = 1.0e-7;
|
||||
// cannot use smaller value due to lack of consistency
|
||||
// of data in update.cpp. could be 1.0e-12
|
||||
const double rel_error = 5.0e-7;
|
||||
|
||||
class PairUnitConvertTest : public ::testing::Test {
|
||||
protected:
|
||||
|
@ -171,6 +173,49 @@ TEST_F(PairUnitConvertTest, lj_cut)
|
|||
EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error));
|
||||
}
|
||||
|
||||
TEST_F(PairUnitConvertTest, sw)
|
||||
{
|
||||
// check if the prerequisite pair style is available
|
||||
if (!info->has_style("pair", "sw")) GTEST_SKIP();
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
lmp->input->one("units metal");
|
||||
lmp->input->one("read_data test_pair_unit_convert.data");
|
||||
lmp->input->one("pair_style sw");
|
||||
lmp->input->one("pair_coeff * * GaN.sw Ga N");
|
||||
lmp->input->one("run 0 post no");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
||||
// copy pressure, energy, and force from first step
|
||||
double pold;
|
||||
lmp->output->thermo->evaluate_keyword("press", &pold);
|
||||
double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul;
|
||||
double **f = lmp->atom->f;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (int j = 0; j < 3; ++j)
|
||||
fold[i][j] = f[i][j];
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
lmp->input->one("clear");
|
||||
lmp->input->one("units real");
|
||||
lmp->input->one("read_data test_pair_unit_convert.data");
|
||||
lmp->input->one("pair_style sw");
|
||||
lmp->input->one("pair_coeff * * GaN.sw Ga N");
|
||||
lmp->input->one("run 0 post no");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
||||
double pnew;
|
||||
lmp->output->thermo->evaluate_keyword("press", &pnew);
|
||||
EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error));
|
||||
double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul;
|
||||
EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error));
|
||||
|
||||
f = lmp->atom->f;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (int j = 0; j < 3; ++j)
|
||||
EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error));
|
||||
}
|
||||
|
||||
TEST_F(PairUnitConvertTest, tersoff)
|
||||
{
|
||||
// check if the prerequisite pair style is available
|
||||
|
@ -256,6 +301,7 @@ TEST_F(PairUnitConvertTest, tersoff_mod)
|
|||
for (int j = 0; j < 3; ++j)
|
||||
EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error));
|
||||
}
|
||||
|
||||
TEST_F(PairUnitConvertTest, tersoff_mod_c)
|
||||
{
|
||||
// check if the prerequisite pair style is available
|
||||
|
@ -342,16 +388,16 @@ TEST_F(PairUnitConvertTest, tersoff_table)
|
|||
EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error));
|
||||
}
|
||||
|
||||
TEST_F(PairUnitConvertTest, sw)
|
||||
TEST_F(PairUnitConvertTest, vashishta)
|
||||
{
|
||||
// check if the prerequisite pair style is available
|
||||
if (!info->has_style("pair", "sw")) GTEST_SKIP();
|
||||
if (!info->has_style("pair", "vashishta")) GTEST_SKIP();
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
lmp->input->one("units metal");
|
||||
lmp->input->one("read_data test_pair_unit_convert.data");
|
||||
lmp->input->one("pair_style sw");
|
||||
lmp->input->one("pair_coeff * * GaN.sw Ga N");
|
||||
lmp->input->one("pair_style vashishta");
|
||||
lmp->input->one("pair_coeff * * SiC.vashishta Si C");
|
||||
lmp->input->one("run 0 post no");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
||||
|
@ -368,8 +414,8 @@ TEST_F(PairUnitConvertTest, sw)
|
|||
lmp->input->one("clear");
|
||||
lmp->input->one("units real");
|
||||
lmp->input->one("read_data test_pair_unit_convert.data");
|
||||
lmp->input->one("pair_style sw");
|
||||
lmp->input->one("pair_coeff * * GaN.sw Ga N");
|
||||
lmp->input->one("pair_style vashishta");
|
||||
lmp->input->one("pair_coeff * * SiC.vashishta Si C");
|
||||
lmp->input->one("run 0 post no");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
||||
|
|
Loading…
Reference in New Issue