Update dump local and local/gz
This commit is contained in:
@ -11,24 +11,18 @@
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "dump_local_gz.h"
|
||||
#include "domain.h"
|
||||
#include "dump_local_gz.h"
|
||||
#include "error.h"
|
||||
#include "update.h"
|
||||
|
||||
|
||||
#include <cstring>
|
||||
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
DumpLocalGZ::DumpLocalGZ(LAMMPS *lmp, int narg, char **arg) :
|
||||
DumpLocal(lmp, narg, arg)
|
||||
{
|
||||
gzFp = nullptr;
|
||||
|
||||
compression_level = Z_BEST_COMPRESSION;
|
||||
|
||||
if (!compressed)
|
||||
error->all(FLERR,"Dump local/gz only writes compressed files");
|
||||
}
|
||||
@ -38,12 +32,8 @@ DumpLocalGZ::DumpLocalGZ(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
DumpLocalGZ::~DumpLocalGZ()
|
||||
{
|
||||
if (gzFp) gzclose(gzFp);
|
||||
gzFp = nullptr;
|
||||
fp = nullptr;
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
generic opening of a dump file
|
||||
ASCII or binary or gzipped
|
||||
@ -93,17 +83,12 @@ void DumpLocalGZ::openfile()
|
||||
// each proc with filewriter = 1 opens a file
|
||||
|
||||
if (filewriter) {
|
||||
std::string mode;
|
||||
if (append_flag) {
|
||||
mode = fmt::format("ab{}", compression_level);
|
||||
} else {
|
||||
mode = fmt::format("wb{}", compression_level);
|
||||
try {
|
||||
writer.open(filecurrent, append_flag);
|
||||
} catch (FileWriterException &e) {
|
||||
error->one(FLERR, e.what());
|
||||
}
|
||||
|
||||
gzFp = gzopen(filecurrent, mode.c_str());
|
||||
|
||||
if (gzFp == nullptr) error->one(FLERR,"Cannot open dump file");
|
||||
} else gzFp = nullptr;
|
||||
}
|
||||
|
||||
// delete string with timestep replaced
|
||||
|
||||
@ -112,29 +97,34 @@ void DumpLocalGZ::openfile()
|
||||
|
||||
void DumpLocalGZ::write_header(bigint ndump)
|
||||
{
|
||||
std::string header;
|
||||
|
||||
if ((multiproc) || (!multiproc && me == 0)) {
|
||||
if (unit_flag && !unit_count) {
|
||||
++unit_count;
|
||||
gzprintf(gzFp,"ITEM: UNITS\n%s\n",update->unit_style);
|
||||
header = fmt::format("ITEM: UNITS\n{}\n",update->unit_style);
|
||||
}
|
||||
if (time_flag) gzprintf(gzFp,"ITEM: TIME\n%.16g\n",compute_time());
|
||||
|
||||
gzprintf(gzFp,"ITEM: TIMESTEP\n");
|
||||
gzprintf(gzFp,BIGINT_FORMAT "\n",update->ntimestep);
|
||||
gzprintf(gzFp,"ITEM: NUMBER OF %s\n",label);
|
||||
gzprintf(gzFp,BIGINT_FORMAT "\n",ndump);
|
||||
if (domain->triclinic) {
|
||||
gzprintf(gzFp,"ITEM: BOX BOUNDS xy xz yz %s\n",boundstr);
|
||||
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);
|
||||
if (time_flag) {
|
||||
header += fmt::format("ITEM: TIME\n{0:.16g}\n", compute_time());
|
||||
}
|
||||
gzprintf(gzFp,"ITEM: %s %s\n",label,columns);
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,19 +133,28 @@ void DumpLocalGZ::write_header(bigint ndump)
|
||||
void DumpLocalGZ::write_data(int n, double *mybuf)
|
||||
{
|
||||
if (buffer_flag == 1) {
|
||||
gzwrite(gzFp,mybuf,sizeof(char)*n);
|
||||
|
||||
writer.write(mybuf, sizeof(char)*n);
|
||||
} else {
|
||||
int i,j;
|
||||
constexpr size_t VBUFFER_SIZE = 256;
|
||||
char vbuffer[VBUFFER_SIZE];
|
||||
int m = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
for (j = 0; j < size_one; j++) {
|
||||
if (vtype[j] == INT)
|
||||
gzprintf(gzFp,vformat[j],static_cast<int> (mybuf[m]));
|
||||
else gzprintf(gzFp,vformat[j],mybuf[m]);
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < size_one; j++) {
|
||||
int written = 0;
|
||||
if (vtype[j] == Dump::INT) {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, vformat[j], static_cast<int> (mybuf[m]));
|
||||
} else {
|
||||
written = snprintf(vbuffer, VBUFFER_SIZE, vformat[j], mybuf[m]);
|
||||
}
|
||||
|
||||
if (written > 0) {
|
||||
writer.write(vbuffer, written);
|
||||
} else if (written < 0) {
|
||||
error->one(FLERR, "Error while writing dump local/gz output");
|
||||
}
|
||||
m++;
|
||||
}
|
||||
gzprintf(gzFp,"\n");
|
||||
writer.write("\n", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,11 +166,11 @@ void DumpLocalGZ::write()
|
||||
DumpLocal::write();
|
||||
if (filewriter) {
|
||||
if (multifile) {
|
||||
gzclose(gzFp);
|
||||
gzFp = nullptr;
|
||||
writer.close();
|
||||
} else {
|
||||
if (flush_flag)
|
||||
gzflush(gzFp,Z_SYNC_FLUSH);
|
||||
if (flush_flag && writer.isopen()) {
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,14 +181,15 @@ 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;
|
||||
try {
|
||||
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, fmt::format("Illegal dump_modify command: {}", e.what()));
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
|
||||
Reference in New Issue
Block a user