diff --git a/src/library.cpp b/src/library.cpp index 67fb51325f..17ca454b3c 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -841,6 +841,10 @@ not recognized, the function returns -1. See :doc:`create_box`. * - nthreads - Number of requested OpenMP threads for LAMMPS' execution + * - newton_bond + - 1 if Newton's 3rd law is applied to bonded interactions, 0 if not. + * - newton_pair + - 1 if Newton's 3rd law is applied to non-bonded interactions, 0 if not. * - triclinic - 1 if the the simulation box is triclinic, 0 if orthogonal. See :doc:`change_box`. @@ -933,6 +937,8 @@ int lammps_extract_setting(void *handle, const char *keyword) if (strcmp(keyword,"dimension") == 0) return lmp->domain->dimension; if (strcmp(keyword,"box_exist") == 0) return lmp->domain->box_exist; + if (strcmp(keyword,"newton_bond") == 0) return lmp->force->newton_bond; + if (strcmp(keyword,"newton_pair") == 0) return lmp->force->newton_pair; if (strcmp(keyword,"triclinic") == 0) return lmp->domain->triclinic; if (strcmp(keyword,"universe_rank") == 0) return lmp->universe->me; diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 9ec87b9234..9df0888a3f 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -91,10 +91,11 @@ TEST_F(LibraryProperties, thermo) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; - if (!verbose) ::testing::internal::CaptureStdout(); + ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); lammps_command(lmp, "run 2 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; EXPECT_EQ(lammps_get_thermo(lmp, "step"), 2); EXPECT_EQ(lammps_get_thermo(lmp, "atoms"), 29); EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "vol"), 3375.0); @@ -106,10 +107,11 @@ TEST_F(LibraryProperties, box) { if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; - if (!verbose) ::testing::internal::CaptureStdout(); + ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); lammps_command(lmp, "run 2 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; double boxlo[3], boxhi[3], xy, yz, xz; int pflags[3], boxflag; lammps_extract_box(lmp, boxlo, boxhi, &xy, &yz, &xz, pflags, &boxflag); @@ -204,6 +206,28 @@ TEST_F(LibraryProperties, setting) 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, "newton_pair"), 1); + EXPECT_EQ(lammps_extract_setting(lmp, "newton_bond"), 1); + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_command(lmp, "newton off"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_extract_setting(lmp, "newton_pair"), 0); + EXPECT_EQ(lammps_extract_setting(lmp, "newton_bond"), 0); + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_command(lmp, "newton on off"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_extract_setting(lmp, "newton_pair"), 1); + EXPECT_EQ(lammps_extract_setting(lmp, "newton_bond"), 0); + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_command(lmp, "newton off on"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_extract_setting(lmp, "newton_pair"), 0); + EXPECT_EQ(lammps_extract_setting(lmp, "newton_bond"), 1); + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_command(lmp, "newton on"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_extract_setting(lmp, "newton_pair"), 1); + EXPECT_EQ(lammps_extract_setting(lmp, "newton_bond"), 1); EXPECT_EQ(lammps_extract_setting(lmp, "ntypes"), 0); EXPECT_EQ(lammps_extract_setting(lmp, "nbondtypes"), 0);