add unit conversion support to pair style tersoff/table

This commit is contained in:
Axel Kohlmeyer
2020-06-24 21:05:00 -04:00
parent 361f636700
commit 00332d299b
4 changed files with 154 additions and 124 deletions

View File

@ -214,6 +214,49 @@ TEST_F(PairUnitConvertTest, tersoff)
EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error));
}
TEST_F(PairUnitConvertTest, tersoff_table)
{
// check if the prerequisite pair style is available
if (!info->has_style("pair", "tersoff/table")) 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 tersoff/table");
lmp->input->one("pair_coeff * * SiC.tersoff Si C");
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 tersoff/table");
lmp->input->one("pair_coeff * * SiC.tersoff Si C");
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, sw)
{
// check if the prerequisite pair style is available

View File

@ -23,6 +23,7 @@
#include "MANYBODY/pair_tersoff_mod_c.h"
#include "MANYBODY/pair_tersoff_zbl.h"
#include "MANYBODY/pair_vashishta.h"
#include "USER-MISC/pair_tersoff_table.h"
#include "input.h"
#include "lammps.h"
#include "potential_file_reader.h"
@ -50,6 +51,7 @@ const int LAMMPS_NS::PairGW::NPARAMS_PER_LINE;
const int LAMMPS_NS::PairGWZBL::NPARAMS_PER_LINE;
const int LAMMPS_NS::PairNb3bHarmonic::NPARAMS_PER_LINE;
const int LAMMPS_NS::PairVashishta::NPARAMS_PER_LINE;
const int LAMMPS_NS::PairTersoffTable::NPARAMS_PER_LINE;
class PotentialFileReaderTest : public ::testing::Test {
protected:
@ -140,6 +142,17 @@ TEST_F(PotentialFileReaderTest, TersoffModC)
ASSERT_EQ(utils::count_words(line), PairTersoffMODC::NPARAMS_PER_LINE);
}
TEST_F(PotentialFileReaderTest, TersoffTable)
{
if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("units metal");
PotentialFileReader reader(lmp, "Si.tersoff", "TersoffTable");
if (!verbose) ::testing::internal::GetCapturedStdout();
auto line = reader.next_line(PairTersoffTable::NPARAMS_PER_LINE);
ASSERT_EQ(utils::count_words(line), PairTersoffTable::NPARAMS_PER_LINE);
}
TEST_F(PotentialFileReaderTest, TersoffZBL)
{
if (!verbose) ::testing::internal::CaptureStdout();