Merge pull request #2331 from rbberger/zstd_support

Update COMPRESS package
This commit is contained in:
Axel Kohlmeyer 2020-09-01 15:01:04 -04:00 committed by GitHub
commit 80519cd109
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 3394 additions and 60 deletions

View File

@ -1,2 +1,10 @@
find_package(ZLIB REQUIRED)
target_link_libraries(lammps PRIVATE ZLIB::ZLIB)
find_package(PkgConfig REQUIRED)
pkg_check_modules(Zstd IMPORTED_TARGET libzstd>=1.4)
if(Zstd_FOUND)
target_compile_definitions(lammps PRIVATE -DLAMMPS_ZSTD)
target_link_libraries(lammps PRIVATE PkgConfig::Zstd)
endif()

View File

@ -46,17 +46,19 @@ Syntax
*atom* args = none
*atom/gz* args = none
*atom/zstd* args = none
*atom/mpiio* args = none
*atom/adios* args = none, discussed on :doc:`dump atom/adios <dump_adios>` doc page
*cfg* args = same as *custom* args, see below
*cfg/gz* args = same as *custom* args, see below
*cfg/zstd* args = same as *custom* args, see below
*cfg/mpiio* args = same as *custom* args, see below
*custom*\ , *custom/gz*\ , *custom/mpiio* args = see below
*custom*\ , *custom/gz*\ , *custom/zstd* , *custom/mpiio* args = see below
*custom/adios* args = same as *custom* args, discussed on :doc:`dump custom/adios <dump_adios>` doc page
*dcd* args = none
*h5md* args = discussed on :doc:`dump h5md <dump_h5md>` doc page
*image* args = discussed on :doc:`dump image <dump_image>` doc page
*local* args = see below
*local*, *local/gz*, *local/zstd* args = see below
*molfile* args = discussed on :doc:`dump molfile <dump_molfile>` doc page
*movie* args = discussed on :doc:`dump image <dump_image>` doc page
*netcdf* args = discussed on :doc:`dump netcdf <dump_netcdf>` doc page
@ -65,9 +67,10 @@ Syntax
*xtc* args = none
*xyz* args = none
*xyz/gz* args = none
*xyz/zstd* args = none
*xyz/mpiio* args = none
* *custom* or *custom/gz* or *custom/mpiio* or *netcdf* or *netcdf/mpiio* args = list of atom attributes
* *custom* or *custom/gz* or *custom/zstd* or *custom/mpiio* or *netcdf* or *netcdf/mpiio* args = list of atom attributes
.. parsed-literal::
@ -111,7 +114,7 @@ Syntax
d_name = per-atom floating point vector with name, managed by fix property/atom
i_name = per-atom integer vector with name, managed by fix property/atom
* *local* args = list of local attributes
* *local* or *local/gz* or *local/zstd* args = list of local attributes
.. parsed-literal::
@ -130,6 +133,7 @@ Examples
dump myDump all atom 100 dump.atom
dump myDump all atom/mpiio 100 dump.atom.mpiio
dump myDump all atom/gz 100 dump.atom.gz
dump myDump all atom/zstd 100 dump.atom.zst
dump 2 subgroup atom 50 dump.run.bin
dump 2 subgroup atom 50 dump.run.mpiio.bin
dump 4a all custom 100 dump.myforce.* id type x y vx fx
@ -187,7 +191,7 @@ default. For the *dcd*\ , *xtc*\ , *xyz*\ , and *molfile* styles, sorting by
atom ID is on by default. See the :doc:`dump_modify <dump_modify>` doc
page for details.
The *atom/gz*\ , *cfg/gz*\ , *custom/gz*\ , and *xyz/gz* styles are identical
The *atom/gz*\ , *cfg/gz*\ , *custom/gz*\ , *local/gz*, and *xyz/gz* styles are identical
in command syntax to the corresponding styles without "gz", however,
they generate compressed files using the zlib library. Thus the filename
suffix ".gz" is mandatory. This is an alternative approach to writing
@ -198,6 +202,11 @@ For the remainder of this doc page, you should thus consider the *atom*
and *atom/gz* styles (etc) to be inter-changeable, with the exception
of the required filename suffix.
Similarly, the *atom/zstd*\ , *cfg/zstd*\ , *custom/zstd*\ , *local/zstd*,
and *xyz/zstd* styles are identical to the gz styles, but use the Zstd
compression library instead. See the :doc:`dump_modify <dump_modify>` doc
page for details on how to control the compression level in both variants.
As explained below, the *atom/mpiio*\ , *cfg/mpiio*\ , *custom/mpiio*\ , and
*xyz/mpiio* styles are identical in command syntax and in the format
of the dump files they create, to the corresponding styles without

View File

@ -114,6 +114,21 @@ Syntax
*framerate* arg = fps
fps = frames per second for movie
* these keywords apply only to the */gz* and */zstd* dump styles
* keyword = *compression_level*
.. parsed-literal::
*compression_level* args = level
level = integer specifying the compression level that should be used (see below for supported levels)
* these keywords apply only to the */zstd* dump styles
* keyword = *compression_level*
.. parsed-literal::
*checksum* args = *yes* or *no* (add checksum at end of zst file)
Examples
""""""""
@ -962,6 +977,28 @@ images less frequently.
----------
The COMPRESS package offers both GZ and Zstd compression variants of styles
atom, custom, local, cfg, and xyz. When using these styles the compression
level can be controlled by the :code:`compression_level` parameter. File names
with these styles have to end in either :code:`.gz` or :code:`.zst`.
GZ supports compression levels from -1 (default), 0 (no compression), and 1 to
9. 9 being the best compression. The COMPRESS :code:`/gz` styles use 9 as
default compression level.
Zstd offers a wider range of compression levels, including negative
levels that sacrifice compression for performance. 0 is the
default, positive levels are 1 to 22, with 22 being the most expensive
compression. Zstd promises higher compression/decompression speeds for
similar compression ratios. For more details see
`http://facebook.github.io/zstd/`.
In addition, Zstd compressed files can have a checksum of the entire
contents. The Zstd enabled dump styles enable this feature by default and it
can be disabled with the :code:`checksum` parameter.
----------
Restrictions
""""""""""""
none
@ -1010,6 +1047,10 @@ The option defaults are
* color = 140 color names are pre-defined as listed below
* framerate = 24
* compression_level = 9 (gz variants)
* compression_level = 0 (zstd variants)
* checksum = yes (zstd variants)
----------
These are the standard 109 element names that LAMMPS pre-defines for

View File

