add 'atom type' test option to force style tests
This commit is contained in:
@ -70,6 +70,7 @@ public:
|
||||
std::vector<coord_t> restart_pos;
|
||||
std::vector<coord_t> run_vel;
|
||||
std::vector<coord_t> restart_vel;
|
||||
std::vector<int> run_atom_types;
|
||||
|
||||
TestConfig() :
|
||||
lammps_version(""), date_generated(""), basename(""), epsilon(1.0e-14), input_file(""),
|
||||
@ -94,6 +95,7 @@ public:
|
||||
restart_pos.clear();
|
||||
run_vel.clear();
|
||||
restart_vel.clear();
|
||||
run_atom_types.clear();
|
||||
global_vector.clear();
|
||||
}
|
||||
TestConfig(const TestConfig &) = delete;
|
||||
|
||||
@ -48,6 +48,7 @@ TestConfigReader::TestConfigReader(TestConfig &config) : config(config)
|
||||
consumers["run_forces"] = &TestConfigReader::run_forces;
|
||||
consumers["run_pos"] = &TestConfigReader::run_pos;
|
||||
consumers["run_vel"] = &TestConfigReader::run_vel;
|
||||
consumers["run_atom_types"] = &TestConfigReader::run_atom_types;
|
||||
|
||||
consumers["pair_style"] = &TestConfigReader::pair_style;
|
||||
consumers["pair_coeff"] = &TestConfigReader::pair_coeff;
|
||||
@ -228,6 +229,20 @@ void TestConfigReader::run_vel(const yaml_event_t &event)
|
||||
}
|
||||
}
|
||||
|
||||
void TestConfigReader::run_atom_types(const yaml_event_t &event)
|
||||
{
|
||||
config.run_atom_types.clear();
|
||||
config.run_atom_types.resize(config.natoms + 1);
|
||||
std::stringstream data((char *)event.data.scalar.value);
|
||||
std::string line;
|
||||
|
||||
while (std::getline(data, line, '\n')) {
|
||||
int tag, atom_type;
|
||||
sscanf(line.c_str(), "%d %d", &tag, &atom_type);
|
||||
config.run_atom_types[tag] = atom_type;
|
||||
}
|
||||
}
|
||||
|
||||
void TestConfigReader::pair_style(const yaml_event_t &event)
|
||||
{
|
||||
config.pair_style = (char *)event.data.scalar.value;
|
||||
|
||||
@ -41,6 +41,7 @@ public:
|
||||
void run_forces(const yaml_event_t &event);
|
||||
void run_pos(const yaml_event_t &event);
|
||||
void run_vel(const yaml_event_t &event);
|
||||
void run_atom_types(const yaml_event_t &event);
|
||||
void pair_style(const yaml_event_t &event);
|
||||
void pair_coeff(const yaml_event_t &event);
|
||||
void bond_style(const yaml_event_t &event);
|
||||
|
||||
@ -284,6 +284,7 @@ TEST(FixTimestep, plain)
|
||||
|
||||
EXPECT_POSITIONS("run_pos (normal run, verlet)", lmp->atom, test_config.run_pos, epsilon);
|
||||
EXPECT_VELOCITIES("run_vel (normal run, verlet)", lmp->atom, test_config.run_vel, epsilon);
|
||||
EXPECT_ATOM_TYPES("run_atom_types (normal run, verlet)", lmp->atom, test_config.run_atom_types);
|
||||
|
||||
int ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
@ -334,6 +335,7 @@ TEST(FixTimestep, plain)
|
||||
|
||||
EXPECT_POSITIONS("run_pos (restart, verlet)", lmp->atom, test_config.run_pos, epsilon);
|
||||
EXPECT_VELOCITIES("run_vel (restart, verlet)", lmp->atom, test_config.run_vel, epsilon);
|
||||
EXPECT_ATOM_TYPES("run_atom_types (restart, verlet)", lmp->atom, test_config.run_atom_types);
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
@ -373,6 +375,7 @@ TEST(FixTimestep, plain)
|
||||
|
||||
EXPECT_POSITIONS("run_pos (rmass, verlet)", lmp->atom, test_config.run_pos, epsilon);
|
||||
EXPECT_VELOCITIES("run_vel (rmass, verlet)", lmp->atom, test_config.run_vel, epsilon);
|
||||
EXPECT_ATOM_TYPES("run_atom_types (rmass, verlet)", lmp->atom, test_config.run_atom_types);
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
@ -426,6 +429,7 @@ TEST(FixTimestep, plain)
|
||||
|
||||
EXPECT_POSITIONS("run_pos (normal run, respa)", lmp->atom, test_config.run_pos, epsilon);
|
||||
EXPECT_VELOCITIES("run_vel (normal run, respa)", lmp->atom, test_config.run_vel, epsilon);
|
||||
EXPECT_ATOM_TYPES("run_atom_types (normal run, respa)", lmp->atom, test_config.run_atom_types);
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
@ -464,6 +468,7 @@ TEST(FixTimestep, plain)
|
||||
|
||||
EXPECT_POSITIONS("run_pos (restart, respa)", lmp->atom, test_config.run_pos, epsilon);
|
||||
EXPECT_VELOCITIES("run_vel (restart, respa)", lmp->atom, test_config.run_vel, epsilon);
|
||||
EXPECT_ATOM_TYPES("run_atom_types (restart, respa)", lmp->atom, test_config.run_atom_types);
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
@ -503,6 +508,7 @@ TEST(FixTimestep, plain)
|
||||
|
||||
EXPECT_POSITIONS("run_pos (rmass, respa)", lmp->atom, test_config.run_pos, epsilon);
|
||||
EXPECT_VELOCITIES("run_vel (rmass, respa)", lmp->atom, test_config.run_vel, epsilon);
|
||||
EXPECT_ATOM_TYPES("run_atom_types (rmass, respa)", lmp->atom, test_config.run_atom_types);
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
@ -584,6 +590,7 @@ TEST(FixTimestep, omp)
|
||||
|
||||
EXPECT_POSITIONS("run_pos (normal run, verlet)", lmp->atom, test_config.run_pos, epsilon);
|
||||
EXPECT_VELOCITIES("run_vel (normal run, verlet)", lmp->atom, test_config.run_vel, epsilon);
|
||||
EXPECT_ATOM_TYPES("run_atom_types (normal run, verlet)", lmp->atom, test_config.run_atom_types);
|
||||
|
||||
int ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
@ -634,6 +641,7 @@ TEST(FixTimestep, omp)
|
||||
|
||||
EXPECT_POSITIONS("run_pos (restart, verlet)", lmp->atom, test_config.run_pos, epsilon);
|
||||
EXPECT_VELOCITIES("run_vel (restart, verlet)", lmp->atom, test_config.run_vel, epsilon);
|
||||
EXPECT_ATOM_TYPES("run_atom_types (restart, verlet)", lmp->atom, test_config.run_atom_types);
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
@ -673,6 +681,7 @@ TEST(FixTimestep, omp)
|
||||
|
||||
EXPECT_POSITIONS("run_pos (rmass, verlet)", lmp->atom, test_config.run_pos, epsilon);
|
||||
EXPECT_VELOCITIES("run_vel (rmass, verlet)", lmp->atom, test_config.run_vel, epsilon);
|
||||
EXPECT_ATOM_TYPES("run_atom_types (rmass, verlet)", lmp->atom, test_config.run_atom_types);
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
@ -725,6 +734,7 @@ TEST(FixTimestep, omp)
|
||||
|
||||
EXPECT_POSITIONS("run_pos (normal run, respa)", lmp->atom, test_config.run_pos, epsilon);
|
||||
EXPECT_VELOCITIES("run_vel (normal run, respa)", lmp->atom, test_config.run_vel, epsilon);
|
||||
EXPECT_ATOM_TYPES("run_atom_types (normal run, respa)", lmp->atom, test_config.run_atom_types);
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
@ -763,6 +773,7 @@ TEST(FixTimestep, omp)
|
||||
|
||||
EXPECT_POSITIONS("run_pos (restart, respa)", lmp->atom, test_config.run_pos, epsilon);
|
||||
EXPECT_VELOCITIES("run_vel (restart, respa)", lmp->atom, test_config.run_vel, epsilon);
|
||||
EXPECT_ATOM_TYPES("run_atom_types (restart, respa)", lmp->atom, test_config.run_atom_types);
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
@ -802,6 +813,7 @@ TEST(FixTimestep, omp)
|
||||
|
||||
EXPECT_POSITIONS("run_pos (rmass, respa)", lmp->atom, test_config.run_pos, epsilon);
|
||||
EXPECT_VELOCITIES("run_vel (rmass, respa)", lmp->atom, test_config.run_vel, epsilon);
|
||||
EXPECT_ATOM_TYPES("run_atom_types (rmass, respa)", lmp->atom, test_config.run_atom_types);
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
|
||||
@ -70,6 +70,7 @@ void EXPECT_FORCES(const std::string &name, Atom *atom, const std::vector<coord_
|
||||
void EXPECT_POSITIONS(const std::string &name, Atom *atom, const std::vector<coord_t> &x_ref,
|
||||
double epsilon)
|
||||
{
|
||||
if (x_ref.empty()) return;
|
||||
SCOPED_TRACE("EXPECT_POSITIONS: " + name);
|
||||
double **x = atom->x;
|
||||
tagint *tag = atom->tag;
|
||||
@ -87,6 +88,7 @@ void EXPECT_POSITIONS(const std::string &name, Atom *atom, const std::vector<coo
|
||||
void EXPECT_VELOCITIES(const std::string &name, Atom *atom, const std::vector<coord_t> &v_ref,
|
||||
double epsilon)
|
||||
{
|
||||
if (v_ref.empty()) return;
|
||||
SCOPED_TRACE("EXPECT_VELOCITIES: " + name);
|
||||
double **v = atom->v;
|
||||
tagint *tag = atom->tag;
|
||||
@ -101,6 +103,23 @@ void EXPECT_VELOCITIES(const std::string &name, Atom *atom, const std::vector<co
|
||||
if (print_stats) std::cerr << name << " stats" << stats << std::endl;
|
||||
}
|
||||
|
||||
void EXPECT_ATOM_TYPES(const std::string &name, Atom *atom, const std::vector<int> &at_ref)
|
||||
{
|
||||
if (at_ref.empty()) return;
|
||||
SCOPED_TRACE("EXPECT_ATOM_TYPES: " + name);
|
||||
int *type = atom->type;
|
||||
tagint *tag = atom->tag;
|
||||
const int nlocal = atom->nlocal;
|
||||
ASSERT_EQ(nlocal + 1, at_ref.size());
|
||||
ErrorStats stats;
|
||||
for (int i = 0; i < nlocal; ++i) {
|
||||
EXPECT_EQ(type[i], at_ref[tag[i]]);
|
||||
EXPECT_EQ(type[i], at_ref[tag[i]]);
|
||||
EXPECT_EQ(type[i], at_ref[tag[i]]);
|
||||
}
|
||||
if (print_stats) std::cerr << name << " stats" << stats << std::endl;
|
||||
}
|
||||
|
||||
// common read_yaml_file function
|
||||
bool read_yaml_file(const char *infile, TestConfig &config)
|
||||
{
|
||||
|
||||
@ -41,5 +41,6 @@ void EXPECT_STRESS(const std::string & name, double * stress, const stress_t & e
|
||||
void EXPECT_FORCES(const std::string & name, LAMMPS_NS::Atom * atom, const std::vector<coord_t> & f_ref, double epsilon);
|
||||
void EXPECT_POSITIONS(const std::string & name, LAMMPS_NS::Atom * atom, const std::vector<coord_t> & x_ref, double epsilon);
|
||||
void EXPECT_VELOCITIES(const std::string & name, LAMMPS_NS::Atom * atom, const std::vector<coord_t> & v_ref, double epsilon);
|
||||
void EXPECT_ATOM_TYPES(const std::string & name, LAMMPS_NS::Atom * atom, const std::vector<int> & at_ref);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user