add support for storing a global scalar and global vector

This commit is contained in:
Axel Kohlmeyer 2020-08-09 00:03:43 -04:00
parent 4b5bc8f63b
commit 2edad432ce
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
4 changed files with 53 additions and 4 deletions

View File

@ -58,6 +58,8 @@ public:
double run_coul;
stress_t init_stress;
stress_t run_stress;
double global_scalar;
std::vector<double> global_vector;
std::vector<coord_t> init_forces;
std::vector<coord_t> run_forces;
std::vector<coord_t> run_pos;
@ -70,7 +72,7 @@ public:
pair_style("zero"), bond_style("zero"), angle_style("zero"), dihedral_style("zero"),
improper_style("zero"), kspace_style("none"), natoms(0), init_energy(0), run_energy(0),
init_vdwl(0), run_vdwl(0), init_coul(0), run_coul(0), init_stress({0, 0, 0, 0, 0, 0}),
run_stress({0, 0, 0, 0, 0, 0})
run_stress({0, 0, 0, 0, 0, 0}), global_scalar(0)
{
prerequisites.clear();
pre_commands.clear();
@ -87,6 +89,7 @@ public:
restart_pos.clear();
run_vel.clear();
restart_vel.clear();
global_vector.clear();
}
virtual ~TestConfig(){};

View File

@ -50,6 +50,9 @@ TestConfigReader::TestConfigReader(TestConfig &config) : YamlReader(), config(co
consumers["run_vdwl"] = &TestConfigReader::run_vdwl;
consumers["run_coul"] = &TestConfigReader::run_coul;
consumers["global_scalar"] = &TestConfigReader::global_scalar;
consumers["global_vector"] = &TestConfigReader::global_vector;
consumers["bond_style"] = &TestConfigReader::bond_style;
consumers["bond_coeff"] = &TestConfigReader::bond_coeff;
consumers["angle_style"] = &TestConfigReader::angle_style;
@ -299,3 +302,23 @@ void TestConfigReader::run_energy(const yaml_event_t &event)
{
config.run_energy = atof((char *)event.data.scalar.value);
}
void TestConfigReader::global_scalar(const yaml_event_t &event)
{
config.global_scalar = atof((char *)event.data.scalar.value);
}
void TestConfigReader::global_vector(const yaml_event_t &event)
{
std::stringstream data((char *)event.data.scalar.value);
config.global_vector.clear();
double value;
std::size_t num;
data >> num;
for (std::size_t i = 0; i < num; ++i) {
data >> value;
if (data.eof()) break;
config.global_vector.push_back(value);
}
}

View File

@ -38,7 +38,6 @@ 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 fix_style(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);
@ -52,6 +51,8 @@ public:
void run_coul(const yaml_event_t &event);
void init_energy(const yaml_event_t &event);
void run_energy(const yaml_event_t &event);
void global_scalar(const yaml_event_t &event);
void global_vector(const yaml_event_t &event);
};
#endif

View File

@ -231,6 +231,28 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
// natoms
writer.emit("natoms", natoms);
int ifix = lmp->modify->find_fix("test");
if (ifix < 0) {
std::cerr << "WARNING: no fix defined with fix ID 'test'\n";
} else {
Fix *fix = lmp->modify->fix[ifix];
// global scalar
if (fix->scalar_flag) {
double value = fix->compute_scalar();
writer.emit("global_scalar", value);
}
// global vector
if (fix->vector_flag) {
int num = fix->size_vector;
block = std::to_string(num);
for (int i = 0; i < num; ++i)
block += fmt::format(" {}", fix->compute_vector(i));
writer.emit_block("global_vector", block);
}
}
// run_pos
block.clear();
auto x = lmp->atom->x;
@ -377,7 +399,7 @@ TEST(FixTimestep, plain)
}
if (print_stats) std::cerr << "run_pos, normal_run, respa: " << stats << std::endl;
v = lmp->atom->v;
v = lmp->atom->v;
ASSERT_EQ(nlocal + 1, v_ref.size());
for (int i = 0; i < nlocal; ++i) {
EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon);
@ -565,7 +587,7 @@ TEST(FixTimestep, omp)
}
if (print_stats) std::cerr << "run_pos, normal_run, respa: " << stats << std::endl;
v = lmp->atom->v;
v = lmp->atom->v;
ASSERT_EQ(nlocal + 1, v_ref.size());
for (int i = 0; i < nlocal; ++i) {
EXPECT_FP_LE_WITH_EPS(v[i][0], v_ref[tag[i]].x, epsilon);