now also test for global scalars and vectors and t_target for thermostats
This commit is contained in:
@ -36,6 +36,7 @@
|
||||
#include "pair.h"
|
||||
#include "universe.h"
|
||||
#include "utils.h"
|
||||
#include "variable.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
@ -138,9 +139,9 @@ LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool use
|
||||
command("timestep 0.25");
|
||||
command("run 0 post no");
|
||||
command("thermo 2");
|
||||
command("run 4 post no");
|
||||
command("run 4 post no start 0 stop 8");
|
||||
command("write_restart " + cfg.basename + ".restart");
|
||||
command("run 4 post no");
|
||||
command("run 4 post no start 0 stop 8");
|
||||
return lmp;
|
||||
}
|
||||
|
||||
@ -166,7 +167,7 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg, bool use_rmass, bool use
|
||||
command(post_command);
|
||||
|
||||
command("thermo 2");
|
||||
command("run 4 post no");
|
||||
command("run 4 post no start 0 stop 8");
|
||||
}
|
||||
|
||||
// re-generate yaml file with current settings.
|
||||
@ -233,7 +234,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
|
||||
|
||||
int ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
std::cerr << "WARNING: no fix defined with fix ID 'test'\n";
|
||||
std::cerr << "ERROR: no fix defined with fix ID 'test'\n";
|
||||
exit(1);
|
||||
} else {
|
||||
Fix *fix = lmp->modify->fix[ifix];
|
||||
|
||||
@ -318,17 +320,57 @@ TEST(FixTimestep, plain)
|
||||
EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon);
|
||||
}
|
||||
if (print_stats) std::cerr << "run_pos, normal_run, verlet: " << stats << std::endl;
|
||||
if (print_stats) std::cerr << "run_pos, normal run, verlet: " << stats << std::endl;
|
||||
|
||||
auto v = lmp->atom->v;
|
||||
const std::vector<coord_t> &v_ref = test_config.run_vel;
|
||||
stats.reset();
|
||||
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);
|
||||
EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon);
|
||||
}
|
||||
if (print_stats) std::cerr << "run_vel, normal_run, verlet: " << stats << std::endl;
|
||||
if (print_stats) std::cerr << "run_vel, normal run, verlet: " << stats << std::endl;
|
||||
|
||||
int ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
|
||||
} else {
|
||||
Fix *fix = lmp->modify->fix[ifix];
|
||||
stats.reset();
|
||||
|
||||
// global scalar
|
||||
if (fix->scalar_flag) {
|
||||
double value = fix->compute_scalar();
|
||||
EXPECT_FP_LE_WITH_EPS(test_config.global_scalar, value, epsilon);
|
||||
}
|
||||
|
||||
// global vector
|
||||
if (fix->vector_flag) {
|
||||
int num = fix->size_vector;
|
||||
EXPECT_EQ(num, test_config.global_vector.size());
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
EXPECT_FP_LE_WITH_EPS(test_config.global_vector[i], fix->compute_vector(i),
|
||||
epsilon);
|
||||
}
|
||||
|
||||
// check t_target for thermostats
|
||||
|
||||
int dim = -1;
|
||||
double *ptr = (double *)fix->extract("t_target", dim);
|
||||
if ((ptr != nullptr) && (dim == 0)) {
|
||||
int ivar = lmp->input->variable->find("t_target");
|
||||
if (ivar >= 0) {
|
||||
double t_ref = atof(lmp->input->variable->retrieve("t_target"));
|
||||
double t_target = *ptr;
|
||||
EXPECT_FP_LE_WITH_EPS(t_target, t_ref, epsilon);
|
||||
}
|
||||
}
|
||||
if (print_stats && stats.has_data())
|
||||
std::cerr << "global_data, normal run, verlet: " << stats << std::endl;
|
||||
}
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
restart_lammps(lmp, test_config, false, false);
|
||||
@ -346,6 +388,7 @@ TEST(FixTimestep, plain)
|
||||
if (print_stats) std::cerr << "run_pos, restart, verlet: " << stats << std::endl;
|
||||
|
||||
v = lmp->atom->v;
|
||||
stats.reset();
|
||||
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);
|
||||
@ -354,6 +397,32 @@ TEST(FixTimestep, plain)
|
||||
}
|
||||
if (print_stats) std::cerr << "run_vel, restart, verlet: " << stats << std::endl;
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
|
||||
} else {
|
||||
Fix *fix = lmp->modify->fix[ifix];
|
||||
stats.reset();
|
||||
|
||||
// global scalar
|
||||
if (fix->scalar_flag) {
|
||||
double value = fix->compute_scalar();
|
||||
EXPECT_FP_LE_WITH_EPS(test_config.global_scalar, value, epsilon);
|
||||
}
|
||||
|
||||
// global vector
|
||||
if (fix->vector_flag) {
|
||||
int num = fix->size_vector;
|
||||
EXPECT_EQ(num, test_config.global_vector.size());
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
EXPECT_FP_LE_WITH_EPS(test_config.global_vector[i], fix->compute_vector(i),
|
||||
epsilon);
|
||||
}
|
||||
if (print_stats && stats.has_data())
|
||||
std::cerr << "global_data, restart, verlet: " << stats << std::endl;
|
||||
}
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
restart_lammps(lmp, test_config, true, false);
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
@ -370,6 +439,7 @@ TEST(FixTimestep, plain)
|
||||
if (print_stats) std::cerr << "run_pos, rmass, verlet: " << stats << std::endl;
|
||||
|
||||
v = lmp->atom->v;
|
||||
stats.reset();
|
||||
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);
|
||||
@ -378,6 +448,32 @@ TEST(FixTimestep, plain)
|
||||
}
|
||||
if (print_stats) std::cerr << "run_vel, rmass, verlet: " << stats << std::endl;
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
|
||||
} else {
|
||||
Fix *fix = lmp->modify->fix[ifix];
|
||||
stats.reset();
|
||||
|
||||
// global scalar
|
||||
if (fix->scalar_flag) {
|
||||
double value = fix->compute_scalar();
|
||||
EXPECT_FP_LE_WITH_EPS(test_config.global_scalar, value, epsilon);
|
||||
}
|
||||
|
||||
// global vector
|
||||
if (fix->vector_flag) {
|
||||
int num = fix->size_vector;
|
||||
EXPECT_EQ(num, test_config.global_vector.size());
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
EXPECT_FP_LE_WITH_EPS(test_config.global_vector[i], fix->compute_vector(i),
|
||||
epsilon);
|
||||
}
|
||||
if (print_stats && stats.has_data())
|
||||
std::cerr << "global_data, rmass, verlet: " << stats << std::endl;
|
||||
}
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
cleanup_lammps(lmp, test_config);
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
@ -397,7 +493,7 @@ TEST(FixTimestep, plain)
|
||||
EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon);
|
||||
}
|
||||
if (print_stats) std::cerr << "run_pos, normal_run, respa: " << stats << std::endl;
|
||||
if (print_stats) std::cerr << "run_pos, normal run, respa: " << stats << std::endl;
|
||||
|
||||
v = lmp->atom->v;
|
||||
ASSERT_EQ(nlocal + 1, v_ref.size());
|
||||
@ -406,7 +502,33 @@ TEST(FixTimestep, plain)
|
||||
EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon);
|
||||
}
|
||||
if (print_stats) std::cerr << "run_vel, normal_run, respa: " << stats << std::endl;
|
||||
if (print_stats) std::cerr << "run_vel, normal run, respa: " << stats << std::endl;
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
|
||||
} else {
|
||||
Fix *fix = lmp->modify->fix[ifix];
|
||||
stats.reset();
|
||||
|
||||
// global scalar
|
||||
if (fix->scalar_flag) {
|
||||
double value = fix->compute_scalar();
|
||||
EXPECT_FP_LE_WITH_EPS(test_config.global_scalar, value, epsilon);
|
||||
}
|
||||
|
||||
// global vector
|
||||
if (fix->vector_flag) {
|
||||
int num = fix->size_vector;
|
||||
EXPECT_EQ(num, test_config.global_vector.size());
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
EXPECT_FP_LE_WITH_EPS(test_config.global_vector[i], fix->compute_vector(i),
|
||||
epsilon);
|
||||
}
|
||||
if (print_stats && stats.has_data())
|
||||
std::cerr << "global_data, normal run, verlet: " << stats << std::endl;
|
||||
}
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
restart_lammps(lmp, test_config, false, false);
|
||||
@ -432,6 +554,32 @@ TEST(FixTimestep, plain)
|
||||
}
|
||||
if (print_stats) std::cerr << "run_vel, restart, respa: " << stats << std::endl;
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
|
||||
} else {
|
||||
Fix *fix = lmp->modify->fix[ifix];
|
||||
stats.reset();
|
||||
|
||||
// global scalar
|
||||
if (fix->scalar_flag) {
|
||||
double value = fix->compute_scalar();
|
||||
EXPECT_FP_LE_WITH_EPS(test_config.global_scalar, value, epsilon);
|
||||
}
|
||||
|
||||
// global vector
|
||||
if (fix->vector_flag) {
|
||||
int num = fix->size_vector;
|
||||
EXPECT_EQ(num, test_config.global_vector.size());
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
EXPECT_FP_LE_WITH_EPS(test_config.global_vector[i], fix->compute_vector(i),
|
||||
epsilon);
|
||||
}
|
||||
if (print_stats && stats.has_data())
|
||||
std::cerr << "global_data, restart, respa: " << stats << std::endl;
|
||||
}
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
restart_lammps(lmp, test_config, true, false);
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
@ -456,6 +604,32 @@ TEST(FixTimestep, plain)
|
||||
}
|
||||
if (print_stats) std::cerr << "run_vel, rmass, respa: " << stats << std::endl;
|
||||
|
||||
ifix = lmp->modify->find_fix("test");
|
||||
if (ifix < 0) {
|
||||
FAIL() << "ERROR: no fix defined with fix ID 'test'\n";
|
||||
} else {
|
||||
Fix *fix = lmp->modify->fix[ifix];
|
||||
stats.reset();
|
||||
|
||||
// global scalar
|
||||
if (fix->scalar_flag) {
|
||||
double value = fix->compute_scalar();
|
||||
EXPECT_FP_LE_WITH_EPS(test_config.global_scalar, value, epsilon);
|
||||
}
|
||||
|
||||
// global vector
|
||||
if (fix->vector_flag) {
|
||||
int num = fix->size_vector;
|
||||
EXPECT_EQ(num, test_config.global_vector.size());
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
EXPECT_FP_LE_WITH_EPS(test_config.global_vector[i], fix->compute_vector(i),
|
||||
epsilon);
|
||||
}
|
||||
if (print_stats && stats.has_data())
|
||||
std::cerr << "global_data, rmass, respa: " << stats << std::endl;
|
||||
}
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
cleanup_lammps(lmp, test_config);
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
@ -506,7 +680,7 @@ TEST(FixTimestep, omp)
|
||||
EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon);
|
||||
}
|
||||
if (print_stats) std::cerr << "run_pos, normal_run, verlet: " << stats << std::endl;
|
||||
if (print_stats) std::cerr << "run_pos, normal run, verlet: " << stats << std::endl;
|
||||
|
||||
auto v = lmp->atom->v;
|
||||
const std::vector<coord_t> &v_ref = test_config.run_vel;
|
||||
@ -516,7 +690,7 @@ TEST(FixTimestep, omp)
|
||||
EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon);
|
||||
}
|
||||
if (print_stats) std::cerr << "run_vel, normal_run, verlet: " << stats << std::endl;
|
||||
if (print_stats) std::cerr << "run_vel, normal run, verlet: " << stats << std::endl;
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
restart_lammps(lmp, test_config, false, false);
|
||||
@ -585,7 +759,7 @@ TEST(FixTimestep, omp)
|
||||
EXPECT_FP_LE_WITH_EPS(x[i][1], x_ref[tag[i]].y, epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(x[i][2], x_ref[tag[i]].z, epsilon);
|
||||
}
|
||||
if (print_stats) std::cerr << "run_pos, normal_run, respa: " << stats << std::endl;
|
||||
if (print_stats) std::cerr << "run_pos, normal run, respa: " << stats << std::endl;
|
||||
|
||||
v = lmp->atom->v;
|
||||
ASSERT_EQ(nlocal + 1, v_ref.size());
|
||||
@ -594,7 +768,7 @@ TEST(FixTimestep, omp)
|
||||
EXPECT_FP_LE_WITH_EPS(v[i][1], v_ref[tag[i]].y, epsilon);
|
||||
EXPECT_FP_LE_WITH_EPS(v[i][2], v_ref[tag[i]].z, epsilon);
|
||||
}
|
||||
if (print_stats) std::cerr << "run_vel, normal_run, respa: " << stats << std::endl;
|
||||
if (print_stats) std::cerr << "run_vel, normal run, respa: " << stats << std::endl;
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
restart_lammps(lmp, test_config, false, false);
|
||||
|
||||
Reference in New Issue
Block a user