added run_torque and EXPECT_TORQUES
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<coord_t> run_torque;
|
||||
|
||||
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_torque.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_torque"] = &TestConfigReader::run_torque;
|
||||
|
||||
consumers["pair_style"] = &TestConfigReader::pair_style;
|
||||
consumers["pair_coeff"] = &TestConfigReader::pair_coeff;
|
||||
@ -228,6 +229,21 @@ void TestConfigReader::run_vel(const yaml_event_t &event)
|
||||
}
|
||||
}
|
||||
|
||||
void TestConfigReader::run_torque(const yaml_event_t &event)
|
||||
{
|
||||
config.run_torque.clear();
|
||||
config.run_torque.resize(config.natoms + 1);
|
||||
std::stringstream data((char *)event.data.scalar.value);
|
||||
std::string line;
|
||||
|
||||
while (std::getline(data, line, '\n')) {
|
||||
int tag;
|
||||
coord_t xyz;
|
||||
sscanf(line.c_str(), "%d %lg %lg %lg", &tag, &xyz.x, &xyz.y, &xyz.z);
|
||||
config.run_torque[tag] = xyz;
|
||||
}
|
||||
}
|
||||
|
||||
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_torque(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);
|
||||
|
||||
@ -244,6 +244,19 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
||||
block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, v[j][0], v[j][1], v[j][2]);
|
||||
}
|
||||
writer.emit_block("run_vel", block);
|
||||
|
||||
// run_torque
|
||||
|
||||
if(lmp->atom->torque_flag) {
|
||||
block.clear();
|
||||
auto *t = lmp->atom->torque;
|
||||
for (int i = 1; i <= natoms; ++i) {
|
||||
const int j = lmp->atom->map(i);
|
||||
block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, t[j][0], t[j][1], t[j][2]);
|
||||
}
|
||||
writer.emit_block("run_torque", block);
|
||||
}
|
||||
|
||||
cleanup_lammps(lmp, config);
|
||||
}
|
||||
|
||||
|
||||
@ -101,6 +101,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_TORQUES(const std::string &name, Atom *atom, const std::vector<coord_t> &t_ref,
|
||||
double epsilon)
|
||||
{
|
||||
SCOPED_TRACE("EXPECT_TORQUES: " + name);
|
||||
double **t = atom->torque;
|
||||
tagint *tag = atom->tag;
|
||||
const int nlocal = atom->nlocal;
|
||||
ASSERT_EQ(nlocal + 1, t_ref.size());
|
||||
ErrorStats stats;
|
||||
for (int i = 0; i < nlocal; ++i) {
|
||||
EXPECT_FP_LE_WITH_EPS(t[i][0], t_ref[tag[i]].x, epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(t[i][1], t_ref[tag[i]].y, epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(t[i][2], t_ref[tag[i]].z, epsilon);
|
||||
}
|
||||
if (print_stats) std::cerr << name << " stats: " << stats << std::endl;
|
||||
}
|
||||
|
||||
// common read_yaml_file function
|
||||
bool read_yaml_file(const char *infile, TestConfig &config)
|
||||
{
|
||||
|
||||
@ -45,5 +45,7 @@ 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_TORQUES(const std::string &name, LAMMPS_NS::Atom *atom,
|
||||
const std::vector<coord_t> &t_ref, double epsilon);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user