@ -31,6 +31,11 @@ Examples
write_dump all image snap*.jpg element element &
bond atom 0.3 shiny 0.1 ssao yes 6345 0.2 size 1600 1600 &
modify backcolor white element C C O H N C C C O H H S O H
write_dump all atom/gz dump.atom.gz modify compression_level 9
write_dump flow custom/zstd dump.%.myforce.zst &
id type c_myF[3] v_ke &
modify sort id &
compression_level 15
Description
"""""""""""

View File

@ -3459,3 +3459,6 @@ zz
Zm
PowerShell
filesystems
Zstd
zstd
checksum

View File

@ -10,5 +10,9 @@ alternative for compressed file I/O on systems where using a pipe can
cause problems, e.g. when using RDMA communication with pinned memory
like clusters with Infiniband or Myrinet.
Update 08/2020: Added variants that use the Zstd compression library instead
of zlib. To enable, set -DLAMMPS_ZSTD. These provide a wider range of
compression levels. See http://facebook.github.io/zstd/ for more details.
Currently a few selected dump styles are supported for writing via
this packaging.

View File

@ -15,8 +15,10 @@
#include "domain.h"
#include "error.h"
#include "update.h"
#include "utils.h"
#include <cstring>
#include "fmt/format.h"
using namespace LAMMPS_NS;
@ -25,6 +27,8 @@ DumpAtomGZ::DumpAtomGZ(LAMMPS *lmp, int narg, char **arg) :
{
gzFp = NULL;
compression_level = Z_BEST_COMPRESSION;
if (!compressed)
error->all(FLERR,"Dump atom/gz only writes compressed files");
}
@ -89,12 +93,15 @@ void DumpAtomGZ::openfile()
// each proc with filewriter = 1 opens a file
if (filewriter) {
std::string mode;
if (append_flag) {
gzFp = gzopen(filecurrent,"ab9");
mode = fmt::format("ab{}", compression_level);
} else {
gzFp = gzopen(filecurrent,"wb9");
mode = fmt::format("wb{}", compression_level);
}
gzFp = gzopen(filecurrent, mode.c_str());
if (gzFp == NULL) error->one(FLERR,"Cannot open dump file");
} else gzFp = NULL;
@ -120,14 +127,14 @@ void DumpAtomGZ::write_header(bigint ndump)
gzprintf(gzFp,BIGINT_FORMAT "\n",ndump);
if (domain->triclinic == 0) {
gzprintf(gzFp,"ITEM: BOX BOUNDS %s\n",boundstr);
gzprintf(gzFp,"%g %g\n",boxxlo,boxxhi);
gzprintf(gzFp,"%g %g\n",boxylo,boxyhi);
gzprintf(gzFp,"%g %g\n",boxzlo,boxzhi);
gzprintf(gzFp,"%-1.16e %-1.16e\n",boxxlo,boxxhi);
gzprintf(gzFp,"%-1.16e %-1.16e\n",boxylo,boxyhi);
gzprintf(gzFp,"%-1.16e %-1.16e\n",boxzlo,boxzhi);
} else {
gzprintf(gzFp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr);
gzprintf(gzFp,"%g %g %g\n",boxxlo,boxxhi,boxxy);
gzprintf(gzFp,"%g %g %g\n",boxylo,boxyhi,boxxz);
gzprintf(gzFp,"%g %g %g\n",boxzlo,boxzhi,boxyz);
gzprintf(gzFp,"%-1.16e %-1.16e %-1.16e\n",boxxlo,boxxhi,boxxy);
gzprintf(gzFp,"%-1.16e %-1.16e %-1.16e\n",boxylo,boxyhi,boxxz);
gzprintf(gzFp,"%-1.16e %-1.16e %-1.16e\n",boxzlo,boxzhi,boxyz);
}
gzprintf(gzFp,"ITEM: ATOMS %s\n",columns);
}
@ -156,3 +163,21 @@ void DumpAtomGZ::write()
}
}
/* ---------------------------------------------------------------------- */
int DumpAtomGZ::modify_param(int narg, char **arg)
{
int consumed = DumpAtom::modify_param(narg, arg);
if(consumed == 0) {
if (strcmp(arg[0],"compression_level") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
int min_level = Z_DEFAULT_COMPRESSION;
int max_level = Z_BEST_COMPRESSION;
compression_level = utils::inumeric(FLERR, arg[1], false, lmp);
if (compression_level < min_level || compression_level > max_level)
error->all(FLERR, fmt::format("Illegal dump_modify command: compression level must in the range of [{}, {}]", min_level, max_level));
return 2;
}
}
return consumed;
}

View File

@ -31,12 +31,15 @@ class DumpAtomGZ : public DumpAtom {
virtual ~DumpAtomGZ();
protected:
int compression_level;
gzFile gzFp; // file pointer for the compressed output stream
virtual void openfile();
virtual void write_header(bigint);
virtual void write_data(int, double *);
virtual void write();
virtual int modify_param(int, char **);
};
}

View File

@ -0,0 +1,195 @@
/* ----------------------------------------------------------------------
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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifdef LAMMPS_ZSTD
#include "dump_atom_zstd.h"
#include "domain.h"
#include "error.h"
#include "update.h"
#include "utils.h"
#include <cstring>
#include "fmt/format.h"
using namespace LAMMPS_NS;
DumpAtomZstd::DumpAtomZstd(LAMMPS *lmp, int narg, char **arg) :
DumpAtom(lmp, narg, arg)
{
if (!compressed)
error->all(FLERR,"Dump atom/zstd only writes compressed files");
}
/* ---------------------------------------------------------------------- */
DumpAtomZstd::~DumpAtomZstd()
{
}
/* ----------------------------------------------------------------------
generic opening of a dump file
ASCII or binary or zstdipped
some derived classes override this function
------------------------------------------------------------------------- */
void DumpAtomZstd::openfile()
{
// single file, already opened, so just return
if (singlefile_opened) return;
if (multifile == 0) singlefile_opened = 1;
// if one file per timestep, replace '*' with current timestep
char *filecurrent = filename;
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
filestar,update->ntimestep,ptr+1);
else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1];
strcpy(nameslist[numfiles],filecurrent);
++numfiles;
} else {
remove(nameslist[fileidx]);
delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1];
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles;
}
}
}
// each proc with filewriter = 1 opens a file
if (filewriter) {
if (append_flag) {
error->one(FLERR, "dump/zstd currently doesn't support append");
}
try {
writer.open(filecurrent);
} catch (FileWriterException & e) {
error->one(FLERR, e.what());
}
}
// delete string with timestep replaced
if (multifile) delete [] filecurrent;
}
/* ---------------------------------------------------------------------- */
void DumpAtomZstd::write_header(bigint ndump)
{
std::string header;
if ((multiproc) || (!multiproc && me == 0)) {
if (unit_flag && !unit_count) {
++unit_count;
header = fmt::format("ITEM: UNITS\n{}\n",update->unit_style);
}
if (time_flag) {
header += fmt::format("ITEM: TIME\n{0:.16g}\n", compute_time());
}
header += fmt::format("ITEM: TIMESTEP\n{}\n", update->ntimestep);
header += fmt::format("ITEM: NUMBER OF ATOMS\n{}\n", ndump);
if (domain->triclinic == 0) {
header += fmt::format("ITEM: BOX BOUNDS {}\n", boundstr);
header += fmt::format("{0:-1.16e} {1:-1.16e}\n", boxxlo, boxxhi);
header += fmt::format("{0:-1.16e} {1:-1.16e}\n", boxylo, boxyhi);
header += fmt::format("{0:-1.16e} {1:-1.16e}\n", boxzlo, boxzhi);
} else {
header += fmt::format("ITEM: BOX BOUNDS xy xz yz {}\n", boundstr);
header += fmt::format("{0:-1.16e} {1:-1.16e} {2:-1.16e}\n", boxxlo, boxxhi, boxxy);
header += fmt::format("{0:-1.16e} {1:-1.16e} {2:-1.16e}\n", boxylo, boxyhi, boxxz);
header += fmt::format("{0:-1.16e} {1:-1.16e} {2:-1.16e}\n", boxzlo, boxzhi, boxyz);
}
header += fmt::format("ITEM: ATOMS {}\n", columns);
writer.write(header.c_str(), header.length());
}
}
/* ---------------------------------------------------------------------- */
void DumpAtomZstd::write_data(int n, double *mybuf)
{
writer.write(mybuf, n);
}
/* ---------------------------------------------------------------------- */
void DumpAtomZstd::write()
{
DumpAtom::write();
if (filewriter) {
if (multifile) {
writer.close();
} else {
if (flush_flag && writer.isopen()) {
writer.flush();
}
}
}
}
/* ---------------------------------------------------------------------- */
int DumpAtomZstd::modify_param(int narg, char **arg)
{
int consumed = DumpAtom::modify_param(narg, arg);
if(consumed == 0) {
try {
if (strcmp(arg[0],"checksum") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
if (strcmp(arg[1],"yes") == 0) writer.setChecksum(true);
else if (strcmp(arg[1],"no") == 0) writer.setChecksum(false);
else error->all(FLERR,"Illegal dump_modify command");
return 2;
} else if (strcmp(arg[0],"compression_level") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
int compression_level = utils::inumeric(FLERR, arg[1], false, lmp);
writer.setCompressionLevel(compression_level);
return 2;
}
} catch (FileWriterException & e) {
error->one(FLERR, e.what());
}
}
return consumed;
}
#endif

View File

@ -0,0 +1,66 @@
/* -*- 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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifdef LAMMPS_ZSTD
#ifdef DUMP_CLASS
DumpStyle(atom/zstd,DumpAtomZstd)
#else
#ifndef LMP_DUMP_ATOM_ZSTD_H
#define LMP_DUMP_ATOM_ZSTD_H
#include "dump_atom.h"
#include "zstd_file_writer.h"
namespace LAMMPS_NS {
class DumpAtomZstd : public DumpAtom {
public:
DumpAtomZstd(class LAMMPS *, int, char **);
virtual ~DumpAtomZstd();
protected:
ZstdFileWriter writer;
virtual void openfile();
virtual void write_header(bigint);
virtual void write_data(int, double *);
virtual void write();
virtual int modify_param(int, char **);
};
}
#endif
#endif
#endif
/* ERROR/WARNING messages:
E: Dump atom/zstd only writes compressed files
The dump atom/zstd output file name must have a .zst suffix.
E: Cannot open dump file
Self-explanatory.
*/

View File

@ -16,8 +16,10 @@
#include "domain.h"
#include "error.h"
#include "update.h"
#include "utils.h"
#include <cstring>
#include "fmt/format.h"
using namespace LAMMPS_NS;
#define UNWRAPEXPAND 10.0
@ -27,6 +29,8 @@ DumpCFGGZ::DumpCFGGZ(LAMMPS *lmp, int narg, char **arg) :
{
gzFp = NULL;
compression_level = Z_BEST_COMPRESSION;
if (!compressed)
error->all(FLERR,"Dump cfg/gz only writes compressed files");
}
@ -93,12 +97,15 @@ void DumpCFGGZ::openfile()
// each proc with filewriter = 1 opens a file
if (filewriter) {
std::string mode;
if (append_flag) {
gzFp = gzopen(filecurrent,"ab9");
mode = fmt::format("ab{}", compression_level);
} else {
gzFp = gzopen(filecurrent,"wb9");
mode = fmt::format("wb{}", compression_level);
}
gzFp = gzopen(filecurrent, mode.c_str());
if (gzFp == NULL) error->one(FLERR,"Cannot open dump file");
} else gzFp = NULL;
@ -164,3 +171,22 @@ void DumpCFGGZ::write()
}
}
/* ---------------------------------------------------------------------- */
int DumpCFGGZ::modify_param(int narg, char **arg)
{
int consumed = DumpCFG::modify_param(narg, arg);
if(consumed == 0) {
if (strcmp(arg[0],"compression_level") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
int min_level = Z_DEFAULT_COMPRESSION;
int max_level = Z_BEST_COMPRESSION;
compression_level = utils::inumeric(FLERR, arg[1], false, lmp);
if (compression_level < min_level || compression_level > max_level)
error->all(FLERR, fmt::format("Illegal dump_modify command: compression level must in the range of [{}, {}]", min_level, max_level));
return 2;
}
}
return consumed;
}

View File

@ -31,12 +31,15 @@ class DumpCFGGZ : public DumpCFG {
virtual ~DumpCFGGZ();
protected:
int compression_level;
gzFile gzFp; // file pointer for the compressed output stream
virtual void openfile();
virtual void write_header(bigint);
virtual void write_data(int, double *);
virtual void write();
virtual int modify_param(int, char **);
};
}

View File

@ -0,0 +1,196 @@
/* ----------------------------------------------------------------------
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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifdef LAMMPS_ZSTD
#include "dump_cfg_zstd.h"
#include "atom.h"
#include "domain.h"
#include "error.h"
#include "update.h"
#include "utils.h"
#include <cstring>
#include "fmt/format.h"
using namespace LAMMPS_NS;
#define UNWRAPEXPAND 10.0
DumpCFGZstd::DumpCFGZstd(LAMMPS *lmp, int narg, char **arg) :
DumpCFG(lmp, narg, arg)
{
if (!compressed)
error->all(FLERR,"Dump cfg/zstd only writes compressed files");
}
/* ---------------------------------------------------------------------- */
DumpCFGZstd::~DumpCFGZstd()
{
}
/* ----------------------------------------------------------------------
generic opening of a dump file
ASCII or binary or zstdipped
some derived classes override this function
------------------------------------------------------------------------- */
void DumpCFGZstd::openfile()
{
// single file, already opened, so just return
if (singlefile_opened) return;
if (multifile == 0) singlefile_opened = 1;
// if one file per timestep, replace '*' with current timestep
char *filecurrent = filename;
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
filestar,update->ntimestep,ptr+1);
else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1];
strcpy(nameslist[numfiles],filecurrent);
++numfiles;
} else {
remove(nameslist[fileidx]);
delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1];
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles;
}
}
}
// each proc with filewriter = 1 opens a file
if (filewriter) {
if (append_flag) {
error->one(FLERR, "dump cfg/zstd currently doesn't support append");
}
try {
writer.open(filecurrent);
} catch (FileWriterException & e) {
error->one(FLERR, e.what());
}
}
// delete string with timestep replaced
if (multifile) delete [] filecurrent;
}
/* ---------------------------------------------------------------------- */
void DumpCFGZstd::write_header(bigint n)
{
// set scale factor used by AtomEye for CFG viz
// default = 1.0
// for peridynamics, set to pre-computed PD scale factor
// so PD particles mimic C atoms
// for unwrapped coords, set to UNWRAPEXPAND (10.0)
// so molecules are not split across periodic box boundaries
double scale = 1.0;
if (atom->peri_flag) scale = atom->pdscale;
else if (unwrapflag == 1) scale = UNWRAPEXPAND;
std::string header = fmt::format("Number of particles = {}\n", n);
header += fmt::format("A = {0:g} Angstrom (basic length-scale)\n", scale);
header += fmt::format("H0(1,1) = {0:g} A\n",domain->xprd);
header += fmt::format("H0(1,2) = 0 A \n");
header += fmt::format("H0(1,3) = 0 A \n");
header += fmt::format("H0(2,1) = {0:g} A \n",domain->xy);
header += fmt::format("H0(2,2) = {0:g} A\n",domain->yprd);
header += fmt::format("H0(2,3) = 0 A \n");
header += fmt::format("H0(3,1) = {0:g} A \n",domain->xz);
header += fmt::format("H0(3,2) = {0:g} A \n",domain->yz);
header += fmt::format("H0(3,3) = {0:g} A\n",domain->zprd);
header += fmt::format(".NO_VELOCITY.\n");
header += fmt::format("entry_count = {}\n",nfield-2);
for (int i = 0; i < nfield-5; i++)
header += fmt::format("auxiliary[{}] = {}\n",i,auxname[i]);
writer.write(header.c_str(), header.length());
}
/* ---------------------------------------------------------------------- */
void DumpCFGZstd::write_data(int n, double *mybuf)
{
writer.write(mybuf, n);
}
/* ---------------------------------------------------------------------- */
void DumpCFGZstd::write()
{
DumpCFG::write();
if (filewriter) {
if (multifile) {
writer.close();
} else {
if (flush_flag && writer.isopen()) {
writer.flush();
}
}
}
}
/* ---------------------------------------------------------------------- */
int DumpCFGZstd::modify_param(int narg, char **arg)
{
int consumed = DumpCFG::modify_param(narg, arg);
if(consumed == 0) {
try {
if (strcmp(arg[0],"checksum") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
if (strcmp(arg[1],"yes") == 0) writer.setChecksum(true);
else if (strcmp(arg[1],"no") == 0) writer.setChecksum(false);
else error->all(FLERR,"Illegal dump_modify command");
return 2;
} else if (strcmp(arg[0],"compression_level") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
int compression_level = utils::inumeric(FLERR, arg[1], false, lmp);
writer.setCompressionLevel(compression_level);
return 2;
}
} catch (FileWriterException & e) {
error->one(FLERR, e.what());
}
}
return consumed;
}
#endif

View File

@ -0,0 +1,65 @@
/* -*- 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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifdef LAMMPS_ZSTD
#ifdef DUMP_CLASS
DumpStyle(cfg/zstd,DumpCFGZstd)
#else
#ifndef LMP_DUMP_CFG_ZSTD_H
#define LMP_DUMP_CFG_ZSTD_H
#include "dump_cfg.h"
#include "zstd_file_writer.h"
namespace LAMMPS_NS {
class DumpCFGZstd : public DumpCFG {
public:
DumpCFGZstd(class LAMMPS *, int, char **);
virtual ~DumpCFGZstd();
protected:
ZstdFileWriter writer;
virtual void openfile();
virtual void write_header(bigint);
virtual void write_data(int, double *);
virtual void write();
virtual int modify_param(int, char **);
};
}
#endif
#endif
#endif
/* ERROR/WARNING messages:
E: Dump cfg/zstd only writes compressed files
The dump cfg/zstd output file name must have a .zstd suffix.
E: Cannot open dump file
Self-explanatory.
*/

View File

@ -15,8 +15,10 @@
#include "domain.h"
#include "error.h"
#include "update.h"
#include "utils.h"
#include <cstring>
#include "fmt/format.h"
using namespace LAMMPS_NS;
@ -25,6 +27,8 @@ DumpCustomGZ::DumpCustomGZ(LAMMPS *lmp, int narg, char **arg) :
{
gzFp = NULL;
compression_level = Z_BEST_COMPRESSION;
if (!compressed)
error->all(FLERR,"Dump custom/gz only writes compressed files");
}
@ -91,12 +95,15 @@ void DumpCustomGZ::openfile()
// each proc with filewriter = 1 opens a file
if (filewriter) {
std::string mode;
if (append_flag) {
gzFp = gzopen(filecurrent,"ab9");
mode = fmt::format("ab{}", compression_level);
} else {
gzFp = gzopen(filecurrent,"wb9");
mode = fmt::format("wb{}", compression_level);
}
gzFp = gzopen(filecurrent, mode.c_str());
if (gzFp == NULL) error->one(FLERR,"Cannot open dump file");
} else gzFp = NULL;
@ -120,14 +127,14 @@ void DumpCustomGZ::write_header(bigint ndump)
gzprintf(gzFp,BIGINT_FORMAT "\n",ndump);
if (domain->triclinic == 0) {
gzprintf(gzFp,"ITEM: BOX BOUNDS %s\n",boundstr);
gzprintf(gzFp,"%-1.16g %-1.16g\n",boxxlo,boxxhi);
gzprintf(gzFp,"%-1.16g %-1.16g\n",boxylo,boxyhi);
gzprintf(gzFp,"%-1.16g %-1.16g\n",boxzlo,boxzhi);
gzprintf(gzFp,"%-1.16e %-1.16e\n",boxxlo,boxxhi);
gzprintf(gzFp,"%-1.16e %-1.16e\n",boxylo,boxyhi);
gzprintf(gzFp,"%-1.16e %-1.16e\n",boxzlo,boxzhi);
} else {
gzprintf(gzFp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr);
gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxxlo,boxxhi,boxxy);
gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxylo,boxyhi,boxxz);
gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxzlo,boxzhi,boxyz);
gzprintf(gzFp,"%-1.16e %-1.16e %-1.16e\n",boxxlo,boxxhi,boxxy);
gzprintf(gzFp,"%-1.16e %-1.16e %-1.16e\n",boxylo,boxyhi,boxxz);
gzprintf(gzFp,"%-1.16e %-1.16e %-1.16e\n",boxzlo,boxzhi,boxyz);
}
gzprintf(gzFp,"ITEM: ATOMS %s\n",columns);
}
@ -156,3 +163,21 @@ void DumpCustomGZ::write()
}
}
/* ---------------------------------------------------------------------- */
int DumpCustomGZ::modify_param(int narg, char **arg)
{
int consumed = DumpCustom::modify_param(narg, arg);
if(consumed == 0) {
if (strcmp(arg[0],"compression_level") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
int min_level = Z_DEFAULT_COMPRESSION;
int max_level = Z_BEST_COMPRESSION;
compression_level = utils::inumeric(FLERR, arg[1], false, lmp);
if (compression_level < min_level || compression_level > max_level)
error->all(FLERR, fmt::format("Illegal dump_modify command: compression level must in the range of [{}, {}]", min_level, max_level));
return 2;
}
}
return consumed;
}

View File

@ -31,12 +31,15 @@ class DumpCustomGZ : public DumpCustom {
virtual ~DumpCustomGZ();
protected:
int compression_level;
gzFile gzFp; // file pointer for the compressed output stream
virtual void openfile();
virtual void write_header(bigint);
virtual void write_data(int, double *);
virtual void write();
virtual int modify_param(int, char **);
};
}

View File

@ -0,0 +1,195 @@
/* ----------------------------------------------------------------------
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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifdef LAMMPS_ZSTD
#include "dump_custom_zstd.h"
#include "domain.h"
#include "error.h"
#include "update.h"
#include "utils.h"
#include <cstring>
#include "fmt/format.h"
using namespace LAMMPS_NS;
DumpCustomZstd::DumpCustomZstd(LAMMPS *lmp, int narg, char **arg) :
DumpCustom(lmp, narg, arg)
{
if (!compressed)
error->all(FLERR,"Dump custom/zstd only writes compressed files");
}
/* ---------------------------------------------------------------------- */
DumpCustomZstd::~DumpCustomZstd()
{
}
/* ----------------------------------------------------------------------
generic opening of a dump file
ASCII or binary or gzipped
some derived classes override this function
------------------------------------------------------------------------- */
void DumpCustomZstd::openfile()
{
// single file, already opened, so just return
if (singlefile_opened) return;
if (multifile == 0) singlefile_opened = 1;
// if one file per timestep, replace '*' with current timestep
char *filecurrent = filename;
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
filestar,update->ntimestep,ptr+1);
else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1];
strcpy(nameslist[numfiles],filecurrent);
++numfiles;
} else {
remove(nameslist[fileidx]);
delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1];
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles;
}
}
}
// each proc with filewriter = 1 opens a file
if (filewriter) {
if (append_flag) {
error->one(FLERR, "dump/zstd currently doesn't support append");
}
try {
writer.open(filecurrent);
} catch (FileWriterException & e) {
error->one(FLERR, e.what());
}
}
// delete string with timestep replaced
if (multifile) delete [] filecurrent;
}
/* ---------------------------------------------------------------------- */
void DumpCustomZstd::write_header(bigint ndump)
{
std::string header;
if ((multiproc) || (!multiproc && me == 0)) {
if (unit_flag && !unit_count) {
++unit_count;
header = fmt::format("ITEM: UNITS\n{}\n",update->unit_style);
}
if (time_flag) {
header += fmt::format("ITEM: TIME\n{0:.16g}\n", compute_time());
}
header += fmt::format("ITEM: TIMESTEP\n{}\n", update->ntimestep);
header += fmt::format("ITEM: NUMBER OF ATOMS\n{}\n", ndump);
if (domain->triclinic == 0) {
header += fmt::format("ITEM: BOX BOUNDS {}\n", boundstr);
header += fmt::format("{0:-1.16e} {1:-1.16e}\n", boxxlo, boxxhi);
header += fmt::format("{0:-1.16e} {1:-1.16e}\n", boxylo, boxyhi);
header += fmt::format("{0:-1.16e} {1:-1.16e}\n", boxzlo, boxzhi);
} else {
header += fmt::format("ITEM: BOX BOUNDS xy xz yz {}\n", boundstr);
header += fmt::format("{0:-1.16e} {1:-1.16e} {2:-1.16e}\n", boxxlo, boxxhi, boxxy);
header += fmt::format("{0:-1.16e} {1:-1.16e} {2:-1.16e}\n", boxylo, boxyhi, boxxz);
header += fmt::format("{0:-1.16e} {1:-1.16e} {2:-1.16e}\n", boxzlo, boxzhi, boxyz);
}
header += fmt::format("ITEM: ATOMS {}\n", columns);
writer.write(header.c_str(), header.length());
}
}
/* ---------------------------------------------------------------------- */
void DumpCustomZstd::write_data(int n, double *mybuf)
{
writer.write(mybuf, n);
}
/* ---------------------------------------------------------------------- */
void DumpCustomZstd::write()
{
DumpCustom::write();
if (filewriter) {
if (multifile) {
writer.close();
} else {
if (flush_flag && writer.isopen()) {
writer.flush();
}
}
}
}
/* ---------------------------------------------------------------------- */
int DumpCustomZstd::modify_param(int narg, char **arg)
{
int consumed = DumpCustom::modify_param(narg, arg);
if(consumed == 0) {
try {
if (strcmp(arg[0],"checksum") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
if (strcmp(arg[1],"yes") == 0) writer.setChecksum(true);
else if (strcmp(arg[1],"no") == 0) writer.setChecksum(false);
else error->all(FLERR,"Illegal dump_modify command");
return 2;
} else if (strcmp(arg[0],"compression_level") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
int compression_level = utils::inumeric(FLERR, arg[1], false, lmp);
writer.setCompressionLevel(compression_level);
return 2;
}
} catch (FileWriterException & e) {
error->one(FLERR, e.what());
}
}
return consumed;
}
#endif

View File

@ -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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifdef LAMMPS_ZSTD
#ifdef DUMP_CLASS
DumpStyle(custom/zstd,DumpCustomZstd)
#else
#ifndef LMP_DUMP_CUSTOM_ZSTD_H
#define LMP_DUMP_CUSTOM_ZSTD_H
#include "dump_custom.h"
#include "zstd_file_writer.h"
#include <stdio.h>
namespace LAMMPS_NS {
class DumpCustomZstd : public DumpCustom {
public:
DumpCustomZstd(class LAMMPS *, int, char **);
virtual ~DumpCustomZstd();
protected:
ZstdFileWriter writer;
virtual void openfile();
virtual void write_header(bigint);
virtual void write_data(int, double *);
virtual void write();
virtual int modify_param(int, char **);
};
}
#endif
#endif
#endif
/* ERROR/WARNING messages:
E: Dump custom/zstd only writes compressed files
The dump custom/zstd output file name must have a .zst suffix.
E: Cannot open dump file
Self-explanatory.
*/

View File

@ -15,8 +15,10 @@
#include "domain.h"
#include "error.h"
#include "update.h"
#include "utils.h"
#include <cstring>
#include "fmt/format.h"
using namespace LAMMPS_NS;
@ -25,6 +27,8 @@ DumpLocalGZ::DumpLocalGZ(LAMMPS *lmp, int narg, char **arg) :
{
gzFp = NULL;
compression_level = Z_BEST_COMPRESSION;
if (!compressed)
error->all(FLERR,"Dump local/gz only writes compressed files");
}
@ -91,12 +95,15 @@ void DumpLocalGZ::openfile()
// each proc with filewriter = 1 opens a file
if (filewriter) {
std::string mode;
if (append_flag) {
gzFp = gzopen(filecurrent,"ab9");
mode = fmt::format("ab{}", compression_level);
} else {
gzFp = gzopen(filecurrent,"wb9");
mode = fmt::format("wb{}", compression_level);
}
gzFp = gzopen(filecurrent, mode.c_str());
if (gzFp == NULL) error->one(FLERR,"Cannot open dump file");
} else gzFp = NULL;
@ -116,18 +123,18 @@ void DumpLocalGZ::write_header(bigint ndump)
gzprintf(gzFp,"ITEM: TIMESTEP\n");
gzprintf(gzFp,BIGINT_FORMAT "\n",update->ntimestep);
gzprintf(gzFp,"ITEM: NUMBER OF ATOMS\n");
gzprintf(gzFp,"ITEM: NUMBER OF %s\n",label);
gzprintf(gzFp,BIGINT_FORMAT "\n",ndump);
if (domain->triclinic == 0) {
gzprintf(gzFp,"ITEM: BOX BOUNDS %s\n",boundstr);
gzprintf(gzFp,"%-1.16g %-1.16g\n",boxxlo,boxxhi);
gzprintf(gzFp,"%-1.16g %-1.16g\n",boxylo,boxyhi);
gzprintf(gzFp,"%-1.16g %-1.16g\n",boxzlo,boxzhi);
} else {
if (domain->triclinic) {
gzprintf(gzFp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr);
gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxxlo,boxxhi,boxxy);
gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxylo,boxyhi,boxxz);
gzprintf(gzFp,"%-1.16g %-1.16g %-1.16g\n",boxzlo,boxzhi,boxyz);
gzprintf(gzFp,"%-1.16e %-1.16e %-1.16e\n",boxxlo,boxxhi,boxxy);
gzprintf(gzFp,"%-1.16e %-1.16e %-1.16e\n",boxylo,boxyhi,boxxz);
gzprintf(gzFp,"%-1.16e %-1.16e %-1.16e\n",boxzlo,boxzhi,boxyz);
} else {
gzprintf(gzFp,"ITEM: BOX BOUNDS %s\n",boundstr);
gzprintf(gzFp,"%-1.16e %-1.16e\n",boxxlo,boxxhi);
gzprintf(gzFp,"%-1.16e %-1.16e\n",boxylo,boxyhi);
gzprintf(gzFp,"%-1.16e %-1.16e\n",boxzlo,boxzhi);
}
gzprintf(gzFp,"ITEM: %s %s\n",label,columns);
}
@ -171,3 +178,21 @@ void DumpLocalGZ::write()
}
}
/* ---------------------------------------------------------------------- */
int DumpLocalGZ::modify_param(int narg, char **arg)
{
int consumed = DumpLocal::modify_param(narg, arg);
if(consumed == 0) {
if (strcmp(arg[0],"compression_level") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
int min_level = Z_DEFAULT_COMPRESSION;
int max_level = Z_BEST_COMPRESSION;
compression_level = utils::inumeric(FLERR, arg[1], false, lmp);
if (compression_level < min_level || compression_level > max_level)
error->all(FLERR, fmt::format("Illegal dump_modify command: compression level must in the range of [{}, {}]", min_level, max_level));
return 2;
}
}
return consumed;
}

View File

@ -31,12 +31,15 @@ class DumpLocalGZ : public DumpLocal {
virtual ~DumpLocalGZ();
protected:
int compression_level;
gzFile gzFp; // file pointer for the compressed output stream
virtual void openfile();
virtual void write_header(bigint);
virtual void write_data(int, double *);
virtual void write();
virtual int modify_param(int, char **);
};
}

View File

@ -0,0 +1,195 @@
/* ----------------------------------------------------------------------
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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifdef LAMMPS_ZSTD
#include "dump_local_zstd.h"
#include "domain.h"
#include "error.h"
#include "update.h"
#include "utils.h"
#include <cstring>
#include "fmt/format.h"
using namespace LAMMPS_NS;
DumpLocalZstd::DumpLocalZstd(LAMMPS *lmp, int narg, char **arg) :
DumpLocal(lmp, narg, arg)
{
if (!compressed)
error->all(FLERR,"Dump local/zstd only writes compressed files");
}
/* ---------------------------------------------------------------------- */
DumpLocalZstd::~DumpLocalZstd()
{
}
/* ----------------------------------------------------------------------
generic opening of a dump file
ASCII or binary or gzipped
some derived classes override this function
------------------------------------------------------------------------- */
void DumpLocalZstd::openfile()
{
// single file, already opened, so just return
if (singlefile_opened) return;
if (multifile == 0) singlefile_opened = 1;
// if one file per timestep, replace '*' with current timestep
char *filecurrent = filename;
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
filestar,update->ntimestep,ptr+1);
else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1];
strcpy(nameslist[numfiles],filecurrent);
++numfiles;
} else {
remove(nameslist[fileidx]);
delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1];
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles;
}
}
}
// each proc with filewriter = 1 opens a file
if (filewriter) {
if (append_flag) {
error->one(FLERR, "dump cfg/zstd currently doesn't support append");
}
try {
writer.open(filecurrent);
} catch (FileWriterException & e) {
error->one(FLERR, e.what());
}
}
// delete string with timestep replaced
if (multifile) delete [] filecurrent;
}
void DumpLocalZstd::write_header(bigint ndump)
{
std::string header;
if ((multiproc) || (!multiproc && me == 0)) {
if (unit_flag && !unit_count) {
++unit_count;
header = fmt::format("ITEM: UNITS\n{}\n",update->unit_style);
}
if (time_flag) {
header += fmt::format("ITEM: TIME\n{0:.16g}\n", compute_time());
}
header += fmt::format("ITEM: TIMESTEP\n{}\n", update->ntimestep);
header += fmt::format("ITEM: NUMBER OF {}\n{}\n", label, ndump);
if (domain->triclinic == 0) {
header += fmt::format("ITEM: BOX BOUNDS {}\n", boundstr);
header += fmt::format("{0:-1.16e} {1:-1.16e}\n", boxxlo, boxxhi);
header += fmt::format("{0:-1.16e} {1:-1.16e}\n", boxylo, boxyhi);
header += fmt::format("{0:-1.16e} {1:-1.16e}\n", boxzlo, boxzhi);
} else {
header += fmt::format("ITEM: BOX BOUNDS xy xz yz {}\n", boundstr);
header += fmt::format("{0:-1.16e} {1:-1.16e} {2:-1.16e}\n", boxxlo, boxxhi, boxxy);
header += fmt::format("{0:-1.16e} {1:-1.16e} {2:-1.16e}\n", boxylo, boxyhi, boxxz);
header += fmt::format("{0:-1.16e} {1:-1.16e} {2:-1.16e}\n", boxzlo, boxzhi, boxyz);
}
header += fmt::format("ITEM: {} {}\n", label, columns);
writer.write(header.c_str(), header.length());
}
}
/* ---------------------------------------------------------------------- */
void DumpLocalZstd::write_data(int n, double *mybuf)
{
writer.write(mybuf, sizeof(char)*n);
}
/* ---------------------------------------------------------------------- */
void DumpLocalZstd::write()
{
DumpLocal::write();
if (filewriter) {
if (multifile) {
writer.close();
} else {
if (flush_flag && writer.isopen()) {
writer.flush();
}
}
}
}
/* ---------------------------------------------------------------------- */
int DumpLocalZstd::modify_param(int narg, char **arg)
{
int consumed = DumpLocal::modify_param(narg, arg);
if(consumed == 0) {
try {
if (strcmp(arg[0],"checksum") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
if (strcmp(arg[1],"yes") == 0) writer.setChecksum(true);
else if (strcmp(arg[1],"no") == 0) writer.setChecksum(false);
else error->all(FLERR,"Illegal dump_modify command");
return 2;
} else if (strcmp(arg[0],"compression_level") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
int compression_level = utils::inumeric(FLERR, arg[1], false, lmp);
writer.setCompressionLevel(compression_level);
return 2;
}
} catch (FileWriterException & e) {
error->one(FLERR, e.what());
}
}
return consumed;
}
#endif

View File

@ -0,0 +1,66 @@
/* -*- 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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifdef LAMMPS_ZSTD
#ifdef DUMP_CLASS
DumpStyle(local/zstd,DumpLocalZstd)
#else
#ifndef LMP_DUMP_LOCAL_ZSTD_H
#define LMP_DUMP_LOCAL_ZSTD_H
#include "dump_local.h"
#include "zstd_file_writer.h"
namespace LAMMPS_NS {
class DumpLocalZstd : public DumpLocal {
public:
DumpLocalZstd(class LAMMPS *, int, char **);
virtual ~DumpLocalZstd();
protected:
ZstdFileWriter writer;
virtual void openfile();
virtual void write_header(bigint);
virtual void write_data(int, double *);
virtual void write();
virtual int modify_param(int, char **);
};
}
#endif
#endif
#endif
/* ERROR/WARNING messages:
E: Dump local/zstd only writes compressed files
The dump local/zstd output file name must have a .zst suffix.
E: Cannot open dump file
Self-explanatory.
*/

View File

@ -14,8 +14,10 @@
#include "dump_xyz_gz.h"
#include "error.h"
#include "update.h"
#include "utils.h"
#include <cstring>
#include "fmt/format.h"
using namespace LAMMPS_NS;
@ -24,6 +26,8 @@ DumpXYZGZ::DumpXYZGZ(LAMMPS *lmp, int narg, char **arg) :
{
gzFp = NULL;
compression_level = Z_BEST_COMPRESSION;
if (!compressed)
error->all(FLERR,"Dump xyz/gz only writes compressed files");
}
@ -90,12 +94,15 @@ void DumpXYZGZ::openfile()
// each proc with filewriter = 1 opens a file
if (filewriter) {
std::string mode;
if (append_flag) {
gzFp = gzopen(filecurrent,"ab9");
mode = fmt::format("ab{}", compression_level);
} else {
gzFp = gzopen(filecurrent,"wb9");
mode = fmt::format("wb{}", compression_level);
}
gzFp = gzopen(filecurrent, mode.c_str());
if (gzFp == NULL) error->one(FLERR,"Cannot open dump file");
} else gzFp = NULL;
@ -134,3 +141,22 @@ void DumpXYZGZ::write()
}
}
}
/* ---------------------------------------------------------------------- */
int DumpXYZGZ::modify_param(int narg, char **arg)
{
int consumed = DumpXYZ::modify_param(narg, arg);
if(consumed == 0) {
if (strcmp(arg[0],"compression_level") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
int min_level = Z_DEFAULT_COMPRESSION;
int max_level = Z_BEST_COMPRESSION;
compression_level = utils::inumeric(FLERR, arg[1], false, lmp);
if (compression_level < min_level || compression_level > max_level)
error->all(FLERR, fmt::format("Illegal dump_modify command: compression level must in the range of [{}, {}]", min_level, max_level));
return 2;
}
}
return consumed;
}

View File

@ -31,12 +31,15 @@ class DumpXYZGZ : public DumpXYZ {
virtual ~DumpXYZGZ();
protected:
int compression_level;
gzFile gzFp; // file pointer for the compressed output stream
virtual void openfile();
virtual void write_header(bigint);
virtual void write_data(int, double *);
virtual void write();
virtual int modify_param(int, char **);
};
}

View File

@ -0,0 +1,170 @@
/* ----------------------------------------------------------------------
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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifdef LAMMPS_ZSTD
#include "dump_xyz_zstd.h"
#include "error.h"
#include "update.h"
#include "utils.h"
#include <cstring>
#include "fmt/format.h"
using namespace LAMMPS_NS;
DumpXYZZstd::DumpXYZZstd(LAMMPS *lmp, int narg, char **arg) :
DumpXYZ(lmp, narg, arg)
{
if (!compressed)
error->all(FLERR,"Dump xyz/zstd only writes compressed files");
}
/* ---------------------------------------------------------------------- */
DumpXYZZstd::~DumpXYZZstd()
{
}
/* ----------------------------------------------------------------------
generic opening of a dump file
ASCII or binary or gzipped
some derived classes override this function
------------------------------------------------------------------------- */
void DumpXYZZstd::openfile()
{
// single file, already opened, so just return
if (singlefile_opened) return;
if (multifile == 0) singlefile_opened = 1;
// if one file per timestep, replace '*' with current timestep
char *filecurrent = filename;
if (multiproc) filecurrent = multiname;
if (multifile) {
char *filestar = filecurrent;
filecurrent = new char[strlen(filestar) + 16];
char *ptr = strchr(filestar,'*');
*ptr = '\0';
if (padflag == 0)
sprintf(filecurrent,"%s" BIGINT_FORMAT "%s",
filestar,update->ntimestep,ptr+1);
else {
char bif[8],pad[16];
strcpy(bif,BIGINT_FORMAT);
sprintf(pad,"%%s%%0%d%s%%s",padflag,&bif[1]);
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*ptr = '*';
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1];
strcpy(nameslist[numfiles],filecurrent);
++numfiles;
} else {
remove(nameslist[fileidx]);
delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1];
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles;
}
}
}
// each proc with filewriter = 1 opens a file
if (filewriter) {
if (append_flag) {
error->one(FLERR, "dump cfg/zstd currently doesn't support append");
}
try {
writer.open(filecurrent);
} catch (FileWriterException & e) {
error->one(FLERR, e.what());
}
}
// delete string with timestep replaced
if (multifile) delete [] filecurrent;
}
void DumpXYZZstd::write_header(bigint ndump)
{
if (me == 0) {
std::string header = fmt::format("{}\n", ndump);
header += fmt::format("Atoms. Timestep: {}\n", update->ntimestep);
writer.write(header.c_str(), header.length());
}
}
/* ---------------------------------------------------------------------- */
void DumpXYZZstd::write_data(int n, double *mybuf)
{
writer.write(mybuf, n);
}
/* ---------------------------------------------------------------------- */
void DumpXYZZstd::write()
{
DumpXYZ::write();
if (filewriter) {
if (multifile) {
writer.close();
} else {
if (flush_flag && writer.isopen()) {
writer.flush();
}
}
}
}
/* ---------------------------------------------------------------------- */
int DumpXYZZstd::modify_param(int narg, char **arg)
{
int consumed = DumpXYZ::modify_param(narg, arg);
if(consumed == 0) {
try {
if (strcmp(arg[0],"checksum") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
if (strcmp(arg[1],"yes") == 0) writer.setChecksum(true);
else if (strcmp(arg[1],"no") == 0) writer.setChecksum(false);
else error->all(FLERR,"Illegal dump_modify command");
return 2;
} else if (strcmp(arg[0],"compression_level") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
int compression_level = utils::inumeric(FLERR, arg[1], false, lmp);
writer.setCompressionLevel(compression_level);
return 2;
}
} catch (FileWriterException & e) {
error->one(FLERR, e.what());
}
}
return consumed;
}
#endif

View File

@ -0,0 +1,66 @@
/* -*- 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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifdef LAMMPS_ZSTD
#ifdef DUMP_CLASS
DumpStyle(xyz/zstd,DumpXYZZstd)
#else
#ifndef LMP_DUMP_XYZ_ZSTD_H
#define LMP_DUMP_XYZ_ZSTD_H
#include "dump_xyz.h"
#include "zstd_file_writer.h"
namespace LAMMPS_NS {
class DumpXYZZstd : public DumpXYZ {
public:
DumpXYZZstd(class LAMMPS *, int, char **);
virtual ~DumpXYZZstd();
protected:
ZstdFileWriter writer;
virtual void openfile();
virtual void write_header(bigint);
virtual void write_data(int, double *);
virtual void write();
virtual int modify_param(int, char **);
};
}
#endif
#endif
#endif
/* ERROR/WARNING messages:
E: Dump xyz/zstd only writes compressed files
The dump xyz/zstd output file name must have a .zst suffix.
E: Cannot open dump file
Self-explanatory.
*/

View File

@ -0,0 +1,162 @@
/* -*- 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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifdef LAMMPS_ZSTD
#include "zstd_file_writer.h"
#include <stdio.h>
#include "fmt/format.h"
using namespace LAMMPS_NS;
ZstdFileWriter::ZstdFileWriter() : FileWriter(),
compression_level(0),
checksum_flag(1),
cctx(nullptr),
fp(nullptr)
{
out_buffer_size = ZSTD_CStreamOutSize();
out_buffer = new char[out_buffer_size];
}
/* ---------------------------------------------------------------------- */
ZstdFileWriter::~ZstdFileWriter()
{
close();
delete [] out_buffer;
out_buffer = nullptr;
out_buffer_size = 0;
}
/* ---------------------------------------------------------------------- */
void ZstdFileWriter::open(const std::string & path)
{
if(isopen()) return;
fp = fopen(path.c_str(), "wb");
if (!fp) {
throw FileWriterException(fmt::format("Could not open file '{}'", path));
}
cctx = ZSTD_createCCtx();
if (!cctx) {
fclose(fp);
fp = nullptr;
throw FileWriterException("Could not create Zstd context");
}
ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, compression_level);
ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, checksum_flag);
}
/* ---------------------------------------------------------------------- */
size_t ZstdFileWriter::write(const void * buffer, size_t length)
{
if(!isopen()) return 0;
ZSTD_inBuffer input = { buffer, length, 0 };
ZSTD_EndDirective mode = ZSTD_e_continue;
do {
ZSTD_outBuffer output = { out_buffer, out_buffer_size, 0 };
size_t const remaining = ZSTD_compressStream2(cctx, &output, &input, mode);
fwrite(out_buffer, sizeof(char), output.pos, fp);
} while(input.pos < input.size);
return length;
}
/* ---------------------------------------------------------------------- */
void ZstdFileWriter::flush()
{
if(!isopen()) return;
size_t remaining;
ZSTD_inBuffer input = { nullptr, 0, 0 };
ZSTD_EndDirective mode = ZSTD_e_flush;
do {
ZSTD_outBuffer output = { out_buffer, out_buffer_size, 0 };
remaining = ZSTD_compressStream2(cctx, &output, &input, mode);
fwrite(out_buffer, sizeof(char), output.pos, fp);
} while(remaining);
fflush(fp);
}
/* ---------------------------------------------------------------------- */
void ZstdFileWriter::close()
{
if(!isopen()) return;
size_t remaining;
ZSTD_inBuffer input = { nullptr, 0, 0 };
ZSTD_EndDirective mode = ZSTD_e_end;
do {
ZSTD_outBuffer output = { out_buffer, out_buffer_size, 0 };
remaining = ZSTD_compressStream2(cctx, &output, &input, mode);
fwrite(out_buffer, sizeof(char), output.pos, fp);
} while(remaining);
ZSTD_freeCCtx(cctx);
cctx = nullptr;
fclose(fp);
fp = nullptr;
}
/* ---------------------------------------------------------------------- */
bool ZstdFileWriter::isopen() const
{
return fp && cctx;
}
/* ---------------------------------------------------------------------- */
void ZstdFileWriter::setCompressionLevel(int level)
{
if (isopen())
throw FileWriterException("Compression level can not be changed while file is open");
const int min_level = ZSTD_minCLevel();
const int max_level = ZSTD_maxCLevel();
if(level < min_level || level > max_level)
throw FileWriterException(fmt::format("Compression level must in the range of [{}, {}]", min_level, max_level));
compression_level = level;
}
/* ---------------------------------------------------------------------- */
void ZstdFileWriter::setChecksum(bool enabled)
{
if (isopen())
throw FileWriterException("Checksum flag can not be changed while file is open");
checksum_flag = enabled ? 1 : 0;
}
#endif

View File

@ -0,0 +1,55 @@
/* -*- 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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifdef LAMMPS_ZSTD
#ifndef LMP_ZSTD_FILE_WRITER_H
#define LMP_ZSTD_FILE_WRITER_H
#include "file_writer.h"
#include <string>
#include <zstd.h>
#include <exception>
namespace LAMMPS_NS {
class ZstdFileWriter : public FileWriter {
int compression_level;
int checksum_flag;
ZSTD_CCtx * cctx;
FILE * fp;
char * out_buffer;
size_t out_buffer_size;
public:
ZstdFileWriter();
virtual ~ZstdFileWriter();
virtual void open(const std::string & path) override;
virtual void close() override;
virtual void flush() override;
virtual size_t write(const void * buffer, size_t length) override;
virtual bool isopen() const override;
void setCompressionLevel(int level);
void setChecksum(bool enabled);
};
}
#endif
#endif

View File

@ -116,6 +116,7 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp)
// check file suffixes
// if ends in .bin = binary file
// else if ends in .gz = gzipped text file
// else if ends in .zst = Zstd compressed text file
// else ASCII text file
fp = NULL;
@ -153,6 +154,8 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp)
if (suffix > filename && strcmp(suffix,".bin") == 0) binary = 1;
suffix = filename + strlen(filename) - strlen(".gz");
if (suffix > filename && strcmp(suffix,".gz") == 0) compressed = 1;
suffix = filename + strlen(filename) - strlen(".zst");
if (suffix > filename && strcmp(suffix,".zst") == 0) compressed = 1;
}
/* ---------------------------------------------------------------------- */

View File

@ -269,14 +269,14 @@ void DumpLocal::write_header(bigint ndump)
fprintf(fp,BIGINT_FORMAT "\n",ndump);
if (domain->triclinic) {
fprintf(fp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr);
fprintf(fp,"%g %g %g\n",boxxlo,boxxhi,boxxy);
fprintf(fp,"%g %g %g\n",boxylo,boxyhi,boxxz);
fprintf(fp,"%g %g %g\n",boxzlo,boxzhi,boxyz);
fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxxlo,boxxhi,boxxy);
fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxylo,boxyhi,boxxz);
fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxzlo,boxzhi,boxyz);
} else {
fprintf(fp,"ITEM: BOX BOUNDS %s\n",boundstr);
fprintf(fp,"%g %g\n",boxxlo,boxxhi);
fprintf(fp,"%g %g\n",boxylo,boxyhi);
fprintf(fp,"%g %g\n",boxzlo,boxzhi);
fprintf(fp,"%-1.16e %-1.16e\n",boxxlo,boxxhi);
fprintf(fp,"%-1.16e %-1.16e\n",boxylo,boxyhi);
fprintf(fp,"%-1.16e %-1.16e\n",boxzlo,boxzhi);
}
fprintf(fp,"ITEM: %s %s\n",label,columns);
}

53
src/file_writer.h Normal file
View File

@ -0,0 +1,53 @@
/* -*- 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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Richard Berger (Temple U)
------------------------------------------------------------------------- */
#ifndef LMP_FILE_WRITER_H
#define LMP_FILE_WRITER_H
#include <string>
namespace LAMMPS_NS {
class FileWriter {
public:
FileWriter() = default;
virtual ~FileWriter() = default;
virtual void open(const std::string & path) = 0;
virtual void close() = 0;
virtual void flush() = 0;
virtual size_t write(const void * buffer, size_t length) = 0;
virtual bool isopen() const = 0;
};
class FileWriterException : public std::exception {
std::string message;
public:
FileWriterException(const std::string & msg) : message(msg) {
}
~FileWriterException() throw() {
}
virtual const char * what() const throw() {
return message.c_str();
}
};
}
#endif

View File

@ -29,6 +29,74 @@ target_link_libraries(test_dump_atom PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME DumpAtom COMMAND test_dump_atom WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties(DumpAtom PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
if (PKG_COMPRESS)
find_program(GZIP_BINARY NAMES gzip REQUIRED)
add_executable(test_dump_atom_gz test_dump_atom_gz.cpp)
target_link_libraries(test_dump_atom_gz PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME DumpAtomGZ COMMAND test_dump_atom_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}")
add_executable(test_dump_custom_gz test_dump_custom_gz.cpp)
target_link_libraries(test_dump_custom_gz PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME DumpCustomGZ COMMAND test_dump_custom_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}")
add_executable(test_dump_cfg_gz test_dump_cfg_gz.cpp)
target_link_libraries(test_dump_cfg_gz PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}")
add_executable(test_dump_xyz_gz test_dump_xyz_gz.cpp)
target_link_libraries(test_dump_xyz_gz PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME DumpXYZGZ COMMAND test_dump_xyz_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}")
add_executable(test_dump_local_gz test_dump_local_gz.cpp)
target_link_libraries(test_dump_local_gz PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME DumpLocalGZ COMMAND test_dump_local_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}")
find_program(ZSTD_BINARY NAMES zstd)
if (ZSTD_BINARY)
add_executable(test_dump_atom_zstd test_dump_atom_zstd.cpp)
target_link_libraries(test_dump_atom_zstd PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME DumpAtomZstd COMMAND test_dump_atom_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}")
add_executable(test_dump_custom_zstd test_dump_custom_zstd.cpp)
target_link_libraries(test_dump_custom_zstd PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME DumpCustomZstd COMMAND test_dump_custom_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}")
add_executable(test_dump_cfg_zstd test_dump_cfg_zstd.cpp)
target_link_libraries(test_dump_cfg_zstd PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}")
add_executable(test_dump_xyz_zstd test_dump_xyz_zstd.cpp)
target_link_libraries(test_dump_xyz_zstd PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME DumpXYZZstd COMMAND test_dump_xyz_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}")
add_executable(test_dump_local_zstd test_dump_local_zstd.cpp)
target_link_libraries(test_dump_local_zstd PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME DumpLocalZstd COMMAND test_dump_local_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}")
endif()
endif()
add_executable(test_dump_custom test_dump_custom.cpp)
target_link_libraries(test_dump_custom PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME DumpCustom COMMAND test_dump_custom WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

View File

@ -0,0 +1,266 @@
/* ----------------------------------------------------------------------
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 "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include <string>
char * GZIP_BINARY = nullptr;
using ::testing::Eq;
class DumpAtomGZTest : public MeltTest {
std::string dump_style = "atom";
public:
void enable_triclinic() {
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id0 {}", dump_modify_options));
command(fmt::format("dump_modify id1 {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
}
};
//-------------------------------------------------------------------------------------------------
// GZ compressed files
//-------------------------------------------------------------------------------------------------
TEST_F(DumpAtomGZTest, compressed_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_run0.melt";
auto compressed_file = "dump_gz_compressed_run0.melt.gz";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_THAT(converted_file, Eq("dump_gz_compressed_run0.melt"));
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpAtomGZTest, compressed_with_units_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_with_units_run0.melt";
auto compressed_file = "dump_gz_compressed_with_units_run0.melt.gz";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpAtomGZTest, compressed_with_time_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_with_time_run0.melt";
auto compressed_file = "dump_gz_compressed_with_time_run0.melt.gz";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpAtomGZTest, compressed_triclinic_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_tri_run0.melt";
auto compressed_file = "dump_gz_compressed_tri_run0.melt.gz";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpAtomGZTest, compressed_triclinic_with_units_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_tri_with_units_run0.melt";
auto compressed_file = "dump_gz_compressed_tri_with_units_run0.melt.gz";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpAtomGZTest, compressed_triclinic_with_time_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_tri_with_time_run0.melt";
auto compressed_file = "dump_gz_compressed_tri_with_time_run0.melt.gz";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpAtomGZTest, compressed_triclinic_with_image_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_tri_with_image_run0.melt";
auto compressed_file = "dump_gz_compressed_tri_with_image_run0.melt.gz";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "image yes", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {
std::vector<std::string> env = utils::split_words(var);
for (auto arg : env) {
if (arg == "-v") {
verbose = true;
}
}
}
GZIP_BINARY = getenv("GZIP_BINARY");
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
int rv = RUN_ALL_TESTS();
MPI_Finalize();
return rv;
}

View File

@ -0,0 +1,273 @@
/* ----------------------------------------------------------------------
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 "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include <string>
char * ZSTD_BINARY = nullptr;
using ::testing::Eq;
class DumpAtomZSTDTest : public MeltTest {
std::string dump_style = "atom";
public:
void enable_triclinic() {
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id0 {}", dump_modify_options));
command(fmt::format("dump_modify id1 {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
}
};
//-------------------------------------------------------------------------------------------------
// ZSTD compressed files
//-------------------------------------------------------------------------------------------------
TEST_F(DumpAtomZSTDTest, compressed_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_run0.melt";
auto compressed_file = "dump_zstd_compressed_run0.melt.zst";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "", 0);
// make sure file is closed
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_THAT(converted_file, Eq("dump_zstd_compressed_run0.melt"));
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpAtomZSTDTest, compressed_with_units_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_with_units_run0.melt";
auto compressed_file = "dump_zstd_compressed_with_units_run0.melt.zst";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", 0);
// make sure file is closed
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpAtomZSTDTest, compressed_with_time_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_with_time_run0.melt";
auto compressed_file = "dump_zstd_compressed_with_time_run0.melt.zst";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", 0);
// make sure file is closed
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpAtomZSTDTest, compressed_triclinic_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_tri_run0.melt";
auto compressed_file = "dump_zstd_compressed_tri_run0.melt.zst";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "", 0);
// make sure file is closed
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_units_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_tri_with_units_run0.melt";
auto compressed_file = "dump_zstd_compressed_tri_with_units_run0.melt.zst";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", 0);
// make sure file is closed
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_time_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_tri_with_time_run0.melt";
auto compressed_file = "dump_zstd_compressed_tri_with_time_run0.melt.zst";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", 0);
// make sure file is closed
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_image_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_tri_with_image_run0.melt";
auto compressed_file = "dump_zstd_compressed_tri_with_image_run0.melt.zst";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "image yes", 0);
// make sure file is closed
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {
std::vector<std::string> env = utils::split_words(var);
for (auto arg : env) {
if (arg == "-v") {
verbose = true;
}
}
}
ZSTD_BINARY = getenv("ZSTD_BINARY");
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
int rv = RUN_ALL_TESTS();
MPI_Finalize();
return rv;
}

View File

@ -46,7 +46,7 @@ TEST_F(DumpCfgTest, invalid_options)
TEST_F(DumpCfgTest, require_multifile)
{
auto dump_file = "dump_melt_run.cfg";
auto dump_file = "dump.melt.cfg_run.cfg";
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz xu yu zu xsu ysu zsu vx vy vz fx fy fz";
if (!verbose) ::testing::internal::CaptureStdout();
@ -60,58 +60,58 @@ TEST_F(DumpCfgTest, require_multifile)
TEST_F(DumpCfgTest, run0)
{
auto dump_file = "dump_cfg_run*.melt";
auto dump_file = "dump_cfg_run*.melt.cfg";
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
generate_dump(dump_file, fields, "", 0);
ASSERT_FILE_EXISTS("dump_cfg_run0.melt");
auto lines = read_lines("dump_cfg_run0.melt");
ASSERT_FILE_EXISTS("dump_cfg_run0.melt.cfg");
auto lines = read_lines("dump_cfg_run0.melt.cfg");
ASSERT_EQ(lines.size(), 124);
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
delete_file("dump_cfg_run0.melt");
delete_file("dump_cfg_run0.melt.cfg");
}
TEST_F(DumpCfgTest, unwrap_run0)
{
auto dump_file = "dump_cfg_unwrap_run*.melt";
auto dump_file = "dump_cfg_unwrap_run*.melt.cfg";
auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
generate_dump(dump_file, fields, "", 0);
ASSERT_FILE_EXISTS("dump_cfg_unwrap_run0.melt");
auto lines = read_lines("dump_cfg_unwrap_run0.melt");
ASSERT_FILE_EXISTS("dump_cfg_unwrap_run0.melt.cfg");
auto lines = read_lines("dump_cfg_unwrap_run0.melt.cfg");
ASSERT_EQ(lines.size(), 124);
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
delete_file("dump_cfg_unwrap_run0.melt");
delete_file("dump_cfg_unwrap_run0.melt.cfg");
}
TEST_F(DumpCfgTest, no_buffer_run0)
{
auto dump_file = "dump_cfg_no_buffer_run*.melt";
auto dump_file = "dump_cfg_no_buffer_run*.melt.cfg";
auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
generate_dump(dump_file, fields, "buffer no", 0);
ASSERT_FILE_EXISTS("dump_cfg_no_buffer_run0.melt");
auto lines = read_lines("dump_cfg_no_buffer_run0.melt");
ASSERT_FILE_EXISTS("dump_cfg_no_buffer_run0.melt.cfg");
auto lines = read_lines("dump_cfg_no_buffer_run0.melt.cfg");
ASSERT_EQ(lines.size(), 124);
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
delete_file("dump_cfg_no_buffer_run0.melt");
delete_file("dump_cfg_no_buffer_run0.melt.cfg");
}
TEST_F(DumpCfgTest, no_unwrap_no_buffer_run0)
{
auto dump_file = "dump_cfg_no_unwrap_no_buffer_run*.melt";
auto dump_file = "dump_cfg_no_unwrap_no_buffer_run*.melt.cfg";
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
generate_dump(dump_file, fields, "buffer no", 0);
ASSERT_FILE_EXISTS("dump_cfg_no_unwrap_no_buffer_run0.melt");
auto lines = read_lines("dump_cfg_no_unwrap_no_buffer_run0.melt");
ASSERT_FILE_EXISTS("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg");
auto lines = read_lines("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg");
ASSERT_EQ(lines.size(), 124);
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
delete_file("dump_cfg_no_unwrap_no_buffer_run0.melt");
delete_file("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg");
}

View File

@ -0,0 +1,129 @@
/* ----------------------------------------------------------------------
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 "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
char * GZIP_BINARY = nullptr;
using ::testing::Eq;
class DumpCfgGZTest : public MeltTest {
std::string dump_style = "cfg";
public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string fields, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id0 {}", dump_modify_options));
command(fmt::format("dump_modify id1 {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
}
};
TEST_F(DumpCfgGZTest, compressed_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
auto text_files = "dump_cfg_gz_text_run*.melt.cfg";
auto compressed_files = "dump_cfg_gz_compressed_run*.melt.cfg.gz";
auto text_file = "dump_cfg_gz_text_run0.melt.cfg";
auto compressed_file = "dump_cfg_gz_compressed_run0.melt.cfg.gz";
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
generate_text_and_compressed_dump(text_files, compressed_files, "cfg/gz", fields, "", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpCfgGZTest, compressed_unwrap_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
auto text_files = "dump_cfg_unwrap_gz_text_run*.melt.cfg";
auto compressed_files = "dump_cfg_unwrap_gz_compressed_run*.melt.cfg.gz";
auto text_file = "dump_cfg_unwrap_gz_text_run0.melt.cfg";
auto compressed_file = "dump_cfg_unwrap_gz_compressed_run0.melt.cfg.gz";
auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
generate_text_and_compressed_dump(text_files, compressed_files, "cfg/gz", fields, "", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {
std::vector<std::string> env = utils::split_words(var);
for (auto arg : env) {
if (arg == "-v") {
verbose = true;
}
}
}
GZIP_BINARY = getenv("GZIP_BINARY");
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
int rv = RUN_ALL_TESTS();
MPI_Finalize();
return rv;
}

View File

@ -0,0 +1,129 @@
/* ----------------------------------------------------------------------
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 "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
char * ZSTD_BINARY = nullptr;
using ::testing::Eq;
class DumpCfgZstdTest : public MeltTest {
std::string dump_style = "cfg";
public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string fields, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id0 {}", dump_modify_options));
command(fmt::format("dump_modify id1 {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
}
};
TEST_F(DumpCfgZstdTest, compressed_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
auto text_files = "dump_cfg_zstd_text_run*.melt.cfg";
auto compressed_files = "dump_cfg_zstd_compressed_run*.melt.cfg.zst";
auto text_file = "dump_cfg_zstd_text_run0.melt.cfg";
auto compressed_file = "dump_cfg_zstd_compressed_run0.melt.cfg.zst";
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
generate_text_and_compressed_dump(text_files, compressed_files, "cfg/gz", fields, "", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpCfgZstdTest, compressed_unwrap_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
auto text_files = "dump_cfg_unwrap_zstd_text_run*.melt.cfg";
auto compressed_files = "dump_cfg_unwrap_zstd_compressed_run*.melt.cfg.zst";
auto text_file = "dump_cfg_unwrap_zstd_text_run0.melt.cfg";
auto compressed_file = "dump_cfg_unwrap_zstd_compressed_run0.melt.cfg.zst";
auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
generate_text_and_compressed_dump(text_files, compressed_files, "cfg/zstd", fields, "", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {
std::vector<std::string> env = utils::split_words(var);
for (auto arg : env) {
if (arg == "-v") {
verbose = true;
}
}
}
ZSTD_BINARY = getenv("ZSTD_BINARY");
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
int rv = RUN_ALL_TESTS();
MPI_Finalize();
return rv;
}

View File

@ -0,0 +1,144 @@
/* ----------------------------------------------------------------------
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 "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
using ::testing::Eq;
char * GZIP_BINARY = nullptr;
class DumpCustomGZTest : public MeltTest {
std::string dump_style = "custom";
public:
void enable_triclinic() {
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string fields, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id0 {}", dump_modify_options));
command(fmt::format("dump_modify id1 {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
}
};
TEST_F(DumpCustomGZTest, compressed_run1)
{
if(!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_custom_gz_text_run1.melt";
auto compressed_file = "dump_custom_gz_compressed_run1.melt.gz";
auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz";
generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", 1);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpCustomGZTest, compressed_triclinic_run1)
{
if(!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_custom_gz_tri_text_run1.melt";
auto compressed_file = "dump_custom_gz_tri_compressed_run1.melt.gz";
auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", 1);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {
std::vector<std::string> env = utils::split_words(var);
for (auto arg : env) {
if (arg == "-v") {
verbose = true;
}
}
}
GZIP_BINARY = getenv("GZIP_BINARY");
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
int rv = RUN_ALL_TESTS();
MPI_Finalize();
return rv;
}

View File

@ -0,0 +1,144 @@
/* ----------------------------------------------------------------------
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 "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
using ::testing::Eq;
char * ZSTD_BINARY = nullptr;
class DumpCustomZstdTest : public MeltTest {
std::string dump_style = "custom";
public:
void enable_triclinic() {
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string fields, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id0 {}", dump_modify_options));
command(fmt::format("dump_modify id1 {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
}
};
TEST_F(DumpCustomZstdTest, compressed_run1)
{
if(!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_custom_zstd_text_run1.melt";
auto compressed_file = "dump_custom_zstd_compressed_run1.melt.zst";
auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz";
generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, "units yes", 1);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
TEST_F(DumpCustomZstdTest, compressed_triclinic_run1)
{
if(!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_custom_zstd_tri_text_run1.melt";
auto compressed_file = "dump_custom_zstd_tri_compressed_run1.melt.zst";
auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, "units yes", 1);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {
std::vector<std::string> env = utils::split_words(var);
for (auto arg : env) {
if (arg == "-v") {
verbose = true;
}
}
}
ZSTD_BINARY = getenv("ZSTD_BINARY");
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
int rv = RUN_ALL_TESTS();
MPI_Finalize();
return rv;
}

View File

@ -0,0 +1,106 @@
/* ----------------------------------------------------------------------
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 "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
char * GZIP_BINARY = nullptr;
using ::testing::Eq;
class DumpLocalGZTest : public MeltTest {
std::string dump_style = "local";
public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string fields, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id0 {}", dump_modify_options));
command(fmt::format("dump_modify id1 {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
}
};
TEST_F(DumpLocalGZTest, compressed_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
command("compute comp all pair/local dist eng");
if (!verbose) ::testing::internal::GetCapturedStdout();
auto text_files = "dump_local_gz_text_run*.melt.local";
auto compressed_files = "dump_local_gz_compressed_run*.melt.local.gz";
auto text_file = "dump_local_gz_text_run0.melt.local";
auto compressed_file = "dump_local_gz_compressed_run0.melt.local.gz";
auto fields = "index c_comp[1]";
generate_text_and_compressed_dump(text_files, compressed_files, "local/gz", fields, "", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {
std::vector<std::string> env = utils::split_words(var);
for (auto arg : env) {
if (arg == "-v") {
verbose = true;
}
}
}
GZIP_BINARY = getenv("GZIP_BINARY");
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
int rv = RUN_ALL_TESTS();
MPI_Finalize();
return rv;
}

View File

@ -0,0 +1,106 @@
/* ----------------------------------------------------------------------
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 "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
char * ZSTD_BINARY = nullptr;
using ::testing::Eq;
class DumpLocalGZTest : public MeltTest {
std::string dump_style = "local";
public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string fields, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id0 {}", dump_modify_options));
command(fmt::format("dump_modify id1 {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
}
};
TEST_F(DumpLocalGZTest, compressed_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
command("compute comp all pair/local dist eng");
if (!verbose) ::testing::internal::GetCapturedStdout();
auto text_files = "dump_local_zstd_text_run*.melt.local";
auto compressed_files = "dump_local_zstd_compressed_run*.melt.local.zst";
auto text_file = "dump_local_zstd_text_run0.melt.local";
auto compressed_file = "dump_local_zstd_compressed_run0.melt.local.zst";
auto fields = "index c_comp[1]";
generate_text_and_compressed_dump(text_files, compressed_files, "local/zstd", fields, "", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {
std::vector<std::string> env = utils::split_words(var);
for (auto arg : env) {
if (arg == "-v") {
verbose = true;
}
}
}
ZSTD_BINARY = getenv("ZSTD_BINARY");
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
int rv = RUN_ALL_TESTS();
MPI_Finalize();
return rv;
}

View File

@ -0,0 +1,101 @@
/* ----------------------------------------------------------------------
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 "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
char * GZIP_BINARY = nullptr;
using ::testing::Eq;
class DumpXYZGZTest : public MeltTest {
std::string dump_style = "xyz";
public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id0 {}", dump_modify_options));
command(fmt::format("dump_modify id1 {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
}
};
TEST_F(DumpXYZGZTest, compressed_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
auto text_files = "dump_xyz_gz_text_run*.melt.xyz";
auto compressed_files = "dump_xyz_gz_compressed_run*.melt.xyz.gz";
auto text_file = "dump_xyz_gz_text_run0.melt.xyz";
auto compressed_file = "dump_xyz_gz_compressed_run0.melt.xyz.gz";
generate_text_and_compressed_dump(text_files, compressed_files, "xyz/gz", "", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {
std::vector<std::string> env = utils::split_words(var);
for (auto arg : env) {
if (arg == "-v") {
verbose = true;
}
}
}
GZIP_BINARY = getenv("GZIP_BINARY");
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
int rv = RUN_ALL_TESTS();
MPI_Finalize();
return rv;
}

View File

@ -0,0 +1,101 @@
/* ----------------------------------------------------------------------
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 "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
char * ZSTD_BINARY = nullptr;
using ::testing::Eq;
class DumpXYZGZTest : public MeltTest {
std::string dump_style = "xyz";
public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id0 {}", dump_modify_options));
command(fmt::format("dump_modify id1 {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
}
};
TEST_F(DumpXYZGZTest, compressed_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
auto text_files = "dump_xyz_zstd_text_run*.melt.xyz";
auto compressed_files = "dump_xyz_zstd_compressed_run*.melt.xyz.zst";
auto text_file = "dump_xyz_zstd_text_run0.melt.xyz";
auto compressed_file = "dump_xyz_zstd_compressed_run0.melt.xyz.zst";
generate_text_and_compressed_dump(text_files, compressed_files, "xyz/zstd", "", 0);
TearDown();
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(compressed_file);
auto converted_file = convert_compressed_to_text(compressed_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(compressed_file);
delete_file(converted_file);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {
std::vector<std::string> env = utils::split_words(var);
for (auto arg : env) {
if (arg == "-v") {
verbose = true;
}
}
}
ZSTD_BINARY = getenv("ZSTD_BINARY");
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
int rv = RUN_ALL_TESTS();
MPI_Finalize();
return rv;
}

View File

@ -71,6 +71,7 @@ protected:
{
if (!verbose) ::testing::internal::CaptureStdout();
delete lmp;
lmp = nullptr;
if (!verbose) ::testing::internal::GetCapturedStdout();
}
};