Merge branch 'develop' into dielectric-force-tests
This commit is contained in:
@ -29,6 +29,10 @@ add_executable(test_delete_atoms test_delete_atoms.cpp)
|
||||
target_link_libraries(test_delete_atoms PRIVATE lammps GTest::GMock)
|
||||
add_test(NAME DeleteAtoms COMMAND test_delete_atoms)
|
||||
|
||||
add_executable(test_set_property test_set_property.cpp)
|
||||
target_link_libraries(test_set_property PRIVATE lammps GTest::GMock)
|
||||
add_test(NAME SetProperty COMMAND test_set_property)
|
||||
|
||||
add_executable(test_variables test_variables.cpp)
|
||||
target_link_libraries(test_variables PRIVATE lammps GTest::GMock)
|
||||
add_test(NAME Variables COMMAND test_variables)
|
||||
|
||||
@ -26,8 +26,6 @@
|
||||
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
|
||||
bool verbose = false;
|
||||
|
||||
using LAMMPS_NS::utils::split_words;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
#define STRINGIFY(val) XSTR(val)
|
||||
@ -296,7 +294,6 @@ TEST_F(ComputeGlobalTest, Reduction)
|
||||
EXPECT_DOUBLE_EQ(rep[2], 26);
|
||||
EXPECT_DOUBLE_EQ(rep[3], max[0]);
|
||||
}
|
||||
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -304,12 +301,12 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -31,9 +31,6 @@
|
||||
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
|
||||
bool verbose = false;
|
||||
|
||||
using LAMMPS_NS::MathConst::MY_PI;
|
||||
using LAMMPS_NS::utils::split_words;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
using ::testing::ContainsRegex;
|
||||
using ::testing::ExitedWithCode;
|
||||
@ -164,12 +161,12 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -316,13 +316,12 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. "
|
||||
"Death tests will be skipped\n";
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -683,13 +683,12 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. "
|
||||
"Death tests will be skipped\n";
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -32,8 +32,6 @@
|
||||
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
|
||||
bool verbose = false;
|
||||
|
||||
using LAMMPS_NS::utils::split_words;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
using ::testing::ContainsRegex;
|
||||
using ::testing::ExitedWithCode;
|
||||
@ -45,7 +43,9 @@ protected:
|
||||
{
|
||||
testbinary = "LatticeRegionTest";
|
||||
LAMMPSTest::SetUp();
|
||||
command("units metal");
|
||||
HIDE_OUTPUT([&] {
|
||||
command("units metal");
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -63,7 +63,7 @@ TEST_F(LatticeRegionTest, lattice_none)
|
||||
ASSERT_EQ(lattice->basis, nullptr);
|
||||
|
||||
TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice"););
|
||||
TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice xxx"););
|
||||
TEST_FAILURE(".*ERROR: Unknown lattice keyword: xxx.*", command("lattice xxx"););
|
||||
TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice none 1.0 origin"););
|
||||
TEST_FAILURE(".*ERROR: Expected floating point.*", command("lattice none xxx"););
|
||||
|
||||
@ -114,10 +114,11 @@ TEST_F(LatticeRegionTest, lattice_sc)
|
||||
ASSERT_EQ(lattice->basis[0][1], 0.0);
|
||||
ASSERT_EQ(lattice->basis[0][2], 0.0);
|
||||
|
||||
TEST_FAILURE(".*ERROR: Illegal lattice command.*",
|
||||
TEST_FAILURE(".*ERROR: Invalid lattice origin argument: 1.*",
|
||||
command("lattice sc 1.0 origin 1.0 1.0 1.0"););
|
||||
TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice sc 1.0 origin 1.0"););
|
||||
TEST_FAILURE(".*ERROR: Illegal lattice command.*",
|
||||
TEST_FAILURE(".*ERROR: Illegal lattice origin command: missing argument.*",
|
||||
command("lattice sc 1.0 origin 1.0"););
|
||||
TEST_FAILURE(".*ERROR: Unknown lattice keyword: xxx.*",
|
||||
command("lattice sc 1.0 origin 0.0 0.0 0.0 xxx"););
|
||||
TEST_FAILURE(".*ERROR: Expected floating point.*",
|
||||
command("lattice sc 1.0 origin xxx 1.0 1.0"););
|
||||
@ -195,11 +196,12 @@ TEST_F(LatticeRegionTest, lattice_fcc)
|
||||
ASSERT_EQ(lattice->basis[3][1], 0.5);
|
||||
ASSERT_EQ(lattice->basis[3][2], 0.5);
|
||||
|
||||
TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*",
|
||||
TEST_FAILURE(".*ERROR: Invalid basis option in lattice command for non-custom style.*",
|
||||
command("lattice fcc 1.0 basis 0.0 0.0 0.0"););
|
||||
TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*",
|
||||
TEST_FAILURE(".*ERROR: Invalid a1 option in lattice command for non-custom style.*",
|
||||
command("lattice fcc 1.0 a1 0.0 1.0 0.0"););
|
||||
TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice fcc 1.0 orient w 1 0 0"););
|
||||
TEST_FAILURE(".*ERROR: Unknown lattice orient argument: w.*",
|
||||
command("lattice fcc 1.0 orient w 1 0 0"););
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("dimension 2");
|
||||
@ -241,9 +243,9 @@ TEST_F(LatticeRegionTest, lattice_hcp)
|
||||
ASSERT_EQ(lattice->a3[1], 0.0);
|
||||
ASSERT_DOUBLE_EQ(lattice->a3[2], sqrt(8.0 / 3.0));
|
||||
|
||||
TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*",
|
||||
TEST_FAILURE(".*ERROR: Invalid a2 option in lattice command for non-custom style.*",
|
||||
command("lattice hcp 1.0 a2 0.0 1.0 0.0"););
|
||||
TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*",
|
||||
TEST_FAILURE(".*ERROR: Invalid a3 option in lattice command for non-custom style.*",
|
||||
command("lattice hcp 1.0 a3 0.0 1.0 0.0"););
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("dimension 2");
|
||||
@ -452,9 +454,9 @@ TEST_F(LatticeRegionTest, lattice_custom)
|
||||
ASSERT_DOUBLE_EQ(lattice->a3[1], 0.0);
|
||||
ASSERT_DOUBLE_EQ(lattice->a3[2], 4.34 * sqrt(8.0 / 3.0));
|
||||
|
||||
TEST_FAILURE(".*ERROR: Illegal lattice command.*",
|
||||
TEST_FAILURE(".*ERROR: Invalid lattice basis argument: -0.1.*",
|
||||
command("lattice custom 1.0 basis -0.1 0 0"););
|
||||
TEST_FAILURE(".*ERROR: Illegal lattice command.*",
|
||||
TEST_FAILURE(".*ERROR: Invalid lattice basis argument: 1.*",
|
||||
command("lattice custom 1.0 basis 0.0 1.0 0"););
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
@ -630,13 +632,12 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. "
|
||||
"Death tests will be skipped\n";
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -30,8 +30,6 @@
|
||||
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
|
||||
bool verbose = false;
|
||||
|
||||
using LAMMPS_NS::utils::split_words;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
using ::testing::ExitedWithCode;
|
||||
using ::testing::StrEq;
|
||||
@ -279,12 +277,12 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -29,8 +29,6 @@
|
||||
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
|
||||
bool verbose = false;
|
||||
|
||||
using LAMMPS_NS::utils::split_words;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
#define GETIDX(i) lmp->atom->map(i)
|
||||
@ -677,7 +675,6 @@ TEST_F(ResetMolIDsTest, FailOnlyMolecular)
|
||||
END_HIDE_OUTPUT();
|
||||
TEST_FAILURE(".*ERROR: Can only use reset_mol_ids.*", command("reset_mol_ids all"););
|
||||
}
|
||||
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -685,13 +682,12 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. "
|
||||
"Death tests will be skipped\n";
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
433
unittest/commands/test_set_property.cpp
Normal file
433
unittest/commands/test_set_property.cpp
Normal file
@ -0,0 +1,433 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "lammps.h"
|
||||
|
||||
#include "atom.h"
|
||||
#include "compute.h"
|
||||
#include "domain.h"
|
||||
#include "math_const.h"
|
||||
#include "modify.h"
|
||||
|
||||
#include "../testing/core.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
|
||||
bool verbose = false;
|
||||
|
||||
using ::testing::ContainsRegex;
|
||||
using ::testing::ExitedWithCode;
|
||||
using ::testing::StrEq;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
class SetTest : public LAMMPSTest {
|
||||
protected:
|
||||
Atom *atom;
|
||||
Domain *domain;
|
||||
void SetUp() override
|
||||
{
|
||||
testbinary = "SetTest";
|
||||
args = {"-log", "none", "-echo", "screen", "-nocite", "-v", "num", "1"};
|
||||
LAMMPSTest::SetUp();
|
||||
atom = lmp->atom;
|
||||
domain = lmp->domain;
|
||||
}
|
||||
|
||||
void TearDown() override { LAMMPSTest::TearDown(); }
|
||||
|
||||
void atomic_system(const std::string &atom_style, const std::string units = "real")
|
||||
{
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("atom_style " + atom_style);
|
||||
command("atom_modify map array");
|
||||
command("units " + units);
|
||||
command("lattice sc 1.0 origin 0.125 0.125 0.125");
|
||||
command("region box block 0 2 0 2 0 2");
|
||||
command("create_box 8 box");
|
||||
command("create_atoms 1 box");
|
||||
command("mass * 1.0");
|
||||
command("region left block 0.0 1.0 INF INF INF INF");
|
||||
command("region right block 1.0 2.0 INF INF INF INF");
|
||||
command("region top block INF INF 0.0 1.0 INF INF");
|
||||
command("region bottom block INF INF 1.0 2.0 INF INF");
|
||||
command("region front block INF INF INF INF 0.0 1.0");
|
||||
command("region back block INF INF INF 1.0 2.0 INF");
|
||||
command("group top region top");
|
||||
command("group bottom region bottom");
|
||||
END_HIDE_OUTPUT();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(SetTest, NoBoxNoAtoms)
|
||||
{
|
||||
ASSERT_EQ(atom->natoms, 0);
|
||||
ASSERT_EQ(domain->box_exist, 0);
|
||||
TEST_FAILURE(".*ERROR: Set command before simulation box is.*", command("set type 1 x 0.0"););
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("region box block 0 2 0 2 0 2");
|
||||
command("create_box 1 box");
|
||||
END_HIDE_OUTPUT();
|
||||
TEST_FAILURE(".*ERROR: Set command on system without atoms.*", command("set type 1 x 0.0"););
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("create_atoms 1 single 0.5 0.5 0.5");
|
||||
command("compute 0 all property/atom proc");
|
||||
END_HIDE_OUTPUT();
|
||||
auto compute = lmp->modify->get_compute_by_id("0");
|
||||
compute->compute_peratom();
|
||||
ASSERT_EQ(compute->vector_atom[0], 0);
|
||||
|
||||
TEST_FAILURE(".*ERROR: Illegal set command: need at least four.*", command("set type 1 x"););
|
||||
TEST_FAILURE(".*ERROR: Unknown set command style: xxx.*", command("set xxx 1 x 0.0"););
|
||||
TEST_FAILURE(".*ERROR: Set keyword or custom property yyy does not exist.*",
|
||||
command("set type 1 yyy 0.0"););
|
||||
|
||||
TEST_FAILURE(".*ERROR: Cannot set attribute spin/atom for atom style atomic.*",
|
||||
command("set atom * spin/atom 1.0 1.0 0.0 0.0"););
|
||||
TEST_FAILURE(".*ERROR: Cannot set attribute spin/atom/random for atom style atomic.*",
|
||||
command("set atom * spin/atom/random 436273456 1.0"););
|
||||
|
||||
TEST_FAILURE(".*ERROR: Illegal compute property/atom command: missing argument.*",
|
||||
command("compute 1 all property/atom"););
|
||||
TEST_FAILURE(".*ERROR: Compute property/atom mol is not available.*",
|
||||
command("compute 1 all property/atom mol"););
|
||||
}
|
||||
|
||||
TEST_F(SetTest, StylesTypes)
|
||||
{
|
||||
atomic_system("molecular");
|
||||
ASSERT_EQ(atom->natoms, 8);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("set group all mol 1");
|
||||
command("set group top type 2");
|
||||
command("set region back type 3");
|
||||
command("set region left mol 2");
|
||||
command("compute 1 all property/atom id type mol");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
auto compute = lmp->modify->get_compute_by_id("1");
|
||||
ASSERT_NE(compute, nullptr);
|
||||
compute->compute_peratom();
|
||||
|
||||
ASSERT_EQ(atom->type[0], 2);
|
||||
ASSERT_EQ(atom->type[1], 2);
|
||||
ASSERT_EQ(atom->type[2], 1);
|
||||
ASSERT_EQ(atom->type[3], 1);
|
||||
ASSERT_EQ(atom->type[4], 2);
|
||||
ASSERT_EQ(atom->type[5], 2);
|
||||
ASSERT_EQ(atom->type[6], 1);
|
||||
ASSERT_EQ(atom->type[7], 1);
|
||||
|
||||
ASSERT_EQ(atom->molecule[0], 2);
|
||||
ASSERT_EQ(atom->molecule[1], 1);
|
||||
ASSERT_EQ(atom->molecule[2], 2);
|
||||
ASSERT_EQ(atom->molecule[3], 1);
|
||||
ASSERT_EQ(atom->molecule[4], 2);
|
||||
ASSERT_EQ(atom->molecule[5], 1);
|
||||
ASSERT_EQ(atom->molecule[6], 2);
|
||||
ASSERT_EQ(atom->molecule[7], 1);
|
||||
|
||||
// atom ID
|
||||
ASSERT_EQ(compute->array_atom[0][0], 1);
|
||||
ASSERT_EQ(compute->array_atom[1][0], 2);
|
||||
ASSERT_EQ(compute->array_atom[2][0], 3);
|
||||
ASSERT_EQ(compute->array_atom[3][0], 4);
|
||||
ASSERT_EQ(compute->array_atom[4][0], 5);
|
||||
ASSERT_EQ(compute->array_atom[5][0], 6);
|
||||
ASSERT_EQ(compute->array_atom[6][0], 7);
|
||||
ASSERT_EQ(compute->array_atom[7][0], 8);
|
||||
|
||||
// atom type
|
||||
ASSERT_EQ(compute->array_atom[0][1], 2);
|
||||
ASSERT_EQ(compute->array_atom[1][1], 2);
|
||||
ASSERT_EQ(compute->array_atom[2][1], 1);
|
||||
ASSERT_EQ(compute->array_atom[3][1], 1);
|
||||
ASSERT_EQ(compute->array_atom[4][1], 2);
|
||||
ASSERT_EQ(compute->array_atom[5][1], 2);
|
||||
ASSERT_EQ(compute->array_atom[6][1], 1);
|
||||
ASSERT_EQ(compute->array_atom[7][1], 1);
|
||||
|
||||
// mol ID
|
||||
ASSERT_EQ(compute->array_atom[0][2], 2);
|
||||
ASSERT_EQ(compute->array_atom[1][2], 1);
|
||||
ASSERT_EQ(compute->array_atom[2][2], 2);
|
||||
ASSERT_EQ(compute->array_atom[3][2], 1);
|
||||
ASSERT_EQ(compute->array_atom[4][2], 2);
|
||||
ASSERT_EQ(compute->array_atom[5][2], 1);
|
||||
ASSERT_EQ(compute->array_atom[6][2], 2);
|
||||
ASSERT_EQ(compute->array_atom[7][2], 1);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("set mol 1 type 4");
|
||||
command("set atom 4*7 type 5");
|
||||
END_HIDE_OUTPUT();
|
||||
ASSERT_EQ(atom->type[0], 2);
|
||||
ASSERT_EQ(atom->type[1], 4);
|
||||
ASSERT_EQ(atom->type[2], 1);
|
||||
ASSERT_EQ(atom->type[3], 5);
|
||||
ASSERT_EQ(atom->type[4], 5);
|
||||
ASSERT_EQ(atom->type[5], 5);
|
||||
ASSERT_EQ(atom->type[6], 5);
|
||||
ASSERT_EQ(atom->type[7], 4);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("variable rev atom 9-id");
|
||||
command("set group all type v_rev");
|
||||
END_HIDE_OUTPUT();
|
||||
ASSERT_EQ(atom->type[0], 8);
|
||||
ASSERT_EQ(atom->type[1], 7);
|
||||
ASSERT_EQ(atom->type[2], 6);
|
||||
ASSERT_EQ(atom->type[3], 5);
|
||||
ASSERT_EQ(atom->type[4], 4);
|
||||
ASSERT_EQ(atom->type[5], 3);
|
||||
ASSERT_EQ(atom->type[6], 2);
|
||||
ASSERT_EQ(atom->type[7], 1);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("set group all type 1");
|
||||
command("set group all type/fraction 2 0.5 453246");
|
||||
END_HIDE_OUTPUT();
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 8; ++i)
|
||||
sum += (atom->type[i] == 2) ? 1 : 0;
|
||||
ASSERT_EQ(sum, 4);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("set group all type 1");
|
||||
command("set group all type/ratio 2 0.5 5784536");
|
||||
END_HIDE_OUTPUT();
|
||||
sum = 0;
|
||||
for (int i = 0; i < 8; ++i)
|
||||
sum += (atom->type[i] == 2) ? 1 : 0;
|
||||
ASSERT_EQ(sum, 4);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("set group all type 1");
|
||||
command("set group all type/subset 2 4 784536");
|
||||
END_HIDE_OUTPUT();
|
||||
sum = 0;
|
||||
for (int i = 0; i < 8; ++i)
|
||||
sum += (atom->type[i] == 2) ? 1 : 0;
|
||||
ASSERT_EQ(sum, 4);
|
||||
|
||||
TEST_FAILURE(".*ERROR: Numeric index 9 is out of bounds .1-8.*", command("set type 9 x 0.0"););
|
||||
TEST_FAILURE(".*ERROR: Invalid range string: 3:10.*", command("set type 3:10 x 0.0"););
|
||||
TEST_FAILURE(".*ERROR: Could not find set group ID nope.*", command("set group nope x 0.0"););
|
||||
}
|
||||
|
||||
TEST_F(SetTest, PosVelCharge)
|
||||
{
|
||||
atomic_system("charge");
|
||||
ASSERT_EQ(atom->natoms, 8);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("set group top charge 1.0");
|
||||
command("set atom 5*8 charge -1.0");
|
||||
END_HIDE_OUTPUT();
|
||||
ASSERT_EQ(atom->q[0], 1);
|
||||
ASSERT_EQ(atom->q[1], 1);
|
||||
ASSERT_EQ(atom->q[2], 0);
|
||||
ASSERT_EQ(atom->q[3], 0);
|
||||
ASSERT_EQ(atom->q[4], -1);
|
||||
ASSERT_EQ(atom->q[5], -1);
|
||||
ASSERT_EQ(atom->q[6], -1);
|
||||
ASSERT_EQ(atom->q[7], -1);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("variable xpos atom 0.5-x");
|
||||
command("variable ypos atom y*0.5");
|
||||
command("set atom * x v_xpos y v_ypos z 0.5");
|
||||
command("set group all vx v_xpos vy v_ypos vz 0.5");
|
||||
END_HIDE_OUTPUT();
|
||||
ASSERT_EQ(atom->x[0][0], 0.375);
|
||||
ASSERT_EQ(atom->x[0][1], 0.0625);
|
||||
ASSERT_EQ(atom->x[0][2], 0.5);
|
||||
ASSERT_EQ(atom->x[1][0], -0.625);
|
||||
ASSERT_EQ(atom->x[1][1], 0.0625);
|
||||
ASSERT_EQ(atom->x[1][2], 0.5);
|
||||
ASSERT_EQ(atom->x[2][0], 0.375);
|
||||
ASSERT_EQ(atom->x[2][1], 0.5625);
|
||||
ASSERT_EQ(atom->x[2][2], 0.5);
|
||||
ASSERT_EQ(atom->x[3][0], -0.625);
|
||||
ASSERT_EQ(atom->x[3][1], 0.5625);
|
||||
ASSERT_EQ(atom->x[3][2], 0.5);
|
||||
ASSERT_EQ(atom->x[4][0], 0.375);
|
||||
ASSERT_EQ(atom->x[4][1], 0.0625);
|
||||
ASSERT_EQ(atom->x[4][2], 0.5);
|
||||
ASSERT_EQ(atom->x[5][0], -0.625);
|
||||
ASSERT_EQ(atom->x[5][1], 0.0625);
|
||||
ASSERT_EQ(atom->x[5][2], 0.5);
|
||||
ASSERT_EQ(atom->x[6][0], 0.375);
|
||||
ASSERT_EQ(atom->x[6][1], 0.5625);
|
||||
ASSERT_EQ(atom->x[6][2], 0.5);
|
||||
ASSERT_EQ(atom->x[7][0], -0.625);
|
||||
ASSERT_EQ(atom->x[7][1], 0.5625);
|
||||
ASSERT_EQ(atom->x[7][2], 0.5);
|
||||
|
||||
ASSERT_EQ(atom->v[0][0], 0.125);
|
||||
ASSERT_EQ(atom->v[0][1], 0.03125);
|
||||
ASSERT_EQ(atom->v[0][2], 0.5);
|
||||
ASSERT_EQ(atom->v[1][0], 1.125);
|
||||
ASSERT_EQ(atom->v[1][1], 0.03125);
|
||||
ASSERT_EQ(atom->v[1][2], 0.5);
|
||||
ASSERT_EQ(atom->v[2][0], 0.125);
|
||||
ASSERT_EQ(atom->v[2][1], 0.28125);
|
||||
ASSERT_EQ(atom->v[2][2], 0.5);
|
||||
ASSERT_EQ(atom->v[3][0], 1.125);
|
||||
ASSERT_EQ(atom->v[3][1], 0.28125);
|
||||
ASSERT_EQ(atom->v[3][2], 0.5);
|
||||
ASSERT_EQ(atom->v[4][0], 0.125);
|
||||
ASSERT_EQ(atom->v[4][1], 0.03125);
|
||||
ASSERT_EQ(atom->v[4][2], 0.5);
|
||||
ASSERT_EQ(atom->v[5][0], 1.125);
|
||||
ASSERT_EQ(atom->v[5][1], 0.03125);
|
||||
ASSERT_EQ(atom->v[5][2], 0.5);
|
||||
ASSERT_EQ(atom->v[6][0], 0.125);
|
||||
ASSERT_EQ(atom->v[6][1], 0.28125);
|
||||
ASSERT_EQ(atom->v[6][2], 0.5);
|
||||
ASSERT_EQ(atom->v[7][0], 1.125);
|
||||
ASSERT_EQ(atom->v[7][1], 0.28125);
|
||||
ASSERT_EQ(atom->v[7][2], 0.5);
|
||||
}
|
||||
|
||||
TEST_F(SetTest, SpinPackage)
|
||||
{
|
||||
if (!Info::has_package("SPIN")) GTEST_SKIP();
|
||||
atomic_system("spin");
|
||||
ASSERT_EQ(atom->natoms, 8);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("set atom 1*2 spin/atom 0.5 0.1 0.5 -0.1");
|
||||
command("set atom 8 spin/atom/random 23974 0.25");
|
||||
END_HIDE_OUTPUT();
|
||||
constexpr double vx = 0.1;
|
||||
constexpr double vy = 0.5;
|
||||
constexpr double vz = -0.1;
|
||||
const double norm = 1.0 / sqrt(vx * vx + vy * vy + vz * vz);
|
||||
ASSERT_EQ(atom->sp[0][0], vx * norm);
|
||||
ASSERT_EQ(atom->sp[0][1], vy * norm);
|
||||
ASSERT_EQ(atom->sp[0][2], vz * norm);
|
||||
ASSERT_EQ(atom->sp[0][3], 0.5);
|
||||
ASSERT_EQ(atom->sp[1][0], vx * norm);
|
||||
ASSERT_EQ(atom->sp[1][1], vy * norm);
|
||||
ASSERT_EQ(atom->sp[1][2], vz * norm);
|
||||
ASSERT_EQ(atom->sp[1][3], 0.5);
|
||||
ASSERT_NE(atom->sp[7][0], 0.0);
|
||||
ASSERT_NE(atom->sp[7][1], 0.0);
|
||||
ASSERT_NE(atom->sp[7][2], 0.0);
|
||||
ASSERT_EQ(atom->sp[7][3], 0.25);
|
||||
|
||||
for (int i = 2; i < 7; ++i)
|
||||
for (int j = 0; j < 4; ++j)
|
||||
ASSERT_EQ(atom->sp[i][j], 0);
|
||||
|
||||
TEST_FAILURE(".*ERROR: Invalid spin magnitude -0.1 in set spin/atom command.*",
|
||||
command("set atom * spin/atom -0.1 1.0 0.0 0.0"););
|
||||
TEST_FAILURE(".*ERROR: At least one spin vector component must be non-zero.*",
|
||||
command("set atom * spin/atom 1.0 0.0 0.0 0.0"););
|
||||
TEST_FAILURE(".*ERROR: Invalid spin magnitude -0.2 in set spin/atom/random command.*",
|
||||
command("set atom * spin/atom/random 436273456 -0.2"););
|
||||
TEST_FAILURE(".*ERROR: Invalid random number seed 0 in set spin/atom/random command.*",
|
||||
command("set atom * spin/atom/random 0 1.0"););
|
||||
}
|
||||
|
||||
TEST_F(SetTest, EffPackage)
|
||||
{
|
||||
if (!Info::has_package("EFF")) GTEST_SKIP();
|
||||
atomic_system("electron");
|
||||
ASSERT_EQ(atom->natoms, 8);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("set atom 1*2 spin/electron -1");
|
||||
command("set atom 3*4 spin/electron 1");
|
||||
command("set atom 5 spin/electron 0");
|
||||
command("set atom 6 spin/electron 2");
|
||||
command("set atom 7* spin/electron 3");
|
||||
command("set region left radius/electron 0.5");
|
||||
command("set region right radius/electron 1.0");
|
||||
command("compute 2 all property/atom espin eradius");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
auto compute = lmp->modify->get_compute_by_id("2");
|
||||
ASSERT_NE(compute, nullptr);
|
||||
compute->compute_peratom();
|
||||
|
||||
EXPECT_EQ(atom->spin[0],-1);
|
||||
EXPECT_EQ(atom->spin[1],-1);
|
||||
EXPECT_EQ(atom->spin[2],1);
|
||||
EXPECT_EQ(atom->spin[3],1);
|
||||
EXPECT_EQ(atom->spin[4],0);
|
||||
EXPECT_EQ(atom->spin[5],2);
|
||||
EXPECT_EQ(atom->spin[6],3);
|
||||
EXPECT_EQ(atom->spin[7],3);
|
||||
EXPECT_EQ(atom->eradius[0],0.5);
|
||||
EXPECT_EQ(atom->eradius[1],1.0);
|
||||
EXPECT_EQ(atom->eradius[2],0.5);
|
||||
EXPECT_EQ(atom->eradius[3],1.0);
|
||||
EXPECT_EQ(atom->eradius[4],0.5);
|
||||
EXPECT_EQ(atom->eradius[5],1.0);
|
||||
EXPECT_EQ(atom->eradius[6],0.5);
|
||||
EXPECT_EQ(atom->eradius[7],1.0);
|
||||
|
||||
EXPECT_EQ(compute->array_atom[0][0],-1);
|
||||
EXPECT_EQ(compute->array_atom[1][0],-1);
|
||||
EXPECT_EQ(compute->array_atom[2][0],1);
|
||||
EXPECT_EQ(compute->array_atom[3][0],1);
|
||||
EXPECT_EQ(compute->array_atom[4][0],0);
|
||||
EXPECT_EQ(compute->array_atom[5][0],2);
|
||||
EXPECT_EQ(compute->array_atom[6][0],3);
|
||||
EXPECT_EQ(compute->array_atom[7][0],3);
|
||||
EXPECT_EQ(compute->array_atom[0][1],0.5);
|
||||
EXPECT_EQ(compute->array_atom[1][1],1.0);
|
||||
EXPECT_EQ(compute->array_atom[2][1],0.5);
|
||||
EXPECT_EQ(compute->array_atom[3][1],1.0);
|
||||
EXPECT_EQ(compute->array_atom[4][1],0.5);
|
||||
EXPECT_EQ(compute->array_atom[5][1],1.0);
|
||||
EXPECT_EQ(compute->array_atom[6][1],0.5);
|
||||
EXPECT_EQ(compute->array_atom[7][1],1.0);
|
||||
|
||||
TEST_FAILURE(".*ERROR on proc 0: Incorrect value for electron spin: 0.5.*",
|
||||
command("set atom * spin/electron 0.5"););
|
||||
TEST_FAILURE(".*ERROR on proc 0: Incorrect value for electron radius: -0.5.*",
|
||||
command("set atom * radius/electron -0.5"););
|
||||
}
|
||||
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
@ -36,8 +36,6 @@
|
||||
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
|
||||
bool verbose = false;
|
||||
|
||||
using LAMMPS_NS::utils::split_words;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
using ::testing::ContainsRegex;
|
||||
using ::testing::ExitedWithCode;
|
||||
@ -81,7 +79,7 @@ TEST_F(SimpleCommandsTest, Echo)
|
||||
ASSERT_EQ(lmp->input->echo_log, 1);
|
||||
|
||||
TEST_FAILURE(".*ERROR: Illegal echo command.*", command("echo"););
|
||||
TEST_FAILURE(".*ERROR: Illegal echo command.*", command("echo xxx"););
|
||||
TEST_FAILURE(".*ERROR: Unknown echo keyword: xxx.*", command("echo xxx"););
|
||||
}
|
||||
|
||||
TEST_F(SimpleCommandsTest, Log)
|
||||
@ -552,13 +550,12 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. "
|
||||
"Death tests will be skipped\n";
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -32,13 +32,11 @@
|
||||
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
|
||||
bool verbose = false;
|
||||
|
||||
using LAMMPS_NS::MathConst::MY_PI;
|
||||
using LAMMPS_NS::utils::split_words;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
using ::testing::ContainsRegex;
|
||||
using ::testing::ExitedWithCode;
|
||||
using ::testing::StrEq;
|
||||
using MathConst::MY_PI;
|
||||
|
||||
class VariableTest : public LAMMPSTest {
|
||||
protected:
|
||||
@ -197,11 +195,11 @@ TEST_F(VariableTest, CreateDelete)
|
||||
ASSERT_EQ(variable->internalstyle(variable->find("ten")), 1);
|
||||
|
||||
TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable"););
|
||||
TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy index"););
|
||||
TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy delete xxx"););
|
||||
TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy loop -1"););
|
||||
TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy loop 10 1"););
|
||||
TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy xxxx"););
|
||||
TEST_FAILURE(".*ERROR: Illegal variable index command.*", command("variable dummy index"););
|
||||
TEST_FAILURE(".*ERROR: Illegal variable delete command: expected 2 arguments but found 3.*", command("variable dummy delete xxx"););
|
||||
TEST_FAILURE(".*ERROR: Invalid variable loop argument: -1.*", command("variable dummy loop -1"););
|
||||
TEST_FAILURE(".*ERROR: Illegal variable loop command.*", command("variable dummy loop 10 1"););
|
||||
TEST_FAILURE(".*ERROR: Unknown variable keyword: xxx.*", command("variable dummy xxxx"););
|
||||
TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*",
|
||||
command("variable two string xxx"););
|
||||
TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*",
|
||||
@ -380,6 +378,7 @@ TEST_F(VariableTest, Functions)
|
||||
command("variable ten1 equal tan(v_eight/2.0)");
|
||||
command("variable ten2 equal asin(-1.0)+acos(0.0)");
|
||||
command("variable ten3 equal floor(100*random(0.2,0.8,v_seed)+1)");
|
||||
command("variable ten4 equal extract_setting(world_size)");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
ASSERT_GT(variable->compute_equal(variable->find("two")), 0.99);
|
||||
@ -393,9 +392,18 @@ TEST_F(VariableTest, Functions)
|
||||
ASSERT_FLOAT_EQ(variable->compute_equal(variable->find("ten1")), 1);
|
||||
ASSERT_GT(variable->compute_equal(variable->find("ten3")), 19);
|
||||
ASSERT_LT(variable->compute_equal(variable->find("ten3")), 81);
|
||||
ASSERT_DOUBLE_EQ(variable->compute_equal(variable->find("ten4")), 1);
|
||||
|
||||
TEST_FAILURE(".*ERROR: Variable four: Invalid syntax in variable formula.*",
|
||||
command("print \"${four}\""););
|
||||
TEST_FAILURE(".*ERROR on proc 0: Invalid immediate variable.*",
|
||||
command("print \"$(extract_setting()\""););
|
||||
TEST_FAILURE(".*ERROR on proc 0: Invalid immediate variable.*",
|
||||
command("print \"$(extract_setting()\""););
|
||||
TEST_FAILURE(".*ERROR: Invalid extract_setting.. function syntax in variable formula.*",
|
||||
command("print \"$(extract_setting(one,two))\""););
|
||||
TEST_FAILURE(".*ERROR: Unknown setting nprocs for extract_setting.. function in variable formula.*",
|
||||
command("print \"$(extract_setting(nprocs))\""););
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, IfCommand)
|
||||
@ -575,13 +583,12 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. "
|
||||
"Death tests will be skipped\n";
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
bool verbose = false;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class Advanced_utils : public LAMMPSTest {
|
||||
protected:
|
||||
Error *error;
|
||||
@ -218,7 +217,6 @@ TEST_F(Advanced_utils, expand_args)
|
||||
delete[] args[i];
|
||||
delete[] args;
|
||||
}
|
||||
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -226,12 +224,12 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -16,9 +16,7 @@
|
||||
bool verbose = false;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
using ::testing::ContainsRegex;
|
||||
using utils::split_words;
|
||||
|
||||
class Error_class : public LAMMPSTest {
|
||||
protected:
|
||||
@ -120,7 +118,6 @@ TEST_F(Error_class, all)
|
||||
{
|
||||
TEST_FAILURE("ERROR: one error.*test_error_class.cpp:.*", error->all(FLERR, "one error"););
|
||||
};
|
||||
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -128,12 +125,12 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -50,7 +50,7 @@ int main(int argc, char **argv)
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -21,13 +21,17 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using ::testing::Eq;
|
||||
|
||||
char *BINARY2TXT_EXECUTABLE = nullptr;
|
||||
bool verbose = false;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class DumpAtomTest : public MeltTest {
|
||||
std::string dump_style = "atom";
|
||||
|
||||
@ -106,6 +110,22 @@ public:
|
||||
END_HIDE_OUTPUT();
|
||||
return fmt::format("{}.txt", binary_file);
|
||||
}
|
||||
|
||||
std::vector<std::string> extract_items(const std::string &file, const std::string &item)
|
||||
{
|
||||
std::string match = fmt::format("^ITEM: {}$", item);
|
||||
std::vector<std::string> values;
|
||||
|
||||
std::ifstream dump(file);
|
||||
for (std::string buffer; std::getline(dump, buffer); /* */) {
|
||||
buffer = utils::trim(buffer);
|
||||
if (utils::strmatch(buffer, match)) {
|
||||
std::getline(dump, buffer);
|
||||
values.push_back(buffer);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DumpAtomTest, run0)
|
||||
@ -679,6 +699,184 @@ TEST_F(DumpAtomTest, binary_write_dump)
|
||||
delete_file(dump_file);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// dump_modify
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
TEST_F(DumpAtomTest, delay)
|
||||
{
|
||||
auto dump_file = dump_filename("delay");
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("dump id all atom 10 " + dump_file);
|
||||
command("dump_modify id delay 20");
|
||||
command("run 50 post no");
|
||||
command("undump id");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
std::vector<std::string> expected, values;
|
||||
values = extract_items(dump_file, "TIMESTEP");
|
||||
expected = {"20", "30", "40", "50"};
|
||||
ASSERT_EQ(values.size(), expected.size());
|
||||
for (int i = 0; i < expected.size(); ++i)
|
||||
ASSERT_THAT(values[i], Eq(expected[i]));
|
||||
|
||||
delete_file(dump_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomTest, colname)
|
||||
{
|
||||
auto dump_file = dump_filename("colname");
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("group one id 1");
|
||||
command("dump id one atom 10 " + dump_file);
|
||||
command("run 5 post no");
|
||||
command("dump_modify id colname id AtomID colname 3 x-scaled colname -1 z-scaled");
|
||||
command("run 10 post no");
|
||||
command("dump_modify id colname default");
|
||||
command("run 10 post no");
|
||||
command("undump id");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
std::vector<std::string> expected, values;
|
||||
values = extract_items(dump_file, "ATOMS id type xs ys zs");
|
||||
expected = {"1 1 0 0 0", "1 1 0 0 0"};
|
||||
ASSERT_EQ(values.size(), expected.size());
|
||||
for (int i = 0; i < expected.size(); ++i)
|
||||
ASSERT_THAT(values[i], Eq(expected[i]));
|
||||
|
||||
values = extract_items(dump_file, "ATOMS AtomID type x-scaled ys z-scaled");
|
||||
expected = {"1 1 0 0 0"};
|
||||
ASSERT_EQ(values.size(), expected.size());
|
||||
for (int i = 0; i < expected.size(); ++i)
|
||||
ASSERT_THAT(values[i], Eq(expected[i]));
|
||||
|
||||
delete_file(dump_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomTest, units_time)
|
||||
{
|
||||
auto dump_file = dump_filename("units_time");
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("dump id all atom 10 " + dump_file);
|
||||
command("dump_modify id units yes time yes");
|
||||
command("run 30 post no");
|
||||
command("timestep 0.01");
|
||||
command("run 30 post no");
|
||||
command("undump id");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
std::vector<std::string> expected, values;
|
||||
values = extract_items(dump_file, "TIME");
|
||||
expected = {"0", "0.05", "0.1", "0.15", "0.25", "0.35", "0.45"};
|
||||
ASSERT_EQ(values.size(), expected.size());
|
||||
for (int i = 0; i < expected.size(); ++i)
|
||||
ASSERT_THAT(values[i], Eq(expected[i]));
|
||||
|
||||
values = extract_items(dump_file, "UNITS");
|
||||
expected = {"lj"};
|
||||
ASSERT_EQ(values.size(), expected.size());
|
||||
for (int i = 0; i < expected.size(); ++i)
|
||||
ASSERT_THAT(values[i], Eq(expected[i]));
|
||||
|
||||
delete_file(dump_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomTest, every)
|
||||
{
|
||||
auto dump_file = dump_filename("every");
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("dump id all atom 10 " + dump_file);
|
||||
command("run 20 post no");
|
||||
command("dump_modify id every 5");
|
||||
command("run 15 post no");
|
||||
command("dump_modify id every 10");
|
||||
command("run 25 post no");
|
||||
command("undump id");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
std::vector<std::string> expected, values;
|
||||
values = extract_items(dump_file, "TIMESTEP");
|
||||
expected = {"0", "10", "20", "25", "30", "35", "40", "50", "60"};
|
||||
ASSERT_EQ(values.size(), expected.size());
|
||||
for (int i = 0; i < expected.size(); ++i)
|
||||
ASSERT_THAT(values[i], Eq(expected[i]));
|
||||
|
||||
delete_file(dump_file);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("reset_timestep 0");
|
||||
command("dump id all atom 1 " + dump_file);
|
||||
command("variable next equal (step+1)*(step+1)");
|
||||
command("dump_modify id every v_next");
|
||||
command("run 50 post no");
|
||||
command("variable next equal logfreq(10,7,10)");
|
||||
command("dump_modify id every v_next");
|
||||
command("run 100 post no");
|
||||
command("undump id");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
values = extract_items(dump_file, "TIMESTEP");
|
||||
expected = {"1", "4", "25", "60", "70", "100"};
|
||||
ASSERT_EQ(values.size(), expected.size());
|
||||
for (int i = 0; i < expected.size(); ++i)
|
||||
ASSERT_THAT(values[i], Eq(expected[i]));
|
||||
|
||||
delete_file(dump_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomTest, every_time)
|
||||
{
|
||||
auto dump_file = dump_filename("every_time");
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("dump id all atom 10 " + dump_file);
|
||||
command("dump_modify id every/time 0.1");
|
||||
command("run 40 post no");
|
||||
command("timestep 0.01");
|
||||
command("run 20 post no");
|
||||
command("undump id");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
std::vector<std::string> expected, values;
|
||||
values = extract_items(dump_file, "TIMESTEP");
|
||||
expected = {"0", "20", "40", "50", "60"};
|
||||
ASSERT_EQ(values.size(), expected.size());
|
||||
for (int i = 0; i < expected.size(); ++i)
|
||||
ASSERT_THAT(values[i], Eq(expected[i]));
|
||||
|
||||
delete_file(dump_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomTest, header)
|
||||
{
|
||||
auto dump_file = dump_filename("header");
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("reset_timestep 5");
|
||||
command("dump id all atom 10 " + dump_file);
|
||||
command("dump_modify id first no header yes");
|
||||
command("run 40 post no");
|
||||
command("undump id");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
std::vector<std::string> expected, values;
|
||||
values = extract_items(dump_file, "TIMESTEP");
|
||||
expected = {"10", "20", "30", "40"};
|
||||
ASSERT_EQ(values.size(), expected.size());
|
||||
for (int i = 0; i < expected.size(); ++i)
|
||||
ASSERT_THAT(values[i], Eq(expected[i]));
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("dump id all atom 10 " + dump_file);
|
||||
command("dump_modify id header no");
|
||||
command("run 40 post no");
|
||||
command("undump id");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
values = extract_items(dump_file, "TIMESTEP");
|
||||
ASSERT_EQ(values.size(), 0);
|
||||
delete_file(dump_file);
|
||||
}
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
@ -686,7 +884,7 @@ int main(int argc, char **argv)
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -23,6 +23,7 @@ using ::testing::Eq;
|
||||
|
||||
bool verbose = false;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
class DumpCfgTest : public MeltTest {
|
||||
std::string dump_style = "cfg";
|
||||
|
||||
@ -143,6 +144,7 @@ TEST_F(DumpCfgTest, no_unwrap_no_buffer_run0)
|
||||
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
|
||||
delete_file("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@ -151,7 +153,7 @@ int main(int argc, char **argv)
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -26,6 +26,7 @@ using ::testing::Eq;
|
||||
char *BINARY2TXT_EXECUTABLE = nullptr;
|
||||
bool verbose = false;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
class DumpCustomTest : public MeltTest {
|
||||
std::string dump_style = "custom";
|
||||
|
||||
@ -383,7 +384,7 @@ TEST_F(DumpCustomTest, rerun_bin)
|
||||
ASSERT_NEAR(pe_2, pe_rerun, 1.0e-14);
|
||||
delete_file(dump_file);
|
||||
}
|
||||
|
||||
}
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
@ -391,7 +392,7 @@ int main(int argc, char **argv)
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -28,6 +28,7 @@ using ::testing::Eq;
|
||||
char *BINARY2TXT_EXECUTABLE = nullptr;
|
||||
bool verbose = false;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
class DumpLocalTest : public MeltTest {
|
||||
std::string dump_style = "local";
|
||||
|
||||
@ -237,6 +238,7 @@ TEST_F(DumpLocalTest, triclinic_run0)
|
||||
ASSERT_EQ(utils::split_words(lines[7]).size(), 3);
|
||||
delete_file(dump_file);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@ -245,7 +247,7 @@ int main(int argc, char **argv)
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -31,6 +31,7 @@ using ::testing::Eq;
|
||||
char *NCDUMP_EXECUTABLE = nullptr;
|
||||
bool verbose = false;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
class DumpNetCDFTest : public MeltTest {
|
||||
std::string dump_style = "netcdf";
|
||||
|
||||
@ -386,6 +387,7 @@ TEST_F(DumpNetCDFTest, run0_mpi)
|
||||
}
|
||||
delete_file(dump_file);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@ -394,7 +396,7 @@ int main(int argc, char **argv)
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
std::vector<std::string> env = LAMMPS_NS::utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
|
||||
@ -494,8 +494,7 @@ int main(int argc, char **argv)
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. "
|
||||
"Death tests will be skipped\n";
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
|
||||
@ -303,9 +303,8 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. "
|
||||
"Death tests will be skipped\n";
|
||||
if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
|
||||
@ -325,9 +325,8 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. "
|
||||
"Death tests will be skipped\n";
|
||||
if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
|
||||
@ -166,9 +166,8 @@ int main(int argc, char **argv)
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. "
|
||||
"Death tests will be skipped\n";
|
||||
if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions())
|
||||
std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n";
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
|
||||
@ -9,7 +9,15 @@ DEFAULT_STYLE_EXAMPLE_LOG=os.path.join('melt', 'log.*.melt.g++.1')
|
||||
MULTI_STYLE_EXAMPLE_LOG=os.path.join('peptide', 'log.27Nov18.peptide.g++.1')
|
||||
sys.path.insert(1,PIZZA_DIR)
|
||||
|
||||
import dump
|
||||
# dump class uses NumPy, so only load and test dump if NumPy is available
|
||||
has_numpy = False
|
||||
try:
|
||||
import numpy
|
||||
has_numpy = True
|
||||
import dump
|
||||
except:
|
||||
pass
|
||||
|
||||
import log
|
||||
|
||||
class Logfiles(unittest.TestCase):
|
||||
@ -112,6 +120,7 @@ class PythonDump(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
del self.lmp
|
||||
|
||||
@unittest.skipIf(not has_numpy,"Missing the NumPy python module")
|
||||
def testDumpCustom(self):
|
||||
dumpfile = os.path.join(os.path.abspath('.'), 'dump.custom')
|
||||
self.lmp.command('shell cd ' + os.environ['TEST_INPUT_DIR'])
|
||||
@ -120,6 +129,7 @@ class PythonDump(unittest.TestCase):
|
||||
self.lmp.command("dump 1 all custom 2 " + dumpfile + " id type mol q x y z vx vy vz")
|
||||
self.lmp.command("dump_modify 1 time yes units yes")
|
||||
self.lmp.command("run 4 post no")
|
||||
self.lmp.command("undump 1")
|
||||
d = dump.dump(dumpfile)
|
||||
id1, id2 = d.minmax("id")
|
||||
self.assertEqual(id1,1)
|
||||
|
||||
@ -26,7 +26,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
using LAMMPS_NS::Info;
|
||||
using LAMMPS_NS::LAMMPS;
|
||||
using LAMMPS_NS::LAMMPSException;
|
||||
|
||||
using ::testing::ContainsRegex;
|
||||
|
||||
@ -37,7 +39,7 @@ using ::testing::ContainsRegex;
|
||||
auto mesg = ::testing::internal::GetCapturedStdout(); \
|
||||
ASSERT_THAT(mesg, ContainsRegex(errmsg)); \
|
||||
} else { \
|
||||
if (platform::mpi_vendor() != "Open MPI") { \
|
||||
if (LAMMPS_NS::platform::mpi_vendor() != "Open MPI") { \
|
||||
::testing::internal::CaptureStdout(); \
|
||||
ASSERT_DEATH({__VA_ARGS__}, ""); \
|
||||
auto mesg = ::testing::internal::GetCapturedStdout(); \
|
||||
@ -101,7 +103,7 @@ public:
|
||||
|
||||
double get_variable_value(const std::string &name)
|
||||
{
|
||||
char *str = utils::strdup(fmt::format("v_{}", name));
|
||||
char *str = LAMMPS_NS::utils::strdup(fmt::format("v_{}", name));
|
||||
double value = lmp->input->variable->compute_equal(str);
|
||||
delete[] str;
|
||||
return value;
|
||||
@ -122,9 +124,9 @@ protected:
|
||||
{
|
||||
int argc = args.size() + 1;
|
||||
char **argv = new char *[argc];
|
||||
argv[0] = utils::strdup(testbinary);
|
||||
argv[0] = LAMMPS_NS::utils::strdup(testbinary);
|
||||
for (int i = 1; i < argc; i++) {
|
||||
argv[i] = utils::strdup(args[i - 1]);
|
||||
argv[i] = LAMMPS_NS::utils::strdup(args[i - 1]);
|
||||
}
|
||||
|
||||
HIDE_OUTPUT([&] {
|
||||
|
||||
Reference in New Issue
Block a user