From b08751d65a2af0500002ddad4fad8e9791f3645a Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 11 Aug 2020 16:17:36 -0400 Subject: [PATCH] Add triclinic tests for dump atom --- src/dump_atom.cpp | 10 ++++++++++ unittest/formats/test_dump.cpp | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/dump_atom.cpp b/src/dump_atom.cpp index a4ec597818..188dc1676f 100644 --- a/src/dump_atom.cpp +++ b/src/dump_atom.cpp @@ -197,6 +197,11 @@ void DumpAtom::header_binary(bigint ndump) void DumpAtom::header_binary_triclinic(bigint ndump) { + // use negative ntimestep as marker for new format + bigint fmtlen = strlen("DUMPATOM"); + bigint marker = -fmtlen; + fwrite(&marker,sizeof(bigint),1,fp); + fwrite("DUMPATOM",sizeof(char),fmtlen,fp); fwrite(&update->ntimestep,sizeof(bigint),1,fp); fwrite(&ndump,sizeof(bigint),1,fp); fwrite(&domain->triclinic,sizeof(int),1,fp); @@ -211,6 +216,11 @@ void DumpAtom::header_binary_triclinic(bigint ndump) fwrite(&boxxz,sizeof(double),1,fp); fwrite(&boxyz,sizeof(double),1,fp); fwrite(&size_one,sizeof(int),1,fp); + + int len = strlen(columns); + fwrite(&len, sizeof(int), 1, fp); + fwrite(columns, sizeof(char), len, fp); + if (multiproc) fwrite(&nclusterprocs,sizeof(int),1,fp); else fwrite(&nprocs,sizeof(int),1,fp); } diff --git a/unittest/formats/test_dump.cpp b/unittest/formats/test_dump.cpp index f58ef94b7e..691d818fc6 100644 --- a/unittest/formats/test_dump.cpp +++ b/unittest/formats/test_dump.cpp @@ -141,6 +141,20 @@ TEST_F(DumpAtomTest, run0) delete_file("dump_run0.melt"); } +TEST_F(DumpAtomTest, tricilinic_run0) +{ + if (!verbose) ::testing::internal::CaptureStdout(); + + command("change_box all triclinic"); + command("dump id all atom 1 dump_triclinic_run0.melt"); + command("run 0"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + ASSERT_FILE_EXISTS("dump_triclinic_run0.melt"); + ASSERT_EQ(count_lines("dump_triclinic_run0.melt"), 41); + delete_file("dump_triclinic_run0.melt"); +} + TEST_F(DumpAtomTest, binary_run0) { if(!BINARY2TXT_BINARY) GTEST_SKIP(); @@ -162,6 +176,28 @@ TEST_F(DumpAtomTest, binary_run0) delete_file("dump_binary_run0.melt.bin.txt"); } +TEST_F(DumpAtomTest, binary_triclinic_run0) +{ + if(!BINARY2TXT_BINARY) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + command("change_box all triclinic"); + command("dump id0 all atom 1 dump_text_tri_run0.melt"); + command("dump id1 all atom 1 dump_binary_tri_run0.melt.bin"); + command("run 0"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + ASSERT_FILE_EXISTS("dump_text_tri_run0.melt"); + ASSERT_FILE_EXISTS("dump_binary_tri_run0.melt.bin"); + std::string cmdline = fmt::format("{} dump_binary_tri_run0.melt.bin", BINARY2TXT_BINARY); + system(cmdline.c_str()); + ASSERT_FILE_EXISTS("dump_binary_tri_run0.melt.bin.txt"); + ASSERT_FILE_EQUAL("dump_text_tri_run0.melt", "dump_binary_tri_run0.melt.bin.txt"); + delete_file("dump_text_tri_run0.melt"); + delete_file("dump_binary_tri_run0.melt.bin"); + delete_file("dump_binary_tri_run0.melt.bin.txt"); +} + TEST_F(DumpAtomTest, run1) { if (!verbose) ::testing::internal::CaptureStdout();