From 3de60fac65b6c5af45a15d0adecb7ffea3e3f458 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 9 Oct 2020 17:50:29 -0400 Subject: [PATCH 01/67] Add custom TestEventListener for MPI testing --- unittest/c-library/CMakeLists.txt | 7 + unittest/c-library/test_library_mpi.cpp | 320 ++++++++++++++++++++++++ 2 files changed, 327 insertions(+) create mode 100644 unittest/c-library/test_library_mpi.cpp diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index fe70cb1584..5172ed68f3 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -55,3 +55,10 @@ add_executable(test_library_config test_library_config.cpp test_main.cpp) target_link_libraries(test_library_config PRIVATE lammps GTest::GTest GTest::GMock) target_compile_definitions(test_library_config PRIVATE ${TEST_CONFIG_DEFS}) add_test(LibraryConfig test_library_config) + +if (BUILD_MPI) + add_executable(test_library_mpi test_library_mpi.cpp) + target_link_libraries(test_library_mpi PRIVATE lammps GTest::GTest GTest::GMock) + target_compile_definitions(test_library_mpi PRIVATE ${TEST_CONFIG_DEFS}) + add_test(NAME LibraryMPI COMMAND ${MPIEXEC_EXECUTABLE} -np 4 $) +endif() diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp new file mode 100644 index 0000000000..e0e2cc3c12 --- /dev/null +++ b/unittest/c-library/test_library_mpi.cpp @@ -0,0 +1,320 @@ +// unit tests for checking LAMMPS configuration settings through the library interface + +#include "lammps.h" +#include "library.h" +#include "timer.h" +#include +#include + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using ::testing::ExitedWithCode; +using ::testing::HasSubstr; +using ::testing::StartsWith; +using ::testing::StrEq; + +using ::testing::TestEventListener; +using ::testing::TestCase; +using ::testing::TestSuite; +using ::testing::UnitTest; +using ::testing::TestPartResult; +using ::testing::TestInfo; + +class MPIPrinter : public TestEventListener { + MPI_Comm comm; + TestEventListener * default_listener; + int me; + int nprocs; + char * buffer; + size_t buffer_size; + std::deque results; + bool finalize_test; +public: + MPIPrinter(TestEventListener * default_listener) : default_listener(default_listener) { + comm = MPI_COMM_WORLD; + MPI_Comm_rank(comm, &me); + MPI_Comm_size(comm, &nprocs); + buffer_size = 1024; + buffer = new char[buffer_size]; + finalize_test = false; + } + + ~MPIPrinter() override { + delete default_listener; + default_listener = nullptr; + + delete [] buffer; + buffer = nullptr; + buffer_size = 0; + } + + virtual void OnTestProgramStart(const UnitTest& unit_test) override { + if(me == 0) default_listener->OnTestProgramStart(unit_test); + } + + virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration) override { + if(me == 0) default_listener->OnTestIterationStart(unit_test, iteration); + } + + virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) override { + if(me == 0) default_listener->OnEnvironmentsSetUpStart(unit_test); + } + + virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) override { + if(me == 0) default_listener->OnEnvironmentsSetUpEnd(unit_test); + } + + virtual void OnTestSuiteStart(const TestSuite& test_suite) override { + if(me == 0) default_listener->OnTestSuiteStart(test_suite); + } + + // Legacy API is deprecated but still available +#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + virtual void OnTestCaseStart(const TestCase& test_case) override { + if(me == 0) default_listener->OnTestSuiteStart(test_case); + } +#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + + + virtual void OnTestStart(const TestInfo& test_info) override { + // Called before a test starts. + if(me == 0) default_listener->OnTestStart(test_info); + results.clear(); + finalize_test = false; + } + + + virtual void OnTestPartResult(const TestPartResult& test_part_result) override { + // Called after a failed assertion or a SUCCESS(). + // test_part_result() + + if (me == 0 && finalize_test) { + default_listener->OnTestPartResult(test_part_result); + } else { + std::stringstream proc_message; + std::istringstream msg(test_part_result.message()); + std::string line; + + while(std::getline(msg, line)) { + proc_message << "[Rank " << me << "] " << line << std::endl; + } + + results.push_back(TestPartResult(test_part_result.type(), test_part_result.file_name(), test_part_result.line_number(), proc_message.str().c_str())); + } + } + + virtual void OnTestEnd(const TestInfo& test_info) override { + // Called after a test ends. + MPI_Barrier(comm); + + // other procs send their test part results + if(me != 0) { + int nresults = results.size(); + MPI_Send(&nresults, 1, MPI_INT, 0, 0, comm); + + for(auto& test_part_result : results) { + + int type = test_part_result.type(); + MPI_Send(&type, 1, MPI_INT, 0, 0, comm); + + const char * str = test_part_result.file_name(); + int length = 0; + if(str) length = strlen(str)+1; + MPI_Send(&length, 1, MPI_INT, 0, 0, comm); + if(str) MPI_Send(str, length, MPI_CHAR, 0, 0, comm); + + int lineno = test_part_result.line_number(); + MPI_Send(&lineno, 1, MPI_INT, 0, 0, comm); + + str = test_part_result.message(); + length = 0; + if(str) length = strlen(str)+1; + MPI_Send(&length, 1, MPI_INT, 0, 0, comm); + if(str) MPI_Send(str, length, MPI_CHAR, 0, 0, comm); + } + } + + if(me == 0) { + // collect results from other procs + for(int p = 1; p < nprocs; p++) { + int nresults = 0; + MPI_Recv(&nresults, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); + + for(int r = 0; r < nresults; r++) { + + int type; + MPI_Recv(&type, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); + + int length = 0; + MPI_Recv(&length, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); + std::string file_name; + + if (length > 0) { + if (length > buffer_size) { + delete [] buffer; + buffer = new char[length]; + buffer_size = length; + } + MPI_Recv(buffer, length, MPI_CHAR, p, 0, comm, MPI_STATUS_IGNORE); + file_name = buffer; + } + + int lineno; + MPI_Recv(&lineno, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); + + MPI_Recv(&length, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); + std::string message; + + if (length > 0) { + if (length > buffer_size) { + delete [] buffer; + buffer = new char[length]; + buffer_size = length; + } + MPI_Recv(buffer, length, MPI_CHAR, p, 0, comm, MPI_STATUS_IGNORE); + message = std::string(buffer); + } + + results.push_back(TestPartResult((TestPartResult::Type)type, file_name.c_str(), lineno, message.c_str())); + } + } + + // ensure failures are reported + finalize_test = true; + + // add all failures + while(!results.empty()) { + auto result = results.front(); + if(result.failed()) { + ADD_FAILURE_AT(result.file_name(), result.line_number()) << result.message(); + } else { + default_listener->OnTestPartResult(result); + } + results.pop_front(); + } + + default_listener->OnTestEnd(test_info); + } + } + + virtual void OnTestSuiteEnd(const TestSuite& test_suite) override { + if(me == 0) default_listener->OnTestSuiteEnd(test_suite); + } + +#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + virtual void OnTestCaseEnd(const TestCase& test_case) override { + if(me == 0) default_listener->OnTestCaseEnd(test_case); + } +#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + + virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) override { + if(me == 0) default_listener->OnEnvironmentsTearDownStart(unit_test); + } + + virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) override { + if(me == 0) default_listener->OnEnvironmentsTearDownEnd(unit_test); + } + + virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override { + if(me == 0) default_listener->OnTestIterationEnd(unit_test, iteration); + } + + virtual void OnTestProgramEnd(const UnitTest& unit_test) override { + if(me == 0) default_listener->OnTestProgramEnd(unit_test); + } +}; + + +TEST(MPI, global_box) +{ + int nprocs, me; + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &me); + EXPECT_EQ(nprocs, 4); + EXPECT_GT(me, -1); + EXPECT_LT(me, 5); + + double boxlo[3]; + double boxhi[3]; + double xy = 0.0; + double yz = 0.0; + double xz = 0.0; + int pflags[3]; + int boxflag; + + ::testing::internal::CaptureStdout(); + const char *args[] = {"LAMMPS_test", "-log", "none", + "-echo", "screen", "-nocite"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); + void * lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); + lammps_command(lmp, "units lj"); + lammps_command(lmp, "atom_style atomic"); + lammps_command(lmp, "region box block 0 2 0 2 0 2"); + lammps_command(lmp, "create_box 1 box"); + + lammps_extract_box(lmp, boxlo, boxhi, &xy, &yz, &xz, pflags, &boxflag); + ::testing::internal::GetCapturedStdout(); + + EXPECT_EQ(boxlo[0], 0.0); + EXPECT_EQ(boxlo[1], 0.0); + EXPECT_EQ(boxlo[2], 0.0); + + EXPECT_EQ(boxhi[0], 2.0); + EXPECT_EQ(boxhi[1], 2.0); + EXPECT_EQ(boxhi[2], 2.0); + + ::testing::internal::CaptureStdout(); + lammps_close(lmp); + ::testing::internal::GetCapturedStdout(); +}; + + +bool verbose = false; + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + ::testing::InitGoogleMock(&argc, argv); + + if (argc < 1) { + return 1; + } + + // handle arguments passed via environment variable + if (const char *var = getenv("TEST_ARGS")) { + std::vector env = LAMMPS_NS::utils::split_words(var); + for (auto arg : env) { + if (arg == "-v") { + verbose = true; + } + } + } + + int iarg = 1; + while (iarg < argc) { + if (strcmp(argv[iarg], "-v") == 0) { + verbose = true; + ++iarg; + } else { + std::cerr << "unknown option: " << argv[iarg] << "\n\n"; + MPI_Finalize(); + return 1; + } + } + + auto & listeners = UnitTest::GetInstance()->listeners(); + + // Remove default listener + auto default_listener = listeners.Release(listeners.default_result_printer()); + + // Adds a listener to the end. googletest takes the ownership. + listeners.Append(new MPIPrinter(default_listener)); + + int rv = RUN_ALL_TESTS(); + MPI_Finalize(); + return rv; +} From d7201bae33e221ab2a904da90340f9a864c2d29f Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 9 Oct 2020 18:01:51 -0400 Subject: [PATCH 02/67] Add library access to sublo and subhi --- src/library.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/library.cpp b/src/library.cpp index 404789d315..87a042b944 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -1161,6 +1161,8 @@ void *lammps_extract_global(void *handle, const char *name) if (strcmp(name,"ntimestep") == 0) return (void *) &lmp->update->ntimestep; if (strcmp(name,"boxlo") == 0) return (void *) lmp->domain->boxlo; if (strcmp(name,"boxhi") == 0) return (void *) lmp->domain->boxhi; + if (strcmp(name,"sublo") == 0) return (void *) lmp->domain->sublo; + if (strcmp(name,"subhi") == 0) return (void *) lmp->domain->subhi; if (strcmp(name,"boxxlo") == 0) return (void *) &lmp->domain->boxlo[0]; if (strcmp(name,"boxxhi") == 0) return (void *) &lmp->domain->boxhi[0]; if (strcmp(name,"boxylo") == 0) return (void *) &lmp->domain->boxlo[1]; From ca405823ae9308ee50fae393ba45b7abc6d067db Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 9 Oct 2020 18:03:02 -0400 Subject: [PATCH 03/67] Add test for sublo and subhi --- unittest/c-library/test_library_mpi.cpp | 73 ++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 8 deletions(-) diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp index e0e2cc3c12..5effb31b4d 100644 --- a/unittest/c-library/test_library_mpi.cpp +++ b/unittest/c-library/test_library_mpi.cpp @@ -86,7 +86,7 @@ public: finalize_test = false; } - + virtual void OnTestPartResult(const TestPartResult& test_part_result) override { // Called after a failed assertion or a SUCCESS(). // test_part_result() @@ -105,7 +105,7 @@ public: results.push_back(TestPartResult(test_part_result.type(), test_part_result.file_name(), test_part_result.line_number(), proc_message.str().c_str())); } } - + virtual void OnTestEnd(const TestInfo& test_info) override { // Called after a test ends. MPI_Barrier(comm); @@ -195,11 +195,11 @@ public: } results.pop_front(); } - + default_listener->OnTestEnd(test_info); } } - + virtual void OnTestSuiteEnd(const TestSuite& test_suite) override { if(me == 0) default_listener->OnTestSuiteEnd(test_suite); } @@ -217,11 +217,11 @@ public: virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) override { if(me == 0) default_listener->OnEnvironmentsTearDownEnd(unit_test); } - + virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override { if(me == 0) default_listener->OnTestIterationEnd(unit_test, iteration); } - + virtual void OnTestProgramEnd(const UnitTest& unit_test) override { if(me == 0) default_listener->OnTestProgramEnd(unit_test); } @@ -258,7 +258,7 @@ TEST(MPI, global_box) lammps_extract_box(lmp, boxlo, boxhi, &xy, &yz, &xz, pflags, &boxflag); ::testing::internal::GetCapturedStdout(); - + EXPECT_EQ(boxlo[0], 0.0); EXPECT_EQ(boxlo[1], 0.0); EXPECT_EQ(boxlo[2], 0.0); @@ -266,7 +266,64 @@ TEST(MPI, global_box) EXPECT_EQ(boxhi[0], 2.0); EXPECT_EQ(boxhi[1], 2.0); EXPECT_EQ(boxhi[2], 2.0); - + + ::testing::internal::CaptureStdout(); + lammps_close(lmp); + ::testing::internal::GetCapturedStdout(); +}; + +TEST(MPI, sub_box) +{ + int nprocs, me; + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &me); + EXPECT_EQ(nprocs, 4); + EXPECT_GT(me, -1); + EXPECT_LT(me, 5); + + double boxlo[3]; + double boxhi[3]; + double xy = 0.0; + double yz = 0.0; + double xz = 0.0; + int pflags[3]; + int boxflag; + + ::testing::internal::CaptureStdout(); + const char *args[] = {"LAMMPS_test", "-log", "none", + "-echo", "screen", "-nocite"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); + void * lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); + lammps_command(lmp, "units lj"); + lammps_command(lmp, "atom_style atomic"); + lammps_command(lmp, "region box block 0 2 0 2 0 2"); + lammps_command(lmp, "create_box 1 box"); + + lammps_extract_box(lmp, boxlo, boxhi, &xy, &yz, &xz, pflags, &boxflag); + ::testing::internal::GetCapturedStdout(); + + EXPECT_EQ(boxlo[0], 0.0); + EXPECT_EQ(boxlo[1], 0.0); + EXPECT_EQ(boxlo[2], 0.0); + + EXPECT_EQ(boxhi[0], 2.0); + EXPECT_EQ(boxhi[1], 2.0); + EXPECT_EQ(boxhi[2], 2.0); + + double * sublo = (double*)lammps_extract_global(lmp, "sublo"); + double * subhi = (double*)lammps_extract_global(lmp, "subhi"); + + ASSERT_NE(sublo, nullptr); + ASSERT_NE(subhi, nullptr); + + EXPECT_GE(sublo[0], boxlo[0]); + EXPECT_GE(sublo[1], boxlo[1]); + EXPECT_GE(sublo[2], boxlo[2]); + EXPECT_LE(subhi[0], boxhi[0]); + EXPECT_LE(subhi[1], boxhi[1]); + EXPECT_LE(subhi[2], boxhi[2]); + ::testing::internal::CaptureStdout(); lammps_close(lmp); ::testing::internal::GetCapturedStdout(); From d26eafbe3f5f57e50d28feecd3817035b9651b87 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Sat, 10 Oct 2020 17:22:18 -0400 Subject: [PATCH 04/67] Refactor MPI test driver --- unittest/c-library/test_library_mpi.cpp | 264 +----------------------- unittest/testing/mpitesting.h | 228 ++++++++++++++++++++ unittest/testing/test_mpi_main.h | 67 ++++++ 3 files changed, 297 insertions(+), 262 deletions(-) create mode 100644 unittest/testing/mpitesting.h create mode 100644 unittest/testing/test_mpi_main.h diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp index 5effb31b4d..c4a50b54ce 100644 --- a/unittest/c-library/test_library_mpi.cpp +++ b/unittest/c-library/test_library_mpi.cpp @@ -4,230 +4,17 @@ #include "library.h" #include "timer.h" #include -#include - -#include #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/test_mpi_main.h" + using ::testing::ExitedWithCode; using ::testing::HasSubstr; using ::testing::StartsWith; using ::testing::StrEq; -using ::testing::TestEventListener; -using ::testing::TestCase; -using ::testing::TestSuite; -using ::testing::UnitTest; -using ::testing::TestPartResult; -using ::testing::TestInfo; - -class MPIPrinter : public TestEventListener { - MPI_Comm comm; - TestEventListener * default_listener; - int me; - int nprocs; - char * buffer; - size_t buffer_size; - std::deque results; - bool finalize_test; -public: - MPIPrinter(TestEventListener * default_listener) : default_listener(default_listener) { - comm = MPI_COMM_WORLD; - MPI_Comm_rank(comm, &me); - MPI_Comm_size(comm, &nprocs); - buffer_size = 1024; - buffer = new char[buffer_size]; - finalize_test = false; - } - - ~MPIPrinter() override { - delete default_listener; - default_listener = nullptr; - - delete [] buffer; - buffer = nullptr; - buffer_size = 0; - } - - virtual void OnTestProgramStart(const UnitTest& unit_test) override { - if(me == 0) default_listener->OnTestProgramStart(unit_test); - } - - virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration) override { - if(me == 0) default_listener->OnTestIterationStart(unit_test, iteration); - } - - virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) override { - if(me == 0) default_listener->OnEnvironmentsSetUpStart(unit_test); - } - - virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) override { - if(me == 0) default_listener->OnEnvironmentsSetUpEnd(unit_test); - } - - virtual void OnTestSuiteStart(const TestSuite& test_suite) override { - if(me == 0) default_listener->OnTestSuiteStart(test_suite); - } - - // Legacy API is deprecated but still available -#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ - virtual void OnTestCaseStart(const TestCase& test_case) override { - if(me == 0) default_listener->OnTestSuiteStart(test_case); - } -#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ - - - virtual void OnTestStart(const TestInfo& test_info) override { - // Called before a test starts. - if(me == 0) default_listener->OnTestStart(test_info); - results.clear(); - finalize_test = false; - } - - - virtual void OnTestPartResult(const TestPartResult& test_part_result) override { - // Called after a failed assertion or a SUCCESS(). - // test_part_result() - - if (me == 0 && finalize_test) { - default_listener->OnTestPartResult(test_part_result); - } else { - std::stringstream proc_message; - std::istringstream msg(test_part_result.message()); - std::string line; - - while(std::getline(msg, line)) { - proc_message << "[Rank " << me << "] " << line << std::endl; - } - - results.push_back(TestPartResult(test_part_result.type(), test_part_result.file_name(), test_part_result.line_number(), proc_message.str().c_str())); - } - } - - virtual void OnTestEnd(const TestInfo& test_info) override { - // Called after a test ends. - MPI_Barrier(comm); - - // other procs send their test part results - if(me != 0) { - int nresults = results.size(); - MPI_Send(&nresults, 1, MPI_INT, 0, 0, comm); - - for(auto& test_part_result : results) { - - int type = test_part_result.type(); - MPI_Send(&type, 1, MPI_INT, 0, 0, comm); - - const char * str = test_part_result.file_name(); - int length = 0; - if(str) length = strlen(str)+1; - MPI_Send(&length, 1, MPI_INT, 0, 0, comm); - if(str) MPI_Send(str, length, MPI_CHAR, 0, 0, comm); - - int lineno = test_part_result.line_number(); - MPI_Send(&lineno, 1, MPI_INT, 0, 0, comm); - - str = test_part_result.message(); - length = 0; - if(str) length = strlen(str)+1; - MPI_Send(&length, 1, MPI_INT, 0, 0, comm); - if(str) MPI_Send(str, length, MPI_CHAR, 0, 0, comm); - } - } - - if(me == 0) { - // collect results from other procs - for(int p = 1; p < nprocs; p++) { - int nresults = 0; - MPI_Recv(&nresults, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); - - for(int r = 0; r < nresults; r++) { - - int type; - MPI_Recv(&type, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); - - int length = 0; - MPI_Recv(&length, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); - std::string file_name; - - if (length > 0) { - if (length > buffer_size) { - delete [] buffer; - buffer = new char[length]; - buffer_size = length; - } - MPI_Recv(buffer, length, MPI_CHAR, p, 0, comm, MPI_STATUS_IGNORE); - file_name = buffer; - } - - int lineno; - MPI_Recv(&lineno, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); - - MPI_Recv(&length, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); - std::string message; - - if (length > 0) { - if (length > buffer_size) { - delete [] buffer; - buffer = new char[length]; - buffer_size = length; - } - MPI_Recv(buffer, length, MPI_CHAR, p, 0, comm, MPI_STATUS_IGNORE); - message = std::string(buffer); - } - - results.push_back(TestPartResult((TestPartResult::Type)type, file_name.c_str(), lineno, message.c_str())); - } - } - - // ensure failures are reported - finalize_test = true; - - // add all failures - while(!results.empty()) { - auto result = results.front(); - if(result.failed()) { - ADD_FAILURE_AT(result.file_name(), result.line_number()) << result.message(); - } else { - default_listener->OnTestPartResult(result); - } - results.pop_front(); - } - - default_listener->OnTestEnd(test_info); - } - } - - virtual void OnTestSuiteEnd(const TestSuite& test_suite) override { - if(me == 0) default_listener->OnTestSuiteEnd(test_suite); - } - -#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ - virtual void OnTestCaseEnd(const TestCase& test_case) override { - if(me == 0) default_listener->OnTestCaseEnd(test_case); - } -#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ - - virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) override { - if(me == 0) default_listener->OnEnvironmentsTearDownStart(unit_test); - } - - virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) override { - if(me == 0) default_listener->OnEnvironmentsTearDownEnd(unit_test); - } - - virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override { - if(me == 0) default_listener->OnTestIterationEnd(unit_test, iteration); - } - - virtual void OnTestProgramEnd(const UnitTest& unit_test) override { - if(me == 0) default_listener->OnTestProgramEnd(unit_test); - } -}; - - TEST(MPI, global_box) { int nprocs, me; @@ -328,50 +115,3 @@ TEST(MPI, sub_box) lammps_close(lmp); ::testing::internal::GetCapturedStdout(); }; - - -bool verbose = false; - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - if (argc < 1) { - return 1; - } - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = LAMMPS_NS::utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - int iarg = 1; - while (iarg < argc) { - if (strcmp(argv[iarg], "-v") == 0) { - verbose = true; - ++iarg; - } else { - std::cerr << "unknown option: " << argv[iarg] << "\n\n"; - MPI_Finalize(); - return 1; - } - } - - auto & listeners = UnitTest::GetInstance()->listeners(); - - // Remove default listener - auto default_listener = listeners.Release(listeners.default_result_printer()); - - // Adds a listener to the end. googletest takes the ownership. - listeners.Append(new MPIPrinter(default_listener)); - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/testing/mpitesting.h b/unittest/testing/mpitesting.h new file mode 100644 index 0000000000..d73cf11d44 --- /dev/null +++ b/unittest/testing/mpitesting.h @@ -0,0 +1,228 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, 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 "gmock/gmock.h" +#include "gtest/gtest.h" + +#include +#include + +using ::testing::TestEventListener; +using ::testing::TestCase; +using ::testing::TestSuite; +using ::testing::UnitTest; +using ::testing::TestPartResult; +using ::testing::TestInfo; + +class MPIPrinter : public TestEventListener { + MPI_Comm comm; + TestEventListener * default_listener; + int me; + int nprocs; + char * buffer; + size_t buffer_size; + std::deque results; + bool finalize_test; +public: + MPIPrinter(TestEventListener * default_listener) : default_listener(default_listener) { + comm = MPI_COMM_WORLD; + MPI_Comm_rank(comm, &me); + MPI_Comm_size(comm, &nprocs); + buffer_size = 1024; + buffer = new char[buffer_size]; + finalize_test = false; + } + + ~MPIPrinter() override { + delete default_listener; + default_listener = nullptr; + + delete [] buffer; + buffer = nullptr; + buffer_size = 0; + } + + virtual void OnTestProgramStart(const UnitTest& unit_test) override { + if(me == 0) default_listener->OnTestProgramStart(unit_test); + } + + virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration) override { + if(me == 0) default_listener->OnTestIterationStart(unit_test, iteration); + } + + virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) override { + if(me == 0) default_listener->OnEnvironmentsSetUpStart(unit_test); + } + + virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) override { + if(me == 0) default_listener->OnEnvironmentsSetUpEnd(unit_test); + } + + virtual void OnTestSuiteStart(const TestSuite& test_suite) override { + if(me == 0) default_listener->OnTestSuiteStart(test_suite); + } + + // Legacy API is deprecated but still available +#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + virtual void OnTestCaseStart(const TestCase& test_case) override { + if(me == 0) default_listener->OnTestSuiteStart(test_case); + } +#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + + + virtual void OnTestStart(const TestInfo& test_info) override { + // Called before a test starts. + if(me == 0) default_listener->OnTestStart(test_info); + results.clear(); + finalize_test = false; + } + + + virtual void OnTestPartResult(const TestPartResult& test_part_result) override { + // Called after a failed assertion or a SUCCESS(). + // test_part_result() + + if (me == 0 && finalize_test) { + default_listener->OnTestPartResult(test_part_result); + } else { + std::stringstream proc_message; + std::istringstream msg(test_part_result.message()); + std::string line; + + while(std::getline(msg, line)) { + proc_message << "[Rank " << me << "] " << line << std::endl; + } + + results.push_back(TestPartResult(test_part_result.type(), test_part_result.file_name(), test_part_result.line_number(), proc_message.str().c_str())); + } + } + + virtual void OnTestEnd(const TestInfo& test_info) override { + // Called after a test ends. + MPI_Barrier(comm); + + // other procs send their test part results + if(me != 0) { + int nresults = results.size(); + MPI_Send(&nresults, 1, MPI_INT, 0, 0, comm); + + for(auto& test_part_result : results) { + + int type = test_part_result.type(); + MPI_Send(&type, 1, MPI_INT, 0, 0, comm); + + const char * str = test_part_result.file_name(); + int length = 0; + if(str) length = strlen(str)+1; + MPI_Send(&length, 1, MPI_INT, 0, 0, comm); + if(str) MPI_Send(str, length, MPI_CHAR, 0, 0, comm); + + int lineno = test_part_result.line_number(); + MPI_Send(&lineno, 1, MPI_INT, 0, 0, comm); + + str = test_part_result.message(); + length = 0; + if(str) length = strlen(str)+1; + MPI_Send(&length, 1, MPI_INT, 0, 0, comm); + if(str) MPI_Send(str, length, MPI_CHAR, 0, 0, comm); + } + } + + if(me == 0) { + // collect results from other procs + for(int p = 1; p < nprocs; p++) { + int nresults = 0; + MPI_Recv(&nresults, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); + + for(int r = 0; r < nresults; r++) { + + int type; + MPI_Recv(&type, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); + + int length = 0; + MPI_Recv(&length, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); + std::string file_name; + + if (length > 0) { + if (length > buffer_size) { + delete [] buffer; + buffer = new char[length]; + buffer_size = length; + } + MPI_Recv(buffer, length, MPI_CHAR, p, 0, comm, MPI_STATUS_IGNORE); + file_name = buffer; + } + + int lineno; + MPI_Recv(&lineno, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); + + MPI_Recv(&length, 1, MPI_INT, p, 0, comm, MPI_STATUS_IGNORE); + std::string message; + + if (length > 0) { + if (length > buffer_size) { + delete [] buffer; + buffer = new char[length]; + buffer_size = length; + } + MPI_Recv(buffer, length, MPI_CHAR, p, 0, comm, MPI_STATUS_IGNORE); + message = std::string(buffer); + } + + results.push_back(TestPartResult((TestPartResult::Type)type, file_name.c_str(), lineno, message.c_str())); + } + } + + // ensure failures are reported + finalize_test = true; + + // add all failures + while(!results.empty()) { + auto result = results.front(); + if(result.failed()) { + ADD_FAILURE_AT(result.file_name(), result.line_number()) << result.message(); + } else { + default_listener->OnTestPartResult(result); + } + results.pop_front(); + } + + default_listener->OnTestEnd(test_info); + } + } + + virtual void OnTestSuiteEnd(const TestSuite& test_suite) override { + if(me == 0) default_listener->OnTestSuiteEnd(test_suite); + } + +#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + virtual void OnTestCaseEnd(const TestCase& test_case) override { + if(me == 0) default_listener->OnTestCaseEnd(test_case); + } +#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + + virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) override { + if(me == 0) default_listener->OnEnvironmentsTearDownStart(unit_test); + } + + virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) override { + if(me == 0) default_listener->OnEnvironmentsTearDownEnd(unit_test); + } + + virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override { + if(me == 0) default_listener->OnTestIterationEnd(unit_test, iteration); + } + + virtual void OnTestProgramEnd(const UnitTest& unit_test) override { + if(me == 0) default_listener->OnTestProgramEnd(unit_test); + } +}; diff --git a/unittest/testing/test_mpi_main.h b/unittest/testing/test_mpi_main.h new file mode 100644 index 0000000000..1e89ba3c8c --- /dev/null +++ b/unittest/testing/test_mpi_main.h @@ -0,0 +1,67 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, 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 "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "mpitesting.h" + +#include +#include + +// whether to print verbose output (i.e. not capturing LAMMPS screen output). +bool verbose = false; + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + ::testing::InitGoogleMock(&argc, argv); + + if (argc < 1) { + return 1; + } + + // handle arguments passed via environment variable + if (const char *var = getenv("TEST_ARGS")) { + std::vector env = LAMMPS_NS::utils::split_words(var); + for (auto arg : env) { + if (arg == "-v") { + verbose = true; + } + } + } + + int iarg = 1; + while (iarg < argc) { + if (strcmp(argv[iarg], "-v") == 0) { + verbose = true; + ++iarg; + } else { + std::cerr << "unknown option: " << argv[iarg] << "\n\n"; + MPI_Finalize(); + return 1; + } + } + + auto & listeners = UnitTest::GetInstance()->listeners(); + + // Remove default listener + auto default_listener = listeners.Release(listeners.default_result_printer()); + + // Adds a listener to the end. googletest takes the ownership. + listeners.Append(new MPIPrinter(default_listener)); + + int rv = RUN_ALL_TESTS(); + MPI_Finalize(); + return rv; +} From 00f87722a235059febf2a0e333e9ccae7f9d51c8 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 12 Oct 2020 10:41:54 -0400 Subject: [PATCH 05/67] Add CMake function add_mpi_test() --- unittest/CMakeLists.txt | 6 ++++++ unittest/c-library/CMakeLists.txt | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index dd375112b7..33d6fce1e6 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -1,5 +1,11 @@ include(GTest) +if(BUILD_MPI) + function(add_mpi_test name binary nproc) + add_test(NAME ${name} COMMAND ${MPIEXEC_EXECUTABLE} -np ${nproc} ${binary}) + endfunction() +endif() + add_subdirectory(utils) add_subdirectory(formats) add_subdirectory(commands) diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index 5172ed68f3..4f1ef2b93b 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -60,5 +60,5 @@ if (BUILD_MPI) add_executable(test_library_mpi test_library_mpi.cpp) target_link_libraries(test_library_mpi PRIVATE lammps GTest::GTest GTest::GMock) target_compile_definitions(test_library_mpi PRIVATE ${TEST_CONFIG_DEFS}) - add_test(NAME LibraryMPI COMMAND ${MPIEXEC_EXECUTABLE} -np 4 $) + add_mpi_test(LibraryMPI $ 4) endif() From 8abe8cb003a1ac1a7f6a9c6e8664c24c518274fd Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 12 Oct 2020 12:58:31 -0400 Subject: [PATCH 06/67] Add tests for lammps_gather() and lammps_scatter() --- unittest/c-library/test_library_mpi.cpp | 128 ++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp index c4a50b54ce..36c386144c 100644 --- a/unittest/c-library/test_library_mpi.cpp +++ b/unittest/c-library/test_library_mpi.cpp @@ -115,3 +115,131 @@ TEST(MPI, sub_box) lammps_close(lmp); ::testing::internal::GetCapturedStdout(); }; + +class MPITest : public ::testing::Test { +public: + void command(const std::string &line) { + lammps_command(lmp, line.c_str()); + } + +protected: + const char * testbinary = "LAMMPSTest"; + void *lmp; + + void SetUp() override + { + const char *args[] = { testbinary, "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); + if (!verbose) ::testing::internal::CaptureStdout(); + lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); + InitSystem(); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + virtual void InitSystem() { + command("units lj"); + command("atom_style atomic"); + command("atom_modify map yes"); + + command("lattice fcc 0.8442"); + command("region box block 0 2 0 2 0 2"); + command("create_box 1 box"); + command("create_atoms 1 box"); + command("mass 1 1.0"); + + command("velocity all create 3.0 87287"); + + command("pair_style lj/cut 2.5"); + command("pair_coeff 1 1 1.0 1.0 2.5"); + + command("neighbor 0.3 bin"); + command("neigh_modify every 20 delay 0 check no"); + } + + void TearDown() override + { + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_close(lmp); + lmp = nullptr; + if (!verbose) ::testing::internal::GetCapturedStdout(); + } +}; + +#if !defined(LAMMPS_BIGBIG) + +TEST_F(MPITest, gather) { + int64_t natoms = (int64_t)lammps_get_natoms(lmp); + ASSERT_EQ(natoms, 32); + int * p_nlocal = (int*)lammps_extract_global(lmp, "nlocal"); + int nlocal = *p_nlocal; + EXPECT_LT(nlocal, 32); + EXPECT_EQ(nlocal, 8); + + // get the entire x on all procs + double * x = new double[natoms * 3]; + lammps_gather(lmp, (char*)"x", 1, 3, x); + + int * tag = (int*)lammps_extract_atom(lmp, "id"); + double ** x_local = (double**)lammps_extract_atom(lmp, "x"); + + // each proc checks its local atoms + for(int i = 0; i < nlocal; i++) { + int64_t j = tag[i]-1; + double * x_i = x_local[i]; + double * x_g = &x[j*3]; + EXPECT_DOUBLE_EQ(x_g[0], x_i[0]); + EXPECT_DOUBLE_EQ(x_g[1], x_i[1]); + EXPECT_DOUBLE_EQ(x_g[2], x_i[2]); + } + + delete [] x; +} + +TEST_F(MPITest, scatter) { + int * p_nlocal = (int*)lammps_extract_global(lmp, "nlocal"); + int nlocal = *p_nlocal; + double * x_orig = new double[3*nlocal]; + double ** x_local = (double**)lammps_extract_atom(lmp, "x"); + + // make copy of original local x vector + for(int i = 0; i < nlocal; i++) { + int j = 3*i; + x_orig[j] = x_local[i][0]; + x_orig[j + 1] = x_local[i][1]; + x_orig[j + 2] = x_local[i][2]; + } + + // get the entire x on all procs + int64_t natoms = (int64_t)lammps_get_natoms(lmp); + double * x = new double[natoms * 3]; + lammps_gather(lmp, (char*)"x", 1, 3, x); + + // shift all coordinates by 0.001 + const double delta = 0.001; + for(int64_t i = 0; i < 3*natoms; i++) x[i] += delta; + + // update positions of all atoms + lammps_scatter(lmp, (char*)"x", 1, 3, x); + delete [] x; + x = nullptr; + + // get new nlocal and x_local + p_nlocal = (int*)lammps_extract_global(lmp, "nlocal"); + nlocal = *p_nlocal; + x_local = (double**)lammps_extract_atom(lmp, "x"); + + ASSERT_EQ(nlocal, 8); + + // each proc checks its local atoms for shift + for(int i = 0; i < nlocal; i++) { + double * x_a = x_local[i]; + double * x_b = &x_orig[i*3]; + EXPECT_DOUBLE_EQ(x_a[0], x_b[0]+delta); + EXPECT_DOUBLE_EQ(x_a[1], x_b[1]+delta); + EXPECT_DOUBLE_EQ(x_a[2], x_b[2]+delta); + } + + delete [] x_orig; +} +#endif From 939b8fd0c7a8ad028c401f082de5a28664a3bd10 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 13 Oct 2020 11:44:08 -0400 Subject: [PATCH 07/67] Update add_mpi_test() CMake function --- unittest/CMakeLists.txt | 14 ++++++++++++-- unittest/c-library/CMakeLists.txt | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 33d6fce1e6..f9606fd2dc 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -1,8 +1,18 @@ include(GTest) if(BUILD_MPI) - function(add_mpi_test name binary nproc) - add_test(NAME ${name} COMMAND ${MPIEXEC_EXECUTABLE} -np ${nproc} ${binary}) + function(add_mpi_test) + set(MPI_TEST_NUM_PROCS 1) + set(MPI_TEST_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + cmake_parse_arguments(MPI_TEST "" "NAME;NUM_PROCS;WORKING_DIRECTORY" "COMMAND" ${ARGN}) + list(GET MPI_TEST_COMMAND 0 EXECUTABLE) + list(REMOVE_AT MPI_TEST_COMMAND 0) + set(ARGS ${MPI_TEST_COMMAND}) + add_test(NAME ${MPI_TEST_NAME} + WORKING_DIRECTORY ${MPI_TEST_WORKING_DIRECTORY} + COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPI_TEST_NUM_PROCS} ${MPIEXEC_PREFLAGS} + ${EXECUTABLE} ${MPIEXEC_POSTFLAGS} ${ARGS} + ) endfunction() endif() diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index 4f1ef2b93b..09717c058e 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -60,5 +60,5 @@ if (BUILD_MPI) add_executable(test_library_mpi test_library_mpi.cpp) target_link_libraries(test_library_mpi PRIVATE lammps GTest::GTest GTest::GMock) target_compile_definitions(test_library_mpi PRIVATE ${TEST_CONFIG_DEFS}) - add_mpi_test(LibraryMPI $ 4) + add_mpi_test(NAME LibraryMPI NUM_PROCS 4 COMMAND $) endif() From fd8ff18abca54cfc4c6c83543a2cb45ba6f619ad Mon Sep 17 00:00:00 2001 From: Joel Clemmer Date: Wed, 14 Oct 2020 20:00:48 -0600 Subject: [PATCH 08/67] Adding restart method to fix neigh/history --- src/fix_neigh_history.cpp | 21 ++++++++++++++++++++- src/fix_neigh_history.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/fix_neigh_history.cpp b/src/fix_neigh_history.cpp index 88cb3fa64e..14f1e095de 100644 --- a/src/fix_neigh_history.cpp +++ b/src/fix_neigh_history.cpp @@ -40,6 +40,8 @@ FixNeighHistory::FixNeighHistory(LAMMPS *lmp, int narg, char **arg) : if (narg != 4) error->all(FLERR,"Illegal fix NEIGH_HISTORY command"); restart_peratom = 1; + restart_global = 1; + create_attribute = 1; maxexchange_dynamic = 1; @@ -840,6 +842,23 @@ int FixNeighHistory::unpack_exchange(int nlocal, double *buf) return m; } +/* ---------------------------------------------------------------------- + Use write_restart to invoke pre_exchange +------------------------------------------------------------------------- */ + +void FixNeighHistory::write_restart(FILE *fp) +{ + // Call pre-exchange to copy updated history in page file + // back into per-atom arrays prior to packing restart data + + pre_exchange(); + if (comm->me == 0) { + int size = 0; + fwrite(&size,sizeof(int),1,fp); + } +} + + /* ---------------------------------------------------------------------- pack values in local atom-based arrays for restart file ------------------------------------------------------------------------- */ @@ -851,7 +870,7 @@ int FixNeighHistory::pack_restart(int i, double *buf) for (int n = 0; n < npartner[i]; n++) { buf[m++] = partner[i][n]; memcpy(&buf[m],&valuepartner[i][dnum*n],dnumbytes); - m += dnum; + m += dnum; } // pack buf[0] this way because other fixes unpack it buf[0] = m; diff --git a/src/fix_neigh_history.h b/src/fix_neigh_history.h index 51d03f5b12..89c726683a 100644 --- a/src/fix_neigh_history.h +++ b/src/fix_neigh_history.h @@ -53,6 +53,7 @@ class FixNeighHistory : public Fix { void unpack_reverse_comm(int, int *, double *); int pack_exchange(int, double *); int unpack_exchange(int, double *); + void write_restart(FILE *); int pack_restart(int, double *); void unpack_restart(int, int); int size_restart(int); From f6433f1c4029f507c2766fd4765b9a60bb066e5d Mon Sep 17 00:00:00 2001 From: Joel Clemmer Date: Wed, 14 Oct 2020 20:05:07 -0600 Subject: [PATCH 09/67] Removing trailing whitespace --- src/fix_neigh_history.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fix_neigh_history.cpp b/src/fix_neigh_history.cpp index 14f1e095de..8487cd2498 100644 --- a/src/fix_neigh_history.cpp +++ b/src/fix_neigh_history.cpp @@ -870,7 +870,7 @@ int FixNeighHistory::pack_restart(int i, double *buf) for (int n = 0; n < npartner[i]; n++) { buf[m++] = partner[i][n]; memcpy(&buf[m],&valuepartner[i][dnum*n],dnumbytes); - m += dnum; + m += dnum; } // pack buf[0] this way because other fixes unpack it buf[0] = m; From e804235d23e151f3dadf252665676d96847d96ca Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Thu, 22 Oct 2020 11:59:41 -0600 Subject: [PATCH 10/67] Add Kokkos support for fix shake and forward comm on Device --- src/Depend.sh | 1 + src/KOKKOS/Install.sh | 2 + src/KOKKOS/comm_kokkos.cpp | 90 +- src/KOKKOS/comm_kokkos.h | 8 +- src/KOKKOS/fix_qeq_reax_kokkos.cpp | 84 +- src/KOKKOS/fix_qeq_reax_kokkos.h | 24 +- src/KOKKOS/fix_shake_kokkos.cpp | 1852 ++++++++++++++++++++++++++++ src/KOKKOS/fix_shake_kokkos.h | 210 ++++ src/KOKKOS/kokkos_base.h | 7 + src/RIGID/fix_shake.cpp | 2 + src/RIGID/fix_shake.h | 8 +- src/fix.cpp | 1 + src/fix.h | 1 + 13 files changed, 2252 insertions(+), 38 deletions(-) create mode 100644 src/KOKKOS/fix_shake_kokkos.cpp create mode 100644 src/KOKKOS/fix_shake_kokkos.h diff --git a/src/Depend.sh b/src/Depend.sh index a6351e7b13..e629ca9197 100755 --- a/src/Depend.sh +++ b/src/Depend.sh @@ -107,6 +107,7 @@ if (test $1 = "PERI") then fi if (test $1 = "RIGID") then + depend KOKKOS depend USER-OMP depend USER-SDPD fi diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index 03508578ae..7c35f81891 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -142,6 +142,8 @@ action fix_reaxc_species_kokkos.cpp fix_reaxc_species.cpp action fix_reaxc_species_kokkos.h fix_reaxc_species.h action fix_setforce_kokkos.cpp action fix_setforce_kokkos.h +action fix_shake_kokkos.cpp fix_shake.cpp +action fix_shake_kokkos.h fix_shake.h action fix_shardlow_kokkos.cpp fix_shardlow.cpp action fix_shardlow_kokkos.h fix_shardlow.h action fix_momentum_kokkos.cpp diff --git a/src/KOKKOS/comm_kokkos.cpp b/src/KOKKOS/comm_kokkos.cpp index f8d833d48c..97bb1a5b0b 100644 --- a/src/KOKKOS/comm_kokkos.cpp +++ b/src/KOKKOS/comm_kokkos.cpp @@ -75,6 +75,11 @@ CommKokkos::CommKokkos(LAMMPS *lmp) : CommBrick(lmp) max_buf_pair = 0; k_buf_send_pair = DAT::tdual_xfloat_1d("comm:k_buf_send_pair",1); k_buf_recv_pair = DAT::tdual_xfloat_1d("comm:k_recv_send_pair",1); + + max_buf_fix = 0; + k_buf_send_fix = DAT::tdual_xfloat_1d("comm:k_buf_send_fix",1); + k_buf_recv_fix = DAT::tdual_xfloat_1d("comm:k_recv_send_fix",1); + } /* ---------------------------------------------------------------------- */ @@ -356,10 +361,79 @@ void CommKokkos::reverse_comm_device() void CommKokkos::forward_comm_fix(Fix *fix, int size) { - k_sendlist.sync(); - CommBrick::forward_comm_fix(fix,size); + if (fix->execution_space == Device && fix->forward_comm_device) { + k_sendlist.sync(); + forward_comm_fix_device(fix,size); + } else { + k_sendlist.sync(); + CommBrick::forward_comm_fix(fix,size); + } } +template +void CommKokkos::forward_comm_fix_device(Fix *fix, int size) +{ + int iswap,n,nsize; + MPI_Request request; + + if (size) nsize = size; + else nsize = fix->comm_forward; + KokkosBase* fixKKBase = dynamic_cast(fix); + + for (iswap = 0; iswap < nswap; iswap++) { + int n = MAX(max_buf_fix,nsize*sendnum[iswap]); + n = MAX(n,nsize*recvnum[iswap]); + if (n > max_buf_fix) + grow_buf_fix(n); + } + + for (iswap = 0; iswap < nswap; iswap++) { + + // pack buffer + + n = fixKKBase->pack_forward_comm_fix_kokkos(sendnum[iswap],k_sendlist, + iswap,k_buf_send_fix,pbc_flag[iswap],pbc[iswap]); + DeviceType().fence(); + + // exchange with another proc + // if self, set recv buffer to send buffer + + if (sendproc[iswap] != me) { + double* buf_send_fix; + double* buf_recv_fix; + if (lmp->kokkos->gpu_aware_flag) { + buf_send_fix = k_buf_send_fix.view().data(); + buf_recv_fix = k_buf_recv_fix.view().data(); + } else { + k_buf_send_fix.modify(); + k_buf_send_fix.sync(); + buf_send_fix = k_buf_send_fix.h_view.data(); + buf_recv_fix = k_buf_recv_fix.h_view.data(); + } + + if (recvnum[iswap]) { + MPI_Irecv(buf_recv_fix,nsize*recvnum[iswap],MPI_DOUBLE, + recvproc[iswap],0,world,&request); + } + if (sendnum[iswap]) + MPI_Send(buf_send_fix,n,MPI_DOUBLE,sendproc[iswap],0,world); + if (recvnum[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE); + + if (!lmp->kokkos->gpu_aware_flag) { + k_buf_recv_fix.modify(); + k_buf_recv_fix.sync(); + } + } else k_buf_recv_fix = k_buf_send_fix; + + // unpack buffer + + fixKKBase->unpack_forward_comm_fix_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_recv_fix); + DeviceType().fence(); + } +} + +/* ---------------------------------------------------------------------- */ + void CommKokkos::reverse_comm_fix(Fix *fix, int size) { k_sendlist.sync(); @@ -456,6 +530,12 @@ void CommKokkos::grow_buf_pair(int n) { k_buf_recv_pair.resize(max_buf_pair); } +void CommKokkos::grow_buf_fix(int n) { + max_buf_fix = n * BUFFACTOR; + k_buf_send_fix.resize(max_buf_fix); + k_buf_recv_fix.resize(max_buf_fix); +} + void CommKokkos::reverse_comm_pair(Pair *pair) { k_sendlist.sync(); @@ -491,8 +571,8 @@ void CommKokkos::exchange() if(!exchange_comm_classic) { static int print = 1; if(print && comm->me==0) { - error->warning(FLERR,"Fixes cannot yet send data in Kokkos communication, " - "switching to classic communication"); + error->warning(FLERR,"Fixes cannot yet send exchange data in Kokkos communication, " + "switching to classic exchange/border communication"); } print = 0; exchange_comm_classic = true; @@ -742,7 +822,7 @@ void CommKokkos::borders() (ghost_velocity && ((AtomVecKokkos*)atom->avec)->no_border_vel_flag)) { if (print && comm->me==0) { error->warning(FLERR,"Required border comm not yet implemented in Kokkos communication, " - "switching to classic communication"); + "switching to classic exchange/border communication"); } print = 0; exchange_comm_classic = true; diff --git a/src/KOKKOS/comm_kokkos.h b/src/KOKKOS/comm_kokkos.h index 9d8766e309..6b4a201ab7 100644 --- a/src/KOKKOS/comm_kokkos.h +++ b/src/KOKKOS/comm_kokkos.h @@ -51,6 +51,7 @@ class CommKokkos : public CommBrick { template void forward_comm_device(int dummy); template void reverse_comm_device(); template void forward_comm_pair_device(Pair *pair); + template void forward_comm_fix_device(Fix *fix, int size=0); template void exchange_device(); template void borders_device(); @@ -73,10 +74,11 @@ class CommKokkos : public CommBrick { DAT::tdual_int_1d k_sendnum_scan; int totalsend; - int max_buf_pair; - DAT::tdual_xfloat_1d k_buf_send_pair; - DAT::tdual_xfloat_1d k_buf_recv_pair; + int max_buf_pair,max_buf_fix; + DAT::tdual_xfloat_1d k_buf_send_pair, k_buf_send_fix; + DAT::tdual_xfloat_1d k_buf_recv_pair, k_buf_recv_fix; void grow_buf_pair(int); + void grow_buf_fix(int); void grow_send(int, int); void grow_recv(int); diff --git a/src/KOKKOS/fix_qeq_reax_kokkos.cpp b/src/KOKKOS/fix_qeq_reax_kokkos.cpp index bf047e7769..c96f5ded68 100644 --- a/src/KOKKOS/fix_qeq_reax_kokkos.cpp +++ b/src/KOKKOS/fix_qeq_reax_kokkos.cpp @@ -47,6 +47,7 @@ FixQEqReaxKokkos(LAMMPS *lmp, int narg, char **arg) : FixQEqReax(lmp, narg, arg) { kokkosable = 1; + forward_comm_device = 1; atomKK = (AtomKokkos *) atom; execution_space = ExecutionSpaceFromDevice::space; @@ -262,19 +263,15 @@ void FixQEqReaxKokkos::pre_force(int /*vflag*/) // comm->forward_comm_fix(this); //Dist_vector( s ); pack_flag = 2; - k_s.template modify(); - k_s.template sync(); - comm->forward_comm_fix(this); - k_s.template modify(); k_s.template sync(); + comm->forward_comm_fix(this); + k_s.template modify(); // comm->forward_comm_fix(this); //Dist_vector( t ); pack_flag = 3; - k_t.template modify(); - k_t.template sync(); - comm->forward_comm_fix(this); - k_t.template modify(); k_t.template sync(); + comm->forward_comm_fix(this); + k_t.template modify(); need_dup = lmp->kokkos->need_dup(); @@ -784,11 +781,9 @@ void FixQEqReaxKokkos::cg_solve1() // comm->forward_comm_fix(this); //Dist_vector( d ); pack_flag = 1; - k_d.template modify(); - k_d.template sync(); - comm->forward_comm_fix(this); - k_d.template modify(); k_d.template sync(); + comm->forward_comm_fix(this); + k_d.template modify(); // sparse_matvec( &H, d, q ); FixQEqReaxKokkosSparse22Functor sparse22_functor(this); @@ -922,11 +917,9 @@ void FixQEqReaxKokkos::cg_solve2() // comm->forward_comm_fix(this); //Dist_vector( d ); pack_flag = 1; - k_d.template modify(); - k_d.template sync(); - comm->forward_comm_fix(this); - k_d.template modify(); k_d.template sync(); + comm->forward_comm_fix(this); + k_d.template modify(); // sparse_matvec( &H, d, q ); FixQEqReaxKokkosSparse22Functor sparse22_functor(this); @@ -1027,11 +1020,9 @@ void FixQEqReaxKokkos::calculate_q() pack_flag = 4; //comm->forward_comm_fix( this ); //Dist_vector( atom->q ); - atomKK->k_q.modify(); - atomKK->k_q.sync(); - comm->forward_comm_fix(this); - atomKK->k_q.modify(); atomKK->k_q.sync(); + comm->forward_comm_fix(this); + atomKK->k_q.modify(); } @@ -1361,6 +1352,59 @@ void FixQEqReaxKokkos::calculate_q_item(int ii) const /* ---------------------------------------------------------------------- */ +template +int FixQEqReaxKokkos::pack_forward_comm_fix_kokkos(int n, DAT::tdual_int_2d k_sendlist, + int iswap_in, DAT::tdual_xfloat_1d &k_buf, + int /*pbc_flag*/, int * /*pbc*/) +{ + d_sendlist = k_sendlist.view(); + iswap = iswap_in; + d_buf = k_buf.view(); + Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); + return n; +} + +template +KOKKOS_INLINE_FUNCTION +void FixQEqReaxKokkos::operator()(TagFixQEqReaxPackForwardComm, const int &i) const { + int j = d_sendlist(iswap, i); + + if (pack_flag == 1) + d_buf[i] = d_d[j]; + else if( pack_flag == 2 ) + d_buf[i] = d_s[j]; + else if( pack_flag == 3 ) + d_buf[i] = d_t[j]; + else if( pack_flag == 4 ) + d_buf[i] = q[j]; +} + +/* ---------------------------------------------------------------------- */ + +template +void FixQEqReaxKokkos::unpack_forward_comm_fix_kokkos(int n, int first_in, DAT::tdual_xfloat_1d &buf) +{ + first = first_in; + d_buf = buf.view(); + Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); +} + +template +KOKKOS_INLINE_FUNCTION +void FixQEqReaxKokkos::operator()(TagFixQEqReaxUnpackForwardComm, const int &i) const { + if (pack_flag == 1) + d_d[i + first] = d_buf[i]; + else if( pack_flag == 2) + d_s[i + first] = d_buf[i]; + else if( pack_flag == 3) + d_t[i + first] = d_buf[i]; + else if( pack_flag == 4) + q[i + first] = d_buf[i]; + +} + +/* ---------------------------------------------------------------------- */ + template int FixQEqReaxKokkos::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, int * /*pbc*/) diff --git a/src/KOKKOS/fix_qeq_reax_kokkos.h b/src/KOKKOS/fix_qeq_reax_kokkos.h index bed532905e..cc9bff3652 100644 --- a/src/KOKKOS/fix_qeq_reax_kokkos.h +++ b/src/KOKKOS/fix_qeq_reax_kokkos.h @@ -26,6 +26,7 @@ FixStyle(qeq/reax/kk/host,FixQEqReaxKokkos) #include "kokkos_type.h" #include "neigh_list.h" #include "neigh_list_kokkos.h" +#include "kokkos_base.h" namespace LAMMPS_NS { @@ -33,9 +34,11 @@ struct TagSparseMatvec1 {}; struct TagSparseMatvec2 {}; struct TagSparseMatvec3 {}; struct TagZeroQGhosts{}; +struct TagFixQEqReaxPackForwardComm {}; +struct TagFixQEqReaxUnpackForwardComm {}; template -class FixQEqReaxKokkos : public FixQEqReax { +class FixQEqReaxKokkos : public FixQEqReax, public KokkosBase { public: typedef DeviceType device_type; typedef ArrayTypes AT; @@ -136,6 +139,12 @@ class FixQEqReaxKokkos : public FixQEqReax { KOKKOS_INLINE_FUNCTION double calculate_H_k(const F_FLOAT &r, const F_FLOAT &shld) const; + KOKKOS_INLINE_FUNCTION + void operator()(TagFixQEqReaxPackForwardComm, const int&) const; + + KOKKOS_INLINE_FUNCTION + void operator()(TagFixQEqReaxUnpackForwardComm, const int&) const; + struct params_qeq{ KOKKOS_INLINE_FUNCTION params_qeq(){chi=0;eta=0;gamma=0;}; @@ -144,6 +153,9 @@ class FixQEqReaxKokkos : public FixQEqReax { F_FLOAT chi, eta, gamma; }; + int pack_forward_comm_fix_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int, int *); + void unpack_forward_comm_fix_kokkos(int, int, DAT::tdual_xfloat_1d&); virtual int pack_forward_comm(int, int *, double *, int, int *); virtual void unpack_forward_comm(int, int, double *); int pack_reverse_comm(int, int, double *); @@ -203,6 +215,11 @@ class FixQEqReaxKokkos : public FixQEqReax { Kokkos::Experimental::ScatterView::value, Kokkos::Experimental::ScatterSum, Kokkos::Experimental::ScatterDuplicated> dup_o; Kokkos::Experimental::ScatterView::value, Kokkos::Experimental::ScatterSum, Kokkos::Experimental::ScatterNonDuplicated> ndup_o; + int iswap; + int first; + typename AT::t_int_2d d_sendlist; + typename AT::t_xfloat_1d_um d_buf; + void init_shielding_k(); void init_hist(); void allocate_matrix(); @@ -216,11 +233,6 @@ class FixQEqReaxKokkos : public FixQEqReax { int count, isuccess; double alpha, beta, delta, cutsq; - int iswap; - int first; - typename AT::t_int_2d d_sendlist; - typename AT::t_xfloat_1d_um v_buf; - void grow_arrays(int); void copy_arrays(int, int, int); int pack_exchange(int, double *); diff --git a/src/KOKKOS/fix_shake_kokkos.cpp b/src/KOKKOS/fix_shake_kokkos.cpp new file mode 100644 index 0000000000..854dfefeed --- /dev/null +++ b/src/KOKKOS/fix_shake_kokkos.cpp @@ -0,0 +1,1852 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, 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 +#include +#include +#include +#include +#include "fix_shake_kokkos.h" +#include "fix_rattle.h" +#include "atom_kokkos.h" +#include "atom_vec.h" +#include "molecule.h" +#include "update.h" +#include "respa.h" +#include "modify.h" +#include "domain.h" +#include "force.h" +#include "bond.h" +#include "angle.h" +#include "comm.h" +#include "group.h" +#include "fix_respa.h" +#include "math_const.h" +#include "memory_kokkos.h" +#include "error.h" +#include "kokkos.h" +#include "atom_masks.h" + +using namespace LAMMPS_NS; +using namespace FixConst; +using namespace MathConst; + +#define RVOUS 1 // 0 for irregular, 1 for all2all + +#define BIG 1.0e20 +#define MASSDELTA 0.1 + +/* ---------------------------------------------------------------------- */ + +template +FixShakeKokkos::FixShakeKokkos(LAMMPS *lmp, int narg, char **arg) : + FixShake(lmp, narg, arg) +{ + kokkosable = 1; + forward_comm_device = 1; + atomKK = (AtomKokkos *)atom; + execution_space = ExecutionSpaceFromDevice::space; + + datamask_read = EMPTY_MASK; + datamask_modify = EMPTY_MASK; + + shake_flag_tmp = shake_flag; + shake_atom_tmp = shake_atom; + shake_type_tmp = shake_type; + + shake_flag = nullptr; + shake_atom = nullptr; + shake_type = nullptr; + + int nmax = atom->nmax; + + grow_arrays(nmax); + + for (int i = 0; i < nmax; i++) { + k_shake_flag.h_view[i] = shake_flag_tmp[i]; + k_shake_atom.h_view(i,0) = shake_atom_tmp[i][0]; + k_shake_atom.h_view(i,1) = shake_atom_tmp[i][1]; + k_shake_atom.h_view(i,2) = shake_atom_tmp[i][2]; + k_shake_atom.h_view(i,3) = shake_atom_tmp[i][3]; + k_shake_type.h_view(i,0) = shake_type_tmp[i][0]; + k_shake_type.h_view(i,1) = shake_type_tmp[i][1]; + k_shake_type.h_view(i,2) = shake_type_tmp[i][2]; + } + + k_shake_flag.modify_host(); + k_shake_atom.modify_host(); + k_shake_type.modify_host(); + + k_bond_distance = DAT::tdual_float_1d("fix_shake:bond_distance",atom->nbondtypes+1); + k_angle_distance = DAT::tdual_float_1d("fix_shake:angle_distance",atom->nangletypes+1); + + d_bond_distance = k_bond_distance.view(); + d_angle_distance = k_angle_distance.view(); + + // use 1D view for scalars to reduce GPU memory operations + + d_scalars = typename AT::t_int_1d("neighbor:scalars",2); + h_scalars = HAT::t_int_1d("neighbor:scalars_mirror",2); + + d_error_flag = Kokkos::subview(d_scalars,0); + d_nlist = Kokkos::subview(d_scalars,1); + + h_error_flag = Kokkos::subview(h_scalars,0); + h_nlist = Kokkos::subview(h_scalars,1); +} + +/* ---------------------------------------------------------------------- */ + +template +FixShakeKokkos::~FixShakeKokkos() +{ + if (copymode) return; + + memoryKK->destroy_kokkos(k_shake_flag,shake_flag); + memoryKK->destroy_kokkos(k_shake_atom,shake_atom); + memoryKK->destroy_kokkos(k_shake_type,shake_type); + memoryKK->destroy_kokkos(k_xshake,xshake); + memoryKK->destroy_kokkos(k_list,list); + + memoryKK->destroy_kokkos(k_vatom,vatom); + + shake_flag = shake_flag_tmp; + shake_atom = shake_atom_tmp; + shake_type = shake_type_tmp; +} + +/* ---------------------------------------------------------------------- + set bond and angle distances + this init must happen after force->bond and force->angle inits +------------------------------------------------------------------------- */ + +template +void FixShakeKokkos::init() +{ + FixShake::init(); + + if (strstr(update->integrate_style,"respa")) + error->all(FLERR,"Cannot yet use respa with Kokkos"); + + if (rattle) + error->all(FLERR,"Cannot yet use KOKKOS package with fix rattle"); + + // set equilibrium bond distances + + for (int i = 1; i <= atom->nbondtypes; i++) + k_bond_distance.h_view[i] = bond_distance[i]; + + // set equilibrium angle distances + + for (int i = 1; i <= atom->nangletypes; i++) + k_angle_distance.h_view[i] = angle_distance[i]; + + k_bond_distance.modify_host(); + k_angle_distance.modify_host(); + + k_bond_distance.sync(); + k_angle_distance.sync(); +} + + +/* ---------------------------------------------------------------------- + build list of SHAKE clusters to constrain + if one or more atoms in cluster are on this proc, + this proc lists the cluster exactly once +------------------------------------------------------------------------- */ + +template +void FixShakeKokkos::pre_neighbor() +{ + // local copies of atom quantities + // used by SHAKE until next re-neighboring + + x = atom->x; + v = atom->v; + f = atom->f; + mass = atom->mass; + rmass = atom->rmass; + type = atom->type; + nlocal = atom->nlocal; + + k_shake_flag.sync(); + k_shake_atom.sync(); + + // extend size of SHAKE list if necessary + + if (nlocal > maxlist) { + maxlist = nlocal; + memoryKK->destroy_kokkos(k_list,list); + memoryKK->create_kokkos(k_list,list,maxlist,"shake:list"); + d_list = k_list.view(); + } + + // don't yet have atom_map_kokkos routines, so move data from host to device + + if (atom->map_style != Atom::MAP_ARRAY) + error->all(FLERR,"Must use atom map style array with Kokkos"); + + int* map_array_host = atom->get_map_array(); + int map_size = atom->get_map_size(); + int map_maxarray = atom->get_map_maxarray(); + if (map_maxarray > (int)k_map_array.extent(0)) + k_map_array = DAT::tdual_int_1d("NeighBond:map_array",map_maxarray); + for (int i=0; i(); + k_map_array.template sync(); + map_array = k_map_array.view(); + + // build list of SHAKE clusters I compute + + Kokkos::deep_copy(d_scalars,0); + + { + // local variables for lambda capture + + auto d_shake_flag = this->d_shake_flag; + auto d_shake_atom = this->d_shake_atom; + auto d_list = this->d_list; + auto d_error_flag = this->d_error_flag; + auto d_nlist = this->d_nlist; + auto map_array = this->map_array; + + Kokkos::parallel_for(nlocal, LAMMPS_LAMBDA(const int& i) { + if (d_shake_flag[i]) { + if (d_shake_flag[i] == 2) { + const int atom1 = map_array(d_shake_atom(i,0)); + const int atom2 = map_array(d_shake_atom(i,1)); + if (atom1 == -1 || atom2 == -1) { + d_error_flag() = 1; + } + if (i <= atom1 && i <= atom2) { + const int nlist = Kokkos::atomic_fetch_add(&d_nlist(),1); + d_list[nlist] = i; + } + } else if (d_shake_flag[i] % 2 == 1) { + const int atom1 = map_array(d_shake_atom(i,0)); + const int atom2 = map_array(d_shake_atom(i,1)); + const int atom3 = map_array(d_shake_atom(i,2)); + if (atom1 == -1 || atom2 == -1 || atom3 == -1) + d_error_flag() = 1; + if (i <= atom1 && i <= atom2 && i <= atom3) { + const int nlist = Kokkos::atomic_fetch_add(&d_nlist(),1); + d_list[nlist] = i; + } + } else { + const int atom1 = map_array(d_shake_atom(i,0)); + const int atom2 = map_array(d_shake_atom(i,1)); + const int atom3 = map_array(d_shake_atom(i,2)); + const int atom4 = map_array(d_shake_atom(i,3)); + if (atom1 == -1 || atom2 == -1 || atom3 == -1 || atom4 == -1) + d_error_flag() = 1; + if (i <= atom1 && i <= atom2 && i <= atom3 && i <= atom4) { + const int nlist = Kokkos::atomic_fetch_add(&d_nlist(),1); + d_list[nlist] = i; + } + } + } + }); + } + + Kokkos::deep_copy(h_scalars,d_scalars); + nlist = h_nlist(); + + if (h_error_flag() == 1) { + error->one(FLERR,fmt::format("Shake atoms missing on proc " + "{} at step {}",me,update->ntimestep)); + } +} + +/* ---------------------------------------------------------------------- + compute the force adjustment for SHAKE constraint +------------------------------------------------------------------------- */ + +template +void FixShakeKokkos::post_force(int vflag) +{ + copymode = 1; + + d_x = atomKK->k_x.view(); + d_f = atomKK->k_f.view(); + d_type = atomKK->k_type.view(); + d_rmass = atomKK->k_rmass.view(); + d_mass = atomKK->k_mass.view(); + nlocal = atomKK->nlocal; + + if (d_rmass.data()) + atomKK->sync(Device,X_MASK|F_MASK|RMASS_MASK); + else + atomKK->sync(Device,X_MASK|F_MASK|TYPE_MASK); + + k_shake_flag.sync(); + k_shake_atom.sync(); + k_shake_type.sync(); + + if (update->ntimestep == next_output) { + atomKK->sync(Host,X_MASK); + k_shake_flag.sync_host(); + k_shake_atom.sync_host(); + stats(); + } + + // xshake = unconstrained move with current v,f + // communicate results if necessary + + unconstrained_update(); + if (nprocs > 1) comm->forward_comm_fix(this); + k_xshake.sync(); + + // virial setup + + if (vflag) v_setup(vflag); + else evflag = 0; + + // reallocate per-atom arrays if necessary + + if (vflag_atom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"improper:vatom"); + d_vatom = k_vatom.template view(); + } + + need_dup = lmp->kokkos->need_dup(); + neighflag = lmp->kokkos->neighflag; + + // allocate duplicated memory + + if (need_dup) { + dup_f = Kokkos::Experimental::create_scatter_view(d_f); + dup_vatom = Kokkos::Experimental::create_scatter_view(d_vatom); + } else { + ndup_f = Kokkos::Experimental::create_scatter_view(d_f); + ndup_vatom = Kokkos::Experimental::create_scatter_view(d_vatom); + } + + Kokkos::deep_copy(d_error_flag,0); + + update_domain_variables(); + + EV_FLOAT ev; + + // loop over clusters to add constraint forces + + if (neighflag == HALF) { + if (evflag) + Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlist),*this,ev); + else + Kokkos::parallel_for(Kokkos::RangePolicy >(0,nlist),*this); + } else if (neighflag == HALFTHREAD) { + if (evflag) + Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlist),*this,ev); + else + Kokkos::parallel_for(Kokkos::RangePolicy >(0,nlist),*this); + } + + copymode = 0; + + Kokkos::deep_copy(h_error_flag,d_error_flag); + + if (h_error_flag() == 2) + error->warning(FLERR,"Shake determinant < 0.0",0); + else if (h_error_flag() == 3) + error->one(FLERR,"Shake determinant = 0.0"); + + // store vflag for coordinate_constraints_end_of_step() + + vflag_post_force = vflag; + + // reduction over duplicated memory + + if (need_dup) + Kokkos::Experimental::contribute(d_f,dup_f); + + atomKK->modified(Device,F_MASK); + + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.template sync(); + } + + // free duplicated memory + + if (need_dup) { + dup_f = decltype(dup_f)(); + dup_vatom = decltype(dup_vatom)(); + } +} + +/* ---------------------------------------------------------------------- */ + +template +template +KOKKOS_INLINE_FUNCTION +void FixShakeKokkos::operator()(TagFixShakePostForce, const int &i, EV_FLOAT& ev) const { + const int m = d_list[i]; + if (d_shake_flag[m] == 2) shake(m,ev); + else if (d_shake_flag[m] == 3) shake3(m,ev); + else if (d_shake_flag[m] == 4) shake4(m,ev); + else shake3angle(m,ev); +} + +template +template +KOKKOS_INLINE_FUNCTION +void FixShakeKokkos::operator()(TagFixShakePostForce, const int &i) const { + EV_FLOAT ev; + this->template operator()(TagFixShakePostForce(), i, ev); +} + +/* ---------------------------------------------------------------------- + count # of degrees-of-freedom removed by SHAKE for atoms in igroup +------------------------------------------------------------------------- */ + +template +int FixShakeKokkos::dof(int igroup) +{ + + d_mask = atomKK->k_mask.view(); + d_tag = atomKK->k_tag.view(); + nlocal = atom->nlocal; + + atomKK->sync(Device,MASK_MASK|TAG_MASK); + k_shake_flag.sync(); + k_shake_atom.sync(); + + // count dof in a cluster if and only if + // the central atom is in group and atom i is the central atom + + int n = 0; + { + // local variables for lambda capture + + auto d_shake_flag = this->d_shake_flag; + auto d_shake_atom = this->d_shake_atom; + auto tag = this->d_tag; + auto mask = this->d_mask; + auto groupbit = group->bitmask[igroup]; + + Kokkos::parallel_reduce(nlocal, LAMMPS_LAMBDA(const int& i, int& n) { + if (!(mask[i] & groupbit)) return; + if (d_shake_flag[i] == 0) return; + if (d_shake_atom(i,0) != tag[i]) return; + if (d_shake_flag[i] == 1) n += 3; + else if (d_shake_flag[i] == 2) n += 1; + else if (d_shake_flag[i] == 3) n += 2; + else if (d_shake_flag[i] == 4) n += 3; + },n); + } + + int nall; + MPI_Allreduce(&n,&nall,1,MPI_INT,MPI_SUM,world); + return nall; +} + + +/* ---------------------------------------------------------------------- + assumes NVE update, seems to be accurate enough for NVT,NPT,NPH as well +------------------------------------------------------------------------- */ + +template +void FixShakeKokkos::unconstrained_update() +{ + d_x = atomKK->k_x.view(); + d_v = atomKK->k_v.view(); + d_f = atomKK->k_f.view(); + d_type = atomKK->k_type.view(); + d_rmass = atomKK->k_rmass.view(); + d_mass = atomKK->k_mass.view(); + nlocal = atom->nlocal; + + if (d_rmass.data()) + atomKK->sync(Device,X_MASK|V_MASK|F_MASK|RMASS_MASK); + else + atomKK->sync(Device,X_MASK|V_MASK|F_MASK|TYPE_MASK); + + + k_shake_flag.sync(); + k_xshake.sync(); + + { + // local variables for lambda capture + + auto d_shake_flag = this->d_shake_flag; + auto d_xshake = this->d_xshake; + auto x = this->d_x; + auto v = this->d_v; + auto f = this->d_f; + auto dtfsq = this->dtfsq; + auto dtv = this->dtv; + + if (d_rmass.data()) { + + auto rmass = this->d_rmass; + + Kokkos::parallel_for(nlocal, LAMMPS_LAMBDA(const int& i) { + if (d_shake_flag[i]) { + const double dtfmsq = dtfsq / rmass[i]; + d_xshake(i,0) = x(i,0) + dtv*v(i,0) + dtfmsq*f(i,0); + d_xshake(i,1) = x(i,1) + dtv*v(i,1) + dtfmsq*f(i,1); + d_xshake(i,2) = x(i,2) + dtv*v(i,2) + dtfmsq*f(i,2); + } else d_xshake(i,2) = d_xshake(i,1) = d_xshake(i,0) = 0.0; + }); + } else { + + auto mass = this->d_mass; + auto type = this->d_type; + + Kokkos::parallel_for(nlocal, LAMMPS_LAMBDA(const int& i) { + if (d_shake_flag[i]) { + const double dtfmsq = dtfsq / mass[type[i]]; + d_xshake(i,0) = x(i,0) + dtv*v(i,0) + dtfmsq*f(i,0); + d_xshake(i,1) = x(i,1) + dtv*v(i,1) + dtfmsq*f(i,1); + d_xshake(i,2) = x(i,2) + dtv*v(i,2) + dtfmsq*f(i,2); + } else d_xshake(i,2) = d_xshake(i,1) = d_xshake(i,0) = 0.0; + }); + } + } + + k_xshake.modify(); +} + +/* ---------------------------------------------------------------------- */ + +template +template +KOKKOS_INLINE_FUNCTION +void FixShakeKokkos::shake(int m, EV_FLOAT& ev) const +{ + + // The f array is duplicated for OpenMP, atomic for CUDA, and neither for Serial + + auto v_f = ScatterViewHelper::value,decltype(dup_f),decltype(ndup_f)>::get(dup_f,ndup_f); + auto a_f = v_f.template access::value>(); + + int nlist,list[2]; + double v[6]; + double invmass0,invmass1; + + // local atom IDs and constraint distances + + int i0 = map_array(d_shake_atom(m,0)); + int i1 = map_array(d_shake_atom(m,1)); + double bond1 = d_bond_distance[d_shake_type(m,0)]; + + // r01 = distance vec between atoms, with PBC + + double r01[3]; + r01[0] = d_x(i0,0) - d_x(i1,0); + r01[1] = d_x(i0,1) - d_x(i1,1); + r01[2] = d_x(i0,2) - d_x(i1,2); + minimum_image(r01); + + // s01 = distance vec after unconstrained update, with PBC + // use Domain::minimum_image_once(), not minimum_image() + // b/c xshake values might be huge, due to e.g. fix gcmc + + double s01[3]; + s01[0] = d_xshake(i0,0) - d_xshake(i1,0); + s01[1] = d_xshake(i0,1) - d_xshake(i1,1); + s01[2] = d_xshake(i0,2) - d_xshake(i1,2); + minimum_image_once(s01); + + // scalar distances between atoms + + double r01sq = r01[0]*r01[0] + r01[1]*r01[1] + r01[2]*r01[2]; + double s01sq = s01[0]*s01[0] + s01[1]*s01[1] + s01[2]*s01[2]; + + // a,b,c = coeffs in quadratic equation for lamda + + if (d_rmass.data()) { + invmass0 = 1.0/d_rmass[i0]; + invmass1 = 1.0/d_rmass[i1]; + } else { + invmass0 = 1.0/d_mass[d_type[i0]]; + invmass1 = 1.0/d_mass[d_type[i1]]; + } + + double a = (invmass0+invmass1)*(invmass0+invmass1) * r01sq; + double b = 2.0 * (invmass0+invmass1) * + (s01[0]*r01[0] + s01[1]*r01[1] + s01[2]*r01[2]); + double c = s01sq - bond1*bond1; + + // error check + + double determ = b*b - 4.0*a*c; + if (determ < 0.0) { + //error->warning(FLERR,"Shake determinant < 0.0",0); + d_error_flag() = 2; + determ = 0.0; + } + + // exact quadratic solution for lamda + + double lamda,lamda1,lamda2; + lamda1 = (-b+sqrt(determ)) / (2.0*a); + lamda2 = (-b-sqrt(determ)) / (2.0*a); + + if (fabs(lamda1) <= fabs(lamda2)) lamda = lamda1; + else lamda = lamda2; + + // update forces if atom is owned by this processor + + lamda /= dtfsq; + + if (i0 < nlocal) { + a_f(i0,0) += lamda*r01[0]; + a_f(i0,1) += lamda*r01[1]; + a_f(i0,2) += lamda*r01[2]; + } + + if (i1 < nlocal) { + a_f(i1,0) -= lamda*r01[0]; + a_f(i1,1) -= lamda*r01[1]; + a_f(i1,2) -= lamda*r01[2]; + } + + if (EVFLAG) { + nlist = 0; + if (i0 < nlocal) list[nlist++] = i0; + if (i1 < nlocal) list[nlist++] = i1; + + v[0] = lamda*r01[0]*r01[0]; + v[1] = lamda*r01[1]*r01[1]; + v[2] = lamda*r01[2]*r01[2]; + v[3] = lamda*r01[0]*r01[1]; + v[4] = lamda*r01[0]*r01[2]; + v[5] = lamda*r01[1]*r01[2]; + + v_tally(ev,nlist,list,2.0,v); + } +} + +/* ---------------------------------------------------------------------- */ + +template +template +KOKKOS_INLINE_FUNCTION +void FixShakeKokkos::shake3(int m, EV_FLOAT& ev) const +{ + + // The f array is duplicated for OpenMP, atomic for CUDA, and neither for Serial + + auto v_f = ScatterViewHelper::value,decltype(dup_f),decltype(ndup_f)>::get(dup_f,ndup_f); + auto a_f = v_f.template access::value>(); + + int nlist,list[3]; + double v[6]; + double invmass0,invmass1,invmass2; + + // local atom IDs and constraint distances + + int i0 = map_array(d_shake_atom(m,0)); + int i1 = map_array(d_shake_atom(m,1)); + int i2 = map_array(d_shake_atom(m,2)); + double bond1 = d_bond_distance[d_shake_type(m,0)]; + double bond2 = d_bond_distance[d_shake_type(m,1)]; + + // r01,r02 = distance vec between atoms, with PBC + + double r01[3]; + r01[0] = d_x(i0,0) - d_x(i1,0); + r01[1] = d_x(i0,1) - d_x(i1,1); + r01[2] = d_x(i0,2) - d_x(i1,2); + minimum_image(r01); + + double r02[3]; + r02[0] = d_x(i0,0) - d_x(i2,0); + r02[1] = d_x(i0,1) - d_x(i2,1); + r02[2] = d_x(i0,2) - d_x(i2,2); + minimum_image(r02); + + // s01,s02 = distance vec after unconstrained update, with PBC + // use Domain::minimum_image_once(), not minimum_image() + // b/c xshake values might be huge, due to e.g. fix gcmc + + double s01[3]; + s01[0] = d_xshake(i0,0) - d_xshake(i1,0); + s01[1] = d_xshake(i0,1) - d_xshake(i1,1); + s01[2] = d_xshake(i0,2) - d_xshake(i1,2); + minimum_image_once(s01); + + double s02[3]; + s02[0] = d_xshake(i0,0) - d_xshake(i2,0); + s02[1] = d_xshake(i0,1) - d_xshake(i2,1); + s02[2] = d_xshake(i0,2) - d_xshake(i2,2); + minimum_image_once(s02); + + // scalar distances between atoms + + double r01sq = r01[0]*r01[0] + r01[1]*r01[1] + r01[2]*r01[2]; + double r02sq = r02[0]*r02[0] + r02[1]*r02[1] + r02[2]*r02[2]; + double s01sq = s01[0]*s01[0] + s01[1]*s01[1] + s01[2]*s01[2]; + double s02sq = s02[0]*s02[0] + s02[1]*s02[1] + s02[2]*s02[2]; + + // matrix coeffs and rhs for lamda equations + + if (d_rmass.data()) { + invmass0 = 1.0/d_rmass[i0]; + invmass1 = 1.0/d_rmass[i1]; + invmass2 = 1.0/d_rmass[i2]; + } else { + invmass0 = 1.0/d_mass[d_type[i0]]; + invmass1 = 1.0/d_mass[d_type[i1]]; + invmass2 = 1.0/d_mass[d_type[i2]]; + } + + double a11 = 2.0 * (invmass0+invmass1) * + (s01[0]*r01[0] + s01[1]*r01[1] + s01[2]*r01[2]); + double a12 = 2.0 * invmass0 * + (s01[0]*r02[0] + s01[1]*r02[1] + s01[2]*r02[2]); + double a21 = 2.0 * invmass0 * + (s02[0]*r01[0] + s02[1]*r01[1] + s02[2]*r01[2]); + double a22 = 2.0 * (invmass0+invmass2) * + (s02[0]*r02[0] + s02[1]*r02[1] + s02[2]*r02[2]); + + // inverse of matrix + + double determ = a11*a22 - a12*a21; + if (determ == 0.0) d_error_flag() = 3; + //error->one(FLERR,"Shake determinant = 0.0"); + double determinv = 1.0/determ; + + double a11inv = a22*determinv; + double a12inv = -a12*determinv; + double a21inv = -a21*determinv; + double a22inv = a11*determinv; + + // quadratic correction coeffs + + double r0102 = (r01[0]*r02[0] + r01[1]*r02[1] + r01[2]*r02[2]); + + double quad1_0101 = (invmass0+invmass1)*(invmass0+invmass1) * r01sq; + double quad1_0202 = invmass0*invmass0 * r02sq; + double quad1_0102 = 2.0 * (invmass0+invmass1)*invmass0 * r0102; + + double quad2_0202 = (invmass0+invmass2)*(invmass0+invmass2) * r02sq; + double quad2_0101 = invmass0*invmass0 * r01sq; + double quad2_0102 = 2.0 * (invmass0+invmass2)*invmass0 * r0102; + + // iterate until converged + + double lamda01 = 0.0; + double lamda02 = 0.0; + int niter = 0; + int done = 0; + + double quad1,quad2,b1,b2,lamda01_new,lamda02_new; + + while (!done && niter < max_iter) { + quad1 = quad1_0101 * lamda01*lamda01 + quad1_0202 * lamda02*lamda02 + + quad1_0102 * lamda01*lamda02; + quad2 = quad2_0101 * lamda01*lamda01 + quad2_0202 * lamda02*lamda02 + + quad2_0102 * lamda01*lamda02; + + b1 = bond1*bond1 - s01sq - quad1; + b2 = bond2*bond2 - s02sq - quad2; + + lamda01_new = a11inv*b1 + a12inv*b2; + lamda02_new = a21inv*b1 + a22inv*b2; + + done = 1; + if (fabs(lamda01_new-lamda01) > tolerance) done = 0; + if (fabs(lamda02_new-lamda02) > tolerance) done = 0; + + lamda01 = lamda01_new; + lamda02 = lamda02_new; + + // stop iterations before we have a floating point overflow + // max double is < 1.0e308, so 1e150 is a reasonable cutoff + + if (fabs(lamda01) > 1e150 || fabs(lamda02) > 1e150) done = 1; + + niter++; + } + + // update forces if atom is owned by this processor + + lamda01 = lamda01/dtfsq; + lamda02 = lamda02/dtfsq; + + if (i0 < nlocal) { + a_f(i0,0) += lamda01*r01[0] + lamda02*r02[0]; + a_f(i0,1) += lamda01*r01[1] + lamda02*r02[1]; + a_f(i0,2) += lamda01*r01[2] + lamda02*r02[2]; + } + + if (i1 < nlocal) { + a_f(i1,0) -= lamda01*r01[0]; + a_f(i1,1) -= lamda01*r01[1]; + a_f(i1,2) -= lamda01*r01[2]; + } + + if (i2 < nlocal) { + a_f(i2,0) -= lamda02*r02[0]; + a_f(i2,1) -= lamda02*r02[1]; + a_f(i2,2) -= lamda02*r02[2]; + } + + if (EVFLAG) { + nlist = 0; + if (i0 < nlocal) list[nlist++] = i0; + if (i1 < nlocal) list[nlist++] = i1; + if (i2 < nlocal) list[nlist++] = i2; + + v[0] = lamda01*r01[0]*r01[0] + lamda02*r02[0]*r02[0]; + v[1] = lamda01*r01[1]*r01[1] + lamda02*r02[1]*r02[1]; + v[2] = lamda01*r01[2]*r01[2] + lamda02*r02[2]*r02[2]; + v[3] = lamda01*r01[0]*r01[1] + lamda02*r02[0]*r02[1]; + v[4] = lamda01*r01[0]*r01[2] + lamda02*r02[0]*r02[2]; + v[5] = lamda01*r01[1]*r01[2] + lamda02*r02[1]*r02[2]; + + v_tally(ev,nlist,list,3.0,v); + } +} + +/* ---------------------------------------------------------------------- */ + +template +template +KOKKOS_INLINE_FUNCTION +void FixShakeKokkos::shake4(int m, EV_FLOAT& ev) const +{ + + // The f array is duplicated for OpenMP, atomic for CUDA, and neither for Serial + + auto v_f = ScatterViewHelper::value,decltype(dup_f),decltype(ndup_f)>::get(dup_f,ndup_f); + auto a_f = v_f.template access::value>(); + + int nlist,list[4]; + double v[6]; + double invmass0,invmass1,invmass2,invmass3; + + // local atom IDs and constraint distances + + int i0 = map_array(d_shake_atom(m,0)); + int i1 = map_array(d_shake_atom(m,1)); + int i2 = map_array(d_shake_atom(m,2)); + int i3 = map_array(d_shake_atom(m,3)); + double bond1 = d_bond_distance[d_shake_type(m,0)]; + double bond2 = d_bond_distance[d_shake_type(m,1)]; + double bond3 = d_bond_distance[d_shake_type(m,2)]; + + // r01,r02,r03 = distance vec between atoms, with PBC + + double r01[3]; + r01[0] = d_x(i0,0) - d_x(i1,0); + r01[1] = d_x(i0,1) - d_x(i1,1); + r01[2] = d_x(i0,2) - d_x(i1,2); + minimum_image(r01); + + double r02[3]; + r02[0] = d_x(i0,0) - d_x(i2,0); + r02[1] = d_x(i0,1) - d_x(i2,1); + r02[2] = d_x(i0,2) - d_x(i2,2); + minimum_image(r02); + + double r03[3]; + r03[0] = d_x(i0,0) - d_x(i3,0); + r03[1] = d_x(i0,1) - d_x(i3,1); + r03[2] = d_x(i0,2) - d_x(i3,2); + minimum_image(r03); + + // s01,s02,s03 = distance vec after unconstrained update, with PBC + // use Domain::minimum_image_once(), not minimum_image() + // b/c xshake values might be huge, due to e.g. fix gcmc + + double s01[3]; + s01[0] = d_xshake(i0,0) - d_xshake(i1,0); + s01[1] = d_xshake(i0,1) - d_xshake(i1,1); + s01[2] = d_xshake(i0,2) - d_xshake(i1,2); + minimum_image_once(s01); + + double s02[3]; + s02[0] = d_xshake(i0,0) - d_xshake(i2,0); + s02[1] = d_xshake(i0,1) - d_xshake(i2,1); + s02[2] = d_xshake(i0,2) - d_xshake(i2,2); + minimum_image_once(s02); + + double s03[3]; + s03[0] = d_xshake(i0,0) - d_xshake(i3,0); + s03[1] = d_xshake(i0,1) - d_xshake(i3,1); + s03[2] = d_xshake(i0,2) - d_xshake(i3,2); + minimum_image_once(s03); + + // scalar distances between atoms + + double r01sq = r01[0]*r01[0] + r01[1]*r01[1] + r01[2]*r01[2]; + double r02sq = r02[0]*r02[0] + r02[1]*r02[1] + r02[2]*r02[2]; + double r03sq = r03[0]*r03[0] + r03[1]*r03[1] + r03[2]*r03[2]; + double s01sq = s01[0]*s01[0] + s01[1]*s01[1] + s01[2]*s01[2]; + double s02sq = s02[0]*s02[0] + s02[1]*s02[1] + s02[2]*s02[2]; + double s03sq = s03[0]*s03[0] + s03[1]*s03[1] + s03[2]*s03[2]; + + // matrix coeffs and rhs for lamda equations + + if (d_rmass.data()) { + invmass0 = 1.0/d_rmass[i0]; + invmass1 = 1.0/d_rmass[i1]; + invmass2 = 1.0/d_rmass[i2]; + invmass3 = 1.0/d_rmass[i3]; + } else { + invmass0 = 1.0/d_mass[d_type[i0]]; + invmass1 = 1.0/d_mass[d_type[i1]]; + invmass2 = 1.0/d_mass[d_type[i2]]; + invmass3 = 1.0/d_mass[d_type[i3]]; + } + + double a11 = 2.0 * (invmass0+invmass1) * + (s01[0]*r01[0] + s01[1]*r01[1] + s01[2]*r01[2]); + double a12 = 2.0 * invmass0 * + (s01[0]*r02[0] + s01[1]*r02[1] + s01[2]*r02[2]); + double a13 = 2.0 * invmass0 * + (s01[0]*r03[0] + s01[1]*r03[1] + s01[2]*r03[2]); + double a21 = 2.0 * invmass0 * + (s02[0]*r01[0] + s02[1]*r01[1] + s02[2]*r01[2]); + double a22 = 2.0 * (invmass0+invmass2) * + (s02[0]*r02[0] + s02[1]*r02[1] + s02[2]*r02[2]); + double a23 = 2.0 * invmass0 * + (s02[0]*r03[0] + s02[1]*r03[1] + s02[2]*r03[2]); + double a31 = 2.0 * invmass0 * + (s03[0]*r01[0] + s03[1]*r01[1] + s03[2]*r01[2]); + double a32 = 2.0 * invmass0 * + (s03[0]*r02[0] + s03[1]*r02[1] + s03[2]*r02[2]); + double a33 = 2.0 * (invmass0+invmass3) * + (s03[0]*r03[0] + s03[1]*r03[1] + s03[2]*r03[2]); + + // inverse of matrix; + + double determ = a11*a22*a33 + a12*a23*a31 + a13*a21*a32 - + a11*a23*a32 - a12*a21*a33 - a13*a22*a31; + if (determ == 0.0) d_error_flag() = 3; + //error->one(FLERR,"Shake determinant = 0.0"); + double determinv = 1.0/determ; + + double a11inv = determinv * (a22*a33 - a23*a32); + double a12inv = -determinv * (a12*a33 - a13*a32); + double a13inv = determinv * (a12*a23 - a13*a22); + double a21inv = -determinv * (a21*a33 - a23*a31); + double a22inv = determinv * (a11*a33 - a13*a31); + double a23inv = -determinv * (a11*a23 - a13*a21); + double a31inv = determinv * (a21*a32 - a22*a31); + double a32inv = -determinv * (a11*a32 - a12*a31); + double a33inv = determinv * (a11*a22 - a12*a21); + + // quadratic correction coeffs + + double r0102 = (r01[0]*r02[0] + r01[1]*r02[1] + r01[2]*r02[2]); + double r0103 = (r01[0]*r03[0] + r01[1]*r03[1] + r01[2]*r03[2]); + double r0203 = (r02[0]*r03[0] + r02[1]*r03[1] + r02[2]*r03[2]); + + double quad1_0101 = (invmass0+invmass1)*(invmass0+invmass1) * r01sq; + double quad1_0202 = invmass0*invmass0 * r02sq; + double quad1_0303 = invmass0*invmass0 * r03sq; + double quad1_0102 = 2.0 * (invmass0+invmass1)*invmass0 * r0102; + double quad1_0103 = 2.0 * (invmass0+invmass1)*invmass0 * r0103; + double quad1_0203 = 2.0 * invmass0*invmass0 * r0203; + + double quad2_0101 = invmass0*invmass0 * r01sq; + double quad2_0202 = (invmass0+invmass2)*(invmass0+invmass2) * r02sq; + double quad2_0303 = invmass0*invmass0 * r03sq; + double quad2_0102 = 2.0 * (invmass0+invmass2)*invmass0 * r0102; + double quad2_0103 = 2.0 * invmass0*invmass0 * r0103; + double quad2_0203 = 2.0 * (invmass0+invmass2)*invmass0 * r0203; + + double quad3_0101 = invmass0*invmass0 * r01sq; + double quad3_0202 = invmass0*invmass0 * r02sq; + double quad3_0303 = (invmass0+invmass3)*(invmass0+invmass3) * r03sq; + double quad3_0102 = 2.0 * invmass0*invmass0 * r0102; + double quad3_0103 = 2.0 * (invmass0+invmass3)*invmass0 * r0103; + double quad3_0203 = 2.0 * (invmass0+invmass3)*invmass0 * r0203; + + // iterate until converged + + double lamda01 = 0.0; + double lamda02 = 0.0; + double lamda03 = 0.0; + int niter = 0; + int done = 0; + + double quad1,quad2,quad3,b1,b2,b3,lamda01_new,lamda02_new,lamda03_new; + + while (!done && niter < max_iter) { + quad1 = quad1_0101 * lamda01*lamda01 + + quad1_0202 * lamda02*lamda02 + + quad1_0303 * lamda03*lamda03 + + quad1_0102 * lamda01*lamda02 + + quad1_0103 * lamda01*lamda03 + + quad1_0203 * lamda02*lamda03; + + quad2 = quad2_0101 * lamda01*lamda01 + + quad2_0202 * lamda02*lamda02 + + quad2_0303 * lamda03*lamda03 + + quad2_0102 * lamda01*lamda02 + + quad2_0103 * lamda01*lamda03 + + quad2_0203 * lamda02*lamda03; + + quad3 = quad3_0101 * lamda01*lamda01 + + quad3_0202 * lamda02*lamda02 + + quad3_0303 * lamda03*lamda03 + + quad3_0102 * lamda01*lamda02 + + quad3_0103 * lamda01*lamda03 + + quad3_0203 * lamda02*lamda03; + + b1 = bond1*bond1 - s01sq - quad1; + b2 = bond2*bond2 - s02sq - quad2; + b3 = bond3*bond3 - s03sq - quad3; + + lamda01_new = a11inv*b1 + a12inv*b2 + a13inv*b3; + lamda02_new = a21inv*b1 + a22inv*b2 + a23inv*b3; + lamda03_new = a31inv*b1 + a32inv*b2 + a33inv*b3; + + done = 1; + if (fabs(lamda01_new-lamda01) > tolerance) done = 0; + if (fabs(lamda02_new-lamda02) > tolerance) done = 0; + if (fabs(lamda03_new-lamda03) > tolerance) done = 0; + + lamda01 = lamda01_new; + lamda02 = lamda02_new; + lamda03 = lamda03_new; + + // stop iterations before we have a floating point overflow + // max double is < 1.0e308, so 1e150 is a reasonable cutoff + + if (fabs(lamda01) > 1e150 || fabs(lamda02) > 1e150 + || fabs(lamda03) > 1e150) done = 1; + + niter++; + } + + // update forces if atom is owned by this processor + + lamda01 = lamda01/dtfsq; + lamda02 = lamda02/dtfsq; + lamda03 = lamda03/dtfsq; + + if (i0 < nlocal) { + a_f(i0,0) += lamda01*r01[0] + lamda02*r02[0] + lamda03*r03[0]; + a_f(i0,1) += lamda01*r01[1] + lamda02*r02[1] + lamda03*r03[1]; + a_f(i0,2) += lamda01*r01[2] + lamda02*r02[2] + lamda03*r03[2]; + } + + if (i1 < nlocal) { + a_f(i1,0) -= lamda01*r01[0]; + a_f(i1,1) -= lamda01*r01[1]; + a_f(i1,2) -= lamda01*r01[2]; + } + + if (i2 < nlocal) { + a_f(i2,0) -= lamda02*r02[0]; + a_f(i2,1) -= lamda02*r02[1]; + a_f(i2,2) -= lamda02*r02[2]; + } + + if (i3 < nlocal) { + a_f(i3,0) -= lamda03*r03[0]; + a_f(i3,1) -= lamda03*r03[1]; + a_f(i3,2) -= lamda03*r03[2]; + } + + if (EVFLAG) { + nlist = 0; + if (i0 < nlocal) list[nlist++] = i0; + if (i1 < nlocal) list[nlist++] = i1; + if (i2 < nlocal) list[nlist++] = i2; + if (i3 < nlocal) list[nlist++] = i3; + + v[0] = lamda01*r01[0]*r01[0]+lamda02*r02[0]*r02[0]+lamda03*r03[0]*r03[0]; + v[1] = lamda01*r01[1]*r01[1]+lamda02*r02[1]*r02[1]+lamda03*r03[1]*r03[1]; + v[2] = lamda01*r01[2]*r01[2]+lamda02*r02[2]*r02[2]+lamda03*r03[2]*r03[2]; + v[3] = lamda01*r01[0]*r01[1]+lamda02*r02[0]*r02[1]+lamda03*r03[0]*r03[1]; + v[4] = lamda01*r01[0]*r01[2]+lamda02*r02[0]*r02[2]+lamda03*r03[0]*r03[2]; + v[5] = lamda01*r01[1]*r01[2]+lamda02*r02[1]*r02[2]+lamda03*r03[1]*r03[2]; + + v_tally(ev,nlist,list,4.0,v); + } +} + +/* ---------------------------------------------------------------------- */ + +template +template +KOKKOS_INLINE_FUNCTION +void FixShakeKokkos::shake3angle(int m, EV_FLOAT& ev) const +{ + + // The f array is duplicated for OpenMP, atomic for CUDA, and neither for Serial + + auto v_f = ScatterViewHelper::value,decltype(dup_f),decltype(ndup_f)>::get(dup_f,ndup_f); + auto a_f = v_f.template access::value>(); + + int nlist,list[3]; + double v[6]; + double invmass0,invmass1,invmass2; + + // local atom IDs and constraint distances + + int i0 = map_array(d_shake_atom(m,0)); + int i1 = map_array(d_shake_atom(m,1)); + int i2 = map_array(d_shake_atom(m,2)); + double bond1 = d_bond_distance[d_shake_type(m,0)]; + double bond2 = d_bond_distance[d_shake_type(m,1)]; + double bond12 = d_angle_distance[d_shake_type(m,2)]; + + // r01,r02,r12 = distance vec between atoms, with PBC + + double r01[3]; + r01[0] = d_x(i0,0) - d_x(i1,0); + r01[1] = d_x(i0,1) - d_x(i1,1); + r01[2] = d_x(i0,2) - d_x(i1,2); + minimum_image(r01); + + double r02[3]; + r02[0] = d_x(i0,0) - d_x(i2,0); + r02[1] = d_x(i0,1) - d_x(i2,1); + r02[2] = d_x(i0,2) - d_x(i2,2); + minimum_image(r02); + + double r12[3]; + r12[0] = d_x(i1,0) - d_x(i2,0); + r12[1] = d_x(i1,1) - d_x(i2,1); + r12[2] = d_x(i1,2) - d_x(i2,2); + minimum_image(r12); + + // s01,s02,s12 = distance vec after unconstrained update, with PBC + // use Domain::minimum_image_once(), not minimum_image() + // b/c xshake values might be huge, due to e.g. fix gcmc + + double s01[3]; + s01[0] = d_xshake(i0,0) - d_xshake(i1,0); + s01[1] = d_xshake(i0,1) - d_xshake(i1,1); + s01[2] = d_xshake(i0,2) - d_xshake(i1,2); + minimum_image_once(s01); + + double s02[3]; + s02[0] = d_xshake(i0,0) - d_xshake(i2,0); + s02[1] = d_xshake(i0,1) - d_xshake(i2,1); + s02[2] = d_xshake(i0,2) - d_xshake(i2,2); + minimum_image_once(s02); + + double s12[3]; + s12[0] = d_xshake(i1,0) - d_xshake(i2,0); + s12[1] = d_xshake(i1,1) - d_xshake(i2,1); + s12[2] = d_xshake(i1,2) - d_xshake(i2,2); + minimum_image_once(s12); + + // scalar distances between atoms + + double r01sq = r01[0]*r01[0] + r01[1]*r01[1] + r01[2]*r01[2]; + double r02sq = r02[0]*r02[0] + r02[1]*r02[1] + r02[2]*r02[2]; + double r12sq = r12[0]*r12[0] + r12[1]*r12[1] + r12[2]*r12[2]; + double s01sq = s01[0]*s01[0] + s01[1]*s01[1] + s01[2]*s01[2]; + double s02sq = s02[0]*s02[0] + s02[1]*s02[1] + s02[2]*s02[2]; + double s12sq = s12[0]*s12[0] + s12[1]*s12[1] + s12[2]*s12[2]; + + // matrix coeffs and rhs for lamda equations + + if (d_rmass.data()) { + invmass0 = 1.0/d_rmass[i0]; + invmass1 = 1.0/d_rmass[i1]; + invmass2 = 1.0/d_rmass[i2]; + } else { + invmass0 = 1.0/d_mass[d_type[i0]]; + invmass1 = 1.0/d_mass[d_type[i1]]; + invmass2 = 1.0/d_mass[d_type[i2]]; + } + + double a11 = 2.0 * (invmass0+invmass1) * + (s01[0]*r01[0] + s01[1]*r01[1] + s01[2]*r01[2]); + double a12 = 2.0 * invmass0 * + (s01[0]*r02[0] + s01[1]*r02[1] + s01[2]*r02[2]); + double a13 = - 2.0 * invmass1 * + (s01[0]*r12[0] + s01[1]*r12[1] + s01[2]*r12[2]); + double a21 = 2.0 * invmass0 * + (s02[0]*r01[0] + s02[1]*r01[1] + s02[2]*r01[2]); + double a22 = 2.0 * (invmass0+invmass2) * + (s02[0]*r02[0] + s02[1]*r02[1] + s02[2]*r02[2]); + double a23 = 2.0 * invmass2 * + (s02[0]*r12[0] + s02[1]*r12[1] + s02[2]*r12[2]); + double a31 = - 2.0 * invmass1 * + (s12[0]*r01[0] + s12[1]*r01[1] + s12[2]*r01[2]); + double a32 = 2.0 * invmass2 * + (s12[0]*r02[0] + s12[1]*r02[1] + s12[2]*r02[2]); + double a33 = 2.0 * (invmass1+invmass2) * + (s12[0]*r12[0] + s12[1]*r12[1] + s12[2]*r12[2]); + + // inverse of matrix + + double determ = a11*a22*a33 + a12*a23*a31 + a13*a21*a32 - + a11*a23*a32 - a12*a21*a33 - a13*a22*a31; + if (determ == 0.0) d_error_flag() = 3; + //error->one(FLERR,"Shake determinant = 0.0"); + double determinv = 1.0/determ; + + double a11inv = determinv * (a22*a33 - a23*a32); + double a12inv = -determinv * (a12*a33 - a13*a32); + double a13inv = determinv * (a12*a23 - a13*a22); + double a21inv = -determinv * (a21*a33 - a23*a31); + double a22inv = determinv * (a11*a33 - a13*a31); + double a23inv = -determinv * (a11*a23 - a13*a21); + double a31inv = determinv * (a21*a32 - a22*a31); + double a32inv = -determinv * (a11*a32 - a12*a31); + double a33inv = determinv * (a11*a22 - a12*a21); + + // quadratic correction coeffs + + double r0102 = (r01[0]*r02[0] + r01[1]*r02[1] + r01[2]*r02[2]); + double r0112 = (r01[0]*r12[0] + r01[1]*r12[1] + r01[2]*r12[2]); + double r0212 = (r02[0]*r12[0] + r02[1]*r12[1] + r02[2]*r12[2]); + + double quad1_0101 = (invmass0+invmass1)*(invmass0+invmass1) * r01sq; + double quad1_0202 = invmass0*invmass0 * r02sq; + double quad1_1212 = invmass1*invmass1 * r12sq; + double quad1_0102 = 2.0 * (invmass0+invmass1)*invmass0 * r0102; + double quad1_0112 = - 2.0 * (invmass0+invmass1)*invmass1 * r0112; + double quad1_0212 = - 2.0 * invmass0*invmass1 * r0212; + + double quad2_0101 = invmass0*invmass0 * r01sq; + double quad2_0202 = (invmass0+invmass2)*(invmass0+invmass2) * r02sq; + double quad2_1212 = invmass2*invmass2 * r12sq; + double quad2_0102 = 2.0 * (invmass0+invmass2)*invmass0 * r0102; + double quad2_0112 = 2.0 * invmass0*invmass2 * r0112; + double quad2_0212 = 2.0 * (invmass0+invmass2)*invmass2 * r0212; + + double quad3_0101 = invmass1*invmass1 * r01sq; + double quad3_0202 = invmass2*invmass2 * r02sq; + double quad3_1212 = (invmass1+invmass2)*(invmass1+invmass2) * r12sq; + double quad3_0102 = - 2.0 * invmass1*invmass2 * r0102; + double quad3_0112 = - 2.0 * (invmass1+invmass2)*invmass1 * r0112; + double quad3_0212 = 2.0 * (invmass1+invmass2)*invmass2 * r0212; + + // iterate until converged + + double lamda01 = 0.0; + double lamda02 = 0.0; + double lamda12 = 0.0; + int niter = 0; + int done = 0; + + double quad1,quad2,quad3,b1,b2,b3,lamda01_new,lamda02_new,lamda12_new; + + while (!done && niter < max_iter) { + + quad1 = quad1_0101 * lamda01*lamda01 + + quad1_0202 * lamda02*lamda02 + + quad1_1212 * lamda12*lamda12 + + quad1_0102 * lamda01*lamda02 + + quad1_0112 * lamda01*lamda12 + + quad1_0212 * lamda02*lamda12; + + quad2 = quad2_0101 * lamda01*lamda01 + + quad2_0202 * lamda02*lamda02 + + quad2_1212 * lamda12*lamda12 + + quad2_0102 * lamda01*lamda02 + + quad2_0112 * lamda01*lamda12 + + quad2_0212 * lamda02*lamda12; + + quad3 = quad3_0101 * lamda01*lamda01 + + quad3_0202 * lamda02*lamda02 + + quad3_1212 * lamda12*lamda12 + + quad3_0102 * lamda01*lamda02 + + quad3_0112 * lamda01*lamda12 + + quad3_0212 * lamda02*lamda12; + + b1 = bond1*bond1 - s01sq - quad1; + b2 = bond2*bond2 - s02sq - quad2; + b3 = bond12*bond12 - s12sq - quad3; + + lamda01_new = a11inv*b1 + a12inv*b2 + a13inv*b3; + lamda02_new = a21inv*b1 + a22inv*b2 + a23inv*b3; + lamda12_new = a31inv*b1 + a32inv*b2 + a33inv*b3; + + done = 1; + if (fabs(lamda01_new-lamda01) > tolerance) done = 0; + if (fabs(lamda02_new-lamda02) > tolerance) done = 0; + if (fabs(lamda12_new-lamda12) > tolerance) done = 0; + + lamda01 = lamda01_new; + lamda02 = lamda02_new; + lamda12 = lamda12_new; + + // stop iterations before we have a floating point overflow + // max double is < 1.0e308, so 1e150 is a reasonable cutoff + + if (fabs(lamda01) > 1e150 || fabs(lamda02) > 1e150 + || fabs(lamda12) > 1e150) done = 1; + + niter++; + } + + // update forces if atom is owned by this processor + + lamda01 = lamda01/dtfsq; + lamda02 = lamda02/dtfsq; + lamda12 = lamda12/dtfsq; + + if (i0 < nlocal) { + a_f(i0,0) += lamda01*r01[0] + lamda02*r02[0]; + a_f(i0,1) += lamda01*r01[1] + lamda02*r02[1]; + a_f(i0,2) += lamda01*r01[2] + lamda02*r02[2]; + } + + if (i1 < nlocal) { + a_f(i1,0) -= lamda01*r01[0] - lamda12*r12[0]; + a_f(i1,1) -= lamda01*r01[1] - lamda12*r12[1]; + a_f(i1,2) -= lamda01*r01[2] - lamda12*r12[2]; + } + + if (i2 < nlocal) { + a_f(i2,0) -= lamda02*r02[0] + lamda12*r12[0]; + a_f(i2,1) -= lamda02*r02[1] + lamda12*r12[1]; + a_f(i2,2) -= lamda02*r02[2] + lamda12*r12[2]; + } + + if (EVFLAG) { + nlist = 0; + if (i0 < nlocal) list[nlist++] = i0; + if (i1 < nlocal) list[nlist++] = i1; + if (i2 < nlocal) list[nlist++] = i2; + + v[0] = lamda01*r01[0]*r01[0]+lamda02*r02[0]*r02[0]+lamda12*r12[0]*r12[0]; + v[1] = lamda01*r01[1]*r01[1]+lamda02*r02[1]*r02[1]+lamda12*r12[1]*r12[1]; + v[2] = lamda01*r01[2]*r01[2]+lamda02*r02[2]*r02[2]+lamda12*r12[2]*r12[2]; + v[3] = lamda01*r01[0]*r01[1]+lamda02*r02[0]*r02[1]+lamda12*r12[0]*r12[1]; + v[4] = lamda01*r01[0]*r01[2]+lamda02*r02[0]*r02[2]+lamda12*r12[0]*r12[2]; + v[5] = lamda01*r01[1]*r01[2]+lamda02*r02[1]*r02[2]+lamda12*r12[1]*r12[2]; + + v_tally(ev,nlist,list,3.0,v); + } +} + +/* ---------------------------------------------------------------------- + allocate local atom-based arrays +------------------------------------------------------------------------- */ + +template +void FixShakeKokkos::grow_arrays(int nmax) +{ + memoryKK->grow_kokkos(k_shake_flag,shake_flag,nmax,"shake:shake_flag"); + memoryKK->grow_kokkos(k_shake_atom,shake_atom,nmax,4,"shake:shake_atom"); + memoryKK->grow_kokkos(k_shake_type,shake_type,nmax,3,"shake:shake_type"); + memoryKK->destroy_kokkos(k_xshake,xshake); + memoryKK->create_kokkos(k_xshake,xshake,nmax,"shake:xshake"); + + d_shake_flag = k_shake_flag.view(); + d_shake_atom = k_shake_atom.view(); + d_shake_type = k_shake_type.view(); + d_xshake = k_xshake.view(); + + memory->destroy(ftmp); + memory->create(ftmp,nmax,3,"shake:ftmp"); + memory->destroy(vtmp); + memory->create(vtmp,nmax,3,"shake:vtmp"); +} + +/* ---------------------------------------------------------------------- + copy values within local atom-based arrays +------------------------------------------------------------------------- */ + +template +void FixShakeKokkos::copy_arrays(int i, int j, int delflag) +{ + k_shake_flag.sync_host(); + k_shake_atom.sync_host(); + k_shake_type.sync_host(); + + FixShake::copy_arrays(i,j,delflag); + + k_shake_flag.modify_host(); + k_shake_atom.modify_host(); + k_shake_type.modify_host(); +} + +/* ---------------------------------------------------------------------- + initialize one atom's array values, called when atom is created +------------------------------------------------------------------------- */ + +template +void FixShakeKokkos::set_arrays(int i) +{ + k_shake_flag.sync_host(); + + shake_flag[i] = 0; + + k_shake_flag.modify_host(); +} + +/* ---------------------------------------------------------------------- + update one atom's array values + called when molecule is created from fix gcmc +------------------------------------------------------------------------- */ + +template +void FixShakeKokkos::update_arrays(int i, int atom_offset) +{ + k_shake_flag.sync_host(); + k_shake_atom.sync_host(); + + FixShake::update_arrays(i,atom_offset); + + k_shake_flag.modify_host(); + k_shake_atom.modify_host(); +} + +/* ---------------------------------------------------------------------- + pack values in local atom-based arrays for exchange with another proc +------------------------------------------------------------------------- */ + +template +int FixShakeKokkos::pack_exchange(int i, double *buf) +{ + k_shake_flag.sync_host(); + k_shake_atom.sync_host(); + k_shake_type.sync_host(); + + int m = FixShake::pack_exchange(i,buf); + + k_shake_flag.modify_host(); + k_shake_atom.modify_host(); + k_shake_type.modify_host(); + + return m; +} + +/* ---------------------------------------------------------------------- + unpack values in local atom-based arrays from exchange with another proc +------------------------------------------------------------------------- */ + +template +int FixShakeKokkos::unpack_exchange(int nlocal, double *buf) +{ + k_shake_flag.sync_host(); + k_shake_atom.sync_host(); + k_shake_type.sync_host(); + + int m = FixShake::unpack_exchange(nlocal,buf); + + k_shake_flag.modify_host(); + k_shake_atom.modify_host(); + k_shake_type.modify_host(); + + return m; +} + +/* ---------------------------------------------------------------------- */ + +template +int FixShakeKokkos::pack_forward_comm_fix_kokkos(int n, DAT::tdual_int_2d k_sendlist, + int iswap_in, DAT::tdual_xfloat_1d &k_buf, + int pbc_flag, int* pbc) +{ + d_sendlist = k_sendlist.view(); + iswap = iswap_in; + d_buf = k_buf.view(); + + if (domain->triclinic == 0) { + dx = pbc[0]*domain->xprd; + dy = pbc[1]*domain->yprd; + dz = pbc[2]*domain->zprd; + } else { + dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; + dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; + dz = pbc[2]*domain->zprd; + } + + if (pbc_flag) + Kokkos::parallel_for(Kokkos::RangePolicy >(0,n),*this); + else + Kokkos::parallel_for(Kokkos::RangePolicy >(0,n),*this); + return n*3; +} + +template +template +KOKKOS_INLINE_FUNCTION +void FixShakeKokkos::operator()(TagFixShakePackForwardComm, const int &i) const { + const int j = d_sendlist(iswap, i); + + if (PBC_FLAG == 0) { + d_buf[3*i] = d_xshake(j,0); + d_buf[3*i+1] = d_xshake(j,1); + d_buf[3*i+2] = d_xshake(j,2); + } else { + d_buf[3*i] = d_xshake(j,0) + dx; + d_buf[3*i+1] = d_xshake(j,1) + dy; + d_buf[3*i+2] = d_xshake(j,2) + dz; + } +} + +/* ---------------------------------------------------------------------- */ + +template +int FixShakeKokkos::pack_forward_comm(int n, int *list, double *buf, + int pbc_flag, int *pbc) +{ + k_xshake.sync_host(); + + int m = FixShake::pack_forward_comm(n,list,buf,pbc_flag,pbc); + + k_xshake.modify_host(); + + return m; +} + +/* ---------------------------------------------------------------------- */ + +template +void FixShakeKokkos::unpack_forward_comm_fix_kokkos(int n, int first_in, DAT::tdual_xfloat_1d &buf) +{ + first = first_in; + d_buf = buf.view(); + Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); +} + +template +KOKKOS_INLINE_FUNCTION +void FixShakeKokkos::operator()(TagFixShakeUnpackForwardComm, const int &i) const { + d_xshake(i + first,0) = d_buf[3*i]; + d_xshake(i + first,1) = d_buf[3*i+1]; + d_xshake(i + first,2) = d_buf[3*i+2]; +} + +/* ---------------------------------------------------------------------- */ + +template +void FixShakeKokkos::unpack_forward_comm(int n, int first, double *buf) +{ + k_xshake.sync_host(); + + FixShake::unpack_forward_comm(n,first,buf); + + k_xshake.modify_host(); +} + +/* ---------------------------------------------------------------------- + add coordinate constraining forces + this method is called at the end of a timestep +------------------------------------------------------------------------- */ + +template +void FixShakeKokkos::shake_end_of_step(int vflag) { + dtv = update->dt; + dtfsq = 0.5 * update->dt * update->dt * force->ftm2v; + FixShakeKokkos::post_force(vflag); + if (!rattle) dtfsq = update->dt * update->dt * force->ftm2v; +} + +/* ---------------------------------------------------------------------- + calculate constraining forces based on the current configuration + change coordinates +------------------------------------------------------------------------- */ + +template +void FixShakeKokkos::correct_coordinates(int vflag) { + atomKK->sync(Host,X_MASK|V_MASK|F_MASK); + + // save current forces and velocities so that you + // initialize them to zero such that FixShake::unconstrained_coordinate_update has no effect + + for (int j=0; jmodified(Host,V_MASK|F_MASK); + + // call SHAKE to correct the coordinates which were updated without constraints + // IMPORTANT: use 1 as argument and thereby enforce velocity Verlet + + dtfsq = 0.5 * update->dt * update->dt * force->ftm2v; + FixShakeKokkos::post_force(vflag); + + atomKK->sync(Host,X_MASK|F_MASK); + + // integrate coordinates: x' = xnp1 + dt^2/2m_i * f, where f is the constraining force + // NOTE: After this command, the coordinates geometry of the molecules will be correct! + + double dtfmsq; + if (rmass) { + for (int i = 0; i < nlocal; i++) { + dtfmsq = dtfsq/ rmass[i]; + x[i][0] = x[i][0] + dtfmsq*f[i][0]; + x[i][1] = x[i][1] + dtfmsq*f[i][1]; + x[i][2] = x[i][2] + dtfmsq*f[i][2]; + } + } + else { + for (int i = 0; i < nlocal; i++) { + dtfmsq = dtfsq / mass[type[i]]; + x[i][0] = x[i][0] + dtfmsq*f[i][0]; + x[i][1] = x[i][1] + dtfmsq*f[i][1]; + x[i][2] = x[i][2] + dtfmsq*f[i][2]; + } + } + + // copy forces and velocities back + + for (int j=0; jdt * update->dt * force->ftm2v; + + // communicate changes + // NOTE: for compatibility xshake is temporarily set to x, such that pack/unpack_forward + // can be used for communicating the coordinates. + + double **xtmp = xshake; + xshake = x; + if (nprocs > 1) { + forward_comm_device = 0; + comm->forward_comm_fix(this); + forward_comm_device = 1; + } + xshake = xtmp; + + atomKK->modified(Host,X_MASK|V_MASK|F_MASK); +} + +/* ---------------------------------------------------------------------- + tally virial into global and per-atom accumulators + n = # of local owned atoms involved, with local indices in list + v = total virial for the interaction involving total atoms + increment global virial by n/total fraction + increment per-atom virial of each atom in list by 1/total fraction + this method can be used when fix computes forces in post_force() + e.g. fix shake, fix rigid: compute virial only on owned atoms + whether newton_bond is on or off + other procs will tally left-over fractions for atoms they own +------------------------------------------------------------------------- */ +template +template +KOKKOS_INLINE_FUNCTION +void FixShakeKokkos::v_tally(EV_FLOAT &ev, int n, int *list, double total, + double *v) const +{ + int m; + + if (vflag_global) { + double fraction = n/total; + ev.v[0] += fraction*v[0]; + ev.v[1] += fraction*v[1]; + ev.v[2] += fraction*v[2]; + ev.v[3] += fraction*v[3]; + ev.v[4] += fraction*v[4]; + ev.v[5] += fraction*v[5]; + } + + if (vflag_atom) { + double fraction = 1.0/total; + for (int i = 0; i < n; i++) { + auto v_vatom = ScatterViewHelper::value,decltype(dup_vatom),decltype(ndup_vatom)>::get(dup_vatom,ndup_vatom); + auto a_vatom = v_vatom.template access::value>(); + m = list[i]; + a_vatom(m,0) += fraction*v[0]; + a_vatom(m,1) += fraction*v[1]; + a_vatom(m,2) += fraction*v[2]; + a_vatom(m,3) += fraction*v[3]; + a_vatom(m,4) += fraction*v[4]; + a_vatom(m,5) += fraction*v[5]; + } + } +} + +/* ---------------------------------------------------------------------- */ + +template +void FixShakeKokkos::update_domain_variables() +{ + triclinic = domain->triclinic; + xperiodic = domain->xperiodic; + xprd_half = domain->xprd_half; + xprd = domain->xprd; + yperiodic = domain->yperiodic; + yprd_half = domain->yprd_half; + yprd = domain->yprd; + zperiodic = domain->zperiodic; + zprd_half = domain->zprd_half; + zprd = domain->zprd; + xy = domain->xy; + xz = domain->xz; + yz = domain->yz; +} + +/* ---------------------------------------------------------------------- + minimum image convention in periodic dimensions + use 1/2 of box size as test + for triclinic, also add/subtract tilt factors in other dims as needed + changed "if" to "while" to enable distance to + far-away ghost atom returned by atom->map() to be wrapped back into box + could be problem for looking up atom IDs when cutoff > boxsize + this should not be used if atom has moved infinitely far outside box + b/c while could iterate forever + e.g. fix shake prediction of new position with highly overlapped atoms + use minimum_image_once() instead + copied from domain.cpp +------------------------------------------------------------------------- */ + +template +KOKKOS_INLINE_FUNCTION +void FixShakeKokkos::minimum_image(double *delta) const +{ + if (triclinic == 0) { + if (xperiodic) { + while (fabs(delta[0]) > xprd_half) { + if (delta[0] < 0.0) delta[0] += xprd; + else delta[0] -= xprd; + } + } + if (yperiodic) { + while (fabs(delta[1]) > yprd_half) { + if (delta[1] < 0.0) delta[1] += yprd; + else delta[1] -= yprd; + } + } + if (zperiodic) { + while (fabs(delta[2]) > zprd_half) { + if (delta[2] < 0.0) delta[2] += zprd; + else delta[2] -= zprd; + } + } + + } else { + if (zperiodic) { + while (fabs(delta[2]) > zprd_half) { + if (delta[2] < 0.0) { + delta[2] += zprd; + delta[1] += yz; + delta[0] += xz; + } else { + delta[2] -= zprd; + delta[1] -= yz; + delta[0] -= xz; + } + } + } + if (yperiodic) { + while (fabs(delta[1]) > yprd_half) { + if (delta[1] < 0.0) { + delta[1] += yprd; + delta[0] += xy; + } else { + delta[1] -= yprd; + delta[0] -= xy; + } + } + } + if (xperiodic) { + while (fabs(delta[0]) > xprd_half) { + if (delta[0] < 0.0) delta[0] += xprd; + else delta[0] -= xprd; + } + } + } +} + +/* ---------------------------------------------------------------------- + minimum image convention in periodic dimensions + use 1/2 of box size as test + for triclinic, also add/subtract tilt factors in other dims as needed + only shift by one box length in each direction + this should not be used if multiple box shifts are required + copied from domain.cpp +------------------------------------------------------------------------- */ + +template +KOKKOS_INLINE_FUNCTION +void FixShakeKokkos::minimum_image_once(double *delta) const +{ + if (triclinic == 0) { + if (xperiodic) { + if (fabs(delta[0]) > xprd_half) { + if (delta[0] < 0.0) delta[0] += xprd; + else delta[0] -= xprd; + } + } + if (yperiodic) { + if (fabs(delta[1]) > yprd_half) { + if (delta[1] < 0.0) delta[1] += yprd; + else delta[1] -= yprd; + } + } + if (zperiodic) { + if (fabs(delta[2]) > zprd_half) { + if (delta[2] < 0.0) delta[2] += zprd; + else delta[2] -= zprd; + } + } + + } else { + if (zperiodic) { + if (fabs(delta[2]) > zprd_half) { + if (delta[2] < 0.0) { + delta[2] += zprd; + delta[1] += yz; + delta[0] += xz; + } else { + delta[2] -= zprd; + delta[1] -= yz; + delta[0] -= xz; + } + } + } + if (yperiodic) { + if (fabs(delta[1]) > yprd_half) { + if (delta[1] < 0.0) { + delta[1] += yprd; + delta[0] += xy; + } else { + delta[1] -= yprd; + delta[0] -= xy; + } + } + } + if (xperiodic) { + if (fabs(delta[0]) > xprd_half) { + if (delta[0] < 0.0) delta[0] += xprd; + else delta[0] -= xprd; + } + } + } +} + +/* ---------------------------------------------------------------------- */ + +namespace LAMMPS_NS { +template class FixShakeKokkos; +#ifdef LMP_KOKKOS_GPU +template class FixShakeKokkos; +#endif +} + diff --git a/src/KOKKOS/fix_shake_kokkos.h b/src/KOKKOS/fix_shake_kokkos.h new file mode 100644 index 0000000000..40aecb4a44 --- /dev/null +++ b/src/KOKKOS/fix_shake_kokkos.h @@ -0,0 +1,210 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, 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. +------------------------------------------------------------------------- */ + +#ifdef FIX_CLASS + +FixStyle(shake/kk,FixShakeKokkos) +FixStyle(shake/kk/device,FixShakeKokkos) +FixStyle(shake/kk/host,FixShakeKokkos) + +#else + +#ifndef LMP_FIX_SHAKE_KOKKOS_H +#define LMP_FIX_SHAKE_KOKKOS_H + +#include "fix_shake.h" +#include "kokkos_type.h" +#include "kokkos_base.h" + +namespace LAMMPS_NS { + +template +struct TagFixShakePostForce{}; + +template +struct TagFixShakePackForwardComm{}; + +struct TagFixShakeUnpackForwardComm{}; + +template +class FixShakeKokkos : public FixShake, public KokkosBase { + + //friend class FixEHEX; + + public: + typedef DeviceType device_type; + typedef EV_FLOAT value_type; + typedef ArrayTypes AT; + + FixShakeKokkos(class LAMMPS *, int, char **); + virtual ~FixShakeKokkos(); + void init(); + void pre_neighbor(); + void post_force(int); + + void grow_arrays(int); + void copy_arrays(int, int, int); + void set_arrays(int); + void update_arrays(int, int); + + int pack_exchange(int, double *); + int unpack_exchange(int, double *); + int pack_forward_comm_fix_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int, int *); + void unpack_forward_comm_fix_kokkos(int, int, DAT::tdual_xfloat_1d&); + int pack_forward_comm(int, int *, double *, int, int *); + void unpack_forward_comm(int, int, double *); + + void shake_end_of_step(int vflag); + void correct_coordinates(int vflag); + + int dof(int); + + void unconstrained_update(); + + template + KOKKOS_INLINE_FUNCTION + void operator()(TagFixShakePostForce, const int&, EV_FLOAT&) const; + + template + KOKKOS_INLINE_FUNCTION + void operator()(TagFixShakePostForce, const int&) const; + + template + KOKKOS_INLINE_FUNCTION + void operator()(TagFixShakePackForwardComm, const int&) const; + + KOKKOS_INLINE_FUNCTION + void operator()(TagFixShakeUnpackForwardComm, const int&) const; + + protected: + + typename AT::t_x_array d_x; + typename AT::t_v_array d_v; + typename AT::t_f_array d_f; + typename AT::t_float_1d d_rmass; + typename AT::t_float_1d d_mass; + typename AT::t_tagint_1d_randomread d_tag; + typename AT::t_int_1d d_type; + typename AT::t_int_1d d_mask; + + DAT::tdual_efloat_1d k_eatom; + typename AT::t_efloat_1d d_eatom; + + DAT::tdual_virial_array k_vatom; + typename AT::t_virial_array d_vatom; + + DAT::tdual_float_1d k_bond_distance; // constraint distances + typename AT::t_float_1d d_bond_distance; + DAT::tdual_float_1d k_angle_distance; + typename AT::t_float_1d d_angle_distance; + + // atom-based arrays + DAT::tdual_int_1d k_shake_flag; + typename AT::t_int_1d d_shake_flag; // 0 if atom not in SHAKE cluster + // 1 = size 3 angle cluster + // 2,3,4 = size of bond-only cluster + DAT::tdual_tagint_2d k_shake_atom; + typename AT::t_tagint_2d d_shake_atom; // global IDs of atoms in cluster + // central atom is 1st + // lowest global ID is 1st for size 2 + DAT::tdual_int_2d k_shake_type; + typename AT::t_int_2d d_shake_type; // bondtype of each bond in cluster + // for angle cluster, 3rd value + // is angletype + DAT::tdual_x_array k_xshake; + typename AT::t_x_array d_xshake; // unconstrained atom coords + + DAT::tdual_int_1d k_list; + typename AT::t_int_1d d_list; // list of clusters to SHAKE + + DAT::tdual_int_scalar k_error_flag; + DAT::tdual_int_scalar k_nlist; + + + template + KOKKOS_INLINE_FUNCTION + void shake(int, EV_FLOAT&) const; + + template + KOKKOS_INLINE_FUNCTION + void shake3(int, EV_FLOAT&) const; + + template + KOKKOS_INLINE_FUNCTION + void shake4(int, EV_FLOAT&) const; + + template + KOKKOS_INLINE_FUNCTION + void shake3angle(int, EV_FLOAT&) const; + + typedef typename KKDevice::value KKDeviceType; + Kokkos::Experimental::ScatterView::value,typename Kokkos::Experimental::ScatterSum,Kokkos::Experimental::ScatterDuplicated> dup_f; + Kokkos::Experimental::ScatterView::value,typename Kokkos::Experimental::ScatterSum,Kokkos::Experimental::ScatterDuplicated> dup_eatom; + Kokkos::Experimental::ScatterView::value,typename Kokkos::Experimental::ScatterSum,Kokkos::Experimental::ScatterDuplicated> dup_vatom; + + Kokkos::Experimental::ScatterView::value,typename Kokkos::Experimental::ScatterSum,Kokkos::Experimental::ScatterNonDuplicated> ndup_f; + Kokkos::Experimental::ScatterView::value,typename Kokkos::Experimental::ScatterSum,Kokkos::Experimental::ScatterNonDuplicated> ndup_eatom; + Kokkos::Experimental::ScatterView::value,typename Kokkos::Experimental::ScatterSum,Kokkos::Experimental::ScatterNonDuplicated> ndup_vatom; + + int neighflag,need_dup; + + typename AT::t_int_1d d_scalars; + HAT::t_int_1d h_scalars; + typename AT::t_int_scalar d_error_flag; + typename AT::t_int_scalar d_nlist; + HAT::t_int_scalar h_error_flag; + HAT::t_int_scalar h_nlist; + + template + KOKKOS_INLINE_FUNCTION + void v_tally(EV_FLOAT&, int, int *, double, double *) const; + + DAT::tdual_int_1d k_map_array; + typename AT::t_int_1d_randomread map_array; + + int iswap; + int first; + typename AT::t_int_2d d_sendlist; + typename AT::t_xfloat_1d_um d_buf; + X_FLOAT dx,dy,dz; + + int *shake_flag_tmp; + tagint **shake_atom_tmp; + int **shake_type_tmp; + + // copied from Domain + + KOKKOS_INLINE_FUNCTION + void minimum_image(double *) const; + + KOKKOS_INLINE_FUNCTION + void minimum_image_once(double *) const; + + void update_domain_variables(); + + int triclinic; + int xperiodic,yperiodic,zperiodic; + X_FLOAT xprd_half,yprd_half,zprd_half; + X_FLOAT xprd,yprd,zprd; + X_FLOAT xy,xz,yz; +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +*/ diff --git a/src/KOKKOS/kokkos_base.h b/src/KOKKOS/kokkos_base.h index 1d8f1e93e2..adacaf6ad8 100644 --- a/src/KOKKOS/kokkos_base.h +++ b/src/KOKKOS/kokkos_base.h @@ -28,6 +28,13 @@ class KokkosBase { int, int *) {return 0;}; virtual void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d &) {} + // Fix + virtual int pack_forward_comm_fix_kokkos(int, DAT::tdual_int_2d, + int, DAT::tdual_xfloat_1d &, + int, int *) {return 0;}; + virtual void unpack_forward_comm_fix_kokkos(int, int, DAT::tdual_xfloat_1d &) {} + + // Region virtual void match_all_kokkos(int, DAT::tdual_int_1d) {} }; diff --git a/src/RIGID/fix_shake.cpp b/src/RIGID/fix_shake.cpp index 1244cd36fb..365fc16fd7 100644 --- a/src/RIGID/fix_shake.cpp +++ b/src/RIGID/fix_shake.cpp @@ -240,6 +240,8 @@ FixShake::FixShake(LAMMPS *lmp, int narg, char **arg) : FixShake::~FixShake() { + if (copymode) return; + // unregister callbacks to this fix from Atom class atom->delete_callback(id,Atom::GROW); diff --git a/src/RIGID/fix_shake.h b/src/RIGID/fix_shake.h index ee9f520fea..53d61397bf 100644 --- a/src/RIGID/fix_shake.h +++ b/src/RIGID/fix_shake.h @@ -34,14 +34,14 @@ class FixShake : public Fix { virtual int setmask(); virtual void init(); void setup(int); - void pre_neighbor(); + virtual void pre_neighbor(); virtual void post_force(int); virtual void post_force_respa(int, int, int); virtual double memory_usage(); virtual void grow_arrays(int); virtual void copy_arrays(int, int, int); - void set_arrays(int); + virtual void set_arrays(int); virtual void update_arrays(int, int); void set_molecule(int, tagint, int, double *, double *, double *); @@ -54,7 +54,7 @@ class FixShake : public Fix { virtual void correct_coordinates(int vflag); virtual void correct_velocities(); - int dof(int); + virtual int dof(int); virtual void reset_dt(); void *extract(const char *, int &); @@ -126,7 +126,7 @@ class FixShake : public Fix { void shake_info(int *, tagint **, int **); int masscheck(double); - void unconstrained_update(); + virtual void unconstrained_update(); void unconstrained_update_respa(int); void shake(int); void shake3(int); diff --git a/src/fix.cpp b/src/fix.cpp index 16628e5374..905374ee05 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -111,6 +111,7 @@ Fix::Fix(LAMMPS *lmp, int /*narg*/, char **arg) : datamask_modify = ALL_MASK; kokkosable = 0; + forward_comm_device = 0; copymode = 0; } diff --git a/src/fix.h b/src/fix.h index 07a222063c..1a28e5c924 100644 --- a/src/fix.h +++ b/src/fix.h @@ -107,6 +107,7 @@ class Fix : protected Pointers { // KOKKOS host/device flag and data masks int kokkosable; // 1 if Kokkos fix + int forward_comm_device; // 1 if forward comm on Device ExecutionSpace execution_space; unsigned int datamask_read,datamask_modify; From 6a3a17c63e15f761a88a728629973ed43baa1627 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Thu, 22 Oct 2020 12:08:12 -0600 Subject: [PATCH 11/67] Update docs --- doc/src/Commands_fix.rst | 2 +- doc/src/fix_shake.rst | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/src/Commands_fix.rst b/doc/src/Commands_fix.rst index 9a3c5df9cd..227409e45c 100644 --- a/doc/src/Commands_fix.rst +++ b/doc/src/Commands_fix.rst @@ -195,7 +195,7 @@ OPT. * :doc:`saed/vtk ` * :doc:`setforce (k) ` * :doc:`setforce/spin ` - * :doc:`shake ` + * :doc:`shake (k) ` * :doc:`shardlow (k) ` * :doc:`smd ` * :doc:`smd/adjust_dt ` diff --git a/doc/src/fix_shake.rst b/doc/src/fix_shake.rst index eb7add7035..116edd8c7e 100644 --- a/doc/src/fix_shake.rst +++ b/doc/src/fix_shake.rst @@ -1,9 +1,12 @@ .. index:: fix shake +.. index:: fix shake/kk .. index:: fix rattle fix shake command ================= +Accelerator Variants: *shake/kk* + fix rattle command ================== From bb2e616c5fe204293ff8f008d8d687605ed62588 Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sat, 24 Oct 2020 12:56:02 -0400 Subject: [PATCH 12/67] molecule: use user-provided IDs in molecule files --- src/molecule.cpp | 52 +++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/molecule.cpp b/src/molecule.cpp index b4f16525e9..afa5296414 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -683,14 +683,15 @@ void Molecule::coords(char *line) ValueTokenizer values(line); if (values.count() != 4) error->one(FLERR,"Invalid Coords section in molecule file"); - values.next_int(); - x[i][0] = values.next_double(); - x[i][1] = values.next_double(); - x[i][2] = values.next_double(); + int iatom = values.next_int() - 1; + if (iatom >= natoms) error->one(FLERR,"Invalid Coords section in molecule file"); + x[iatom][0] = values.next_double(); + x[iatom][1] = values.next_double(); + x[iatom][2] = values.next_double(); - x[i][0] *= sizescale; - x[i][1] *= sizescale; - x[i][2] *= sizescale; + x[iatom][0] *= sizescale; + x[iatom][1] *= sizescale; + x[iatom][2] *= sizescale; } } catch (TokenizerException &e) { error->one(FLERR, fmt::format("Invalid Coords section in molecule file\n" @@ -718,9 +719,10 @@ void Molecule::types(char *line) ValueTokenizer values(line); if (values.count() != 2) error->one(FLERR,"Invalid Types section in molecule file"); - values.next_int(); - type[i] = values.next_int(); - type[i] += toffset; + int iatom = values.next_int() - 1; + if (iatom >= natoms) error->one(FLERR,"Invalid Types section in molecule file"); + type[iatom] = values.next_int(); + type[iatom] += toffset; } } catch (TokenizerException &e) { error->one(FLERR, fmt::format("Invalid Types section in molecule file\n" @@ -748,9 +750,10 @@ void Molecule::molecules(char *line) ValueTokenizer values(line); if (values.count() != 2) error->one(FLERR,"Invalid Molecules section in molecule file"); - values.next_int(); - molecule[i] = values.next_int(); - // molecule[i] += moffset; // placeholder for possible molecule offset + int iatom = values.next_int() - 1; + if (iatom >= natoms) error->one(FLERR,"Invalid Molecules section in molecule file"); + molecule[iatom] = values.next_int(); + // molecule[iatom] += moffset; // placeholder for possible molecule offset } } catch (TokenizerException &e) { error->one(FLERR, fmt::format("Invalid Molecules section in molecule file\n" @@ -808,8 +811,9 @@ void Molecule::charges(char *line) ValueTokenizer values(line); if ((int)values.count() != 2) error->one(FLERR,"Invalid Charges section in molecule file"); - values.next_int(); - q[i] = values.next_double(); + int iatom = values.next_int() - 1; + if (iatom >= natoms) error->one(FLERR,"Invalid Charges section in molecule file"); + q[iatom] = values.next_double(); } } catch (TokenizerException &e) { error->one(FLERR, fmt::format("Invalid Charges section in molecule file\n" @@ -831,11 +835,12 @@ void Molecule::diameters(char *line) ValueTokenizer values(line); if (values.count() != 2) error->one(FLERR,"Invalid Diameters section in molecule file"); - values.next_int(); - radius[i] = values.next_double(); - radius[i] *= sizescale; - radius[i] *= 0.5; - maxradius = MAX(maxradius,radius[i]); + int iatom = values.next_int() - 1; + if (iatom >= natoms) error->one(FLERR,"Invalid Diameters section in molecule file"); + radius[iatom] = values.next_double(); + radius[iatom] *= sizescale; + radius[iatom] *= 0.5; + maxradius = MAX(maxradius,radius[iatom]); } } catch (TokenizerException &e) { error->one(FLERR, fmt::format("Invalid Diameters section in molecule file\n" @@ -860,9 +865,10 @@ void Molecule::masses(char *line) ValueTokenizer values(line); if (values.count() != 2) error->one(FLERR,"Invalid Masses section in molecule file"); - values.next_int(); - rmass[i] = values.next_double(); - rmass[i] *= sizescale*sizescale*sizescale; + int iatom = values.next_int() - 1; + if (iatom >= natoms) error->one(FLERR,"Invalid Diameters section in molecule file"); + rmass[iatom] = values.next_double(); + rmass[iatom] *= sizescale*sizescale*sizescale; } } catch (TokenizerException &e) { error->one(FLERR, fmt::format("Invalid Masses section in molecule file\n" From 7df8b81af98f33f133d378704f1ff2a18c033682 Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sat, 24 Oct 2020 13:08:49 -0400 Subject: [PATCH 13/67] Update molecule.rst --- doc/src/molecule.rst | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/doc/src/molecule.rst b/doc/src/molecule.rst index 7b316b9d24..2c20dc8856 100644 --- a/doc/src/molecule.rst +++ b/doc/src/molecule.rst @@ -201,11 +201,9 @@ bonds between nuclear cores and Drude electrons in a different manner. Each section is listed below in alphabetic order. The format of each section is described including the number of lines it must contain and -rules (if any) for whether it can appear in the data file. In each -case the ID is ignored; it is simply included for readability, and -should be a number from 1 to Nlines for the section, indicating which -atom (or bond, etc) the entry applies to. The lines are assumed to be -listed in order from 1 to Nlines, but LAMMPS does not check for this. +rules (if any) for whether it can appear in the data file. For per- +atom sections, entries should be numbered from 1 to Natoms, where +Natoms is the number of atoms in the template. ---------- From f2b575d3ecb6b9885e74ff113baf2284e47fc707 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Mon, 26 Oct 2020 12:42:26 -0600 Subject: [PATCH 14/67] Fix GPU memory issues --- src/KOKKOS/fix_shake_kokkos.cpp | 24 ++++++++++++++++++++++++ src/KOKKOS/fix_shake_kokkos.h | 1 + src/RIGID/fix_shake.h | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/KOKKOS/fix_shake_kokkos.cpp b/src/KOKKOS/fix_shake_kokkos.cpp index 854dfefeed..fcf52b8834 100644 --- a/src/KOKKOS/fix_shake_kokkos.cpp +++ b/src/KOKKOS/fix_shake_kokkos.cpp @@ -297,6 +297,7 @@ void FixShakeKokkos::post_force(int vflag) atomKK->sync(Host,X_MASK); k_shake_flag.sync_host(); k_shake_atom.sync_host(); + k_shake_type.sync_host(); stats(); } @@ -1410,6 +1411,29 @@ void FixShakeKokkos::update_arrays(int i, int atom_offset) k_shake_atom.modify_host(); } +/* ---------------------------------------------------------------------- + initialize a molecule inserted by another fix, e.g. deposit or pour + called when molecule is created + nlocalprev = # of atoms on this proc before molecule inserted + tagprev = atom ID previous to new atoms in the molecule + xgeom,vcm,quat ignored +------------------------------------------------------------------------- */ + +template +void FixShakeKokkos::set_molecule(int nlocalprev, tagint tagprev, int imol, + double * xgeom, double * vcm, double * quat) +{ + atomKK->sync(Host,TAG_MASK); + k_shake_flag.sync_host(); + k_shake_atom.sync_host(); + k_shake_type.sync_host(); + + FixShake::set_molecule(nlocalprev,tagprev,imol,xgeom,vcm,quat); + + k_shake_atom.modify_host(); + k_shake_type.modify_host(); +} + /* ---------------------------------------------------------------------- pack values in local atom-based arrays for exchange with another proc ------------------------------------------------------------------------- */ diff --git a/src/KOKKOS/fix_shake_kokkos.h b/src/KOKKOS/fix_shake_kokkos.h index 40aecb4a44..82743573bd 100644 --- a/src/KOKKOS/fix_shake_kokkos.h +++ b/src/KOKKOS/fix_shake_kokkos.h @@ -56,6 +56,7 @@ class FixShakeKokkos : public FixShake, public KokkosBase { void copy_arrays(int, int, int); void set_arrays(int); void update_arrays(int, int); + void set_molecule(int, tagint, int, double *, double *, double *); int pack_exchange(int, double *); int unpack_exchange(int, double *); diff --git a/src/RIGID/fix_shake.h b/src/RIGID/fix_shake.h index 53d61397bf..f1be3e2d1d 100644 --- a/src/RIGID/fix_shake.h +++ b/src/RIGID/fix_shake.h @@ -43,7 +43,7 @@ class FixShake : public Fix { virtual void copy_arrays(int, int, int); virtual void set_arrays(int); virtual void update_arrays(int, int); - void set_molecule(int, tagint, int, double *, double *, double *); + virtual void set_molecule(int, tagint, int, double *, double *, double *); virtual int pack_exchange(int, double *); virtual int unpack_exchange(int, double *); From e2ab5f1ce9b7eb1faecf6adbc4a0b982ab6eae85 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Tue, 27 Oct 2020 09:31:19 -0600 Subject: [PATCH 15/67] Fix race condition in Kokkos pair and fix forward comm --- src/KOKKOS/comm_kokkos.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/KOKKOS/comm_kokkos.cpp b/src/KOKKOS/comm_kokkos.cpp index 97bb1a5b0b..f63f7ff002 100644 --- a/src/KOKKOS/comm_kokkos.cpp +++ b/src/KOKKOS/comm_kokkos.cpp @@ -375,6 +375,7 @@ void CommKokkos::forward_comm_fix_device(Fix *fix, int size) { int iswap,n,nsize; MPI_Request request; + DAT::tdual_xfloat_1d k_buf_tmp; if (size) nsize = size; else nsize = fix->comm_forward; @@ -423,11 +424,12 @@ void CommKokkos::forward_comm_fix_device(Fix *fix, int size) k_buf_recv_fix.modify(); k_buf_recv_fix.sync(); } - } else k_buf_recv_fix = k_buf_send_fix; + k_buf_tmp = k_buf_recv_fix; + } else k_buf_tmp = k_buf_send_fix; // unpack buffer - fixKKBase->unpack_forward_comm_fix_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_recv_fix); + fixKKBase->unpack_forward_comm_fix_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_tmp); DeviceType().fence(); } } @@ -468,6 +470,7 @@ void CommKokkos::forward_comm_pair_device(Pair *pair) { int iswap,n; MPI_Request request; + DAT::tdual_xfloat_1d k_buf_tmp; int nsize = pair->comm_forward; KokkosBase* pairKKBase = dynamic_cast(pair); @@ -515,11 +518,12 @@ void CommKokkos::forward_comm_pair_device(Pair *pair) k_buf_recv_pair.modify(); k_buf_recv_pair.sync(); } - } else k_buf_recv_pair = k_buf_send_pair; + k_buf_tmp = k_buf_recv_pair; + } else k_buf_tmp = k_buf_send_pair; // unpack buffer - pairKKBase->unpack_forward_comm_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_recv_pair); + pairKKBase->unpack_forward_comm_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_tmp); DeviceType().fence(); } } From 91d558310a1fe86c722d50108187d67a5ca2fec7 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Tue, 27 Oct 2020 11:23:05 -0600 Subject: [PATCH 16/67] Fix atomic issue --- src/KOKKOS/fix_shake_kokkos.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/KOKKOS/fix_shake_kokkos.cpp b/src/KOKKOS/fix_shake_kokkos.cpp index fcf52b8834..851f55906c 100644 --- a/src/KOKKOS/fix_shake_kokkos.cpp +++ b/src/KOKKOS/fix_shake_kokkos.cpp @@ -321,9 +321,22 @@ void FixShakeKokkos::post_force(int vflag) d_vatom = k_vatom.template view(); } - need_dup = lmp->kokkos->need_dup(); + neighflag = lmp->kokkos->neighflag; + // FULL neighlist still needs atomics in fix shake + + if (neighflag == FULL) { + if (lmp->kokkos->nthreads > 1 || lmp->kokkos->ngpus > 0) + neighflag = HALFTHREAD; + else + neighflag = HALF; + } + + need_dup = 0; + if (neighflag != HALF) + need_dup = std::is_same::value,Kokkos::Experimental::ScatterDuplicated>::value; + // allocate duplicated memory if (need_dup) { @@ -344,10 +357,10 @@ void FixShakeKokkos::post_force(int vflag) if (neighflag == HALF) { if (evflag) - Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlist),*this,ev); + Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlist),*this,ev); else Kokkos::parallel_for(Kokkos::RangePolicy >(0,nlist),*this); - } else if (neighflag == HALFTHREAD) { + } else { if (evflag) Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,nlist),*this,ev); else From 22a804e6347fd9d1024a3abb66261dad6544551b Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Tue, 27 Oct 2020 12:25:27 -0600 Subject: [PATCH 17/67] Fix memory issue --- src/KOKKOS/comm_kokkos.cpp | 1 + src/KOKKOS/fix_shake_kokkos.cpp | 29 +++++++++++++++++++++++++---- src/RIGID/fix_shake.cpp | 33 +++++++++++++++++---------------- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/KOKKOS/comm_kokkos.cpp b/src/KOKKOS/comm_kokkos.cpp index f63f7ff002..2ef4b14d4f 100644 --- a/src/KOKKOS/comm_kokkos.cpp +++ b/src/KOKKOS/comm_kokkos.cpp @@ -838,6 +838,7 @@ void CommKokkos::borders() else borders_device(); } else { atomKK->sync(Host,ALL_MASK); + k_sendlist.sync(); CommBrick::borders(); k_sendlist.modify(); atomKK->modified(Host,ALL_MASK); diff --git a/src/KOKKOS/fix_shake_kokkos.cpp b/src/KOKKOS/fix_shake_kokkos.cpp index 851f55906c..64c284952c 100644 --- a/src/KOKKOS/fix_shake_kokkos.cpp +++ b/src/KOKKOS/fix_shake_kokkos.cpp @@ -103,6 +103,10 @@ FixShakeKokkos::FixShakeKokkos(LAMMPS *lmp, int narg, char **arg) : h_error_flag = Kokkos::subview(h_scalars,0); h_nlist = Kokkos::subview(h_scalars,1); + + memory->destroy(shake_flag_tmp); + memory->destroy(shake_atom_tmp); + memory->destroy(shake_type_tmp); } /* ---------------------------------------------------------------------- */ @@ -112,6 +116,27 @@ FixShakeKokkos::~FixShakeKokkos() { if (copymode) return; + k_shake_flag.sync_host(); + k_shake_atom.sync_host(); + + for (int i = 0; i < nlocal; i++) { + if (shake_flag[i] == 0) continue; + else if (shake_flag[i] == 1) { + bondtype_findset(i,shake_atom[i][0],shake_atom[i][1],1); + bondtype_findset(i,shake_atom[i][0],shake_atom[i][2],1); + angletype_findset(i,shake_atom[i][1],shake_atom[i][2],1); + } else if (shake_flag[i] == 2) { + bondtype_findset(i,shake_atom[i][0],shake_atom[i][1],1); + } else if (shake_flag[i] == 3) { + bondtype_findset(i,shake_atom[i][0],shake_atom[i][1],1); + bondtype_findset(i,shake_atom[i][0],shake_atom[i][2],1); + } else if (shake_flag[i] == 4) { + bondtype_findset(i,shake_atom[i][0],shake_atom[i][1],1); + bondtype_findset(i,shake_atom[i][0],shake_atom[i][2],1); + bondtype_findset(i,shake_atom[i][0],shake_atom[i][3],1); + } + } + memoryKK->destroy_kokkos(k_shake_flag,shake_flag); memoryKK->destroy_kokkos(k_shake_atom,shake_atom); memoryKK->destroy_kokkos(k_shake_type,shake_type); @@ -119,10 +144,6 @@ FixShakeKokkos::~FixShakeKokkos() memoryKK->destroy_kokkos(k_list,list); memoryKK->destroy_kokkos(k_vatom,vatom); - - shake_flag = shake_flag_tmp; - shake_atom = shake_atom_tmp; - shake_type = shake_type_tmp; } /* ---------------------------------------------------------------------- diff --git a/src/RIGID/fix_shake.cpp b/src/RIGID/fix_shake.cpp index 365fc16fd7..10f79311b9 100644 --- a/src/RIGID/fix_shake.cpp +++ b/src/RIGID/fix_shake.cpp @@ -251,23 +251,24 @@ FixShake::~FixShake() int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - if (shake_flag[i] == 0) continue; - else if (shake_flag[i] == 1) { - bondtype_findset(i,shake_atom[i][0],shake_atom[i][1],1); - bondtype_findset(i,shake_atom[i][0],shake_atom[i][2],1); - angletype_findset(i,shake_atom[i][1],shake_atom[i][2],1); - } else if (shake_flag[i] == 2) { - bondtype_findset(i,shake_atom[i][0],shake_atom[i][1],1); - } else if (shake_flag[i] == 3) { - bondtype_findset(i,shake_atom[i][0],shake_atom[i][1],1); - bondtype_findset(i,shake_atom[i][0],shake_atom[i][2],1); - } else if (shake_flag[i] == 4) { - bondtype_findset(i,shake_atom[i][0],shake_atom[i][1],1); - bondtype_findset(i,shake_atom[i][0],shake_atom[i][2],1); - bondtype_findset(i,shake_atom[i][0],shake_atom[i][3],1); + if (shake_flag) + for (int i = 0; i < nlocal; i++) { + if (shake_flag[i] == 0) continue; + else if (shake_flag[i] == 1) { + bondtype_findset(i,shake_atom[i][0],shake_atom[i][1],1); + bondtype_findset(i,shake_atom[i][0],shake_atom[i][2],1); + angletype_findset(i,shake_atom[i][1],shake_atom[i][2],1); + } else if (shake_flag[i] == 2) { + bondtype_findset(i,shake_atom[i][0],shake_atom[i][1],1); + } else if (shake_flag[i] == 3) { + bondtype_findset(i,shake_atom[i][0],shake_atom[i][1],1); + bondtype_findset(i,shake_atom[i][0],shake_atom[i][2],1); + } else if (shake_flag[i] == 4) { + bondtype_findset(i,shake_atom[i][0],shake_atom[i][1],1); + bondtype_findset(i,shake_atom[i][0],shake_atom[i][2],1); + bondtype_findset(i,shake_atom[i][0],shake_atom[i][3],1); + } } - } // delete locally stored arrays From c7b39283b1067a103450535a2d70b8f17870fe26 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 29 Oct 2020 05:58:39 -0400 Subject: [PATCH 18/67] need to transfer molecule templates when using "replicate" --- src/replicate.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/replicate.cpp b/src/replicate.cpp index 7a8b5d28c2..296e099208 100644 --- a/src/replicate.cpp +++ b/src/replicate.cpp @@ -43,9 +43,6 @@ void Replicate::command(int narg, char **arg) error->all(FLERR,"Replicate command before simulation box is defined"); if (narg < 3 || narg > 4) error->all(FLERR,"Illegal replicate command"); - if (atom->molecular == Atom::TEMPLATE) - error->all(FLERR,"Cannot use replicate command with atom style template"); - int me = comm->me; int nprocs = comm->nprocs; @@ -162,6 +159,20 @@ void Replicate::command(int narg, char **arg) else atom = new Atom(lmp); atom->settings(old); + + // transfer molecule templates. needs to be done early for atom style template + + if (old->nmolecule) { + atom->molecules = (Molecule **) memory->smalloc((old->nmolecule)*sizeof(Molecule *), + "atom::molecules"); + atom->nmolecule = old->nmolecule; + for (int i = 0; i < old->nmolecule; ++i) + atom->molecules[i] = old->molecules[i]; + memory->sfree(old->molecules); + old->molecules = nullptr; + old->nmolecule = 0; + } + atom->create_avec(old->atom_style,old->avec->nargcopy,old->avec->argcopy,0); // check that new system will not be too large @@ -749,17 +760,19 @@ void Replicate::command(int narg, char **arg) error->all(FLERR,"Replicate did not assign all atoms correctly"); if (me == 0) { + const char *molstyle = ""; + if (atom->molecular == Atom::TEMPLATE) molstyle = "template "; if (atom->nbonds) { - utils::logmesg(lmp,fmt::format(" {} bonds\n",atom->nbonds)); + utils::logmesg(lmp,fmt::format(" {} {}bonds\n",atom->nbonds,molstyle)); } if (atom->nangles) { - utils::logmesg(lmp,fmt::format(" {} angles\n",atom->nangles)); + utils::logmesg(lmp,fmt::format(" {} {}angles\n",atom->nangles,molstyle)); } if (atom->ndihedrals) { - utils::logmesg(lmp,fmt::format(" {} dihedrals\n",atom->ndihedrals)); + utils::logmesg(lmp,fmt::format(" {} {}dihedrals\n",atom->ndihedrals,molstyle)); } if (atom->nimpropers) { - utils::logmesg(lmp,fmt::format(" {} impropers\n",atom->nimpropers)); + utils::logmesg(lmp,fmt::format(" {} {}impropers\n",atom->nimpropers,molstyle)); } } From f2b9db0de42227abbfbc3a2588a145762ceeb520 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 29 Oct 2020 06:21:54 -0400 Subject: [PATCH 19/67] update atom style tester to test replicate for atom style template --- unittest/formats/test_atom_styles.cpp | 1544 ++++++++++++++----------- 1 file changed, 842 insertions(+), 702 deletions(-) diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index 2dcefab6dd..0bc4833fea 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -3480,193 +3480,193 @@ TEST_F(AtomStyleTest, template) lmp->input->one("atom_style template twomols"); lmp->input->one("newton on"); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_THAT(std::string(lmp->atom->atom_style), Eq("template")); - EXPECT_NE(lmp->atom->avec, nullptr); - EXPECT_EQ(lmp->atom->natoms, 0); - EXPECT_EQ(lmp->atom->nlocal, 0); - EXPECT_EQ(lmp->atom->nghost, 0); - EXPECT_EQ(lmp->atom->nmax, 1); - EXPECT_EQ(lmp->atom->tag_enable, 1); - EXPECT_EQ(lmp->atom->molecular, Atom::TEMPLATE); - EXPECT_EQ(lmp->atom->nellipsoids, 0); - EXPECT_EQ(lmp->atom->nlines, 0); - EXPECT_EQ(lmp->atom->ntris, 0); - EXPECT_EQ(lmp->atom->nbodies, 0); - EXPECT_EQ(lmp->atom->nbonds, 0); - EXPECT_EQ(lmp->atom->nangles, 0); - EXPECT_EQ(lmp->atom->ndihedrals, 0); - EXPECT_EQ(lmp->atom->nimpropers, 0); - EXPECT_EQ(lmp->atom->ntypes, 0); - EXPECT_EQ(lmp->atom->nbondtypes, 2); - EXPECT_EQ(lmp->atom->nangletypes, 2); - EXPECT_EQ(lmp->atom->ndihedraltypes, 0); - EXPECT_EQ(lmp->atom->nimpropertypes, 0); - EXPECT_EQ(lmp->atom->bond_per_atom, 0); - EXPECT_EQ(lmp->atom->angle_per_atom, 0); - EXPECT_EQ(lmp->atom->dihedral_per_atom, 0); - EXPECT_EQ(lmp->atom->improper_per_atom, 0); - EXPECT_EQ(lmp->atom->extra_bond_per_atom, 0); - EXPECT_EQ(lmp->atom->extra_angle_per_atom, 0); - EXPECT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - EXPECT_EQ(lmp->atom->extra_improper_per_atom, 0); + ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); + ASSERT_NE(lmp->atom->avec, nullptr); + ASSERT_EQ(lmp->atom->natoms, 0); + ASSERT_EQ(lmp->atom->nlocal, 0); + ASSERT_EQ(lmp->atom->nghost, 0); + ASSERT_EQ(lmp->atom->nmax, 1); + ASSERT_EQ(lmp->atom->tag_enable, 1); + ASSERT_EQ(lmp->atom->molecular, Atom::TEMPLATE); + ASSERT_EQ(lmp->atom->nellipsoids, 0); + ASSERT_EQ(lmp->atom->nlines, 0); + ASSERT_EQ(lmp->atom->ntris, 0); + ASSERT_EQ(lmp->atom->nbodies, 0); + ASSERT_EQ(lmp->atom->nbonds, 0); + ASSERT_EQ(lmp->atom->nangles, 0); + ASSERT_EQ(lmp->atom->ndihedrals, 0); + ASSERT_EQ(lmp->atom->nimpropers, 0); + ASSERT_EQ(lmp->atom->ntypes, 0); + ASSERT_EQ(lmp->atom->nbondtypes, 2); + ASSERT_EQ(lmp->atom->nangletypes, 2); + ASSERT_EQ(lmp->atom->ndihedraltypes, 0); + ASSERT_EQ(lmp->atom->nimpropertypes, 0); + ASSERT_EQ(lmp->atom->bond_per_atom, 0); + ASSERT_EQ(lmp->atom->angle_per_atom, 0); + ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); + ASSERT_EQ(lmp->atom->improper_per_atom, 0); + ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); + ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); + ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); + ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - EXPECT_EQ(lmp->atom->sphere_flag, 0); - EXPECT_EQ(lmp->atom->ellipsoid_flag, 0); - EXPECT_EQ(lmp->atom->line_flag, 0); - EXPECT_EQ(lmp->atom->tri_flag, 0); - EXPECT_EQ(lmp->atom->body_flag, 0); - EXPECT_EQ(lmp->atom->peri_flag, 0); - EXPECT_EQ(lmp->atom->electron_flag, 0); - EXPECT_EQ(lmp->atom->wavepacket_flag, 0); - EXPECT_EQ(lmp->atom->sph_flag, 0); - EXPECT_EQ(lmp->atom->molecule_flag, 1); - EXPECT_EQ(lmp->atom->molindex_flag, 0); - EXPECT_EQ(lmp->atom->molatom_flag, 0); - EXPECT_EQ(lmp->atom->q_flag, 0); - EXPECT_EQ(lmp->atom->mu_flag, 0); - EXPECT_EQ(lmp->atom->rmass_flag, 0); - EXPECT_EQ(lmp->atom->radius_flag, 0); - EXPECT_EQ(lmp->atom->omega_flag, 0); - EXPECT_EQ(lmp->atom->torque_flag, 0); - EXPECT_EQ(lmp->atom->angmom_flag, 0); - EXPECT_EQ(lmp->atom->vfrac_flag, 0); - EXPECT_EQ(lmp->atom->spin_flag, 0); - EXPECT_EQ(lmp->atom->eradius_flag, 0); - EXPECT_EQ(lmp->atom->ervel_flag, 0); - EXPECT_EQ(lmp->atom->erforce_flag, 0); - EXPECT_EQ(lmp->atom->cs_flag, 0); - EXPECT_EQ(lmp->atom->csforce_flag, 0); - EXPECT_EQ(lmp->atom->vforce_flag, 0); - EXPECT_EQ(lmp->atom->ervelforce_flag, 0); - EXPECT_EQ(lmp->atom->etag_flag, 0); - EXPECT_EQ(lmp->atom->rho_flag, 0); - EXPECT_EQ(lmp->atom->esph_flag, 0); - EXPECT_EQ(lmp->atom->cv_flag, 0); - EXPECT_EQ(lmp->atom->vest_flag, 0); - EXPECT_EQ(lmp->atom->dpd_flag, 0); - EXPECT_EQ(lmp->atom->edpd_flag, 0); - EXPECT_EQ(lmp->atom->tdpd_flag, 0); - EXPECT_EQ(lmp->atom->mesont_flag, 0); - EXPECT_EQ(lmp->atom->sp_flag, 0); - EXPECT_EQ(lmp->atom->x0_flag, 0); - EXPECT_EQ(lmp->atom->smd_flag, 0); - EXPECT_EQ(lmp->atom->damage_flag, 0); - EXPECT_EQ(lmp->atom->contact_radius_flag, 0); - EXPECT_EQ(lmp->atom->smd_data_9_flag, 0); - EXPECT_EQ(lmp->atom->smd_stress_flag, 0); - EXPECT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - EXPECT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - EXPECT_EQ(lmp->atom->pdscale, 1.0); + ASSERT_EQ(lmp->atom->sphere_flag, 0); + ASSERT_EQ(lmp->atom->ellipsoid_flag, 0); + ASSERT_EQ(lmp->atom->line_flag, 0); + ASSERT_EQ(lmp->atom->tri_flag, 0); + ASSERT_EQ(lmp->atom->body_flag, 0); + ASSERT_EQ(lmp->atom->peri_flag, 0); + ASSERT_EQ(lmp->atom->electron_flag, 0); + ASSERT_EQ(lmp->atom->wavepacket_flag, 0); + ASSERT_EQ(lmp->atom->sph_flag, 0); + ASSERT_EQ(lmp->atom->molecule_flag, 1); + ASSERT_EQ(lmp->atom->molindex_flag, 0); + ASSERT_EQ(lmp->atom->molatom_flag, 0); + ASSERT_EQ(lmp->atom->q_flag, 0); + ASSERT_EQ(lmp->atom->mu_flag, 0); + ASSERT_EQ(lmp->atom->rmass_flag, 0); + ASSERT_EQ(lmp->atom->radius_flag, 0); + ASSERT_EQ(lmp->atom->omega_flag, 0); + ASSERT_EQ(lmp->atom->torque_flag, 0); + ASSERT_EQ(lmp->atom->angmom_flag, 0); + ASSERT_EQ(lmp->atom->vfrac_flag, 0); + ASSERT_EQ(lmp->atom->spin_flag, 0); + ASSERT_EQ(lmp->atom->eradius_flag, 0); + ASSERT_EQ(lmp->atom->ervel_flag, 0); + ASSERT_EQ(lmp->atom->erforce_flag, 0); + ASSERT_EQ(lmp->atom->cs_flag, 0); + ASSERT_EQ(lmp->atom->csforce_flag, 0); + ASSERT_EQ(lmp->atom->vforce_flag, 0); + ASSERT_EQ(lmp->atom->ervelforce_flag, 0); + ASSERT_EQ(lmp->atom->etag_flag, 0); + ASSERT_EQ(lmp->atom->rho_flag, 0); + ASSERT_EQ(lmp->atom->esph_flag, 0); + ASSERT_EQ(lmp->atom->cv_flag, 0); + ASSERT_EQ(lmp->atom->vest_flag, 0); + ASSERT_EQ(lmp->atom->dpd_flag, 0); + ASSERT_EQ(lmp->atom->edpd_flag, 0); + ASSERT_EQ(lmp->atom->tdpd_flag, 0); + ASSERT_EQ(lmp->atom->mesont_flag, 0); + ASSERT_EQ(lmp->atom->sp_flag, 0); + ASSERT_EQ(lmp->atom->x0_flag, 0); + ASSERT_EQ(lmp->atom->smd_flag, 0); + ASSERT_EQ(lmp->atom->damage_flag, 0); + ASSERT_EQ(lmp->atom->contact_radius_flag, 0); + ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); + ASSERT_EQ(lmp->atom->smd_stress_flag, 0); + ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); + ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); + ASSERT_EQ(lmp->atom->pdscale, 1.0); - EXPECT_NE(lmp->atom->tag, nullptr); - EXPECT_NE(lmp->atom->type, nullptr); - EXPECT_NE(lmp->atom->mask, nullptr); - EXPECT_NE(lmp->atom->image, nullptr); - EXPECT_NE(lmp->atom->x, nullptr); - EXPECT_NE(lmp->atom->v, nullptr); - EXPECT_NE(lmp->atom->f, nullptr); - EXPECT_EQ(lmp->atom->q, nullptr); - EXPECT_EQ(lmp->atom->mu, nullptr); - EXPECT_EQ(lmp->atom->omega, nullptr); - EXPECT_EQ(lmp->atom->angmom, nullptr); - EXPECT_EQ(lmp->atom->torque, nullptr); - EXPECT_EQ(lmp->atom->radius, nullptr); - EXPECT_EQ(lmp->atom->rmass, nullptr); - EXPECT_EQ(lmp->atom->ellipsoid, nullptr); - EXPECT_EQ(lmp->atom->line, nullptr); - EXPECT_EQ(lmp->atom->tri, nullptr); - EXPECT_EQ(lmp->atom->body, nullptr); - EXPECT_NE(lmp->atom->molecule, nullptr); - EXPECT_NE(lmp->atom->molindex, nullptr); - EXPECT_NE(lmp->atom->molatom, nullptr); - EXPECT_EQ(lmp->atom->num_bond, nullptr); - EXPECT_EQ(lmp->atom->bond_type, nullptr); - EXPECT_EQ(lmp->atom->bond_atom, nullptr); - EXPECT_EQ(lmp->atom->num_angle, nullptr); - EXPECT_EQ(lmp->atom->angle_type, nullptr); - EXPECT_EQ(lmp->atom->angle_atom1, nullptr); - EXPECT_EQ(lmp->atom->angle_atom2, nullptr); - EXPECT_EQ(lmp->atom->angle_atom3, nullptr); - EXPECT_EQ(lmp->atom->num_dihedral, nullptr); - EXPECT_EQ(lmp->atom->dihedral_type, nullptr); - EXPECT_EQ(lmp->atom->dihedral_atom1, nullptr); - EXPECT_EQ(lmp->atom->dihedral_atom2, nullptr); - EXPECT_EQ(lmp->atom->dihedral_atom3, nullptr); - EXPECT_EQ(lmp->atom->dihedral_atom4, nullptr); - EXPECT_EQ(lmp->atom->num_improper, nullptr); - EXPECT_EQ(lmp->atom->improper_type, nullptr); - EXPECT_EQ(lmp->atom->improper_atom1, nullptr); - EXPECT_EQ(lmp->atom->improper_atom2, nullptr); - EXPECT_EQ(lmp->atom->improper_atom3, nullptr); - EXPECT_EQ(lmp->atom->improper_atom4, nullptr); - EXPECT_EQ(lmp->atom->maxspecial, 1); - EXPECT_EQ(lmp->atom->nspecial, nullptr); - EXPECT_EQ(lmp->atom->special, nullptr); - EXPECT_EQ(lmp->atom->vfrac, nullptr); - EXPECT_EQ(lmp->atom->s0, nullptr); - EXPECT_EQ(lmp->atom->x0, nullptr); - EXPECT_EQ(lmp->atom->sp, nullptr); - EXPECT_EQ(lmp->atom->fm, nullptr); - EXPECT_EQ(lmp->atom->fm_long, nullptr); - EXPECT_EQ(lmp->atom->spin, nullptr); - EXPECT_EQ(lmp->atom->eradius, nullptr); - EXPECT_EQ(lmp->atom->ervel, nullptr); - EXPECT_EQ(lmp->atom->erforce, nullptr); - EXPECT_EQ(lmp->atom->ervelforce, nullptr); - EXPECT_EQ(lmp->atom->cs, nullptr); - EXPECT_EQ(lmp->atom->csforce, nullptr); - EXPECT_EQ(lmp->atom->vforce, nullptr); - EXPECT_EQ(lmp->atom->etag, nullptr); - EXPECT_EQ(lmp->atom->uCond, nullptr); - EXPECT_EQ(lmp->atom->uMech, nullptr); - EXPECT_EQ(lmp->atom->uChem, nullptr); - EXPECT_EQ(lmp->atom->uCG, nullptr); - EXPECT_EQ(lmp->atom->uCGnew, nullptr); - EXPECT_EQ(lmp->atom->duChem, nullptr); - EXPECT_EQ(lmp->atom->dpdTheta, nullptr); - EXPECT_EQ(lmp->atom->cc, nullptr); - EXPECT_EQ(lmp->atom->cc_flux, nullptr); - EXPECT_EQ(lmp->atom->edpd_temp, nullptr); - EXPECT_EQ(lmp->atom->edpd_flux, nullptr); - EXPECT_EQ(lmp->atom->edpd_cv, nullptr); - EXPECT_EQ(lmp->atom->length, nullptr); - EXPECT_EQ(lmp->atom->buckling, nullptr); - EXPECT_EQ(lmp->atom->bond_nt, nullptr); - EXPECT_EQ(lmp->atom->contact_radius, nullptr); - EXPECT_EQ(lmp->atom->smd_data_9, nullptr); - EXPECT_EQ(lmp->atom->smd_stress, nullptr); - EXPECT_EQ(lmp->atom->eff_plastic_strain, nullptr); - EXPECT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - EXPECT_EQ(lmp->atom->damage, nullptr); - EXPECT_EQ(lmp->atom->rho, nullptr); - EXPECT_EQ(lmp->atom->drho, nullptr); - EXPECT_EQ(lmp->atom->esph, nullptr); - EXPECT_EQ(lmp->atom->desph, nullptr); - EXPECT_EQ(lmp->atom->cv, nullptr); - EXPECT_EQ(lmp->atom->vest, nullptr); - EXPECT_EQ(lmp->atom->nmolecule, 2); - EXPECT_NE(lmp->atom->molecules, nullptr); - EXPECT_EQ(lmp->atom->nivector, 0); - EXPECT_EQ(lmp->atom->ndvector, 0); - EXPECT_EQ(lmp->atom->iname, nullptr); - EXPECT_EQ(lmp->atom->dname, nullptr); - EXPECT_EQ(lmp->atom->mass, nullptr); - EXPECT_EQ(lmp->atom->mass_setflag, nullptr); - EXPECT_EQ(lmp->atom->nextra_grow, 0); - EXPECT_EQ(lmp->atom->nextra_restart, 0); - EXPECT_EQ(lmp->atom->nextra_border, 0); - EXPECT_EQ(lmp->atom->nextra_grow_max, 0); - EXPECT_EQ(lmp->atom->nextra_restart_max, 0); - EXPECT_EQ(lmp->atom->nextra_border_max, 0); - EXPECT_EQ(lmp->atom->nextra_store, 0); - EXPECT_EQ(lmp->atom->extra_grow, nullptr); - EXPECT_EQ(lmp->atom->extra_restart, nullptr); - EXPECT_EQ(lmp->atom->extra_border, nullptr); - EXPECT_EQ(lmp->atom->extra, nullptr); - EXPECT_EQ(lmp->atom->sametag, nullptr); - EXPECT_EQ(lmp->atom->map_style, 3); - EXPECT_EQ(lmp->atom->map_user, 0); - EXPECT_EQ(lmp->atom->map_tag_max, -1); + ASSERT_NE(lmp->atom->tag, nullptr); + ASSERT_NE(lmp->atom->type, nullptr); + ASSERT_NE(lmp->atom->mask, nullptr); + ASSERT_NE(lmp->atom->image, nullptr); + ASSERT_NE(lmp->atom->x, nullptr); + ASSERT_NE(lmp->atom->v, nullptr); + ASSERT_NE(lmp->atom->f, nullptr); + ASSERT_EQ(lmp->atom->q, nullptr); + ASSERT_EQ(lmp->atom->mu, nullptr); + ASSERT_EQ(lmp->atom->omega, nullptr); + ASSERT_EQ(lmp->atom->angmom, nullptr); + ASSERT_EQ(lmp->atom->torque, nullptr); + ASSERT_EQ(lmp->atom->radius, nullptr); + ASSERT_EQ(lmp->atom->rmass, nullptr); + ASSERT_EQ(lmp->atom->ellipsoid, nullptr); + ASSERT_EQ(lmp->atom->line, nullptr); + ASSERT_EQ(lmp->atom->tri, nullptr); + ASSERT_EQ(lmp->atom->body, nullptr); + ASSERT_NE(lmp->atom->molecule, nullptr); + ASSERT_NE(lmp->atom->molindex, nullptr); + ASSERT_NE(lmp->atom->molatom, nullptr); + ASSERT_EQ(lmp->atom->num_bond, nullptr); + ASSERT_EQ(lmp->atom->bond_type, nullptr); + ASSERT_EQ(lmp->atom->bond_atom, nullptr); + ASSERT_EQ(lmp->atom->num_angle, nullptr); + ASSERT_EQ(lmp->atom->angle_type, nullptr); + ASSERT_EQ(lmp->atom->angle_atom1, nullptr); + ASSERT_EQ(lmp->atom->angle_atom2, nullptr); + ASSERT_EQ(lmp->atom->angle_atom3, nullptr); + ASSERT_EQ(lmp->atom->num_dihedral, nullptr); + ASSERT_EQ(lmp->atom->dihedral_type, nullptr); + ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); + ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); + ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); + ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); + ASSERT_EQ(lmp->atom->num_improper, nullptr); + ASSERT_EQ(lmp->atom->improper_type, nullptr); + ASSERT_EQ(lmp->atom->improper_atom1, nullptr); + ASSERT_EQ(lmp->atom->improper_atom2, nullptr); + ASSERT_EQ(lmp->atom->improper_atom3, nullptr); + ASSERT_EQ(lmp->atom->improper_atom4, nullptr); + ASSERT_EQ(lmp->atom->maxspecial, 1); + ASSERT_EQ(lmp->atom->nspecial, nullptr); + ASSERT_EQ(lmp->atom->special, nullptr); + ASSERT_EQ(lmp->atom->vfrac, nullptr); + ASSERT_EQ(lmp->atom->s0, nullptr); + ASSERT_EQ(lmp->atom->x0, nullptr); + ASSERT_EQ(lmp->atom->sp, nullptr); + ASSERT_EQ(lmp->atom->fm, nullptr); + ASSERT_EQ(lmp->atom->fm_long, nullptr); + ASSERT_EQ(lmp->atom->spin, nullptr); + ASSERT_EQ(lmp->atom->eradius, nullptr); + ASSERT_EQ(lmp->atom->ervel, nullptr); + ASSERT_EQ(lmp->atom->erforce, nullptr); + ASSERT_EQ(lmp->atom->ervelforce, nullptr); + ASSERT_EQ(lmp->atom->cs, nullptr); + ASSERT_EQ(lmp->atom->csforce, nullptr); + ASSERT_EQ(lmp->atom->vforce, nullptr); + ASSERT_EQ(lmp->atom->etag, nullptr); + ASSERT_EQ(lmp->atom->uCond, nullptr); + ASSERT_EQ(lmp->atom->uMech, nullptr); + ASSERT_EQ(lmp->atom->uChem, nullptr); + ASSERT_EQ(lmp->atom->uCG, nullptr); + ASSERT_EQ(lmp->atom->uCGnew, nullptr); + ASSERT_EQ(lmp->atom->duChem, nullptr); + ASSERT_EQ(lmp->atom->dpdTheta, nullptr); + ASSERT_EQ(lmp->atom->cc, nullptr); + ASSERT_EQ(lmp->atom->cc_flux, nullptr); + ASSERT_EQ(lmp->atom->edpd_temp, nullptr); + ASSERT_EQ(lmp->atom->edpd_flux, nullptr); + ASSERT_EQ(lmp->atom->edpd_cv, nullptr); + ASSERT_EQ(lmp->atom->length, nullptr); + ASSERT_EQ(lmp->atom->buckling, nullptr); + ASSERT_EQ(lmp->atom->bond_nt, nullptr); + ASSERT_EQ(lmp->atom->contact_radius, nullptr); + ASSERT_EQ(lmp->atom->smd_data_9, nullptr); + ASSERT_EQ(lmp->atom->smd_stress, nullptr); + ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); + ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); + ASSERT_EQ(lmp->atom->damage, nullptr); + ASSERT_EQ(lmp->atom->rho, nullptr); + ASSERT_EQ(lmp->atom->drho, nullptr); + ASSERT_EQ(lmp->atom->esph, nullptr); + ASSERT_EQ(lmp->atom->desph, nullptr); + ASSERT_EQ(lmp->atom->cv, nullptr); + ASSERT_EQ(lmp->atom->vest, nullptr); + ASSERT_EQ(lmp->atom->nmolecule, 2); + ASSERT_NE(lmp->atom->molecules, nullptr); + ASSERT_EQ(lmp->atom->nivector, 0); + ASSERT_EQ(lmp->atom->ndvector, 0); + ASSERT_EQ(lmp->atom->iname, nullptr); + ASSERT_EQ(lmp->atom->dname, nullptr); + ASSERT_EQ(lmp->atom->mass, nullptr); + ASSERT_EQ(lmp->atom->mass_setflag, nullptr); + ASSERT_EQ(lmp->atom->nextra_grow, 0); + ASSERT_EQ(lmp->atom->nextra_restart, 0); + ASSERT_EQ(lmp->atom->nextra_border, 0); + ASSERT_EQ(lmp->atom->nextra_grow_max, 0); + ASSERT_EQ(lmp->atom->nextra_restart_max, 0); + ASSERT_EQ(lmp->atom->nextra_border_max, 0); + ASSERT_EQ(lmp->atom->nextra_store, 0); + ASSERT_EQ(lmp->atom->extra_grow, nullptr); + ASSERT_EQ(lmp->atom->extra_restart, nullptr); + ASSERT_EQ(lmp->atom->extra_border, nullptr); + ASSERT_EQ(lmp->atom->extra, nullptr); + ASSERT_EQ(lmp->atom->sametag, nullptr); + ASSERT_EQ(lmp->atom->map_style, 3); + ASSERT_EQ(lmp->atom->map_user, 0); + ASSERT_EQ(lmp->atom->map_tag_max, -1); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 4 box bond/types 2 angle/types 2 "); @@ -3687,34 +3687,34 @@ TEST_F(AtomStyleTest, template) lmp->input->one("angle_coeff * 109.0"); lmp->input->one("pair_coeff * *"); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_THAT(std::string(lmp->atom->atom_style), Eq("template")); - EXPECT_NE(lmp->atom->avec, nullptr); - EXPECT_EQ(lmp->atom->natoms, 12); - EXPECT_EQ(lmp->atom->nbonds, 6); - EXPECT_EQ(lmp->atom->nbondtypes, 2); - EXPECT_EQ(lmp->atom->nangles, 3); - EXPECT_EQ(lmp->atom->nangletypes, 2); - EXPECT_EQ(lmp->atom->nellipsoids, 0); - EXPECT_EQ(lmp->atom->nlocal, 12); - EXPECT_EQ(lmp->atom->nghost, 0); - EXPECT_NE(lmp->atom->nmax, -1); - EXPECT_EQ(lmp->atom->tag_enable, 1); - EXPECT_EQ(lmp->atom->molecular, Atom::TEMPLATE); - EXPECT_EQ(lmp->atom->ntypes, 4); - EXPECT_EQ(lmp->atom->nextra_grow, 0); - EXPECT_EQ(lmp->atom->nextra_restart, 0); - EXPECT_EQ(lmp->atom->nextra_border, 0); - EXPECT_EQ(lmp->atom->nextra_grow_max, 0); - EXPECT_EQ(lmp->atom->nextra_restart_max, 0); - EXPECT_EQ(lmp->atom->nextra_border_max, 0); - EXPECT_EQ(lmp->atom->nextra_store, 0); - EXPECT_EQ(lmp->atom->extra_grow, nullptr); - EXPECT_EQ(lmp->atom->extra_restart, nullptr); - EXPECT_EQ(lmp->atom->extra_border, nullptr); - EXPECT_EQ(lmp->atom->extra, nullptr); + ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); + ASSERT_NE(lmp->atom->avec, nullptr); + ASSERT_EQ(lmp->atom->natoms, 12); + ASSERT_EQ(lmp->atom->nbonds, 6); + ASSERT_EQ(lmp->atom->nbondtypes, 2); + ASSERT_EQ(lmp->atom->nangles, 3); + ASSERT_EQ(lmp->atom->nangletypes, 2); + ASSERT_EQ(lmp->atom->nellipsoids, 0); + ASSERT_EQ(lmp->atom->nlocal, 12); + ASSERT_EQ(lmp->atom->nghost, 0); + ASSERT_NE(lmp->atom->nmax, -1); + ASSERT_EQ(lmp->atom->tag_enable, 1); + ASSERT_EQ(lmp->atom->molecular, Atom::TEMPLATE); + ASSERT_EQ(lmp->atom->ntypes, 4); + ASSERT_EQ(lmp->atom->nextra_grow, 0); + ASSERT_EQ(lmp->atom->nextra_restart, 0); + ASSERT_EQ(lmp->atom->nextra_border, 0); + ASSERT_EQ(lmp->atom->nextra_grow_max, 0); + ASSERT_EQ(lmp->atom->nextra_restart_max, 0); + ASSERT_EQ(lmp->atom->nextra_border_max, 0); + ASSERT_EQ(lmp->atom->nextra_store, 0); + ASSERT_EQ(lmp->atom->extra_grow, nullptr); + ASSERT_EQ(lmp->atom->extra_restart, nullptr); + ASSERT_EQ(lmp->atom->extra_border, nullptr); + ASSERT_EQ(lmp->atom->extra, nullptr); - EXPECT_NE(lmp->atom->mass, nullptr); - EXPECT_NE(lmp->atom->mass_setflag, nullptr); + ASSERT_NE(lmp->atom->mass, nullptr); + ASSERT_NE(lmp->atom->mass_setflag, nullptr); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("write_data test_atom_styles.data"); @@ -3729,66 +3729,66 @@ TEST_F(AtomStyleTest, template) lmp->input->one("atom_modify map array"); lmp->input->one("read_data test_atom_styles.data"); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_THAT(std::string(lmp->atom->atom_style), Eq("template")); - EXPECT_NE(lmp->atom->avec, nullptr); + ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); + ASSERT_NE(lmp->atom->avec, nullptr); - EXPECT_EQ(lmp->atom->natoms, 12); - EXPECT_EQ(lmp->atom->nlocal, 12); - EXPECT_EQ(lmp->atom->nbonds, 6); - EXPECT_EQ(lmp->atom->nangles, 3); - EXPECT_EQ(lmp->atom->nbondtypes, 2); - EXPECT_EQ(lmp->atom->nangletypes, 2); - EXPECT_EQ(lmp->atom->nghost, 0); - EXPECT_NE(lmp->atom->nmax, -1); - EXPECT_EQ(lmp->atom->tag_enable, 1); - EXPECT_EQ(lmp->atom->molecular, Atom::TEMPLATE); - EXPECT_EQ(lmp->atom->ntypes, 4); - EXPECT_NE(lmp->atom->sametag, nullptr); - EXPECT_EQ(lmp->atom->tag_consecutive(), 1); - EXPECT_EQ(lmp->atom->map_style, Atom::MAP_ARRAY); - EXPECT_EQ(lmp->atom->map_user, 1); - EXPECT_EQ(lmp->atom->map_tag_max, 12); + ASSERT_EQ(lmp->atom->natoms, 12); + ASSERT_EQ(lmp->atom->nlocal, 12); + ASSERT_EQ(lmp->atom->nbonds, 6); + ASSERT_EQ(lmp->atom->nangles, 3); + ASSERT_EQ(lmp->atom->nbondtypes, 2); + ASSERT_EQ(lmp->atom->nangletypes, 2); + ASSERT_EQ(lmp->atom->nghost, 0); + ASSERT_NE(lmp->atom->nmax, -1); + ASSERT_EQ(lmp->atom->tag_enable, 1); + ASSERT_EQ(lmp->atom->molecular, Atom::TEMPLATE); + ASSERT_EQ(lmp->atom->ntypes, 4); + ASSERT_NE(lmp->atom->sametag, nullptr); + ASSERT_EQ(lmp->atom->tag_consecutive(), 1); + ASSERT_EQ(lmp->atom->map_style, Atom::MAP_ARRAY); + ASSERT_EQ(lmp->atom->map_user, 1); + ASSERT_EQ(lmp->atom->map_tag_max, 12); auto molecule = lmp->atom->molecule; auto molindex = lmp->atom->molindex; auto molatom = lmp->atom->molatom; - EXPECT_EQ(molecule[GETIDX(1)], 1); - EXPECT_EQ(molecule[GETIDX(2)], 1); - EXPECT_EQ(molecule[GETIDX(3)], 1); - EXPECT_EQ(molecule[GETIDX(4)], 2); - EXPECT_EQ(molecule[GETIDX(5)], 2); - EXPECT_EQ(molecule[GETIDX(6)], 2); - EXPECT_EQ(molecule[GETIDX(7)], 3); - EXPECT_EQ(molecule[GETIDX(8)], 3); - EXPECT_EQ(molecule[GETIDX(9)], 3); - EXPECT_EQ(molecule[GETIDX(10)], 0); - EXPECT_EQ(molecule[GETIDX(11)], 0); - EXPECT_EQ(molecule[GETIDX(12)], 0); - EXPECT_EQ(molindex[GETIDX(1)], 0); - EXPECT_EQ(molindex[GETIDX(2)], 0); - EXPECT_EQ(molindex[GETIDX(3)], 0); - EXPECT_EQ(molindex[GETIDX(4)], 0); - EXPECT_EQ(molindex[GETIDX(5)], 0); - EXPECT_EQ(molindex[GETIDX(6)], 0); - EXPECT_EQ(molindex[GETIDX(7)], 0); - EXPECT_EQ(molindex[GETIDX(8)], 0); - EXPECT_EQ(molindex[GETIDX(9)], 0); - EXPECT_EQ(molindex[GETIDX(10)], -1); - EXPECT_EQ(molindex[GETIDX(11)], -1); - EXPECT_EQ(molindex[GETIDX(12)], -1); - EXPECT_EQ(molatom[GETIDX(1)], 0); - EXPECT_EQ(molatom[GETIDX(2)], 1); - EXPECT_EQ(molatom[GETIDX(3)], 2); - EXPECT_EQ(molatom[GETIDX(4)], 0); - EXPECT_EQ(molatom[GETIDX(5)], 1); - EXPECT_EQ(molatom[GETIDX(6)], 2); - EXPECT_EQ(molatom[GETIDX(7)], 0); - EXPECT_EQ(molatom[GETIDX(8)], 1); - EXPECT_EQ(molatom[GETIDX(9)], 2); - EXPECT_EQ(molatom[GETIDX(10)], -1); - EXPECT_EQ(molatom[GETIDX(11)], -1); - EXPECT_EQ(molatom[GETIDX(12)], -1); + ASSERT_EQ(molecule[GETIDX(1)], 1); + ASSERT_EQ(molecule[GETIDX(2)], 1); + ASSERT_EQ(molecule[GETIDX(3)], 1); + ASSERT_EQ(molecule[GETIDX(4)], 2); + ASSERT_EQ(molecule[GETIDX(5)], 2); + ASSERT_EQ(molecule[GETIDX(6)], 2); + ASSERT_EQ(molecule[GETIDX(7)], 3); + ASSERT_EQ(molecule[GETIDX(8)], 3); + ASSERT_EQ(molecule[GETIDX(9)], 3); + ASSERT_EQ(molecule[GETIDX(10)], 0); + ASSERT_EQ(molecule[GETIDX(11)], 0); + ASSERT_EQ(molecule[GETIDX(12)], 0); + ASSERT_EQ(molindex[GETIDX(1)], 0); + ASSERT_EQ(molindex[GETIDX(2)], 0); + ASSERT_EQ(molindex[GETIDX(3)], 0); + ASSERT_EQ(molindex[GETIDX(4)], 0); + ASSERT_EQ(molindex[GETIDX(5)], 0); + ASSERT_EQ(molindex[GETIDX(6)], 0); + ASSERT_EQ(molindex[GETIDX(7)], 0); + ASSERT_EQ(molindex[GETIDX(8)], 0); + ASSERT_EQ(molindex[GETIDX(9)], 0); + ASSERT_EQ(molindex[GETIDX(10)], -1); + ASSERT_EQ(molindex[GETIDX(11)], -1); + ASSERT_EQ(molindex[GETIDX(12)], -1); + ASSERT_EQ(molatom[GETIDX(1)], 0); + ASSERT_EQ(molatom[GETIDX(2)], 1); + ASSERT_EQ(molatom[GETIDX(3)], 2); + ASSERT_EQ(molatom[GETIDX(4)], 0); + ASSERT_EQ(molatom[GETIDX(5)], 1); + ASSERT_EQ(molatom[GETIDX(6)], 2); + ASSERT_EQ(molatom[GETIDX(7)], 0); + ASSERT_EQ(molatom[GETIDX(8)], 1); + ASSERT_EQ(molatom[GETIDX(9)], 2); + ASSERT_EQ(molatom[GETIDX(10)], -1); + ASSERT_EQ(molatom[GETIDX(11)], -1); + ASSERT_EQ(molatom[GETIDX(12)], -1); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("clear"); @@ -3801,54 +3801,54 @@ TEST_F(AtomStyleTest, template) lmp->input->one("atom_modify map array"); lmp->input->one("read_data test_atom_styles.data"); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_THAT(std::string(lmp->atom->atom_style), Eq("template")); - EXPECT_NE(lmp->atom->avec, nullptr); + ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); + ASSERT_NE(lmp->atom->avec, nullptr); - EXPECT_EQ(lmp->atom->natoms, 12); - EXPECT_EQ(lmp->atom->nlocal, 12); - EXPECT_EQ(lmp->atom->nbonds, 6); - EXPECT_EQ(lmp->atom->nangles, 3); - EXPECT_EQ(lmp->atom->nbondtypes, 2); - EXPECT_EQ(lmp->atom->nangletypes, 2); - EXPECT_EQ(lmp->atom->nghost, 0); - EXPECT_NE(lmp->atom->nmax, -1); - EXPECT_EQ(lmp->atom->tag_enable, 1); - EXPECT_EQ(lmp->atom->molecular, Atom::TEMPLATE); - EXPECT_EQ(lmp->atom->ntypes, 4); - EXPECT_NE(lmp->atom->sametag, nullptr); - EXPECT_EQ(lmp->atom->tag_consecutive(), 1); - EXPECT_EQ(lmp->atom->map_style, Atom::MAP_ARRAY); - EXPECT_EQ(lmp->atom->map_user, 1); - EXPECT_EQ(lmp->atom->map_tag_max, 12); + ASSERT_EQ(lmp->atom->natoms, 12); + ASSERT_EQ(lmp->atom->nlocal, 12); + ASSERT_EQ(lmp->atom->nbonds, 6); + ASSERT_EQ(lmp->atom->nangles, 3); + ASSERT_EQ(lmp->atom->nbondtypes, 2); + ASSERT_EQ(lmp->atom->nangletypes, 2); + ASSERT_EQ(lmp->atom->nghost, 0); + ASSERT_NE(lmp->atom->nmax, -1); + ASSERT_EQ(lmp->atom->tag_enable, 1); + ASSERT_EQ(lmp->atom->molecular, Atom::TEMPLATE); + ASSERT_EQ(lmp->atom->ntypes, 4); + ASSERT_NE(lmp->atom->sametag, nullptr); + ASSERT_EQ(lmp->atom->tag_consecutive(), 1); + ASSERT_EQ(lmp->atom->map_style, Atom::MAP_ARRAY); + ASSERT_EQ(lmp->atom->map_user, 1); + ASSERT_EQ(lmp->atom->map_tag_max, 12); molecule = lmp->atom->molecule; molindex = lmp->atom->molindex; molatom = lmp->atom->molatom; - EXPECT_EQ(molindex[GETIDX(1)], 0); - EXPECT_EQ(molindex[GETIDX(2)], 0); - EXPECT_EQ(molindex[GETIDX(3)], 0); - EXPECT_EQ(molindex[GETIDX(4)], 0); - EXPECT_EQ(molindex[GETIDX(5)], 0); - EXPECT_EQ(molindex[GETIDX(6)], 0); - EXPECT_EQ(molindex[GETIDX(7)], 0); - EXPECT_EQ(molindex[GETIDX(8)], 0); - EXPECT_EQ(molindex[GETIDX(9)], 0); - EXPECT_EQ(molindex[GETIDX(10)], -1); - EXPECT_EQ(molindex[GETIDX(11)], -1); - EXPECT_EQ(molindex[GETIDX(12)], -1); - EXPECT_EQ(molatom[GETIDX(1)], 0); - EXPECT_EQ(molatom[GETIDX(2)], 1); - EXPECT_EQ(molatom[GETIDX(3)], 2); - EXPECT_EQ(molatom[GETIDX(4)], 0); - EXPECT_EQ(molatom[GETIDX(5)], 1); - EXPECT_EQ(molatom[GETIDX(6)], 2); - EXPECT_EQ(molatom[GETIDX(7)], 0); - EXPECT_EQ(molatom[GETIDX(8)], 1); - EXPECT_EQ(molatom[GETIDX(9)], 2); - EXPECT_EQ(molatom[GETIDX(10)], -1); - EXPECT_EQ(molatom[GETIDX(11)], -1); - EXPECT_EQ(molatom[GETIDX(12)], -1); + ASSERT_EQ(molindex[GETIDX(1)], 0); + ASSERT_EQ(molindex[GETIDX(2)], 0); + ASSERT_EQ(molindex[GETIDX(3)], 0); + ASSERT_EQ(molindex[GETIDX(4)], 0); + ASSERT_EQ(molindex[GETIDX(5)], 0); + ASSERT_EQ(molindex[GETIDX(6)], 0); + ASSERT_EQ(molindex[GETIDX(7)], 0); + ASSERT_EQ(molindex[GETIDX(8)], 0); + ASSERT_EQ(molindex[GETIDX(9)], 0); + ASSERT_EQ(molindex[GETIDX(10)], -1); + ASSERT_EQ(molindex[GETIDX(11)], -1); + ASSERT_EQ(molindex[GETIDX(12)], -1); + ASSERT_EQ(molatom[GETIDX(1)], 0); + ASSERT_EQ(molatom[GETIDX(2)], 1); + ASSERT_EQ(molatom[GETIDX(3)], 2); + ASSERT_EQ(molatom[GETIDX(4)], 0); + ASSERT_EQ(molatom[GETIDX(5)], 1); + ASSERT_EQ(molatom[GETIDX(6)], 2); + ASSERT_EQ(molatom[GETIDX(7)], 0); + ASSERT_EQ(molatom[GETIDX(8)], 1); + ASSERT_EQ(molatom[GETIDX(9)], 2); + ASSERT_EQ(molatom[GETIDX(10)], -1); + ASSERT_EQ(molatom[GETIDX(11)], -1); + ASSERT_EQ(molatom[GETIDX(12)], -1); auto x = lmp->atom->x; auto v = lmp->atom->v; @@ -3899,18 +3899,18 @@ TEST_F(AtomStyleTest, template) EXPECT_NEAR(v[GETIDX(12)][0], 0.0, EPSILON); EXPECT_NEAR(v[GETIDX(12)][1], 0.0, EPSILON); EXPECT_NEAR(v[GETIDX(12)][2], 0.0, EPSILON); - EXPECT_EQ(type[GETIDX(1)], 1); - EXPECT_EQ(type[GETIDX(2)], 2); - EXPECT_EQ(type[GETIDX(3)], 2); - EXPECT_EQ(type[GETIDX(4)], 1); - EXPECT_EQ(type[GETIDX(5)], 2); - EXPECT_EQ(type[GETIDX(6)], 2); - EXPECT_EQ(type[GETIDX(7)], 1); - EXPECT_EQ(type[GETIDX(8)], 2); - EXPECT_EQ(type[GETIDX(9)], 2); - EXPECT_EQ(type[GETIDX(10)], 3); - EXPECT_EQ(type[GETIDX(11)], 3); - EXPECT_EQ(type[GETIDX(12)], 4); + ASSERT_EQ(type[GETIDX(1)], 1); + ASSERT_EQ(type[GETIDX(2)], 2); + ASSERT_EQ(type[GETIDX(3)], 2); + ASSERT_EQ(type[GETIDX(4)], 1); + ASSERT_EQ(type[GETIDX(5)], 2); + ASSERT_EQ(type[GETIDX(6)], 2); + ASSERT_EQ(type[GETIDX(7)], 1); + ASSERT_EQ(type[GETIDX(8)], 2); + ASSERT_EQ(type[GETIDX(9)], 2); + ASSERT_EQ(type[GETIDX(10)], 3); + ASSERT_EQ(type[GETIDX(11)], 3); + ASSERT_EQ(type[GETIDX(12)], 4); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("group two id 7:10"); @@ -3919,50 +3919,119 @@ TEST_F(AtomStyleTest, template) lmp->input->one("clear"); lmp->input->one("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); lmp->input->one("read_restart test_atom_styles.restart"); - // FIXME. - // lmp->input->one("replicate 1 1 2 bbox"); + lmp->input->one("replicate 1 1 2 bbox"); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_THAT(std::string(lmp->atom->atom_style), Eq("template")); - EXPECT_NE(lmp->atom->avec, nullptr); - EXPECT_EQ(lmp->atom->natoms, 8); - EXPECT_EQ(lmp->atom->nlocal, 8); - EXPECT_EQ(lmp->atom->nghost, 0); - EXPECT_NE(lmp->atom->nmax, -1); - EXPECT_EQ(lmp->atom->tag_enable, 1); - EXPECT_EQ(lmp->atom->q_flag, 0); - EXPECT_EQ(lmp->atom->molecular, Atom::TEMPLATE); - EXPECT_EQ(lmp->atom->ntypes, 4); - EXPECT_EQ(lmp->atom->tag_consecutive(), 0); - EXPECT_EQ(lmp->atom->map_tag_max, 12); + ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); + ASSERT_NE(lmp->atom->avec, nullptr); + ASSERT_EQ(lmp->atom->natoms, 16); + ASSERT_EQ(lmp->atom->nbonds, 8); + ASSERT_EQ(lmp->atom->nangles, 4); + ASSERT_EQ(lmp->atom->nlocal, 16); + ASSERT_EQ(lmp->atom->nghost, 0); + ASSERT_NE(lmp->atom->nmax, -1); + ASSERT_EQ(lmp->atom->tag_enable, 1); + ASSERT_EQ(lmp->atom->q_flag, 0); + ASSERT_EQ(lmp->atom->molecular, Atom::TEMPLATE); + ASSERT_EQ(lmp->atom->ntypes, 4); + ASSERT_EQ(lmp->atom->tag_consecutive(), 0); + ASSERT_EQ(lmp->atom->map_tag_max, 24); type = lmp->atom->type; molecule = lmp->atom->molecule; molindex = lmp->atom->molindex; molatom = lmp->atom->molatom; - EXPECT_EQ(type[GETIDX(1)], 1); - EXPECT_EQ(type[GETIDX(2)], 2); - EXPECT_EQ(type[GETIDX(3)], 2); - EXPECT_EQ(type[GETIDX(4)], 1); - EXPECT_EQ(type[GETIDX(5)], 2); - EXPECT_EQ(type[GETIDX(6)], 2); - EXPECT_EQ(type[GETIDX(11)], 3); - EXPECT_EQ(type[GETIDX(12)], 4); + ASSERT_EQ(type[GETIDX(1)], 1); + ASSERT_EQ(type[GETIDX(2)], 2); + ASSERT_EQ(type[GETIDX(3)], 2); + ASSERT_EQ(type[GETIDX(4)], 1); + ASSERT_EQ(type[GETIDX(5)], 2); + ASSERT_EQ(type[GETIDX(6)], 2); + ASSERT_EQ(type[GETIDX(11)], 3); + ASSERT_EQ(type[GETIDX(12)], 4); + ASSERT_EQ(type[GETIDX(13)], 1); + ASSERT_EQ(type[GETIDX(14)], 2); + ASSERT_EQ(type[GETIDX(15)], 2); + ASSERT_EQ(type[GETIDX(16)], 1); + ASSERT_EQ(type[GETIDX(17)], 2); + ASSERT_EQ(type[GETIDX(18)], 2); + ASSERT_EQ(type[GETIDX(23)], 3); + ASSERT_EQ(type[GETIDX(24)], 4); + + ASSERT_EQ(molindex[GETIDX(1)], 0); + ASSERT_EQ(molindex[GETIDX(2)], 0); + ASSERT_EQ(molindex[GETIDX(3)], 0); + ASSERT_EQ(molindex[GETIDX(4)], 0); + ASSERT_EQ(molindex[GETIDX(5)], 0); + ASSERT_EQ(molindex[GETIDX(6)], 0); + ASSERT_EQ(molindex[GETIDX(11)], -1); + ASSERT_EQ(molindex[GETIDX(12)], -1); + ASSERT_EQ(molindex[GETIDX(13)], 0); + ASSERT_EQ(molindex[GETIDX(14)], 0); + ASSERT_EQ(molindex[GETIDX(15)], 0); + ASSERT_EQ(molindex[GETIDX(16)], 0); + ASSERT_EQ(molindex[GETIDX(17)], 0); + ASSERT_EQ(molindex[GETIDX(18)], 0); + ASSERT_EQ(molindex[GETIDX(23)], -1); + ASSERT_EQ(molindex[GETIDX(24)], -1); + ASSERT_EQ(molatom[GETIDX(1)], 0); + ASSERT_EQ(molatom[GETIDX(2)], 1); + ASSERT_EQ(molatom[GETIDX(3)], 2); + ASSERT_EQ(molatom[GETIDX(4)], 0); + ASSERT_EQ(molatom[GETIDX(5)], 1); + ASSERT_EQ(molatom[GETIDX(6)], 2); + ASSERT_EQ(molatom[GETIDX(11)], -1); + ASSERT_EQ(molatom[GETIDX(12)], -1); + ASSERT_EQ(molatom[GETIDX(13)], 0); + ASSERT_EQ(molatom[GETIDX(14)], 1); + ASSERT_EQ(molatom[GETIDX(15)], 2); + ASSERT_EQ(molatom[GETIDX(16)], 0); + ASSERT_EQ(molatom[GETIDX(17)], 1); + ASSERT_EQ(molatom[GETIDX(18)], 2); + ASSERT_EQ(molatom[GETIDX(23)], -1); + ASSERT_EQ(molatom[GETIDX(24)], -1); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("reset_atom_ids"); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_EQ(lmp->atom->tag_consecutive(), 1); - EXPECT_EQ(lmp->atom->map_tag_max, 8); + ASSERT_EQ(lmp->atom->tag_consecutive(), 1); + ASSERT_EQ(lmp->atom->map_tag_max, 16); - type = lmp->atom->type; - EXPECT_EQ(type[GETIDX(1)], 1); - EXPECT_EQ(type[GETIDX(2)], 2); - EXPECT_EQ(type[GETIDX(3)], 2); - EXPECT_EQ(type[GETIDX(4)], 1); - EXPECT_EQ(type[GETIDX(5)], 2); - EXPECT_EQ(type[GETIDX(6)], 2); - EXPECT_EQ(type[GETIDX(7)], 4); - EXPECT_EQ(type[GETIDX(8)], 3); + type = lmp->atom->type; + molecule = lmp->atom->molecule; + molindex = lmp->atom->molindex; + molatom = lmp->atom->molatom; + ASSERT_EQ(type[GETIDX(1)], 1); + ASSERT_EQ(type[GETIDX(2)], 2); + ASSERT_EQ(type[GETIDX(3)], 2); + ASSERT_EQ(type[GETIDX(4)], 1); + ASSERT_EQ(type[GETIDX(5)], 2); + ASSERT_EQ(type[GETIDX(6)], 2); + ASSERT_EQ(type[GETIDX(7)], 4); + ASSERT_EQ(type[GETIDX(8)], 3); + ASSERT_EQ(type[GETIDX(9)], 1); + ASSERT_EQ(type[GETIDX(10)], 2); + ASSERT_EQ(type[GETIDX(11)], 2); + ASSERT_EQ(type[GETIDX(12)], 1); + ASSERT_EQ(type[GETIDX(13)], 2); + ASSERT_EQ(type[GETIDX(14)], 2); + ASSERT_EQ(type[GETIDX(15)], 4); + ASSERT_EQ(type[GETIDX(16)], 3); + ASSERT_EQ(molatom[GETIDX(1)], 0); + ASSERT_EQ(molatom[GETIDX(2)], 1); + ASSERT_EQ(molatom[GETIDX(3)], 2); + ASSERT_EQ(molatom[GETIDX(4)], 0); + ASSERT_EQ(molatom[GETIDX(5)], 1); + ASSERT_EQ(molatom[GETIDX(6)], 2); + ASSERT_EQ(molatom[GETIDX(7)], -1); + ASSERT_EQ(molatom[GETIDX(8)], -1); + ASSERT_EQ(molatom[GETIDX(9)], 0); + ASSERT_EQ(molatom[GETIDX(10)], 1); + ASSERT_EQ(molatom[GETIDX(11)], 2); + ASSERT_EQ(molatom[GETIDX(12)], 0); + ASSERT_EQ(molatom[GETIDX(13)], 1); + ASSERT_EQ(molatom[GETIDX(14)], 2); + ASSERT_EQ(molatom[GETIDX(15)], -1); + ASSERT_EQ(molatom[GETIDX(16)], -1); } TEST_F(AtomStyleTest, template_charge) @@ -3983,191 +4052,191 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_NE(hybrid->styles[0], nullptr); ASSERT_NE(hybrid->styles[1], nullptr); - EXPECT_EQ(lmp->atom->natoms, 0); - EXPECT_EQ(lmp->atom->nlocal, 0); - EXPECT_EQ(lmp->atom->nghost, 0); - EXPECT_EQ(lmp->atom->nmax, 1); - EXPECT_EQ(lmp->atom->tag_enable, 1); - EXPECT_EQ(lmp->atom->molecular, Atom::TEMPLATE); - EXPECT_EQ(lmp->atom->nellipsoids, 0); - EXPECT_EQ(lmp->atom->nlines, 0); - EXPECT_EQ(lmp->atom->ntris, 0); - EXPECT_EQ(lmp->atom->nbodies, 0); - EXPECT_EQ(lmp->atom->nbonds, 0); - EXPECT_EQ(lmp->atom->nangles, 0); - EXPECT_EQ(lmp->atom->ndihedrals, 0); - EXPECT_EQ(lmp->atom->nimpropers, 0); - EXPECT_EQ(lmp->atom->ntypes, 0); - EXPECT_EQ(lmp->atom->nbondtypes, 2); - EXPECT_EQ(lmp->atom->nangletypes, 2); - EXPECT_EQ(lmp->atom->ndihedraltypes, 0); - EXPECT_EQ(lmp->atom->nimpropertypes, 0); - EXPECT_EQ(lmp->atom->bond_per_atom, 0); - EXPECT_EQ(lmp->atom->angle_per_atom, 0); - EXPECT_EQ(lmp->atom->dihedral_per_atom, 0); - EXPECT_EQ(lmp->atom->improper_per_atom, 0); - EXPECT_EQ(lmp->atom->extra_bond_per_atom, 0); - EXPECT_EQ(lmp->atom->extra_angle_per_atom, 0); - EXPECT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - EXPECT_EQ(lmp->atom->extra_improper_per_atom, 0); + ASSERT_EQ(lmp->atom->natoms, 0); + ASSERT_EQ(lmp->atom->nlocal, 0); + ASSERT_EQ(lmp->atom->nghost, 0); + ASSERT_EQ(lmp->atom->nmax, 1); + ASSERT_EQ(lmp->atom->tag_enable, 1); + ASSERT_EQ(lmp->atom->molecular, Atom::TEMPLATE); + ASSERT_EQ(lmp->atom->nellipsoids, 0); + ASSERT_EQ(lmp->atom->nlines, 0); + ASSERT_EQ(lmp->atom->ntris, 0); + ASSERT_EQ(lmp->atom->nbodies, 0); + ASSERT_EQ(lmp->atom->nbonds, 0); + ASSERT_EQ(lmp->atom->nangles, 0); + ASSERT_EQ(lmp->atom->ndihedrals, 0); + ASSERT_EQ(lmp->atom->nimpropers, 0); + ASSERT_EQ(lmp->atom->ntypes, 0); + ASSERT_EQ(lmp->atom->nbondtypes, 2); + ASSERT_EQ(lmp->atom->nangletypes, 2); + ASSERT_EQ(lmp->atom->ndihedraltypes, 0); + ASSERT_EQ(lmp->atom->nimpropertypes, 0); + ASSERT_EQ(lmp->atom->bond_per_atom, 0); + ASSERT_EQ(lmp->atom->angle_per_atom, 0); + ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); + ASSERT_EQ(lmp->atom->improper_per_atom, 0); + ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); + ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); + ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); + ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - EXPECT_EQ(lmp->atom->sphere_flag, 0); - EXPECT_EQ(lmp->atom->ellipsoid_flag, 0); - EXPECT_EQ(lmp->atom->line_flag, 0); - EXPECT_EQ(lmp->atom->tri_flag, 0); - EXPECT_EQ(lmp->atom->body_flag, 0); - EXPECT_EQ(lmp->atom->peri_flag, 0); - EXPECT_EQ(lmp->atom->electron_flag, 0); - EXPECT_EQ(lmp->atom->wavepacket_flag, 0); - EXPECT_EQ(lmp->atom->sph_flag, 0); - EXPECT_EQ(lmp->atom->molecule_flag, 1); - EXPECT_EQ(lmp->atom->molindex_flag, 0); - EXPECT_EQ(lmp->atom->molatom_flag, 0); - EXPECT_EQ(lmp->atom->q_flag, 1); - EXPECT_EQ(lmp->atom->mu_flag, 0); - EXPECT_EQ(lmp->atom->rmass_flag, 0); - EXPECT_EQ(lmp->atom->radius_flag, 0); - EXPECT_EQ(lmp->atom->omega_flag, 0); - EXPECT_EQ(lmp->atom->torque_flag, 0); - EXPECT_EQ(lmp->atom->angmom_flag, 0); - EXPECT_EQ(lmp->atom->vfrac_flag, 0); - EXPECT_EQ(lmp->atom->spin_flag, 0); - EXPECT_EQ(lmp->atom->eradius_flag, 0); - EXPECT_EQ(lmp->atom->ervel_flag, 0); - EXPECT_EQ(lmp->atom->erforce_flag, 0); - EXPECT_EQ(lmp->atom->cs_flag, 0); - EXPECT_EQ(lmp->atom->csforce_flag, 0); - EXPECT_EQ(lmp->atom->vforce_flag, 0); - EXPECT_EQ(lmp->atom->ervelforce_flag, 0); - EXPECT_EQ(lmp->atom->etag_flag, 0); - EXPECT_EQ(lmp->atom->rho_flag, 0); - EXPECT_EQ(lmp->atom->esph_flag, 0); - EXPECT_EQ(lmp->atom->cv_flag, 0); - EXPECT_EQ(lmp->atom->vest_flag, 0); - EXPECT_EQ(lmp->atom->dpd_flag, 0); - EXPECT_EQ(lmp->atom->edpd_flag, 0); - EXPECT_EQ(lmp->atom->tdpd_flag, 0); - EXPECT_EQ(lmp->atom->mesont_flag, 0); - EXPECT_EQ(lmp->atom->sp_flag, 0); - EXPECT_EQ(lmp->atom->x0_flag, 0); - EXPECT_EQ(lmp->atom->smd_flag, 0); - EXPECT_EQ(lmp->atom->damage_flag, 0); - EXPECT_EQ(lmp->atom->contact_radius_flag, 0); - EXPECT_EQ(lmp->atom->smd_data_9_flag, 0); - EXPECT_EQ(lmp->atom->smd_stress_flag, 0); - EXPECT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - EXPECT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - EXPECT_EQ(lmp->atom->pdscale, 1.0); + ASSERT_EQ(lmp->atom->sphere_flag, 0); + ASSERT_EQ(lmp->atom->ellipsoid_flag, 0); + ASSERT_EQ(lmp->atom->line_flag, 0); + ASSERT_EQ(lmp->atom->tri_flag, 0); + ASSERT_EQ(lmp->atom->body_flag, 0); + ASSERT_EQ(lmp->atom->peri_flag, 0); + ASSERT_EQ(lmp->atom->electron_flag, 0); + ASSERT_EQ(lmp->atom->wavepacket_flag, 0); + ASSERT_EQ(lmp->atom->sph_flag, 0); + ASSERT_EQ(lmp->atom->molecule_flag, 1); + ASSERT_EQ(lmp->atom->molindex_flag, 0); + ASSERT_EQ(lmp->atom->molatom_flag, 0); + ASSERT_EQ(lmp->atom->q_flag, 1); + ASSERT_EQ(lmp->atom->mu_flag, 0); + ASSERT_EQ(lmp->atom->rmass_flag, 0); + ASSERT_EQ(lmp->atom->radius_flag, 0); + ASSERT_EQ(lmp->atom->omega_flag, 0); + ASSERT_EQ(lmp->atom->torque_flag, 0); + ASSERT_EQ(lmp->atom->angmom_flag, 0); + ASSERT_EQ(lmp->atom->vfrac_flag, 0); + ASSERT_EQ(lmp->atom->spin_flag, 0); + ASSERT_EQ(lmp->atom->eradius_flag, 0); + ASSERT_EQ(lmp->atom->ervel_flag, 0); + ASSERT_EQ(lmp->atom->erforce_flag, 0); + ASSERT_EQ(lmp->atom->cs_flag, 0); + ASSERT_EQ(lmp->atom->csforce_flag, 0); + ASSERT_EQ(lmp->atom->vforce_flag, 0); + ASSERT_EQ(lmp->atom->ervelforce_flag, 0); + ASSERT_EQ(lmp->atom->etag_flag, 0); + ASSERT_EQ(lmp->atom->rho_flag, 0); + ASSERT_EQ(lmp->atom->esph_flag, 0); + ASSERT_EQ(lmp->atom->cv_flag, 0); + ASSERT_EQ(lmp->atom->vest_flag, 0); + ASSERT_EQ(lmp->atom->dpd_flag, 0); + ASSERT_EQ(lmp->atom->edpd_flag, 0); + ASSERT_EQ(lmp->atom->tdpd_flag, 0); + ASSERT_EQ(lmp->atom->mesont_flag, 0); + ASSERT_EQ(lmp->atom->sp_flag, 0); + ASSERT_EQ(lmp->atom->x0_flag, 0); + ASSERT_EQ(lmp->atom->smd_flag, 0); + ASSERT_EQ(lmp->atom->damage_flag, 0); + ASSERT_EQ(lmp->atom->contact_radius_flag, 0); + ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); + ASSERT_EQ(lmp->atom->smd_stress_flag, 0); + ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); + ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); + ASSERT_EQ(lmp->atom->pdscale, 1.0); - EXPECT_NE(lmp->atom->tag, nullptr); - EXPECT_NE(lmp->atom->type, nullptr); - EXPECT_NE(lmp->atom->mask, nullptr); - EXPECT_NE(lmp->atom->image, nullptr); - EXPECT_NE(lmp->atom->x, nullptr); - EXPECT_NE(lmp->atom->v, nullptr); - EXPECT_NE(lmp->atom->f, nullptr); - EXPECT_NE(lmp->atom->q, nullptr); - EXPECT_EQ(lmp->atom->mu, nullptr); - EXPECT_EQ(lmp->atom->omega, nullptr); - EXPECT_EQ(lmp->atom->angmom, nullptr); - EXPECT_EQ(lmp->atom->torque, nullptr); - EXPECT_EQ(lmp->atom->radius, nullptr); - EXPECT_EQ(lmp->atom->rmass, nullptr); - EXPECT_EQ(lmp->atom->ellipsoid, nullptr); - EXPECT_EQ(lmp->atom->line, nullptr); - EXPECT_EQ(lmp->atom->tri, nullptr); - EXPECT_EQ(lmp->atom->body, nullptr); - EXPECT_NE(lmp->atom->molecule, nullptr); - EXPECT_NE(lmp->atom->molindex, nullptr); - EXPECT_NE(lmp->atom->molatom, nullptr); - EXPECT_EQ(lmp->atom->num_bond, nullptr); - EXPECT_EQ(lmp->atom->bond_type, nullptr); - EXPECT_EQ(lmp->atom->bond_atom, nullptr); - EXPECT_EQ(lmp->atom->num_angle, nullptr); - EXPECT_EQ(lmp->atom->angle_type, nullptr); - EXPECT_EQ(lmp->atom->angle_atom1, nullptr); - EXPECT_EQ(lmp->atom->angle_atom2, nullptr); - EXPECT_EQ(lmp->atom->angle_atom3, nullptr); - EXPECT_EQ(lmp->atom->num_dihedral, nullptr); - EXPECT_EQ(lmp->atom->dihedral_type, nullptr); - EXPECT_EQ(lmp->atom->dihedral_atom1, nullptr); - EXPECT_EQ(lmp->atom->dihedral_atom2, nullptr); - EXPECT_EQ(lmp->atom->dihedral_atom3, nullptr); - EXPECT_EQ(lmp->atom->dihedral_atom4, nullptr); - EXPECT_EQ(lmp->atom->num_improper, nullptr); - EXPECT_EQ(lmp->atom->improper_type, nullptr); - EXPECT_EQ(lmp->atom->improper_atom1, nullptr); - EXPECT_EQ(lmp->atom->improper_atom2, nullptr); - EXPECT_EQ(lmp->atom->improper_atom3, nullptr); - EXPECT_EQ(lmp->atom->improper_atom4, nullptr); - EXPECT_EQ(lmp->atom->maxspecial, 1); - EXPECT_EQ(lmp->atom->nspecial, nullptr); - EXPECT_EQ(lmp->atom->special, nullptr); - EXPECT_EQ(lmp->atom->vfrac, nullptr); - EXPECT_EQ(lmp->atom->s0, nullptr); - EXPECT_EQ(lmp->atom->x0, nullptr); - EXPECT_EQ(lmp->atom->sp, nullptr); - EXPECT_EQ(lmp->atom->fm, nullptr); - EXPECT_EQ(lmp->atom->fm_long, nullptr); - EXPECT_EQ(lmp->atom->spin, nullptr); - EXPECT_EQ(lmp->atom->eradius, nullptr); - EXPECT_EQ(lmp->atom->ervel, nullptr); - EXPECT_EQ(lmp->atom->erforce, nullptr); - EXPECT_EQ(lmp->atom->ervelforce, nullptr); - EXPECT_EQ(lmp->atom->cs, nullptr); - EXPECT_EQ(lmp->atom->csforce, nullptr); - EXPECT_EQ(lmp->atom->vforce, nullptr); - EXPECT_EQ(lmp->atom->etag, nullptr); - EXPECT_EQ(lmp->atom->uCond, nullptr); - EXPECT_EQ(lmp->atom->uMech, nullptr); - EXPECT_EQ(lmp->atom->uChem, nullptr); - EXPECT_EQ(lmp->atom->uCG, nullptr); - EXPECT_EQ(lmp->atom->uCGnew, nullptr); - EXPECT_EQ(lmp->atom->duChem, nullptr); - EXPECT_EQ(lmp->atom->dpdTheta, nullptr); - EXPECT_EQ(lmp->atom->cc, nullptr); - EXPECT_EQ(lmp->atom->cc_flux, nullptr); - EXPECT_EQ(lmp->atom->edpd_temp, nullptr); - EXPECT_EQ(lmp->atom->edpd_flux, nullptr); - EXPECT_EQ(lmp->atom->edpd_cv, nullptr); - EXPECT_EQ(lmp->atom->length, nullptr); - EXPECT_EQ(lmp->atom->buckling, nullptr); - EXPECT_EQ(lmp->atom->bond_nt, nullptr); - EXPECT_EQ(lmp->atom->contact_radius, nullptr); - EXPECT_EQ(lmp->atom->smd_data_9, nullptr); - EXPECT_EQ(lmp->atom->smd_stress, nullptr); - EXPECT_EQ(lmp->atom->eff_plastic_strain, nullptr); - EXPECT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - EXPECT_EQ(lmp->atom->damage, nullptr); - EXPECT_EQ(lmp->atom->rho, nullptr); - EXPECT_EQ(lmp->atom->drho, nullptr); - EXPECT_EQ(lmp->atom->esph, nullptr); - EXPECT_EQ(lmp->atom->desph, nullptr); - EXPECT_EQ(lmp->atom->cv, nullptr); - EXPECT_EQ(lmp->atom->vest, nullptr); - EXPECT_EQ(lmp->atom->nmolecule, 2); - EXPECT_NE(lmp->atom->molecules, nullptr); - EXPECT_EQ(lmp->atom->nivector, 0); - EXPECT_EQ(lmp->atom->ndvector, 0); - EXPECT_EQ(lmp->atom->iname, nullptr); - EXPECT_EQ(lmp->atom->dname, nullptr); - EXPECT_EQ(lmp->atom->mass, nullptr); - EXPECT_EQ(lmp->atom->mass_setflag, nullptr); - EXPECT_EQ(lmp->atom->nextra_grow, 0); - EXPECT_EQ(lmp->atom->nextra_restart, 0); - EXPECT_EQ(lmp->atom->nextra_border, 0); - EXPECT_EQ(lmp->atom->nextra_grow_max, 0); - EXPECT_EQ(lmp->atom->nextra_restart_max, 0); - EXPECT_EQ(lmp->atom->nextra_border_max, 0); - EXPECT_EQ(lmp->atom->nextra_store, 0); - EXPECT_EQ(lmp->atom->extra_grow, nullptr); - EXPECT_EQ(lmp->atom->extra_restart, nullptr); - EXPECT_EQ(lmp->atom->extra_border, nullptr); - EXPECT_EQ(lmp->atom->extra, nullptr); - EXPECT_EQ(lmp->atom->sametag, nullptr); - EXPECT_EQ(lmp->atom->map_style, 3); - EXPECT_EQ(lmp->atom->map_user, 0); - EXPECT_EQ(lmp->atom->map_tag_max, -1); + ASSERT_NE(lmp->atom->tag, nullptr); + ASSERT_NE(lmp->atom->type, nullptr); + ASSERT_NE(lmp->atom->mask, nullptr); + ASSERT_NE(lmp->atom->image, nullptr); + ASSERT_NE(lmp->atom->x, nullptr); + ASSERT_NE(lmp->atom->v, nullptr); + ASSERT_NE(lmp->atom->f, nullptr); + ASSERT_NE(lmp->atom->q, nullptr); + ASSERT_EQ(lmp->atom->mu, nullptr); + ASSERT_EQ(lmp->atom->omega, nullptr); + ASSERT_EQ(lmp->atom->angmom, nullptr); + ASSERT_EQ(lmp->atom->torque, nullptr); + ASSERT_EQ(lmp->atom->radius, nullptr); + ASSERT_EQ(lmp->atom->rmass, nullptr); + ASSERT_EQ(lmp->atom->ellipsoid, nullptr); + ASSERT_EQ(lmp->atom->line, nullptr); + ASSERT_EQ(lmp->atom->tri, nullptr); + ASSERT_EQ(lmp->atom->body, nullptr); + ASSERT_NE(lmp->atom->molecule, nullptr); + ASSERT_NE(lmp->atom->molindex, nullptr); + ASSERT_NE(lmp->atom->molatom, nullptr); + ASSERT_EQ(lmp->atom->num_bond, nullptr); + ASSERT_EQ(lmp->atom->bond_type, nullptr); + ASSERT_EQ(lmp->atom->bond_atom, nullptr); + ASSERT_EQ(lmp->atom->num_angle, nullptr); + ASSERT_EQ(lmp->atom->angle_type, nullptr); + ASSERT_EQ(lmp->atom->angle_atom1, nullptr); + ASSERT_EQ(lmp->atom->angle_atom2, nullptr); + ASSERT_EQ(lmp->atom->angle_atom3, nullptr); + ASSERT_EQ(lmp->atom->num_dihedral, nullptr); + ASSERT_EQ(lmp->atom->dihedral_type, nullptr); + ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); + ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); + ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); + ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); + ASSERT_EQ(lmp->atom->num_improper, nullptr); + ASSERT_EQ(lmp->atom->improper_type, nullptr); + ASSERT_EQ(lmp->atom->improper_atom1, nullptr); + ASSERT_EQ(lmp->atom->improper_atom2, nullptr); + ASSERT_EQ(lmp->atom->improper_atom3, nullptr); + ASSERT_EQ(lmp->atom->improper_atom4, nullptr); + ASSERT_EQ(lmp->atom->maxspecial, 1); + ASSERT_EQ(lmp->atom->nspecial, nullptr); + ASSERT_EQ(lmp->atom->special, nullptr); + ASSERT_EQ(lmp->atom->vfrac, nullptr); + ASSERT_EQ(lmp->atom->s0, nullptr); + ASSERT_EQ(lmp->atom->x0, nullptr); + ASSERT_EQ(lmp->atom->sp, nullptr); + ASSERT_EQ(lmp->atom->fm, nullptr); + ASSERT_EQ(lmp->atom->fm_long, nullptr); + ASSERT_EQ(lmp->atom->spin, nullptr); + ASSERT_EQ(lmp->atom->eradius, nullptr); + ASSERT_EQ(lmp->atom->ervel, nullptr); + ASSERT_EQ(lmp->atom->erforce, nullptr); + ASSERT_EQ(lmp->atom->ervelforce, nullptr); + ASSERT_EQ(lmp->atom->cs, nullptr); + ASSERT_EQ(lmp->atom->csforce, nullptr); + ASSERT_EQ(lmp->atom->vforce, nullptr); + ASSERT_EQ(lmp->atom->etag, nullptr); + ASSERT_EQ(lmp->atom->uCond, nullptr); + ASSERT_EQ(lmp->atom->uMech, nullptr); + ASSERT_EQ(lmp->atom->uChem, nullptr); + ASSERT_EQ(lmp->atom->uCG, nullptr); + ASSERT_EQ(lmp->atom->uCGnew, nullptr); + ASSERT_EQ(lmp->atom->duChem, nullptr); + ASSERT_EQ(lmp->atom->dpdTheta, nullptr); + ASSERT_EQ(lmp->atom->cc, nullptr); + ASSERT_EQ(lmp->atom->cc_flux, nullptr); + ASSERT_EQ(lmp->atom->edpd_temp, nullptr); + ASSERT_EQ(lmp->atom->edpd_flux, nullptr); + ASSERT_EQ(lmp->atom->edpd_cv, nullptr); + ASSERT_EQ(lmp->atom->length, nullptr); + ASSERT_EQ(lmp->atom->buckling, nullptr); + ASSERT_EQ(lmp->atom->bond_nt, nullptr); + ASSERT_EQ(lmp->atom->contact_radius, nullptr); + ASSERT_EQ(lmp->atom->smd_data_9, nullptr); + ASSERT_EQ(lmp->atom->smd_stress, nullptr); + ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); + ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); + ASSERT_EQ(lmp->atom->damage, nullptr); + ASSERT_EQ(lmp->atom->rho, nullptr); + ASSERT_EQ(lmp->atom->drho, nullptr); + ASSERT_EQ(lmp->atom->esph, nullptr); + ASSERT_EQ(lmp->atom->desph, nullptr); + ASSERT_EQ(lmp->atom->cv, nullptr); + ASSERT_EQ(lmp->atom->vest, nullptr); + ASSERT_EQ(lmp->atom->nmolecule, 2); + ASSERT_NE(lmp->atom->molecules, nullptr); + ASSERT_EQ(lmp->atom->nivector, 0); + ASSERT_EQ(lmp->atom->ndvector, 0); + ASSERT_EQ(lmp->atom->iname, nullptr); + ASSERT_EQ(lmp->atom->dname, nullptr); + ASSERT_EQ(lmp->atom->mass, nullptr); + ASSERT_EQ(lmp->atom->mass_setflag, nullptr); + ASSERT_EQ(lmp->atom->nextra_grow, 0); + ASSERT_EQ(lmp->atom->nextra_restart, 0); + ASSERT_EQ(lmp->atom->nextra_border, 0); + ASSERT_EQ(lmp->atom->nextra_grow_max, 0); + ASSERT_EQ(lmp->atom->nextra_restart_max, 0); + ASSERT_EQ(lmp->atom->nextra_border_max, 0); + ASSERT_EQ(lmp->atom->nextra_store, 0); + ASSERT_EQ(lmp->atom->extra_grow, nullptr); + ASSERT_EQ(lmp->atom->extra_restart, nullptr); + ASSERT_EQ(lmp->atom->extra_border, nullptr); + ASSERT_EQ(lmp->atom->extra, nullptr); + ASSERT_EQ(lmp->atom->sametag, nullptr); + ASSERT_EQ(lmp->atom->map_style, 3); + ASSERT_EQ(lmp->atom->map_user, 0); + ASSERT_EQ(lmp->atom->map_tag_max, -1); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 4 box bond/types 2 angle/types 2 "); @@ -4200,33 +4269,33 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_NE(hybrid->styles[0], nullptr); ASSERT_NE(hybrid->styles[1], nullptr); - EXPECT_EQ(lmp->atom->natoms, 12); - EXPECT_EQ(lmp->atom->nbonds, 6); - EXPECT_EQ(lmp->atom->nbondtypes, 2); - EXPECT_EQ(lmp->atom->nangles, 3); - EXPECT_EQ(lmp->atom->nangletypes, 2); - EXPECT_EQ(lmp->atom->nellipsoids, 0); - EXPECT_EQ(lmp->atom->nlocal, 12); - EXPECT_EQ(lmp->atom->nghost, 0); - EXPECT_NE(lmp->atom->nmax, -1); - EXPECT_EQ(lmp->atom->tag_enable, 1); - EXPECT_EQ(lmp->atom->molecular, Atom::TEMPLATE); - EXPECT_EQ(lmp->atom->q_flag, 1); - EXPECT_EQ(lmp->atom->ntypes, 4); - EXPECT_EQ(lmp->atom->nextra_grow, 0); - EXPECT_EQ(lmp->atom->nextra_restart, 0); - EXPECT_EQ(lmp->atom->nextra_border, 0); - EXPECT_EQ(lmp->atom->nextra_grow_max, 0); - EXPECT_EQ(lmp->atom->nextra_restart_max, 0); - EXPECT_EQ(lmp->atom->nextra_border_max, 0); - EXPECT_EQ(lmp->atom->nextra_store, 0); - EXPECT_EQ(lmp->atom->extra_grow, nullptr); - EXPECT_EQ(lmp->atom->extra_restart, nullptr); - EXPECT_EQ(lmp->atom->extra_border, nullptr); - EXPECT_EQ(lmp->atom->extra, nullptr); + ASSERT_EQ(lmp->atom->natoms, 12); + ASSERT_EQ(lmp->atom->nbonds, 6); + ASSERT_EQ(lmp->atom->nbondtypes, 2); + ASSERT_EQ(lmp->atom->nangles, 3); + ASSERT_EQ(lmp->atom->nangletypes, 2); + ASSERT_EQ(lmp->atom->nellipsoids, 0); + ASSERT_EQ(lmp->atom->nlocal, 12); + ASSERT_EQ(lmp->atom->nghost, 0); + ASSERT_NE(lmp->atom->nmax, -1); + ASSERT_EQ(lmp->atom->tag_enable, 1); + ASSERT_EQ(lmp->atom->molecular, Atom::TEMPLATE); + ASSERT_EQ(lmp->atom->q_flag, 1); + ASSERT_EQ(lmp->atom->ntypes, 4); + ASSERT_EQ(lmp->atom->nextra_grow, 0); + ASSERT_EQ(lmp->atom->nextra_restart, 0); + ASSERT_EQ(lmp->atom->nextra_border, 0); + ASSERT_EQ(lmp->atom->nextra_grow_max, 0); + ASSERT_EQ(lmp->atom->nextra_restart_max, 0); + ASSERT_EQ(lmp->atom->nextra_border_max, 0); + ASSERT_EQ(lmp->atom->nextra_store, 0); + ASSERT_EQ(lmp->atom->extra_grow, nullptr); + ASSERT_EQ(lmp->atom->extra_restart, nullptr); + ASSERT_EQ(lmp->atom->extra_border, nullptr); + ASSERT_EQ(lmp->atom->extra, nullptr); - EXPECT_NE(lmp->atom->mass, nullptr); - EXPECT_NE(lmp->atom->mass_setflag, nullptr); + ASSERT_NE(lmp->atom->mass, nullptr); + ASSERT_NE(lmp->atom->mass_setflag, nullptr); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("write_data test_atom_styles.data"); @@ -4241,66 +4310,66 @@ TEST_F(AtomStyleTest, template_charge) lmp->input->one("atom_modify map array"); lmp->input->one("read_data test_atom_styles.data"); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); - EXPECT_NE(lmp->atom->avec, nullptr); + ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); + ASSERT_NE(lmp->atom->avec, nullptr); - EXPECT_EQ(lmp->atom->natoms, 12); - EXPECT_EQ(lmp->atom->nlocal, 12); - EXPECT_EQ(lmp->atom->nbonds, 6); - EXPECT_EQ(lmp->atom->nangles, 3); - EXPECT_EQ(lmp->atom->nbondtypes, 2); - EXPECT_EQ(lmp->atom->nangletypes, 2); - EXPECT_EQ(lmp->atom->nghost, 0); - EXPECT_NE(lmp->atom->nmax, -1); - EXPECT_EQ(lmp->atom->tag_enable, 1); - EXPECT_EQ(lmp->atom->molecular, Atom::TEMPLATE); - EXPECT_EQ(lmp->atom->ntypes, 4); - EXPECT_NE(lmp->atom->sametag, nullptr); - EXPECT_EQ(lmp->atom->tag_consecutive(), 1); - EXPECT_EQ(lmp->atom->map_style, Atom::MAP_ARRAY); - EXPECT_EQ(lmp->atom->map_user, 1); - EXPECT_EQ(lmp->atom->map_tag_max, 12); + ASSERT_EQ(lmp->atom->natoms, 12); + ASSERT_EQ(lmp->atom->nlocal, 12); + ASSERT_EQ(lmp->atom->nbonds, 6); + ASSERT_EQ(lmp->atom->nangles, 3); + ASSERT_EQ(lmp->atom->nbondtypes, 2); + ASSERT_EQ(lmp->atom->nangletypes, 2); + ASSERT_EQ(lmp->atom->nghost, 0); + ASSERT_NE(lmp->atom->nmax, -1); + ASSERT_EQ(lmp->atom->tag_enable, 1); + ASSERT_EQ(lmp->atom->molecular, Atom::TEMPLATE); + ASSERT_EQ(lmp->atom->ntypes, 4); + ASSERT_NE(lmp->atom->sametag, nullptr); + ASSERT_EQ(lmp->atom->tag_consecutive(), 1); + ASSERT_EQ(lmp->atom->map_style, Atom::MAP_ARRAY); + ASSERT_EQ(lmp->atom->map_user, 1); + ASSERT_EQ(lmp->atom->map_tag_max, 12); auto molecule = lmp->atom->molecule; auto molindex = lmp->atom->molindex; auto molatom = lmp->atom->molatom; - EXPECT_EQ(molecule[GETIDX(1)], 1); - EXPECT_EQ(molecule[GETIDX(2)], 1); - EXPECT_EQ(molecule[GETIDX(3)], 1); - EXPECT_EQ(molecule[GETIDX(4)], 2); - EXPECT_EQ(molecule[GETIDX(5)], 2); - EXPECT_EQ(molecule[GETIDX(6)], 2); - EXPECT_EQ(molecule[GETIDX(7)], 3); - EXPECT_EQ(molecule[GETIDX(8)], 3); - EXPECT_EQ(molecule[GETIDX(9)], 3); - EXPECT_EQ(molecule[GETIDX(10)], 0); - EXPECT_EQ(molecule[GETIDX(11)], 0); - EXPECT_EQ(molecule[GETIDX(12)], 0); - EXPECT_EQ(molindex[GETIDX(1)], 0); - EXPECT_EQ(molindex[GETIDX(2)], 0); - EXPECT_EQ(molindex[GETIDX(3)], 0); - EXPECT_EQ(molindex[GETIDX(4)], 0); - EXPECT_EQ(molindex[GETIDX(5)], 0); - EXPECT_EQ(molindex[GETIDX(6)], 0); - EXPECT_EQ(molindex[GETIDX(7)], 0); - EXPECT_EQ(molindex[GETIDX(8)], 0); - EXPECT_EQ(molindex[GETIDX(9)], 0); - EXPECT_EQ(molindex[GETIDX(10)], -1); - EXPECT_EQ(molindex[GETIDX(11)], -1); - EXPECT_EQ(molindex[GETIDX(12)], -1); - EXPECT_EQ(molatom[GETIDX(1)], 0); - EXPECT_EQ(molatom[GETIDX(2)], 1); - EXPECT_EQ(molatom[GETIDX(3)], 2); - EXPECT_EQ(molatom[GETIDX(4)], 0); - EXPECT_EQ(molatom[GETIDX(5)], 1); - EXPECT_EQ(molatom[GETIDX(6)], 2); - EXPECT_EQ(molatom[GETIDX(7)], 0); - EXPECT_EQ(molatom[GETIDX(8)], 1); - EXPECT_EQ(molatom[GETIDX(9)], 2); - EXPECT_EQ(molatom[GETIDX(10)], -1); - EXPECT_EQ(molatom[GETIDX(11)], -1); - EXPECT_EQ(molatom[GETIDX(12)], -1); + ASSERT_EQ(molecule[GETIDX(1)], 1); + ASSERT_EQ(molecule[GETIDX(2)], 1); + ASSERT_EQ(molecule[GETIDX(3)], 1); + ASSERT_EQ(molecule[GETIDX(4)], 2); + ASSERT_EQ(molecule[GETIDX(5)], 2); + ASSERT_EQ(molecule[GETIDX(6)], 2); + ASSERT_EQ(molecule[GETIDX(7)], 3); + ASSERT_EQ(molecule[GETIDX(8)], 3); + ASSERT_EQ(molecule[GETIDX(9)], 3); + ASSERT_EQ(molecule[GETIDX(10)], 0); + ASSERT_EQ(molecule[GETIDX(11)], 0); + ASSERT_EQ(molecule[GETIDX(12)], 0); + ASSERT_EQ(molindex[GETIDX(1)], 0); + ASSERT_EQ(molindex[GETIDX(2)], 0); + ASSERT_EQ(molindex[GETIDX(3)], 0); + ASSERT_EQ(molindex[GETIDX(4)], 0); + ASSERT_EQ(molindex[GETIDX(5)], 0); + ASSERT_EQ(molindex[GETIDX(6)], 0); + ASSERT_EQ(molindex[GETIDX(7)], 0); + ASSERT_EQ(molindex[GETIDX(8)], 0); + ASSERT_EQ(molindex[GETIDX(9)], 0); + ASSERT_EQ(molindex[GETIDX(10)], -1); + ASSERT_EQ(molindex[GETIDX(11)], -1); + ASSERT_EQ(molindex[GETIDX(12)], -1); + ASSERT_EQ(molatom[GETIDX(1)], 0); + ASSERT_EQ(molatom[GETIDX(2)], 1); + ASSERT_EQ(molatom[GETIDX(3)], 2); + ASSERT_EQ(molatom[GETIDX(4)], 0); + ASSERT_EQ(molatom[GETIDX(5)], 1); + ASSERT_EQ(molatom[GETIDX(6)], 2); + ASSERT_EQ(molatom[GETIDX(7)], 0); + ASSERT_EQ(molatom[GETIDX(8)], 1); + ASSERT_EQ(molatom[GETIDX(9)], 2); + ASSERT_EQ(molatom[GETIDX(10)], -1); + ASSERT_EQ(molatom[GETIDX(11)], -1); + ASSERT_EQ(molatom[GETIDX(12)], -1); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("clear"); @@ -4313,54 +4382,54 @@ TEST_F(AtomStyleTest, template_charge) lmp->input->one("atom_modify map array"); lmp->input->one("read_data test_atom_styles.data"); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); - EXPECT_NE(lmp->atom->avec, nullptr); + ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); + ASSERT_NE(lmp->atom->avec, nullptr); - EXPECT_EQ(lmp->atom->natoms, 12); - EXPECT_EQ(lmp->atom->nlocal, 12); - EXPECT_EQ(lmp->atom->nbonds, 6); - EXPECT_EQ(lmp->atom->nangles, 3); - EXPECT_EQ(lmp->atom->nbondtypes, 2); - EXPECT_EQ(lmp->atom->nangletypes, 2); - EXPECT_EQ(lmp->atom->nghost, 0); - EXPECT_NE(lmp->atom->nmax, -1); - EXPECT_EQ(lmp->atom->tag_enable, 1); - EXPECT_EQ(lmp->atom->molecular, Atom::TEMPLATE); - EXPECT_EQ(lmp->atom->ntypes, 4); - EXPECT_NE(lmp->atom->sametag, nullptr); - EXPECT_EQ(lmp->atom->tag_consecutive(), 1); - EXPECT_EQ(lmp->atom->map_style, Atom::MAP_ARRAY); - EXPECT_EQ(lmp->atom->map_user, 1); - EXPECT_EQ(lmp->atom->map_tag_max, 12); + ASSERT_EQ(lmp->atom->natoms, 12); + ASSERT_EQ(lmp->atom->nlocal, 12); + ASSERT_EQ(lmp->atom->nbonds, 6); + ASSERT_EQ(lmp->atom->nangles, 3); + ASSERT_EQ(lmp->atom->nbondtypes, 2); + ASSERT_EQ(lmp->atom->nangletypes, 2); + ASSERT_EQ(lmp->atom->nghost, 0); + ASSERT_NE(lmp->atom->nmax, -1); + ASSERT_EQ(lmp->atom->tag_enable, 1); + ASSERT_EQ(lmp->atom->molecular, Atom::TEMPLATE); + ASSERT_EQ(lmp->atom->ntypes, 4); + ASSERT_NE(lmp->atom->sametag, nullptr); + ASSERT_EQ(lmp->atom->tag_consecutive(), 1); + ASSERT_EQ(lmp->atom->map_style, Atom::MAP_ARRAY); + ASSERT_EQ(lmp->atom->map_user, 1); + ASSERT_EQ(lmp->atom->map_tag_max, 12); molecule = lmp->atom->molecule; molindex = lmp->atom->molindex; molatom = lmp->atom->molatom; - EXPECT_EQ(molindex[GETIDX(1)], 0); - EXPECT_EQ(molindex[GETIDX(2)], 0); - EXPECT_EQ(molindex[GETIDX(3)], 0); - EXPECT_EQ(molindex[GETIDX(4)], 0); - EXPECT_EQ(molindex[GETIDX(5)], 0); - EXPECT_EQ(molindex[GETIDX(6)], 0); - EXPECT_EQ(molindex[GETIDX(7)], 0); - EXPECT_EQ(molindex[GETIDX(8)], 0); - EXPECT_EQ(molindex[GETIDX(9)], 0); - EXPECT_EQ(molindex[GETIDX(10)], -1); - EXPECT_EQ(molindex[GETIDX(11)], -1); - EXPECT_EQ(molindex[GETIDX(12)], -1); - EXPECT_EQ(molatom[GETIDX(1)], 0); - EXPECT_EQ(molatom[GETIDX(2)], 1); - EXPECT_EQ(molatom[GETIDX(3)], 2); - EXPECT_EQ(molatom[GETIDX(4)], 0); - EXPECT_EQ(molatom[GETIDX(5)], 1); - EXPECT_EQ(molatom[GETIDX(6)], 2); - EXPECT_EQ(molatom[GETIDX(7)], 0); - EXPECT_EQ(molatom[GETIDX(8)], 1); - EXPECT_EQ(molatom[GETIDX(9)], 2); - EXPECT_EQ(molatom[GETIDX(10)], -1); - EXPECT_EQ(molatom[GETIDX(11)], -1); - EXPECT_EQ(molatom[GETIDX(12)], -1); + ASSERT_EQ(molindex[GETIDX(1)], 0); + ASSERT_EQ(molindex[GETIDX(2)], 0); + ASSERT_EQ(molindex[GETIDX(3)], 0); + ASSERT_EQ(molindex[GETIDX(4)], 0); + ASSERT_EQ(molindex[GETIDX(5)], 0); + ASSERT_EQ(molindex[GETIDX(6)], 0); + ASSERT_EQ(molindex[GETIDX(7)], 0); + ASSERT_EQ(molindex[GETIDX(8)], 0); + ASSERT_EQ(molindex[GETIDX(9)], 0); + ASSERT_EQ(molindex[GETIDX(10)], -1); + ASSERT_EQ(molindex[GETIDX(11)], -1); + ASSERT_EQ(molindex[GETIDX(12)], -1); + ASSERT_EQ(molatom[GETIDX(1)], 0); + ASSERT_EQ(molatom[GETIDX(2)], 1); + ASSERT_EQ(molatom[GETIDX(3)], 2); + ASSERT_EQ(molatom[GETIDX(4)], 0); + ASSERT_EQ(molatom[GETIDX(5)], 1); + ASSERT_EQ(molatom[GETIDX(6)], 2); + ASSERT_EQ(molatom[GETIDX(7)], 0); + ASSERT_EQ(molatom[GETIDX(8)], 1); + ASSERT_EQ(molatom[GETIDX(9)], 2); + ASSERT_EQ(molatom[GETIDX(10)], -1); + ASSERT_EQ(molatom[GETIDX(11)], -1); + ASSERT_EQ(molatom[GETIDX(12)], -1); auto x = lmp->atom->x; auto v = lmp->atom->v; @@ -4424,18 +4493,18 @@ TEST_F(AtomStyleTest, template_charge) EXPECT_NEAR(q[GETIDX(10)], 0.7, EPSILON); EXPECT_NEAR(q[GETIDX(11)], -0.35, EPSILON); EXPECT_NEAR(q[GETIDX(12)], -0.35, EPSILON); - EXPECT_EQ(type[GETIDX(1)], 1); - EXPECT_EQ(type[GETIDX(2)], 2); - EXPECT_EQ(type[GETIDX(3)], 2); - EXPECT_EQ(type[GETIDX(4)], 1); - EXPECT_EQ(type[GETIDX(5)], 2); - EXPECT_EQ(type[GETIDX(6)], 2); - EXPECT_EQ(type[GETIDX(7)], 1); - EXPECT_EQ(type[GETIDX(8)], 2); - EXPECT_EQ(type[GETIDX(9)], 2); - EXPECT_EQ(type[GETIDX(10)], 3); - EXPECT_EQ(type[GETIDX(11)], 3); - EXPECT_EQ(type[GETIDX(12)], 4); + ASSERT_EQ(type[GETIDX(1)], 1); + ASSERT_EQ(type[GETIDX(2)], 2); + ASSERT_EQ(type[GETIDX(3)], 2); + ASSERT_EQ(type[GETIDX(4)], 1); + ASSERT_EQ(type[GETIDX(5)], 2); + ASSERT_EQ(type[GETIDX(6)], 2); + ASSERT_EQ(type[GETIDX(7)], 1); + ASSERT_EQ(type[GETIDX(8)], 2); + ASSERT_EQ(type[GETIDX(9)], 2); + ASSERT_EQ(type[GETIDX(10)], 3); + ASSERT_EQ(type[GETIDX(11)], 3); + ASSERT_EQ(type[GETIDX(12)], 4); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("group two id 7:10"); @@ -4444,49 +4513,120 @@ TEST_F(AtomStyleTest, template_charge) lmp->input->one("clear"); lmp->input->one("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); lmp->input->one("read_restart test_atom_styles.restart"); - // FIXME. - // lmp->input->one("replicate 1 1 2 bbox"); + lmp->input->one("replicate 1 1 2 bbox"); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); - EXPECT_NE(lmp->atom->avec, nullptr); - EXPECT_EQ(lmp->atom->natoms, 8); - EXPECT_EQ(lmp->atom->nlocal, 8); - EXPECT_EQ(lmp->atom->nghost, 0); - EXPECT_NE(lmp->atom->nmax, -1); - EXPECT_EQ(lmp->atom->tag_enable, 1); - EXPECT_EQ(lmp->atom->molecular, Atom::TEMPLATE); - EXPECT_EQ(lmp->atom->ntypes, 4); - EXPECT_EQ(lmp->atom->tag_consecutive(), 0); - EXPECT_EQ(lmp->atom->map_tag_max, 12); + ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); + ASSERT_NE(lmp->atom->avec, nullptr); + ASSERT_EQ(lmp->atom->natoms, 16); + + ASSERT_EQ(lmp->atom->nlocal, 16); + ASSERT_EQ(lmp->atom->nghost, 0); + ASSERT_NE(lmp->atom->nmax, -1); + ASSERT_EQ(lmp->atom->tag_enable, 1); + ASSERT_EQ(lmp->atom->molecular, Atom::TEMPLATE); + ASSERT_EQ(lmp->atom->ntypes, 4); + ASSERT_EQ(lmp->atom->nbonds, 8); + ASSERT_EQ(lmp->atom->nangles, 4); + ASSERT_EQ(lmp->atom->tag_consecutive(), 0); + ASSERT_EQ(lmp->atom->map_tag_max, 24); type = lmp->atom->type; molecule = lmp->atom->molecule; molindex = lmp->atom->molindex; molatom = lmp->atom->molatom; - EXPECT_EQ(type[GETIDX(1)], 1); - EXPECT_EQ(type[GETIDX(2)], 2); - EXPECT_EQ(type[GETIDX(3)], 2); - EXPECT_EQ(type[GETIDX(4)], 1); - EXPECT_EQ(type[GETIDX(5)], 2); - EXPECT_EQ(type[GETIDX(6)], 2); - EXPECT_EQ(type[GETIDX(11)], 3); - EXPECT_EQ(type[GETIDX(12)], 4); + ASSERT_EQ(type[GETIDX(1)], 1); + ASSERT_EQ(type[GETIDX(2)], 2); + ASSERT_EQ(type[GETIDX(3)], 2); + ASSERT_EQ(type[GETIDX(4)], 1); + ASSERT_EQ(type[GETIDX(5)], 2); + ASSERT_EQ(type[GETIDX(6)], 2); + ASSERT_EQ(type[GETIDX(11)], 3); + ASSERT_EQ(type[GETIDX(12)], 4); + ASSERT_EQ(type[GETIDX(13)], 1); + ASSERT_EQ(type[GETIDX(14)], 2); + ASSERT_EQ(type[GETIDX(15)], 2); + ASSERT_EQ(type[GETIDX(16)], 1); + ASSERT_EQ(type[GETIDX(17)], 2); + ASSERT_EQ(type[GETIDX(18)], 2); + ASSERT_EQ(type[GETIDX(23)], 3); + ASSERT_EQ(type[GETIDX(24)], 4); + + ASSERT_EQ(molindex[GETIDX(1)], 0); + ASSERT_EQ(molindex[GETIDX(2)], 0); + ASSERT_EQ(molindex[GETIDX(3)], 0); + ASSERT_EQ(molindex[GETIDX(4)], 0); + ASSERT_EQ(molindex[GETIDX(5)], 0); + ASSERT_EQ(molindex[GETIDX(6)], 0); + ASSERT_EQ(molindex[GETIDX(11)], -1); + ASSERT_EQ(molindex[GETIDX(12)], -1); + ASSERT_EQ(molindex[GETIDX(13)], 0); + ASSERT_EQ(molindex[GETIDX(14)], 0); + ASSERT_EQ(molindex[GETIDX(15)], 0); + ASSERT_EQ(molindex[GETIDX(16)], 0); + ASSERT_EQ(molindex[GETIDX(17)], 0); + ASSERT_EQ(molindex[GETIDX(18)], 0); + ASSERT_EQ(molindex[GETIDX(23)], -1); + ASSERT_EQ(molindex[GETIDX(24)], -1); + ASSERT_EQ(molatom[GETIDX(1)], 0); + ASSERT_EQ(molatom[GETIDX(2)], 1); + ASSERT_EQ(molatom[GETIDX(3)], 2); + ASSERT_EQ(molatom[GETIDX(4)], 0); + ASSERT_EQ(molatom[GETIDX(5)], 1); + ASSERT_EQ(molatom[GETIDX(6)], 2); + ASSERT_EQ(molatom[GETIDX(11)], -1); + ASSERT_EQ(molatom[GETIDX(12)], -1); + ASSERT_EQ(molatom[GETIDX(13)], 0); + ASSERT_EQ(molatom[GETIDX(14)], 1); + ASSERT_EQ(molatom[GETIDX(15)], 2); + ASSERT_EQ(molatom[GETIDX(16)], 0); + ASSERT_EQ(molatom[GETIDX(17)], 1); + ASSERT_EQ(molatom[GETIDX(18)], 2); + ASSERT_EQ(molatom[GETIDX(23)], -1); + ASSERT_EQ(molatom[GETIDX(24)], -1); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("reset_atom_ids"); if (!verbose) ::testing::internal::GetCapturedStdout(); - EXPECT_EQ(lmp->atom->tag_consecutive(), 1); - EXPECT_EQ(lmp->atom->map_tag_max, 8); + ASSERT_EQ(lmp->atom->tag_consecutive(), 1); + ASSERT_EQ(lmp->atom->map_tag_max, 16); - type = lmp->atom->type; - EXPECT_EQ(type[GETIDX(1)], 1); - EXPECT_EQ(type[GETIDX(2)], 2); - EXPECT_EQ(type[GETIDX(3)], 2); - EXPECT_EQ(type[GETIDX(4)], 1); - EXPECT_EQ(type[GETIDX(5)], 2); - EXPECT_EQ(type[GETIDX(6)], 2); - EXPECT_EQ(type[GETIDX(7)], 4); - EXPECT_EQ(type[GETIDX(8)], 3); + + type = lmp->atom->type; + molecule = lmp->atom->molecule; + molindex = lmp->atom->molindex; + molatom = lmp->atom->molatom; + ASSERT_EQ(type[GETIDX(1)], 1); + ASSERT_EQ(type[GETIDX(2)], 2); + ASSERT_EQ(type[GETIDX(3)], 2); + ASSERT_EQ(type[GETIDX(4)], 1); + ASSERT_EQ(type[GETIDX(5)], 2); + ASSERT_EQ(type[GETIDX(6)], 2); + ASSERT_EQ(type[GETIDX(7)], 4); + ASSERT_EQ(type[GETIDX(8)], 3); + ASSERT_EQ(type[GETIDX(9)], 1); + ASSERT_EQ(type[GETIDX(10)], 2); + ASSERT_EQ(type[GETIDX(11)], 2); + ASSERT_EQ(type[GETIDX(12)], 1); + ASSERT_EQ(type[GETIDX(13)], 2); + ASSERT_EQ(type[GETIDX(14)], 2); + ASSERT_EQ(type[GETIDX(15)], 4); + ASSERT_EQ(type[GETIDX(16)], 3); + ASSERT_EQ(molatom[GETIDX(1)], 0); + ASSERT_EQ(molatom[GETIDX(2)], 1); + ASSERT_EQ(molatom[GETIDX(3)], 2); + ASSERT_EQ(molatom[GETIDX(4)], 0); + ASSERT_EQ(molatom[GETIDX(5)], 1); + ASSERT_EQ(molatom[GETIDX(6)], 2); + ASSERT_EQ(molatom[GETIDX(7)], -1); + ASSERT_EQ(molatom[GETIDX(8)], -1); + ASSERT_EQ(molatom[GETIDX(9)], 0); + ASSERT_EQ(molatom[GETIDX(10)], 1); + ASSERT_EQ(molatom[GETIDX(11)], 2); + ASSERT_EQ(molatom[GETIDX(12)], 0); + ASSERT_EQ(molatom[GETIDX(13)], 1); + ASSERT_EQ(molatom[GETIDX(14)], 2); + ASSERT_EQ(molatom[GETIDX(15)], -1); + ASSERT_EQ(molatom[GETIDX(16)], -1); } TEST_F(AtomStyleTest, bond) From 26a8d875e9c6a219aed786982a82075c0515448f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 29 Oct 2020 14:52:22 -0400 Subject: [PATCH 20/67] whitespace fix --- unittest/formats/test_atom_styles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index 0bc4833fea..7de1602ab8 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -4518,7 +4518,7 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 16); - + ASSERT_EQ(lmp->atom->nlocal, 16); ASSERT_EQ(lmp->atom->nghost, 0); ASSERT_NE(lmp->atom->nmax, -1); From c7b02b5bb2ffa7d056c9ee8ee63f2a6b8e636a20 Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Thu, 5 Nov 2020 14:12:42 -0600 Subject: [PATCH 21/67] Fix a bug in pair_kim for per-atom virial This results in wrong computation of stress/atom in LAMMPS. The issue happens after the PR #1704, where the `vflag_atom` is updated from `vflag_atom = vflag / 4;` to `vflag_atom = vflag & 4;` and causes paasing the wrong pointer to the KIM-API. --- src/KIM/pair_kim.cpp | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/KIM/pair_kim.cpp b/src/KIM/pair_kim.cpp index 9f9f2c83a9..6ea4e03fe3 100644 --- a/src/KIM/pair_kim.cpp +++ b/src/KIM/pair_kim.cpp @@ -650,9 +650,22 @@ int PairKIM::pack_reverse_comm(int n, int first, double *buf) buf[m++] = fp[3*i+2]; } return m; - } else if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, - KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom == 1) && + } + // ---------------------------------------------------------------------- + // for virial computation setup, see pair::ev_setup + // + // vflag = 4 = per-atom virial only + // vflag = 5 or 6 = both global and per-atom virial + // vflag = 12 = both per-atom virial and per-atom centroid virial + // vflag = 13 or 15 = global, per-atom virial and per-atom centroid virial + // + // vflag_atom = vflag & 4; + // + // per-atom virial -> vflag_atom == 4 + // ------------------------------------------------------------------------- + if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, + KIM_SUPPORT_STATUS_notSupported) && + (vflag_atom == 4) && KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, KIM_SUPPORT_STATUS_notSupported)) { double *va=&(vatom[0][0]); @@ -669,10 +682,10 @@ int PairKIM::pack_reverse_comm(int n, int first, double *buf) buf[m++] = va[6*i+5]; } return m; - } else if (KIM_SupportStatus_Equal(kim_model_support_for_forces, - KIM_SUPPORT_STATUS_notSupported) - && - (vflag_atom == 1) && + } + if (KIM_SupportStatus_Equal(kim_model_support_for_forces, + KIM_SUPPORT_STATUS_notSupported) && + (vflag_atom == 4) && KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, KIM_SUPPORT_STATUS_notSupported)) { double *va=&(vatom[0][0]); @@ -685,7 +698,8 @@ int PairKIM::pack_reverse_comm(int n, int first, double *buf) buf[m++] = va[6*i+5]; } return m; - } else return 0; + } + return 0; } /* ---------------------------------------------------------------------- */ @@ -712,7 +726,7 @@ void PairKIM::unpack_reverse_comm(int n, int *list, double *buf) } else if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom == 1) && + (vflag_atom == 4) && KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, KIM_SUPPORT_STATUS_notSupported)) { double *va=&(vatom[0][0]); @@ -732,7 +746,7 @@ void PairKIM::unpack_reverse_comm(int n, int *list, double *buf) } else if (KIM_SupportStatus_Equal(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom == 1) && + (vflag_atom == 4) && KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, KIM_SUPPORT_STATUS_notSupported)) { double *va=&(vatom[0][0]); @@ -918,6 +932,7 @@ void PairKIM::set_argument_pointers() memory->create(eatom,comm->nthreads*maxeatom,"pair:eatom"); } } + if (KIM_SupportStatus_Equal(kim_model_support_for_particleEnergy, KIM_SUPPORT_STATUS_optional) && (eflag_atom != 1)) { @@ -946,17 +961,18 @@ void PairKIM::set_argument_pointers() // Set KIM pointer appropriately for particleVirial if (KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, KIM_SUPPORT_STATUS_required) - && (vflag_atom != 1)) { + && (vflag_atom != 4)) { // reallocate per-atom virial array if necessary - if (atom->nmax > maxeatom) { + if (atom->nmax > maxvatom) { maxvatom = atom->nmax; memory->destroy(vatom); memory->create(vatom,comm->nthreads*maxvatom,6,"pair:vatom"); } } + if (KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, KIM_SUPPORT_STATUS_optional) - && (vflag_atom != 1)) { + && (vflag_atom != 4)) { kimerror = kimerror || KIM_ComputeArguments_SetArgumentPointerDouble( pargs, KIM_COMPUTE_ARGUMENT_NAME_partialParticleVirial, From 2777e690f0ad62ff898914c4d8e80f53d688db8a Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Thu, 5 Nov 2020 14:19:48 -0600 Subject: [PATCH 22/67] clean up the code, and remove unnecessary else conditions --- src/KIM/pair_kim.cpp | 91 +++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 48 deletions(-) diff --git a/src/KIM/pair_kim.cpp b/src/KIM/pair_kim.cpp index 6ea4e03fe3..333eca99ab 100644 --- a/src/KIM/pair_kim.cpp +++ b/src/KIM/pair_kim.cpp @@ -632,19 +632,15 @@ double PairKIM::init_one(int i, int j) int PairKIM::pack_reverse_comm(int n, int first, double *buf) { - int i,m,last; - double *fp; - fp = &(atom->f[0][0]); - - m = 0; - last = first + n; + int m = 0; + int const last = first + n; if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, - KIM_SUPPORT_STATUS_notSupported) - && + KIM_SUPPORT_STATUS_notSupported) && ((vflag_atom == 0) || KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, KIM_SUPPORT_STATUS_notSupported))) { - for (i = first; i < last; i++) { + const double *const fp = &(atom->f[0][0]); + for (int i = first; i < last; i++) { buf[m++] = fp[3*i+0]; buf[m++] = fp[3*i+1]; buf[m++] = fp[3*i+2]; @@ -665,11 +661,12 @@ int PairKIM::pack_reverse_comm(int n, int first, double *buf) // ------------------------------------------------------------------------- if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom == 4) && - KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported)) { - double *va=&(vatom[0][0]); - for (i = first; i < last; i++) { + (vflag_atom == 4) && + KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, + KIM_SUPPORT_STATUS_notSupported)) { + const double *const fp = &(atom->f[0][0]); + const double *const va = &(vatom[0][0]); + for (int i = first; i < last; i++) { buf[m++] = fp[3*i+0]; buf[m++] = fp[3*i+1]; buf[m++] = fp[3*i+2]; @@ -685,11 +682,11 @@ int PairKIM::pack_reverse_comm(int n, int first, double *buf) } if (KIM_SupportStatus_Equal(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom == 4) && - KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported)) { - double *va=&(vatom[0][0]); - for (i = first; i < last; i++) { + (vflag_atom == 4) && + KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, + KIM_SUPPORT_STATUS_notSupported)) { + const double *const va = &(vatom[0][0]); + for (int i = first; i < last; i++) { buf[m++] = va[6*i+0]; buf[m++] = va[6*i+1]; buf[m++] = va[6*i+2]; @@ -706,32 +703,30 @@ int PairKIM::pack_reverse_comm(int n, int first, double *buf) void PairKIM::unpack_reverse_comm(int n, int *list, double *buf) { - int i,j,m; - double *fp; - fp = &(atom->f[0][0]); - - m = 0; + int m = 0; if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, - KIM_SUPPORT_STATUS_notSupported) - && + KIM_SUPPORT_STATUS_notSupported) && ((vflag_atom == 0) || KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, KIM_SUPPORT_STATUS_notSupported))) { - for (i = 0; i < n; i++) { - j = list[i]; + double *const fp = &(atom->f[0][0]); + for (int i = 0; i < n; i++) { + const int j = list[i]; fp[3*j+0]+= buf[m++]; fp[3*j+1]+= buf[m++]; fp[3*j+2]+= buf[m++]; } - } else if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, - KIM_SUPPORT_STATUS_notSupported) - && - (vflag_atom == 4) && - KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported)) { - double *va=&(vatom[0][0]); - for (i = 0; i < n; i++) { - j = list[i]; + return; + } + if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, + KIM_SUPPORT_STATUS_notSupported) && + (vflag_atom == 4) && + KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, + KIM_SUPPORT_STATUS_notSupported)) { + double *const fp = &(atom->f[0][0]); + double *const va = &(vatom[0][0]); + for (int i = 0; i < n; i++) { + const int j = list[i]; fp[3*j+0]+= buf[m++]; fp[3*j+1]+= buf[m++]; fp[3*j+2]+= buf[m++]; @@ -743,15 +738,16 @@ void PairKIM::unpack_reverse_comm(int n, int *list, double *buf) va[j*6+4]+=buf[m++]; va[j*6+5]+=buf[m++]; } - } else if (KIM_SupportStatus_Equal(kim_model_support_for_forces, - KIM_SUPPORT_STATUS_notSupported) - && - (vflag_atom == 4) && - KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported)) { - double *va=&(vatom[0][0]); - for (i = 0; i < n; i++) { - j = list[i]; + return; + } + if (KIM_SupportStatus_Equal(kim_model_support_for_forces, + KIM_SUPPORT_STATUS_notSupported) && + (vflag_atom == 4) && + KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, + KIM_SUPPORT_STATUS_notSupported)) { + double *const va=&(vatom[0][0]); + for (int i = 0; i < n; i++) { + const int j = list[i]; va[j*6+0]+=buf[m++]; va[j*6+1]+=buf[m++]; va[j*6+2]+=buf[m++]; @@ -759,9 +755,8 @@ void PairKIM::unpack_reverse_comm(int n, int *list, double *buf) va[j*6+4]+=buf[m++]; va[j*6+5]+=buf[m++]; } - } else { - ; // do nothing } + // do nothing } /* ---------------------------------------------------------------------- From 355ddce28672d7ed57efcdbf5610903c3aed145a Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Wed, 11 Nov 2020 05:36:48 -0600 Subject: [PATCH 23/67] Update the vflag_atom based on the intended use in LAMMPS --- src/KIM/pair_kim.cpp | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/src/KIM/pair_kim.cpp b/src/KIM/pair_kim.cpp index 333eca99ab..faeda2b69e 100644 --- a/src/KIM/pair_kim.cpp +++ b/src/KIM/pair_kim.cpp @@ -636,9 +636,9 @@ int PairKIM::pack_reverse_comm(int n, int first, double *buf) int const last = first + n; if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && - ((vflag_atom == 0) || - KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported))) { + (KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, + KIM_SUPPORT_STATUS_notSupported) || + (vflag_atom == 0))) { const double *const fp = &(atom->f[0][0]); for (int i = first; i < last; i++) { buf[m++] = fp[3*i+0]; @@ -648,22 +648,14 @@ int PairKIM::pack_reverse_comm(int n, int first, double *buf) return m; } // ---------------------------------------------------------------------- - // for virial computation setup, see pair::ev_setup - // - // vflag = 4 = per-atom virial only - // vflag = 5 or 6 = both global and per-atom virial - // vflag = 12 = both per-atom virial and per-atom centroid virial - // vflag = 13 or 15 = global, per-atom virial and per-atom centroid virial - // - // vflag_atom = vflag & 4; - // - // per-atom virial -> vflag_atom == 4 + // see Pair::ev_setup & Integrate::ev_set() + // for values of eflag (0-3) and vflag (0-14) // ------------------------------------------------------------------------- if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, - KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom == 4) && + KIM_SUPPORT_STATUS_notSupported) && KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported)) { + KIM_SUPPORT_STATUS_notSupported) && + (vflag_atom != 0)) { const double *const fp = &(atom->f[0][0]); const double *const va = &(vatom[0][0]); for (int i = first; i < last; i++) { @@ -682,9 +674,9 @@ int PairKIM::pack_reverse_comm(int n, int first, double *buf) } if (KIM_SupportStatus_Equal(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom == 4) && KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported)) { + KIM_SUPPORT_STATUS_notSupported) && + (vflag_atom != 0)) { const double *const va = &(vatom[0][0]); for (int i = first; i < last; i++) { buf[m++] = va[6*i+0]; @@ -706,9 +698,9 @@ void PairKIM::unpack_reverse_comm(int n, int *list, double *buf) int m = 0; if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && - ((vflag_atom == 0) || - KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported))) { + (KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, + KIM_SUPPORT_STATUS_notSupported) || + (vflag_atom == 0))) { double *const fp = &(atom->f[0][0]); for (int i = 0; i < n; i++) { const int j = list[i]; @@ -720,9 +712,9 @@ void PairKIM::unpack_reverse_comm(int n, int *list, double *buf) } if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom == 4) && KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported)) { + KIM_SUPPORT_STATUS_notSupported) && + (vflag_atom != 0)) { double *const fp = &(atom->f[0][0]); double *const va = &(vatom[0][0]); for (int i = 0; i < n; i++) { @@ -742,9 +734,9 @@ void PairKIM::unpack_reverse_comm(int n, int *list, double *buf) } if (KIM_SupportStatus_Equal(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom == 4) && KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported)) { + KIM_SUPPORT_STATUS_notSupported) && + (vflag_atom != 0)) { double *const va=&(vatom[0][0]); for (int i = 0; i < n; i++) { const int j = list[i]; From d09eb491f8e045b662f1c4c574e391cdeba68638 Mon Sep 17 00:00:00 2001 From: jrgissing Date: Wed, 11 Nov 2020 13:00:10 -0500 Subject: [PATCH 24/67] molecule: add iatom < 0 check --- src/molecule.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/molecule.cpp b/src/molecule.cpp index afa5296414..104ad3dccf 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -684,7 +684,7 @@ void Molecule::coords(char *line) if (values.count() != 4) error->one(FLERR,"Invalid Coords section in molecule file"); int iatom = values.next_int() - 1; - if (iatom >= natoms) error->one(FLERR,"Invalid Coords section in molecule file"); + if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Coords section in molecule file"); x[iatom][0] = values.next_double(); x[iatom][1] = values.next_double(); x[iatom][2] = values.next_double(); @@ -720,7 +720,7 @@ void Molecule::types(char *line) if (values.count() != 2) error->one(FLERR,"Invalid Types section in molecule file"); int iatom = values.next_int() - 1; - if (iatom >= natoms) error->one(FLERR,"Invalid Types section in molecule file"); + if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Types section in molecule file"); type[iatom] = values.next_int(); type[iatom] += toffset; } @@ -751,7 +751,7 @@ void Molecule::molecules(char *line) if (values.count() != 2) error->one(FLERR,"Invalid Molecules section in molecule file"); int iatom = values.next_int() - 1; - if (iatom >= natoms) error->one(FLERR,"Invalid Molecules section in molecule file"); + if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Molecules section in molecule file"); molecule[iatom] = values.next_int(); // molecule[iatom] += moffset; // placeholder for possible molecule offset } @@ -812,7 +812,7 @@ void Molecule::charges(char *line) if ((int)values.count() != 2) error->one(FLERR,"Invalid Charges section in molecule file"); int iatom = values.next_int() - 1; - if (iatom >= natoms) error->one(FLERR,"Invalid Charges section in molecule file"); + if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Charges section in molecule file"); q[iatom] = values.next_double(); } } catch (TokenizerException &e) { @@ -836,7 +836,7 @@ void Molecule::diameters(char *line) if (values.count() != 2) error->one(FLERR,"Invalid Diameters section in molecule file"); int iatom = values.next_int() - 1; - if (iatom >= natoms) error->one(FLERR,"Invalid Diameters section in molecule file"); + if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Diameters section in molecule file"); radius[iatom] = values.next_double(); radius[iatom] *= sizescale; radius[iatom] *= 0.5; @@ -866,7 +866,7 @@ void Molecule::masses(char *line) if (values.count() != 2) error->one(FLERR,"Invalid Masses section in molecule file"); int iatom = values.next_int() - 1; - if (iatom >= natoms) error->one(FLERR,"Invalid Diameters section in molecule file"); + if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Masses section in molecule file"); rmass[iatom] = values.next_double(); rmass[iatom] *= sizescale*sizescale*sizescale; } From f24320d26a5e0085b1bd4dabc61d66f221299cd8 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 11 Nov 2020 22:09:03 -0500 Subject: [PATCH 25/67] Introduce enums for energy and virial flags --- src/integrate.cpp | 8 ++++---- src/pair.cpp | 14 +++++++------- src/pair.h | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/integrate.cpp b/src/integrate.cpp index 7d4bf36929..cf84797fde 100644 --- a/src/integrate.cpp +++ b/src/integrate.cpp @@ -125,7 +125,7 @@ void Integrate::ev_setup() vflag = 8 = per-atom centroid virial only vflag = 9 or 10 = both global and per-atom centroid virial vflag = 12 = both per-atom virial and per-atom centroid virial - vflag = 13 or 15 = global, per-atom virial and per-atom centroid virial + vflag = 13 or 14 = global, per-atom virial and per-atom centroid virial ------------------------------------------------------------------------- */ void Integrate::ev_set(bigint ntimestep) @@ -142,7 +142,7 @@ void Integrate::ev_set(bigint ntimestep) int eflag_atom = 0; for (i = 0; i < nelist_atom; i++) if (elist_atom[i]->matchstep(ntimestep)) flag = 1; - if (flag) eflag_atom = 2; + if (flag) eflag_atom = ENERGY_PER_ATOM; if (eflag_global) update->eflag_global = ntimestep; if (eflag_atom) update->eflag_atom = ntimestep; @@ -158,13 +158,13 @@ void Integrate::ev_set(bigint ntimestep) int vflag_atom = 0; for (i = 0; i < nvlist_atom; i++) if (vlist_atom[i]->matchstep(ntimestep)) flag = 1; - if (flag) vflag_atom = 4; + if (flag) vflag_atom = VIRIAL_PER_ATOM; flag = 0; int cvflag_atom = 0; for (i = 0; i < ncvlist_atom; i++) if (cvlist_atom[i]->matchstep(ntimestep)) flag = 1; - if (flag) cvflag_atom = 8; + if (flag) cvflag_atom = VIRIAL_PER_ATOM_CENTROID; if (vflag_global) update->vflag_global = ntimestep; if (vflag_atom || cvflag_atom) update->vflag_atom = ntimestep; diff --git a/src/pair.cpp b/src/pair.cpp index 1ff2322b48..2e2e942a93 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -786,14 +786,14 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) evflag = 1; eflag_either = eflag; - eflag_global = eflag % 2; - eflag_atom = eflag / 2; + eflag_global = eflag & ENERGY_GLOBAL; + eflag_atom = eflag & ENERGY_PER_ATOM; - vflag_global = vflag % 4; - vflag_atom = vflag & 4; + vflag_global = vflag & (VIRIAL_GLOBAL_PW_SUM | VIRIAL_GLOBAL_PW_FDOTR_W_GHOSTS); + vflag_atom = vflag & VIRIAL_PER_ATOM; cvflag_atom = 0; - if (vflag & 8) { + if (vflag & VIRIAL_PER_ATOM_CENTROID) { if (centroidstressflag & 2) { cvflag_atom = 1; } else { @@ -869,11 +869,11 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) } } - // if vflag_global = 2 and pair::compute() calls virial_fdotr_compute() + // if vflag_global = VIRIAL_GLOBAL_PW_FDOTR_W_GHOSTS and pair::compute() calls virial_fdotr_compute() // compute global virial via (F dot r) instead of via pairwise summation // unset other flags as appropriate - if (vflag_global == 2 && no_virial_fdotr_compute == 0) { + if (vflag_global == VIRIAL_GLOBAL_PW_FDOTR_W_GHOSTS && no_virial_fdotr_compute == 0) { vflag_fdotr = 1; vflag_global = 0; if (vflag_atom == 0 && cvflag_atom == 0) vflag_either = 0; diff --git a/src/pair.h b/src/pair.h index ace233539f..7cbe7af541 100644 --- a/src/pair.h +++ b/src/pair.h @@ -18,6 +18,20 @@ namespace LAMMPS_NS { +enum { + ENERGY_NO_COMPUTATION = 0x00, + ENERGY_GLOBAL = 0x01, + ENERGY_PER_ATOM = 0x02 +}; + +enum { + VIRIAL_NO_COMPUTATION = 0x00, + VIRIAL_GLOBAL_PW_SUM = 0x01, + VIRIAL_GLOBAL_PW_FDOTR_W_GHOSTS = 0x02, + VIRIAL_PER_ATOM = 0x04, + VIRIAL_PER_ATOM_CENTROID = 0x08 +}; + class Pair : protected Pointers { friend class AngleSDK; friend class AngleSDKOMP; From 00557e00a43ea655f0cec37ce935a5785f17dbd1 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 13 Nov 2020 12:08:09 -0500 Subject: [PATCH 26/67] Add AtomState struct and ASSERT helpers --- unittest/formats/test_atom_styles.cpp | 549 ++++++++++++++++---------- 1 file changed, 347 insertions(+), 202 deletions(-) diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index 7de1602ab8..fed52f8745 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -130,217 +130,361 @@ protected: } }; +// default class Atom state +struct AtomState { + std::string atom_style = "atomic"; + bigint natoms = 0; + int nlocal = 0; + int nghost = 0; + int nmax = 1; + int tag_enable = 1; + int molecular = Atom::ATOMIC; + bigint nellipsoids = 0; + bigint nlines = 0; + bigint ntris = 0; + bigint nbodies = 0; + bigint nbonds = 0; + bigint nangles = 0; + bigint ndihedrals = 0; + bigint nimpropers = 0; + int ntypes = 0; + int nbondtypes = 0; + int nangletypes = 0; + int ndihedraltypes = 0; + int nimpropertypes = 0; + int bond_per_atom = 0; + int angle_per_atom = 0; + int dihedral_per_atom = 0; + int improper_per_atom = 0; + int extra_bond_per_atom = 0; + int extra_angle_per_atom = 0; + int extra_dihedral_per_atom = 0; + int extra_improper_per_atom = 0; + + int sphere_flag = 0; + int ellipsoid_flag = 0; + int line_flag = 0; + int tri_flag = 0; + int body_flag = 0; + int peri_flag = 0; + int electron_flag = 0; + int wavepacket_flag = 0; + int sph_flag = 0; + int molecule_flag = 0; + int molindex_flag = 0; + int molatom_flag = 0; + int q_flag = 0; + int mu_flag = 0; + int rmass_flag = 0; + int radius_flag = 0; + int omega_flag = 0; + int torque_flag = 0; + int angmom_flag = 0; + int vfrac_flag = 0; + int spin_flag = 0; + int eradius_flag = 0; + int ervel_flag = 0; + int erforce_flag = 0; + int cs_flag = 0; + int csforce_flag = 0; + int vforce_flag = 0; + int ervelforce_flag = 0; + int etag_flag = 0; + int rho_flag = 0; + int esph_flag = 0; + int cv_flag = 0; + int vest_flag = 0; + int dpd_flag = 0; + int edpd_flag = 0; + int tdpd_flag = 0; + int mesont_flag = 0; + int sp_flag = 0; + int x0_flag = 0; + int smd_flag = 0; + int damage_flag = 0; + int contact_radius_flag = 0; + int smd_data_9_flag = 0; + int smd_stress_flag = 0; + int eff_plastic_strain_flag = 0; + int eff_plastic_strain_rate_flag = 0; + double pdscale = 1.0; + + + int maxspecial = 1; + + int nmolecule = 0; + + int nivector = 0; + int ndvector = 0; + + int nextra_grow = 0; + int nextra_restart = 0; + int nextra_border = 0; + int nextra_grow_max = 0; + int nextra_restart_max = 0; + int nextra_border_max = 0; + int nextra_store = 0; + + int map_style = Atom::MAP_NONE; + int map_user = 0; + tagint map_tag_max = -1; + + // properties X that aren't controlled by an equivalent X_flag + bool has_type = true; + bool has_mask = true; + bool has_image = true; + bool has_x = true; + bool has_v = true; + bool has_f = true; + + bool has_bonds = false; + bool has_angles = false; + bool has_dihedral = false; + bool has_improper = false; + + bool has_iname = false; + bool has_dname = false; + bool has_mass = false; + bool has_mass_setflag = false; +}; + +template +void ASSERT_ARRAY_ALLOCATED(const T * ptr, bool enabled) { + if (enabled) { + ASSERT_NE(ptr, nullptr); + } else { + ASSERT_EQ(ptr, nullptr); + } +} + +void ASSERT_ATOM_STATE_EQ(Atom* atom, const AtomState& expected) { + ASSERT_THAT(std::string(atom->atom_style), Eq(expected.atom_style)); + + ASSERT_NE(atom->avec, nullptr); + ASSERT_EQ(atom->natoms, expected.natoms); + ASSERT_EQ(atom->nlocal, expected.nlocal); + ASSERT_EQ(atom->nghost, expected.nghost); + ASSERT_EQ(atom->nmax, expected.nmax); + ASSERT_EQ(atom->tag_enable, expected.tag_enable); + ASSERT_EQ(atom->molecular, expected.molecular); + ASSERT_EQ(atom->nellipsoids, expected.nellipsoids); + ASSERT_EQ(atom->nlines, expected.nlines); + ASSERT_EQ(atom->ntris, expected.ntris); + ASSERT_EQ(atom->nbodies, expected.nbodies); + ASSERT_EQ(atom->nbonds, expected.nbonds); + ASSERT_EQ(atom->nangles, expected.nangles); + ASSERT_EQ(atom->ndihedrals, expected.ndihedrals); + ASSERT_EQ(atom->nimpropers, expected.nimpropers); + ASSERT_EQ(atom->ntypes, expected.ntypes); + ASSERT_EQ(atom->nbondtypes, expected.nbondtypes); + ASSERT_EQ(atom->nangletypes, expected.nangletypes); + ASSERT_EQ(atom->ndihedraltypes, expected.ndihedraltypes); + ASSERT_EQ(atom->nimpropertypes, expected.nimpropertypes); + ASSERT_EQ(atom->bond_per_atom, expected.bond_per_atom); + ASSERT_EQ(atom->angle_per_atom, expected.angle_per_atom); + ASSERT_EQ(atom->dihedral_per_atom, expected.dihedral_per_atom); + ASSERT_EQ(atom->improper_per_atom, expected.improper_per_atom); + ASSERT_EQ(atom->extra_bond_per_atom, expected.extra_bond_per_atom); + ASSERT_EQ(atom->extra_angle_per_atom, expected.extra_angle_per_atom); + ASSERT_EQ(atom->extra_dihedral_per_atom, expected.extra_dihedral_per_atom); + ASSERT_EQ(atom->extra_improper_per_atom, expected.extra_improper_per_atom); + + ASSERT_EQ(atom->sphere_flag, expected.sphere_flag); + ASSERT_EQ(atom->ellipsoid_flag, expected.ellipsoid_flag); + ASSERT_EQ(atom->line_flag, expected.line_flag); + ASSERT_EQ(atom->tri_flag, expected.tri_flag); + ASSERT_EQ(atom->body_flag, expected.body_flag); + ASSERT_EQ(atom->peri_flag, expected.peri_flag); + ASSERT_EQ(atom->electron_flag, expected.electron_flag); + ASSERT_EQ(atom->wavepacket_flag, expected.wavepacket_flag); + ASSERT_EQ(atom->sph_flag, expected.sph_flag); + ASSERT_EQ(atom->molecule_flag, expected.molecule_flag); + ASSERT_EQ(atom->molindex_flag, expected.molindex_flag); + ASSERT_EQ(atom->molatom_flag, expected.molatom_flag); + ASSERT_EQ(atom->q_flag, expected.q_flag); + ASSERT_EQ(atom->mu_flag, expected.mu_flag); + ASSERT_EQ(atom->rmass_flag, expected.rmass_flag); + ASSERT_EQ(atom->radius_flag, expected.radius_flag); + ASSERT_EQ(atom->omega_flag, expected.omega_flag); + ASSERT_EQ(atom->torque_flag, expected.torque_flag); + ASSERT_EQ(atom->angmom_flag, expected.angmom_flag); + ASSERT_EQ(atom->vfrac_flag, expected.vfrac_flag); + ASSERT_EQ(atom->spin_flag, expected.spin_flag); + ASSERT_EQ(atom->eradius_flag, expected.eradius_flag); + ASSERT_EQ(atom->ervel_flag, expected.ervel_flag); + ASSERT_EQ(atom->erforce_flag, expected.erforce_flag); + ASSERT_EQ(atom->cs_flag, expected.cs_flag); + ASSERT_EQ(atom->csforce_flag, expected.csforce_flag); + ASSERT_EQ(atom->vforce_flag, expected.vforce_flag); + ASSERT_EQ(atom->ervelforce_flag, expected.ervelforce_flag); + ASSERT_EQ(atom->etag_flag, expected.etag_flag); + ASSERT_EQ(atom->rho_flag, expected.rho_flag); + ASSERT_EQ(atom->esph_flag, expected.esph_flag); + ASSERT_EQ(atom->cv_flag, expected.cv_flag); + ASSERT_EQ(atom->vest_flag, expected.vest_flag); + ASSERT_EQ(atom->dpd_flag, expected.dpd_flag); + ASSERT_EQ(atom->edpd_flag, expected.edpd_flag); + ASSERT_EQ(atom->tdpd_flag, expected.tdpd_flag); + ASSERT_EQ(atom->mesont_flag, expected.mesont_flag); + ASSERT_EQ(atom->sp_flag, expected.sp_flag); + ASSERT_EQ(atom->x0_flag, expected.x0_flag); + ASSERT_EQ(atom->smd_flag, expected.smd_flag); + ASSERT_EQ(atom->damage_flag, expected.damage_flag); + ASSERT_EQ(atom->contact_radius_flag, expected.contact_radius_flag); + ASSERT_EQ(atom->smd_data_9_flag, expected.smd_data_9_flag); + ASSERT_EQ(atom->smd_stress_flag, expected.smd_stress_flag); + ASSERT_EQ(atom->eff_plastic_strain_flag, expected.eff_plastic_strain_flag); + ASSERT_EQ(atom->eff_plastic_strain_rate_flag, expected.eff_plastic_strain_rate_flag); + ASSERT_EQ(atom->pdscale, expected.pdscale); + + ASSERT_ARRAY_ALLOCATED(atom->tag, expected.tag_enable); + ASSERT_ARRAY_ALLOCATED(atom->type, expected.has_type); + ASSERT_ARRAY_ALLOCATED(atom->mask, expected.has_mask); + ASSERT_ARRAY_ALLOCATED(atom->image, expected.has_image); + + ASSERT_ARRAY_ALLOCATED(atom->x, expected.has_x); + ASSERT_ARRAY_ALLOCATED(atom->v, expected.has_v); + ASSERT_ARRAY_ALLOCATED(atom->f, expected.has_f); + ASSERT_ARRAY_ALLOCATED(atom->q, expected.q_flag); + ASSERT_ARRAY_ALLOCATED(atom->mu, expected.mu_flag); + + ASSERT_ARRAY_ALLOCATED(atom->omega, expected.omega_flag); + ASSERT_ARRAY_ALLOCATED(atom->angmom, expected.angmom_flag); + ASSERT_ARRAY_ALLOCATED(atom->torque, expected.torque_flag); + ASSERT_ARRAY_ALLOCATED(atom->radius, expected.radius_flag); + ASSERT_ARRAY_ALLOCATED(atom->rmass, expected.rmass_flag); + ASSERT_ARRAY_ALLOCATED(atom->ellipsoid, expected.ellipsoid_flag); + ASSERT_ARRAY_ALLOCATED(atom->line, expected.line_flag); + ASSERT_ARRAY_ALLOCATED(atom->tri, expected.tri_flag); + ASSERT_ARRAY_ALLOCATED(atom->body, expected.body_flag); + ASSERT_ARRAY_ALLOCATED(atom->molecule, expected.molecule_flag); + ASSERT_ARRAY_ALLOCATED(atom->molindex, expected.molindex_flag); + ASSERT_ARRAY_ALLOCATED(atom->molatom, expected.molatom_flag); + + ASSERT_ARRAY_ALLOCATED(atom->num_bond, expected.has_bonds); + ASSERT_ARRAY_ALLOCATED(atom->bond_type, expected.has_bonds); + ASSERT_ARRAY_ALLOCATED(atom->bond_atom, expected.has_bonds); + + ASSERT_ARRAY_ALLOCATED(atom->num_angle, expected.has_angles); + ASSERT_ARRAY_ALLOCATED(atom->angle_type, expected.has_angles); + ASSERT_ARRAY_ALLOCATED(atom->angle_atom1, expected.has_angles); + ASSERT_ARRAY_ALLOCATED(atom->angle_atom2, expected.has_angles); + ASSERT_ARRAY_ALLOCATED(atom->angle_atom3, expected.has_angles); + + ASSERT_ARRAY_ALLOCATED(atom->num_dihedral, expected.has_dihedral); + ASSERT_ARRAY_ALLOCATED(atom->dihedral_type, expected.has_dihedral); + ASSERT_ARRAY_ALLOCATED(atom->dihedral_atom1, expected.has_dihedral); + ASSERT_ARRAY_ALLOCATED(atom->dihedral_atom2, expected.has_dihedral); + ASSERT_ARRAY_ALLOCATED(atom->dihedral_atom3, expected.has_dihedral); + ASSERT_ARRAY_ALLOCATED(atom->dihedral_atom4, expected.has_dihedral); + + ASSERT_ARRAY_ALLOCATED(atom->num_improper, expected.has_improper); + ASSERT_ARRAY_ALLOCATED(atom->improper_type, expected.has_improper); + ASSERT_ARRAY_ALLOCATED(atom->improper_atom1, expected.has_improper); + ASSERT_ARRAY_ALLOCATED(atom->improper_atom2, expected.has_improper); + ASSERT_ARRAY_ALLOCATED(atom->improper_atom3, expected.has_improper); + ASSERT_ARRAY_ALLOCATED(atom->improper_atom4, expected.has_improper); + + ASSERT_EQ(atom->maxspecial, expected.maxspecial); + + // currently ignored + ASSERT_ARRAY_ALLOCATED(atom->nspecial, false); + ASSERT_ARRAY_ALLOCATED(atom->special, false); + ASSERT_ARRAY_ALLOCATED(atom->vfrac, false); + ASSERT_ARRAY_ALLOCATED(atom->s0, false); + ASSERT_ARRAY_ALLOCATED(atom->x0, false); + ASSERT_ARRAY_ALLOCATED(atom->sp, false); + ASSERT_ARRAY_ALLOCATED(atom->fm, false); + ASSERT_ARRAY_ALLOCATED(atom->fm_long, false); + ASSERT_ARRAY_ALLOCATED(atom->spin, false); + ASSERT_ARRAY_ALLOCATED(atom->eradius, false); + ASSERT_ARRAY_ALLOCATED(atom->ervel, false); + ASSERT_ARRAY_ALLOCATED(atom->erforce, false); + ASSERT_ARRAY_ALLOCATED(atom->ervelforce, false); + ASSERT_ARRAY_ALLOCATED(atom->cs, false); + ASSERT_ARRAY_ALLOCATED(atom->csforce, false); + ASSERT_ARRAY_ALLOCATED(atom->vforce, false); + ASSERT_ARRAY_ALLOCATED(atom->etag, false); + ASSERT_ARRAY_ALLOCATED(atom->uCond, false); + ASSERT_ARRAY_ALLOCATED(atom->uMech, false); + ASSERT_ARRAY_ALLOCATED(atom->uChem, false); + ASSERT_ARRAY_ALLOCATED(atom->uCG, false); + ASSERT_ARRAY_ALLOCATED(atom->uCGnew, false); + ASSERT_ARRAY_ALLOCATED(atom->duChem, false); + ASSERT_ARRAY_ALLOCATED(atom->dpdTheta, false); + ASSERT_ARRAY_ALLOCATED(atom->cc, false); + ASSERT_ARRAY_ALLOCATED(atom->cc_flux, false); + ASSERT_ARRAY_ALLOCATED(atom->edpd_temp, false); + ASSERT_ARRAY_ALLOCATED(atom->edpd_flux, false); + ASSERT_ARRAY_ALLOCATED(atom->edpd_cv, false); + ASSERT_ARRAY_ALLOCATED(atom->length, false); + ASSERT_ARRAY_ALLOCATED(atom->buckling, false); + ASSERT_ARRAY_ALLOCATED(atom->bond_nt, false); + ASSERT_ARRAY_ALLOCATED(atom->contact_radius, false); + ASSERT_ARRAY_ALLOCATED(atom->smd_data_9, false); + ASSERT_ARRAY_ALLOCATED(atom->smd_stress, false); + ASSERT_ARRAY_ALLOCATED(atom->eff_plastic_strain, false); + ASSERT_ARRAY_ALLOCATED(atom->eff_plastic_strain_rate, false); + ASSERT_ARRAY_ALLOCATED(atom->damage, false); + ASSERT_ARRAY_ALLOCATED(atom->rho, false); + ASSERT_ARRAY_ALLOCATED(atom->drho, false); + ASSERT_ARRAY_ALLOCATED(atom->esph, false); + ASSERT_ARRAY_ALLOCATED(atom->desph, false); + ASSERT_ARRAY_ALLOCATED(atom->cv, false); + ASSERT_ARRAY_ALLOCATED(atom->vest, false); + + ASSERT_EQ(atom->nmolecule, expected.nmolecule); + + ASSERT_ARRAY_ALLOCATED(atom->molecules, expected.molecule_flag); + + ASSERT_EQ(atom->nivector, expected.nivector); + ASSERT_EQ(atom->ndvector, expected.ndvector); + + ASSERT_ARRAY_ALLOCATED(atom->iname, expected.has_iname); + ASSERT_ARRAY_ALLOCATED(atom->dname, expected.has_dname); + ASSERT_ARRAY_ALLOCATED(atom->mass, expected.has_mass); + ASSERT_ARRAY_ALLOCATED(atom->mass_setflag, expected.has_mass_setflag); + + ASSERT_EQ(atom->nextra_grow, expected.nextra_grow); + ASSERT_EQ(atom->nextra_restart, expected.nextra_restart); + ASSERT_EQ(atom->nextra_border, expected.nextra_border); + ASSERT_EQ(atom->nextra_grow_max, expected.nextra_grow_max); + ASSERT_EQ(atom->nextra_restart_max, expected.nextra_restart_max); + ASSERT_EQ(atom->nextra_border_max, expected.nextra_border_max); + ASSERT_EQ(atom->nextra_store, expected.nextra_store); + + ASSERT_ARRAY_ALLOCATED(atom->extra_grow, false); + ASSERT_ARRAY_ALLOCATED(atom->extra_restart, false); + ASSERT_ARRAY_ALLOCATED(atom->extra_border, false); + ASSERT_ARRAY_ALLOCATED(atom->extra, false); + ASSERT_ARRAY_ALLOCATED(atom->sametag, false); + + ASSERT_EQ(atom->map_style, expected.map_style); + ASSERT_EQ(atom->map_user, expected.map_user); + ASSERT_EQ(atom->map_tag_max, expected.map_tag_max); +} + TEST_F(AtomStyleTest, atomic) { - ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); - ASSERT_NE(lmp->atom->avec, nullptr); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::ATOMIC); - ASSERT_EQ(lmp->atom->nellipsoids, 0); - ASSERT_EQ(lmp->atom->nlines, 0); - ASSERT_EQ(lmp->atom->ntris, 0); - ASSERT_EQ(lmp->atom->nbodies, 0); - ASSERT_EQ(lmp->atom->nbonds, 0); - ASSERT_EQ(lmp->atom->nangles, 0); - ASSERT_EQ(lmp->atom->ndihedrals, 0); - ASSERT_EQ(lmp->atom->nimpropers, 0); - ASSERT_EQ(lmp->atom->ntypes, 0); - ASSERT_EQ(lmp->atom->nbondtypes, 0); - ASSERT_EQ(lmp->atom->nangletypes, 0); - ASSERT_EQ(lmp->atom->ndihedraltypes, 0); - ASSERT_EQ(lmp->atom->nimpropertypes, 0); - ASSERT_EQ(lmp->atom->bond_per_atom, 0); - ASSERT_EQ(lmp->atom->angle_per_atom, 0); - ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->improper_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); + AtomState expected; + expected.atom_style = "atomic"; + expected.molecular = Atom::ATOMIC; + expected.tag_enable = 1; + expected.has_type = true; + expected.has_mask = true; + expected.has_image = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; - ASSERT_EQ(lmp->atom->sphere_flag, 0); - ASSERT_EQ(lmp->atom->ellipsoid_flag, 0); - ASSERT_EQ(lmp->atom->line_flag, 0); - ASSERT_EQ(lmp->atom->tri_flag, 0); - ASSERT_EQ(lmp->atom->body_flag, 0); - ASSERT_EQ(lmp->atom->peri_flag, 0); - ASSERT_EQ(lmp->atom->electron_flag, 0); - ASSERT_EQ(lmp->atom->wavepacket_flag, 0); - ASSERT_EQ(lmp->atom->sph_flag, 0); - ASSERT_EQ(lmp->atom->molecule_flag, 0); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - ASSERT_EQ(lmp->atom->q_flag, 0); - ASSERT_EQ(lmp->atom->mu_flag, 0); - ASSERT_EQ(lmp->atom->rmass_flag, 0); - ASSERT_EQ(lmp->atom->radius_flag, 0); - ASSERT_EQ(lmp->atom->omega_flag, 0); - ASSERT_EQ(lmp->atom->torque_flag, 0); - ASSERT_EQ(lmp->atom->angmom_flag, 0); - ASSERT_EQ(lmp->atom->vfrac_flag, 0); - ASSERT_EQ(lmp->atom->spin_flag, 0); - ASSERT_EQ(lmp->atom->eradius_flag, 0); - ASSERT_EQ(lmp->atom->ervel_flag, 0); - ASSERT_EQ(lmp->atom->erforce_flag, 0); - ASSERT_EQ(lmp->atom->cs_flag, 0); - ASSERT_EQ(lmp->atom->csforce_flag, 0); - ASSERT_EQ(lmp->atom->vforce_flag, 0); - ASSERT_EQ(lmp->atom->ervelforce_flag, 0); - ASSERT_EQ(lmp->atom->etag_flag, 0); - ASSERT_EQ(lmp->atom->rho_flag, 0); - ASSERT_EQ(lmp->atom->esph_flag, 0); - ASSERT_EQ(lmp->atom->cv_flag, 0); - ASSERT_EQ(lmp->atom->vest_flag, 0); - ASSERT_EQ(lmp->atom->dpd_flag, 0); - ASSERT_EQ(lmp->atom->edpd_flag, 0); - ASSERT_EQ(lmp->atom->tdpd_flag, 0); - ASSERT_EQ(lmp->atom->mesont_flag, 0); - ASSERT_EQ(lmp->atom->sp_flag, 0); - ASSERT_EQ(lmp->atom->x0_flag, 0); - ASSERT_EQ(lmp->atom->smd_flag, 0); - ASSERT_EQ(lmp->atom->damage_flag, 0); - ASSERT_EQ(lmp->atom->contact_radius_flag, 0); - ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); - ASSERT_EQ(lmp->atom->smd_stress_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - ASSERT_EQ(lmp->atom->pdscale, 1.0); - - ASSERT_NE(lmp->atom->tag, nullptr); - ASSERT_NE(lmp->atom->type, nullptr); - ASSERT_NE(lmp->atom->mask, nullptr); - ASSERT_NE(lmp->atom->image, nullptr); - ASSERT_NE(lmp->atom->x, nullptr); - ASSERT_NE(lmp->atom->v, nullptr); - ASSERT_NE(lmp->atom->f, nullptr); - ASSERT_EQ(lmp->atom->q, nullptr); - ASSERT_EQ(lmp->atom->mu, nullptr); - ASSERT_EQ(lmp->atom->omega, nullptr); - ASSERT_EQ(lmp->atom->angmom, nullptr); - ASSERT_EQ(lmp->atom->torque, nullptr); - ASSERT_EQ(lmp->atom->radius, nullptr); - ASSERT_EQ(lmp->atom->rmass, nullptr); - ASSERT_EQ(lmp->atom->ellipsoid, nullptr); - ASSERT_EQ(lmp->atom->line, nullptr); - ASSERT_EQ(lmp->atom->tri, nullptr); - ASSERT_EQ(lmp->atom->body, nullptr); - ASSERT_EQ(lmp->atom->molecule, nullptr); - ASSERT_EQ(lmp->atom->molindex, nullptr); - ASSERT_EQ(lmp->atom->molatom, nullptr); - ASSERT_EQ(lmp->atom->num_bond, nullptr); - ASSERT_EQ(lmp->atom->bond_type, nullptr); - ASSERT_EQ(lmp->atom->bond_atom, nullptr); - ASSERT_EQ(lmp->atom->num_angle, nullptr); - ASSERT_EQ(lmp->atom->angle_type, nullptr); - ASSERT_EQ(lmp->atom->angle_atom1, nullptr); - ASSERT_EQ(lmp->atom->angle_atom2, nullptr); - ASSERT_EQ(lmp->atom->angle_atom3, nullptr); - ASSERT_EQ(lmp->atom->num_dihedral, nullptr); - ASSERT_EQ(lmp->atom->dihedral_type, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); - ASSERT_EQ(lmp->atom->num_improper, nullptr); - ASSERT_EQ(lmp->atom->improper_type, nullptr); - ASSERT_EQ(lmp->atom->improper_atom1, nullptr); - ASSERT_EQ(lmp->atom->improper_atom2, nullptr); - ASSERT_EQ(lmp->atom->improper_atom3, nullptr); - ASSERT_EQ(lmp->atom->improper_atom4, nullptr); - ASSERT_EQ(lmp->atom->maxspecial, 1); - ASSERT_EQ(lmp->atom->nspecial, nullptr); - ASSERT_EQ(lmp->atom->special, nullptr); - ASSERT_EQ(lmp->atom->vfrac, nullptr); - ASSERT_EQ(lmp->atom->s0, nullptr); - ASSERT_EQ(lmp->atom->x0, nullptr); - ASSERT_EQ(lmp->atom->sp, nullptr); - ASSERT_EQ(lmp->atom->fm, nullptr); - ASSERT_EQ(lmp->atom->fm_long, nullptr); - ASSERT_EQ(lmp->atom->spin, nullptr); - ASSERT_EQ(lmp->atom->eradius, nullptr); - ASSERT_EQ(lmp->atom->ervel, nullptr); - ASSERT_EQ(lmp->atom->erforce, nullptr); - ASSERT_EQ(lmp->atom->ervelforce, nullptr); - ASSERT_EQ(lmp->atom->cs, nullptr); - ASSERT_EQ(lmp->atom->csforce, nullptr); - ASSERT_EQ(lmp->atom->vforce, nullptr); - ASSERT_EQ(lmp->atom->etag, nullptr); - ASSERT_EQ(lmp->atom->uCond, nullptr); - ASSERT_EQ(lmp->atom->uMech, nullptr); - ASSERT_EQ(lmp->atom->uChem, nullptr); - ASSERT_EQ(lmp->atom->uCG, nullptr); - ASSERT_EQ(lmp->atom->uCGnew, nullptr); - ASSERT_EQ(lmp->atom->duChem, nullptr); - ASSERT_EQ(lmp->atom->dpdTheta, nullptr); - ASSERT_EQ(lmp->atom->cc, nullptr); - ASSERT_EQ(lmp->atom->cc_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_temp, nullptr); - ASSERT_EQ(lmp->atom->edpd_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_cv, nullptr); - ASSERT_EQ(lmp->atom->length, nullptr); - ASSERT_EQ(lmp->atom->buckling, nullptr); - ASSERT_EQ(lmp->atom->bond_nt, nullptr); - ASSERT_EQ(lmp->atom->contact_radius, nullptr); - ASSERT_EQ(lmp->atom->smd_data_9, nullptr); - ASSERT_EQ(lmp->atom->smd_stress, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - ASSERT_EQ(lmp->atom->damage, nullptr); - ASSERT_EQ(lmp->atom->rho, nullptr); - ASSERT_EQ(lmp->atom->drho, nullptr); - ASSERT_EQ(lmp->atom->esph, nullptr); - ASSERT_EQ(lmp->atom->desph, nullptr); - ASSERT_EQ(lmp->atom->cv, nullptr); - ASSERT_EQ(lmp->atom->vest, nullptr); - ASSERT_EQ(lmp->atom->nmolecule, 0); - ASSERT_EQ(lmp->atom->molecules, nullptr); - ASSERT_EQ(lmp->atom->nivector, 0); - ASSERT_EQ(lmp->atom->ndvector, 0); - ASSERT_EQ(lmp->atom->iname, nullptr); - ASSERT_EQ(lmp->atom->dname, nullptr); - ASSERT_EQ(lmp->atom->mass, nullptr); - ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - ASSERT_EQ(lmp->atom->nextra_grow, 0); - ASSERT_EQ(lmp->atom->nextra_restart, 0); - ASSERT_EQ(lmp->atom->nextra_border, 0); - ASSERT_EQ(lmp->atom->nextra_grow_max, 0); - ASSERT_EQ(lmp->atom->nextra_restart_max, 0); - ASSERT_EQ(lmp->atom->nextra_border_max, 0); - ASSERT_EQ(lmp->atom->nextra_store, 0); - ASSERT_EQ(lmp->atom->extra_grow, nullptr); - ASSERT_EQ(lmp->atom->extra_restart, nullptr); - ASSERT_EQ(lmp->atom->extra_border, nullptr); - ASSERT_EQ(lmp->atom->extra, nullptr); - ASSERT_EQ(lmp->atom->sametag, nullptr); - ASSERT_EQ(lmp->atom->map_style, Atom::MAP_NONE); - ASSERT_EQ(lmp->atom->map_user, 0); - ASSERT_EQ(lmp->atom->map_tag_max, -1); + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("atom_style charge"); lmp->input->one("atom_style atomic"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); - ASSERT_NE(lmp->atom->avec, nullptr); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::ATOMIC); - ASSERT_EQ(lmp->atom->ntypes, 0); - - ASSERT_EQ(lmp->atom->molecule_flag, 0); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - - ASSERT_EQ(lmp->atom->q_flag, 0); - ASSERT_EQ(lmp->atom->q, nullptr); + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("atom_modify map hash"); @@ -353,6 +497,7 @@ TEST_F(AtomStyleTest, atomic) lmp->input->one("mass 2 2.4"); lmp->input->one("pair_coeff * *"); if (!verbose) ::testing::internal::GetCapturedStdout(); + ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); From e6c844d7192b5779b51c430447404bffda552c77 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 13 Nov 2020 13:11:16 -0500 Subject: [PATCH 27/67] Simplify template and template_charge test cases --- unittest/formats/test_atom_styles.cpp | 412 +++----------------------- 1 file changed, 39 insertions(+), 373 deletions(-) diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index fed52f8745..5529176f4f 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -3625,193 +3625,24 @@ TEST_F(AtomStyleTest, template) lmp->input->one("atom_style template twomols"); lmp->input->one("newton on"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); - ASSERT_NE(lmp->atom->avec, nullptr); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::TEMPLATE); - ASSERT_EQ(lmp->atom->nellipsoids, 0); - ASSERT_EQ(lmp->atom->nlines, 0); - ASSERT_EQ(lmp->atom->ntris, 0); - ASSERT_EQ(lmp->atom->nbodies, 0); - ASSERT_EQ(lmp->atom->nbonds, 0); - ASSERT_EQ(lmp->atom->nangles, 0); - ASSERT_EQ(lmp->atom->ndihedrals, 0); - ASSERT_EQ(lmp->atom->nimpropers, 0); - ASSERT_EQ(lmp->atom->ntypes, 0); - ASSERT_EQ(lmp->atom->nbondtypes, 2); - ASSERT_EQ(lmp->atom->nangletypes, 2); - ASSERT_EQ(lmp->atom->ndihedraltypes, 0); - ASSERT_EQ(lmp->atom->nimpropertypes, 0); - ASSERT_EQ(lmp->atom->bond_per_atom, 0); - ASSERT_EQ(lmp->atom->angle_per_atom, 0); - ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->improper_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - ASSERT_EQ(lmp->atom->sphere_flag, 0); - ASSERT_EQ(lmp->atom->ellipsoid_flag, 0); - ASSERT_EQ(lmp->atom->line_flag, 0); - ASSERT_EQ(lmp->atom->tri_flag, 0); - ASSERT_EQ(lmp->atom->body_flag, 0); - ASSERT_EQ(lmp->atom->peri_flag, 0); - ASSERT_EQ(lmp->atom->electron_flag, 0); - ASSERT_EQ(lmp->atom->wavepacket_flag, 0); - ASSERT_EQ(lmp->atom->sph_flag, 0); - ASSERT_EQ(lmp->atom->molecule_flag, 1); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - ASSERT_EQ(lmp->atom->q_flag, 0); - ASSERT_EQ(lmp->atom->mu_flag, 0); - ASSERT_EQ(lmp->atom->rmass_flag, 0); - ASSERT_EQ(lmp->atom->radius_flag, 0); - ASSERT_EQ(lmp->atom->omega_flag, 0); - ASSERT_EQ(lmp->atom->torque_flag, 0); - ASSERT_EQ(lmp->atom->angmom_flag, 0); - ASSERT_EQ(lmp->atom->vfrac_flag, 0); - ASSERT_EQ(lmp->atom->spin_flag, 0); - ASSERT_EQ(lmp->atom->eradius_flag, 0); - ASSERT_EQ(lmp->atom->ervel_flag, 0); - ASSERT_EQ(lmp->atom->erforce_flag, 0); - ASSERT_EQ(lmp->atom->cs_flag, 0); - ASSERT_EQ(lmp->atom->csforce_flag, 0); - ASSERT_EQ(lmp->atom->vforce_flag, 0); - ASSERT_EQ(lmp->atom->ervelforce_flag, 0); - ASSERT_EQ(lmp->atom->etag_flag, 0); - ASSERT_EQ(lmp->atom->rho_flag, 0); - ASSERT_EQ(lmp->atom->esph_flag, 0); - ASSERT_EQ(lmp->atom->cv_flag, 0); - ASSERT_EQ(lmp->atom->vest_flag, 0); - ASSERT_EQ(lmp->atom->dpd_flag, 0); - ASSERT_EQ(lmp->atom->edpd_flag, 0); - ASSERT_EQ(lmp->atom->tdpd_flag, 0); - ASSERT_EQ(lmp->atom->mesont_flag, 0); - ASSERT_EQ(lmp->atom->sp_flag, 0); - ASSERT_EQ(lmp->atom->x0_flag, 0); - ASSERT_EQ(lmp->atom->smd_flag, 0); - ASSERT_EQ(lmp->atom->damage_flag, 0); - ASSERT_EQ(lmp->atom->contact_radius_flag, 0); - ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); - ASSERT_EQ(lmp->atom->smd_stress_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - ASSERT_EQ(lmp->atom->pdscale, 1.0); - - ASSERT_NE(lmp->atom->tag, nullptr); - ASSERT_NE(lmp->atom->type, nullptr); - ASSERT_NE(lmp->atom->mask, nullptr); - ASSERT_NE(lmp->atom->image, nullptr); - ASSERT_NE(lmp->atom->x, nullptr); - ASSERT_NE(lmp->atom->v, nullptr); - ASSERT_NE(lmp->atom->f, nullptr); - ASSERT_EQ(lmp->atom->q, nullptr); - ASSERT_EQ(lmp->atom->mu, nullptr); - ASSERT_EQ(lmp->atom->omega, nullptr); - ASSERT_EQ(lmp->atom->angmom, nullptr); - ASSERT_EQ(lmp->atom->torque, nullptr); - ASSERT_EQ(lmp->atom->radius, nullptr); - ASSERT_EQ(lmp->atom->rmass, nullptr); - ASSERT_EQ(lmp->atom->ellipsoid, nullptr); - ASSERT_EQ(lmp->atom->line, nullptr); - ASSERT_EQ(lmp->atom->tri, nullptr); - ASSERT_EQ(lmp->atom->body, nullptr); - ASSERT_NE(lmp->atom->molecule, nullptr); - ASSERT_NE(lmp->atom->molindex, nullptr); - ASSERT_NE(lmp->atom->molatom, nullptr); - ASSERT_EQ(lmp->atom->num_bond, nullptr); - ASSERT_EQ(lmp->atom->bond_type, nullptr); - ASSERT_EQ(lmp->atom->bond_atom, nullptr); - ASSERT_EQ(lmp->atom->num_angle, nullptr); - ASSERT_EQ(lmp->atom->angle_type, nullptr); - ASSERT_EQ(lmp->atom->angle_atom1, nullptr); - ASSERT_EQ(lmp->atom->angle_atom2, nullptr); - ASSERT_EQ(lmp->atom->angle_atom3, nullptr); - ASSERT_EQ(lmp->atom->num_dihedral, nullptr); - ASSERT_EQ(lmp->atom->dihedral_type, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); - ASSERT_EQ(lmp->atom->num_improper, nullptr); - ASSERT_EQ(lmp->atom->improper_type, nullptr); - ASSERT_EQ(lmp->atom->improper_atom1, nullptr); - ASSERT_EQ(lmp->atom->improper_atom2, nullptr); - ASSERT_EQ(lmp->atom->improper_atom3, nullptr); - ASSERT_EQ(lmp->atom->improper_atom4, nullptr); - ASSERT_EQ(lmp->atom->maxspecial, 1); - ASSERT_EQ(lmp->atom->nspecial, nullptr); - ASSERT_EQ(lmp->atom->special, nullptr); - ASSERT_EQ(lmp->atom->vfrac, nullptr); - ASSERT_EQ(lmp->atom->s0, nullptr); - ASSERT_EQ(lmp->atom->x0, nullptr); - ASSERT_EQ(lmp->atom->sp, nullptr); - ASSERT_EQ(lmp->atom->fm, nullptr); - ASSERT_EQ(lmp->atom->fm_long, nullptr); - ASSERT_EQ(lmp->atom->spin, nullptr); - ASSERT_EQ(lmp->atom->eradius, nullptr); - ASSERT_EQ(lmp->atom->ervel, nullptr); - ASSERT_EQ(lmp->atom->erforce, nullptr); - ASSERT_EQ(lmp->atom->ervelforce, nullptr); - ASSERT_EQ(lmp->atom->cs, nullptr); - ASSERT_EQ(lmp->atom->csforce, nullptr); - ASSERT_EQ(lmp->atom->vforce, nullptr); - ASSERT_EQ(lmp->atom->etag, nullptr); - ASSERT_EQ(lmp->atom->uCond, nullptr); - ASSERT_EQ(lmp->atom->uMech, nullptr); - ASSERT_EQ(lmp->atom->uChem, nullptr); - ASSERT_EQ(lmp->atom->uCG, nullptr); - ASSERT_EQ(lmp->atom->uCGnew, nullptr); - ASSERT_EQ(lmp->atom->duChem, nullptr); - ASSERT_EQ(lmp->atom->dpdTheta, nullptr); - ASSERT_EQ(lmp->atom->cc, nullptr); - ASSERT_EQ(lmp->atom->cc_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_temp, nullptr); - ASSERT_EQ(lmp->atom->edpd_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_cv, nullptr); - ASSERT_EQ(lmp->atom->length, nullptr); - ASSERT_EQ(lmp->atom->buckling, nullptr); - ASSERT_EQ(lmp->atom->bond_nt, nullptr); - ASSERT_EQ(lmp->atom->contact_radius, nullptr); - ASSERT_EQ(lmp->atom->smd_data_9, nullptr); - ASSERT_EQ(lmp->atom->smd_stress, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - ASSERT_EQ(lmp->atom->damage, nullptr); - ASSERT_EQ(lmp->atom->rho, nullptr); - ASSERT_EQ(lmp->atom->drho, nullptr); - ASSERT_EQ(lmp->atom->esph, nullptr); - ASSERT_EQ(lmp->atom->desph, nullptr); - ASSERT_EQ(lmp->atom->cv, nullptr); - ASSERT_EQ(lmp->atom->vest, nullptr); - ASSERT_EQ(lmp->atom->nmolecule, 2); - ASSERT_NE(lmp->atom->molecules, nullptr); - ASSERT_EQ(lmp->atom->nivector, 0); - ASSERT_EQ(lmp->atom->ndvector, 0); - ASSERT_EQ(lmp->atom->iname, nullptr); - ASSERT_EQ(lmp->atom->dname, nullptr); - ASSERT_EQ(lmp->atom->mass, nullptr); - ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - ASSERT_EQ(lmp->atom->nextra_grow, 0); - ASSERT_EQ(lmp->atom->nextra_restart, 0); - ASSERT_EQ(lmp->atom->nextra_border, 0); - ASSERT_EQ(lmp->atom->nextra_grow_max, 0); - ASSERT_EQ(lmp->atom->nextra_restart_max, 0); - ASSERT_EQ(lmp->atom->nextra_border_max, 0); - ASSERT_EQ(lmp->atom->nextra_store, 0); - ASSERT_EQ(lmp->atom->extra_grow, nullptr); - ASSERT_EQ(lmp->atom->extra_restart, nullptr); - ASSERT_EQ(lmp->atom->extra_border, nullptr); - ASSERT_EQ(lmp->atom->extra, nullptr); - ASSERT_EQ(lmp->atom->sametag, nullptr); - ASSERT_EQ(lmp->atom->map_style, 3); - ASSERT_EQ(lmp->atom->map_user, 0); - ASSERT_EQ(lmp->atom->map_tag_max, -1); + AtomState expected; + expected.atom_style = "template"; + expected.molecular = Atom::TEMPLATE; + expected.nbondtypes = 2; + expected.nangletypes = 2; + expected.tag_enable = 1; + expected.has_type = true; + expected.has_mask = true; + expected.has_image = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; + expected.molecule_flag = 1; + expected.molindex_flag = 1; + expected.molatom_flag = 1; + expected.nmolecule = 2; + expected.map_style = 3; if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 4 box bond/types 2 angle/types 2 "); @@ -4188,201 +4019,36 @@ TEST_F(AtomStyleTest, template_charge) lmp->input->one("atom_style hybrid template twomols charge"); lmp->input->one("newton on"); if (!verbose) ::testing::internal::GetCapturedStdout(); + + AtomState expected; + expected.atom_style = "hybrid"; + expected.molecular = Atom::TEMPLATE; + expected.nbondtypes = 2; + expected.nangletypes = 2; + expected.tag_enable = 1; + expected.has_type = true; + expected.has_mask = true; + expected.has_image = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; + expected.molecule_flag = 1; + expected.molindex_flag = 1; + expected.molatom_flag = 1; + expected.q_flag = 1; + expected.nmolecule = 2; + expected.map_style = 3; + + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); + auto hybrid = (AtomVecHybrid *)lmp->atom->avec; ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_EQ(hybrid->nstyles, 2); ASSERT_THAT(std::string(hybrid->keywords[0]), Eq("template")); ASSERT_THAT(std::string(hybrid->keywords[1]), Eq("charge")); - ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_NE(hybrid->styles[0], nullptr); ASSERT_NE(hybrid->styles[1], nullptr); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::TEMPLATE); - ASSERT_EQ(lmp->atom->nellipsoids, 0); - ASSERT_EQ(lmp->atom->nlines, 0); - ASSERT_EQ(lmp->atom->ntris, 0); - ASSERT_EQ(lmp->atom->nbodies, 0); - ASSERT_EQ(lmp->atom->nbonds, 0); - ASSERT_EQ(lmp->atom->nangles, 0); - ASSERT_EQ(lmp->atom->ndihedrals, 0); - ASSERT_EQ(lmp->atom->nimpropers, 0); - ASSERT_EQ(lmp->atom->ntypes, 0); - ASSERT_EQ(lmp->atom->nbondtypes, 2); - ASSERT_EQ(lmp->atom->nangletypes, 2); - ASSERT_EQ(lmp->atom->ndihedraltypes, 0); - ASSERT_EQ(lmp->atom->nimpropertypes, 0); - ASSERT_EQ(lmp->atom->bond_per_atom, 0); - ASSERT_EQ(lmp->atom->angle_per_atom, 0); - ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->improper_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - - ASSERT_EQ(lmp->atom->sphere_flag, 0); - ASSERT_EQ(lmp->atom->ellipsoid_flag, 0); - ASSERT_EQ(lmp->atom->line_flag, 0); - ASSERT_EQ(lmp->atom->tri_flag, 0); - ASSERT_EQ(lmp->atom->body_flag, 0); - ASSERT_EQ(lmp->atom->peri_flag, 0); - ASSERT_EQ(lmp->atom->electron_flag, 0); - ASSERT_EQ(lmp->atom->wavepacket_flag, 0); - ASSERT_EQ(lmp->atom->sph_flag, 0); - ASSERT_EQ(lmp->atom->molecule_flag, 1); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - ASSERT_EQ(lmp->atom->q_flag, 1); - ASSERT_EQ(lmp->atom->mu_flag, 0); - ASSERT_EQ(lmp->atom->rmass_flag, 0); - ASSERT_EQ(lmp->atom->radius_flag, 0); - ASSERT_EQ(lmp->atom->omega_flag, 0); - ASSERT_EQ(lmp->atom->torque_flag, 0); - ASSERT_EQ(lmp->atom->angmom_flag, 0); - ASSERT_EQ(lmp->atom->vfrac_flag, 0); - ASSERT_EQ(lmp->atom->spin_flag, 0); - ASSERT_EQ(lmp->atom->eradius_flag, 0); - ASSERT_EQ(lmp->atom->ervel_flag, 0); - ASSERT_EQ(lmp->atom->erforce_flag, 0); - ASSERT_EQ(lmp->atom->cs_flag, 0); - ASSERT_EQ(lmp->atom->csforce_flag, 0); - ASSERT_EQ(lmp->atom->vforce_flag, 0); - ASSERT_EQ(lmp->atom->ervelforce_flag, 0); - ASSERT_EQ(lmp->atom->etag_flag, 0); - ASSERT_EQ(lmp->atom->rho_flag, 0); - ASSERT_EQ(lmp->atom->esph_flag, 0); - ASSERT_EQ(lmp->atom->cv_flag, 0); - ASSERT_EQ(lmp->atom->vest_flag, 0); - ASSERT_EQ(lmp->atom->dpd_flag, 0); - ASSERT_EQ(lmp->atom->edpd_flag, 0); - ASSERT_EQ(lmp->atom->tdpd_flag, 0); - ASSERT_EQ(lmp->atom->mesont_flag, 0); - ASSERT_EQ(lmp->atom->sp_flag, 0); - ASSERT_EQ(lmp->atom->x0_flag, 0); - ASSERT_EQ(lmp->atom->smd_flag, 0); - ASSERT_EQ(lmp->atom->damage_flag, 0); - ASSERT_EQ(lmp->atom->contact_radius_flag, 0); - ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); - ASSERT_EQ(lmp->atom->smd_stress_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - ASSERT_EQ(lmp->atom->pdscale, 1.0); - - ASSERT_NE(lmp->atom->tag, nullptr); - ASSERT_NE(lmp->atom->type, nullptr); - ASSERT_NE(lmp->atom->mask, nullptr); - ASSERT_NE(lmp->atom->image, nullptr); - ASSERT_NE(lmp->atom->x, nullptr); - ASSERT_NE(lmp->atom->v, nullptr); - ASSERT_NE(lmp->atom->f, nullptr); - ASSERT_NE(lmp->atom->q, nullptr); - ASSERT_EQ(lmp->atom->mu, nullptr); - ASSERT_EQ(lmp->atom->omega, nullptr); - ASSERT_EQ(lmp->atom->angmom, nullptr); - ASSERT_EQ(lmp->atom->torque, nullptr); - ASSERT_EQ(lmp->atom->radius, nullptr); - ASSERT_EQ(lmp->atom->rmass, nullptr); - ASSERT_EQ(lmp->atom->ellipsoid, nullptr); - ASSERT_EQ(lmp->atom->line, nullptr); - ASSERT_EQ(lmp->atom->tri, nullptr); - ASSERT_EQ(lmp->atom->body, nullptr); - ASSERT_NE(lmp->atom->molecule, nullptr); - ASSERT_NE(lmp->atom->molindex, nullptr); - ASSERT_NE(lmp->atom->molatom, nullptr); - ASSERT_EQ(lmp->atom->num_bond, nullptr); - ASSERT_EQ(lmp->atom->bond_type, nullptr); - ASSERT_EQ(lmp->atom->bond_atom, nullptr); - ASSERT_EQ(lmp->atom->num_angle, nullptr); - ASSERT_EQ(lmp->atom->angle_type, nullptr); - ASSERT_EQ(lmp->atom->angle_atom1, nullptr); - ASSERT_EQ(lmp->atom->angle_atom2, nullptr); - ASSERT_EQ(lmp->atom->angle_atom3, nullptr); - ASSERT_EQ(lmp->atom->num_dihedral, nullptr); - ASSERT_EQ(lmp->atom->dihedral_type, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); - ASSERT_EQ(lmp->atom->num_improper, nullptr); - ASSERT_EQ(lmp->atom->improper_type, nullptr); - ASSERT_EQ(lmp->atom->improper_atom1, nullptr); - ASSERT_EQ(lmp->atom->improper_atom2, nullptr); - ASSERT_EQ(lmp->atom->improper_atom3, nullptr); - ASSERT_EQ(lmp->atom->improper_atom4, nullptr); - ASSERT_EQ(lmp->atom->maxspecial, 1); - ASSERT_EQ(lmp->atom->nspecial, nullptr); - ASSERT_EQ(lmp->atom->special, nullptr); - ASSERT_EQ(lmp->atom->vfrac, nullptr); - ASSERT_EQ(lmp->atom->s0, nullptr); - ASSERT_EQ(lmp->atom->x0, nullptr); - ASSERT_EQ(lmp->atom->sp, nullptr); - ASSERT_EQ(lmp->atom->fm, nullptr); - ASSERT_EQ(lmp->atom->fm_long, nullptr); - ASSERT_EQ(lmp->atom->spin, nullptr); - ASSERT_EQ(lmp->atom->eradius, nullptr); - ASSERT_EQ(lmp->atom->ervel, nullptr); - ASSERT_EQ(lmp->atom->erforce, nullptr); - ASSERT_EQ(lmp->atom->ervelforce, nullptr); - ASSERT_EQ(lmp->atom->cs, nullptr); - ASSERT_EQ(lmp->atom->csforce, nullptr); - ASSERT_EQ(lmp->atom->vforce, nullptr); - ASSERT_EQ(lmp->atom->etag, nullptr); - ASSERT_EQ(lmp->atom->uCond, nullptr); - ASSERT_EQ(lmp->atom->uMech, nullptr); - ASSERT_EQ(lmp->atom->uChem, nullptr); - ASSERT_EQ(lmp->atom->uCG, nullptr); - ASSERT_EQ(lmp->atom->uCGnew, nullptr); - ASSERT_EQ(lmp->atom->duChem, nullptr); - ASSERT_EQ(lmp->atom->dpdTheta, nullptr); - ASSERT_EQ(lmp->atom->cc, nullptr); - ASSERT_EQ(lmp->atom->cc_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_temp, nullptr); - ASSERT_EQ(lmp->atom->edpd_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_cv, nullptr); - ASSERT_EQ(lmp->atom->length, nullptr); - ASSERT_EQ(lmp->atom->buckling, nullptr); - ASSERT_EQ(lmp->atom->bond_nt, nullptr); - ASSERT_EQ(lmp->atom->contact_radius, nullptr); - ASSERT_EQ(lmp->atom->smd_data_9, nullptr); - ASSERT_EQ(lmp->atom->smd_stress, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - ASSERT_EQ(lmp->atom->damage, nullptr); - ASSERT_EQ(lmp->atom->rho, nullptr); - ASSERT_EQ(lmp->atom->drho, nullptr); - ASSERT_EQ(lmp->atom->esph, nullptr); - ASSERT_EQ(lmp->atom->desph, nullptr); - ASSERT_EQ(lmp->atom->cv, nullptr); - ASSERT_EQ(lmp->atom->vest, nullptr); - ASSERT_EQ(lmp->atom->nmolecule, 2); - ASSERT_NE(lmp->atom->molecules, nullptr); - ASSERT_EQ(lmp->atom->nivector, 0); - ASSERT_EQ(lmp->atom->ndvector, 0); - ASSERT_EQ(lmp->atom->iname, nullptr); - ASSERT_EQ(lmp->atom->dname, nullptr); - ASSERT_EQ(lmp->atom->mass, nullptr); - ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - ASSERT_EQ(lmp->atom->nextra_grow, 0); - ASSERT_EQ(lmp->atom->nextra_restart, 0); - ASSERT_EQ(lmp->atom->nextra_border, 0); - ASSERT_EQ(lmp->atom->nextra_grow_max, 0); - ASSERT_EQ(lmp->atom->nextra_restart_max, 0); - ASSERT_EQ(lmp->atom->nextra_border_max, 0); - ASSERT_EQ(lmp->atom->nextra_store, 0); - ASSERT_EQ(lmp->atom->extra_grow, nullptr); - ASSERT_EQ(lmp->atom->extra_restart, nullptr); - ASSERT_EQ(lmp->atom->extra_border, nullptr); - ASSERT_EQ(lmp->atom->extra, nullptr); - ASSERT_EQ(lmp->atom->sametag, nullptr); - ASSERT_EQ(lmp->atom->map_style, 3); - ASSERT_EQ(lmp->atom->map_user, 0); - ASSERT_EQ(lmp->atom->map_tag_max, -1); - if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 4 box bond/types 2 angle/types 2 "); lmp->input->one("create_atoms 0 single -2.0 2.0 0.1 mol twomols 65234"); From 76e3639db2763f32c3eccae60a65c1431596a04b Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 13 Nov 2020 13:11:46 -0500 Subject: [PATCH 28/67] Set molindex_flag and molatom_flag --- src/MOLECULE/atom_vec_template.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/MOLECULE/atom_vec_template.cpp b/src/MOLECULE/atom_vec_template.cpp index c01942eb5c..0aefc66e26 100644 --- a/src/MOLECULE/atom_vec_template.cpp +++ b/src/MOLECULE/atom_vec_template.cpp @@ -27,6 +27,8 @@ AtomVecTemplate::AtomVecTemplate(LAMMPS *lmp) : AtomVec(lmp) mass_type = PER_TYPE; atom->molecule_flag = 1; + atom->molindex_flag = 1; + atom->molatom_flag = 1; // strings with peratom variables to include in each AtomVec method // strings cannot contain fields in corresponding AtomVec default strings From 504e67502320bf5a3bc75b76afa849ae2f5b3b04 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 13 Nov 2020 13:19:44 -0500 Subject: [PATCH 29/67] Splitting up long test methods --- unittest/formats/test_atom_styles.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index 5529176f4f..88ebcbc669 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -464,7 +464,7 @@ void ASSERT_ATOM_STATE_EQ(Atom* atom, const AtomState& expected) { ASSERT_EQ(atom->map_tag_max, expected.map_tag_max); } -TEST_F(AtomStyleTest, atomic) +TEST_F(AtomStyleTest, atomic_is_default) { AtomState expected; expected.atom_style = "atomic"; @@ -478,6 +478,20 @@ TEST_F(AtomStyleTest, atomic) expected.has_f = true; ASSERT_ATOM_STATE_EQ(lmp->atom, expected); +} + +TEST_F(AtomStyleTest, atomic_after_charge) +{ + AtomState expected; + expected.atom_style = "atomic"; + expected.molecular = Atom::ATOMIC; + expected.tag_enable = 1; + expected.has_type = true; + expected.has_mask = true; + expected.has_image = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("atom_style charge"); @@ -485,7 +499,10 @@ TEST_F(AtomStyleTest, atomic) if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_ATOM_STATE_EQ(lmp->atom, expected); +} +TEST_F(AtomStyleTest, atomic) +{ if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("atom_modify map hash"); lmp->input->one("create_box 2 box"); From 5d79ba12d753c588a164153510144ccf9b46c19a Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 13 Nov 2020 15:14:28 -0500 Subject: [PATCH 30/67] Use macro for better message during failure --- unittest/formats/test_atom_styles.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index 88ebcbc669..f516c7f4f8 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -248,14 +248,12 @@ struct AtomState { bool has_mass_setflag = false; }; -template -void ASSERT_ARRAY_ALLOCATED(const T * ptr, bool enabled) { - if (enabled) { - ASSERT_NE(ptr, nullptr); - } else { - ASSERT_EQ(ptr, nullptr); +#define ASSERT_ARRAY_ALLOCATED(ptr, enabled) \ + if (enabled) { \ + ASSERT_NE(ptr, nullptr); \ + } else { \ + ASSERT_EQ(ptr, nullptr); \ } -} void ASSERT_ATOM_STATE_EQ(Atom* atom, const AtomState& expected) { ASSERT_THAT(std::string(atom->atom_style), Eq(expected.atom_style)); From bfd71f330ba5418f29e6b36d66d6719b3c00a5d6 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 13 Nov 2020 17:03:52 -0500 Subject: [PATCH 31/67] Simplify other AtomStyles tests --- unittest/formats/test_atom_styles.cpp | 1838 +++---------------------- 1 file changed, 166 insertions(+), 1672 deletions(-) diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index f516c7f4f8..d6acd78295 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -246,6 +246,9 @@ struct AtomState { bool has_dname = false; bool has_mass = false; bool has_mass_setflag = false; + + bool has_nspecial = false; + bool has_special = false; }; #define ASSERT_ARRAY_ALLOCATED(ptr, enabled) \ @@ -386,8 +389,8 @@ void ASSERT_ATOM_STATE_EQ(Atom* atom, const AtomState& expected) { ASSERT_EQ(atom->maxspecial, expected.maxspecial); // currently ignored - ASSERT_ARRAY_ALLOCATED(atom->nspecial, false); - ASSERT_ARRAY_ALLOCATED(atom->special, false); + ASSERT_ARRAY_ALLOCATED(atom->nspecial, expected.has_nspecial); + ASSERT_ARRAY_ALLOCATED(atom->special, expected.has_special); ASSERT_ARRAY_ALLOCATED(atom->vfrac, false); ASSERT_ARRAY_ALLOCATED(atom->s0, false); ASSERT_ARRAY_ALLOCATED(atom->x0, false); @@ -433,7 +436,7 @@ void ASSERT_ATOM_STATE_EQ(Atom* atom, const AtomState& expected) { ASSERT_EQ(atom->nmolecule, expected.nmolecule); - ASSERT_ARRAY_ALLOCATED(atom->molecules, expected.molecule_flag); + ASSERT_ARRAY_ALLOCATED(atom->molecules, expected.nmolecule > 0); ASSERT_EQ(atom->nivector, expected.nivector); ASSERT_EQ(atom->ndvector, expected.ndvector); @@ -695,193 +698,19 @@ TEST_F(AtomStyleTest, charge) if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("atom_style charge"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("charge")); - ASSERT_NE(lmp->atom->avec, nullptr); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::ATOMIC); - ASSERT_EQ(lmp->atom->nellipsoids, 0); - ASSERT_EQ(lmp->atom->nlines, 0); - ASSERT_EQ(lmp->atom->ntris, 0); - ASSERT_EQ(lmp->atom->nbodies, 0); - ASSERT_EQ(lmp->atom->nbonds, 0); - ASSERT_EQ(lmp->atom->nangles, 0); - ASSERT_EQ(lmp->atom->ndihedrals, 0); - ASSERT_EQ(lmp->atom->nimpropers, 0); - ASSERT_EQ(lmp->atom->ntypes, 0); - ASSERT_EQ(lmp->atom->nbondtypes, 0); - ASSERT_EQ(lmp->atom->nangletypes, 0); - ASSERT_EQ(lmp->atom->ndihedraltypes, 0); - ASSERT_EQ(lmp->atom->nimpropertypes, 0); - ASSERT_EQ(lmp->atom->bond_per_atom, 0); - ASSERT_EQ(lmp->atom->angle_per_atom, 0); - ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->improper_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - ASSERT_EQ(lmp->atom->sphere_flag, 0); - ASSERT_EQ(lmp->atom->ellipsoid_flag, 0); - ASSERT_EQ(lmp->atom->line_flag, 0); - ASSERT_EQ(lmp->atom->tri_flag, 0); - ASSERT_EQ(lmp->atom->body_flag, 0); - ASSERT_EQ(lmp->atom->peri_flag, 0); - ASSERT_EQ(lmp->atom->electron_flag, 0); - ASSERT_EQ(lmp->atom->wavepacket_flag, 0); - ASSERT_EQ(lmp->atom->sph_flag, 0); - ASSERT_EQ(lmp->atom->molecule_flag, 0); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - ASSERT_EQ(lmp->atom->q_flag, 1); - ASSERT_EQ(lmp->atom->mu_flag, 0); - ASSERT_EQ(lmp->atom->rmass_flag, 0); - ASSERT_EQ(lmp->atom->radius_flag, 0); - ASSERT_EQ(lmp->atom->omega_flag, 0); - ASSERT_EQ(lmp->atom->torque_flag, 0); - ASSERT_EQ(lmp->atom->angmom_flag, 0); - ASSERT_EQ(lmp->atom->vfrac_flag, 0); - ASSERT_EQ(lmp->atom->spin_flag, 0); - ASSERT_EQ(lmp->atom->eradius_flag, 0); - ASSERT_EQ(lmp->atom->ervel_flag, 0); - ASSERT_EQ(lmp->atom->erforce_flag, 0); - ASSERT_EQ(lmp->atom->cs_flag, 0); - ASSERT_EQ(lmp->atom->csforce_flag, 0); - ASSERT_EQ(lmp->atom->vforce_flag, 0); - ASSERT_EQ(lmp->atom->ervelforce_flag, 0); - ASSERT_EQ(lmp->atom->etag_flag, 0); - ASSERT_EQ(lmp->atom->rho_flag, 0); - ASSERT_EQ(lmp->atom->esph_flag, 0); - ASSERT_EQ(lmp->atom->cv_flag, 0); - ASSERT_EQ(lmp->atom->vest_flag, 0); - ASSERT_EQ(lmp->atom->dpd_flag, 0); - ASSERT_EQ(lmp->atom->edpd_flag, 0); - ASSERT_EQ(lmp->atom->tdpd_flag, 0); - ASSERT_EQ(lmp->atom->mesont_flag, 0); - ASSERT_EQ(lmp->atom->sp_flag, 0); - ASSERT_EQ(lmp->atom->x0_flag, 0); - ASSERT_EQ(lmp->atom->smd_flag, 0); - ASSERT_EQ(lmp->atom->damage_flag, 0); - ASSERT_EQ(lmp->atom->contact_radius_flag, 0); - ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); - ASSERT_EQ(lmp->atom->smd_stress_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - ASSERT_EQ(lmp->atom->pdscale, 1.0); - - ASSERT_NE(lmp->atom->tag, nullptr); - ASSERT_NE(lmp->atom->type, nullptr); - ASSERT_NE(lmp->atom->mask, nullptr); - ASSERT_NE(lmp->atom->image, nullptr); - ASSERT_NE(lmp->atom->x, nullptr); - ASSERT_NE(lmp->atom->v, nullptr); - ASSERT_NE(lmp->atom->f, nullptr); - ASSERT_NE(lmp->atom->q, nullptr); - ASSERT_EQ(lmp->atom->mu, nullptr); - ASSERT_EQ(lmp->atom->omega, nullptr); - ASSERT_EQ(lmp->atom->angmom, nullptr); - ASSERT_EQ(lmp->atom->torque, nullptr); - ASSERT_EQ(lmp->atom->radius, nullptr); - ASSERT_EQ(lmp->atom->rmass, nullptr); - ASSERT_EQ(lmp->atom->ellipsoid, nullptr); - ASSERT_EQ(lmp->atom->line, nullptr); - ASSERT_EQ(lmp->atom->tri, nullptr); - ASSERT_EQ(lmp->atom->body, nullptr); - ASSERT_EQ(lmp->atom->molecule, nullptr); - ASSERT_EQ(lmp->atom->molindex, nullptr); - ASSERT_EQ(lmp->atom->molatom, nullptr); - ASSERT_EQ(lmp->atom->num_bond, nullptr); - ASSERT_EQ(lmp->atom->bond_type, nullptr); - ASSERT_EQ(lmp->atom->bond_atom, nullptr); - ASSERT_EQ(lmp->atom->num_angle, nullptr); - ASSERT_EQ(lmp->atom->angle_type, nullptr); - ASSERT_EQ(lmp->atom->angle_atom1, nullptr); - ASSERT_EQ(lmp->atom->angle_atom2, nullptr); - ASSERT_EQ(lmp->atom->angle_atom3, nullptr); - ASSERT_EQ(lmp->atom->num_dihedral, nullptr); - ASSERT_EQ(lmp->atom->dihedral_type, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); - ASSERT_EQ(lmp->atom->num_improper, nullptr); - ASSERT_EQ(lmp->atom->improper_type, nullptr); - ASSERT_EQ(lmp->atom->improper_atom1, nullptr); - ASSERT_EQ(lmp->atom->improper_atom2, nullptr); - ASSERT_EQ(lmp->atom->improper_atom3, nullptr); - ASSERT_EQ(lmp->atom->improper_atom4, nullptr); - ASSERT_EQ(lmp->atom->maxspecial, 1); - ASSERT_EQ(lmp->atom->nspecial, nullptr); - ASSERT_EQ(lmp->atom->special, nullptr); - ASSERT_EQ(lmp->atom->vfrac, nullptr); - ASSERT_EQ(lmp->atom->s0, nullptr); - ASSERT_EQ(lmp->atom->x0, nullptr); - ASSERT_EQ(lmp->atom->sp, nullptr); - ASSERT_EQ(lmp->atom->fm, nullptr); - ASSERT_EQ(lmp->atom->fm_long, nullptr); - ASSERT_EQ(lmp->atom->spin, nullptr); - ASSERT_EQ(lmp->atom->eradius, nullptr); - ASSERT_EQ(lmp->atom->ervel, nullptr); - ASSERT_EQ(lmp->atom->erforce, nullptr); - ASSERT_EQ(lmp->atom->ervelforce, nullptr); - ASSERT_EQ(lmp->atom->cs, nullptr); - ASSERT_EQ(lmp->atom->csforce, nullptr); - ASSERT_EQ(lmp->atom->vforce, nullptr); - ASSERT_EQ(lmp->atom->etag, nullptr); - ASSERT_EQ(lmp->atom->uCond, nullptr); - ASSERT_EQ(lmp->atom->uMech, nullptr); - ASSERT_EQ(lmp->atom->uChem, nullptr); - ASSERT_EQ(lmp->atom->uCG, nullptr); - ASSERT_EQ(lmp->atom->uCGnew, nullptr); - ASSERT_EQ(lmp->atom->duChem, nullptr); - ASSERT_EQ(lmp->atom->dpdTheta, nullptr); - ASSERT_EQ(lmp->atom->cc, nullptr); - ASSERT_EQ(lmp->atom->cc_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_temp, nullptr); - ASSERT_EQ(lmp->atom->edpd_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_cv, nullptr); - ASSERT_EQ(lmp->atom->length, nullptr); - ASSERT_EQ(lmp->atom->buckling, nullptr); - ASSERT_EQ(lmp->atom->bond_nt, nullptr); - ASSERT_EQ(lmp->atom->contact_radius, nullptr); - ASSERT_EQ(lmp->atom->smd_data_9, nullptr); - ASSERT_EQ(lmp->atom->smd_stress, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - ASSERT_EQ(lmp->atom->damage, nullptr); - ASSERT_EQ(lmp->atom->rho, nullptr); - ASSERT_EQ(lmp->atom->drho, nullptr); - ASSERT_EQ(lmp->atom->esph, nullptr); - ASSERT_EQ(lmp->atom->desph, nullptr); - ASSERT_EQ(lmp->atom->cv, nullptr); - ASSERT_EQ(lmp->atom->vest, nullptr); - ASSERT_EQ(lmp->atom->nmolecule, 0); - ASSERT_EQ(lmp->atom->molecules, nullptr); - ASSERT_EQ(lmp->atom->nivector, 0); - ASSERT_EQ(lmp->atom->ndvector, 0); - ASSERT_EQ(lmp->atom->iname, nullptr); - ASSERT_EQ(lmp->atom->dname, nullptr); - ASSERT_EQ(lmp->atom->mass, nullptr); - ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - ASSERT_EQ(lmp->atom->nextra_grow, 0); - ASSERT_EQ(lmp->atom->nextra_restart, 0); - ASSERT_EQ(lmp->atom->nextra_border, 0); - ASSERT_EQ(lmp->atom->nextra_grow_max, 0); - ASSERT_EQ(lmp->atom->nextra_restart_max, 0); - ASSERT_EQ(lmp->atom->nextra_border_max, 0); - ASSERT_EQ(lmp->atom->nextra_store, 0); - ASSERT_EQ(lmp->atom->extra_grow, nullptr); - ASSERT_EQ(lmp->atom->extra_restart, nullptr); - ASSERT_EQ(lmp->atom->extra_border, nullptr); - ASSERT_EQ(lmp->atom->extra, nullptr); - ASSERT_EQ(lmp->atom->sametag, nullptr); - ASSERT_EQ(lmp->atom->map_style, Atom::MAP_NONE); - ASSERT_EQ(lmp->atom->map_user, 0); - ASSERT_EQ(lmp->atom->map_tag_max, -1); + AtomState expected; + expected.atom_style = "charge"; + expected.molecular = Atom::ATOMIC; + expected.tag_enable = 1; + expected.has_type = true; + expected.has_image = true; + expected.has_mask = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; + expected.q_flag = 1; + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 2 box"); @@ -1046,193 +875,24 @@ TEST_F(AtomStyleTest, sphere) if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("atom_style sphere"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("sphere")); - ASSERT_NE(lmp->atom->avec, nullptr); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::ATOMIC); - ASSERT_EQ(lmp->atom->nellipsoids, 0); - ASSERT_EQ(lmp->atom->nlines, 0); - ASSERT_EQ(lmp->atom->ntris, 0); - ASSERT_EQ(lmp->atom->nbodies, 0); - ASSERT_EQ(lmp->atom->nbonds, 0); - ASSERT_EQ(lmp->atom->nangles, 0); - ASSERT_EQ(lmp->atom->ndihedrals, 0); - ASSERT_EQ(lmp->atom->nimpropers, 0); - ASSERT_EQ(lmp->atom->ntypes, 0); - ASSERT_EQ(lmp->atom->nbondtypes, 0); - ASSERT_EQ(lmp->atom->nangletypes, 0); - ASSERT_EQ(lmp->atom->ndihedraltypes, 0); - ASSERT_EQ(lmp->atom->nimpropertypes, 0); - ASSERT_EQ(lmp->atom->bond_per_atom, 0); - ASSERT_EQ(lmp->atom->angle_per_atom, 0); - ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->improper_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - ASSERT_EQ(lmp->atom->sphere_flag, 1); - ASSERT_EQ(lmp->atom->ellipsoid_flag, 0); - ASSERT_EQ(lmp->atom->line_flag, 0); - ASSERT_EQ(lmp->atom->tri_flag, 0); - ASSERT_EQ(lmp->atom->body_flag, 0); - ASSERT_EQ(lmp->atom->peri_flag, 0); - ASSERT_EQ(lmp->atom->electron_flag, 0); - ASSERT_EQ(lmp->atom->wavepacket_flag, 0); - ASSERT_EQ(lmp->atom->sph_flag, 0); - ASSERT_EQ(lmp->atom->molecule_flag, 0); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - ASSERT_EQ(lmp->atom->q_flag, 0); - ASSERT_EQ(lmp->atom->mu_flag, 0); - ASSERT_EQ(lmp->atom->rmass_flag, 1); - ASSERT_EQ(lmp->atom->radius_flag, 1); - ASSERT_EQ(lmp->atom->omega_flag, 1); - ASSERT_EQ(lmp->atom->torque_flag, 1); - ASSERT_EQ(lmp->atom->angmom_flag, 0); - ASSERT_EQ(lmp->atom->vfrac_flag, 0); - ASSERT_EQ(lmp->atom->spin_flag, 0); - ASSERT_EQ(lmp->atom->eradius_flag, 0); - ASSERT_EQ(lmp->atom->ervel_flag, 0); - ASSERT_EQ(lmp->atom->erforce_flag, 0); - ASSERT_EQ(lmp->atom->cs_flag, 0); - ASSERT_EQ(lmp->atom->csforce_flag, 0); - ASSERT_EQ(lmp->atom->vforce_flag, 0); - ASSERT_EQ(lmp->atom->ervelforce_flag, 0); - ASSERT_EQ(lmp->atom->etag_flag, 0); - ASSERT_EQ(lmp->atom->rho_flag, 0); - ASSERT_EQ(lmp->atom->esph_flag, 0); - ASSERT_EQ(lmp->atom->cv_flag, 0); - ASSERT_EQ(lmp->atom->vest_flag, 0); - ASSERT_EQ(lmp->atom->dpd_flag, 0); - ASSERT_EQ(lmp->atom->edpd_flag, 0); - ASSERT_EQ(lmp->atom->tdpd_flag, 0); - ASSERT_EQ(lmp->atom->mesont_flag, 0); - ASSERT_EQ(lmp->atom->sp_flag, 0); - ASSERT_EQ(lmp->atom->x0_flag, 0); - ASSERT_EQ(lmp->atom->smd_flag, 0); - ASSERT_EQ(lmp->atom->damage_flag, 0); - ASSERT_EQ(lmp->atom->contact_radius_flag, 0); - ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); - ASSERT_EQ(lmp->atom->smd_stress_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - ASSERT_EQ(lmp->atom->pdscale, 1.0); + AtomState expected; + expected.atom_style = "sphere"; + expected.molecular = Atom::ATOMIC; + expected.tag_enable = 1; + expected.sphere_flag = 1; + expected.rmass_flag = 1; + expected.radius_flag = 1; + expected.omega_flag = 1; + expected.torque_flag = 1; + expected.has_type = true; + expected.has_mask = true; + expected.has_image = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; - ASSERT_NE(lmp->atom->tag, nullptr); - ASSERT_NE(lmp->atom->type, nullptr); - ASSERT_NE(lmp->atom->mask, nullptr); - ASSERT_NE(lmp->atom->image, nullptr); - ASSERT_NE(lmp->atom->x, nullptr); - ASSERT_NE(lmp->atom->v, nullptr); - ASSERT_NE(lmp->atom->f, nullptr); - ASSERT_EQ(lmp->atom->q, nullptr); - ASSERT_EQ(lmp->atom->mu, nullptr); - ASSERT_NE(lmp->atom->omega, nullptr); - ASSERT_EQ(lmp->atom->angmom, nullptr); - ASSERT_NE(lmp->atom->torque, nullptr); - ASSERT_NE(lmp->atom->radius, nullptr); - ASSERT_NE(lmp->atom->rmass, nullptr); - ASSERT_EQ(lmp->atom->ellipsoid, nullptr); - ASSERT_EQ(lmp->atom->line, nullptr); - ASSERT_EQ(lmp->atom->tri, nullptr); - ASSERT_EQ(lmp->atom->body, nullptr); - ASSERT_EQ(lmp->atom->molecule, nullptr); - ASSERT_EQ(lmp->atom->molindex, nullptr); - ASSERT_EQ(lmp->atom->molatom, nullptr); - ASSERT_EQ(lmp->atom->num_bond, nullptr); - ASSERT_EQ(lmp->atom->bond_type, nullptr); - ASSERT_EQ(lmp->atom->bond_atom, nullptr); - ASSERT_EQ(lmp->atom->num_angle, nullptr); - ASSERT_EQ(lmp->atom->angle_type, nullptr); - ASSERT_EQ(lmp->atom->angle_atom1, nullptr); - ASSERT_EQ(lmp->atom->angle_atom2, nullptr); - ASSERT_EQ(lmp->atom->angle_atom3, nullptr); - ASSERT_EQ(lmp->atom->num_dihedral, nullptr); - ASSERT_EQ(lmp->atom->dihedral_type, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); - ASSERT_EQ(lmp->atom->num_improper, nullptr); - ASSERT_EQ(lmp->atom->improper_type, nullptr); - ASSERT_EQ(lmp->atom->improper_atom1, nullptr); - ASSERT_EQ(lmp->atom->improper_atom2, nullptr); - ASSERT_EQ(lmp->atom->improper_atom3, nullptr); - ASSERT_EQ(lmp->atom->improper_atom4, nullptr); - ASSERT_EQ(lmp->atom->maxspecial, 1); - ASSERT_EQ(lmp->atom->nspecial, nullptr); - ASSERT_EQ(lmp->atom->special, nullptr); - ASSERT_EQ(lmp->atom->vfrac, nullptr); - ASSERT_EQ(lmp->atom->s0, nullptr); - ASSERT_EQ(lmp->atom->x0, nullptr); - ASSERT_EQ(lmp->atom->sp, nullptr); - ASSERT_EQ(lmp->atom->fm, nullptr); - ASSERT_EQ(lmp->atom->fm_long, nullptr); - ASSERT_EQ(lmp->atom->spin, nullptr); - ASSERT_EQ(lmp->atom->eradius, nullptr); - ASSERT_EQ(lmp->atom->ervel, nullptr); - ASSERT_EQ(lmp->atom->erforce, nullptr); - ASSERT_EQ(lmp->atom->ervelforce, nullptr); - ASSERT_EQ(lmp->atom->cs, nullptr); - ASSERT_EQ(lmp->atom->csforce, nullptr); - ASSERT_EQ(lmp->atom->vforce, nullptr); - ASSERT_EQ(lmp->atom->etag, nullptr); - ASSERT_EQ(lmp->atom->uCond, nullptr); - ASSERT_EQ(lmp->atom->uMech, nullptr); - ASSERT_EQ(lmp->atom->uChem, nullptr); - ASSERT_EQ(lmp->atom->uCG, nullptr); - ASSERT_EQ(lmp->atom->uCGnew, nullptr); - ASSERT_EQ(lmp->atom->duChem, nullptr); - ASSERT_EQ(lmp->atom->dpdTheta, nullptr); - ASSERT_EQ(lmp->atom->cc, nullptr); - ASSERT_EQ(lmp->atom->cc_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_temp, nullptr); - ASSERT_EQ(lmp->atom->edpd_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_cv, nullptr); - ASSERT_EQ(lmp->atom->length, nullptr); - ASSERT_EQ(lmp->atom->buckling, nullptr); - ASSERT_EQ(lmp->atom->bond_nt, nullptr); - ASSERT_EQ(lmp->atom->contact_radius, nullptr); - ASSERT_EQ(lmp->atom->smd_data_9, nullptr); - ASSERT_EQ(lmp->atom->smd_stress, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - ASSERT_EQ(lmp->atom->damage, nullptr); - ASSERT_EQ(lmp->atom->rho, nullptr); - ASSERT_EQ(lmp->atom->drho, nullptr); - ASSERT_EQ(lmp->atom->esph, nullptr); - ASSERT_EQ(lmp->atom->desph, nullptr); - ASSERT_EQ(lmp->atom->cv, nullptr); - ASSERT_EQ(lmp->atom->vest, nullptr); - ASSERT_EQ(lmp->atom->nmolecule, 0); - ASSERT_EQ(lmp->atom->molecules, nullptr); - ASSERT_EQ(lmp->atom->nivector, 0); - ASSERT_EQ(lmp->atom->ndvector, 0); - ASSERT_EQ(lmp->atom->iname, nullptr); - ASSERT_EQ(lmp->atom->dname, nullptr); - ASSERT_EQ(lmp->atom->mass, nullptr); - ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - ASSERT_EQ(lmp->atom->nextra_grow, 0); - ASSERT_EQ(lmp->atom->nextra_restart, 0); - ASSERT_EQ(lmp->atom->nextra_border, 0); - ASSERT_EQ(lmp->atom->nextra_grow_max, 0); - ASSERT_EQ(lmp->atom->nextra_restart_max, 0); - ASSERT_EQ(lmp->atom->nextra_border_max, 0); - ASSERT_EQ(lmp->atom->nextra_store, 0); - ASSERT_EQ(lmp->atom->extra_grow, nullptr); - ASSERT_EQ(lmp->atom->extra_restart, nullptr); - ASSERT_EQ(lmp->atom->extra_border, nullptr); - ASSERT_EQ(lmp->atom->extra, nullptr); - ASSERT_EQ(lmp->atom->sametag, nullptr); - ASSERT_EQ(lmp->atom->map_style, Atom::MAP_NONE); - ASSERT_EQ(lmp->atom->map_user, 0); - ASSERT_EQ(lmp->atom->map_tag_max, -1); + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 2 box"); @@ -1386,193 +1046,23 @@ TEST_F(AtomStyleTest, ellipsoid) if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("atom_style ellipsoid"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("ellipsoid")); - ASSERT_NE(lmp->atom->avec, nullptr); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::ATOMIC); - ASSERT_EQ(lmp->atom->nellipsoids, 0); - ASSERT_EQ(lmp->atom->nlines, 0); - ASSERT_EQ(lmp->atom->ntris, 0); - ASSERT_EQ(lmp->atom->nbodies, 0); - ASSERT_EQ(lmp->atom->nbonds, 0); - ASSERT_EQ(lmp->atom->nangles, 0); - ASSERT_EQ(lmp->atom->ndihedrals, 0); - ASSERT_EQ(lmp->atom->nimpropers, 0); - ASSERT_EQ(lmp->atom->ntypes, 0); - ASSERT_EQ(lmp->atom->nbondtypes, 0); - ASSERT_EQ(lmp->atom->nangletypes, 0); - ASSERT_EQ(lmp->atom->ndihedraltypes, 0); - ASSERT_EQ(lmp->atom->nimpropertypes, 0); - ASSERT_EQ(lmp->atom->bond_per_atom, 0); - ASSERT_EQ(lmp->atom->angle_per_atom, 0); - ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->improper_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - ASSERT_EQ(lmp->atom->sphere_flag, 0); - ASSERT_EQ(lmp->atom->ellipsoid_flag, 1); - ASSERT_EQ(lmp->atom->line_flag, 0); - ASSERT_EQ(lmp->atom->tri_flag, 0); - ASSERT_EQ(lmp->atom->body_flag, 0); - ASSERT_EQ(lmp->atom->peri_flag, 0); - ASSERT_EQ(lmp->atom->electron_flag, 0); - ASSERT_EQ(lmp->atom->wavepacket_flag, 0); - ASSERT_EQ(lmp->atom->sph_flag, 0); - ASSERT_EQ(lmp->atom->molecule_flag, 0); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - ASSERT_EQ(lmp->atom->q_flag, 0); - ASSERT_EQ(lmp->atom->mu_flag, 0); - ASSERT_EQ(lmp->atom->rmass_flag, 1); - ASSERT_EQ(lmp->atom->radius_flag, 0); - ASSERT_EQ(lmp->atom->omega_flag, 0); - ASSERT_EQ(lmp->atom->torque_flag, 1); - ASSERT_EQ(lmp->atom->angmom_flag, 1); - ASSERT_EQ(lmp->atom->vfrac_flag, 0); - ASSERT_EQ(lmp->atom->spin_flag, 0); - ASSERT_EQ(lmp->atom->eradius_flag, 0); - ASSERT_EQ(lmp->atom->ervel_flag, 0); - ASSERT_EQ(lmp->atom->erforce_flag, 0); - ASSERT_EQ(lmp->atom->cs_flag, 0); - ASSERT_EQ(lmp->atom->csforce_flag, 0); - ASSERT_EQ(lmp->atom->vforce_flag, 0); - ASSERT_EQ(lmp->atom->ervelforce_flag, 0); - ASSERT_EQ(lmp->atom->etag_flag, 0); - ASSERT_EQ(lmp->atom->rho_flag, 0); - ASSERT_EQ(lmp->atom->esph_flag, 0); - ASSERT_EQ(lmp->atom->cv_flag, 0); - ASSERT_EQ(lmp->atom->vest_flag, 0); - ASSERT_EQ(lmp->atom->dpd_flag, 0); - ASSERT_EQ(lmp->atom->edpd_flag, 0); - ASSERT_EQ(lmp->atom->tdpd_flag, 0); - ASSERT_EQ(lmp->atom->mesont_flag, 0); - ASSERT_EQ(lmp->atom->sp_flag, 0); - ASSERT_EQ(lmp->atom->x0_flag, 0); - ASSERT_EQ(lmp->atom->smd_flag, 0); - ASSERT_EQ(lmp->atom->damage_flag, 0); - ASSERT_EQ(lmp->atom->contact_radius_flag, 0); - ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); - ASSERT_EQ(lmp->atom->smd_stress_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - ASSERT_EQ(lmp->atom->pdscale, 1.0); + AtomState expected; + expected.atom_style = "ellipsoid"; + expected.molecular = Atom::ATOMIC; + expected.tag_enable = 1; + expected.ellipsoid_flag = 1; + expected.rmass_flag = 1; + expected.angmom_flag = 1; + expected.torque_flag = 1; + expected.has_type = true; + expected.has_mask = true; + expected.has_image = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; - ASSERT_NE(lmp->atom->tag, nullptr); - ASSERT_NE(lmp->atom->type, nullptr); - ASSERT_NE(lmp->atom->mask, nullptr); - ASSERT_NE(lmp->atom->image, nullptr); - ASSERT_NE(lmp->atom->x, nullptr); - ASSERT_NE(lmp->atom->v, nullptr); - ASSERT_NE(lmp->atom->f, nullptr); - ASSERT_EQ(lmp->atom->q, nullptr); - ASSERT_EQ(lmp->atom->mu, nullptr); - ASSERT_EQ(lmp->atom->omega, nullptr); - ASSERT_NE(lmp->atom->angmom, nullptr); - ASSERT_NE(lmp->atom->torque, nullptr); - ASSERT_EQ(lmp->atom->radius, nullptr); - ASSERT_NE(lmp->atom->rmass, nullptr); - ASSERT_NE(lmp->atom->ellipsoid, nullptr); - ASSERT_EQ(lmp->atom->line, nullptr); - ASSERT_EQ(lmp->atom->tri, nullptr); - ASSERT_EQ(lmp->atom->body, nullptr); - ASSERT_EQ(lmp->atom->molecule, nullptr); - ASSERT_EQ(lmp->atom->molindex, nullptr); - ASSERT_EQ(lmp->atom->molatom, nullptr); - ASSERT_EQ(lmp->atom->num_bond, nullptr); - ASSERT_EQ(lmp->atom->bond_type, nullptr); - ASSERT_EQ(lmp->atom->bond_atom, nullptr); - ASSERT_EQ(lmp->atom->num_angle, nullptr); - ASSERT_EQ(lmp->atom->angle_type, nullptr); - ASSERT_EQ(lmp->atom->angle_atom1, nullptr); - ASSERT_EQ(lmp->atom->angle_atom2, nullptr); - ASSERT_EQ(lmp->atom->angle_atom3, nullptr); - ASSERT_EQ(lmp->atom->num_dihedral, nullptr); - ASSERT_EQ(lmp->atom->dihedral_type, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); - ASSERT_EQ(lmp->atom->num_improper, nullptr); - ASSERT_EQ(lmp->atom->improper_type, nullptr); - ASSERT_EQ(lmp->atom->improper_atom1, nullptr); - ASSERT_EQ(lmp->atom->improper_atom2, nullptr); - ASSERT_EQ(lmp->atom->improper_atom3, nullptr); - ASSERT_EQ(lmp->atom->improper_atom4, nullptr); - ASSERT_EQ(lmp->atom->maxspecial, 1); - ASSERT_EQ(lmp->atom->nspecial, nullptr); - ASSERT_EQ(lmp->atom->special, nullptr); - ASSERT_EQ(lmp->atom->vfrac, nullptr); - ASSERT_EQ(lmp->atom->s0, nullptr); - ASSERT_EQ(lmp->atom->x0, nullptr); - ASSERT_EQ(lmp->atom->sp, nullptr); - ASSERT_EQ(lmp->atom->fm, nullptr); - ASSERT_EQ(lmp->atom->fm_long, nullptr); - ASSERT_EQ(lmp->atom->spin, nullptr); - ASSERT_EQ(lmp->atom->eradius, nullptr); - ASSERT_EQ(lmp->atom->ervel, nullptr); - ASSERT_EQ(lmp->atom->erforce, nullptr); - ASSERT_EQ(lmp->atom->ervelforce, nullptr); - ASSERT_EQ(lmp->atom->cs, nullptr); - ASSERT_EQ(lmp->atom->csforce, nullptr); - ASSERT_EQ(lmp->atom->vforce, nullptr); - ASSERT_EQ(lmp->atom->etag, nullptr); - ASSERT_EQ(lmp->atom->uCond, nullptr); - ASSERT_EQ(lmp->atom->uMech, nullptr); - ASSERT_EQ(lmp->atom->uChem, nullptr); - ASSERT_EQ(lmp->atom->uCG, nullptr); - ASSERT_EQ(lmp->atom->uCGnew, nullptr); - ASSERT_EQ(lmp->atom->duChem, nullptr); - ASSERT_EQ(lmp->atom->dpdTheta, nullptr); - ASSERT_EQ(lmp->atom->cc, nullptr); - ASSERT_EQ(lmp->atom->cc_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_temp, nullptr); - ASSERT_EQ(lmp->atom->edpd_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_cv, nullptr); - ASSERT_EQ(lmp->atom->length, nullptr); - ASSERT_EQ(lmp->atom->buckling, nullptr); - ASSERT_EQ(lmp->atom->bond_nt, nullptr); - ASSERT_EQ(lmp->atom->contact_radius, nullptr); - ASSERT_EQ(lmp->atom->smd_data_9, nullptr); - ASSERT_EQ(lmp->atom->smd_stress, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - ASSERT_EQ(lmp->atom->damage, nullptr); - ASSERT_EQ(lmp->atom->rho, nullptr); - ASSERT_EQ(lmp->atom->drho, nullptr); - ASSERT_EQ(lmp->atom->esph, nullptr); - ASSERT_EQ(lmp->atom->desph, nullptr); - ASSERT_EQ(lmp->atom->cv, nullptr); - ASSERT_EQ(lmp->atom->vest, nullptr); - ASSERT_EQ(lmp->atom->nmolecule, 0); - ASSERT_EQ(lmp->atom->molecules, nullptr); - ASSERT_EQ(lmp->atom->nivector, 0); - ASSERT_EQ(lmp->atom->ndvector, 0); - ASSERT_EQ(lmp->atom->iname, nullptr); - ASSERT_EQ(lmp->atom->dname, nullptr); - ASSERT_EQ(lmp->atom->mass, nullptr); - ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - ASSERT_EQ(lmp->atom->nextra_grow, 0); - ASSERT_EQ(lmp->atom->nextra_restart, 0); - ASSERT_EQ(lmp->atom->nextra_border, 0); - ASSERT_EQ(lmp->atom->nextra_grow_max, 0); - ASSERT_EQ(lmp->atom->nextra_restart_max, 0); - ASSERT_EQ(lmp->atom->nextra_border_max, 0); - ASSERT_EQ(lmp->atom->nextra_store, 0); - ASSERT_EQ(lmp->atom->extra_grow, nullptr); - ASSERT_EQ(lmp->atom->extra_restart, nullptr); - ASSERT_EQ(lmp->atom->extra_border, nullptr); - ASSERT_EQ(lmp->atom->extra, nullptr); - ASSERT_EQ(lmp->atom->sametag, nullptr); - ASSERT_EQ(lmp->atom->map_style, Atom::MAP_NONE); - ASSERT_EQ(lmp->atom->map_user, 0); - ASSERT_EQ(lmp->atom->map_tag_max, -1); + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 3 box"); @@ -1894,193 +1384,26 @@ TEST_F(AtomStyleTest, line) lmp->input->one("dimension 2"); lmp->input->one("atom_style line"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("line")); - ASSERT_NE(lmp->atom->avec, nullptr); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::ATOMIC); - ASSERT_EQ(lmp->atom->nellipsoids, 0); - ASSERT_EQ(lmp->atom->nlines, 0); - ASSERT_EQ(lmp->atom->ntris, 0); - ASSERT_EQ(lmp->atom->nbodies, 0); - ASSERT_EQ(lmp->atom->nbonds, 0); - ASSERT_EQ(lmp->atom->nangles, 0); - ASSERT_EQ(lmp->atom->ndihedrals, 0); - ASSERT_EQ(lmp->atom->nimpropers, 0); - ASSERT_EQ(lmp->atom->ntypes, 0); - ASSERT_EQ(lmp->atom->nbondtypes, 0); - ASSERT_EQ(lmp->atom->nangletypes, 0); - ASSERT_EQ(lmp->atom->ndihedraltypes, 0); - ASSERT_EQ(lmp->atom->nimpropertypes, 0); - ASSERT_EQ(lmp->atom->bond_per_atom, 0); - ASSERT_EQ(lmp->atom->angle_per_atom, 0); - ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->improper_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - ASSERT_EQ(lmp->atom->sphere_flag, 1); - ASSERT_EQ(lmp->atom->ellipsoid_flag, 0); - ASSERT_EQ(lmp->atom->line_flag, 1); - ASSERT_EQ(lmp->atom->tri_flag, 0); - ASSERT_EQ(lmp->atom->body_flag, 0); - ASSERT_EQ(lmp->atom->peri_flag, 0); - ASSERT_EQ(lmp->atom->electron_flag, 0); - ASSERT_EQ(lmp->atom->wavepacket_flag, 0); - ASSERT_EQ(lmp->atom->sph_flag, 0); - ASSERT_EQ(lmp->atom->molecule_flag, 1); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - ASSERT_EQ(lmp->atom->q_flag, 0); - ASSERT_EQ(lmp->atom->mu_flag, 0); - ASSERT_EQ(lmp->atom->rmass_flag, 1); - ASSERT_EQ(lmp->atom->radius_flag, 1); - ASSERT_EQ(lmp->atom->omega_flag, 1); - ASSERT_EQ(lmp->atom->torque_flag, 1); - ASSERT_EQ(lmp->atom->angmom_flag, 0); - ASSERT_EQ(lmp->atom->vfrac_flag, 0); - ASSERT_EQ(lmp->atom->spin_flag, 0); - ASSERT_EQ(lmp->atom->eradius_flag, 0); - ASSERT_EQ(lmp->atom->ervel_flag, 0); - ASSERT_EQ(lmp->atom->erforce_flag, 0); - ASSERT_EQ(lmp->atom->cs_flag, 0); - ASSERT_EQ(lmp->atom->csforce_flag, 0); - ASSERT_EQ(lmp->atom->vforce_flag, 0); - ASSERT_EQ(lmp->atom->ervelforce_flag, 0); - ASSERT_EQ(lmp->atom->etag_flag, 0); - ASSERT_EQ(lmp->atom->rho_flag, 0); - ASSERT_EQ(lmp->atom->esph_flag, 0); - ASSERT_EQ(lmp->atom->cv_flag, 0); - ASSERT_EQ(lmp->atom->vest_flag, 0); - ASSERT_EQ(lmp->atom->dpd_flag, 0); - ASSERT_EQ(lmp->atom->edpd_flag, 0); - ASSERT_EQ(lmp->atom->tdpd_flag, 0); - ASSERT_EQ(lmp->atom->mesont_flag, 0); - ASSERT_EQ(lmp->atom->sp_flag, 0); - ASSERT_EQ(lmp->atom->x0_flag, 0); - ASSERT_EQ(lmp->atom->smd_flag, 0); - ASSERT_EQ(lmp->atom->damage_flag, 0); - ASSERT_EQ(lmp->atom->contact_radius_flag, 0); - ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); - ASSERT_EQ(lmp->atom->smd_stress_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - ASSERT_EQ(lmp->atom->pdscale, 1.0); + AtomState expected; + expected.atom_style = "line"; + expected.molecular = Atom::ATOMIC; + expected.tag_enable = 1; + expected.sphere_flag = 1; + expected.molecule_flag = 1; + expected.line_flag = 1; + expected.rmass_flag = 1; + expected.radius_flag = 1; + expected.omega_flag = 1; + expected.torque_flag = 1; + expected.has_type = true; + expected.has_mask = true; + expected.has_image = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; - ASSERT_NE(lmp->atom->tag, nullptr); - ASSERT_NE(lmp->atom->type, nullptr); - ASSERT_NE(lmp->atom->mask, nullptr); - ASSERT_NE(lmp->atom->image, nullptr); - ASSERT_NE(lmp->atom->x, nullptr); - ASSERT_NE(lmp->atom->v, nullptr); - ASSERT_NE(lmp->atom->f, nullptr); - ASSERT_EQ(lmp->atom->q, nullptr); - ASSERT_EQ(lmp->atom->mu, nullptr); - ASSERT_NE(lmp->atom->omega, nullptr); - ASSERT_EQ(lmp->atom->angmom, nullptr); - ASSERT_NE(lmp->atom->torque, nullptr); - ASSERT_NE(lmp->atom->radius, nullptr); - ASSERT_NE(lmp->atom->rmass, nullptr); - ASSERT_EQ(lmp->atom->ellipsoid, nullptr); - ASSERT_NE(lmp->atom->line, nullptr); - ASSERT_EQ(lmp->atom->tri, nullptr); - ASSERT_EQ(lmp->atom->body, nullptr); - ASSERT_NE(lmp->atom->molecule, nullptr); - ASSERT_EQ(lmp->atom->molindex, nullptr); - ASSERT_EQ(lmp->atom->molatom, nullptr); - ASSERT_EQ(lmp->atom->num_bond, nullptr); - ASSERT_EQ(lmp->atom->bond_type, nullptr); - ASSERT_EQ(lmp->atom->bond_atom, nullptr); - ASSERT_EQ(lmp->atom->num_angle, nullptr); - ASSERT_EQ(lmp->atom->angle_type, nullptr); - ASSERT_EQ(lmp->atom->angle_atom1, nullptr); - ASSERT_EQ(lmp->atom->angle_atom2, nullptr); - ASSERT_EQ(lmp->atom->angle_atom3, nullptr); - ASSERT_EQ(lmp->atom->num_dihedral, nullptr); - ASSERT_EQ(lmp->atom->dihedral_type, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); - ASSERT_EQ(lmp->atom->num_improper, nullptr); - ASSERT_EQ(lmp->atom->improper_type, nullptr); - ASSERT_EQ(lmp->atom->improper_atom1, nullptr); - ASSERT_EQ(lmp->atom->improper_atom2, nullptr); - ASSERT_EQ(lmp->atom->improper_atom3, nullptr); - ASSERT_EQ(lmp->atom->improper_atom4, nullptr); - ASSERT_EQ(lmp->atom->maxspecial, 1); - ASSERT_EQ(lmp->atom->nspecial, nullptr); - ASSERT_EQ(lmp->atom->special, nullptr); - ASSERT_EQ(lmp->atom->vfrac, nullptr); - ASSERT_EQ(lmp->atom->s0, nullptr); - ASSERT_EQ(lmp->atom->x0, nullptr); - ASSERT_EQ(lmp->atom->sp, nullptr); - ASSERT_EQ(lmp->atom->fm, nullptr); - ASSERT_EQ(lmp->atom->fm_long, nullptr); - ASSERT_EQ(lmp->atom->spin, nullptr); - ASSERT_EQ(lmp->atom->eradius, nullptr); - ASSERT_EQ(lmp->atom->ervel, nullptr); - ASSERT_EQ(lmp->atom->erforce, nullptr); - ASSERT_EQ(lmp->atom->ervelforce, nullptr); - ASSERT_EQ(lmp->atom->cs, nullptr); - ASSERT_EQ(lmp->atom->csforce, nullptr); - ASSERT_EQ(lmp->atom->vforce, nullptr); - ASSERT_EQ(lmp->atom->etag, nullptr); - ASSERT_EQ(lmp->atom->uCond, nullptr); - ASSERT_EQ(lmp->atom->uMech, nullptr); - ASSERT_EQ(lmp->atom->uChem, nullptr); - ASSERT_EQ(lmp->atom->uCG, nullptr); - ASSERT_EQ(lmp->atom->uCGnew, nullptr); - ASSERT_EQ(lmp->atom->duChem, nullptr); - ASSERT_EQ(lmp->atom->dpdTheta, nullptr); - ASSERT_EQ(lmp->atom->cc, nullptr); - ASSERT_EQ(lmp->atom->cc_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_temp, nullptr); - ASSERT_EQ(lmp->atom->edpd_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_cv, nullptr); - ASSERT_EQ(lmp->atom->length, nullptr); - ASSERT_EQ(lmp->atom->buckling, nullptr); - ASSERT_EQ(lmp->atom->bond_nt, nullptr); - ASSERT_EQ(lmp->atom->contact_radius, nullptr); - ASSERT_EQ(lmp->atom->smd_data_9, nullptr); - ASSERT_EQ(lmp->atom->smd_stress, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - ASSERT_EQ(lmp->atom->damage, nullptr); - ASSERT_EQ(lmp->atom->rho, nullptr); - ASSERT_EQ(lmp->atom->drho, nullptr); - ASSERT_EQ(lmp->atom->esph, nullptr); - ASSERT_EQ(lmp->atom->desph, nullptr); - ASSERT_EQ(lmp->atom->cv, nullptr); - ASSERT_EQ(lmp->atom->vest, nullptr); - ASSERT_EQ(lmp->atom->nmolecule, 0); - ASSERT_EQ(lmp->atom->molecules, nullptr); - ASSERT_EQ(lmp->atom->nivector, 0); - ASSERT_EQ(lmp->atom->ndvector, 0); - ASSERT_EQ(lmp->atom->iname, nullptr); - ASSERT_EQ(lmp->atom->dname, nullptr); - ASSERT_EQ(lmp->atom->mass, nullptr); - ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - ASSERT_EQ(lmp->atom->nextra_grow, 0); - ASSERT_EQ(lmp->atom->nextra_restart, 0); - ASSERT_EQ(lmp->atom->nextra_border, 0); - ASSERT_EQ(lmp->atom->nextra_grow_max, 0); - ASSERT_EQ(lmp->atom->nextra_restart_max, 0); - ASSERT_EQ(lmp->atom->nextra_border_max, 0); - ASSERT_EQ(lmp->atom->nextra_store, 0); - ASSERT_EQ(lmp->atom->extra_grow, nullptr); - ASSERT_EQ(lmp->atom->extra_restart, nullptr); - ASSERT_EQ(lmp->atom->extra_border, nullptr); - ASSERT_EQ(lmp->atom->extra, nullptr); - ASSERT_EQ(lmp->atom->sametag, nullptr); - ASSERT_EQ(lmp->atom->map_style, Atom::MAP_NONE); - ASSERT_EQ(lmp->atom->map_user, 0); - ASSERT_EQ(lmp->atom->map_tag_max, -1); + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 3 box"); @@ -2331,193 +1654,27 @@ TEST_F(AtomStyleTest, tri) if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("atom_style tri"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("tri")); - ASSERT_NE(lmp->atom->avec, nullptr); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::ATOMIC); - ASSERT_EQ(lmp->atom->nellipsoids, 0); - ASSERT_EQ(lmp->atom->nlines, 0); - ASSERT_EQ(lmp->atom->ntris, 0); - ASSERT_EQ(lmp->atom->nbodies, 0); - ASSERT_EQ(lmp->atom->nbonds, 0); - ASSERT_EQ(lmp->atom->nangles, 0); - ASSERT_EQ(lmp->atom->ndihedrals, 0); - ASSERT_EQ(lmp->atom->nimpropers, 0); - ASSERT_EQ(lmp->atom->ntypes, 0); - ASSERT_EQ(lmp->atom->nbondtypes, 0); - ASSERT_EQ(lmp->atom->nangletypes, 0); - ASSERT_EQ(lmp->atom->ndihedraltypes, 0); - ASSERT_EQ(lmp->atom->nimpropertypes, 0); - ASSERT_EQ(lmp->atom->bond_per_atom, 0); - ASSERT_EQ(lmp->atom->angle_per_atom, 0); - ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->improper_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - ASSERT_EQ(lmp->atom->sphere_flag, 1); - ASSERT_EQ(lmp->atom->ellipsoid_flag, 0); - ASSERT_EQ(lmp->atom->line_flag, 0); - ASSERT_EQ(lmp->atom->tri_flag, 1); - ASSERT_EQ(lmp->atom->body_flag, 0); - ASSERT_EQ(lmp->atom->peri_flag, 0); - ASSERT_EQ(lmp->atom->electron_flag, 0); - ASSERT_EQ(lmp->atom->wavepacket_flag, 0); - ASSERT_EQ(lmp->atom->sph_flag, 0); - ASSERT_EQ(lmp->atom->molecule_flag, 1); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - ASSERT_EQ(lmp->atom->q_flag, 0); - ASSERT_EQ(lmp->atom->mu_flag, 0); - ASSERT_EQ(lmp->atom->rmass_flag, 1); - ASSERT_EQ(lmp->atom->radius_flag, 1); - ASSERT_EQ(lmp->atom->omega_flag, 1); - ASSERT_EQ(lmp->atom->torque_flag, 1); - ASSERT_EQ(lmp->atom->angmom_flag, 1); - ASSERT_EQ(lmp->atom->vfrac_flag, 0); - ASSERT_EQ(lmp->atom->spin_flag, 0); - ASSERT_EQ(lmp->atom->eradius_flag, 0); - ASSERT_EQ(lmp->atom->ervel_flag, 0); - ASSERT_EQ(lmp->atom->erforce_flag, 0); - ASSERT_EQ(lmp->atom->cs_flag, 0); - ASSERT_EQ(lmp->atom->csforce_flag, 0); - ASSERT_EQ(lmp->atom->vforce_flag, 0); - ASSERT_EQ(lmp->atom->ervelforce_flag, 0); - ASSERT_EQ(lmp->atom->etag_flag, 0); - ASSERT_EQ(lmp->atom->rho_flag, 0); - ASSERT_EQ(lmp->atom->esph_flag, 0); - ASSERT_EQ(lmp->atom->cv_flag, 0); - ASSERT_EQ(lmp->atom->vest_flag, 0); - ASSERT_EQ(lmp->atom->dpd_flag, 0); - ASSERT_EQ(lmp->atom->edpd_flag, 0); - ASSERT_EQ(lmp->atom->tdpd_flag, 0); - ASSERT_EQ(lmp->atom->mesont_flag, 0); - ASSERT_EQ(lmp->atom->sp_flag, 0); - ASSERT_EQ(lmp->atom->x0_flag, 0); - ASSERT_EQ(lmp->atom->smd_flag, 0); - ASSERT_EQ(lmp->atom->damage_flag, 0); - ASSERT_EQ(lmp->atom->contact_radius_flag, 0); - ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); - ASSERT_EQ(lmp->atom->smd_stress_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - ASSERT_EQ(lmp->atom->pdscale, 1.0); + AtomState expected; + expected.atom_style = "tri"; + expected.molecular = Atom::ATOMIC; + expected.tag_enable = 1; + expected.sphere_flag = 1; + expected.molecule_flag = 1; + expected.tri_flag = 1; + expected.rmass_flag = 1; + expected.radius_flag = 1; + expected.omega_flag = 1; + expected.angmom_flag = 1; + expected.torque_flag = 1; + expected.has_type = true; + expected.has_mask = true; + expected.has_image = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; - ASSERT_NE(lmp->atom->tag, nullptr); - ASSERT_NE(lmp->atom->type, nullptr); - ASSERT_NE(lmp->atom->mask, nullptr); - ASSERT_NE(lmp->atom->image, nullptr); - ASSERT_NE(lmp->atom->x, nullptr); - ASSERT_NE(lmp->atom->v, nullptr); - ASSERT_NE(lmp->atom->f, nullptr); - ASSERT_EQ(lmp->atom->q, nullptr); - ASSERT_EQ(lmp->atom->mu, nullptr); - ASSERT_NE(lmp->atom->omega, nullptr); - ASSERT_NE(lmp->atom->angmom, nullptr); - ASSERT_NE(lmp->atom->torque, nullptr); - ASSERT_NE(lmp->atom->radius, nullptr); - ASSERT_NE(lmp->atom->rmass, nullptr); - ASSERT_EQ(lmp->atom->ellipsoid, nullptr); - ASSERT_EQ(lmp->atom->line, nullptr); - ASSERT_NE(lmp->atom->tri, nullptr); - ASSERT_EQ(lmp->atom->body, nullptr); - ASSERT_NE(lmp->atom->molecule, nullptr); - ASSERT_EQ(lmp->atom->molindex, nullptr); - ASSERT_EQ(lmp->atom->molatom, nullptr); - ASSERT_EQ(lmp->atom->num_bond, nullptr); - ASSERT_EQ(lmp->atom->bond_type, nullptr); - ASSERT_EQ(lmp->atom->bond_atom, nullptr); - ASSERT_EQ(lmp->atom->num_angle, nullptr); - ASSERT_EQ(lmp->atom->angle_type, nullptr); - ASSERT_EQ(lmp->atom->angle_atom1, nullptr); - ASSERT_EQ(lmp->atom->angle_atom2, nullptr); - ASSERT_EQ(lmp->atom->angle_atom3, nullptr); - ASSERT_EQ(lmp->atom->num_dihedral, nullptr); - ASSERT_EQ(lmp->atom->dihedral_type, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); - ASSERT_EQ(lmp->atom->num_improper, nullptr); - ASSERT_EQ(lmp->atom->improper_type, nullptr); - ASSERT_EQ(lmp->atom->improper_atom1, nullptr); - ASSERT_EQ(lmp->atom->improper_atom2, nullptr); - ASSERT_EQ(lmp->atom->improper_atom3, nullptr); - ASSERT_EQ(lmp->atom->improper_atom4, nullptr); - ASSERT_EQ(lmp->atom->maxspecial, 1); - ASSERT_EQ(lmp->atom->nspecial, nullptr); - ASSERT_EQ(lmp->atom->special, nullptr); - ASSERT_EQ(lmp->atom->vfrac, nullptr); - ASSERT_EQ(lmp->atom->s0, nullptr); - ASSERT_EQ(lmp->atom->x0, nullptr); - ASSERT_EQ(lmp->atom->sp, nullptr); - ASSERT_EQ(lmp->atom->fm, nullptr); - ASSERT_EQ(lmp->atom->fm_long, nullptr); - ASSERT_EQ(lmp->atom->spin, nullptr); - ASSERT_EQ(lmp->atom->eradius, nullptr); - ASSERT_EQ(lmp->atom->ervel, nullptr); - ASSERT_EQ(lmp->atom->erforce, nullptr); - ASSERT_EQ(lmp->atom->ervelforce, nullptr); - ASSERT_EQ(lmp->atom->cs, nullptr); - ASSERT_EQ(lmp->atom->csforce, nullptr); - ASSERT_EQ(lmp->atom->vforce, nullptr); - ASSERT_EQ(lmp->atom->etag, nullptr); - ASSERT_EQ(lmp->atom->uCond, nullptr); - ASSERT_EQ(lmp->atom->uMech, nullptr); - ASSERT_EQ(lmp->atom->uChem, nullptr); - ASSERT_EQ(lmp->atom->uCG, nullptr); - ASSERT_EQ(lmp->atom->uCGnew, nullptr); - ASSERT_EQ(lmp->atom->duChem, nullptr); - ASSERT_EQ(lmp->atom->dpdTheta, nullptr); - ASSERT_EQ(lmp->atom->cc, nullptr); - ASSERT_EQ(lmp->atom->cc_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_temp, nullptr); - ASSERT_EQ(lmp->atom->edpd_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_cv, nullptr); - ASSERT_EQ(lmp->atom->length, nullptr); - ASSERT_EQ(lmp->atom->buckling, nullptr); - ASSERT_EQ(lmp->atom->bond_nt, nullptr); - ASSERT_EQ(lmp->atom->contact_radius, nullptr); - ASSERT_EQ(lmp->atom->smd_data_9, nullptr); - ASSERT_EQ(lmp->atom->smd_stress, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - ASSERT_EQ(lmp->atom->damage, nullptr); - ASSERT_EQ(lmp->atom->rho, nullptr); - ASSERT_EQ(lmp->atom->drho, nullptr); - ASSERT_EQ(lmp->atom->esph, nullptr); - ASSERT_EQ(lmp->atom->desph, nullptr); - ASSERT_EQ(lmp->atom->cv, nullptr); - ASSERT_EQ(lmp->atom->vest, nullptr); - ASSERT_EQ(lmp->atom->nmolecule, 0); - ASSERT_EQ(lmp->atom->molecules, nullptr); - ASSERT_EQ(lmp->atom->nivector, 0); - ASSERT_EQ(lmp->atom->ndvector, 0); - ASSERT_EQ(lmp->atom->iname, nullptr); - ASSERT_EQ(lmp->atom->dname, nullptr); - ASSERT_EQ(lmp->atom->mass, nullptr); - ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - ASSERT_EQ(lmp->atom->nextra_grow, 0); - ASSERT_EQ(lmp->atom->nextra_restart, 0); - ASSERT_EQ(lmp->atom->nextra_border, 0); - ASSERT_EQ(lmp->atom->nextra_grow_max, 0); - ASSERT_EQ(lmp->atom->nextra_restart_max, 0); - ASSERT_EQ(lmp->atom->nextra_border_max, 0); - ASSERT_EQ(lmp->atom->nextra_store, 0); - ASSERT_EQ(lmp->atom->extra_grow, nullptr); - ASSERT_EQ(lmp->atom->extra_restart, nullptr); - ASSERT_EQ(lmp->atom->extra_border, nullptr); - ASSERT_EQ(lmp->atom->extra, nullptr); - ASSERT_EQ(lmp->atom->sametag, nullptr); - ASSERT_EQ(lmp->atom->map_style, Atom::MAP_NONE); - ASSERT_EQ(lmp->atom->map_user, 0); - ASSERT_EQ(lmp->atom->map_tag_max, -1); + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 3 box"); @@ -2901,199 +2058,30 @@ TEST_F(AtomStyleTest, body_nparticle) if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("atom_style body nparticle 2 4"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("body")); + + AtomState expected; + expected.atom_style = "body"; + expected.molecular = Atom::ATOMIC; + expected.tag_enable = 1; + expected.body_flag = 1; + expected.rmass_flag = 1; + expected.radius_flag = 1; + expected.angmom_flag = 1; + expected.torque_flag = 1; + expected.has_type = true; + expected.has_mask = true; + expected.has_image = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; + + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); auto avec = (AtomVecBody *)lmp->atom->avec; ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_NE(avec->bptr, nullptr); ASSERT_THAT(std::string(avec->bptr->style), Eq("nparticle")); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::ATOMIC); - ASSERT_EQ(lmp->atom->nellipsoids, 0); - ASSERT_EQ(lmp->atom->nlines, 0); - ASSERT_EQ(lmp->atom->ntris, 0); - ASSERT_EQ(lmp->atom->nbodies, 0); - ASSERT_EQ(lmp->atom->nbonds, 0); - ASSERT_EQ(lmp->atom->nangles, 0); - ASSERT_EQ(lmp->atom->ndihedrals, 0); - ASSERT_EQ(lmp->atom->nimpropers, 0); - ASSERT_EQ(lmp->atom->ntypes, 0); - ASSERT_EQ(lmp->atom->nbondtypes, 0); - ASSERT_EQ(lmp->atom->nangletypes, 0); - ASSERT_EQ(lmp->atom->ndihedraltypes, 0); - ASSERT_EQ(lmp->atom->nimpropertypes, 0); - ASSERT_EQ(lmp->atom->bond_per_atom, 0); - ASSERT_EQ(lmp->atom->angle_per_atom, 0); - ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->improper_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - - ASSERT_EQ(lmp->atom->sphere_flag, 0); - ASSERT_EQ(lmp->atom->ellipsoid_flag, 0); - ASSERT_EQ(lmp->atom->line_flag, 0); - ASSERT_EQ(lmp->atom->tri_flag, 0); - ASSERT_EQ(lmp->atom->body_flag, 1); - ASSERT_EQ(lmp->atom->peri_flag, 0); - ASSERT_EQ(lmp->atom->electron_flag, 0); - ASSERT_EQ(lmp->atom->wavepacket_flag, 0); - ASSERT_EQ(lmp->atom->sph_flag, 0); - ASSERT_EQ(lmp->atom->molecule_flag, 0); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - ASSERT_EQ(lmp->atom->q_flag, 0); - ASSERT_EQ(lmp->atom->mu_flag, 0); - ASSERT_EQ(lmp->atom->rmass_flag, 1); - ASSERT_EQ(lmp->atom->radius_flag, 1); - ASSERT_EQ(lmp->atom->omega_flag, 0); - ASSERT_EQ(lmp->atom->torque_flag, 1); - ASSERT_EQ(lmp->atom->angmom_flag, 1); - ASSERT_EQ(lmp->atom->vfrac_flag, 0); - ASSERT_EQ(lmp->atom->spin_flag, 0); - ASSERT_EQ(lmp->atom->eradius_flag, 0); - ASSERT_EQ(lmp->atom->ervel_flag, 0); - ASSERT_EQ(lmp->atom->erforce_flag, 0); - ASSERT_EQ(lmp->atom->cs_flag, 0); - ASSERT_EQ(lmp->atom->csforce_flag, 0); - ASSERT_EQ(lmp->atom->vforce_flag, 0); - ASSERT_EQ(lmp->atom->ervelforce_flag, 0); - ASSERT_EQ(lmp->atom->etag_flag, 0); - ASSERT_EQ(lmp->atom->rho_flag, 0); - ASSERT_EQ(lmp->atom->esph_flag, 0); - ASSERT_EQ(lmp->atom->cv_flag, 0); - ASSERT_EQ(lmp->atom->vest_flag, 0); - ASSERT_EQ(lmp->atom->dpd_flag, 0); - ASSERT_EQ(lmp->atom->edpd_flag, 0); - ASSERT_EQ(lmp->atom->tdpd_flag, 0); - ASSERT_EQ(lmp->atom->mesont_flag, 0); - ASSERT_EQ(lmp->atom->sp_flag, 0); - ASSERT_EQ(lmp->atom->x0_flag, 0); - ASSERT_EQ(lmp->atom->smd_flag, 0); - ASSERT_EQ(lmp->atom->damage_flag, 0); - ASSERT_EQ(lmp->atom->contact_radius_flag, 0); - ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); - ASSERT_EQ(lmp->atom->smd_stress_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - ASSERT_EQ(lmp->atom->pdscale, 1.0); - - ASSERT_NE(lmp->atom->tag, nullptr); - ASSERT_NE(lmp->atom->type, nullptr); - ASSERT_NE(lmp->atom->mask, nullptr); - ASSERT_NE(lmp->atom->image, nullptr); - ASSERT_NE(lmp->atom->x, nullptr); - ASSERT_NE(lmp->atom->v, nullptr); - ASSERT_NE(lmp->atom->f, nullptr); - ASSERT_EQ(lmp->atom->q, nullptr); - ASSERT_EQ(lmp->atom->mu, nullptr); - ASSERT_EQ(lmp->atom->omega, nullptr); - ASSERT_NE(lmp->atom->angmom, nullptr); - ASSERT_NE(lmp->atom->torque, nullptr); - ASSERT_NE(lmp->atom->radius, nullptr); - ASSERT_NE(lmp->atom->rmass, nullptr); - ASSERT_EQ(lmp->atom->ellipsoid, nullptr); - ASSERT_EQ(lmp->atom->line, nullptr); - ASSERT_EQ(lmp->atom->tri, nullptr); - ASSERT_NE(lmp->atom->body, nullptr); - ASSERT_EQ(lmp->atom->molecule, nullptr); - ASSERT_EQ(lmp->atom->molindex, nullptr); - ASSERT_EQ(lmp->atom->molatom, nullptr); - ASSERT_EQ(lmp->atom->num_bond, nullptr); - ASSERT_EQ(lmp->atom->bond_type, nullptr); - ASSERT_EQ(lmp->atom->bond_atom, nullptr); - ASSERT_EQ(lmp->atom->num_angle, nullptr); - ASSERT_EQ(lmp->atom->angle_type, nullptr); - ASSERT_EQ(lmp->atom->angle_atom1, nullptr); - ASSERT_EQ(lmp->atom->angle_atom2, nullptr); - ASSERT_EQ(lmp->atom->angle_atom3, nullptr); - ASSERT_EQ(lmp->atom->num_dihedral, nullptr); - ASSERT_EQ(lmp->atom->dihedral_type, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); - ASSERT_EQ(lmp->atom->num_improper, nullptr); - ASSERT_EQ(lmp->atom->improper_type, nullptr); - ASSERT_EQ(lmp->atom->improper_atom1, nullptr); - ASSERT_EQ(lmp->atom->improper_atom2, nullptr); - ASSERT_EQ(lmp->atom->improper_atom3, nullptr); - ASSERT_EQ(lmp->atom->improper_atom4, nullptr); - ASSERT_EQ(lmp->atom->maxspecial, 1); - ASSERT_EQ(lmp->atom->nspecial, nullptr); - ASSERT_EQ(lmp->atom->special, nullptr); - ASSERT_EQ(lmp->atom->vfrac, nullptr); - ASSERT_EQ(lmp->atom->s0, nullptr); - ASSERT_EQ(lmp->atom->x0, nullptr); - ASSERT_EQ(lmp->atom->sp, nullptr); - ASSERT_EQ(lmp->atom->fm, nullptr); - ASSERT_EQ(lmp->atom->fm_long, nullptr); - ASSERT_EQ(lmp->atom->spin, nullptr); - ASSERT_EQ(lmp->atom->eradius, nullptr); - ASSERT_EQ(lmp->atom->ervel, nullptr); - ASSERT_EQ(lmp->atom->erforce, nullptr); - ASSERT_EQ(lmp->atom->ervelforce, nullptr); - ASSERT_EQ(lmp->atom->cs, nullptr); - ASSERT_EQ(lmp->atom->csforce, nullptr); - ASSERT_EQ(lmp->atom->vforce, nullptr); - ASSERT_EQ(lmp->atom->etag, nullptr); - ASSERT_EQ(lmp->atom->uCond, nullptr); - ASSERT_EQ(lmp->atom->uMech, nullptr); - ASSERT_EQ(lmp->atom->uChem, nullptr); - ASSERT_EQ(lmp->atom->uCG, nullptr); - ASSERT_EQ(lmp->atom->uCGnew, nullptr); - ASSERT_EQ(lmp->atom->duChem, nullptr); - ASSERT_EQ(lmp->atom->dpdTheta, nullptr); - ASSERT_EQ(lmp->atom->cc, nullptr); - ASSERT_EQ(lmp->atom->cc_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_temp, nullptr); - ASSERT_EQ(lmp->atom->edpd_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_cv, nullptr); - ASSERT_EQ(lmp->atom->length, nullptr); - ASSERT_EQ(lmp->atom->buckling, nullptr); - ASSERT_EQ(lmp->atom->bond_nt, nullptr); - ASSERT_EQ(lmp->atom->contact_radius, nullptr); - ASSERT_EQ(lmp->atom->smd_data_9, nullptr); - ASSERT_EQ(lmp->atom->smd_stress, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - ASSERT_EQ(lmp->atom->damage, nullptr); - ASSERT_EQ(lmp->atom->rho, nullptr); - ASSERT_EQ(lmp->atom->drho, nullptr); - ASSERT_EQ(lmp->atom->esph, nullptr); - ASSERT_EQ(lmp->atom->desph, nullptr); - ASSERT_EQ(lmp->atom->cv, nullptr); - ASSERT_EQ(lmp->atom->vest, nullptr); - ASSERT_EQ(lmp->atom->nmolecule, 0); - ASSERT_EQ(lmp->atom->molecules, nullptr); - ASSERT_EQ(lmp->atom->nivector, 0); - ASSERT_EQ(lmp->atom->ndvector, 0); - ASSERT_EQ(lmp->atom->iname, nullptr); - ASSERT_EQ(lmp->atom->dname, nullptr); - ASSERT_EQ(lmp->atom->mass, nullptr); - ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - ASSERT_EQ(lmp->atom->nextra_grow, 0); - ASSERT_EQ(lmp->atom->nextra_restart, 0); - ASSERT_EQ(lmp->atom->nextra_border, 0); - ASSERT_EQ(lmp->atom->nextra_grow_max, 0); - ASSERT_EQ(lmp->atom->nextra_restart_max, 0); - ASSERT_EQ(lmp->atom->nextra_border_max, 0); - ASSERT_EQ(lmp->atom->nextra_store, 0); - ASSERT_EQ(lmp->atom->extra_grow, nullptr); - ASSERT_EQ(lmp->atom->extra_restart, nullptr); - ASSERT_EQ(lmp->atom->extra_border, nullptr); - ASSERT_EQ(lmp->atom->extra, nullptr); - ASSERT_EQ(lmp->atom->sametag, nullptr); - ASSERT_EQ(lmp->atom->map_style, Atom::MAP_NONE); - ASSERT_EQ(lmp->atom->map_user, 0); - ASSERT_EQ(lmp->atom->map_tag_max, -1); - const char data_file[] = "\n4 atoms\n" "4 bodies\n" "3 atom types\n\n" @@ -3659,6 +2647,8 @@ TEST_F(AtomStyleTest, template) expected.nmolecule = 2; expected.map_style = 3; + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); + if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 4 box bond/types 2 angle/types 2 "); lmp->input->one("create_atoms 0 single -2.0 2.0 0.1 mol twomols 65234"); @@ -4463,193 +3453,24 @@ TEST_F(AtomStyleTest, bond) lmp->input->one("atom_style bond"); lmp->input->one("newton on"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("bond")); - ASSERT_NE(lmp->atom->avec, nullptr); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::MOLECULAR); - ASSERT_EQ(lmp->atom->nellipsoids, 0); - ASSERT_EQ(lmp->atom->nlines, 0); - ASSERT_EQ(lmp->atom->ntris, 0); - ASSERT_EQ(lmp->atom->nbodies, 0); - ASSERT_EQ(lmp->atom->nbonds, 0); - ASSERT_EQ(lmp->atom->nangles, 0); - ASSERT_EQ(lmp->atom->ndihedrals, 0); - ASSERT_EQ(lmp->atom->nimpropers, 0); - ASSERT_EQ(lmp->atom->ntypes, 0); - ASSERT_EQ(lmp->atom->nbondtypes, 0); - ASSERT_EQ(lmp->atom->nangletypes, 0); - ASSERT_EQ(lmp->atom->ndihedraltypes, 0); - ASSERT_EQ(lmp->atom->nimpropertypes, 0); - ASSERT_EQ(lmp->atom->bond_per_atom, 0); - ASSERT_EQ(lmp->atom->angle_per_atom, 0); - ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->improper_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - ASSERT_EQ(lmp->atom->sphere_flag, 0); - ASSERT_EQ(lmp->atom->ellipsoid_flag, 0); - ASSERT_EQ(lmp->atom->line_flag, 0); - ASSERT_EQ(lmp->atom->tri_flag, 0); - ASSERT_EQ(lmp->atom->body_flag, 0); - ASSERT_EQ(lmp->atom->peri_flag, 0); - ASSERT_EQ(lmp->atom->electron_flag, 0); - ASSERT_EQ(lmp->atom->wavepacket_flag, 0); - ASSERT_EQ(lmp->atom->sph_flag, 0); - ASSERT_EQ(lmp->atom->molecule_flag, 1); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - ASSERT_EQ(lmp->atom->q_flag, 0); - ASSERT_EQ(lmp->atom->mu_flag, 0); - ASSERT_EQ(lmp->atom->rmass_flag, 0); - ASSERT_EQ(lmp->atom->radius_flag, 0); - ASSERT_EQ(lmp->atom->omega_flag, 0); - ASSERT_EQ(lmp->atom->torque_flag, 0); - ASSERT_EQ(lmp->atom->angmom_flag, 0); - ASSERT_EQ(lmp->atom->vfrac_flag, 0); - ASSERT_EQ(lmp->atom->spin_flag, 0); - ASSERT_EQ(lmp->atom->eradius_flag, 0); - ASSERT_EQ(lmp->atom->ervel_flag, 0); - ASSERT_EQ(lmp->atom->erforce_flag, 0); - ASSERT_EQ(lmp->atom->cs_flag, 0); - ASSERT_EQ(lmp->atom->csforce_flag, 0); - ASSERT_EQ(lmp->atom->vforce_flag, 0); - ASSERT_EQ(lmp->atom->ervelforce_flag, 0); - ASSERT_EQ(lmp->atom->etag_flag, 0); - ASSERT_EQ(lmp->atom->rho_flag, 0); - ASSERT_EQ(lmp->atom->esph_flag, 0); - ASSERT_EQ(lmp->atom->cv_flag, 0); - ASSERT_EQ(lmp->atom->vest_flag, 0); - ASSERT_EQ(lmp->atom->dpd_flag, 0); - ASSERT_EQ(lmp->atom->edpd_flag, 0); - ASSERT_EQ(lmp->atom->tdpd_flag, 0); - ASSERT_EQ(lmp->atom->mesont_flag, 0); - ASSERT_EQ(lmp->atom->sp_flag, 0); - ASSERT_EQ(lmp->atom->x0_flag, 0); - ASSERT_EQ(lmp->atom->smd_flag, 0); - ASSERT_EQ(lmp->atom->damage_flag, 0); - ASSERT_EQ(lmp->atom->contact_radius_flag, 0); - ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); - ASSERT_EQ(lmp->atom->smd_stress_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - ASSERT_EQ(lmp->atom->pdscale, 1.0); + AtomState expected; + expected.atom_style = "bond"; + expected.molecular = Atom::MOLECULAR; + expected.tag_enable = 1; + expected.molecule_flag = 1; + expected.has_type = true; + expected.has_mask = true; + expected.has_image = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; + expected.has_bonds = true; + expected.has_nspecial = true; + expected.has_special = true; + expected.map_style = 3; - ASSERT_NE(lmp->atom->tag, nullptr); - ASSERT_NE(lmp->atom->type, nullptr); - ASSERT_NE(lmp->atom->mask, nullptr); - ASSERT_NE(lmp->atom->image, nullptr); - ASSERT_NE(lmp->atom->x, nullptr); - ASSERT_NE(lmp->atom->v, nullptr); - ASSERT_NE(lmp->atom->f, nullptr); - ASSERT_EQ(lmp->atom->q, nullptr); - ASSERT_EQ(lmp->atom->mu, nullptr); - ASSERT_EQ(lmp->atom->omega, nullptr); - ASSERT_EQ(lmp->atom->angmom, nullptr); - ASSERT_EQ(lmp->atom->torque, nullptr); - ASSERT_EQ(lmp->atom->radius, nullptr); - ASSERT_EQ(lmp->atom->rmass, nullptr); - ASSERT_EQ(lmp->atom->ellipsoid, nullptr); - ASSERT_EQ(lmp->atom->line, nullptr); - ASSERT_EQ(lmp->atom->tri, nullptr); - ASSERT_EQ(lmp->atom->body, nullptr); - ASSERT_NE(lmp->atom->molecule, nullptr); - ASSERT_EQ(lmp->atom->molindex, nullptr); - ASSERT_EQ(lmp->atom->molatom, nullptr); - ASSERT_NE(lmp->atom->num_bond, nullptr); - ASSERT_NE(lmp->atom->bond_type, nullptr); - ASSERT_NE(lmp->atom->bond_atom, nullptr); - ASSERT_EQ(lmp->atom->num_angle, nullptr); - ASSERT_EQ(lmp->atom->angle_type, nullptr); - ASSERT_EQ(lmp->atom->angle_atom1, nullptr); - ASSERT_EQ(lmp->atom->angle_atom2, nullptr); - ASSERT_EQ(lmp->atom->angle_atom3, nullptr); - ASSERT_EQ(lmp->atom->num_dihedral, nullptr); - ASSERT_EQ(lmp->atom->dihedral_type, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); - ASSERT_EQ(lmp->atom->num_improper, nullptr); - ASSERT_EQ(lmp->atom->improper_type, nullptr); - ASSERT_EQ(lmp->atom->improper_atom1, nullptr); - ASSERT_EQ(lmp->atom->improper_atom2, nullptr); - ASSERT_EQ(lmp->atom->improper_atom3, nullptr); - ASSERT_EQ(lmp->atom->improper_atom4, nullptr); - ASSERT_EQ(lmp->atom->maxspecial, 1); - ASSERT_NE(lmp->atom->nspecial, nullptr); - ASSERT_NE(lmp->atom->special, nullptr); - ASSERT_EQ(lmp->atom->vfrac, nullptr); - ASSERT_EQ(lmp->atom->s0, nullptr); - ASSERT_EQ(lmp->atom->x0, nullptr); - ASSERT_EQ(lmp->atom->sp, nullptr); - ASSERT_EQ(lmp->atom->fm, nullptr); - ASSERT_EQ(lmp->atom->fm_long, nullptr); - ASSERT_EQ(lmp->atom->spin, nullptr); - ASSERT_EQ(lmp->atom->eradius, nullptr); - ASSERT_EQ(lmp->atom->ervel, nullptr); - ASSERT_EQ(lmp->atom->erforce, nullptr); - ASSERT_EQ(lmp->atom->ervelforce, nullptr); - ASSERT_EQ(lmp->atom->cs, nullptr); - ASSERT_EQ(lmp->atom->csforce, nullptr); - ASSERT_EQ(lmp->atom->vforce, nullptr); - ASSERT_EQ(lmp->atom->etag, nullptr); - ASSERT_EQ(lmp->atom->uCond, nullptr); - ASSERT_EQ(lmp->atom->uMech, nullptr); - ASSERT_EQ(lmp->atom->uChem, nullptr); - ASSERT_EQ(lmp->atom->uCG, nullptr); - ASSERT_EQ(lmp->atom->uCGnew, nullptr); - ASSERT_EQ(lmp->atom->duChem, nullptr); - ASSERT_EQ(lmp->atom->dpdTheta, nullptr); - ASSERT_EQ(lmp->atom->cc, nullptr); - ASSERT_EQ(lmp->atom->cc_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_temp, nullptr); - ASSERT_EQ(lmp->atom->edpd_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_cv, nullptr); - ASSERT_EQ(lmp->atom->length, nullptr); - ASSERT_EQ(lmp->atom->buckling, nullptr); - ASSERT_EQ(lmp->atom->bond_nt, nullptr); - ASSERT_EQ(lmp->atom->contact_radius, nullptr); - ASSERT_EQ(lmp->atom->smd_data_9, nullptr); - ASSERT_EQ(lmp->atom->smd_stress, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - ASSERT_EQ(lmp->atom->damage, nullptr); - ASSERT_EQ(lmp->atom->rho, nullptr); - ASSERT_EQ(lmp->atom->drho, nullptr); - ASSERT_EQ(lmp->atom->esph, nullptr); - ASSERT_EQ(lmp->atom->desph, nullptr); - ASSERT_EQ(lmp->atom->cv, nullptr); - ASSERT_EQ(lmp->atom->vest, nullptr); - ASSERT_EQ(lmp->atom->nmolecule, 0); - ASSERT_EQ(lmp->atom->molecules, nullptr); - ASSERT_EQ(lmp->atom->nivector, 0); - ASSERT_EQ(lmp->atom->ndvector, 0); - ASSERT_EQ(lmp->atom->iname, nullptr); - ASSERT_EQ(lmp->atom->dname, nullptr); - ASSERT_EQ(lmp->atom->mass, nullptr); - ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - ASSERT_EQ(lmp->atom->nextra_grow, 0); - ASSERT_EQ(lmp->atom->nextra_restart, 0); - ASSERT_EQ(lmp->atom->nextra_border, 0); - ASSERT_EQ(lmp->atom->nextra_grow_max, 0); - ASSERT_EQ(lmp->atom->nextra_restart_max, 0); - ASSERT_EQ(lmp->atom->nextra_border_max, 0); - ASSERT_EQ(lmp->atom->nextra_store, 0); - ASSERT_EQ(lmp->atom->extra_grow, nullptr); - ASSERT_EQ(lmp->atom->extra_restart, nullptr); - ASSERT_EQ(lmp->atom->extra_border, nullptr); - ASSERT_EQ(lmp->atom->extra, nullptr); - ASSERT_EQ(lmp->atom->sametag, nullptr); - ASSERT_EQ(lmp->atom->map_style, 3); - ASSERT_EQ(lmp->atom->map_user, 0); - ASSERT_EQ(lmp->atom->map_tag_max, -1); + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 3 box bond/types 2 " @@ -4980,193 +3801,25 @@ TEST_F(AtomStyleTest, angle) lmp->input->one("atom_style angle"); lmp->input->one("newton on"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("angle")); - ASSERT_NE(lmp->atom->avec, nullptr); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::MOLECULAR); - ASSERT_EQ(lmp->atom->nellipsoids, 0); - ASSERT_EQ(lmp->atom->nlines, 0); - ASSERT_EQ(lmp->atom->ntris, 0); - ASSERT_EQ(lmp->atom->nbodies, 0); - ASSERT_EQ(lmp->atom->nbonds, 0); - ASSERT_EQ(lmp->atom->nangles, 0); - ASSERT_EQ(lmp->atom->ndihedrals, 0); - ASSERT_EQ(lmp->atom->nimpropers, 0); - ASSERT_EQ(lmp->atom->ntypes, 0); - ASSERT_EQ(lmp->atom->nbondtypes, 0); - ASSERT_EQ(lmp->atom->nangletypes, 0); - ASSERT_EQ(lmp->atom->ndihedraltypes, 0); - ASSERT_EQ(lmp->atom->nimpropertypes, 0); - ASSERT_EQ(lmp->atom->bond_per_atom, 0); - ASSERT_EQ(lmp->atom->angle_per_atom, 0); - ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->improper_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - ASSERT_EQ(lmp->atom->sphere_flag, 0); - ASSERT_EQ(lmp->atom->ellipsoid_flag, 0); - ASSERT_EQ(lmp->atom->line_flag, 0); - ASSERT_EQ(lmp->atom->tri_flag, 0); - ASSERT_EQ(lmp->atom->body_flag, 0); - ASSERT_EQ(lmp->atom->peri_flag, 0); - ASSERT_EQ(lmp->atom->electron_flag, 0); - ASSERT_EQ(lmp->atom->wavepacket_flag, 0); - ASSERT_EQ(lmp->atom->sph_flag, 0); - ASSERT_EQ(lmp->atom->molecule_flag, 1); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - ASSERT_EQ(lmp->atom->q_flag, 0); - ASSERT_EQ(lmp->atom->mu_flag, 0); - ASSERT_EQ(lmp->atom->rmass_flag, 0); - ASSERT_EQ(lmp->atom->radius_flag, 0); - ASSERT_EQ(lmp->atom->omega_flag, 0); - ASSERT_EQ(lmp->atom->torque_flag, 0); - ASSERT_EQ(lmp->atom->angmom_flag, 0); - ASSERT_EQ(lmp->atom->vfrac_flag, 0); - ASSERT_EQ(lmp->atom->spin_flag, 0); - ASSERT_EQ(lmp->atom->eradius_flag, 0); - ASSERT_EQ(lmp->atom->ervel_flag, 0); - ASSERT_EQ(lmp->atom->erforce_flag, 0); - ASSERT_EQ(lmp->atom->cs_flag, 0); - ASSERT_EQ(lmp->atom->csforce_flag, 0); - ASSERT_EQ(lmp->atom->vforce_flag, 0); - ASSERT_EQ(lmp->atom->ervelforce_flag, 0); - ASSERT_EQ(lmp->atom->etag_flag, 0); - ASSERT_EQ(lmp->atom->rho_flag, 0); - ASSERT_EQ(lmp->atom->esph_flag, 0); - ASSERT_EQ(lmp->atom->cv_flag, 0); - ASSERT_EQ(lmp->atom->vest_flag, 0); - ASSERT_EQ(lmp->atom->dpd_flag, 0); - ASSERT_EQ(lmp->atom->edpd_flag, 0); - ASSERT_EQ(lmp->atom->tdpd_flag, 0); - ASSERT_EQ(lmp->atom->mesont_flag, 0); - ASSERT_EQ(lmp->atom->sp_flag, 0); - ASSERT_EQ(lmp->atom->x0_flag, 0); - ASSERT_EQ(lmp->atom->smd_flag, 0); - ASSERT_EQ(lmp->atom->damage_flag, 0); - ASSERT_EQ(lmp->atom->contact_radius_flag, 0); - ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); - ASSERT_EQ(lmp->atom->smd_stress_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - ASSERT_EQ(lmp->atom->pdscale, 1.0); + AtomState expected; + expected.atom_style = "angle"; + expected.molecular = Atom::MOLECULAR; + expected.tag_enable = 1; + expected.molecule_flag = 1; + expected.has_type = true; + expected.has_mask = true; + expected.has_image = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; + expected.has_bonds = true; + expected.has_angles = true; + expected.has_nspecial = true; + expected.has_special = true; + expected.map_style = 3; - ASSERT_NE(lmp->atom->tag, nullptr); - ASSERT_NE(lmp->atom->type, nullptr); - ASSERT_NE(lmp->atom->mask, nullptr); - ASSERT_NE(lmp->atom->image, nullptr); - ASSERT_NE(lmp->atom->x, nullptr); - ASSERT_NE(lmp->atom->v, nullptr); - ASSERT_NE(lmp->atom->f, nullptr); - ASSERT_EQ(lmp->atom->q, nullptr); - ASSERT_EQ(lmp->atom->mu, nullptr); - ASSERT_EQ(lmp->atom->omega, nullptr); - ASSERT_EQ(lmp->atom->angmom, nullptr); - ASSERT_EQ(lmp->atom->torque, nullptr); - ASSERT_EQ(lmp->atom->radius, nullptr); - ASSERT_EQ(lmp->atom->rmass, nullptr); - ASSERT_EQ(lmp->atom->ellipsoid, nullptr); - ASSERT_EQ(lmp->atom->line, nullptr); - ASSERT_EQ(lmp->atom->tri, nullptr); - ASSERT_EQ(lmp->atom->body, nullptr); - ASSERT_NE(lmp->atom->molecule, nullptr); - ASSERT_EQ(lmp->atom->molindex, nullptr); - ASSERT_EQ(lmp->atom->molatom, nullptr); - ASSERT_NE(lmp->atom->num_bond, nullptr); - ASSERT_NE(lmp->atom->bond_type, nullptr); - ASSERT_NE(lmp->atom->bond_atom, nullptr); - ASSERT_NE(lmp->atom->num_angle, nullptr); - ASSERT_NE(lmp->atom->angle_type, nullptr); - ASSERT_NE(lmp->atom->angle_atom1, nullptr); - ASSERT_NE(lmp->atom->angle_atom2, nullptr); - ASSERT_NE(lmp->atom->angle_atom3, nullptr); - ASSERT_EQ(lmp->atom->num_dihedral, nullptr); - ASSERT_EQ(lmp->atom->dihedral_type, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom1, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom2, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom3, nullptr); - ASSERT_EQ(lmp->atom->dihedral_atom4, nullptr); - ASSERT_EQ(lmp->atom->num_improper, nullptr); - ASSERT_EQ(lmp->atom->improper_type, nullptr); - ASSERT_EQ(lmp->atom->improper_atom1, nullptr); - ASSERT_EQ(lmp->atom->improper_atom2, nullptr); - ASSERT_EQ(lmp->atom->improper_atom3, nullptr); - ASSERT_EQ(lmp->atom->improper_atom4, nullptr); - ASSERT_EQ(lmp->atom->maxspecial, 1); - ASSERT_NE(lmp->atom->nspecial, nullptr); - ASSERT_NE(lmp->atom->special, nullptr); - ASSERT_EQ(lmp->atom->vfrac, nullptr); - ASSERT_EQ(lmp->atom->s0, nullptr); - ASSERT_EQ(lmp->atom->x0, nullptr); - ASSERT_EQ(lmp->atom->sp, nullptr); - ASSERT_EQ(lmp->atom->fm, nullptr); - ASSERT_EQ(lmp->atom->fm_long, nullptr); - ASSERT_EQ(lmp->atom->spin, nullptr); - ASSERT_EQ(lmp->atom->eradius, nullptr); - ASSERT_EQ(lmp->atom->ervel, nullptr); - ASSERT_EQ(lmp->atom->erforce, nullptr); - ASSERT_EQ(lmp->atom->ervelforce, nullptr); - ASSERT_EQ(lmp->atom->cs, nullptr); - ASSERT_EQ(lmp->atom->csforce, nullptr); - ASSERT_EQ(lmp->atom->vforce, nullptr); - ASSERT_EQ(lmp->atom->etag, nullptr); - ASSERT_EQ(lmp->atom->uCond, nullptr); - ASSERT_EQ(lmp->atom->uMech, nullptr); - ASSERT_EQ(lmp->atom->uChem, nullptr); - ASSERT_EQ(lmp->atom->uCG, nullptr); - ASSERT_EQ(lmp->atom->uCGnew, nullptr); - ASSERT_EQ(lmp->atom->duChem, nullptr); - ASSERT_EQ(lmp->atom->dpdTheta, nullptr); - ASSERT_EQ(lmp->atom->cc, nullptr); - ASSERT_EQ(lmp->atom->cc_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_temp, nullptr); - ASSERT_EQ(lmp->atom->edpd_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_cv, nullptr); - ASSERT_EQ(lmp->atom->length, nullptr); - ASSERT_EQ(lmp->atom->buckling, nullptr); - ASSERT_EQ(lmp->atom->bond_nt, nullptr); - ASSERT_EQ(lmp->atom->contact_radius, nullptr); - ASSERT_EQ(lmp->atom->smd_data_9, nullptr); - ASSERT_EQ(lmp->atom->smd_stress, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - ASSERT_EQ(lmp->atom->damage, nullptr); - ASSERT_EQ(lmp->atom->rho, nullptr); - ASSERT_EQ(lmp->atom->drho, nullptr); - ASSERT_EQ(lmp->atom->esph, nullptr); - ASSERT_EQ(lmp->atom->desph, nullptr); - ASSERT_EQ(lmp->atom->cv, nullptr); - ASSERT_EQ(lmp->atom->vest, nullptr); - ASSERT_EQ(lmp->atom->nmolecule, 0); - ASSERT_EQ(lmp->atom->molecules, nullptr); - ASSERT_EQ(lmp->atom->nivector, 0); - ASSERT_EQ(lmp->atom->ndvector, 0); - ASSERT_EQ(lmp->atom->iname, nullptr); - ASSERT_EQ(lmp->atom->dname, nullptr); - ASSERT_EQ(lmp->atom->mass, nullptr); - ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - ASSERT_EQ(lmp->atom->nextra_grow, 0); - ASSERT_EQ(lmp->atom->nextra_restart, 0); - ASSERT_EQ(lmp->atom->nextra_border, 0); - ASSERT_EQ(lmp->atom->nextra_grow_max, 0); - ASSERT_EQ(lmp->atom->nextra_restart_max, 0); - ASSERT_EQ(lmp->atom->nextra_border_max, 0); - ASSERT_EQ(lmp->atom->nextra_store, 0); - ASSERT_EQ(lmp->atom->extra_grow, nullptr); - ASSERT_EQ(lmp->atom->extra_restart, nullptr); - ASSERT_EQ(lmp->atom->extra_border, nullptr); - ASSERT_EQ(lmp->atom->extra, nullptr); - ASSERT_EQ(lmp->atom->sametag, nullptr); - ASSERT_EQ(lmp->atom->map_style, 3); - ASSERT_EQ(lmp->atom->map_user, 0); - ASSERT_EQ(lmp->atom->map_tag_max, -1); + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 3 box bond/types 2 angle/types 2 " @@ -5508,199 +4161,40 @@ TEST_F(AtomStyleTest, full_ellipsoid) if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("atom_style hybrid full ellipsoid"); if (!verbose) ::testing::internal::GetCapturedStdout(); + + AtomState expected; + expected.atom_style = "hybrid"; + expected.molecular = Atom::MOLECULAR; + expected.tag_enable = 1; + expected.molecule_flag = 1; + expected.ellipsoid_flag = 1; + expected.q_flag = 1; + expected.rmass_flag = 1; + expected.torque_flag = 1; + expected.angmom_flag = 1; + expected.has_type = true; + expected.has_mask = true; + expected.has_image = true; + expected.has_x = true; + expected.has_v = true; + expected.has_f = true; + expected.has_bonds = true; + expected.has_angles = true; + expected.has_dihedral = true; + expected.has_improper = true; + expected.has_nspecial = true; + expected.has_special = true; + expected.map_style = 3; + + ASSERT_ATOM_STATE_EQ(lmp->atom, expected); + auto hybrid = (AtomVecHybrid *)lmp->atom->avec; ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_EQ(hybrid->nstyles, 2); ASSERT_THAT(std::string(hybrid->keywords[0]), Eq("full")); ASSERT_THAT(std::string(hybrid->keywords[1]), Eq("ellipsoid")); - ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_NE(hybrid->styles[0], nullptr); ASSERT_NE(hybrid->styles[1], nullptr); - ASSERT_EQ(lmp->atom->natoms, 0); - ASSERT_EQ(lmp->atom->nlocal, 0); - ASSERT_EQ(lmp->atom->nghost, 0); - ASSERT_EQ(lmp->atom->nmax, 1); - ASSERT_EQ(lmp->atom->tag_enable, 1); - ASSERT_EQ(lmp->atom->molecular, Atom::MOLECULAR); - ASSERT_EQ(lmp->atom->nellipsoids, 0); - ASSERT_EQ(lmp->atom->nlines, 0); - ASSERT_EQ(lmp->atom->ntris, 0); - ASSERT_EQ(lmp->atom->nbodies, 0); - ASSERT_EQ(lmp->atom->nbonds, 0); - ASSERT_EQ(lmp->atom->nangles, 0); - ASSERT_EQ(lmp->atom->ndihedrals, 0); - ASSERT_EQ(lmp->atom->nimpropers, 0); - ASSERT_EQ(lmp->atom->ntypes, 0); - ASSERT_EQ(lmp->atom->nbondtypes, 0); - ASSERT_EQ(lmp->atom->nangletypes, 0); - ASSERT_EQ(lmp->atom->ndihedraltypes, 0); - ASSERT_EQ(lmp->atom->nimpropertypes, 0); - ASSERT_EQ(lmp->atom->bond_per_atom, 0); - ASSERT_EQ(lmp->atom->angle_per_atom, 0); - ASSERT_EQ(lmp->atom->dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->improper_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_bond_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_angle_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_dihedral_per_atom, 0); - ASSERT_EQ(lmp->atom->extra_improper_per_atom, 0); - - ASSERT_EQ(lmp->atom->sphere_flag, 0); - ASSERT_EQ(lmp->atom->ellipsoid_flag, 1); - ASSERT_EQ(lmp->atom->line_flag, 0); - ASSERT_EQ(lmp->atom->tri_flag, 0); - ASSERT_EQ(lmp->atom->body_flag, 0); - ASSERT_EQ(lmp->atom->peri_flag, 0); - ASSERT_EQ(lmp->atom->electron_flag, 0); - ASSERT_EQ(lmp->atom->wavepacket_flag, 0); - ASSERT_EQ(lmp->atom->sph_flag, 0); - ASSERT_EQ(lmp->atom->molecule_flag, 1); - ASSERT_EQ(lmp->atom->molindex_flag, 0); - ASSERT_EQ(lmp->atom->molatom_flag, 0); - ASSERT_EQ(lmp->atom->q_flag, 1); - ASSERT_EQ(lmp->atom->mu_flag, 0); - ASSERT_EQ(lmp->atom->rmass_flag, 1); - ASSERT_EQ(lmp->atom->radius_flag, 0); - ASSERT_EQ(lmp->atom->omega_flag, 0); - ASSERT_EQ(lmp->atom->torque_flag, 1); - ASSERT_EQ(lmp->atom->angmom_flag, 1); - ASSERT_EQ(lmp->atom->vfrac_flag, 0); - ASSERT_EQ(lmp->atom->spin_flag, 0); - ASSERT_EQ(lmp->atom->eradius_flag, 0); - ASSERT_EQ(lmp->atom->ervel_flag, 0); - ASSERT_EQ(lmp->atom->erforce_flag, 0); - ASSERT_EQ(lmp->atom->cs_flag, 0); - ASSERT_EQ(lmp->atom->csforce_flag, 0); - ASSERT_EQ(lmp->atom->vforce_flag, 0); - ASSERT_EQ(lmp->atom->ervelforce_flag, 0); - ASSERT_EQ(lmp->atom->etag_flag, 0); - ASSERT_EQ(lmp->atom->rho_flag, 0); - ASSERT_EQ(lmp->atom->esph_flag, 0); - ASSERT_EQ(lmp->atom->cv_flag, 0); - ASSERT_EQ(lmp->atom->vest_flag, 0); - ASSERT_EQ(lmp->atom->dpd_flag, 0); - ASSERT_EQ(lmp->atom->edpd_flag, 0); - ASSERT_EQ(lmp->atom->tdpd_flag, 0); - ASSERT_EQ(lmp->atom->mesont_flag, 0); - ASSERT_EQ(lmp->atom->sp_flag, 0); - ASSERT_EQ(lmp->atom->x0_flag, 0); - ASSERT_EQ(lmp->atom->smd_flag, 0); - ASSERT_EQ(lmp->atom->damage_flag, 0); - ASSERT_EQ(lmp->atom->contact_radius_flag, 0); - ASSERT_EQ(lmp->atom->smd_data_9_flag, 0); - ASSERT_EQ(lmp->atom->smd_stress_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_flag, 0); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate_flag, 0); - ASSERT_EQ(lmp->atom->pdscale, 1.0); - - ASSERT_NE(lmp->atom->tag, nullptr); - ASSERT_NE(lmp->atom->type, nullptr); - ASSERT_NE(lmp->atom->mask, nullptr); - ASSERT_NE(lmp->atom->image, nullptr); - ASSERT_NE(lmp->atom->x, nullptr); - ASSERT_NE(lmp->atom->v, nullptr); - ASSERT_NE(lmp->atom->f, nullptr); - ASSERT_NE(lmp->atom->q, nullptr); - ASSERT_EQ(lmp->atom->mu, nullptr); - ASSERT_EQ(lmp->atom->omega, nullptr); - ASSERT_NE(lmp->atom->angmom, nullptr); - ASSERT_NE(lmp->atom->torque, nullptr); - ASSERT_EQ(lmp->atom->radius, nullptr); - ASSERT_NE(lmp->atom->rmass, nullptr); - ASSERT_NE(lmp->atom->ellipsoid, nullptr); - ASSERT_EQ(lmp->atom->line, nullptr); - ASSERT_EQ(lmp->atom->tri, nullptr); - ASSERT_EQ(lmp->atom->body, nullptr); - ASSERT_NE(lmp->atom->molecule, nullptr); - ASSERT_EQ(lmp->atom->molindex, nullptr); - ASSERT_EQ(lmp->atom->molatom, nullptr); - ASSERT_NE(lmp->atom->num_bond, nullptr); - ASSERT_NE(lmp->atom->bond_type, nullptr); - ASSERT_NE(lmp->atom->bond_atom, nullptr); - ASSERT_NE(lmp->atom->num_angle, nullptr); - ASSERT_NE(lmp->atom->angle_type, nullptr); - ASSERT_NE(lmp->atom->angle_atom1, nullptr); - ASSERT_NE(lmp->atom->angle_atom2, nullptr); - ASSERT_NE(lmp->atom->angle_atom3, nullptr); - ASSERT_NE(lmp->atom->num_dihedral, nullptr); - ASSERT_NE(lmp->atom->dihedral_type, nullptr); - ASSERT_NE(lmp->atom->dihedral_atom1, nullptr); - ASSERT_NE(lmp->atom->dihedral_atom2, nullptr); - ASSERT_NE(lmp->atom->dihedral_atom3, nullptr); - ASSERT_NE(lmp->atom->dihedral_atom4, nullptr); - ASSERT_NE(lmp->atom->num_improper, nullptr); - ASSERT_NE(lmp->atom->improper_type, nullptr); - ASSERT_NE(lmp->atom->improper_atom1, nullptr); - ASSERT_NE(lmp->atom->improper_atom2, nullptr); - ASSERT_NE(lmp->atom->improper_atom3, nullptr); - ASSERT_NE(lmp->atom->improper_atom4, nullptr); - ASSERT_EQ(lmp->atom->maxspecial, 1); - ASSERT_NE(lmp->atom->nspecial, nullptr); - ASSERT_NE(lmp->atom->special, nullptr); - ASSERT_EQ(lmp->atom->vfrac, nullptr); - ASSERT_EQ(lmp->atom->s0, nullptr); - ASSERT_EQ(lmp->atom->x0, nullptr); - ASSERT_EQ(lmp->atom->sp, nullptr); - ASSERT_EQ(lmp->atom->fm, nullptr); - ASSERT_EQ(lmp->atom->fm_long, nullptr); - ASSERT_EQ(lmp->atom->spin, nullptr); - ASSERT_EQ(lmp->atom->eradius, nullptr); - ASSERT_EQ(lmp->atom->ervel, nullptr); - ASSERT_EQ(lmp->atom->erforce, nullptr); - ASSERT_EQ(lmp->atom->ervelforce, nullptr); - ASSERT_EQ(lmp->atom->cs, nullptr); - ASSERT_EQ(lmp->atom->csforce, nullptr); - ASSERT_EQ(lmp->atom->vforce, nullptr); - ASSERT_EQ(lmp->atom->etag, nullptr); - ASSERT_EQ(lmp->atom->uCond, nullptr); - ASSERT_EQ(lmp->atom->uMech, nullptr); - ASSERT_EQ(lmp->atom->uChem, nullptr); - ASSERT_EQ(lmp->atom->uCG, nullptr); - ASSERT_EQ(lmp->atom->uCGnew, nullptr); - ASSERT_EQ(lmp->atom->duChem, nullptr); - ASSERT_EQ(lmp->atom->dpdTheta, nullptr); - ASSERT_EQ(lmp->atom->cc, nullptr); - ASSERT_EQ(lmp->atom->cc_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_temp, nullptr); - ASSERT_EQ(lmp->atom->edpd_flux, nullptr); - ASSERT_EQ(lmp->atom->edpd_cv, nullptr); - ASSERT_EQ(lmp->atom->length, nullptr); - ASSERT_EQ(lmp->atom->buckling, nullptr); - ASSERT_EQ(lmp->atom->bond_nt, nullptr); - ASSERT_EQ(lmp->atom->contact_radius, nullptr); - ASSERT_EQ(lmp->atom->smd_data_9, nullptr); - ASSERT_EQ(lmp->atom->smd_stress, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain, nullptr); - ASSERT_EQ(lmp->atom->eff_plastic_strain_rate, nullptr); - ASSERT_EQ(lmp->atom->damage, nullptr); - ASSERT_EQ(lmp->atom->rho, nullptr); - ASSERT_EQ(lmp->atom->drho, nullptr); - ASSERT_EQ(lmp->atom->esph, nullptr); - ASSERT_EQ(lmp->atom->desph, nullptr); - ASSERT_EQ(lmp->atom->cv, nullptr); - ASSERT_EQ(lmp->atom->vest, nullptr); - ASSERT_EQ(lmp->atom->nmolecule, 0); - ASSERT_EQ(lmp->atom->molecules, nullptr); - ASSERT_EQ(lmp->atom->nivector, 0); - ASSERT_EQ(lmp->atom->ndvector, 0); - ASSERT_EQ(lmp->atom->iname, nullptr); - ASSERT_EQ(lmp->atom->dname, nullptr); - ASSERT_EQ(lmp->atom->mass, nullptr); - ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - ASSERT_EQ(lmp->atom->nextra_grow, 0); - ASSERT_EQ(lmp->atom->nextra_restart, 0); - ASSERT_EQ(lmp->atom->nextra_border, 0); - ASSERT_EQ(lmp->atom->nextra_grow_max, 0); - ASSERT_EQ(lmp->atom->nextra_restart_max, 0); - ASSERT_EQ(lmp->atom->nextra_border_max, 0); - ASSERT_EQ(lmp->atom->nextra_store, 0); - ASSERT_EQ(lmp->atom->extra_grow, nullptr); - ASSERT_EQ(lmp->atom->extra_restart, nullptr); - ASSERT_EQ(lmp->atom->extra_border, nullptr); - ASSERT_EQ(lmp->atom->extra, nullptr); - ASSERT_EQ(lmp->atom->sametag, nullptr); - ASSERT_EQ(lmp->atom->map_style, 3); - ASSERT_EQ(lmp->atom->map_user, 0); - ASSERT_EQ(lmp->atom->map_tag_max, -1); if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("create_box 3 box bond/types 2 " From 7500d902daa098540bef27df51f54856312aa652 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 13 Nov 2020 17:15:40 -0500 Subject: [PATCH 32/67] Shorten constant names and move to force.h --- src/force.h | 14 ++++++++++++++ src/integrate.cpp | 6 +++--- src/pair.cpp | 10 +++++----- src/pair.h | 14 -------------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/force.h b/src/force.h index a2cc37f0b8..a43eaaddf9 100644 --- a/src/force.h +++ b/src/force.h @@ -26,6 +26,20 @@ namespace LAMMPS_NS { class KSpace; class Pair; +enum { + ENERGY_NONE = 0x00, + ENERGY_GLOBAL = 0x01, + ENERGY_PERATOM = 0x02 +}; + +enum { + VIRIAL_NONE = 0x00, + VIRIAL_TALLY = 0x01, + VIRIAL_FDOTR = 0x02, + VIRIAL_PERATOM = 0x04, + VIRIAL_CENTROID = 0x08 +}; + class Force : protected Pointers { public: double boltz; // Boltzmann constant (eng/degree-K) diff --git a/src/integrate.cpp b/src/integrate.cpp index cf84797fde..d4060e1a1d 100644 --- a/src/integrate.cpp +++ b/src/integrate.cpp @@ -142,7 +142,7 @@ void Integrate::ev_set(bigint ntimestep) int eflag_atom = 0; for (i = 0; i < nelist_atom; i++) if (elist_atom[i]->matchstep(ntimestep)) flag = 1; - if (flag) eflag_atom = ENERGY_PER_ATOM; + if (flag) eflag_atom = ENERGY_PERATOM; if (eflag_global) update->eflag_global = ntimestep; if (eflag_atom) update->eflag_atom = ntimestep; @@ -158,13 +158,13 @@ void Integrate::ev_set(bigint ntimestep) int vflag_atom = 0; for (i = 0; i < nvlist_atom; i++) if (vlist_atom[i]->matchstep(ntimestep)) flag = 1; - if (flag) vflag_atom = VIRIAL_PER_ATOM; + if (flag) vflag_atom = VIRIAL_PERATOM; flag = 0; int cvflag_atom = 0; for (i = 0; i < ncvlist_atom; i++) if (cvlist_atom[i]->matchstep(ntimestep)) flag = 1; - if (flag) cvflag_atom = VIRIAL_PER_ATOM_CENTROID; + if (flag) cvflag_atom = VIRIAL_CENTROID; if (vflag_global) update->vflag_global = ntimestep; if (vflag_atom || cvflag_atom) update->vflag_atom = ntimestep; diff --git a/src/pair.cpp b/src/pair.cpp index 2e2e942a93..80d7830336 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -787,13 +787,13 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) eflag_either = eflag; eflag_global = eflag & ENERGY_GLOBAL; - eflag_atom = eflag & ENERGY_PER_ATOM; + eflag_atom = eflag & ENERGY_PERATOM; - vflag_global = vflag & (VIRIAL_GLOBAL_PW_SUM | VIRIAL_GLOBAL_PW_FDOTR_W_GHOSTS); - vflag_atom = vflag & VIRIAL_PER_ATOM; + vflag_global = vflag & (VIRIAL_TALLY | VIRIAL_FDOTR); + vflag_atom = vflag & VIRIAL_PERATOM; cvflag_atom = 0; - if (vflag & VIRIAL_PER_ATOM_CENTROID) { + if (vflag & VIRIAL_CENTROID) { if (centroidstressflag & 2) { cvflag_atom = 1; } else { @@ -873,7 +873,7 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) // compute global virial via (F dot r) instead of via pairwise summation // unset other flags as appropriate - if (vflag_global == VIRIAL_GLOBAL_PW_FDOTR_W_GHOSTS && no_virial_fdotr_compute == 0) { + if (vflag_global == VIRIAL_FDOTR && no_virial_fdotr_compute == 0) { vflag_fdotr = 1; vflag_global = 0; if (vflag_atom == 0 && cvflag_atom == 0) vflag_either = 0; diff --git a/src/pair.h b/src/pair.h index 7cbe7af541..ace233539f 100644 --- a/src/pair.h +++ b/src/pair.h @@ -18,20 +18,6 @@ namespace LAMMPS_NS { -enum { - ENERGY_NO_COMPUTATION = 0x00, - ENERGY_GLOBAL = 0x01, - ENERGY_PER_ATOM = 0x02 -}; - -enum { - VIRIAL_NO_COMPUTATION = 0x00, - VIRIAL_GLOBAL_PW_SUM = 0x01, - VIRIAL_GLOBAL_PW_FDOTR_W_GHOSTS = 0x02, - VIRIAL_PER_ATOM = 0x04, - VIRIAL_PER_ATOM_CENTROID = 0x08 -}; - class Pair : protected Pointers { friend class AngleSDK; friend class AngleSDKOMP; From 4a8c458634af060e77bf78f40e37dbb6e6a623a0 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 13 Nov 2020 17:21:41 -0500 Subject: [PATCH 33/67] Update comment --- unittest/formats/test_atom_styles.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index d6acd78295..3ceff53b78 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -388,9 +388,10 @@ void ASSERT_ATOM_STATE_EQ(Atom* atom, const AtomState& expected) { ASSERT_EQ(atom->maxspecial, expected.maxspecial); - // currently ignored ASSERT_ARRAY_ALLOCATED(atom->nspecial, expected.has_nspecial); ASSERT_ARRAY_ALLOCATED(atom->special, expected.has_special); + + // currently ignored ASSERT_ARRAY_ALLOCATED(atom->vfrac, false); ASSERT_ARRAY_ALLOCATED(atom->s0, false); ASSERT_ARRAY_ALLOCATED(atom->x0, false); From aaae3da12a9ba376d766870bdacbcb037fcd5cc7 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 13 Nov 2020 17:52:37 -0500 Subject: [PATCH 34/67] Update comment --- src/pair.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pair.cpp b/src/pair.cpp index 80d7830336..eff9690c70 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -869,7 +869,7 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) } } - // if vflag_global = VIRIAL_GLOBAL_PW_FDOTR_W_GHOSTS and pair::compute() calls virial_fdotr_compute() + // if vflag_global = VIRIAL_FDOTR and pair::compute() calls virial_fdotr_compute() // compute global virial via (F dot r) instead of via pairwise summation // unset other flags as appropriate From 8b9f2e0539fa6cb5e2428ebf7a8e674a0f801d11 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sat, 14 Nov 2020 15:51:26 -0500 Subject: [PATCH 35/67] molecule: add atom ID completeness check --- src/molecule.cpp | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/molecule.cpp b/src/molecule.cpp index 57fadfaca4..77fa9c82df 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -509,7 +509,6 @@ void Molecule::read(int flag) // count = vector for tallying bonds,angles,etc per atom if (flag == 0) memory->create(count,natoms,"molecule:count"); - else count = nullptr; // grab keyword and skip next line @@ -616,10 +615,6 @@ void Molecule::read(int flag) parse_keyword(1,line,keyword); } - // clean up - - memory->destroy(count); - // error check if (flag == 0) { @@ -665,6 +660,10 @@ void Molecule::read(int flag) maxradius = radius[0]; } } + + // clean up + + if (flag) memory->destroy(count); } /* ---------------------------------------------------------------------- @@ -673,6 +672,7 @@ void Molecule::read(int flag) void Molecule::coords(char *line) { + for (int i = 0; i < natoms; i++) count[i] = 0; try { for (int i = 0; i < natoms; i++) { readline(line); @@ -682,6 +682,7 @@ void Molecule::coords(char *line) int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Coords section in molecule file"); + count[iatom]++; x[iatom][0] = values.next_double(); x[iatom][1] = values.next_double(); x[iatom][2] = values.next_double(); @@ -695,6 +696,9 @@ void Molecule::coords(char *line) "{}", e.what())); } + for (int i = 0; i < natoms; i++) + if (count[i] == 0) error->all(FLERR,"Invalid Coords section in molecule file"); + if (domain->dimension == 2) { for (int i = 0; i < natoms; i++) if (x[i][2] != 0.0) @@ -709,6 +713,7 @@ void Molecule::coords(char *line) void Molecule::types(char *line) { + for (int i = 0; i < natoms; i++) count[i] = 0; try { for (int i = 0; i < natoms; i++) { readline(line); @@ -718,6 +723,7 @@ void Molecule::types(char *line) int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Types section in molecule file"); + count[iatom]++; type[iatom] = values.next_int(); type[iatom] += toffset; } @@ -726,6 +732,9 @@ void Molecule::types(char *line) "{}", e.what())); } + for (int i = 0; i < natoms; i++) + if (count[i] == 0) error->all(FLERR,"Invalid Types section in molecule file"); + for (int i = 0; i < natoms; i++) if ((type[i] <= 0) || (domain->box_exist && (type[i] > atom->ntypes))) error->all(FLERR,"Invalid atom type in molecule file"); @@ -741,6 +750,7 @@ void Molecule::types(char *line) void Molecule::molecules(char *line) { + for (int i = 0; i < natoms; i++) count[i] = 0; try { for (int i = 0; i < natoms; i++) { readline(line); @@ -749,6 +759,7 @@ void Molecule::molecules(char *line) int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Molecules section in molecule file"); + count[iatom]++; molecule[iatom] = values.next_int(); // molecule[iatom] += moffset; // placeholder for possible molecule offset } @@ -757,6 +768,9 @@ void Molecule::molecules(char *line) "{}", e.what())); } + for (int i = 0; i < natoms; i++) + if (count[i] == 0) error->all(FLERR,"Invalid Molecules section in molecule file"); + for (int i = 0; i < natoms; i++) if (molecule[i] <= 0) error->all(FLERR,"Invalid molecule ID in molecule file"); @@ -801,6 +815,7 @@ void Molecule::fragments(char *line) void Molecule::charges(char *line) { + for (int i = 0; i < natoms; i++) count[i] = 0; try { for (int i = 0; i < natoms; i++) { readline(line); @@ -810,12 +825,16 @@ void Molecule::charges(char *line) int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Charges section in molecule file"); + count[iatom]++; q[iatom] = values.next_double(); } } catch (TokenizerException &e) { error->one(FLERR, fmt::format("Invalid Charges section in molecule file\n" "{}", e.what())); } + + for (int i = 0; i < natoms; i++) + if (count[i] == 0) error->all(FLERR,"Invalid Charges section in molecule file"); } /* ---------------------------------------------------------------------- @@ -824,6 +843,7 @@ void Molecule::charges(char *line) void Molecule::diameters(char *line) { + for (int i = 0; i < natoms; i++) count[i] = 0; try { maxradius = 0.0; for (int i = 0; i < natoms; i++) { @@ -834,6 +854,7 @@ void Molecule::diameters(char *line) int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Diameters section in molecule file"); + count[iatom]++; radius[iatom] = values.next_double(); radius[iatom] *= sizescale; radius[iatom] *= 0.5; @@ -844,6 +865,9 @@ void Molecule::diameters(char *line) "{}", e.what())); } + for (int i = 0; i < natoms; i++) + if (count[i] == 0) error->all(FLERR,"Invalid Diameters section in molecule file"); + for (int i = 0; i < natoms; i++) if (radius[i] < 0.0) error->all(FLERR,"Invalid atom diameter in molecule file"); @@ -855,6 +879,7 @@ void Molecule::diameters(char *line) void Molecule::masses(char *line) { + for (int i = 0; i < natoms; i++) count[i] = 0; try { for (int i = 0; i < natoms; i++) { readline(line); @@ -864,6 +889,7 @@ void Molecule::masses(char *line) int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Masses section in molecule file"); + count[iatom]++; rmass[iatom] = values.next_double(); rmass[iatom] *= sizescale*sizescale*sizescale; } @@ -872,6 +898,9 @@ void Molecule::masses(char *line) "{}", e.what())); } + for (int i = 0; i < natoms; i++) + if (count[i] == 0) error->all(FLERR,"Invalid Masses section in molecule file"); + for (int i = 0; i < natoms; i++) if (rmass[i] <= 0.0) error->all(FLERR,"Invalid atom mass in molecule file"); } @@ -1302,7 +1331,6 @@ void Molecule::special_generate() { int newton_bond = force->newton_bond; tagint atom1,atom2; - int *count = new int[natoms]; // temporary array for special atoms @@ -1388,7 +1416,6 @@ void Molecule::special_generate() } } } - delete[] count; maxspecial = 0; for (int i = 0; i < natoms; i++) From d287e116106bdb77bb3b705f82872a5b8e20acc2 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sat, 14 Nov 2020 16:04:39 -0500 Subject: [PATCH 36/67] clarify docs --- doc/src/molecule.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/src/molecule.rst b/doc/src/molecule.rst index 06dc010038..01f7e539d0 100644 --- a/doc/src/molecule.rst +++ b/doc/src/molecule.rst @@ -202,8 +202,9 @@ bonds between nuclear cores and Drude electrons in a different manner. Each section is listed below in alphabetic order. The format of each section is described including the number of lines it must contain and rules (if any) for whether it can appear in the data file. For per- -atom sections, entries should be numbered from 1 to Natoms, where -Natoms is the number of atoms in the template. +atom sections, entries should be numbered from 1 to Natoms (where +Natoms is the number of atoms in the template), indicating which atom +(or bond, etc) the entry applies to. ---------- From dd23db9369f9b705d23d51a3172a960053e051dc Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Mon, 16 Nov 2020 08:13:33 -0700 Subject: [PATCH 37/67] standardize flags for energy/virial computations in forces --- src/angle.cpp | 11 ++++++++++- src/bond.cpp | 10 +++++++++- src/compute_centroid_stress_atom.cpp | 4 ++-- src/dihedral.cpp | 11 ++++++++++- src/improper.cpp | 11 ++++++++++- src/integrate.cpp | 27 ++++++++++++--------------- src/kspace.cpp | 10 +++++++++- src/min.cpp | 9 +++++---- src/pair.cpp | 24 +++++++++++++++++++++--- src/pair.h | 8 ++++---- src/respa.cpp | 5 +++-- src/verlet.cpp | 9 +++++---- 12 files changed, 100 insertions(+), 39 deletions(-) diff --git a/src/angle.cpp b/src/angle.cpp index 97b2c4c3e1..1994a07c78 100644 --- a/src/angle.cpp +++ b/src/angle.cpp @@ -75,7 +75,16 @@ void Angle::init() /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for bitwise settings of eflag/vflag + set the following flags, values are otherwise 0: + evflag = 1 if any bits of eflag or vflag are set + eflag_global = 1 if ENERGY_GLOBAL bit of eflag set + eflag_atom = 1 if ENERGY_ATOM bit of eflag set + eflag_either = 1 if eflag_global or eflag_atom is set + vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set + vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set ------------------------------------------------------------------------- */ void Angle::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/bond.cpp b/src/bond.cpp index 1912d15aa7..ed8cc3dbd6 100644 --- a/src/bond.cpp +++ b/src/bond.cpp @@ -80,7 +80,15 @@ void Bond::init() /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for bitwise settings of eflag/vflag + set the following flags, values are otherwise 0: + evflag = 1 if any bits of eflag or vflag are set + eflag_global = 1 if ENERGY_GLOBAL bit of eflag set + eflag_atom = 1 if ENERGY_ATOM bit of eflag set + eflag_either = 1 if eflag_global or eflag_atom is set + vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom = 1 if VIRIAL_PERATOM or VIRIAL_CENTROID bit of vflag set + vflag_either = 1 if vflag_global or vflag_atom is set ------------------------------------------------------------------------- */ void Bond::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/compute_centroid_stress_atom.cpp b/src/compute_centroid_stress_atom.cpp index d17d402a3d..d4d602ee64 100644 --- a/src/compute_centroid_stress_atom.cpp +++ b/src/compute_centroid_stress_atom.cpp @@ -126,7 +126,7 @@ void ComputeCentroidStressAtom::init() // check if pair styles support centroid atom stress if (pairflag && force->pair) - if (force->pair->centroidstressflag & 4) + if (force->pair->centroidstressflag == CENTROID_NOTAVAIL) error->all(FLERR, "Pair style does not support compute centroid/stress/atom"); } @@ -178,7 +178,7 @@ void ComputeCentroidStressAtom::compute_peratom() // per-atom virial and per-atom centroid virial are the same for two-body // many-body pair styles not yet implemented if (pairflag && force->pair && force->pair->compute_flag) { - if (force->pair->centroidstressflag & 2) { + if (force->pair->centroidstressflag == CENTROID_AVAIL) { double **cvatom = force->pair->cvatom; for (i = 0; i < npair; i++) for (j = 0; j < 9; j++) diff --git a/src/dihedral.cpp b/src/dihedral.cpp index f778341bfa..f2d1a548c2 100644 --- a/src/dihedral.cpp +++ b/src/dihedral.cpp @@ -74,7 +74,16 @@ void Dihedral::init() /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for bitwise settings of eflag/vflag + set the following flags, values are otherwise 0: + evflag = 1 if any bits of eflag or vflag are set + eflag_global = 1 if ENERGY_GLOBAL bit of eflag set + eflag_atom = 1 if ENERGY_ATOM bit of eflag set + eflag_either = 1 if eflag_global or eflag_atom is set + vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set + vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set ------------------------------------------------------------------------- */ void Dihedral::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/improper.cpp b/src/improper.cpp index faf9e2fa52..4e481462cf 100644 --- a/src/improper.cpp +++ b/src/improper.cpp @@ -72,7 +72,16 @@ void Improper::init() /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for bitwise settings of eflag/vflag + set the following flags, values are otherwise 0: + evflag = 1 if any bits of eflag or vflag are set + eflag_global = 1 if ENERGY_GLOBAL bit of eflag set + eflag_atom = 1 if ENERGY_ATOM bit of eflag set + eflag_either = 1 if eflag_global or eflag_atom is set + vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set + vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set ------------------------------------------------------------------------- */ void Improper::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/integrate.cpp b/src/integrate.cpp index d4060e1a1d..e88182e9cf 100644 --- a/src/integrate.cpp +++ b/src/integrate.cpp @@ -111,21 +111,18 @@ void Integrate::ev_setup() /* ---------------------------------------------------------------------- set eflag,vflag for current iteration + based on computes that need energy/virial info on this timestep invoke matchstep() on all timestep-dependent computes to clear their arrays - eflag/vflag based on computes that need info on this ntimestep - eflag = 0 = no energy computation - eflag = 1 = global energy only - eflag = 2 = per-atom energy only - eflag = 3 = both global and per-atom energy - vflag = 0 = no virial computation (pressure) - vflag = 1 = global virial with pair portion via sum of pairwise interactions - vflag = 2 = global virial with pair portion via F dot r including ghosts - vflag = 4 = per-atom virial only - vflag = 5 or 6 = both global and per-atom virial - vflag = 8 = per-atom centroid virial only - vflag = 9 or 10 = both global and per-atom centroid virial - vflag = 12 = both per-atom virial and per-atom centroid virial - vflag = 13 or 14 = global, per-atom virial and per-atom centroid virial + eflag: set any or no bits + ENERGY_GLOBAL bit for global energy + ENERGY_ATOM bit for per-atom energy + vflag: set any or no bits, but GLOBAL/FDOTR bit cannot both be set + VIRIAL_PAIR bit for global virial as sum of pairwise terms + VIRIAL_FDOTR bit for global virial via F dot r + VIRIAL_ATOM bit for per-atom virial + VIRIAL_CENTROID bit for per-atom centroid virial + all force components (pair,bond,angle,...,kspace) use eflag/vflag + in their ev_setup() method to set local energy/virial flags ------------------------------------------------------------------------- */ void Integrate::ev_set(bigint ntimestep) @@ -136,7 +133,7 @@ void Integrate::ev_set(bigint ntimestep) int eflag_global = 0; for (i = 0; i < nelist_global; i++) if (elist_global[i]->matchstep(ntimestep)) flag = 1; - if (flag) eflag_global = 1; + if (flag) eflag_global = ENERGY_GLOBAL; flag = 0; int eflag_atom = 0; diff --git a/src/kspace.cpp b/src/kspace.cpp index 16668c137a..79fe10d849 100644 --- a/src/kspace.cpp +++ b/src/kspace.cpp @@ -214,7 +214,15 @@ void KSpace::pair_check() /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for bitwise settings of eflag/vflag + set the following flags, values are otherwise 0: + evflag = 1 if any bits of eflag or vflag are set + eflag_global = 1 if ENERGY_GLOBAL bit of eflag set + eflag_atom = 1 if ENERGY_ATOM bit of eflag set + eflag_either = 1 if eflag_global or eflag_atom is set + vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + vflag_either = 1 if vflag_global or vflag_atom is set ------------------------------------------------------------------------- */ void KSpace::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/min.cpp b/src/min.cpp index ac711d8900..1db5c8b239 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -144,11 +144,12 @@ void Min::init() requestor = nullptr; // virial_style: - // 1 if computed explicitly by pair->compute via sum over pair interactions - // 2 if computed implicitly by pair->virial_compute via sum over ghost atoms + // VIRIAL_PAIR if computed explicitly in pair via sum over pair interactions + // VIRIAL_FDOTR if computed implicitly in pair by + // virial_fdotr_compute() via sum over ghosts - if (force->newton_pair) virial_style = 2; - else virial_style = 1; + if (force->newton_pair) virial_style = VIRIAL_FDOTR; + else virial_style = VIRIAL_PAIR; // setup lists of computes for global and per-atom PE and pressure diff --git a/src/pair.cpp b/src/pair.cpp index eff9690c70..396f50b09a 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -74,9 +74,10 @@ Pair::Pair(LAMMPS *lmp) : Pointers(lmp) setflag = nullptr; cutsq = nullptr; - ewaldflag = pppmflag = msmflag = dispersionflag = tip4pflag = dipoleflag = spinflag = 0; + ewaldflag = pppmflag = msmflag = dispersionflag = + tip4pflag = dipoleflag = spinflag = 0; reinitflag = 1; - centroidstressflag = 4; + centroidstressflag = CENTROID_SAME; // pair_modify settings @@ -776,7 +777,24 @@ void Pair::del_tally_callback(Compute *ptr) /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for bitwise settings of eflag/vflag + set the following flags, values are otherwise 0: + evflag = 1 if any bits of eflag or vflag are set + eflag_global = 1 if ENERGY_GLOBAL bit of eflag set + eflag_atom = 1 if ENERGY_ATOM bit of eflag set + eflag_either = 1 if eflag_global or eflag_atom is set + vflag_global = 1 if VIRIAL_PAIR bit of vflag set + vflag_global = 2 if VIRIAL_FDOTR bit of vflag set + vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + vflag_atom = 1 if VIRIAL_CENTROID bit of vflag set + and centroidstressflag != CENTROID_AVAIL + cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set + and centroidstressflag = CENTROID_AVAIL + vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set + centroidstressflag is set by the pair style to one of these values: + CENTROID_SAME = same as two-body stress + CENTROID_AVAIL = different and implemented + CENTROID_NOTAVAIL = different but not yet implemented ------------------------------------------------------------------------- */ void Pair::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/pair.h b/src/pair.h index ace233539f..5f931cea54 100644 --- a/src/pair.h +++ b/src/pair.h @@ -68,10 +68,10 @@ class Pair : protected Pointers { int spinflag; // 1 if compatible with spin solver int reinitflag; // 1 if compatible with fix adapt and alike - int centroidstressflag; // compatibility with centroid atomic stress - // 1 if same as two-body atomic stress - // 2 if implemented and different from two-body - // 4 if not compatible/implemented + int centroidstressflag; // centroid atomic compared to two-body stress + // CENTROID_SAME = same as two-body stress + // CENTROID_AVAIL = different and implemented + // CENTROID_NOTAVAIL = different, not yet implemented int tail_flag; // pair_modify flag for LJ tail correction double etail,ptail; // energy/pressure tail corrections diff --git a/src/respa.cpp b/src/respa.cpp index dcabcb11ef..aebee0f6eb 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -311,9 +311,10 @@ void Respa::init() if (force->pair && force->pair->respa_enable == 0) error->all(FLERR,"Pair style does not support rRESPA inner/middle/outer"); - // virial_style = 1 (explicit) since never computed implicitly like Verlet + // virial_style = VIRIAL_PAIR (explicit) + // since never computed implicitly with virial_fdotr_compute() like Verlet - virial_style = 1; + virial_style = VIRIAL_PAIR; // setup lists of computes for global and per-atom PE and pressure diff --git a/src/verlet.cpp b/src/verlet.cpp index 3d20a771f4..5e53daafbb 100644 --- a/src/verlet.cpp +++ b/src/verlet.cpp @@ -54,11 +54,12 @@ void Verlet::init() error->warning(FLERR,"No fixes defined, atoms won't move"); // virial_style: - // 1 if computed explicitly by pair->compute via sum over pair interactions - // 2 if computed implicitly by pair->virial_fdotr_compute via sum over ghosts + // VIRIAL_PAIR if computed explicitly in pair via sum over pair interactions + // VIRIAL_FDOTR if computed implicitly in pair by + // virial_fdotr_compute() via sum over ghosts - if (force->newton_pair) virial_style = 2; - else virial_style = 1; + if (force->newton_pair) virial_style = VIRIAL_FDOTR; + else virial_style = VIRIAL_PAIR; // setup lists of computes for global and per-atom PE and pressure From f3bc76d6a47120212aa80155fd03fcd078737a82 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 16 Nov 2020 10:35:42 -0500 Subject: [PATCH 38/67] Add CENTROID enum and rename some constants --- src/force.h | 12 +++++++++--- src/pair.cpp | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/force.h b/src/force.h index a43eaaddf9..f213200cf4 100644 --- a/src/force.h +++ b/src/force.h @@ -29,17 +29,23 @@ namespace LAMMPS_NS { enum { ENERGY_NONE = 0x00, ENERGY_GLOBAL = 0x01, - ENERGY_PERATOM = 0x02 + ENERGY_ATOM = 0x02 }; enum { VIRIAL_NONE = 0x00, - VIRIAL_TALLY = 0x01, + VIRIAL_PAIR = 0x01, VIRIAL_FDOTR = 0x02, - VIRIAL_PERATOM = 0x04, + VIRIAL_ATOM = 0x04, VIRIAL_CENTROID = 0x08 }; +enum { + CENTROID_SAME = 0x00, + CENTROID_AVAIL = 0x01, + CENTROID_NOTAVAIL = 0x02 +}; + class Force : protected Pointers { public: double boltz; // Boltzmann constant (eng/degree-K) diff --git a/src/pair.cpp b/src/pair.cpp index 396f50b09a..ca738c46e7 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -785,7 +785,7 @@ void Pair::del_tally_callback(Compute *ptr) eflag_either = 1 if eflag_global or eflag_atom is set vflag_global = 1 if VIRIAL_PAIR bit of vflag set vflag_global = 2 if VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + vflag_atom = 1 if VIRIAL_ATOM bit of vflag set vflag_atom = 1 if VIRIAL_CENTROID bit of vflag set and centroidstressflag != CENTROID_AVAIL cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set @@ -805,10 +805,10 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) eflag_either = eflag; eflag_global = eflag & ENERGY_GLOBAL; - eflag_atom = eflag & ENERGY_PERATOM; + eflag_atom = eflag & ENERGY_ATOM; - vflag_global = vflag & (VIRIAL_TALLY | VIRIAL_FDOTR); - vflag_atom = vflag & VIRIAL_PERATOM; + vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); + vflag_atom = vflag & VIRIAL_ATOM; cvflag_atom = 0; if (vflag & VIRIAL_CENTROID) { From c0f3697d9eea3f8e6f4e21aeb78b5136f8ad0807 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 16 Nov 2020 10:51:56 -0500 Subject: [PATCH 39/67] Undo value changes for CENTROID constants --- src/force.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/force.h b/src/force.h index f213200cf4..9be26bd2a7 100644 --- a/src/force.h +++ b/src/force.h @@ -41,9 +41,9 @@ enum { }; enum { - CENTROID_SAME = 0x00, - CENTROID_AVAIL = 0x01, - CENTROID_NOTAVAIL = 0x02 + CENTROID_SAME = 0x01, + CENTROID_AVAIL = 0x02, + CENTROID_NOTAVAIL = 0x04 }; class Force : protected Pointers { From 1ba9dd743574d565fbd4ae5db7b93decceb245b0 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 16 Nov 2020 11:01:31 -0500 Subject: [PATCH 40/67] Apply CENTROID_* constants --- src/CLASS2/pair_lj_class2.cpp | 2 +- src/CLASS2/pair_lj_class2_coul_cut.cpp | 2 +- src/PYTHON/pair_python.cpp | 2 +- src/USER-FEP/pair_coul_cut_soft.cpp | 2 +- src/USER-FEP/pair_lj_class2_coul_cut_soft.cpp | 2 +- src/USER-FEP/pair_lj_class2_soft.cpp | 2 +- src/USER-FEP/pair_lj_cut_coul_cut_soft.cpp | 2 +- src/USER-FEP/pair_lj_cut_soft.cpp | 2 +- src/pair.cpp | 4 ++-- src/pair_beck.cpp | 2 +- src/pair_buck.cpp | 2 +- src/pair_buck_coul_cut.cpp | 2 +- src/pair_coul_cut.cpp | 2 +- src/pair_coul_dsf.cpp | 2 +- src/pair_coul_wolf.cpp | 2 +- src/pair_hybrid.cpp | 6 +++--- src/pair_lj_cubic.cpp | 2 +- src/pair_lj_cut.cpp | 2 +- src/pair_lj_cut_coul_cut.cpp | 2 +- src/pair_lj_cut_coul_dsf.cpp | 2 +- src/pair_lj_cut_coul_wolf.cpp | 2 +- src/pair_lj_expand.cpp | 2 +- src/pair_lj_gromacs_coul_gromacs.cpp | 2 +- src/pair_lj_smooth.cpp | 2 +- src/pair_lj_smooth_linear.cpp | 2 +- src/pair_morse.cpp | 2 +- src/pair_ufm.cpp | 2 +- 27 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/CLASS2/pair_lj_class2.cpp b/src/CLASS2/pair_lj_class2.cpp index 79e0c02fd7..3727b17493 100644 --- a/src/CLASS2/pair_lj_class2.cpp +++ b/src/CLASS2/pair_lj_class2.cpp @@ -35,7 +35,7 @@ PairLJClass2::PairLJClass2(LAMMPS *lmp) : Pair(lmp) { respa_enable = 1; writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/CLASS2/pair_lj_class2_coul_cut.cpp b/src/CLASS2/pair_lj_class2_coul_cut.cpp index c27dd0aee3..a767b70e82 100644 --- a/src/CLASS2/pair_lj_class2_coul_cut.cpp +++ b/src/CLASS2/pair_lj_class2_coul_cut.cpp @@ -33,7 +33,7 @@ using namespace MathConst; PairLJClass2CoulCut::PairLJClass2CoulCut(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/PYTHON/pair_python.cpp b/src/PYTHON/pair_python.cpp index ab726c8a28..eb54d1d4e5 100644 --- a/src/PYTHON/pair_python.cpp +++ b/src/PYTHON/pair_python.cpp @@ -41,7 +41,7 @@ PairPython::PairPython(LAMMPS *lmp) : Pair(lmp) { one_coeff = 1; reinitflag = 0; cut_global = 0.0; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; py_potential = nullptr; skip_types = nullptr; diff --git a/src/USER-FEP/pair_coul_cut_soft.cpp b/src/USER-FEP/pair_coul_cut_soft.cpp index 3540fb0504..0928e18d6a 100644 --- a/src/USER-FEP/pair_coul_cut_soft.cpp +++ b/src/USER-FEP/pair_coul_cut_soft.cpp @@ -33,7 +33,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ PairCoulCutSoft::PairCoulCutSoft(LAMMPS *lmp) : Pair(lmp) { - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/USER-FEP/pair_lj_class2_coul_cut_soft.cpp b/src/USER-FEP/pair_lj_class2_coul_cut_soft.cpp index 7e9f210905..8b462b0ac7 100644 --- a/src/USER-FEP/pair_lj_class2_coul_cut_soft.cpp +++ b/src/USER-FEP/pair_lj_class2_coul_cut_soft.cpp @@ -33,7 +33,7 @@ using namespace MathConst; PairLJClass2CoulCutSoft::PairLJClass2CoulCutSoft(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/USER-FEP/pair_lj_class2_soft.cpp b/src/USER-FEP/pair_lj_class2_soft.cpp index 716bf890cf..df8d1aaab6 100644 --- a/src/USER-FEP/pair_lj_class2_soft.cpp +++ b/src/USER-FEP/pair_lj_class2_soft.cpp @@ -32,7 +32,7 @@ using namespace MathConst; PairLJClass2Soft::PairLJClass2Soft(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/USER-FEP/pair_lj_cut_coul_cut_soft.cpp b/src/USER-FEP/pair_lj_cut_coul_cut_soft.cpp index f776944ee3..f69ea9a5d9 100644 --- a/src/USER-FEP/pair_lj_cut_coul_cut_soft.cpp +++ b/src/USER-FEP/pair_lj_cut_coul_cut_soft.cpp @@ -37,7 +37,7 @@ using namespace MathConst; PairLJCutCoulCutSoft::PairLJCutCoulCutSoft(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/USER-FEP/pair_lj_cut_soft.cpp b/src/USER-FEP/pair_lj_cut_soft.cpp index 6d292acbb3..c3574746e2 100644 --- a/src/USER-FEP/pair_lj_cut_soft.cpp +++ b/src/USER-FEP/pair_lj_cut_soft.cpp @@ -43,7 +43,7 @@ PairLJCutSoft::PairLJCutSoft(LAMMPS *lmp) : Pair(lmp) respa_enable = 1; writedata = 1; allocated = 0; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair.cpp b/src/pair.cpp index ca738c46e7..0627939eff 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -812,13 +812,13 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) cvflag_atom = 0; if (vflag & VIRIAL_CENTROID) { - if (centroidstressflag & 2) { + if (centroidstressflag & CENTROID_AVAIL) { cvflag_atom = 1; } else { vflag_atom = 1; } // extra check, because both bits might be set - if (centroidstressflag & 1) vflag_atom = 1; + if (centroidstressflag & CENTROID_SAME) vflag_atom = 1; } vflag_either = vflag_global || vflag_atom; diff --git a/src/pair_beck.cpp b/src/pair_beck.cpp index bfd39a56e5..6a5875e59b 100644 --- a/src/pair_beck.cpp +++ b/src/pair_beck.cpp @@ -33,7 +33,7 @@ using namespace MathSpecial; /* ---------------------------------------------------------------------- */ PairBeck::PairBeck(LAMMPS *lmp) : Pair(lmp) { - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_buck.cpp b/src/pair_buck.cpp index 1954ae2891..d829495495 100644 --- a/src/pair_buck.cpp +++ b/src/pair_buck.cpp @@ -32,7 +32,7 @@ using namespace MathConst; PairBuck::PairBuck(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_buck_coul_cut.cpp b/src/pair_buck_coul_cut.cpp index 0940a3232a..65925f0b33 100644 --- a/src/pair_buck_coul_cut.cpp +++ b/src/pair_buck_coul_cut.cpp @@ -36,7 +36,7 @@ using namespace MathConst; PairBuckCoulCut::PairBuckCoulCut(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_coul_cut.cpp b/src/pair_coul_cut.cpp index c50cc75c0c..a3653920be 100644 --- a/src/pair_coul_cut.cpp +++ b/src/pair_coul_cut.cpp @@ -29,7 +29,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ PairCoulCut::PairCoulCut(LAMMPS *lmp) : Pair(lmp) { - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_coul_dsf.cpp b/src/pair_coul_dsf.cpp index 889f2757aa..f9be4eac96 100644 --- a/src/pair_coul_dsf.cpp +++ b/src/pair_coul_dsf.cpp @@ -44,7 +44,7 @@ using namespace MathConst; /* ---------------------------------------------------------------------- */ PairCoulDSF::PairCoulDSF(LAMMPS *lmp) : Pair(lmp) { - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_coul_wolf.cpp b/src/pair_coul_wolf.cpp index df22b5a67d..57acf90153 100644 --- a/src/pair_coul_wolf.cpp +++ b/src/pair_coul_wolf.cpp @@ -36,7 +36,7 @@ using namespace MathConst; PairCoulWolf::PairCoulWolf(LAMMPS *lmp) : Pair(lmp) { single_enable = 0; // NOTE: single() method below is not yet correct - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_hybrid.cpp b/src/pair_hybrid.cpp index 8e69deb21a..1c3ef45307 100644 --- a/src/pair_hybrid.cpp +++ b/src/pair_hybrid.cpp @@ -45,7 +45,7 @@ PairHybrid::PairHybrid(LAMMPS *lmp) : Pair(lmp), // assume pair hybrid always supports centroid atomic stress, // so that cflag_atom gets set when needed - centroidstressflag = 2; + centroidstressflag = CENTROID_AVAIL; } /* ---------------------------------------------------------------------- */ @@ -168,7 +168,7 @@ void PairHybrid::compute(int eflag, int vflag) if (cvflag_atom) { n = atom->nlocal; if (force->newton_pair) n += atom->nghost; - if (styles[m]->centroidstressflag & 2) { + if (styles[m]->centroidstressflag & CENTROID_AVAIL) { double **cvatom_substyle = styles[m]->cvatom; for (i = 0; i < n; i++) for (j = 0; j < 9; j++) @@ -401,7 +401,7 @@ void PairHybrid::flags() if (styles[m]->dispersionflag) dispersionflag = 1; if (styles[m]->tip4pflag) tip4pflag = 1; if (styles[m]->compute_flag) compute_flag = 1; - if (styles[m]->centroidstressflag & 4) centroidstressflag |= 4; + if (styles[m]->centroidstressflag & CENTROID_NOTAVAIL) centroidstressflag |= CENTROID_NOTAVAIL; } single_enable = (single_enable == nstyles) ? 1 : 0; respa_enable = (respa_enable == nstyles) ? 1 : 0; diff --git a/src/pair_lj_cubic.cpp b/src/pair_lj_cubic.cpp index 73e99d5ff8..5dd64ff6ae 100644 --- a/src/pair_lj_cubic.cpp +++ b/src/pair_lj_cubic.cpp @@ -33,7 +33,7 @@ using namespace PairLJCubicConstants; /* ---------------------------------------------------------------------- */ PairLJCubic::PairLJCubic(LAMMPS *lmp) : Pair(lmp) { - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_cut.cpp b/src/pair_lj_cut.cpp index cdd9167b65..c68c106156 100644 --- a/src/pair_lj_cut.cpp +++ b/src/pair_lj_cut.cpp @@ -41,7 +41,7 @@ PairLJCut::PairLJCut(LAMMPS *lmp) : Pair(lmp) { respa_enable = 1; writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_cut_coul_cut.cpp b/src/pair_lj_cut_coul_cut.cpp index 2b164ede1d..97e26e78b8 100644 --- a/src/pair_lj_cut_coul_cut.cpp +++ b/src/pair_lj_cut_coul_cut.cpp @@ -33,7 +33,7 @@ using namespace MathConst; PairLJCutCoulCut::PairLJCutCoulCut(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_cut_coul_dsf.cpp b/src/pair_lj_cut_coul_dsf.cpp index d1989ba020..7d238aa720 100644 --- a/src/pair_lj_cut_coul_dsf.cpp +++ b/src/pair_lj_cut_coul_dsf.cpp @@ -46,7 +46,7 @@ using namespace MathConst; PairLJCutCoulDSF::PairLJCutCoulDSF(LAMMPS *lmp) : Pair(lmp) { single_enable = 0; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_cut_coul_wolf.cpp b/src/pair_lj_cut_coul_wolf.cpp index 540cb5c959..0b9a3abce1 100644 --- a/src/pair_lj_cut_coul_wolf.cpp +++ b/src/pair_lj_cut_coul_wolf.cpp @@ -37,7 +37,7 @@ PairLJCutCoulWolf::PairLJCutCoulWolf(LAMMPS *lmp) : Pair(lmp) { single_enable = 0; writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_expand.cpp b/src/pair_lj_expand.cpp index 6cb13f7390..d22d7335db 100644 --- a/src/pair_lj_expand.cpp +++ b/src/pair_lj_expand.cpp @@ -32,7 +32,7 @@ using namespace MathConst; PairLJExpand::PairLJExpand(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_gromacs_coul_gromacs.cpp b/src/pair_lj_gromacs_coul_gromacs.cpp index 30dc5b67fd..f9726dc3d3 100644 --- a/src/pair_lj_gromacs_coul_gromacs.cpp +++ b/src/pair_lj_gromacs_coul_gromacs.cpp @@ -34,7 +34,7 @@ using namespace LAMMPS_NS; PairLJGromacsCoulGromacs::PairLJGromacsCoulGromacs(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_smooth.cpp b/src/pair_lj_smooth.cpp index b6d4526f77..9f51627a19 100644 --- a/src/pair_lj_smooth.cpp +++ b/src/pair_lj_smooth.cpp @@ -33,7 +33,7 @@ using namespace LAMMPS_NS; PairLJSmooth::PairLJSmooth(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_smooth_linear.cpp b/src/pair_lj_smooth_linear.cpp index 2b494b14e7..6c7d678842 100644 --- a/src/pair_lj_smooth_linear.cpp +++ b/src/pair_lj_smooth_linear.cpp @@ -32,7 +32,7 @@ using namespace LAMMPS_NS; PairLJSmoothLinear::PairLJSmoothLinear(LAMMPS *lmp) : Pair(lmp) { single_hessian_enable = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_morse.cpp b/src/pair_morse.cpp index 3ec3db1e2b..08247c51d4 100644 --- a/src/pair_morse.cpp +++ b/src/pair_morse.cpp @@ -30,7 +30,7 @@ using namespace LAMMPS_NS; PairMorse::PairMorse(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_ufm.cpp b/src/pair_ufm.cpp index 45dcf3fbe2..ec570c0119 100644 --- a/src/pair_ufm.cpp +++ b/src/pair_ufm.cpp @@ -36,7 +36,7 @@ using namespace LAMMPS_NS; PairUFM::PairUFM(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = 1; + centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ From 5ce536f2e9510c76d1cd70a2295d1a520499e505 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 16 Nov 2020 11:03:18 -0500 Subject: [PATCH 41/67] Update constant names --- src/angle.cpp | 2 +- src/bond.cpp | 2 +- src/dihedral.cpp | 2 +- src/improper.cpp | 2 +- src/integrate.cpp | 4 ++-- src/kspace.cpp | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/angle.cpp b/src/angle.cpp index 1994a07c78..75925b7b94 100644 --- a/src/angle.cpp +++ b/src/angle.cpp @@ -82,7 +82,7 @@ void Angle::init() eflag_atom = 1 if ENERGY_ATOM bit of eflag set eflag_either = 1 if eflag_global or eflag_atom is set vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + vflag_atom = 1 if VIRIAL_ATOM bit of vflag set cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set ------------------------------------------------------------------------- */ diff --git a/src/bond.cpp b/src/bond.cpp index ed8cc3dbd6..f29d9c8b5a 100644 --- a/src/bond.cpp +++ b/src/bond.cpp @@ -87,7 +87,7 @@ void Bond::init() eflag_atom = 1 if ENERGY_ATOM bit of eflag set eflag_either = 1 if eflag_global or eflag_atom is set vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_PERATOM or VIRIAL_CENTROID bit of vflag set + vflag_atom = 1 if VIRIAL_ATOM or VIRIAL_CENTROID bit of vflag set vflag_either = 1 if vflag_global or vflag_atom is set ------------------------------------------------------------------------- */ diff --git a/src/dihedral.cpp b/src/dihedral.cpp index f2d1a548c2..f7e9f9fb4a 100644 --- a/src/dihedral.cpp +++ b/src/dihedral.cpp @@ -81,7 +81,7 @@ void Dihedral::init() eflag_atom = 1 if ENERGY_ATOM bit of eflag set eflag_either = 1 if eflag_global or eflag_atom is set vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + vflag_atom = 1 if VIRIAL_ATOM bit of vflag set cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set ------------------------------------------------------------------------- */ diff --git a/src/improper.cpp b/src/improper.cpp index 4e481462cf..f1accf25c7 100644 --- a/src/improper.cpp +++ b/src/improper.cpp @@ -79,7 +79,7 @@ void Improper::init() eflag_atom = 1 if ENERGY_ATOM bit of eflag set eflag_either = 1 if eflag_global or eflag_atom is set vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + vflag_atom = 1 if VIRIAL_ATOM bit of vflag set cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set ------------------------------------------------------------------------- */ diff --git a/src/integrate.cpp b/src/integrate.cpp index e88182e9cf..8b8f607e00 100644 --- a/src/integrate.cpp +++ b/src/integrate.cpp @@ -139,7 +139,7 @@ void Integrate::ev_set(bigint ntimestep) int eflag_atom = 0; for (i = 0; i < nelist_atom; i++) if (elist_atom[i]->matchstep(ntimestep)) flag = 1; - if (flag) eflag_atom = ENERGY_PERATOM; + if (flag) eflag_atom = ENERGY_ATOM; if (eflag_global) update->eflag_global = ntimestep; if (eflag_atom) update->eflag_atom = ntimestep; @@ -155,7 +155,7 @@ void Integrate::ev_set(bigint ntimestep) int vflag_atom = 0; for (i = 0; i < nvlist_atom; i++) if (vlist_atom[i]->matchstep(ntimestep)) flag = 1; - if (flag) vflag_atom = VIRIAL_PERATOM; + if (flag) vflag_atom = VIRIAL_ATOM; flag = 0; int cvflag_atom = 0; diff --git a/src/kspace.cpp b/src/kspace.cpp index 79fe10d849..9ca35b9e72 100644 --- a/src/kspace.cpp +++ b/src/kspace.cpp @@ -221,7 +221,7 @@ void KSpace::pair_check() eflag_atom = 1 if ENERGY_ATOM bit of eflag set eflag_either = 1 if eflag_global or eflag_atom is set vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + vflag_atom = 1 if VIRIAL_ATOM bit of vflag set vflag_either = 1 if vflag_global or vflag_atom is set ------------------------------------------------------------------------- */ From 746655ed2ec5c458ae099c6408dbe4f96f7944fa Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 16 Nov 2020 11:52:42 -0500 Subject: [PATCH 42/67] Undo more changes to make values match new constants --- src/compute_centroid_stress_atom.cpp | 4 ++-- src/pair.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compute_centroid_stress_atom.cpp b/src/compute_centroid_stress_atom.cpp index d4d602ee64..35633d5e4d 100644 --- a/src/compute_centroid_stress_atom.cpp +++ b/src/compute_centroid_stress_atom.cpp @@ -126,7 +126,7 @@ void ComputeCentroidStressAtom::init() // check if pair styles support centroid atom stress if (pairflag && force->pair) - if (force->pair->centroidstressflag == CENTROID_NOTAVAIL) + if (force->pair->centroidstressflag & CENTROID_NOTAVAIL) error->all(FLERR, "Pair style does not support compute centroid/stress/atom"); } @@ -178,7 +178,7 @@ void ComputeCentroidStressAtom::compute_peratom() // per-atom virial and per-atom centroid virial are the same for two-body // many-body pair styles not yet implemented if (pairflag && force->pair && force->pair->compute_flag) { - if (force->pair->centroidstressflag == CENTROID_AVAIL) { + if (force->pair->centroidstressflag & CENTROID_AVAIL) { double **cvatom = force->pair->cvatom; for (i = 0; i < npair; i++) for (j = 0; j < 9; j++) diff --git a/src/pair.cpp b/src/pair.cpp index 0627939eff..470c147798 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -77,7 +77,7 @@ Pair::Pair(LAMMPS *lmp) : Pointers(lmp) ewaldflag = pppmflag = msmflag = dispersionflag = tip4pflag = dipoleflag = spinflag = 0; reinitflag = 1; - centroidstressflag = CENTROID_SAME; + centroidstressflag = CENTROID_NOTAVAIL; // pair_modify settings From 145d688fa4cdf38b72454fcee959eb6251243a44 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Mon, 16 Nov 2020 15:09:17 -0500 Subject: [PATCH 43/67] clairfy docs --- doc/src/molecule.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/src/molecule.rst b/doc/src/molecule.rst index 01f7e539d0..b86983766d 100644 --- a/doc/src/molecule.rst +++ b/doc/src/molecule.rst @@ -204,7 +204,9 @@ section is described including the number of lines it must contain and rules (if any) for whether it can appear in the data file. For per- atom sections, entries should be numbered from 1 to Natoms (where Natoms is the number of atoms in the template), indicating which atom -(or bond, etc) the entry applies to. +(or bond, etc) the entry applies to. Per-atom sections need to +include a setting for every atom, but the atoms can be listed in any +order. ---------- From 251dcdf8a20a9aad519dc6ac8064286e50bd3b9e Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 16 Nov 2020 15:33:15 -0500 Subject: [PATCH 44/67] Make use of ENERGY_ and VIRIAL_ constants --- src/KOKKOS/pair_hybrid_kokkos.cpp | 12 +-- src/KOKKOS/pair_reaxc_kokkos.cpp | 8 +- src/USER-INTEL/intel_preprocess.h | 4 +- src/USER-INTEL/pair_buck_coul_cut_intel.cpp | 2 +- src/USER-INTEL/pair_buck_intel.cpp | 2 +- src/USER-INTEL/pair_dpd_intel.cpp | 2 +- src/USER-INTEL/pair_eam_intel.cpp | 2 +- src/USER-INTEL/pair_gayberne_intel.cpp | 2 +- .../pair_lj_charmm_coul_charmm_intel.cpp | 2 +- .../pair_lj_charmm_coul_long_intel.cpp | 2 +- .../pair_lj_cut_coul_long_intel.cpp | 2 +- src/USER-INTEL/pair_lj_cut_intel.cpp | 2 +- src/USER-OMP/thr_omp.cpp | 90 +++++++++---------- src/angle.cpp | 10 +-- src/bond.cpp | 8 +- src/dihedral.cpp | 10 +-- src/fix.cpp | 12 +-- src/improper.cpp | 10 +-- src/kspace.cpp | 8 +- src/min.cpp | 8 +- src/pair_hybrid.cpp | 16 ++-- 21 files changed, 108 insertions(+), 106 deletions(-) diff --git a/src/KOKKOS/pair_hybrid_kokkos.cpp b/src/KOKKOS/pair_hybrid_kokkos.cpp index d4888883b0..0d28e4a15d 100644 --- a/src/KOKKOS/pair_hybrid_kokkos.cpp +++ b/src/KOKKOS/pair_hybrid_kokkos.cpp @@ -64,23 +64,23 @@ void PairHybridKokkos::compute(int eflag, int vflag) int i,j,m,n; // if no_virial_fdotr_compute is set and global component of - // incoming vflag = 2, then - // reset vflag as if global component were 1 + // incoming vflag = VIRIAL_FDOTR, then + // reset vflag as if global component were VIRIAL_PAIR // necessary since one or more sub-styles cannot compute virial as F dot r int neighflag = lmp->kokkos->neighflag; if (neighflag == FULL) no_virial_fdotr_compute = 1; - if (no_virial_fdotr_compute && vflag % 4 == 2) vflag = 1 + vflag/4 * 4; + if (no_virial_fdotr_compute && vflag & VIRIAL_FDOTR) vflag = VIRIAL_PAIR | (vflag & ~VIRIAL_FDOTR); ev_init(eflag,vflag); - // check if global component of incoming vflag = 2 - // if so, reset vflag passed to substyle as if it were 0 + // check if global component of incoming vflag = VIRIAL_FDOTR + // if so, reset vflag passed to substyle as if it were VIRIAL_NONE // necessary so substyle will not invoke virial_fdotr_compute() int vflag_substyle; - if (vflag % 4 == 2) vflag_substyle = vflag/4 * 4; + if (vflag & VIRIAL_FDOTR) vflag_substyle = VIRIAL_NONE | (vflag & ~VIRIAL_FDOTR); else vflag_substyle = vflag; double *saved_special = save_special(); diff --git a/src/KOKKOS/pair_reaxc_kokkos.cpp b/src/KOKKOS/pair_reaxc_kokkos.cpp index 12d4c3924a..b281897b0d 100644 --- a/src/KOKKOS/pair_reaxc_kokkos.cpp +++ b/src/KOKKOS/pair_reaxc_kokkos.cpp @@ -3640,12 +3640,12 @@ void PairReaxCKokkos::ev_setup(int eflag, int vflag, int) evflag = 1; eflag_either = eflag; - eflag_global = eflag % 2; - eflag_atom = eflag / 2; + eflag_global = eflag & ENERGY_GLOBAL; + eflag_atom = eflag & ENERGY_ATOM; vflag_either = vflag; - vflag_global = vflag % 4; - vflag_atom = vflag / 4; + vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); + vflag_atom = vflag / 4; // TODO // reallocate per-atom arrays if necessary diff --git a/src/USER-INTEL/intel_preprocess.h b/src/USER-INTEL/intel_preprocess.h index 3e547b58a0..3c285871cf 100644 --- a/src/USER-INTEL/intel_preprocess.h +++ b/src/USER-INTEL/intel_preprocess.h @@ -502,7 +502,7 @@ enum {TIME_PACK, TIME_HOST_NEIGHBOR, TIME_HOST_PAIR, TIME_OFFLOAD_NEIGHBOR, acc_t *f_scalar = &f_start[0].x; \ int f_stride4 = f_stride * 4; \ int t; \ - if (vflag == 2) t = 4; else t = 1; \ + if (vflag == VIRIAL_FDOTR) t = 4; else t = 1; \ acc_t *f_scalar2 = f_scalar + f_stride4 * t; \ for ( ; t < nthreads; t++) { \ _use_simd_pragma("vector aligned") \ @@ -512,7 +512,7 @@ enum {TIME_PACK, TIME_HOST_NEIGHBOR, TIME_HOST_PAIR, TIME_OFFLOAD_NEIGHBOR, f_scalar2 += f_stride4; \ } \ \ - if (vflag == 2) { \ + if (vflag == VIRIAL_FDOTR) { \ int nt_min = MIN(4,nthreads); \ IP_PRE_fdotr_acc_force_l5(iifrom, iito, minlocal, nt_min, f_start, \ f_stride, pos, ov0, ov1, ov2, ov3, ov4, \ diff --git a/src/USER-INTEL/pair_buck_coul_cut_intel.cpp b/src/USER-INTEL/pair_buck_coul_cut_intel.cpp index 80993f212e..3da131684c 100644 --- a/src/USER-INTEL/pair_buck_coul_cut_intel.cpp +++ b/src/USER-INTEL/pair_buck_coul_cut_intel.cpp @@ -245,7 +245,7 @@ void PairBuckCoulCutIntel::eval(const int offload, const int vflag, fxtmp = fytmp = fztmp = (acc_t)0; if (EFLAG) fwtmp = sevdwl = secoul = (acc_t)0; if (NEWTON_PAIR == 0) - if (vflag==1) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; + if (vflag == VIRIAL_PAIR) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; #if defined(LMP_SIMD_COMPILER) #pragma vector aligned diff --git a/src/USER-INTEL/pair_buck_intel.cpp b/src/USER-INTEL/pair_buck_intel.cpp index 95b37796ba..afa9b448b5 100644 --- a/src/USER-INTEL/pair_buck_intel.cpp +++ b/src/USER-INTEL/pair_buck_intel.cpp @@ -227,7 +227,7 @@ void PairBuckIntel::eval(const int offload, const int vflag, fxtmp = fytmp = fztmp = (acc_t)0; if (EFLAG) fwtmp = sevdwl = (acc_t)0; if (NEWTON_PAIR == 0) - if (vflag==1) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; + if (vflag == VIRIAL_PAIR) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; #if defined(LMP_SIMD_COMPILER) #pragma vector aligned diff --git a/src/USER-INTEL/pair_dpd_intel.cpp b/src/USER-INTEL/pair_dpd_intel.cpp index 5adcb4c6ea..a0a71e4a37 100644 --- a/src/USER-INTEL/pair_dpd_intel.cpp +++ b/src/USER-INTEL/pair_dpd_intel.cpp @@ -265,7 +265,7 @@ void PairDPDIntel::eval(const int offload, const int vflag, fxtmp = fytmp = fztmp = (acc_t)0; if (EFLAG) fwtmp = sevdwl = (acc_t)0; if (NEWTON_PAIR == 0) - if (vflag==1) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; + if (vflag == VIRIAL_PAIR) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; if (rngi + jnum > rng_size) { #ifdef LMP_USE_MKL_RNG diff --git a/src/USER-INTEL/pair_eam_intel.cpp b/src/USER-INTEL/pair_eam_intel.cpp index 6ebd7abe3d..a25d588ecf 100644 --- a/src/USER-INTEL/pair_eam_intel.cpp +++ b/src/USER-INTEL/pair_eam_intel.cpp @@ -481,7 +481,7 @@ void PairEAMIntel::eval(const int offload, const int vflag, fxtmp = fytmp = fztmp = (acc_t)0; if (EFLAG) fwtmp = sevdwl = (acc_t)0; if (NEWTON_PAIR == 0) - if (vflag==1) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; + if (vflag == VIRIAL_PAIR) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; int ej = 0; #if defined(LMP_SIMD_COMPILER) diff --git a/src/USER-INTEL/pair_gayberne_intel.cpp b/src/USER-INTEL/pair_gayberne_intel.cpp index a9aa00340e..c34c6965de 100644 --- a/src/USER-INTEL/pair_gayberne_intel.cpp +++ b/src/USER-INTEL/pair_gayberne_intel.cpp @@ -399,7 +399,7 @@ void PairGayBerneIntel::eval(const int offload, const int vflag, if (EFLAG) fwtmp = sevdwl = (acc_t)0.0; if (NEWTON_PAIR == 0) - if (vflag==1) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0.0; + if (vflag == VIRIAL_PAIR) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0.0; bool multiple_forms = false; int packed_j = 0; diff --git a/src/USER-INTEL/pair_lj_charmm_coul_charmm_intel.cpp b/src/USER-INTEL/pair_lj_charmm_coul_charmm_intel.cpp index bf55a53981..8f4dba4a24 100644 --- a/src/USER-INTEL/pair_lj_charmm_coul_charmm_intel.cpp +++ b/src/USER-INTEL/pair_lj_charmm_coul_charmm_intel.cpp @@ -265,7 +265,7 @@ void PairLJCharmmCoulCharmmIntel::eval(const int offload, const int vflag, fxtmp = fytmp = fztmp = (acc_t)0; if (EFLAG) fwtmp = sevdwl = secoul = (acc_t)0; if (NEWTON_PAIR == 0) - if (vflag==1) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; + if (vflag == VIRIAL_PAIR) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; int ej = 0; #if defined(LMP_SIMD_COMPILER) diff --git a/src/USER-INTEL/pair_lj_charmm_coul_long_intel.cpp b/src/USER-INTEL/pair_lj_charmm_coul_long_intel.cpp index 2f375fd08c..ffed4853ba 100644 --- a/src/USER-INTEL/pair_lj_charmm_coul_long_intel.cpp +++ b/src/USER-INTEL/pair_lj_charmm_coul_long_intel.cpp @@ -282,7 +282,7 @@ void PairLJCharmmCoulLongIntel::eval(const int offload, const int vflag, fxtmp = fytmp = fztmp = (acc_t)0; if (EFLAG) fwtmp = sevdwl = secoul = (acc_t)0; if (NEWTON_PAIR == 0) - if (vflag==1) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; + if (vflag == VIRIAL_PAIR) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; int ej = 0; #if defined(LMP_SIMD_COMPILER) diff --git a/src/USER-INTEL/pair_lj_cut_coul_long_intel.cpp b/src/USER-INTEL/pair_lj_cut_coul_long_intel.cpp index fa3cfd7bc3..c1d85ad37f 100644 --- a/src/USER-INTEL/pair_lj_cut_coul_long_intel.cpp +++ b/src/USER-INTEL/pair_lj_cut_coul_long_intel.cpp @@ -275,7 +275,7 @@ void PairLJCutCoulLongIntel::eval(const int offload, const int vflag, fxtmp = fytmp = fztmp = (acc_t)0; if (EFLAG) fwtmp = sevdwl = secoul = (acc_t)0; if (NEWTON_PAIR == 0) - if (vflag==1) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; + if (vflag == VIRIAL_PAIR) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; int ej = 0; #if defined(LMP_SIMD_COMPILER) diff --git a/src/USER-INTEL/pair_lj_cut_intel.cpp b/src/USER-INTEL/pair_lj_cut_intel.cpp index 426abb7660..8697a4f548 100644 --- a/src/USER-INTEL/pair_lj_cut_intel.cpp +++ b/src/USER-INTEL/pair_lj_cut_intel.cpp @@ -233,7 +233,7 @@ void PairLJCutIntel::eval(const int offload, const int vflag, fxtmp = fytmp = fztmp = (acc_t)0; if (EFLAG) fwtmp = sevdwl = (acc_t)0; if (NEWTON_PAIR == 0) - if (vflag==1) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; + if (vflag == VIRIAL_PAIR) sv0 = sv1 = sv2 = sv3 = sv4 = sv5 = (acc_t)0; #if defined(LMP_SIMD_COMPILER) #pragma vector aligned nog2s diff --git a/src/USER-OMP/thr_omp.cpp b/src/USER-OMP/thr_omp.cpp index 0a8611707b..e590aedc87 100644 --- a/src/USER-OMP/thr_omp.cpp +++ b/src/USER-OMP/thr_omp.cpp @@ -70,20 +70,20 @@ void ThrOMP::ev_setup_thr(int eflag, int vflag, int nall, double *eatom, if (tid == 0) thr_error = 0; if (thr_style & THR_PAIR) { - if (eflag & 2) { + if (eflag & ENERGY_ATOM) { thr->eatom_pair = eatom + tid*nall; if (nall > 0) memset(&(thr->eatom_pair[0]),0,nall*sizeof(double)); } // per-atom virial and per-atom centroid virial are the same for two-body // many-body pair styles not yet implemented - if (vflag & 12) { + if (vflag & (VIRIAL_ATOM | VIRIAL_CENTROID)) { thr->vatom_pair = vatom + tid*nall; if (nall > 0) memset(&(thr->vatom_pair[0][0]),0,nall*6*sizeof(double)); } // check cvatom_pair, because can't access centroidstressflag - if ((vflag & 8) && cvatom) { + if ((vflag & VIRIAL_CENTROID) && cvatom) { thr->cvatom_pair = cvatom + tid*nall; if (nall > 0) memset(&(thr->cvatom_pair[0][0]),0,nall*9*sizeof(double)); @@ -94,13 +94,13 @@ void ThrOMP::ev_setup_thr(int eflag, int vflag, int nall, double *eatom, } if (thr_style & THR_BOND) { - if (eflag & 2) { + if (eflag & ENERGY_ATOM) { thr->eatom_bond = eatom + tid*nall; if (nall > 0) memset(&(thr->eatom_bond[0]),0,nall*sizeof(double)); } // per-atom virial and per-atom centroid virial are the same for bonds - if (vflag & 12) { + if (vflag & (VIRIAL_ATOM | VIRIAL_CENTROID)) { thr->vatom_bond = vatom + tid*nall; if (nall > 0) memset(&(thr->vatom_bond[0][0]),0,nall*6*sizeof(double)); @@ -108,17 +108,17 @@ void ThrOMP::ev_setup_thr(int eflag, int vflag, int nall, double *eatom, } if (thr_style & THR_ANGLE) { - if (eflag & 2) { + if (eflag & ENERGY_ATOM) { thr->eatom_angle = eatom + tid*nall; if (nall > 0) memset(&(thr->eatom_angle[0]),0,nall*sizeof(double)); } - if (vflag & 4) { + if (vflag & VIRIAL_ATOM) { thr->vatom_angle = vatom + tid*nall; if (nall > 0) memset(&(thr->vatom_angle[0][0]),0,nall*6*sizeof(double)); } - if (vflag & 8) { + if (vflag & VIRIAL_CENTROID) { thr->cvatom_angle = cvatom + tid*nall; if (nall > 0) memset(&(thr->cvatom_angle[0][0]),0,nall*9*sizeof(double)); @@ -126,17 +126,17 @@ void ThrOMP::ev_setup_thr(int eflag, int vflag, int nall, double *eatom, } if (thr_style & THR_DIHEDRAL) { - if (eflag & 2) { + if (eflag & ENERGY_ATOM) { thr->eatom_dihed = eatom + tid*nall; if (nall > 0) memset(&(thr->eatom_dihed[0]),0,nall*sizeof(double)); } - if (vflag & 4) { + if (vflag & VIRIAL_ATOM) { thr->vatom_dihed = vatom + tid*nall; if (nall > 0) memset(&(thr->vatom_dihed[0][0]),0,nall*6*sizeof(double)); } - if (vflag & 8) { + if (vflag & VIRIAL_CENTROID) { thr->cvatom_dihed = cvatom + tid*nall; if (nall > 0) memset(&(thr->cvatom_dihed[0][0]),0,nall*9*sizeof(double)); @@ -144,17 +144,17 @@ void ThrOMP::ev_setup_thr(int eflag, int vflag, int nall, double *eatom, } if (thr_style & THR_IMPROPER) { - if (eflag & 2) { + if (eflag & ENERGY_ATOM) { thr->eatom_imprp = eatom + tid*nall; if (nall > 0) memset(&(thr->eatom_imprp[0]),0,nall*sizeof(double)); } - if (vflag & 4) { + if (vflag & VIRIAL_ATOM) { thr->vatom_imprp = vatom + tid*nall; if (nall > 0) memset(&(thr->vatom_imprp[0][0]),0,nall*6*sizeof(double)); } - if (vflag & 8) { + if (vflag & VIRIAL_CENTROID) { thr->cvatom_imprp = cvatom + tid*nall; if (nall > 0) memset(&(thr->cvatom_imprp[0][0]),0,nall*9*sizeof(double)); @@ -222,29 +222,29 @@ void ThrOMP::reduce_thr(void *style, const int eflag, const int vflag, #pragma omp critical #endif { - if (eflag & 1) { + if (eflag & ENERGY_GLOBAL) { pair->eng_vdwl += thr->eng_vdwl; pair->eng_coul += thr->eng_coul; thr->eng_vdwl = 0.0; thr->eng_coul = 0.0; } - if (vflag & 3) + if (vflag & (VIRIAL_PAIR | VIRIAL_FDOTR)) for (int i=0; i < 6; ++i) { pair->virial[i] += thr->virial_pair[i]; thr->virial_pair[i] = 0.0; } } - if (eflag & 2) { + if (eflag & ENERGY_ATOM) { data_reduce_thr(&(pair->eatom[0]), nall, nthreads, 1, tid); } // per-atom virial and per-atom centroid virial are the same for two-body // many-body pair styles not yet implemented - if (vflag & 12) { + if (vflag & (VIRIAL_ATOM | VIRIAL_CENTROID)) { data_reduce_thr(&(pair->vatom[0][0]), nall, nthreads, 6, tid); } // check cvatom_pair, because can't access centroidstressflag - if ((vflag & 8) && thr->cvatom_pair) { + if ((vflag & VIRIAL_CENTROID) && thr->cvatom_pair) { data_reduce_thr(&(pair->cvatom[0][0]), nall, nthreads, 9, tid); } } @@ -259,12 +259,12 @@ void ThrOMP::reduce_thr(void *style, const int eflag, const int vflag, #pragma omp critical #endif { - if (eflag & 1) { + if (eflag & ENERGY_GLOBAL) { bond->energy += thr->eng_bond; thr->eng_bond = 0.0; } - if (vflag & 3) { + if (vflag & (VIRIAL_PAIR | VIRIAL_FDOTR)) { for (int i=0; i < 6; ++i) { bond->virial[i] += thr->virial_bond[i]; thr->virial_bond[i] = 0.0; @@ -272,11 +272,11 @@ void ThrOMP::reduce_thr(void *style, const int eflag, const int vflag, } } - if (eflag & 2) { + if (eflag & ENERGY_ATOM) { data_reduce_thr(&(bond->eatom[0]), nall, nthreads, 1, tid); } // per-atom virial and per-atom centroid virial are the same for bonds - if (vflag & 12) { + if (vflag & (VIRIAL_ATOM | VIRIAL_CENTROID)) { data_reduce_thr(&(bond->vatom[0][0]), nall, nthreads, 6, tid); } @@ -291,12 +291,12 @@ void ThrOMP::reduce_thr(void *style, const int eflag, const int vflag, #pragma omp critical #endif { - if (eflag & 1) { + if (eflag & ENERGY_GLOBAL) { angle->energy += thr->eng_angle; thr->eng_angle = 0.0; } - if (vflag & 3) { + if (vflag & (VIRIAL_PAIR | VIRIAL_FDOTR)) { for (int i=0; i < 6; ++i) { angle->virial[i] += thr->virial_angle[i]; thr->virial_angle[i] = 0.0; @@ -304,13 +304,13 @@ void ThrOMP::reduce_thr(void *style, const int eflag, const int vflag, } } - if (eflag & 2) { + if (eflag & ENERGY_ATOM) { data_reduce_thr(&(angle->eatom[0]), nall, nthreads, 1, tid); } - if (vflag & 4) { + if (vflag & VIRIAL_ATOM) { data_reduce_thr(&(angle->vatom[0][0]), nall, nthreads, 6, tid); } - if (vflag & 8) { + if (vflag & VIRIAL_CENTROID) { data_reduce_thr(&(angle->cvatom[0][0]), nall, nthreads, 9, tid); } @@ -325,12 +325,12 @@ void ThrOMP::reduce_thr(void *style, const int eflag, const int vflag, #pragma omp critical #endif { - if (eflag & 1) { + if (eflag & ENERGY_GLOBAL) { dihedral->energy += thr->eng_dihed; thr->eng_dihed = 0.0; } - if (vflag & 3) { + if (vflag & (VIRIAL_PAIR | VIRIAL_FDOTR)) { for (int i=0; i < 6; ++i) { dihedral->virial[i] += thr->virial_dihed[i]; thr->virial_dihed[i] = 0.0; @@ -338,13 +338,13 @@ void ThrOMP::reduce_thr(void *style, const int eflag, const int vflag, } } - if (eflag & 2) { + if (eflag & ENERGY_ATOM) { data_reduce_thr(&(dihedral->eatom[0]), nall, nthreads, 1, tid); } - if (vflag & 4) { + if (vflag & VIRIAL_ATOM) { data_reduce_thr(&(dihedral->vatom[0][0]), nall, nthreads, 6, tid); } - if (vflag & 8) { + if (vflag & VIRIAL_CENTROID) { data_reduce_thr(&(dihedral->cvatom[0][0]), nall, nthreads, 9, tid); } @@ -360,7 +360,7 @@ void ThrOMP::reduce_thr(void *style, const int eflag, const int vflag, #pragma omp critical #endif { - if (eflag & 1) { + if (eflag & ENERGY_GLOBAL) { dihedral->energy += thr->eng_dihed; pair->eng_vdwl += thr->eng_vdwl; pair->eng_coul += thr->eng_coul; @@ -369,7 +369,7 @@ void ThrOMP::reduce_thr(void *style, const int eflag, const int vflag, thr->eng_coul = 0.0; } - if (vflag & 3) { + if (vflag & (VIRIAL_PAIR | VIRIAL_FDOTR)) { for (int i=0; i < 6; ++i) { dihedral->virial[i] += thr->virial_dihed[i]; pair->virial[i] += thr->virial_pair[i]; @@ -379,23 +379,23 @@ void ThrOMP::reduce_thr(void *style, const int eflag, const int vflag, } } - if (eflag & 2) { + if (eflag & ENERGY_ATOM) { data_reduce_thr(&(dihedral->eatom[0]), nall, nthreads, 1, tid); data_reduce_thr(&(pair->eatom[0]), nall, nthreads, 1, tid); } - if (vflag & 4) { + if (vflag & VIRIAL_ATOM) { data_reduce_thr(&(dihedral->vatom[0][0]), nall, nthreads, 6, tid); } - if (vflag & 8) { + if (vflag & VIRIAL_CENTROID) { data_reduce_thr(&(dihedral->cvatom[0][0]), nall, nthreads, 9, tid); } // per-atom virial and per-atom centroid virial are the same for two-body // many-body pair styles not yet implemented - if (vflag & 12) { + if (vflag & (VIRIAL_ATOM | VIRIAL_CENTROID)) { data_reduce_thr(&(pair->vatom[0][0]), nall, nthreads, 6, tid); } // check cvatom_pair, because can't access centroidstressflag - if ((vflag & 8) && thr->cvatom_pair) { + if ((vflag & VIRIAL_CENTROID) && thr->cvatom_pair) { data_reduce_thr(&(pair->cvatom[0][0]), nall, nthreads, 9, tid); } } @@ -409,12 +409,12 @@ void ThrOMP::reduce_thr(void *style, const int eflag, const int vflag, #pragma omp critical #endif { - if (eflag & 1) { + if (eflag & ENERGY_GLOBAL) { improper->energy += thr->eng_imprp; thr->eng_imprp = 0.0; } - if (vflag & 3) { + if (vflag & (VIRIAL_PAIR | VIRIAL_FDOTR)) { for (int i=0; i < 6; ++i) { improper->virial[i] += thr->virial_imprp[i]; thr->virial_imprp[i] = 0.0; @@ -422,13 +422,13 @@ void ThrOMP::reduce_thr(void *style, const int eflag, const int vflag, } } - if (eflag & 2) { + if (eflag & ENERGY_ATOM) { data_reduce_thr(&(improper->eatom[0]), nall, nthreads, 1, tid); } - if (vflag & 4) { + if (vflag & VIRIAL_ATOM) { data_reduce_thr(&(improper->vatom[0][0]), nall, nthreads, 6, tid); } - if (vflag & 8) { + if (vflag & VIRIAL_CENTROID) { data_reduce_thr(&(improper->cvatom[0][0]), nall, nthreads, 9, tid); } diff --git a/src/angle.cpp b/src/angle.cpp index 75925b7b94..83f5431683 100644 --- a/src/angle.cpp +++ b/src/angle.cpp @@ -94,12 +94,12 @@ void Angle::ev_setup(int eflag, int vflag, int alloc) evflag = 1; eflag_either = eflag; - eflag_global = eflag % 2; - eflag_atom = eflag / 2; + eflag_global = eflag & ENERGY_GLOBAL; + eflag_atom = eflag & ENERGY_ATOM; - vflag_global = vflag % 4; - vflag_atom = vflag & 4; - cvflag_atom = vflag & 8; + vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); + vflag_atom = vflag & VIRIAL_ATOM; + cvflag_atom = vflag & VIRIAL_CENTROID; vflag_either = vflag_global || vflag_atom; // reallocate per-atom arrays if necessary diff --git a/src/bond.cpp b/src/bond.cpp index f29d9c8b5a..ddd1ae9b37 100644 --- a/src/bond.cpp +++ b/src/bond.cpp @@ -98,13 +98,13 @@ void Bond::ev_setup(int eflag, int vflag, int alloc) evflag = 1; eflag_either = eflag; - eflag_global = eflag % 2; - eflag_atom = eflag / 2; + eflag_global = eflag & ENERGY_GLOBAL; + eflag_atom = eflag & ENERGY_ATOM; vflag_either = vflag; - vflag_global = vflag % 4; + vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); // per-atom virial and per-atom centroid virial are the same for bonds - vflag_atom = vflag / 4; + vflag_atom = vflag & (VIRIAL_ATOM | VIRIAL_CENTROID); // reallocate per-atom arrays if necessary diff --git a/src/dihedral.cpp b/src/dihedral.cpp index f7e9f9fb4a..1d77598e38 100644 --- a/src/dihedral.cpp +++ b/src/dihedral.cpp @@ -93,12 +93,12 @@ void Dihedral::ev_setup(int eflag, int vflag, int alloc) evflag = 1; eflag_either = eflag; - eflag_global = eflag % 2; - eflag_atom = eflag / 2; + eflag_global = eflag & ENERGY_GLOBAL; + eflag_atom = eflag & ENERGY_ATOM; - vflag_global = vflag % 4; - vflag_atom = vflag & 4; - cvflag_atom = vflag & 8; + vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); + vflag_atom = vflag & VIRIAL_ATOM; + cvflag_atom = vflag & VIRIAL_CENTROID; vflag_either = vflag_global || vflag_atom; // reallocate per-atom arrays if necessary diff --git a/src/fix.cpp b/src/fix.cpp index 16628e5374..3814cd4cb8 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -189,12 +189,12 @@ void Fix::ev_setup(int eflag, int vflag) evflag = 1; eflag_either = eflag; - eflag_global = eflag % 2; - eflag_atom = eflag / 2; + eflag_global = eflag % 2; // TODO + eflag_atom = eflag / 2; // TODO vflag_either = vflag; - vflag_global = vflag % 4; - vflag_atom = vflag / 4; + vflag_global = vflag % 4; // TODO + vflag_atom = vflag / 4; // TODO // reallocate per-atom arrays if necessary @@ -250,8 +250,8 @@ void Fix::v_setup(int vflag) evflag = 1; - vflag_global = vflag % 4; - vflag_atom = vflag / 4; + vflag_global = vflag % 4; // TODO + vflag_atom = vflag / 4; // TODO // reallocate per-atom array if necessary diff --git a/src/improper.cpp b/src/improper.cpp index f1accf25c7..f716f84969 100644 --- a/src/improper.cpp +++ b/src/improper.cpp @@ -91,12 +91,12 @@ void Improper::ev_setup(int eflag, int vflag, int alloc) evflag = 1; eflag_either = eflag; - eflag_global = eflag % 2; - eflag_atom = eflag / 2; + eflag_global = eflag & ENERGY_GLOBAL; + eflag_atom = eflag & ENERGY_ATOM; - vflag_global = vflag % 4; - vflag_atom = vflag & 4; - cvflag_atom = vflag & 8; + vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); + vflag_atom = vflag & VIRIAL_ATOM; + cvflag_atom = vflag & VIRIAL_CENTROID; vflag_either = vflag_global || vflag_atom; // reallocate per-atom arrays if necessary diff --git a/src/kspace.cpp b/src/kspace.cpp index 9ca35b9e72..a373c65a9d 100644 --- a/src/kspace.cpp +++ b/src/kspace.cpp @@ -232,12 +232,12 @@ void KSpace::ev_setup(int eflag, int vflag, int alloc) evflag = 1; eflag_either = eflag; - eflag_global = eflag % 2; - eflag_atom = eflag / 2; + eflag_global = eflag & ENERGY_GLOBAL; + eflag_atom = eflag & ENERGY_ATOM; vflag_either = vflag; - vflag_global = vflag % 4; - vflag_atom = vflag / 4; + vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); + vflag_atom = vflag / 4; // TODO if (eflag_atom || vflag_atom) evflag_atom = 1; else evflag_atom = 0; diff --git a/src/min.cpp b/src/min.cpp index 1db5c8b239..b62bceba7a 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -798,6 +798,8 @@ void Min::ev_setup() } /* ---------------------------------------------------------------------- + TODO: comment + set eflag,vflag for current iteration invoke matchstep() on all timestep-dependent computes to clear their arrays eflag/vflag based on computes that need info on this ntimestep @@ -829,7 +831,7 @@ void Min::ev_set(bigint ntimestep) int eflag_atom = 0; for (i = 0; i < nelist_atom; i++) if (elist_atom[i]->matchstep(ntimestep)) flag = 1; - if (flag) eflag_atom = 2; + if (flag) eflag_atom = ENERGY_ATOM; if (eflag_global) update->eflag_global = update->ntimestep; if (eflag_atom) update->eflag_atom = update->ntimestep; @@ -845,13 +847,13 @@ void Min::ev_set(bigint ntimestep) int vflag_atom = 0; for (i = 0; i < nvlist_atom; i++) if (vlist_atom[i]->matchstep(ntimestep)) flag = 1; - if (flag) vflag_atom = 4; + if (flag) vflag_atom = VIRIAL_ATOM; flag = 0; int cvflag_atom = 0; for (i = 0; i < ncvlist_atom; i++) if (cvlist_atom[i]->matchstep(ntimestep)) flag = 1; - if (flag) cvflag_atom = 8; + if (flag) cvflag_atom = VIRIAL_CENTROID; if (vflag_global) update->vflag_global = update->ntimestep; if (vflag_atom || cvflag_atom) update->vflag_atom = update->ntimestep; diff --git a/src/pair_hybrid.cpp b/src/pair_hybrid.cpp index 1c3ef45307..8f58d14e20 100644 --- a/src/pair_hybrid.cpp +++ b/src/pair_hybrid.cpp @@ -82,10 +82,10 @@ PairHybrid::~PairHybrid() /* ---------------------------------------------------------------------- call each sub-style's compute() or compute_outer() function accumulate sub-style global/peratom energy/virial in hybrid - for global vflag = 1: + for global vflag = VIRIAL_PAIR: each sub-style computes own virial[6] sum sub-style virial[6] to hybrid's virial[6] - for global vflag = 2: + for global vflag = VIRIAL_FDOTR: call sub-style with adjusted vflag to prevent it calling virial_fdotr_compute() hybrid calls virial_fdotr_compute() on final accumulated f @@ -96,20 +96,20 @@ void PairHybrid::compute(int eflag, int vflag) int i,j,m,n; // if no_virial_fdotr_compute is set and global component of - // incoming vflag = 2, then - // reset vflag as if global component were 1 + // incoming vflag = VIRIAL_FDOTR, then + // reset vflag as if global component were VIRIAL_PAIR // necessary since one or more sub-styles cannot compute virial as F dot r - if (no_virial_fdotr_compute && vflag % 4 == 2) vflag = 1 + vflag/4 * 4; + if (no_virial_fdotr_compute && (vflag & VIRIAL_FDOTR)) vflag = VIRIAL_PAIR | (vflag & ~VIRIAL_FDOTR); ev_init(eflag,vflag); - // check if global component of incoming vflag = 2 - // if so, reset vflag passed to substyle as if it were 0 + // check if global component of incoming vflag = VIRIAL_FDOTR + // if so, reset vflag passed to substyle as if it were VIRIAL_NONE // necessary so substyle will not invoke virial_fdotr_compute() int vflag_substyle; - if (vflag % 4 == 2) vflag_substyle = vflag/4 * 4; + if (vflag & VIRIAL_FDOTR) vflag_substyle = vflag & ~VIRIAL_FDOTR; else vflag_substyle = vflag; double *saved_special = save_special(); From f6a1352be352c77c8bab294c63e65ff106946e5f Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 16 Nov 2020 16:23:21 -0500 Subject: [PATCH 45/67] Update remaining lines --- src/KOKKOS/pair_reaxc_kokkos.cpp | 8 ++++---- src/fix.cpp | 15 ++++++++------- src/kspace.cpp | 4 ++-- src/min.cpp | 25 ++++++++++--------------- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/KOKKOS/pair_reaxc_kokkos.cpp b/src/KOKKOS/pair_reaxc_kokkos.cpp index b281897b0d..54ab4aa128 100644 --- a/src/KOKKOS/pair_reaxc_kokkos.cpp +++ b/src/KOKKOS/pair_reaxc_kokkos.cpp @@ -3629,7 +3629,7 @@ void PairReaxCKokkos::v_tally3_atom(EV_FLOAT_REAX &ev, const int &i, /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for values of eflag and vflag ------------------------------------------------------------------------- */ template @@ -3645,7 +3645,7 @@ void PairReaxCKokkos::ev_setup(int eflag, int vflag, int) vflag_either = vflag; vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); - vflag_atom = vflag / 4; // TODO + vflag_atom = vflag & (VIRIAL_ATOM | VIRIAL_CENTROID); // reallocate per-atom arrays if necessary @@ -3673,11 +3673,11 @@ void PairReaxCKokkos::ev_setup(int eflag, int vflag, int) Kokkos::parallel_for(Kokkos::RangePolicy(0,maxvatom),*this); } - // if vflag_global = 2 and pair::compute() calls virial_fdotr_compute() + // if vflag_global = VIRIAL_FDOTR and pair::compute() calls virial_fdotr_compute() // compute global virial via (F dot r) instead of via pairwise summation // unset other flags as appropriate - if (vflag_global == 2 && no_virial_fdotr_compute == 0) { + if (vflag_global == VIRIAL_FDOTR && no_virial_fdotr_compute == 0) { vflag_fdotr = 1; vflag_global = 0; if (vflag_atom == 0) vflag_either = 0; diff --git a/src/fix.cpp b/src/fix.cpp index 3814cd4cb8..aabbc58473 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -16,6 +16,7 @@ #include "atom.h" #include "atom_masks.h" #include "error.h" +#include "force.h" #include "group.h" #include "memory.h" @@ -189,12 +190,12 @@ void Fix::ev_setup(int eflag, int vflag) evflag = 1; eflag_either = eflag; - eflag_global = eflag % 2; // TODO - eflag_atom = eflag / 2; // TODO + eflag_global = eflag & ENERGY_GLOBAL; + eflag_atom = eflag & ENERGY_ATOM; vflag_either = vflag; - vflag_global = vflag % 4; // TODO - vflag_atom = vflag / 4; // TODO + vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); + vflag_atom = vflag & (VIRIAL_ATOM | VIRIAL_CENTROID); // reallocate per-atom arrays if necessary @@ -234,7 +235,7 @@ void Fix::ev_setup(int eflag, int vflag) /* ---------------------------------------------------------------------- if thermo_virial is on: setup for virial computation - see integrate::ev_set() for values of vflag (0-6) + see integrate::ev_set() for values of vflag fixes call this if use v_tally() else: set evflag=0 ------------------------------------------------------------------------- */ @@ -250,8 +251,8 @@ void Fix::v_setup(int vflag) evflag = 1; - vflag_global = vflag % 4; // TODO - vflag_atom = vflag / 4; // TODO + vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); + vflag_atom = vflag & (VIRIAL_ATOM | VIRIAL_CENTROID); // reallocate per-atom array if necessary diff --git a/src/kspace.cpp b/src/kspace.cpp index a373c65a9d..ef7970e2ec 100644 --- a/src/kspace.cpp +++ b/src/kspace.cpp @@ -221,7 +221,7 @@ void KSpace::pair_check() eflag_atom = 1 if ENERGY_ATOM bit of eflag set eflag_either = 1 if eflag_global or eflag_atom is set vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_ATOM bit of vflag set + vflag_atom = 1 if VIRIAL_ATOM or VIRIAL_CENTROID bit of vflag set vflag_either = 1 if vflag_global or vflag_atom is set ------------------------------------------------------------------------- */ @@ -237,7 +237,7 @@ void KSpace::ev_setup(int eflag, int vflag, int alloc) vflag_either = vflag; vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); - vflag_atom = vflag / 4; // TODO + vflag_atom = vflag & (VIRIAL_ATOM | VIRIAL_CENTROID); if (eflag_atom || vflag_atom) evflag_atom = 1; else evflag_atom = 0; diff --git a/src/min.cpp b/src/min.cpp index b62bceba7a..ca0d508e95 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -798,25 +798,20 @@ void Min::ev_setup() } /* ---------------------------------------------------------------------- - TODO: comment - set eflag,vflag for current iteration invoke matchstep() on all timestep-dependent computes to clear their arrays eflag/vflag based on computes that need info on this ntimestep always set eflag_global = 1, since need energy every iteration - eflag = 0 = no energy computation - eflag = 1 = global energy only - eflag = 2 = per-atom energy only - eflag = 3 = both global and per-atom energy - vflag = 0 = no virial computation (pressure) - vflag = 1 = global virial with pair portion via sum of pairwise interactions - vflag = 2 = global virial with pair portion via F dot r including ghosts - vflag = 4 = per-atom virial only - vflag = 5 or 6 = both global and per-atom virial - vflag = 8 = per-atom centroid virial only - vflag = 9 or 10 = both global and per-atom centroid virial - vflag = 12 = both per-atom virial and per-atom centroid virial - vflag = 13 or 15 = global, per-atom virial and per-atom centroid virial + eflag: set any or no bits + ENERGY_GLOBAL bit for global energy + ENERGY_ATOM bit for per-atom energy + vflag: set any or no bits, but GLOBAL/FDOTR bit cannot both be set + VIRIAL_PAIR bit for global virial as sum of pairwise terms + VIRIAL_FDOTR bit for global virial via F dot r + VIRIAL_ATOM bit for per-atom virial + VIRIAL_CENTROID bit for per-atom centroid virial + all force components (pair,bond,angle,...,kspace) use eflag/vflag + in their ev_setup() method to set local energy/virial flags ------------------------------------------------------------------------- */ void Min::ev_set(bigint ntimestep) From 35035189e628a7e6ebc71ce73b5852fe6781663c Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 16 Nov 2020 16:36:06 -0500 Subject: [PATCH 46/67] Replace a few more 2s with VIRIAL_FDOTR --- src/KOKKOS/dihedral_charmm_kokkos.cpp | 2 +- src/MOLECULE/bond_quartic.cpp | 2 +- src/MOLECULE/dihedral_charmm.cpp | 2 +- src/MOLECULE/dihedral_charmmfsw.cpp | 2 +- src/USER-INTEL/dihedral_charmm_intel.cpp | 2 +- src/USER-MOFFF/angle_cosine_buck6d.cpp | 2 +- src/USER-OMP/bond_quartic_omp.cpp | 2 +- src/USER-OMP/dihedral_charmm_omp.cpp | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/KOKKOS/dihedral_charmm_kokkos.cpp b/src/KOKKOS/dihedral_charmm_kokkos.cpp index 86539bc090..d1e8735c8a 100644 --- a/src/KOKKOS/dihedral_charmm_kokkos.cpp +++ b/src/KOKKOS/dihedral_charmm_kokkos.cpp @@ -76,7 +76,7 @@ void DihedralCharmmKokkos::compute(int eflag_in, int vflag_in) // insure pair->ev_tally() will use 1-4 virial contribution - if (weightflag && vflag_global == 2) + if (weightflag && vflag_global == VIRIAL_FDOTR) force->pair->vflag_either = force->pair->vflag_global = 1; // reallocate per-atom arrays if necessary diff --git a/src/MOLECULE/bond_quartic.cpp b/src/MOLECULE/bond_quartic.cpp index 20269a0966..c7151c3aca 100644 --- a/src/MOLECULE/bond_quartic.cpp +++ b/src/MOLECULE/bond_quartic.cpp @@ -63,7 +63,7 @@ void BondQuartic::compute(int eflag, int vflag) // insure pair->ev_tally() will use 1-4 virial contribution - if (vflag_global == 2) + if (vflag_global == VIRIAL_FDOTR) force->pair->vflag_either = force->pair->vflag_global = 1; double **cutsq = force->pair->cutsq; diff --git a/src/MOLECULE/dihedral_charmm.cpp b/src/MOLECULE/dihedral_charmm.cpp index c3d94976ac..cc60dbec2b 100644 --- a/src/MOLECULE/dihedral_charmm.cpp +++ b/src/MOLECULE/dihedral_charmm.cpp @@ -79,7 +79,7 @@ void DihedralCharmm::compute(int eflag, int vflag) // insure pair->ev_tally() will use 1-4 virial contribution - if (weightflag && vflag_global == 2) + if (weightflag && vflag_global == VIRIAL_FDOTR) force->pair->vflag_either = force->pair->vflag_global = 1; double **x = atom->x; diff --git a/src/MOLECULE/dihedral_charmmfsw.cpp b/src/MOLECULE/dihedral_charmmfsw.cpp index 1f86014933..1164e93f18 100644 --- a/src/MOLECULE/dihedral_charmmfsw.cpp +++ b/src/MOLECULE/dihedral_charmmfsw.cpp @@ -82,7 +82,7 @@ void DihedralCharmmfsw::compute(int eflag, int vflag) // insure pair->ev_tally() will use 1-4 virial contribution - if (weightflag && vflag_global == 2) + if (weightflag && vflag_global == VIRIAL_FDOTR) force->pair->vflag_either = force->pair->vflag_global = 1; double **x = atom->x; diff --git a/src/USER-INTEL/dihedral_charmm_intel.cpp b/src/USER-INTEL/dihedral_charmm_intel.cpp index fb9e8781b1..d84658c797 100644 --- a/src/USER-INTEL/dihedral_charmm_intel.cpp +++ b/src/USER-INTEL/dihedral_charmm_intel.cpp @@ -91,7 +91,7 @@ void DihedralCharmmIntel::compute(int eflag, int vflag, // insure pair->ev_tally() will use 1-4 virial contribution - if (weightflag && vflag_global == 2) + if (weightflag && vflag_global == VIRIAL_FDOTR) force->pair->vflag_either = force->pair->vflag_global = 1; if (evflag) { diff --git a/src/USER-MOFFF/angle_cosine_buck6d.cpp b/src/USER-MOFFF/angle_cosine_buck6d.cpp index 3ab7327325..277ee8830b 100644 --- a/src/USER-MOFFF/angle_cosine_buck6d.cpp +++ b/src/USER-MOFFF/angle_cosine_buck6d.cpp @@ -72,7 +72,7 @@ void AngleCosineBuck6d::compute(int eflag, int vflag) // insure pair->ev_tally() will use 1-3 virial contribution - if (vflag_global == 2) + if (vflag_global == VIRIAL_FDOTR) force->pair->vflag_either = force->pair->vflag_global = 1; double **x = atom->x; diff --git a/src/USER-OMP/bond_quartic_omp.cpp b/src/USER-OMP/bond_quartic_omp.cpp index 73fa0614d8..1f39a7cee1 100644 --- a/src/USER-OMP/bond_quartic_omp.cpp +++ b/src/USER-OMP/bond_quartic_omp.cpp @@ -45,7 +45,7 @@ void BondQuarticOMP::compute(int eflag, int vflag) // insure pair->ev_tally() will use 1-4 virial contribution - if (vflag_global == 2) + if (vflag_global == VIRIAL_FDOTR) force->pair->vflag_either = force->pair->vflag_global = 1; const int nall = atom->nlocal + atom->nghost; diff --git a/src/USER-OMP/dihedral_charmm_omp.cpp b/src/USER-OMP/dihedral_charmm_omp.cpp index 6b399be09d..c75378a8be 100644 --- a/src/USER-OMP/dihedral_charmm_omp.cpp +++ b/src/USER-OMP/dihedral_charmm_omp.cpp @@ -49,7 +49,7 @@ void DihedralCharmmOMP::compute(int eflag, int vflag) // insure pair->ev_tally() will use 1-4 virial contribution - if (weightflag && vflag_global == 2) + if (weightflag && vflag_global == VIRIAL_FDOTR) force->pair->vflag_either = force->pair->vflag_global = 1; const int nall = atom->nlocal + atom->nghost; From 0876684780298710850ad0a87cf84f14c95a6646 Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Wed, 18 Nov 2020 12:17:14 -0700 Subject: [PATCH 47/67] energy/virial flags with CENTROID enum --- doc/src/compute_stress_atom.rst | 236 ++++++++++++----------- src/GRANULAR/pair_gran_hooke_history.cpp | 2 +- src/GRANULAR/pair_granular.cpp | 1 + src/KOKKOS/angle_charmm_kokkos.cpp | 2 + src/KOKKOS/angle_class2_kokkos.cpp | 2 + src/KOKKOS/angle_cosine_kokkos.cpp | 2 + src/KOKKOS/angle_harmonic_kokkos.cpp | 2 + src/KOKKOS/dihedral_charmm_kokkos.cpp | 2 + src/KOKKOS/dihedral_class2_kokkos.cpp | 2 + src/KOKKOS/dihedral_harmonic_kokkos.cpp | 2 + src/KOKKOS/dihedral_opls_kokkos.cpp | 2 + src/KOKKOS/improper_class2_kokkos.cpp | 2 + src/KOKKOS/improper_harmonic_kokkos.cpp | 2 + src/KOKKOS/pair_reaxc_kokkos.cpp | 4 +- src/MANYBODY/pair_adp.cpp | 1 + src/MANYBODY/pair_airebo.cpp | 1 + src/MANYBODY/pair_atm.cpp | 1 + src/MANYBODY/pair_bop.cpp | 1 + src/MANYBODY/pair_comb.cpp | 1 + src/MANYBODY/pair_comb3.cpp | 2 + src/MANYBODY/pair_eim.cpp | 1 + src/MANYBODY/pair_gw.cpp | 1 + src/MANYBODY/pair_lcbop.cpp | 1 + src/MANYBODY/pair_nb3b_harmonic.cpp | 3 +- src/MANYBODY/pair_polymorphic.cpp | 2 + src/MANYBODY/pair_sw.cpp | 1 + src/MANYBODY/pair_tersoff.cpp | 1 + src/MANYBODY/pair_vashishta.cpp | 1 + src/MLIAP/pair_mliap.cpp | 2 +- src/SNAP/pair_snap.cpp | 1 + src/USER-MEAMC/pair_meamc.cpp | 4 +- src/USER-MESONT/pair_mesocnt.cpp | 5 +- src/USER-MISC/pair_agni.cpp | 1 + src/USER-MISC/pair_drip.cpp | 2 +- src/USER-MISC/pair_edip.cpp | 2 +- src/USER-MISC/pair_edip_multi.cpp | 1 + src/USER-MISC/pair_extep.cpp | 1 + src/USER-MISC/pair_meam_sw_spline.cpp | 1 + src/USER-MISC/pair_tersoff_table.cpp | 1 + src/USER-QUIP/pair_quip.cpp | 2 +- src/USER-REAXC/pair_reaxc.cpp | 2 +- src/angle.cpp | 27 ++- src/angle.h | 5 + src/bond.cpp | 16 +- src/compute_centroid_stress_atom.cpp | 57 ++++-- src/dihedral.cpp | 27 ++- src/dihedral.h | 5 + src/fix.cpp | 3 +- src/fix.h | 5 + src/improper.cpp | 15 +- src/improper.h | 5 + src/integrate.cpp | 2 +- src/kspace.cpp | 20 +- src/kspace.h | 5 + src/pair.cpp | 52 +++-- src/pair.h | 2 +- src/pair_beck.cpp | 5 +- src/pair_buck.cpp | 1 - src/pair_buck_coul_cut.cpp | 1 - src/pair_coul_cut.cpp | 4 +- src/pair_coul_dsf.cpp | 5 +- src/pair_coul_wolf.cpp | 1 - src/pair_hybrid.cpp | 36 ++-- src/pair_lj_cubic.cpp | 4 +- src/pair_lj_cut.cpp | 2 - src/pair_lj_cut_coul_cut.cpp | 1 - src/pair_lj_cut_coul_dsf.cpp | 1 - src/pair_lj_cut_coul_wolf.cpp | 1 - src/pair_lj_expand.cpp | 1 - src/pair_lj_gromacs_coul_gromacs.cpp | 2 - src/pair_lj_smooth.cpp | 1 - src/pair_lj_smooth_linear.cpp | 2 - src/pair_morse.cpp | 2 - src/pair_ufm.cpp | 2 - 74 files changed, 362 insertions(+), 262 deletions(-) diff --git a/doc/src/compute_stress_atom.rst b/doc/src/compute_stress_atom.rst index 16afd49548..9ebb51a3eb 100644 --- a/doc/src/compute_stress_atom.rst +++ b/doc/src/compute_stress_atom.rst @@ -33,32 +33,31 @@ Examples Description """"""""""" -Define a computation that computes per-atom stress -tensor for each atom in a group. In case of compute *stress/atom*, -the tensor for each atom is symmetric with 6 -components and is stored as a 6-element vector in the following order: -:math:`xx`, :math:`yy`, :math:`zz`, :math:`xy`, :math:`xz`, :math:`yz`. -In case of compute *centroid/stress/atom*, -the tensor for each atom is asymmetric with 9 components -and is stored as a 9-element vector in the following order: -:math:`xx`, :math:`yy`, :math:`zz`, :math:`xy`, :math:`xz`, :math:`yz`, -:math:`yx`, :math:`zx`, :math:`zy`. -See the :doc:`compute pressure ` command if you want the stress tensor +Define a computation that computes per-atom stress tensor for each +atom in a group. In case of compute *stress/atom*, the tensor for +each atom is symmetric with 6 components and is stored as a 6-element +vector in the following order: :math:`xx`, :math:`yy`, :math:`zz`, +:math:`xy`, :math:`xz`, :math:`yz`. In case of compute +*centroid/stress/atom*, the tensor for each atom is asymmetric with 9 +components and is stored as a 9-element vector in the following order: +:math:`xx`, :math:`yy`, :math:`zz`, :math:`xy`, :math:`xz`, +:math:`yz`, :math:`yx`, :math:`zx`, :math:`zy`. See the :doc:`compute +pressure ` command if you want the stress tensor (pressure) of the entire system. -The stress tensor for atom :math:`I` is given by the following formula, -where :math:`a` and :math:`b` take on values :math:`x`, :math:`y`, :math:`z` -to generate the components of the tensor: +The stress tensor for atom :math:`I` is given by the following +formula, where :math:`a` and :math:`b` take on values :math:`x`, +:math:`y`, :math:`z` to generate the components of the tensor: .. math:: S_{ab} = - m v_a v_b - W_{ab} -The first term is a kinetic energy contribution for atom :math:`I`. See -details below on how the specified *temp-ID* can affect the velocities -used in this calculation. The second term is the virial -contribution due to intra and intermolecular interactions, -where the exact computation details are determined by the compute style. +The first term is a kinetic energy contribution for atom :math:`I`. +See details below on how the specified *temp-ID* can affect the +velocities used in this calculation. The second term is the virial +contribution due to intra and intermolecular interactions, where the +exact computation details are determined by the compute style. In case of compute *stress/atom*, the virial contribution is: @@ -68,29 +67,26 @@ In case of compute *stress/atom*, the virial contribution is: & + \frac{1}{3} \sum_{n = 1}^{N_a} (r_{1_a} F_{1_b} + r_{2_a} F_{2_b} + r_{3_a} F_{3_b}) + \frac{1}{4} \sum_{n = 1}^{N_d} (r_{1_a} F_{1_b} + r_{2_a} F_{2_b} + r_{3_a} F_{3_b} + r_{4_a} F_{4_b}) \\ & + \frac{1}{4} \sum_{n = 1}^{N_i} (r_{1_a} F_{1_b} + r_{2_a} F_{2_b} + r_{3_a} F_{3_b} + r_{4_a} F_{4_b}) + {\rm Kspace}(r_{i_a},F_{i_b}) + \sum_{n = 1}^{N_f} r_{i_a} F_{i_b} -The first term is a pairwise energy -contribution where :math:`n` loops over the :math:`N_p` -neighbors of atom :math:`I`, :math:`\mathbf{r}_1` and :math:`\mathbf{r}_2` -are the positions of the 2 atoms in the pairwise interaction, -and :math:`\mathbf{F}_1` and :math:`\mathbf{F}_2` are the forces -on the 2 atoms resulting from the pairwise interaction. -The second term is a bond contribution of -similar form for the :math:`N_b` bonds which atom :math:`I` is part of. -There are similar terms for the :math:`N_a` angle, :math:`N_d` dihedral, -and :math:`N_i` improper interactions atom :math:`I` is part of. -There is also a term for the KSpace -contribution from long-range Coulombic interactions, if defined. -Finally, there is a term for the :math:`N_f` :doc:`fixes ` that apply -internal constraint forces to atom :math:`I`. Currently, only the -:doc:`fix shake ` and :doc:`fix rigid ` commands -contribute to this term. -As the coefficients in the formula imply, a virial contribution -produced by a small set of atoms (e.g. 4 atoms in a dihedral or 3 -atoms in a Tersoff 3-body interaction) is assigned in equal portions -to each atom in the set. E.g. 1/4 of the dihedral virial to each of -the 4 atoms, or 1/3 of the fix virial due to SHAKE constraints applied -to atoms in a water molecule via the :doc:`fix shake ` -command. +The first term is a pairwise energy contribution where :math:`n` loops +over the :math:`N_p` neighbors of atom :math:`I`, :math:`\mathbf{r}_1` +and :math:`\mathbf{r}_2` are the positions of the 2 atoms in the +pairwise interaction, and :math:`\mathbf{F}_1` and +:math:`\mathbf{F}_2` are the forces on the 2 atoms resulting from the +pairwise interaction. The second term is a bond contribution of +similar form for the :math:`N_b` bonds which atom :math:`I` is part +of. There are similar terms for the :math:`N_a` angle, :math:`N_d` +dihedral, and :math:`N_i` improper interactions atom :math:`I` is part +of. There is also a term for the KSpace contribution from long-range +Coulombic interactions, if defined. Finally, there is a term for the +:math:`N_f` :doc:`fixes ` that apply internal constraint forces +to atom :math:`I`. Currently, only the :doc:`fix shake ` +and :doc:`fix rigid ` commands contribute to this term. As +the coefficients in the formula imply, a virial contribution produced +by a small set of atoms (e.g. 4 atoms in a dihedral or 3 atoms in a +Tersoff 3-body interaction) is assigned in equal portions to each atom +in the set. E.g. 1/4 of the dihedral virial to each of the 4 atoms, +or 1/3 of the fix virial due to SHAKE constraints applied to atoms in +a water molecule via the :doc:`fix shake ` command. In case of compute *centroid/stress/atom*, the virial contribution is: @@ -99,71 +95,69 @@ In case of compute *centroid/stress/atom*, the virial contribution is: W_{ab} & = \sum_{n = 1}^{N_p} r_{I0_a} F_{I_b} + \sum_{n = 1}^{N_b} r_{I0_a} F_{I_b} + \sum_{n = 1}^{N_a} r_{I0_a} F_{I_b} + \sum_{n = 1}^{N_d} r_{I0_a} F_{I_b} + \sum_{n = 1}^{N_i} r_{I0_a} F_{I_b} \\ & + {\rm Kspace}(r_{i_a},F_{i_b}) + \sum_{n = 1}^{N_f} r_{i_a} F_{i_b} -As with compute *stress/atom*, the first, second, third, fourth and fifth terms -are pairwise, bond, angle, dihedral and improper contributions, -but instead of assigning the virial contribution equally to each atom, -only the force :math:`\mathbf{F}_I` acting on atom :math:`I` -due to the interaction and the relative -position :math:`\mathbf{r}_{I0}` of the atom :math:`I` to the geometric center -of the interacting atoms, i.e. centroid, is used. -As the geometric center is different -for each interaction, the :math:`\mathbf{r}_{I0}` also differs. -The sixth and seventh terms, Kspace and :doc:`fix ` contribution -respectively, are computed identical to compute *stress/atom*. -Although the total system virial is the same as compute *stress/atom*, -compute *centroid/stress/atom* is know to result in more consistent -heat flux values for angle, dihedrals and improper contributions -when computed via :doc:`compute heat/flux `. +As with compute *stress/atom*, the first, second, third, fourth and +fifth terms are pairwise, bond, angle, dihedral and improper +contributions, but instead of assigning the virial contribution +equally to each atom, only the force :math:`\mathbf{F}_I` acting on +atom :math:`I` due to the interaction and the relative position +:math:`\mathbf{r}_{I0}` of the atom :math:`I` to the geometric center +of the interacting atoms, i.e. centroid, is used. As the geometric +center is different for each interaction, the :math:`\mathbf{r}_{I0}` +also differs. The sixth and seventh terms, Kspace and :doc:`fix +` contribution respectively, are computed identical to compute +*stress/atom*. Although the total system virial is the same as +compute *stress/atom*, compute *centroid/stress/atom* is know to +result in more consistent heat flux values for angle, dihedrals and +improper contributions when computed via :doc:`compute heat/flux +`. -If no extra keywords are listed, the kinetic contribution -all of the virial contribution terms are -included in the per-atom stress tensor. If any extra keywords are -listed, only those terms are summed to compute the tensor. The -*virial* keyword means include all terms except the kinetic energy -*ke*\ . +If no extra keywords are listed, the kinetic contribution all of the +virial contribution terms are included in the per-atom stress tensor. +If any extra keywords are listed, only those terms are summed to +compute the tensor. The *virial* keyword means include all terms +except the kinetic energy *ke*\ . Note that the stress for each atom is due to its interaction with all other atoms in the simulation, not just with other atoms in the group. -Details of how compute *stress/atom* obtains the virial for individual atoms for -either pairwise or many-body potentials, and including the effects of -periodic boundary conditions is discussed in :ref:`(Thompson) `. -The basic idea for many-body potentials is to treat each component of -the force computation between a small cluster of atoms in the same -manner as in the formula above for bond, angle, dihedral, etc -interactions. Namely the quantity :math:`\mathbf{r} \cdot \mathbf{F}` -is summed over the atoms in -the interaction, with the :math:`r` vectors unwrapped by periodic boundaries -so that the cluster of atoms is close together. The total +Details of how compute *stress/atom* obtains the virial for individual +atoms for either pairwise or many-body potentials, and including the +effects of periodic boundary conditions is discussed in +:ref:`(Thompson) `. The basic idea for many-body +potentials is to treat each component of the force computation between +a small cluster of atoms in the same manner as in the formula above +for bond, angle, dihedral, etc interactions. Namely the quantity +:math:`\mathbf{r} \cdot \mathbf{F}` is summed over the atoms in the +interaction, with the :math:`r` vectors unwrapped by periodic +boundaries so that the cluster of atoms is close together. The total contribution for the cluster interaction is divided evenly among those -atoms. Details of how compute *centroid/stress/atom* obtains -the virial for individual atoms -is given in :ref:`(Surblys) `, -where the idea is that the virial of the atom :math:`I` -is the result of only the force :math:`\mathbf{F}_I` on the atom due -to the interaction -and its positional vector :math:`\mathbf{r}_{I0}`, -relative to the geometric center of the -interacting atoms, regardless of the number of participating atoms. -The periodic boundary treatment is identical to +atoms. + +Details of how compute *centroid/stress/atom* obtains the virial for +individual atoms is given in :ref:`(Surblys) `, where the +idea is that the virial of the atom :math:`I` is the result of only +the force :math:`\mathbf{F}_I` on the atom due to the interaction and +its positional vector :math:`\mathbf{r}_{I0}`, relative to the +geometric center of the interacting atoms, regardless of the number of +participating atoms. The periodic boundary treatment is identical to that of compute *stress/atom*, and both of them reduce to identical -expressions for two-body interactions, -i.e. computed values for contributions from bonds and two-body pair styles, -such as :doc:`Lennard-Jones `, will be the same, -while contributions from angles, dihedrals and impropers will be different. +expressions for two-body interactions, i.e. computed values for +contributions from bonds and two-body pair styles, such as +:doc:`Lennard-Jones `, will be the same, while contributions +from angles, dihedrals and impropers will be different. The :doc:`dihedral_style charmm ` style calculates pairwise interactions between 1-4 atoms. The virial contribution of these terms is included in the pair virial, not the dihedral virial. The KSpace contribution is calculated using the method in -:ref:`(Heyes) ` for the Ewald method and by the methodology described -in :ref:`(Sirk) ` for PPPM. The choice of KSpace solver is specified -by the :doc:`kspace_style pppm ` command. Note that for -PPPM, the calculation requires 6 extra FFTs each timestep that -per-atom stress is calculated. Thus it can significantly increase the -cost of the PPPM calculation if it is needed on a large fraction of -the simulation timesteps. +:ref:`(Heyes) ` for the Ewald method and by the methodology +described in :ref:`(Sirk) ` for PPPM. The choice of KSpace +solver is specified by the :doc:`kspace_style pppm ` +command. Note that for PPPM, the calculation requires 6 extra FFTs +each timestep that per-atom stress is calculated. Thus it can +significantly increase the cost of the PPPM calculation if it is +needed on a large fraction of the simulation timesteps. The *temp-ID* argument can be used to affect the per-atom velocities used in the kinetic energy contribution to the total stress. If the @@ -189,10 +183,10 @@ See the :doc:`compute voronoi/atom ` command for one possible way to estimate a per-atom volume. Thus, if the diagonal components of the per-atom stress tensor are -summed for all atoms in the system and the sum is divided by :math:`dV`, where -:math:`d` = dimension and :math:`V` is the volume of the system, -the result should be :math:`-P`, where :math:`P` -is the total pressure of the system. +summed for all atoms in the system and the sum is divided by +:math:`dV`, where :math:`d` = dimension and :math:`V` is the volume of +the system, the result should be :math:`-P`, where :math:`P` is the +total pressure of the system. These lines in an input script for a 3d system should yield that result. I.e. the last 2 columns of thermo output will be the same: @@ -207,33 +201,43 @@ result. I.e. the last 2 columns of thermo output will be the same: .. note:: The per-atom stress does not include any Lennard-Jones tail - corrections to the pressure added by the :doc:`pair_modify tail yes ` command, since those are contributions to the - global system pressure. + corrections to the pressure added by the :doc:`pair_modify tail yes + ` command, since those are contributions to the global + system pressure. Output info """"""""""" -This compute *stress/atom* calculates a per-atom array with 6 columns, which can be -accessed by indices 1-6 by any command that uses per-atom values from -a compute as input. -The compute *centroid/stress/atom* produces a per-atom array with 9 columns, -but otherwise can be used in an identical manner to compute *stress/atom*. -See the :doc:`Howto output ` doc page -for an overview of LAMMPS output options. +Compute *stress/atom* calculates a per-atom array with 6 columns, +which can be accessed by indices 1-6 by any command that uses per-atom +values from a compute as input. Compute *centroid/stress/atom* +produces a per-atom array with 9 columns, but otherwise can be used in +an identical manner to compute *stress/atom*. See the :doc:`Howto +output ` doc page for an overview of LAMMPS output +options. -The per-atom array values will be in pressure\*volume -:doc:`units ` as discussed above. +The per-atom array values will be in pressure\*volume :doc:`units +` as discussed above. Restrictions """""""""""" -Currently (Spring 2020), compute *centroid/stress/atom* does not support -pair styles with many-body interactions, such as :doc:`Tersoff -`, or pair styles with long-range Coulomb interactions. -LAMMPS will generate an error in such cases. In principal, equivalent -formulation to that of angle, dihedral and improper contributions in the -virial :math:`W_{ab}` formula can also be applied to the many-body pair -styles, and is planned in the future. +Currently, compute *centroid/stress/atom* does not support pair styles +with many-body interactions (:doc:`EAM ` is an exception, +since its computations are performed pairwise), nor granular pair +styles with pairwise forces which are not aligned with the vector +between the pair of particles. All bond styles are supported. All +angle, dihedral, improper styles are supported with the exception of +USER-INTEL and KOKKOS variants of specific styles. It also does not +support models with long-range Coulombic or dispersion forces, +i.e. the kspace_style command in LAMMPS. It also does not support the +following fixes which add rigid-body constraints: :doc:`fix shake +`, :doc:`fix rattle `, :doc:`fix rigid +`, :doc:`fix rigid/small `. + +LAMMPS will generate an error if one of these options is included in +your model. Extension of centroid stress calculations to these force +and fix styles is planned for the futre. Related commands """""""""""""""" diff --git a/src/GRANULAR/pair_gran_hooke_history.cpp b/src/GRANULAR/pair_gran_hooke_history.cpp index 9d775c7f5b..7b7586d355 100644 --- a/src/GRANULAR/pair_gran_hooke_history.cpp +++ b/src/GRANULAR/pair_gran_hooke_history.cpp @@ -34,7 +34,6 @@ #include "memory.h" #include "error.h" - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -43,6 +42,7 @@ PairGranHookeHistory::PairGranHookeHistory(LAMMPS *lmp) : Pair(lmp) { single_enable = 1; no_virial_fdotr_compute = 1; + centroidstressflag = CENTROID_NOTAVAIL; history = 1; size_history = 3; diff --git a/src/GRANULAR/pair_granular.cpp b/src/GRANULAR/pair_granular.cpp index 1d2c7c3627..fe88d0755f 100644 --- a/src/GRANULAR/pair_granular.cpp +++ b/src/GRANULAR/pair_granular.cpp @@ -66,6 +66,7 @@ PairGranular::PairGranular(LAMMPS *lmp) : Pair(lmp) { single_enable = 1; no_virial_fdotr_compute = 1; + centroidstressflag = CENTROID_NOTAVAIL; single_extra = 12; svector = new double[single_extra]; diff --git a/src/KOKKOS/angle_charmm_kokkos.cpp b/src/KOKKOS/angle_charmm_kokkos.cpp index 6451b8c393..b363062c20 100644 --- a/src/KOKKOS/angle_charmm_kokkos.cpp +++ b/src/KOKKOS/angle_charmm_kokkos.cpp @@ -42,6 +42,8 @@ AngleCharmmKokkos::AngleCharmmKokkos(LAMMPS *lmp) : AngleCharmm(lmp) execution_space = ExecutionSpaceFromDevice::space; datamask_read = X_MASK | F_MASK | ENERGY_MASK | VIRIAL_MASK; datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/angle_class2_kokkos.cpp b/src/KOKKOS/angle_class2_kokkos.cpp index d4866201e7..a640289c76 100644 --- a/src/KOKKOS/angle_class2_kokkos.cpp +++ b/src/KOKKOS/angle_class2_kokkos.cpp @@ -42,6 +42,8 @@ AngleClass2Kokkos::AngleClass2Kokkos(LAMMPS *lmp) : AngleClass2(lmp) execution_space = ExecutionSpaceFromDevice::space; datamask_read = X_MASK | F_MASK | ENERGY_MASK | VIRIAL_MASK; datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/angle_cosine_kokkos.cpp b/src/KOKKOS/angle_cosine_kokkos.cpp index 6dbba1f86e..9f70df3baf 100644 --- a/src/KOKKOS/angle_cosine_kokkos.cpp +++ b/src/KOKKOS/angle_cosine_kokkos.cpp @@ -42,6 +42,8 @@ AngleCosineKokkos::AngleCosineKokkos(LAMMPS *lmp) : AngleCosine(lmp) execution_space = ExecutionSpaceFromDevice::space; datamask_read = X_MASK | F_MASK | ENERGY_MASK | VIRIAL_MASK; datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/angle_harmonic_kokkos.cpp b/src/KOKKOS/angle_harmonic_kokkos.cpp index 42d42dd6ca..088f1072dc 100644 --- a/src/KOKKOS/angle_harmonic_kokkos.cpp +++ b/src/KOKKOS/angle_harmonic_kokkos.cpp @@ -42,6 +42,8 @@ AngleHarmonicKokkos::AngleHarmonicKokkos(LAMMPS *lmp) : AngleHarmoni execution_space = ExecutionSpaceFromDevice::space; datamask_read = X_MASK | F_MASK | ENERGY_MASK | VIRIAL_MASK; datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/dihedral_charmm_kokkos.cpp b/src/KOKKOS/dihedral_charmm_kokkos.cpp index d1e8735c8a..92efd9d082 100644 --- a/src/KOKKOS/dihedral_charmm_kokkos.cpp +++ b/src/KOKKOS/dihedral_charmm_kokkos.cpp @@ -48,6 +48,8 @@ DihedralCharmmKokkos::DihedralCharmmKokkos(LAMMPS *lmp) : DihedralCh k_warning_flag = Kokkos::DualView("Dihedral:warning_flag"); d_warning_flag = k_warning_flag.template view(); h_warning_flag = k_warning_flag.h_view; + + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/dihedral_class2_kokkos.cpp b/src/KOKKOS/dihedral_class2_kokkos.cpp index 4848b86756..59a20b26da 100644 --- a/src/KOKKOS/dihedral_class2_kokkos.cpp +++ b/src/KOKKOS/dihedral_class2_kokkos.cpp @@ -47,6 +47,8 @@ DihedralClass2Kokkos::DihedralClass2Kokkos(LAMMPS *lmp) : DihedralCl k_warning_flag = DAT::tdual_int_scalar("Dihedral:warning_flag"); d_warning_flag = k_warning_flag.view(); h_warning_flag = k_warning_flag.h_view; + + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/dihedral_harmonic_kokkos.cpp b/src/KOKKOS/dihedral_harmonic_kokkos.cpp index 2681e84e94..764981f231 100644 --- a/src/KOKKOS/dihedral_harmonic_kokkos.cpp +++ b/src/KOKKOS/dihedral_harmonic_kokkos.cpp @@ -47,6 +47,8 @@ DihedralHarmonicKokkos::DihedralHarmonicKokkos(LAMMPS *lmp) : Dihedr k_warning_flag = DAT::tdual_int_scalar("Dihedral:warning_flag"); d_warning_flag = k_warning_flag.view(); h_warning_flag = k_warning_flag.h_view; + + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/dihedral_opls_kokkos.cpp b/src/KOKKOS/dihedral_opls_kokkos.cpp index 01c7f89e0c..ae2b522f81 100644 --- a/src/KOKKOS/dihedral_opls_kokkos.cpp +++ b/src/KOKKOS/dihedral_opls_kokkos.cpp @@ -47,6 +47,8 @@ DihedralOPLSKokkos::DihedralOPLSKokkos(LAMMPS *lmp) : DihedralOPLS(l k_warning_flag = DAT::tdual_int_scalar("Dihedral:warning_flag"); d_warning_flag = k_warning_flag.view(); h_warning_flag = k_warning_flag.h_view; + + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/improper_class2_kokkos.cpp b/src/KOKKOS/improper_class2_kokkos.cpp index f0b27afb3f..68f7223c44 100644 --- a/src/KOKKOS/improper_class2_kokkos.cpp +++ b/src/KOKKOS/improper_class2_kokkos.cpp @@ -43,6 +43,8 @@ ImproperClass2Kokkos::ImproperClass2Kokkos(LAMMPS *lmp) : ImproperCl k_warning_flag = DAT::tdual_int_scalar("Dihedral:warning_flag"); d_warning_flag = k_warning_flag.view(); h_warning_flag = k_warning_flag.h_view; + + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/improper_harmonic_kokkos.cpp b/src/KOKKOS/improper_harmonic_kokkos.cpp index 444088c156..8a64e679bf 100644 --- a/src/KOKKOS/improper_harmonic_kokkos.cpp +++ b/src/KOKKOS/improper_harmonic_kokkos.cpp @@ -44,6 +44,8 @@ ImproperHarmonicKokkos::ImproperHarmonicKokkos(LAMMPS *lmp) : Improp k_warning_flag = Kokkos::DualView("Dihedral:warning_flag"); d_warning_flag = k_warning_flag.template view(); h_warning_flag = k_warning_flag.h_view; + + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/pair_reaxc_kokkos.cpp b/src/KOKKOS/pair_reaxc_kokkos.cpp index 54ab4aa128..eea397dc69 100644 --- a/src/KOKKOS/pair_reaxc_kokkos.cpp +++ b/src/KOKKOS/pair_reaxc_kokkos.cpp @@ -3630,6 +3630,8 @@ void PairReaxCKokkos::v_tally3_atom(EV_FLOAT_REAX &ev, const int &i, /* ---------------------------------------------------------------------- setup for energy, virial computation see integrate::ev_set() for values of eflag and vflag + see pair::ev_setup() for values of eflag_* and vflag_* + VIRIAL_CENTROID bitflag is not yet supported by ReaxFF ------------------------------------------------------------------------- */ template @@ -3645,7 +3647,7 @@ void PairReaxCKokkos::ev_setup(int eflag, int vflag, int) vflag_either = vflag; vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); - vflag_atom = vflag & (VIRIAL_ATOM | VIRIAL_CENTROID); + vflag_atom = vflag & VIRIAL_ATOM; // reallocate per-atom arrays if necessary diff --git a/src/MANYBODY/pair_adp.cpp b/src/MANYBODY/pair_adp.cpp index fffa53b3d8..401c1f35ad 100644 --- a/src/MANYBODY/pair_adp.cpp +++ b/src/MANYBODY/pair_adp.cpp @@ -69,6 +69,7 @@ PairADP::PairADP(LAMMPS *lmp) : Pair(lmp) single_enable = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- diff --git a/src/MANYBODY/pair_airebo.cpp b/src/MANYBODY/pair_airebo.cpp index 5955e8c29c..4a0c2a874d 100644 --- a/src/MANYBODY/pair_airebo.cpp +++ b/src/MANYBODY/pair_airebo.cpp @@ -69,6 +69,7 @@ PairAIREBO::PairAIREBO(LAMMPS *lmp) nC = nH = nullptr; map = nullptr; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; sigwid = 0.84; sigcut = 3.0; diff --git a/src/MANYBODY/pair_atm.cpp b/src/MANYBODY/pair_atm.cpp index 5b15909845..460e1f6828 100644 --- a/src/MANYBODY/pair_atm.cpp +++ b/src/MANYBODY/pair_atm.cpp @@ -52,6 +52,7 @@ PairATM::PairATM(LAMMPS *lmp) : Pair(lmp) restartinfo = 1; one_coeff = 0; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- diff --git a/src/MANYBODY/pair_bop.cpp b/src/MANYBODY/pair_bop.cpp index fb2b06f48b..29fd8b63c6 100644 --- a/src/MANYBODY/pair_bop.cpp +++ b/src/MANYBODY/pair_bop.cpp @@ -61,6 +61,7 @@ PairBOP::PairBOP(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; ghostneigh = 1; allocated = 0; diff --git a/src/MANYBODY/pair_comb.cpp b/src/MANYBODY/pair_comb.cpp index 916b00d8d4..b850e9d2c1 100644 --- a/src/MANYBODY/pair_comb.cpp +++ b/src/MANYBODY/pair_comb.cpp @@ -53,6 +53,7 @@ PairComb::PairComb(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; nmax = 0; NCo = nullptr; diff --git a/src/MANYBODY/pair_comb3.cpp b/src/MANYBODY/pair_comb3.cpp index 4465cfdcb0..ddf4695df7 100644 --- a/src/MANYBODY/pair_comb3.cpp +++ b/src/MANYBODY/pair_comb3.cpp @@ -51,6 +51,8 @@ PairComb3::PairComb3(LAMMPS *lmp) : Pair(lmp) single_enable = 0; restartinfo = 0; one_coeff = 1; + manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; ghostneigh = 1; nmax = 0; diff --git a/src/MANYBODY/pair_eim.cpp b/src/MANYBODY/pair_eim.cpp index 5606dc137b..dbb16125c7 100644 --- a/src/MANYBODY/pair_eim.cpp +++ b/src/MANYBODY/pair_eim.cpp @@ -39,6 +39,7 @@ PairEIM::PairEIM(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); setfl = nullptr; diff --git a/src/MANYBODY/pair_gw.cpp b/src/MANYBODY/pair_gw.cpp index 4a67e51b79..675ec1b3fe 100644 --- a/src/MANYBODY/pair_gw.cpp +++ b/src/MANYBODY/pair_gw.cpp @@ -48,6 +48,7 @@ PairGW::PairGW(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nelements = 0; diff --git a/src/MANYBODY/pair_lcbop.cpp b/src/MANYBODY/pair_lcbop.cpp index 6184ebfe29..df43aac9d2 100644 --- a/src/MANYBODY/pair_lcbop.cpp +++ b/src/MANYBODY/pair_lcbop.cpp @@ -45,6 +45,7 @@ PairLCBOP::PairLCBOP(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; ghostneigh = 1; maxlocal = 0; diff --git a/src/MANYBODY/pair_nb3b_harmonic.cpp b/src/MANYBODY/pair_nb3b_harmonic.cpp index 369d3bfc04..ffb059c067 100644 --- a/src/MANYBODY/pair_nb3b_harmonic.cpp +++ b/src/MANYBODY/pair_nb3b_harmonic.cpp @@ -46,7 +46,8 @@ PairNb3bHarmonic::PairNb3bHarmonic(LAMMPS *lmp) : Pair(lmp) single_enable = 0; restartinfo = 0; one_coeff = 1; - manybody_flag = 1; + manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nelements = 0; diff --git a/src/MANYBODY/pair_polymorphic.cpp b/src/MANYBODY/pair_polymorphic.cpp index b045ec66d1..e256063b73 100644 --- a/src/MANYBODY/pair_polymorphic.cpp +++ b/src/MANYBODY/pair_polymorphic.cpp @@ -44,6 +44,8 @@ PairPolymorphic::PairPolymorphic(LAMMPS *lmp) : Pair(lmp) single_enable = 0; restartinfo = 0; one_coeff = 1; + manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; nelements = 0; elements = nullptr; diff --git a/src/MANYBODY/pair_sw.cpp b/src/MANYBODY/pair_sw.cpp index a300c11e1a..708027913c 100644 --- a/src/MANYBODY/pair_sw.cpp +++ b/src/MANYBODY/pair_sw.cpp @@ -43,6 +43,7 @@ PairSW::PairSW(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nelements = 0; diff --git a/src/MANYBODY/pair_tersoff.cpp b/src/MANYBODY/pair_tersoff.cpp index be285d7268..dbb7cd2f48 100644 --- a/src/MANYBODY/pair_tersoff.cpp +++ b/src/MANYBODY/pair_tersoff.cpp @@ -47,6 +47,7 @@ PairTersoff::PairTersoff(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nelements = 0; diff --git a/src/MANYBODY/pair_vashishta.cpp b/src/MANYBODY/pair_vashishta.cpp index 550fd661d6..d5a1374a80 100644 --- a/src/MANYBODY/pair_vashishta.cpp +++ b/src/MANYBODY/pair_vashishta.cpp @@ -45,6 +45,7 @@ PairVashishta::PairVashishta(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nelements = 0; diff --git a/src/MLIAP/pair_mliap.cpp b/src/MLIAP/pair_mliap.cpp index f5895d6e5d..a422271f19 100644 --- a/src/MLIAP/pair_mliap.cpp +++ b/src/MLIAP/pair_mliap.cpp @@ -38,7 +38,7 @@ PairMLIAP::PairMLIAP(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; - + centroidstressflag = CENTROID_NOTAVAIL; } /* ---------------------------------------------------------------------- */ diff --git a/src/SNAP/pair_snap.cpp b/src/SNAP/pair_snap.cpp index e6ff85b4b6..a7ea6de591 100644 --- a/src/SNAP/pair_snap.cpp +++ b/src/SNAP/pair_snap.cpp @@ -40,6 +40,7 @@ PairSNAP::PairSNAP(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; nelements = 0; elements = nullptr; diff --git a/src/USER-MEAMC/pair_meamc.cpp b/src/USER-MEAMC/pair_meamc.cpp index e99c17cb31..d0fb8a0463 100644 --- a/src/USER-MEAMC/pair_meamc.cpp +++ b/src/USER-MEAMC/pair_meamc.cpp @@ -17,7 +17,6 @@ #include "pair_meamc.h" - #include #include "meam.h" @@ -30,8 +29,6 @@ #include "memory.h" #include "error.h" - - using namespace LAMMPS_NS; #define MAXLINE 1024 @@ -52,6 +49,7 @@ PairMEAMC::PairMEAMC(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; allocated = 0; diff --git a/src/USER-MESONT/pair_mesocnt.cpp b/src/USER-MESONT/pair_mesocnt.cpp index b4e21888e0..39a97321a7 100644 --- a/src/USER-MESONT/pair_mesocnt.cpp +++ b/src/USER-MESONT/pair_mesocnt.cpp @@ -23,7 +23,6 @@ #include - #include "atom.h" #include "comm.h" #include "force.h" @@ -33,9 +32,6 @@ #include "memory.h" #include "error.h" #include "update.h" - - - #include "math_const.h" #include "math_extra.h" @@ -58,6 +54,7 @@ PairMesoCNT::PairMesoCNT(LAMMPS *lmp) : Pair(lmp) respa_enable = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; no_virial_fdotr_compute = 0; writedata = 0; ghostneigh = 0; diff --git a/src/USER-MISC/pair_agni.cpp b/src/USER-MISC/pair_agni.cpp index 52f1db923c..c9f6aff689 100644 --- a/src/USER-MISC/pair_agni.cpp +++ b/src/USER-MISC/pair_agni.cpp @@ -81,6 +81,7 @@ PairAGNI::PairAGNI(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; no_virial_fdotr_compute = 1; diff --git a/src/USER-MISC/pair_drip.cpp b/src/USER-MISC/pair_drip.cpp index a58b77782a..45b49ee293 100644 --- a/src/USER-MISC/pair_drip.cpp +++ b/src/USER-MISC/pair_drip.cpp @@ -34,7 +34,6 @@ #include "memory.h" #include "error.h" - using namespace LAMMPS_NS; #define MAXLINE 1024 @@ -48,6 +47,7 @@ PairDRIP::PairDRIP(LAMMPS *lmp) : Pair(lmp) single_enable = 0; restartinfo = 0; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; params = nullptr; nearest3neigh = nullptr; diff --git a/src/USER-MISC/pair_edip.cpp b/src/USER-MISC/pair_edip.cpp index 52fcfa85fb..b29f499de8 100644 --- a/src/USER-MISC/pair_edip.cpp +++ b/src/USER-MISC/pair_edip.cpp @@ -36,7 +36,6 @@ #include "memory.h" #include "error.h" - using namespace LAMMPS_NS; #define MAXLINE 1024 @@ -63,6 +62,7 @@ PairEDIP::PairEDIP(LAMMPS *lmp) : restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; nelements = 0; elements = nullptr; diff --git a/src/USER-MISC/pair_edip_multi.cpp b/src/USER-MISC/pair_edip_multi.cpp index 7213ca37ed..811f80abfc 100644 --- a/src/USER-MISC/pair_edip_multi.cpp +++ b/src/USER-MISC/pair_edip_multi.cpp @@ -68,6 +68,7 @@ PairEDIPMulti::PairEDIPMulti(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; nelements = 0; elements = nullptr; diff --git a/src/USER-MISC/pair_extep.cpp b/src/USER-MISC/pair_extep.cpp index 2bf5aee947..2d0001c680 100644 --- a/src/USER-MISC/pair_extep.cpp +++ b/src/USER-MISC/pair_extep.cpp @@ -49,6 +49,7 @@ PairExTeP::PairExTeP(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; ghostneigh = 1; nelements = 0; diff --git a/src/USER-MISC/pair_meam_sw_spline.cpp b/src/USER-MISC/pair_meam_sw_spline.cpp index c27cdcf610..17511e90b8 100644 --- a/src/USER-MISC/pair_meam_sw_spline.cpp +++ b/src/USER-MISC/pair_meam_sw_spline.cpp @@ -47,6 +47,7 @@ PairMEAMSWSpline::PairMEAMSWSpline(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; nelements = 0; elements = nullptr; diff --git a/src/USER-MISC/pair_tersoff_table.cpp b/src/USER-MISC/pair_tersoff_table.cpp index feaa789688..c4e2d2c993 100644 --- a/src/USER-MISC/pair_tersoff_table.cpp +++ b/src/USER-MISC/pair_tersoff_table.cpp @@ -61,6 +61,7 @@ PairTersoffTable::PairTersoffTable(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nelements = 0; diff --git a/src/USER-QUIP/pair_quip.cpp b/src/USER-QUIP/pair_quip.cpp index 6b4b4ff576..0cbc71e564 100644 --- a/src/USER-QUIP/pair_quip.cpp +++ b/src/USER-QUIP/pair_quip.cpp @@ -16,7 +16,6 @@ Aidan Thompson (Sandia, athomps@sandia.gov) ------------------------------------------------------------------------- */ - #include #include @@ -44,6 +43,7 @@ PairQUIP::PairQUIP(LAMMPS *lmp) : Pair(lmp) one_coeff = 1; no_virial_fdotr_compute = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; map = nullptr; quip_potential = nullptr; diff --git a/src/USER-REAXC/pair_reaxc.cpp b/src/USER-REAXC/pair_reaxc.cpp index d13a48cb6d..d3507bdf85 100644 --- a/src/USER-REAXC/pair_reaxc.cpp +++ b/src/USER-REAXC/pair_reaxc.cpp @@ -40,7 +40,6 @@ #include "memory.h" #include "error.h" - #include "reaxc_defs.h" #include "reaxc_types.h" #include "reaxc_allocate.h" @@ -77,6 +76,7 @@ PairReaxC::PairReaxC(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; ghostneigh = 1; fix_id = new char[24]; diff --git a/src/angle.cpp b/src/angle.cpp index 83f5431683..25eab2b752 100644 --- a/src/angle.cpp +++ b/src/angle.cpp @@ -40,6 +40,7 @@ Angle::Angle(LAMMPS *lmp) : Pointers(lmp) vatom = nullptr; cvatom = nullptr; setflag = nullptr; + centroidstressflag = CENTROID_AVAIL; execution_space = Host; datamask_read = ALL_MASK; @@ -77,14 +78,17 @@ void Angle::init() setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag set the following flags, values are otherwise 0: - evflag = 1 if any bits of eflag or vflag are set - eflag_global = 1 if ENERGY_GLOBAL bit of eflag set - eflag_atom = 1 if ENERGY_ATOM bit of eflag set - eflag_either = 1 if eflag_global or eflag_atom is set - vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_ATOM bit of vflag set - cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set - vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set + evflag != 0 if any bits of eflag or vflag are set + eflag_global != 0 if ENERGY_GLOBAL bit of eflag set + eflag_atom != 0 if ENERGY_ATOM bit of eflag set + eflag_either != 0 if eflag_global or eflag_atom is set + vflag_global != 0 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom != 0 if VIRIAL_ATOM bit of vflag set + vflag_atom != 0 if VIRIAL_CENTROID bit of vflag set + and centroidstressflag != CENTROID_AVAIL + cvflag_atom != 0 if VIRIAL_CENTROID bit of vflag set + and centroidstressflag = CENTROID_AVAIL + vflag_either != 0 if any of vflag_global, vflag_atom, cvflag_atom is set ------------------------------------------------------------------------- */ void Angle::ev_setup(int eflag, int vflag, int alloc) @@ -99,8 +103,11 @@ void Angle::ev_setup(int eflag, int vflag, int alloc) vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); vflag_atom = vflag & VIRIAL_ATOM; - cvflag_atom = vflag & VIRIAL_CENTROID; - vflag_either = vflag_global || vflag_atom; + if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) + vflag_atom = 1; + if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) + cvflag_atom = 1; + vflag_either = vflag_global || vflag_atom || cvflag_atom; // reallocate per-atom arrays if necessary diff --git a/src/angle.h b/src/angle.h index 139380ff39..ffed437743 100644 --- a/src/angle.h +++ b/src/angle.h @@ -30,6 +30,11 @@ class Angle : protected Pointers { double *eatom,**vatom; // accumulated per-atom energy/virial double **cvatom; // accumulated per-atom centroid virial + int centroidstressflag; // centroid stress compared to two-body stress + // CENTROID_SAME = same as two-body stress + // CENTROID_AVAIL = different and implemented + // CENTROID_NOTAVAIL = different, not yet implemented + // KOKKOS host/device flag and data masks ExecutionSpace execution_space; diff --git a/src/bond.cpp b/src/bond.cpp index ddd1ae9b37..89265915fb 100644 --- a/src/bond.cpp +++ b/src/bond.cpp @@ -82,13 +82,14 @@ void Bond::init() setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag set the following flags, values are otherwise 0: - evflag = 1 if any bits of eflag or vflag are set - eflag_global = 1 if ENERGY_GLOBAL bit of eflag set - eflag_atom = 1 if ENERGY_ATOM bit of eflag set - eflag_either = 1 if eflag_global or eflag_atom is set - vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_ATOM or VIRIAL_CENTROID bit of vflag set - vflag_either = 1 if vflag_global or vflag_atom is set + evflag != 0 if any bits of eflag or vflag are set + eflag_global != 0 if ENERGY_GLOBAL bit of eflag set + eflag_atom != 0 if ENERGY_ATOM bit of eflag set + eflag_either != 0 if eflag_global or eflag_atom is set + vflag_global != 0 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom != 0 if VIRIAL_ATOM or VIRIAL_CENTROID bit of vflag set + two-body and centroid stress are identical for bonds + vflag_either != 0 if vflag_global or vflag_atom is set ------------------------------------------------------------------------- */ void Bond::ev_setup(int eflag, int vflag, int alloc) @@ -103,7 +104,6 @@ void Bond::ev_setup(int eflag, int vflag, int alloc) vflag_either = vflag; vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); - // per-atom virial and per-atom centroid virial are the same for bonds vflag_atom = vflag & (VIRIAL_ATOM | VIRIAL_CENTROID); // reallocate per-atom arrays if necessary diff --git a/src/compute_centroid_stress_atom.cpp b/src/compute_centroid_stress_atom.cpp index 35633d5e4d..15be95bee1 100644 --- a/src/compute_centroid_stress_atom.cpp +++ b/src/compute_centroid_stress_atom.cpp @@ -124,10 +124,35 @@ void ComputeCentroidStressAtom::init() else biasflag = NOBIAS; } else biasflag = NOBIAS; - // check if pair styles support centroid atom stress + // check if force components and fixes support centroid atom stress + // all bond styles support it as CENTROID_SAME + if (pairflag && force->pair) - if (force->pair->centroidstressflag & CENTROID_NOTAVAIL) + if (force->pair->centroidstressflag == CENTROID_NOTAVAIL) error->all(FLERR, "Pair style does not support compute centroid/stress/atom"); + + if (angleflag && force->angle) + if (force->angle->centroidstressflag == CENTROID_NOTAVAIL) + error->all(FLERR, "Angle style does not support compute centroid/stress/atom"); + + if (dihedralflag && force->dihedral) + if (force->dihedral->centroidstressflag == CENTROID_NOTAVAIL) + error->all(FLERR, "Dihedral style does not support compute centroid/stress/atom"); + + if (improperflag && force->improper) + if (force->improper->centroidstressflag == CENTROID_NOTAVAIL) + error->all(FLERR, "Improper style does not support compute centroid/stress/atom"); + + if (kspaceflag && force->kspace) + if (force->kspace->centroidstressflag == CENTROID_NOTAVAIL) + error->all(FLERR, "KSpace style does not support compute centroid/stress/atom"); + + if (fixflag) { + for (int ifix = 0; ifix < modify->nfix; ifix++) + if (modify->fix[ifix]->virial_flag && + modify->fix[ifix]->centroidstressflag == CENTROID_NOTAVAIL) + error->all(FLERR, "Fix style does not support compute centroid/stress/atom"); + } } /* ---------------------------------------------------------------------- */ @@ -173,12 +198,12 @@ void ComputeCentroidStressAtom::compute_peratom() for (j = 0; j < 9; j++) stress[i][j] = 0.0; - // add in per-atom contributions from each force - - // per-atom virial and per-atom centroid virial are the same for two-body - // many-body pair styles not yet implemented + // add in per-atom contributions from all force components and fixes + + // pair styles are either CENTROID_SAME or CENTROID_AVAIL or CENTROID_NOTAVAIL + if (pairflag && force->pair && force->pair->compute_flag) { - if (force->pair->centroidstressflag & CENTROID_AVAIL) { + if (force->pair->centroidstressflag == CENTROID_AVAIL) { double **cvatom = force->pair->cvatom; for (i = 0; i < npair; i++) for (j = 0; j < 9; j++) @@ -195,6 +220,9 @@ void ComputeCentroidStressAtom::compute_peratom() } // per-atom virial and per-atom centroid virial are the same for bonds + // bond styles are all CENTROID_SAME + // all other styles are CENTROID_AVAIL or CENTROID_NOTAVAIL + if (bondflag && force->bond) { double **vatom = force->bond->vatom; for (i = 0; i < nbond; i++) { @@ -228,12 +256,9 @@ void ComputeCentroidStressAtom::compute_peratom() if (kspaceflag && force->kspace && force->kspace->compute_flag) { double **vatom = force->kspace->vatom; - for (i = 0; i < nkspace; i++) { - for (j = 0; j < 6; j++) - stress[i][j] += vatom[i][j]; - for (j = 6; j < 9; j++) - stress[i][j] += vatom[i][j-3]; - } + for (i = 0; i < nkspace; i++) + for (j = 0; j < 9; j++) + stress[i][j] += cvatom[i][j]; } // add in per-atom contributions from relevant fixes @@ -241,7 +266,8 @@ void ComputeCentroidStressAtom::compute_peratom() // possible during setup phase if fix has not initialized its vatom yet // e.g. fix ave/spatial defined before fix shake, // and fix ave/spatial uses a per-atom stress from this compute as input - + // fix styles are CENTROID_SAME or CENTROID_NOTAVAIL + if (fixflag) { for (int ifix = 0; ifix < modify->nfix; ifix++) if (modify->fix[ifix]->virial_flag) { @@ -258,7 +284,8 @@ void ComputeCentroidStressAtom::compute_peratom() // communicate ghost virials between neighbor procs - if (force->newton || (force->kspace && force->kspace->tip4pflag && force->kspace->compute_flag)) + if (force->newton || + (force->kspace && force->kspace->tip4pflag && force->kspace->compute_flag)) comm->reverse_comm_compute(this); // zero virial of atoms not in group diff --git a/src/dihedral.cpp b/src/dihedral.cpp index 1d77598e38..68c69fa787 100644 --- a/src/dihedral.cpp +++ b/src/dihedral.cpp @@ -40,6 +40,7 @@ Dihedral::Dihedral(LAMMPS *lmp) : Pointers(lmp) vatom = nullptr; cvatom = nullptr; setflag = nullptr; + centroidstressflag = CENTROID_AVAIL; execution_space = Host; datamask_read = ALL_MASK; @@ -76,14 +77,17 @@ void Dihedral::init() setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag set the following flags, values are otherwise 0: - evflag = 1 if any bits of eflag or vflag are set - eflag_global = 1 if ENERGY_GLOBAL bit of eflag set - eflag_atom = 1 if ENERGY_ATOM bit of eflag set - eflag_either = 1 if eflag_global or eflag_atom is set - vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_ATOM bit of vflag set - cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set - vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set + evflag != 0 if any bits of eflag or vflag are set + eflag_global != 0 if ENERGY_GLOBAL bit of eflag set + eflag_atom != 0 if ENERGY_ATOM bit of eflag set + eflag_either != 0 if eflag_global or eflag_atom is set + vflag_global != 0 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom != 0 if VIRIAL_ATOM bit of vflag set + vflag_atom != 0 if VIRIAL_CENTROID bit of vflag set + and centroidstressflag != CENTROID_AVAIL + cvflag_atom != 0 if VIRIAL_CENTROID bit of vflag set + and centroidstressflag = CENTROID_AVAIL + vflag_either != 0 if any of vflag_global, vflag_atom, cvflag_atom is set ------------------------------------------------------------------------- */ void Dihedral::ev_setup(int eflag, int vflag, int alloc) @@ -98,8 +102,11 @@ void Dihedral::ev_setup(int eflag, int vflag, int alloc) vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); vflag_atom = vflag & VIRIAL_ATOM; - cvflag_atom = vflag & VIRIAL_CENTROID; - vflag_either = vflag_global || vflag_atom; + if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) + vflag_atom = 1; + if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) + cvflag_atom = 1; + vflag_either = vflag_global || vflag_atom || cvflag_atom; // reallocate per-atom arrays if necessary diff --git a/src/dihedral.h b/src/dihedral.h index c96891b1c4..c571a74dd4 100644 --- a/src/dihedral.h +++ b/src/dihedral.h @@ -30,6 +30,11 @@ class Dihedral : protected Pointers { double *eatom,**vatom; // accumulated per-atom energy/virial double **cvatom; // accumulated per-atom centroid virial + int centroidstressflag; // centroid stress compared to two-body stress + // CENTROID_SAME = same as two-body stress + // CENTROID_AVAIL = different and implemented + // CENTROID_NOTAVAIL = different, not yet implemented + // KOKKOS host/device flag and data masks ExecutionSpace execution_space; diff --git a/src/fix.cpp b/src/fix.cpp index aabbc58473..b58e7c4fa5 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -104,7 +104,8 @@ Fix::Fix(LAMMPS *lmp, int /*narg*/, char **arg) : maxeatom = maxvatom = 0; vflag_atom = 0; - + centroidstressflag = CENTROID_SAME; + // KOKKOS per-fix data masks execution_space = Host; diff --git a/src/fix.h b/src/fix.h index 07a222063c..216bb00469 100644 --- a/src/fix.h +++ b/src/fix.h @@ -102,6 +102,11 @@ class Fix : protected Pointers { double virial[6]; // accumulated virial double *eatom,**vatom; // accumulated per-atom energy/virial + int centroidstressflag; // centroid stress compared to two-body stress + // CENTROID_SAME = same as two-body stress + // CENTROID_AVAIL = different and implemented + // CENTROID_NOTAVAIL = different, not yet implemented + int restart_reset; // 1 if restart just re-initialized fix // KOKKOS host/device flag and data masks diff --git a/src/improper.cpp b/src/improper.cpp index f716f84969..b46e27bb2d 100644 --- a/src/improper.cpp +++ b/src/improper.cpp @@ -37,6 +37,7 @@ Improper::Improper(LAMMPS *lmp) : Pointers(lmp) vatom = nullptr; cvatom = nullptr; setflag = nullptr; + centroidstressflag = CENTROID_AVAIL; execution_space = Host; datamask_read = ALL_MASK; @@ -80,8 +81,11 @@ void Improper::init() eflag_either = 1 if eflag_global or eflag_atom is set vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set vflag_atom = 1 if VIRIAL_ATOM bit of vflag set - cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set - vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set + vflag_atom != 0 if VIRIAL_CENTROID bit of vflag set + and centroidstressflag != CENTROID_AVAIL + cvflag_atom != 0 if VIRIAL_CENTROID bit of vflag set + and centroidstressflag = CENTROID_AVAIL + vflag_either != 0 if any of vflag_global, vflag_atom, cvflag_atom is set ------------------------------------------------------------------------- */ void Improper::ev_setup(int eflag, int vflag, int alloc) @@ -96,8 +100,11 @@ void Improper::ev_setup(int eflag, int vflag, int alloc) vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); vflag_atom = vflag & VIRIAL_ATOM; - cvflag_atom = vflag & VIRIAL_CENTROID; - vflag_either = vflag_global || vflag_atom; + if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) + vflag_atom = 1; + if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) + cvflag_atom = 1; + vflag_either = vflag_global || vflag_atom || cvflag_atom; // reallocate per-atom arrays if necessary diff --git a/src/improper.h b/src/improper.h index f3bed2607c..9e73be931c 100644 --- a/src/improper.h +++ b/src/improper.h @@ -30,6 +30,11 @@ class Improper : protected Pointers { double *eatom,**vatom; // accumulated per-atom energy/virial double **cvatom; // accumulated per-atom centroid virial + int centroidstressflag; // centroid stress compared to two-body stress + // CENTROID_SAME = same as two-body stress + // CENTROID_AVAIL = different and implemented + // CENTROID_NOTAVAIL = different, not yet implemented + // KOKKOS host/device flag and data masks ExecutionSpace execution_space; diff --git a/src/integrate.cpp b/src/integrate.cpp index 8b8f607e00..5c700527a1 100644 --- a/src/integrate.cpp +++ b/src/integrate.cpp @@ -116,7 +116,7 @@ void Integrate::ev_setup() eflag: set any or no bits ENERGY_GLOBAL bit for global energy ENERGY_ATOM bit for per-atom energy - vflag: set any or no bits, but GLOBAL/FDOTR bit cannot both be set + vflag: set any or no bits, but PAIR/FDOTR bits cannot both be set VIRIAL_PAIR bit for global virial as sum of pairwise terms VIRIAL_FDOTR bit for global virial via F dot r VIRIAL_ATOM bit for per-atom virial diff --git a/src/kspace.cpp b/src/kspace.cpp index ef7970e2ec..a6dd5fdffb 100644 --- a/src/kspace.cpp +++ b/src/kspace.cpp @@ -88,7 +88,8 @@ KSpace::KSpace(LAMMPS *lmp) : Pointers(lmp) maxeatom = maxvatom = 0; eatom = nullptr; vatom = nullptr; - + centroidstressatom = NOTAVAIL; + execution_space = Host; datamask_read = ALL_MASK; datamask_modify = ALL_MASK; @@ -216,13 +217,14 @@ void KSpace::pair_check() setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag set the following flags, values are otherwise 0: - evflag = 1 if any bits of eflag or vflag are set - eflag_global = 1 if ENERGY_GLOBAL bit of eflag set - eflag_atom = 1 if ENERGY_ATOM bit of eflag set - eflag_either = 1 if eflag_global or eflag_atom is set - vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_ATOM or VIRIAL_CENTROID bit of vflag set - vflag_either = 1 if vflag_global or vflag_atom is set + evflag != 0 if any bits of eflag or vflag are set + eflag_global != 0 if ENERGY_GLOBAL bit of eflag set + eflag_atom != 0 if ENERGY_ATOM bit of eflag set + eflag_either != 0 if eflag_global or eflag_atom is set + vflag_global != 0 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom != 0 if VIRIAL_ATOM bit of vflag set + no current support for centroid stress + vflag_either != 0 if vflag_global or vflag_atom is set ------------------------------------------------------------------------- */ void KSpace::ev_setup(int eflag, int vflag, int alloc) @@ -237,7 +239,7 @@ void KSpace::ev_setup(int eflag, int vflag, int alloc) vflag_either = vflag; vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); - vflag_atom = vflag & (VIRIAL_ATOM | VIRIAL_CENTROID); + vflag_atom = vflag & VIRIAL_ATOM; if (eflag_atom || vflag_atom) evflag_atom = 1; else evflag_atom = 0; diff --git a/src/kspace.h b/src/kspace.h index 110a790dfe..978daeace1 100644 --- a/src/kspace.h +++ b/src/kspace.h @@ -80,6 +80,11 @@ class KSpace : protected Pointers { int group_group_enable; // 1 if style supports group/group calculation + int centroidstressflag; // centroid stress compared to two-body stress + // CENTROID_SAME = same as two-body stress + // CENTROID_AVAIL = different and implemented + // CENTROID_NOTAVAIL = different, not yet implemented + // KOKKOS host/device flag and data masks ExecutionSpace execution_space; diff --git a/src/pair.cpp b/src/pair.cpp index 470c147798..2cb0b2b210 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -77,7 +77,7 @@ Pair::Pair(LAMMPS *lmp) : Pointers(lmp) ewaldflag = pppmflag = msmflag = dispersionflag = tip4pflag = dipoleflag = spinflag = 0; reinitflag = 1; - centroidstressflag = CENTROID_NOTAVAIL; + centroidstressflag = CENTROID_SAME; // pair_modify settings @@ -779,18 +779,21 @@ void Pair::del_tally_callback(Compute *ptr) setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag set the following flags, values are otherwise 0: - evflag = 1 if any bits of eflag or vflag are set - eflag_global = 1 if ENERGY_GLOBAL bit of eflag set - eflag_atom = 1 if ENERGY_ATOM bit of eflag set - eflag_either = 1 if eflag_global or eflag_atom is set - vflag_global = 1 if VIRIAL_PAIR bit of vflag set - vflag_global = 2 if VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_ATOM bit of vflag set - vflag_atom = 1 if VIRIAL_CENTROID bit of vflag set - and centroidstressflag != CENTROID_AVAIL - cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set - and centroidstressflag = CENTROID_AVAIL - vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set + evflag != 0 if any bits of eflag or vflag are set + eflag_global != 0 if ENERGY_GLOBAL bit of eflag set + eflag_atom != 0 if ENERGY_ATOM bit of eflag set + eflag_either != 0 if eflag_global or eflag_atom is set + vflag_global = VIRIAL_PAIR if VIRIAL_PAIR bit of vflag set + vflag_global = VIRIAL_FDOTR if VIRIAL_FDOTR bit of vflag set + this setting also sets vflag_dotr = 1 if pair style supports it, + which unsets vflag_global and can also thus change other flags, + see logic at end of method + vflag_atom != 0 if VIRIAL_ATOM bit of vflag set + vflag_atom != 0 if VIRIAL_CENTROID bit of vflag set + and centroidstressflag != CENTROID_AVAIL + cvflag_atom != 0 if VIRIAL_CENTROID bit of vflag set + and centroidstressflag = CENTROID_AVAIL + vflag_either != 0 if any of vflag_global, vflag_atom, cvflag_atom is set centroidstressflag is set by the pair style to one of these values: CENTROID_SAME = same as two-body stress CENTROID_AVAIL = different and implemented @@ -809,19 +812,11 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); vflag_atom = vflag & VIRIAL_ATOM; - cvflag_atom = 0; - - if (vflag & VIRIAL_CENTROID) { - if (centroidstressflag & CENTROID_AVAIL) { - cvflag_atom = 1; - } else { - vflag_atom = 1; - } - // extra check, because both bits might be set - if (centroidstressflag & CENTROID_SAME) vflag_atom = 1; - } - - vflag_either = vflag_global || vflag_atom; + if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) + vflag_atom = 1; + if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) + cvflag_atom = 1; + vflag_either = vflag_global || vflag_atom || cvflag_atom; // reallocate per-atom arrays if necessary @@ -894,11 +889,10 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) if (vflag_global == VIRIAL_FDOTR && no_virial_fdotr_compute == 0) { vflag_fdotr = 1; vflag_global = 0; - if (vflag_atom == 0 && cvflag_atom == 0) vflag_either = 0; - if (vflag_either == 0 && eflag_either == 0) evflag = 0; + if (!vflag_atom == 0 && !cvflag_atom) vflag_either = 0; + if (!vflag_either == 0 && !eflag_either) evflag = 0; } else vflag_fdotr = 0; - // run ev_setup option for USER-TALLY computes if (num_tally_compute > 0) { diff --git a/src/pair.h b/src/pair.h index 5f931cea54..ff0ce82cc8 100644 --- a/src/pair.h +++ b/src/pair.h @@ -68,7 +68,7 @@ class Pair : protected Pointers { int spinflag; // 1 if compatible with spin solver int reinitflag; // 1 if compatible with fix adapt and alike - int centroidstressflag; // centroid atomic compared to two-body stress + int centroidstressflag; // centroid stress compared to two-body stress // CENTROID_SAME = same as two-body stress // CENTROID_AVAIL = different and implemented // CENTROID_NOTAVAIL = different, not yet implemented diff --git a/src/pair_beck.cpp b/src/pair_beck.cpp index 6a5875e59b..a6e63fc4ec 100644 --- a/src/pair_beck.cpp +++ b/src/pair_beck.cpp @@ -26,15 +26,12 @@ #include "error.h" #include "math_special.h" - using namespace LAMMPS_NS; using namespace MathSpecial; /* ---------------------------------------------------------------------- */ -PairBeck::PairBeck(LAMMPS *lmp) : Pair(lmp) { - centroidstressflag = CENTROID_SAME; -} +PairBeck::PairBeck(LAMMPS *lmp) : Pair(lmp) {} /* ---------------------------------------------------------------------- */ diff --git a/src/pair_buck.cpp b/src/pair_buck.cpp index d829495495..989c341add 100644 --- a/src/pair_buck.cpp +++ b/src/pair_buck.cpp @@ -32,7 +32,6 @@ using namespace MathConst; PairBuck::PairBuck(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_buck_coul_cut.cpp b/src/pair_buck_coul_cut.cpp index 65925f0b33..05b36d3620 100644 --- a/src/pair_buck_coul_cut.cpp +++ b/src/pair_buck_coul_cut.cpp @@ -36,7 +36,6 @@ using namespace MathConst; PairBuckCoulCut::PairBuckCoulCut(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_coul_cut.cpp b/src/pair_coul_cut.cpp index a3653920be..44ddd424d9 100644 --- a/src/pair_coul_cut.cpp +++ b/src/pair_coul_cut.cpp @@ -28,9 +28,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -PairCoulCut::PairCoulCut(LAMMPS *lmp) : Pair(lmp) { - centroidstressflag = CENTROID_SAME; -} +PairCoulCut::PairCoulCut(LAMMPS *lmp) : Pair(lmp) {} /* ---------------------------------------------------------------------- */ diff --git a/src/pair_coul_dsf.cpp b/src/pair_coul_dsf.cpp index f9be4eac96..20bae21594 100644 --- a/src/pair_coul_dsf.cpp +++ b/src/pair_coul_dsf.cpp @@ -29,7 +29,6 @@ #include "math_const.h" #include "error.h" - using namespace LAMMPS_NS; using namespace MathConst; @@ -43,9 +42,7 @@ using namespace MathConst; /* ---------------------------------------------------------------------- */ -PairCoulDSF::PairCoulDSF(LAMMPS *lmp) : Pair(lmp) { - centroidstressflag = CENTROID_SAME; -} +PairCoulDSF::PairCoulDSF(LAMMPS *lmp) : Pair(lmp) {} /* ---------------------------------------------------------------------- */ diff --git a/src/pair_coul_wolf.cpp b/src/pair_coul_wolf.cpp index 57acf90153..4466651237 100644 --- a/src/pair_coul_wolf.cpp +++ b/src/pair_coul_wolf.cpp @@ -36,7 +36,6 @@ using namespace MathConst; PairCoulWolf::PairCoulWolf(LAMMPS *lmp) : Pair(lmp) { single_enable = 0; // NOTE: single() method below is not yet correct - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_hybrid.cpp b/src/pair_hybrid.cpp index 8f58d14e20..a62d220e7a 100644 --- a/src/pair_hybrid.cpp +++ b/src/pair_hybrid.cpp @@ -29,7 +29,6 @@ #include "suffix.h" - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -42,10 +41,6 @@ PairHybrid::PairHybrid(LAMMPS *lmp) : Pair(lmp), outerflag = 0; respaflag = 0; - - // assume pair hybrid always supports centroid atomic stress, - // so that cflag_atom gets set when needed - centroidstressflag = CENTROID_AVAIL; } /* ---------------------------------------------------------------------- */ @@ -95,12 +90,13 @@ void PairHybrid::compute(int eflag, int vflag) { int i,j,m,n; - // if no_virial_fdotr_compute is set and global component of - // incoming vflag = VIRIAL_FDOTR, then - // reset vflag as if global component were VIRIAL_PAIR + // check if no_virial_fdotr_compute is set and global component of + // incoming vflag = VIRIAL_FDOTR + // if so, reset vflag as if global component were VIRIAL_PAIR // necessary since one or more sub-styles cannot compute virial as F dot r - if (no_virial_fdotr_compute && (vflag & VIRIAL_FDOTR)) vflag = VIRIAL_PAIR | (vflag & ~VIRIAL_FDOTR); + if (no_virial_fdotr_compute && (vflag & VIRIAL_FDOTR)) + vflag = VIRIAL_PAIR | (vflag & ~VIRIAL_FDOTR); ev_init(eflag,vflag); @@ -165,10 +161,13 @@ void PairHybrid::compute(int eflag, int vflag) for (j = 0; j < 6; j++) vatom[i][j] += vatom_substyle[i][j]; } + + // substyles may be CENTROID_SAME or CENTROID_AVAIL + if (cvflag_atom) { n = atom->nlocal; if (force->newton_pair) n += atom->nghost; - if (styles[m]->centroidstressflag & CENTROID_AVAIL) { + if (styles[m]->centroidstressflag == CENTROID_AVAIL) { double **cvatom_substyle = styles[m]->cvatom; for (i = 0; i < n; i++) for (j = 0; j < 9; j++) @@ -386,6 +385,7 @@ void PairHybrid::flags() compute_flag = 0; respa_enable = 0; restartinfo = 0; + for (m = 0; m < nstyles; m++) { if (styles[m]->single_enable) ++single_enable; if (styles[m]->respa_enable) ++respa_enable; @@ -401,12 +401,26 @@ void PairHybrid::flags() if (styles[m]->dispersionflag) dispersionflag = 1; if (styles[m]->tip4pflag) tip4pflag = 1; if (styles[m]->compute_flag) compute_flag = 1; - if (styles[m]->centroidstressflag & CENTROID_NOTAVAIL) centroidstressflag |= CENTROID_NOTAVAIL; } single_enable = (single_enable == nstyles) ? 1 : 0; respa_enable = (respa_enable == nstyles) ? 1 : 0; restartinfo = (restartinfo == nstyles) ? 1 : 0; init_svector(); + + // set centroidstressflag for pair hybrid + // set to CENTROID_NOTAVAIL if any substyle is NOTAVAIL + // else set to CENTROID_AVAIL if any substyle is AVAIL + // else set to CENTROID_SAME if all substyles are SAME + + centroidstressflag = CENTROID_SAME; + + for (m = 0; m < nstyles; m++) { + if (styles[m]->centroidstressflag == CENTROID_NOTAVAIL) + centroidstressflag == CENTROID_NOTAVAIL; + if (centroidstyle == CENTROID_SAME && + styles[m]->centroidstressflag == CENTROID_AVAIL) + centroidstressflag == CENTROID_AVAIL; + } } /* ---------------------------------------------------------------------- diff --git a/src/pair_lj_cubic.cpp b/src/pair_lj_cubic.cpp index 5dd64ff6ae..7fe4757358 100644 --- a/src/pair_lj_cubic.cpp +++ b/src/pair_lj_cubic.cpp @@ -32,9 +32,7 @@ using namespace PairLJCubicConstants; /* ---------------------------------------------------------------------- */ -PairLJCubic::PairLJCubic(LAMMPS *lmp) : Pair(lmp) { - centroidstressflag = CENTROID_SAME; -} +PairLJCubic::PairLJCubic(LAMMPS *lmp) : Pair(lmp) {} /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_cut.cpp b/src/pair_lj_cut.cpp index c68c106156..32ac15da79 100644 --- a/src/pair_lj_cut.cpp +++ b/src/pair_lj_cut.cpp @@ -31,7 +31,6 @@ #include "memory.h" #include "error.h" - using namespace LAMMPS_NS; using namespace MathConst; @@ -41,7 +40,6 @@ PairLJCut::PairLJCut(LAMMPS *lmp) : Pair(lmp) { respa_enable = 1; writedata = 1; - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_cut_coul_cut.cpp b/src/pair_lj_cut_coul_cut.cpp index 97e26e78b8..9ed84bd1a4 100644 --- a/src/pair_lj_cut_coul_cut.cpp +++ b/src/pair_lj_cut_coul_cut.cpp @@ -33,7 +33,6 @@ using namespace MathConst; PairLJCutCoulCut::PairLJCutCoulCut(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_cut_coul_dsf.cpp b/src/pair_lj_cut_coul_dsf.cpp index 7d238aa720..3382ca1986 100644 --- a/src/pair_lj_cut_coul_dsf.cpp +++ b/src/pair_lj_cut_coul_dsf.cpp @@ -46,7 +46,6 @@ using namespace MathConst; PairLJCutCoulDSF::PairLJCutCoulDSF(LAMMPS *lmp) : Pair(lmp) { single_enable = 0; - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_cut_coul_wolf.cpp b/src/pair_lj_cut_coul_wolf.cpp index 0b9a3abce1..f75422b684 100644 --- a/src/pair_lj_cut_coul_wolf.cpp +++ b/src/pair_lj_cut_coul_wolf.cpp @@ -37,7 +37,6 @@ PairLJCutCoulWolf::PairLJCutCoulWolf(LAMMPS *lmp) : Pair(lmp) { single_enable = 0; writedata = 1; - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_expand.cpp b/src/pair_lj_expand.cpp index d22d7335db..bc6ef98785 100644 --- a/src/pair_lj_expand.cpp +++ b/src/pair_lj_expand.cpp @@ -32,7 +32,6 @@ using namespace MathConst; PairLJExpand::PairLJExpand(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_gromacs_coul_gromacs.cpp b/src/pair_lj_gromacs_coul_gromacs.cpp index f9726dc3d3..3f047d2334 100644 --- a/src/pair_lj_gromacs_coul_gromacs.cpp +++ b/src/pair_lj_gromacs_coul_gromacs.cpp @@ -26,7 +26,6 @@ #include "memory.h" #include "error.h" - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -34,7 +33,6 @@ using namespace LAMMPS_NS; PairLJGromacsCoulGromacs::PairLJGromacsCoulGromacs(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_smooth.cpp b/src/pair_lj_smooth.cpp index 9f51627a19..f45dbaa6bc 100644 --- a/src/pair_lj_smooth.cpp +++ b/src/pair_lj_smooth.cpp @@ -33,7 +33,6 @@ using namespace LAMMPS_NS; PairLJSmooth::PairLJSmooth(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_lj_smooth_linear.cpp b/src/pair_lj_smooth_linear.cpp index 6c7d678842..54c0f2612d 100644 --- a/src/pair_lj_smooth_linear.cpp +++ b/src/pair_lj_smooth_linear.cpp @@ -25,14 +25,12 @@ #include "memory.h" #include "error.h" - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ PairLJSmoothLinear::PairLJSmoothLinear(LAMMPS *lmp) : Pair(lmp) { single_hessian_enable = 1; - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_morse.cpp b/src/pair_morse.cpp index 08247c51d4..6c67a8ef55 100644 --- a/src/pair_morse.cpp +++ b/src/pair_morse.cpp @@ -22,7 +22,6 @@ #include "memory.h" #include "error.h" - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -30,7 +29,6 @@ using namespace LAMMPS_NS; PairMorse::PairMorse(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ diff --git a/src/pair_ufm.cpp b/src/pair_ufm.cpp index ec570c0119..8decaa42a7 100644 --- a/src/pair_ufm.cpp +++ b/src/pair_ufm.cpp @@ -28,7 +28,6 @@ #include "memory.h" #include "error.h" - using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -36,7 +35,6 @@ using namespace LAMMPS_NS; PairUFM::PairUFM(LAMMPS *lmp) : Pair(lmp) { writedata = 1; - centroidstressflag = CENTROID_SAME; } /* ---------------------------------------------------------------------- */ From 8ca690acd3c6400281092a169d83dc70ad72c12a Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Wed, 18 Nov 2020 12:22:06 -0700 Subject: [PATCH 48/67] missed one file --- src/improper.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/improper.cpp b/src/improper.cpp index b46e27bb2d..c4b691f6d5 100644 --- a/src/improper.cpp +++ b/src/improper.cpp @@ -75,12 +75,12 @@ void Improper::init() setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag set the following flags, values are otherwise 0: - evflag = 1 if any bits of eflag or vflag are set - eflag_global = 1 if ENERGY_GLOBAL bit of eflag set - eflag_atom = 1 if ENERGY_ATOM bit of eflag set - eflag_either = 1 if eflag_global or eflag_atom is set - vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set - vflag_atom = 1 if VIRIAL_ATOM bit of vflag set + evflag != 0 if any bits of eflag or vflag are set + eflag_global != 0 if ENERGY_GLOBAL bit of eflag set + eflag_atom != 0 if ENERGY_ATOM bit of eflag set + eflag_either != 0 if eflag_global or eflag_atom is set + vflag_global != 0 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom != 0 if VIRIAL_ATOM bit of vflag set vflag_atom != 0 if VIRIAL_CENTROID bit of vflag set and centroidstressflag != CENTROID_AVAIL cvflag_atom != 0 if VIRIAL_CENTROID bit of vflag set From 3ee6203e5a6c79c82217437fa071bd1781c381f9 Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Wed, 18 Nov 2020 12:51:24 -0700 Subject: [PATCH 49/67] simplification to Pair::ev_setup() --- src/pair.cpp | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/pair.cpp b/src/pair.cpp index 2cb0b2b210..bf43168407 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -779,21 +779,19 @@ void Pair::del_tally_callback(Compute *ptr) setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag set the following flags, values are otherwise 0: - evflag != 0 if any bits of eflag or vflag are set eflag_global != 0 if ENERGY_GLOBAL bit of eflag set eflag_atom != 0 if ENERGY_ATOM bit of eflag set eflag_either != 0 if eflag_global or eflag_atom is set - vflag_global = VIRIAL_PAIR if VIRIAL_PAIR bit of vflag set - vflag_global = VIRIAL_FDOTR if VIRIAL_FDOTR bit of vflag set - this setting also sets vflag_dotr = 1 if pair style supports it, - which unsets vflag_global and can also thus change other flags, - see logic at end of method + vflag_global != 0 if VIRIAL_PAIR bit of vflag set + vflag_global != 0 if VIRIAL_FDOTR bit of vflag is set but no_virial_fdotr = 1 + vflag_fdotr != 0 if VIRIAL_FDOTR bit of vflag set and no_virial_fdotr = 0 vflag_atom != 0 if VIRIAL_ATOM bit of vflag set vflag_atom != 0 if VIRIAL_CENTROID bit of vflag set and centroidstressflag != CENTROID_AVAIL cvflag_atom != 0 if VIRIAL_CENTROID bit of vflag set and centroidstressflag = CENTROID_AVAIL vflag_either != 0 if any of vflag_global, vflag_atom, cvflag_atom is set + evflag != 0 if eflag_either or vflag_either is set centroidstressflag is set by the pair style to one of these values: CENTROID_SAME = same as two-body stress CENTROID_AVAIL = different and implemented @@ -804,20 +802,20 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) { int i,n; - evflag = 1; - eflag_either = eflag; eflag_global = eflag & ENERGY_GLOBAL; eflag_atom = eflag & ENERGY_ATOM; - - vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR); + + vflag_global = vflag & VIRIAL_PAIR; + if (vflag & VIRIAL_FDOTR && no_virial_fdotr_compute == 1) vflag_global = 1; + if (vflag & VIRIAL_FDOTR && no_virial_fdotr_compute == 0) vflag_fdotr = 1; vflag_atom = vflag & VIRIAL_ATOM; - if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) - vflag_atom = 1; - if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) - cvflag_atom = 1; + if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) vflag_atom = 1; + if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) cvflag_atom = 1; vflag_either = vflag_global || vflag_atom || cvflag_atom; + evflag = eflag_either || vflag_either; + // reallocate per-atom arrays if necessary if (eflag_atom && atom->nmax > maxeatom) { @@ -882,17 +880,6 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) } } - // if vflag_global = VIRIAL_FDOTR and pair::compute() calls virial_fdotr_compute() - // compute global virial via (F dot r) instead of via pairwise summation - // unset other flags as appropriate - - if (vflag_global == VIRIAL_FDOTR && no_virial_fdotr_compute == 0) { - vflag_fdotr = 1; - vflag_global = 0; - if (!vflag_atom == 0 && !cvflag_atom) vflag_either = 0; - if (!vflag_either == 0 && !eflag_either) evflag = 0; - } else vflag_fdotr = 0; - // run ev_setup option for USER-TALLY computes if (num_tally_compute > 0) { @@ -1575,6 +1562,8 @@ void Pair::virial_fdotr_compute() double **x = atom->x; double **f = atom->f; + for (int i = 0; i < 6; i++) virial[i] = 0.0; + // sum over force on all particles including ghosts if (neighbor->includegroup == 0) { From 006fae0ee1ddbd7439fc502172054bf2aac925c8 Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Wed, 18 Nov 2020 12:52:59 -0700 Subject: [PATCH 50/67] one more optimization --- src/pair.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pair.cpp b/src/pair.cpp index bf43168407..ec7bd8d94f 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -815,7 +815,8 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) vflag_either = vflag_global || vflag_atom || cvflag_atom; evflag = eflag_either || vflag_either; - + if (!evflag) return; + // reallocate per-atom arrays if necessary if (eflag_atom && atom->nmax > maxeatom) { From c62c907281a461d9934d29b190b14e1626581de6 Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Wed, 18 Nov 2020 13:02:07 -0700 Subject: [PATCH 51/67] doc string tweak --- src/pair_hybrid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pair_hybrid.cpp b/src/pair_hybrid.cpp index a62d220e7a..64c7e599b5 100644 --- a/src/pair_hybrid.cpp +++ b/src/pair_hybrid.cpp @@ -101,7 +101,7 @@ void PairHybrid::compute(int eflag, int vflag) ev_init(eflag,vflag); // check if global component of incoming vflag = VIRIAL_FDOTR - // if so, reset vflag passed to substyle as if it were VIRIAL_NONE + // if so, reset vflag passed to substyle so VIRIAL_FDOTR is turned off // necessary so substyle will not invoke virial_fdotr_compute() int vflag_substyle; From 5691ec3dfdfeab73930f5efc0a81ac0124c44d75 Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Wed, 18 Nov 2020 15:05:11 -0700 Subject: [PATCH 52/67] insure cvflag is zero, other tweaks --- src/MOLECULE/fix_cmap.cpp | 3 +-- src/POEMS/fix_poems.cpp | 1 + src/USER-MISC/pair_agni.cpp | 1 + src/angle.cpp | 3 ++- src/bond.cpp | 2 +- src/compute_centroid_stress_atom.cpp | 13 +++++++------ src/dihedral.cpp | 3 ++- src/force.h | 6 +++--- src/improper.cpp | 3 ++- src/kspace.cpp | 5 +++-- src/pair.cpp | 3 ++- src/pair_hybrid.cpp | 2 +- 12 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/MOLECULE/fix_cmap.cpp b/src/MOLECULE/fix_cmap.cpp index ab5c0a7323..f48d5254cf 100644 --- a/src/MOLECULE/fix_cmap.cpp +++ b/src/MOLECULE/fix_cmap.cpp @@ -42,8 +42,6 @@ #include "memory.h" #include "error.h" - - using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; @@ -74,6 +72,7 @@ FixCMAP::FixCMAP(LAMMPS *lmp, int narg, char **arg) : restart_peratom = 1; peatom_flag = 1; virial_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; thermo_virial = 1; peratom_freq = 1; scalar_flag = 1; diff --git a/src/POEMS/fix_poems.cpp b/src/POEMS/fix_poems.cpp index fb39c21f2a..a220216fdd 100644 --- a/src/POEMS/fix_poems.cpp +++ b/src/POEMS/fix_poems.cpp @@ -74,6 +74,7 @@ FixPOEMS::FixPOEMS(LAMMPS *lmp, int narg, char **arg) : time_integrate = 1; rigid_flag = 1; virial_flag = 1; + centroidstressflag = CENTROID_NOTAVAIL; thermo_virial = 1; dof_flag = 1; diff --git a/src/USER-MISC/pair_agni.cpp b/src/USER-MISC/pair_agni.cpp index c9f6aff689..afb457d9e4 100644 --- a/src/USER-MISC/pair_agni.cpp +++ b/src/USER-MISC/pair_agni.cpp @@ -20,6 +20,7 @@ #include "atom.h" #include "citeme.h" #include "comm.h" +#include "force.h" #include "error.h" #include "math_const.h" #include "math_special.h" diff --git a/src/angle.cpp b/src/angle.cpp index 25eab2b752..110719d432 100644 --- a/src/angle.cpp +++ b/src/angle.cpp @@ -77,7 +77,7 @@ void Angle::init() /* ---------------------------------------------------------------------- setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag - set the following flags, values are otherwise 0: + set the following flags, values are otherwise set to 0: evflag != 0 if any bits of eflag or vflag are set eflag_global != 0 if ENERGY_GLOBAL bit of eflag set eflag_atom != 0 if ENERGY_ATOM bit of eflag set @@ -105,6 +105,7 @@ void Angle::ev_setup(int eflag, int vflag, int alloc) vflag_atom = vflag & VIRIAL_ATOM; if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) vflag_atom = 1; + cvflag_atom = 0; if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) cvflag_atom = 1; vflag_either = vflag_global || vflag_atom || cvflag_atom; diff --git a/src/bond.cpp b/src/bond.cpp index 89265915fb..16d3c43dea 100644 --- a/src/bond.cpp +++ b/src/bond.cpp @@ -81,7 +81,7 @@ void Bond::init() /* ---------------------------------------------------------------------- setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag - set the following flags, values are otherwise 0: + set the following flags, values are otherwise set to 0: evflag != 0 if any bits of eflag or vflag are set eflag_global != 0 if ENERGY_GLOBAL bit of eflag set eflag_atom != 0 if ENERGY_ATOM bit of eflag set diff --git a/src/compute_centroid_stress_atom.cpp b/src/compute_centroid_stress_atom.cpp index 15be95bee1..3de2c3dada 100644 --- a/src/compute_centroid_stress_atom.cpp +++ b/src/compute_centroid_stress_atom.cpp @@ -222,6 +222,7 @@ void ComputeCentroidStressAtom::compute_peratom() // per-atom virial and per-atom centroid virial are the same for bonds // bond styles are all CENTROID_SAME // all other styles are CENTROID_AVAIL or CENTROID_NOTAVAIL + // add KSpace when it becomes supported if (bondflag && force->bond) { double **vatom = force->bond->vatom; @@ -254,12 +255,12 @@ void ComputeCentroidStressAtom::compute_peratom() stress[i][j] += cvatom[i][j]; } - if (kspaceflag && force->kspace && force->kspace->compute_flag) { - double **vatom = force->kspace->vatom; - for (i = 0; i < nkspace; i++) - for (j = 0; j < 9; j++) - stress[i][j] += cvatom[i][j]; - } + //if (kspaceflag && force->kspace && force->kspace->compute_flag) { + // double **vatom = force->kspace->vatom; + // for (i = 0; i < nkspace; i++) + // for (j = 0; j < 9; j++) + // stress[i][j] += cvatom[i][j]; + // } // add in per-atom contributions from relevant fixes // skip if vatom = nullptr diff --git a/src/dihedral.cpp b/src/dihedral.cpp index 68c69fa787..4680b6f67d 100644 --- a/src/dihedral.cpp +++ b/src/dihedral.cpp @@ -76,7 +76,7 @@ void Dihedral::init() /* ---------------------------------------------------------------------- setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag - set the following flags, values are otherwise 0: + set the following flags, values are otherwise set to 0: evflag != 0 if any bits of eflag or vflag are set eflag_global != 0 if ENERGY_GLOBAL bit of eflag set eflag_atom != 0 if ENERGY_ATOM bit of eflag set @@ -104,6 +104,7 @@ void Dihedral::ev_setup(int eflag, int vflag, int alloc) vflag_atom = vflag & VIRIAL_ATOM; if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) vflag_atom = 1; + cvflag_atom = 0; if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) cvflag_atom = 1; vflag_either = vflag_global || vflag_atom || cvflag_atom; diff --git a/src/force.h b/src/force.h index 9be26bd2a7..b087b8e187 100644 --- a/src/force.h +++ b/src/force.h @@ -41,9 +41,9 @@ enum { }; enum { - CENTROID_SAME = 0x01, - CENTROID_AVAIL = 0x02, - CENTROID_NOTAVAIL = 0x04 + CENTROID_SAME = 0, + CENTROID_AVAIL = 1, + CENTROID_NOTAVAIL = 2 }; class Force : protected Pointers { diff --git a/src/improper.cpp b/src/improper.cpp index c4b691f6d5..6e0f829733 100644 --- a/src/improper.cpp +++ b/src/improper.cpp @@ -74,7 +74,7 @@ void Improper::init() /* ---------------------------------------------------------------------- setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag - set the following flags, values are otherwise 0: + set the following flags, values are otherwise set to 0: evflag != 0 if any bits of eflag or vflag are set eflag_global != 0 if ENERGY_GLOBAL bit of eflag set eflag_atom != 0 if ENERGY_ATOM bit of eflag set @@ -102,6 +102,7 @@ void Improper::ev_setup(int eflag, int vflag, int alloc) vflag_atom = vflag & VIRIAL_ATOM; if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) vflag_atom = 1; + cvflag_atom = 0; if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) cvflag_atom = 1; vflag_either = vflag_global || vflag_atom || cvflag_atom; diff --git a/src/kspace.cpp b/src/kspace.cpp index a6dd5fdffb..594fd1ba8d 100644 --- a/src/kspace.cpp +++ b/src/kspace.cpp @@ -88,7 +88,7 @@ KSpace::KSpace(LAMMPS *lmp) : Pointers(lmp) maxeatom = maxvatom = 0; eatom = nullptr; vatom = nullptr; - centroidstressatom = NOTAVAIL; + centroidstressflag = CENTROID_NOTAVAIL; execution_space = Host; datamask_read = ALL_MASK; @@ -216,7 +216,7 @@ void KSpace::pair_check() /* ---------------------------------------------------------------------- setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag - set the following flags, values are otherwise 0: + set the following flags, values are otherwise set to 0: evflag != 0 if any bits of eflag or vflag are set eflag_global != 0 if ENERGY_GLOBAL bit of eflag set eflag_atom != 0 if ENERGY_ATOM bit of eflag set @@ -225,6 +225,7 @@ void KSpace::pair_check() vflag_atom != 0 if VIRIAL_ATOM bit of vflag set no current support for centroid stress vflag_either != 0 if vflag_global or vflag_atom is set + evflag_atom != 0 if eflag_atom or vflag_atom is set ------------------------------------------------------------------------- */ void KSpace::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/pair.cpp b/src/pair.cpp index ec7bd8d94f..74a03fbed9 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -778,7 +778,7 @@ void Pair::del_tally_callback(Compute *ptr) /* ---------------------------------------------------------------------- setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag - set the following flags, values are otherwise 0: + set the following flags, values are otherwise set to 0: eflag_global != 0 if ENERGY_GLOBAL bit of eflag set eflag_atom != 0 if ENERGY_ATOM bit of eflag set eflag_either != 0 if eflag_global or eflag_atom is set @@ -811,6 +811,7 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) if (vflag & VIRIAL_FDOTR && no_virial_fdotr_compute == 0) vflag_fdotr = 1; vflag_atom = vflag & VIRIAL_ATOM; if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) vflag_atom = 1; + cvflag_atom = 0; if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) cvflag_atom = 1; vflag_either = vflag_global || vflag_atom || cvflag_atom; diff --git a/src/pair_hybrid.cpp b/src/pair_hybrid.cpp index 64c7e599b5..41c90942b7 100644 --- a/src/pair_hybrid.cpp +++ b/src/pair_hybrid.cpp @@ -417,7 +417,7 @@ void PairHybrid::flags() for (m = 0; m < nstyles; m++) { if (styles[m]->centroidstressflag == CENTROID_NOTAVAIL) centroidstressflag == CENTROID_NOTAVAIL; - if (centroidstyle == CENTROID_SAME && + if (centroidstressflag == CENTROID_SAME && styles[m]->centroidstressflag == CENTROID_AVAIL) centroidstressflag == CENTROID_AVAIL; } From 6d0c8e71de6dd3d2b760ad237b4aee41962260ce Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 18 Nov 2020 17:51:04 -0500 Subject: [PATCH 53/67] Correct assignment of centroidstressflag --- src/pair_hybrid.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pair_hybrid.cpp b/src/pair_hybrid.cpp index 41c90942b7..07206dc518 100644 --- a/src/pair_hybrid.cpp +++ b/src/pair_hybrid.cpp @@ -416,10 +416,10 @@ void PairHybrid::flags() for (m = 0; m < nstyles; m++) { if (styles[m]->centroidstressflag == CENTROID_NOTAVAIL) - centroidstressflag == CENTROID_NOTAVAIL; + centroidstressflag = CENTROID_NOTAVAIL; if (centroidstressflag == CENTROID_SAME && styles[m]->centroidstressflag == CENTROID_AVAIL) - centroidstressflag == CENTROID_AVAIL; + centroidstressflag = CENTROID_AVAIL; } } From 9ea025295dd02683a7d3419c9b3db0172cc856a8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 19 Nov 2020 11:33:15 -0500 Subject: [PATCH 54/67] need to define LAMMPS_LIB_MPI to make `lammps_open()` visible --- unittest/c-library/test_library_mpi.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp index 36c386144c..a1780f4043 100644 --- a/unittest/c-library/test_library_mpi.cpp +++ b/unittest/c-library/test_library_mpi.cpp @@ -1,5 +1,6 @@ // unit tests for checking LAMMPS configuration settings through the library interface +#define LAMMPS_LIB_MPI 1 #include "lammps.h" #include "library.h" #include "timer.h" From 3d7fd453c3cba42190753e1c547fc3ff6e0100cc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 19 Nov 2020 13:47:23 -0500 Subject: [PATCH 55/67] allow extracting variables that are not atom or equal style compatible --- src/library.cpp | 52 ++++++++++++++++++++++++++++--------------------- src/library.h | 2 +- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index b98e439aa7..b0c6d3649c 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -1811,36 +1811,44 @@ void *lammps_extract_fix(void *handle, char *id, int style, int type, \verbatim embed:rst This function returns a pointer to data from a LAMMPS :doc:`variable` -identified by its name. The variable must be either an *equal*\ -style -compatible or an *atom*\ -style variable. Variables of style *internal* +identified by its name. When the variable is either an *equal*\ -style +compatible or an *atom*\ -style variable the variable is evaluated and +the corresponding value(s) returned. Variables of style *internal* are compatible with *equal*\ -style variables and so are *python*\ --style variables, if they return a numeric value. The function returns +-style variables, if they return a numeric value. For other +variable styles their string value is returned. The function returns ``NULL`` when a variable of the provided *name* is not found or of an incompatible style. The *group* argument is only used for *atom*\ -style variables and ignored otherwise. If set to ``NULL`` when extracting data from and *atom*\ -style variable, the group is assumed to be "all". -.. note:: +When requesting data from an *equal*\ -style or compatible variable +this function allocates storage for a single double value, copies the +returned value to it, and returns a pointer to the location of the +copy. Therefore the allocated storage needs to be freed after its +use to avoid a memory leak. Example: - When requesting data from an *equal*\ -style or compatible variable - this function allocates storage for a single double value, copies the - returned value to it, and returns a pointer to the location of the - copy. Therefore the allocated storage needs to be freed after its - use to avoid a memory leak. Example: +.. code-block:: c - .. code-block:: c + double *dptr = (double *) lammps_extract_variable(handle,name,NULL); + double value = *dptr; + lammps_free((void *)dptr); - double *dptr = (double *) lammps_extract_variable(handle,name,NULL); - double value = *dptr; - lammps_free((void *)dptr); +For *atom*\ -style variables the data returned is a pointer to an +allocated block of storage of double of the length ``atom->nlocal``. +Since the data is returned a copy, the location will persist, but its +content will not be updated, in case the variable is re-evaluated. +To avoid a memory leak this pointer needs to be freed after use in +the calling program. - For *atom*\ -style variables the data returned is a pointer to an - allocated block of storage of double of the length ``atom->nlocal``. - To avoid a memory leak, also this pointer needs to be freed after use. +For other variable styles the returned pointer needs to be cast to +a char pointer. -Since the data is returned as copies, the location will persist, but its -values will not be updated, in case the variable is re-evaluated. +.. code-block:: c + + const char *cptr = (const char *) lammps_extract_variable(handle,name,NULL); + printf("The value of variable %s is %s\n", name, cptr); .. note:: @@ -1858,7 +1866,7 @@ values will not be updated, in case the variable is re-evaluated. * \return pointer (cast to ``void *``) to the location of the * requested data or ``NULL`` if not found. */ -void *lammps_extract_variable(void *handle, char *name, char *group) +void *lammps_extract_variable(void *handle, const char *name, const char *group) { LAMMPS *lmp = (LAMMPS *) handle; @@ -1871,9 +1879,7 @@ void *lammps_extract_variable(void *handle, char *name, char *group) double *dptr = (double *) malloc(sizeof(double)); *dptr = lmp->input->variable->compute_equal(ivar); return (void *) dptr; - } - - if (lmp->input->variable->atomstyle(ivar)) { + } else if (lmp->input->variable->atomstyle(ivar)) { if (group == nullptr) group = (char *)"all"; int igroup = lmp->group->find(group); if (igroup < 0) return nullptr; @@ -1881,6 +1887,8 @@ void *lammps_extract_variable(void *handle, char *name, char *group) double *vector = (double *) malloc(nlocal*sizeof(double)); lmp->input->variable->compute_atom(ivar,igroup,vector,1,0); return (void *) vector; + } else { + return lmp->input->variable->retrieve(name); } } END_CAPTURE diff --git a/src/library.h b/src/library.h index a38ea2dc82..7806903e49 100644 --- a/src/library.h +++ b/src/library.h @@ -140,7 +140,7 @@ void *lammps_extract_atom(void *handle, const char *name); void *lammps_extract_compute(void *handle, char *id, int, int); void *lammps_extract_fix(void *handle, char *, int, int, int, int); -void *lammps_extract_variable(void *handle, char *, char *); +void *lammps_extract_variable(void *handle, const char *, const char *); int lammps_set_variable(void *, char *, char *); /* ---------------------------------------------------------------------- From 949274a2a4c37eb6b159907db21c0a70f5310440 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 19 Nov 2020 13:48:28 -0500 Subject: [PATCH 56/67] refactor handling of partition arguments so it does not modify the string passed --- src/universe.cpp | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/universe.cpp b/src/universe.cpp index 4abaa5fa1c..3f58c4a074 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -158,7 +158,6 @@ void Universe::reorder(char *style, char *arg) void Universe::add_world(char *str) { int n,nper; - char *ptr; n = 1; nper = 0; @@ -171,28 +170,23 @@ void Universe::add_world(char *str) // str may not be empty and may only consist of digits or 'x' - size_t len = strlen(str); - if (len < 1) valid = false; - for (size_t i=0; i < len; ++i) - if (isdigit(str[i]) || str[i] == 'x') continue; - else valid = false; + std::string part(str); + if (part.size() == 0) valid = false; + if (part.find_first_not_of("0123456789x") != std::string::npos) valid = false; if (valid) { - if ((ptr = strchr(str,'x')) != nullptr) { + std::size_t found = part.find_first_of("x"); - // 'x' may not be the first or last character + // 'x' may not be the first or last character - if (ptr == str) { - valid = false; - } else if (strlen(str) == len-1) { - valid = false; - } else { - *ptr = '\0'; - n = atoi(str); - nper = atoi(ptr+1); - *ptr = 'x'; - } - } else nper = atoi(str); + if ((found == 0) || (found == (part.size() - 1))) { + valid = false; + } else if (found == std::string::npos) { + nper = atoi(part.c_str()); + } else { + n = atoi(part.substr(0,found).c_str()); + nper = atoi(part.substr(found-1).c_str());\ + } } // require minimum of 1 partition with 1 processor From c7247aaaafe3a2a00ff8cddaf4587d5cd2bf0cfe Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 19 Nov 2020 13:49:10 -0500 Subject: [PATCH 57/67] provide access to universe and world size and rank information. and number of OpenMP threads --- src/library.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/library.cpp b/src/library.cpp index b0c6d3649c..0a8e70bc95 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -839,9 +839,19 @@ not recognized, the function returns -1. * - box_exist - 1 if the simulation box is defined, 0 if not. See :doc:`create_box`. + * - nthreads + - Number of requested OpenMP threads for LAMMPS' execution * - triclinic - 1 if the the simulation box is triclinic, 0 if orthogonal. See :doc:`change_box`. + * - universe_rank + - MPI rank on LAMMPS' universe communicator (0 <= universe_rank < universe_size) + * - universe_size + - Number of ranks on LAMMPS' universe communicator (world_size <= universe_size) + * - world_rank + - MPI rank on LAMMPS' world communicator (0 <= world_rank < world_size) + * - world_size + - Number of ranks on LAMMPS' world communicator .. _extract_system_sizes: @@ -925,6 +935,12 @@ int lammps_extract_setting(void *handle, const char *keyword) if (strcmp(keyword,"box_exist") == 0) return lmp->domain->box_exist; if (strcmp(keyword,"triclinic") == 0) return lmp->domain->triclinic; + if (strcmp(keyword,"universe_rank") == 0) return lmp->universe->me; + if (strcmp(keyword,"universe_size") == 0) return lmp->universe->nprocs; + if (strcmp(keyword,"world_rank") == 0) return lmp->comm->me; + if (strcmp(keyword,"world_size") == 0) return lmp->comm->nprocs; + if (strcmp(keyword,"nthreads") == 0) return lmp->comm->nthreads; + if (strcmp(keyword,"nlocal") == 0) return lmp->atom->nlocal; if (strcmp(keyword,"nghost") == 0) return lmp->atom->nghost; if (strcmp(keyword,"nall") == 0) return lmp->atom->nlocal+lmp->atom->nghost; From 6acc69ddd2a180723666de23bae37ab01c316b7e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 19 Nov 2020 13:51:32 -0500 Subject: [PATCH 58/67] reformat with clang-format --- unittest/c-library/test_library_mpi.cpp | 122 ++++++++++++------------ 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp index a1780f4043..f6aca0d89b 100644 --- a/unittest/c-library/test_library_mpi.cpp +++ b/unittest/c-library/test_library_mpi.cpp @@ -27,18 +27,17 @@ TEST(MPI, global_box) double boxlo[3]; double boxhi[3]; - double xy = 0.0; - double yz = 0.0; - double xz = 0.0; + double xy = 0.0; + double yz = 0.0; + double xz = 0.0; int pflags[3]; int boxflag; ::testing::internal::CaptureStdout(); - const char *args[] = {"LAMMPS_test", "-log", "none", - "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - void * lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); + const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); + void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); lammps_command(lmp, "units lj"); lammps_command(lmp, "atom_style atomic"); lammps_command(lmp, "region box block 0 2 0 2 0 2"); @@ -71,18 +70,17 @@ TEST(MPI, sub_box) double boxlo[3]; double boxhi[3]; - double xy = 0.0; - double yz = 0.0; - double xz = 0.0; + double xy = 0.0; + double yz = 0.0; + double xz = 0.0; int pflags[3]; int boxflag; ::testing::internal::CaptureStdout(); - const char *args[] = {"LAMMPS_test", "-log", "none", - "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - void * lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); + const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); + void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); lammps_command(lmp, "units lj"); lammps_command(lmp, "atom_style atomic"); lammps_command(lmp, "region box block 0 2 0 2 0 2"); @@ -99,8 +97,8 @@ TEST(MPI, sub_box) EXPECT_EQ(boxhi[1], 2.0); EXPECT_EQ(boxhi[2], 2.0); - double * sublo = (double*)lammps_extract_global(lmp, "sublo"); - double * subhi = (double*)lammps_extract_global(lmp, "subhi"); + double *sublo = (double *)lammps_extract_global(lmp, "sublo"); + double *subhi = (double *)lammps_extract_global(lmp, "subhi"); ASSERT_NE(sublo, nullptr); ASSERT_NE(subhi, nullptr); @@ -119,26 +117,25 @@ TEST(MPI, sub_box) class MPITest : public ::testing::Test { public: - void command(const std::string &line) { - lammps_command(lmp, line.c_str()); - } + void command(const std::string &line) { lammps_command(lmp, line.c_str()); } protected: - const char * testbinary = "LAMMPSTest"; + const char *testbinary = "LAMMPSTest"; void *lmp; void SetUp() override { - const char *args[] = { testbinary, "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); if (!verbose) ::testing::internal::CaptureStdout(); lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); InitSystem(); if (!verbose) ::testing::internal::GetCapturedStdout(); } - virtual void InitSystem() { + virtual void InitSystem() + { command("units lj"); command("atom_style atomic"); command("atom_modify map yes"); @@ -169,78 +166,81 @@ protected: #if !defined(LAMMPS_BIGBIG) -TEST_F(MPITest, gather) { +TEST_F(MPITest, gather) +{ int64_t natoms = (int64_t)lammps_get_natoms(lmp); ASSERT_EQ(natoms, 32); - int * p_nlocal = (int*)lammps_extract_global(lmp, "nlocal"); - int nlocal = *p_nlocal; + int *p_nlocal = (int *)lammps_extract_global(lmp, "nlocal"); + int nlocal = *p_nlocal; EXPECT_LT(nlocal, 32); EXPECT_EQ(nlocal, 8); // get the entire x on all procs - double * x = new double[natoms * 3]; - lammps_gather(lmp, (char*)"x", 1, 3, x); + double *x = new double[natoms * 3]; + lammps_gather(lmp, (char *)"x", 1, 3, x); - int * tag = (int*)lammps_extract_atom(lmp, "id"); - double ** x_local = (double**)lammps_extract_atom(lmp, "x"); + int *tag = (int *)lammps_extract_atom(lmp, "id"); + double **x_local = (double **)lammps_extract_atom(lmp, "x"); // each proc checks its local atoms - for(int i = 0; i < nlocal; i++) { - int64_t j = tag[i]-1; - double * x_i = x_local[i]; - double * x_g = &x[j*3]; + for (int i = 0; i < nlocal; i++) { + int64_t j = tag[i] - 1; + double *x_i = x_local[i]; + double *x_g = &x[j * 3]; EXPECT_DOUBLE_EQ(x_g[0], x_i[0]); EXPECT_DOUBLE_EQ(x_g[1], x_i[1]); EXPECT_DOUBLE_EQ(x_g[2], x_i[2]); } - delete [] x; + delete[] x; } -TEST_F(MPITest, scatter) { - int * p_nlocal = (int*)lammps_extract_global(lmp, "nlocal"); - int nlocal = *p_nlocal; - double * x_orig = new double[3*nlocal]; - double ** x_local = (double**)lammps_extract_atom(lmp, "x"); +TEST_F(MPITest, scatter) +{ + int *p_nlocal = (int *)lammps_extract_global(lmp, "nlocal"); + int nlocal = *p_nlocal; + double *x_orig = new double[3 * nlocal]; + double **x_local = (double **)lammps_extract_atom(lmp, "x"); // make copy of original local x vector - for(int i = 0; i < nlocal; i++) { - int j = 3*i; - x_orig[j] = x_local[i][0]; + for (int i = 0; i < nlocal; i++) { + int j = 3 * i; + x_orig[j] = x_local[i][0]; x_orig[j + 1] = x_local[i][1]; x_orig[j + 2] = x_local[i][2]; } // get the entire x on all procs int64_t natoms = (int64_t)lammps_get_natoms(lmp); - double * x = new double[natoms * 3]; - lammps_gather(lmp, (char*)"x", 1, 3, x); + double *x = new double[natoms * 3]; + lammps_gather(lmp, (char *)"x", 1, 3, x); // shift all coordinates by 0.001 const double delta = 0.001; - for(int64_t i = 0; i < 3*natoms; i++) x[i] += delta; + for (int64_t i = 0; i < 3 * natoms; i++) + x[i] += delta; // update positions of all atoms - lammps_scatter(lmp, (char*)"x", 1, 3, x); - delete [] x; + lammps_scatter(lmp, (char *)"x", 1, 3, x); + delete[] x; x = nullptr; // get new nlocal and x_local - p_nlocal = (int*)lammps_extract_global(lmp, "nlocal"); - nlocal = *p_nlocal; - x_local = (double**)lammps_extract_atom(lmp, "x"); + p_nlocal = (int *)lammps_extract_global(lmp, "nlocal"); + nlocal = *p_nlocal; + x_local = (double **)lammps_extract_atom(lmp, "x"); ASSERT_EQ(nlocal, 8); // each proc checks its local atoms for shift - for(int i = 0; i < nlocal; i++) { - double * x_a = x_local[i]; - double * x_b = &x_orig[i*3]; - EXPECT_DOUBLE_EQ(x_a[0], x_b[0]+delta); - EXPECT_DOUBLE_EQ(x_a[1], x_b[1]+delta); - EXPECT_DOUBLE_EQ(x_a[2], x_b[2]+delta); + for (int i = 0; i < nlocal; i++) { + double *x_a = x_local[i]; + double *x_b = &x_orig[i * 3]; + EXPECT_DOUBLE_EQ(x_a[0], x_b[0] + delta); + EXPECT_DOUBLE_EQ(x_a[1], x_b[1] + delta); + EXPECT_DOUBLE_EQ(x_a[2], x_b[2] + delta); } - delete [] x_orig; + delete[] x_orig; } #endif From 7450d9547ac88ff7e1a36fbfc28394c4818b8227 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 19 Nov 2020 13:52:26 -0500 Subject: [PATCH 59/67] add tests for accessing world/universe size and rank with different MPI settings --- unittest/c-library/test_library_mpi.cpp | 82 +++++++++++++++++++ .../c-library/test_library_properties.cpp | 6 ++ 2 files changed, 88 insertions(+) diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp index f6aca0d89b..029af72c84 100644 --- a/unittest/c-library/test_library_mpi.cpp +++ b/unittest/c-library/test_library_mpi.cpp @@ -115,6 +115,78 @@ TEST(MPI, sub_box) ::testing::internal::GetCapturedStdout(); }; +TEST(MPI, split_comm) +{ + int nprocs, me, color, key; + MPI_Comm newcomm; + lammps_mpi_init(); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &me); + color = me % 2; + key = me; + + MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm); + + const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); + void *lmp = lammps_open(argc, argv, newcomm, nullptr); + lammps_command(lmp, "units lj"); + lammps_command(lmp, "atom_style atomic"); + lammps_command(lmp, "region box block 0 2 0 2 0 2"); + lammps_command(lmp, "create_box 1 box"); + + MPI_Comm_size(newcomm, &nprocs); + MPI_Comm_rank(newcomm, &me); + EXPECT_EQ(nprocs, 2); + EXPECT_GT(me, -1); + EXPECT_LT(me, 2); + EXPECT_EQ(lammps_extract_setting(lmp, "universe_size"), nprocs); + EXPECT_EQ(lammps_extract_setting(lmp, "universe_rank"), me); + EXPECT_EQ(lammps_extract_setting(lmp, "world_size"), nprocs); + EXPECT_EQ(lammps_extract_setting(lmp, "world_rank"), me); + + lammps_close(lmp); +}; + +TEST(MPI, multi_partition) +{ + FILE *fp; + int nprocs, me; + lammps_mpi_init(); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &me); + fp = fopen("in.mp_dummy", "w"); + fclose(fp); + + const char *args[] = {"LAMMPS_test", "-log", "none", "-partition", "2x2", + "-echo", "screen", "-nocite", "-in", "in.mp_dummy"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); + void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); + + lammps_command(lmp, "units lj"); + lammps_command(lmp, "atom_style atomic"); + lammps_command(lmp, "region box block 0 2 0 2 0 2"); + lammps_command(lmp, "create_box 1 box"); + lammps_command(lmp, "variable partition universe 1 2"); + + EXPECT_EQ(lammps_extract_setting(lmp, "universe_size"), nprocs); + EXPECT_EQ(lammps_extract_setting(lmp, "universe_rank"), me); + EXPECT_EQ(lammps_extract_setting(lmp, "world_size"), nprocs / 2); + EXPECT_EQ(lammps_extract_setting(lmp, "world_rank"), me % 2); + + char *part_id = (char *)lammps_extract_variable(lmp, "partition", nullptr); + if (me < 2) { + ASSERT_THAT(part_id, StrEq("1")); + } else { + ASSERT_THAT(part_id, StrEq("2")); + } + + lammps_close(lmp); + unlink("in.mp_dummy"); +}; + class MPITest : public ::testing::Test { public: void command(const std::string &line) { lammps_command(lmp, line.c_str()); } @@ -164,6 +236,16 @@ protected: } }; +TEST_F(MPITest, size_rank) +{ + int nprocs, me; + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &me); + + EXPECT_EQ(nprocs, lammps_extract_setting(lmp, "world_size")); + EXPECT_EQ(me, lammps_extract_setting(lmp, "world_rank")); +} + #if !defined(LAMMPS_BIGBIG) TEST_F(MPITest, gather) diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 8f5d3284a1..9ec87b9234 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -199,6 +199,12 @@ TEST_F(LibraryProperties, setting) lammps_command(lmp, "dimension 3"); if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_extract_setting(lmp, "world_size"), 1); + EXPECT_EQ(lammps_extract_setting(lmp, "world_rank"), 0); + EXPECT_EQ(lammps_extract_setting(lmp, "universe_size"), 1); + EXPECT_EQ(lammps_extract_setting(lmp, "universe_rank"), 0); + EXPECT_GT(lammps_extract_setting(lmp, "nthreads"), 0); + EXPECT_EQ(lammps_extract_setting(lmp, "ntypes"), 0); EXPECT_EQ(lammps_extract_setting(lmp, "nbondtypes"), 0); EXPECT_EQ(lammps_extract_setting(lmp, "nangletypes"), 0); From 371b1a80e3e603607df19e783aa0c003af18b070 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 19 Nov 2020 18:58:21 -0500 Subject: [PATCH 60/67] add support for '-in none' for multi-partition runs from the library interface --- doc/src/Run_options.rst | 19 +++++++++++-------- src/input.cpp | 7 +++++++ src/lammps.cpp | 13 ++++++++----- unittest/c-library/test_library_mpi.cpp | 5 +---- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/doc/src/Run_options.rst b/doc/src/Run_options.rst index f5435ec3a9..9c269e552f 100644 --- a/doc/src/Run_options.rst +++ b/doc/src/Run_options.rst @@ -62,15 +62,18 @@ used. **-in file** -Specify a file to use as an input script. This is an optional switch -when running LAMMPS in one-partition mode. If it is not specified, -LAMMPS reads its script from standard input, typically from a script -via I/O redirection; e.g. lmp_linux < in.run. I/O redirection should -also work in parallel, but if it does not (in the unlikely case that -an MPI implementation does not support it), then use the -in flag. +Specify a file to use as an input script. This is an optional but +recommended switch when running LAMMPS in one-partition mode. If it +is not specified, LAMMPS reads its script from standard input, typically +from a script via I/O redirection; e.g. lmp_linux < in.run. +With many MPI implementations I/O redirection also works in parallel, +but using the -in flag will always work. + Note that this is a required switch when running LAMMPS in multi-partition mode, since multiple processors cannot all read from -stdin. +stdin concurrently. The file name may be "none" for starting +multi-partition calculations without reading an initial input file +from the library interface. ---------- @@ -296,7 +299,7 @@ command-line option. **-pscreen file** Specify the base name for the partition screen file, so partition N -writes screen information to file.N. If file is none, then no +writes screen information to file.N. If file is "none", then no partition screen files are created. This overrides the filename specified in the -screen command-line option. This option is useful when working with large numbers of partitions, allowing the partition diff --git a/src/input.cpp b/src/input.cpp index c907a16c9d..abdc3775ce 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -189,8 +189,15 @@ void Input::file() // if line ends in continuation char '&', concatenate next line if (me == 0) { + m = 0; while (1) { + + if (infile == nullptr) { + n = 0; + break; + } + if (maxline-m < 2) reallocate(line,maxline,0); // end of file reached, so break diff --git a/src/lammps.cpp b/src/lammps.cpp index ff0df97105..102d2f18cf 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -456,6 +456,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : if (universe->me == 0) { if (inflag == 0) infile = stdin; + else if (strcmp(arg[inflag], "none") == 0) infile = stdin; else infile = fopen(arg[inflag],"r"); if (infile == nullptr) error->one(FLERR,fmt::format("Cannot open input script {}: {}", @@ -530,10 +531,12 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : str, utils::getsyserror())); } - infile = fopen(arg[inflag],"r"); - if (infile == nullptr) - error->one(FLERR,fmt::format("Cannot open input script {}: {}", - arg[inflag], utils::getsyserror())); + if (strcmp(arg[inflag], "none") != 0) { + infile = fopen(arg[inflag],"r"); + if (infile == nullptr) + error->one(FLERR,fmt::format("Cannot open input script {}: {}", + arg[inflag], utils::getsyserror())); + } } // screen and logfile messages for universe and world @@ -1103,7 +1106,7 @@ void _noopt LAMMPS::help() "List of command line options supported by this LAMMPS executable:\n\n" "-echo none/screen/log/both : echoing of input script (-e)\n" "-help : print this help message (-h)\n" - "-in filename : read input from file, not stdin (-i)\n" + "-in none/filename : read input from file or stdin (default) (-i)\n" "-kokkos on/off ... : turn KOKKOS mode on or off (-k)\n" "-log none/filename : where to send log output (-l)\n" "-mpicolor color : which exe in a multi-exe mpirun cmd (-m)\n" diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp index 029af72c84..7936ee45ad 100644 --- a/unittest/c-library/test_library_mpi.cpp +++ b/unittest/c-library/test_library_mpi.cpp @@ -156,11 +156,9 @@ TEST(MPI, multi_partition) lammps_mpi_init(); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &me); - fp = fopen("in.mp_dummy", "w"); - fclose(fp); const char *args[] = {"LAMMPS_test", "-log", "none", "-partition", "2x2", - "-echo", "screen", "-nocite", "-in", "in.mp_dummy"}; + "-echo", "screen", "-nocite", "-in", "none"}; char **argv = (char **)args; int argc = sizeof(args) / sizeof(char *); void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); @@ -184,7 +182,6 @@ TEST(MPI, multi_partition) } lammps_close(lmp); - unlink("in.mp_dummy"); }; class MPITest : public ::testing::Test { From 2d69051cdfbe30732206f419e882a820917d5aee Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 19 Nov 2020 19:20:02 -0500 Subject: [PATCH 61/67] add documentation for sublo/subhi extracted flags. add corresponding entries to get data type. --- doc/utils/sphinx-config/false_positives.txt | 2 ++ src/library.cpp | 22 +++++++++++++++++++++ unittest/c-library/test_library_mpi.cpp | 16 +++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index b776b7281b..463b2467fc 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -2979,6 +2979,8 @@ Subclassed subcutoff subcycle subcycling +subhi +sublo Subramaniyan subscripted subscripting diff --git a/src/library.cpp b/src/library.cpp index 0a8e70bc95..67fb51325f 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -995,6 +995,10 @@ int lammps_extract_global_datatype(void *handle, const char *name) if (strcmp(name,"boxlo") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"boxhi") == 0) return LAMMPS_DOUBLE; + if (strcmp(name,"sublo") == 0) return LAMMPS_DOUBLE; + if (strcmp(name,"subhi") == 0) return LAMMPS_DOUBLE; + if (strcmp(name,"sublo_lambda") == 0) return LAMMPS_DOUBLE; + if (strcmp(name,"subhi_lambda") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"boxxlo") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"boxxhi") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"boxylo") == 0) return LAMMPS_DOUBLE; @@ -1159,6 +1163,22 @@ report the "native" data type. The following tables are provided: - double - 1 - upper box boundary in z-direction. See :doc:`create_box`. + * - sublo + - double + - 3 + - subbox lower boundaries + * - subhi + - double + - 3 + - subbox upper boundaries + * - sublo_lambda + - double + - 3 + - subbox lower boundaries in fractional coordinates (for triclinic cells) + * - subhi_lambda + - double + - 3 + - subbox upper boundaries in fractional coordinates (for triclinic cells) * - periodicity - int - 3 @@ -1352,6 +1372,8 @@ void *lammps_extract_global(void *handle, const char *name) if (strcmp(name,"boxhi") == 0) return (void *) lmp->domain->boxhi; if (strcmp(name,"sublo") == 0) return (void *) lmp->domain->sublo; if (strcmp(name,"subhi") == 0) return (void *) lmp->domain->subhi; + if (strcmp(name,"sublo_lambda") == 0) return (void *) lmp->domain->sublo_lamda; + if (strcmp(name,"subhi_lambda") == 0) return (void *) lmp->domain->subhi_lamda; if (strcmp(name,"boxxlo") == 0) return (void *) &lmp->domain->boxlo[0]; if (strcmp(name,"boxxhi") == 0) return (void *) &lmp->domain->boxhi[0]; if (strcmp(name,"boxylo") == 0) return (void *) &lmp->domain->boxlo[1]; diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp index 7936ee45ad..cf33ed13b5 100644 --- a/unittest/c-library/test_library_mpi.cpp +++ b/unittest/c-library/test_library_mpi.cpp @@ -110,6 +110,22 @@ TEST(MPI, sub_box) EXPECT_LE(subhi[1], boxhi[1]); EXPECT_LE(subhi[2], boxhi[2]); + ::testing::internal::CaptureStdout(); + lammps_command(lmp, "change_box all triclinic"); + ::testing::internal::GetCapturedStdout(); + + sublo = (double *)lammps_extract_global(lmp, "sublo_lambda"); + subhi = (double *)lammps_extract_global(lmp, "subhi_lambda"); + ASSERT_NE(sublo, nullptr); + ASSERT_NE(subhi, nullptr); + + EXPECT_GE(sublo[0], 0.0); + EXPECT_GE(sublo[1], 0.0); + EXPECT_GE(sublo[2], 0.0); + EXPECT_LE(subhi[0], 1.0); + EXPECT_LE(subhi[1], 1.0); + EXPECT_LE(subhi[2], 1.0); + ::testing::internal::CaptureStdout(); lammps_close(lmp); ::testing::internal::GetCapturedStdout(); From cbde5619b073dd14ad201d13d4951750c9988f02 Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Fri, 20 Nov 2020 10:51:33 -0700 Subject: [PATCH 62/67] leave placeholder for KSpace in compute centroid/stress/atom --- src/compute_centroid_stress_atom.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/compute_centroid_stress_atom.cpp b/src/compute_centroid_stress_atom.cpp index 3de2c3dada..2a992c28b8 100644 --- a/src/compute_centroid_stress_atom.cpp +++ b/src/compute_centroid_stress_atom.cpp @@ -221,8 +221,8 @@ void ComputeCentroidStressAtom::compute_peratom() // per-atom virial and per-atom centroid virial are the same for bonds // bond styles are all CENTROID_SAME - // all other styles are CENTROID_AVAIL or CENTROID_NOTAVAIL - // add KSpace when it becomes supported + // angle, dihedral, improper styles are CENTROID_AVAIL or CENTROID_NOTAVAIL + // KSpace styles are all CENTROID_NOTAVAIL, placeholder CENTROID_SAME below if (bondflag && force->bond) { double **vatom = force->bond->vatom; @@ -255,12 +255,15 @@ void ComputeCentroidStressAtom::compute_peratom() stress[i][j] += cvatom[i][j]; } - //if (kspaceflag && force->kspace && force->kspace->compute_flag) { - // double **vatom = force->kspace->vatom; - // for (i = 0; i < nkspace; i++) - // for (j = 0; j < 9; j++) - // stress[i][j] += cvatom[i][j]; - // } + if (kspaceflag && force->kspace && force->kspace->compute_flag) { + double **vatom = force->kspace->vatom; + for (i = 0; i < nkspace; i++) + for (j = 0; j < 6; j++) + stress[i][j] += vatom[i][j]; + for (j = 6; j < 9; j++) + stress[i][j] += vatom[i][j-3]; + } + } // add in per-atom contributions from relevant fixes // skip if vatom = nullptr From e1835250c7351a2ba0145e448753216f8346168c Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Fri, 20 Nov 2020 13:51:08 -0700 Subject: [PATCH 63/67] missing brace --- src/compute_centroid_stress_atom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compute_centroid_stress_atom.cpp b/src/compute_centroid_stress_atom.cpp index 2a992c28b8..a6755b5b53 100644 --- a/src/compute_centroid_stress_atom.cpp +++ b/src/compute_centroid_stress_atom.cpp @@ -257,7 +257,7 @@ void ComputeCentroidStressAtom::compute_peratom() if (kspaceflag && force->kspace && force->kspace->compute_flag) { double **vatom = force->kspace->vatom; - for (i = 0; i < nkspace; i++) + for (i = 0; i < nkspace; i++) { for (j = 0; j < 6; j++) stress[i][j] += vatom[i][j]; for (j = 6; j < 9; j++) From 3f31c692163ceb5853875f6e372da0d52c49fbb9 Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Tue, 17 Nov 2020 11:41:19 -0600 Subject: [PATCH 64/67] Update the vflag_atom based on the intended use in LAMMPS --- src/KIM/pair_kim.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/KIM/pair_kim.cpp b/src/KIM/pair_kim.cpp index faeda2b69e..82dae0ded8 100644 --- a/src/KIM/pair_kim.cpp +++ b/src/KIM/pair_kim.cpp @@ -241,7 +241,7 @@ void PairKIM::compute(int eflag, int vflag) comm->reverse_comm_pair(this); } - if ((vflag_atom) && + if ((vflag_atom != 0) && KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, KIM_SUPPORT_STATUS_notSupported)) { // flip sign and order of virial if KIM is computing it @@ -651,11 +651,11 @@ int PairKIM::pack_reverse_comm(int n, int first, double *buf) // see Pair::ev_setup & Integrate::ev_set() // for values of eflag (0-3) and vflag (0-14) // ------------------------------------------------------------------------- - if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, - KIM_SUPPORT_STATUS_notSupported) && - KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, + if ((vflag_atom != 0) && + KIM_SupportStatus_NotEqual(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom != 0)) { + KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, + KIM_SUPPORT_STATUS_notSupported)) { const double *const fp = &(atom->f[0][0]); const double *const va = &(vatom[0][0]); for (int i = first; i < last; i++) { @@ -672,11 +672,11 @@ int PairKIM::pack_reverse_comm(int n, int first, double *buf) } return m; } - if (KIM_SupportStatus_Equal(kim_model_support_for_forces, + if ((vflag_atom != 0) && + KIM_SupportStatus_Equal(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom != 0)) { + KIM_SUPPORT_STATUS_notSupported)) { const double *const va = &(vatom[0][0]); for (int i = first; i < last; i++) { buf[m++] = va[6*i+0]; @@ -710,11 +710,11 @@ void PairKIM::unpack_reverse_comm(int n, int *list, double *buf) } return; } - if (KIM_SupportStatus_NotEqual(kim_model_support_for_forces, + if ((vflag_atom != 0) && + KIM_SupportStatus_NotEqual(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom != 0)) { + KIM_SUPPORT_STATUS_notSupported)) { double *const fp = &(atom->f[0][0]); double *const va = &(vatom[0][0]); for (int i = 0; i < n; i++) { @@ -732,11 +732,11 @@ void PairKIM::unpack_reverse_comm(int n, int *list, double *buf) } return; } - if (KIM_SupportStatus_Equal(kim_model_support_for_forces, + if ((vflag_atom != 0) && + KIM_SupportStatus_Equal(kim_model_support_for_forces, KIM_SUPPORT_STATUS_notSupported) && KIM_SupportStatus_NotEqual(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_notSupported) && - (vflag_atom != 0)) { + KIM_SUPPORT_STATUS_notSupported)) { double *const va=&(vatom[0][0]); for (int i = 0; i < n; i++) { const int j = list[i]; @@ -946,9 +946,9 @@ void PairKIM::set_argument_pointers() } // Set KIM pointer appropriately for particleVirial - if (KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_required) - && (vflag_atom != 4)) { + if ((vflag_atom == 0) && + KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, + KIM_SUPPORT_STATUS_required)) { // reallocate per-atom virial array if necessary if (atom->nmax > maxvatom) { maxvatom = atom->nmax; @@ -957,9 +957,9 @@ void PairKIM::set_argument_pointers() } } - if (KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, - KIM_SUPPORT_STATUS_optional) - && (vflag_atom != 4)) { + if ((vflag_atom == 0) && + KIM_SupportStatus_Equal(kim_model_support_for_particleVirial, + KIM_SUPPORT_STATUS_optional)) { kimerror = kimerror || KIM_ComputeArguments_SetArgumentPointerDouble( pargs, KIM_COMPUTE_ARGUMENT_NAME_partialParticleVirial, From af0df870f4ef067d4fd0969aaa9fa801f75fb601 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 23 Nov 2020 18:36:28 -0500 Subject: [PATCH 65/67] Fix bug introduced by uninitialized moloffset --- src/create_atoms.cpp | 6 +++--- src/molecule.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/create_atoms.cpp b/src/create_atoms.cpp index e461e4928a..4abb2c4696 100644 --- a/src/create_atoms.cpp +++ b/src/create_atoms.cpp @@ -446,7 +446,7 @@ void CreateAtoms::command(int narg, char **arg) // molcreate = # of molecules I created - int molcreate = (atom->nlocal - nlocal_previous) / onemol->natoms; + tagint molcreate = (atom->nlocal - nlocal_previous) / onemol->natoms; // increment total bonds,angles,etc @@ -463,13 +463,13 @@ void CreateAtoms::command(int narg, char **arg) // moloffset = max molecule ID for all molecules owned by previous procs // including molecules existing before this creation - tagint moloffset; + tagint moloffset = 0; if (molecule_flag) { tagint max = 0; for (int i = 0; i < nlocal_previous; i++) max = MAX(max,molecule[i]); tagint maxmol; MPI_Allreduce(&max,&maxmol,1,MPI_LMP_TAGINT,MPI_MAX,world); - MPI_Scan(&molcreate,&moloffset,1,MPI_INT,MPI_SUM,world); + MPI_Scan(&molcreate,&moloffset,1,MPI_LMP_TAGINT,MPI_SUM,world); moloffset = moloffset - molcreate + maxmol; } diff --git a/src/molecule.cpp b/src/molecule.cpp index 77fa9c82df..d85cf47c71 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -760,7 +760,7 @@ void Molecule::molecules(char *line) int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Molecules section in molecule file"); count[iatom]++; - molecule[iatom] = values.next_int(); + molecule[iatom] = values.next_tagint(); // molecule[iatom] += moffset; // placeholder for possible molecule offset } } catch (TokenizerException &e) { From c7d8e93f5a3595a6fc0659fb566d35acc6e33fd1 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 24 Nov 2020 13:53:20 -0500 Subject: [PATCH 66/67] Add missing init of virial --- src/pair.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pair.cpp b/src/pair.cpp index 74a03fbed9..be6afe912e 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -808,6 +808,7 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) vflag_global = vflag & VIRIAL_PAIR; if (vflag & VIRIAL_FDOTR && no_virial_fdotr_compute == 1) vflag_global = 1; + vflag_fdotr = 0; if (vflag & VIRIAL_FDOTR && no_virial_fdotr_compute == 0) vflag_fdotr = 1; vflag_atom = vflag & VIRIAL_ATOM; if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) vflag_atom = 1; @@ -816,7 +817,6 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) vflag_either = vflag_global || vflag_atom || cvflag_atom; evflag = eflag_either || vflag_either; - if (!evflag) return; // reallocate per-atom arrays if necessary @@ -847,7 +847,7 @@ void Pair::ev_setup(int eflag, int vflag, int alloc) // b/c some bonds/dihedrals call pair::ev_tally with pairwise info if (eflag_global) eng_vdwl = eng_coul = 0.0; - if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0; + if (vflag_global || vflag_fdotr) for (i = 0; i < 6; i++) virial[i] = 0.0; if (eflag_atom && alloc) { n = atom->nlocal; if (force->newton) n += atom->nghost; @@ -1564,8 +1564,6 @@ void Pair::virial_fdotr_compute() double **x = atom->x; double **f = atom->f; - for (int i = 0; i < 6; i++) virial[i] = 0.0; - // sum over force on all particles including ghosts if (neighbor->includegroup == 0) { From 109cee1ce1680454957b2be7f90497af6657353c Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 24 Nov 2020 14:24:53 -0500 Subject: [PATCH 67/67] Doc string update for Pair::ev_setup() --- src/pair.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pair.cpp b/src/pair.cpp index be6afe912e..0f97b83622 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -782,11 +782,11 @@ void Pair::del_tally_callback(Compute *ptr) eflag_global != 0 if ENERGY_GLOBAL bit of eflag set eflag_atom != 0 if ENERGY_ATOM bit of eflag set eflag_either != 0 if eflag_global or eflag_atom is set - vflag_global != 0 if VIRIAL_PAIR bit of vflag set - vflag_global != 0 if VIRIAL_FDOTR bit of vflag is set but no_virial_fdotr = 1 + vflag_global != 0 if VIRIAL_PAIR bit of vflag set, OR + if VIRIAL_FDOTR bit of vflag is set but no_virial_fdotr = 1 vflag_fdotr != 0 if VIRIAL_FDOTR bit of vflag set and no_virial_fdotr = 0 - vflag_atom != 0 if VIRIAL_ATOM bit of vflag set - vflag_atom != 0 if VIRIAL_CENTROID bit of vflag set + vflag_atom != 0 if VIRIAL_ATOM bit of vflag set, OR + if VIRIAL_CENTROID bit of vflag set and centroidstressflag != CENTROID_AVAIL cvflag_atom != 0 if VIRIAL_CENTROID bit of vflag set and centroidstressflag = CENTROID_AVAIL