add support for adding an ITEM: TIME output to some dump files

This commit is contained in:
Axel Kohlmeyer
2019-09-30 11:03:22 -04:00
parent 6cd460072b
commit 01214de6bd
8 changed files with 35 additions and 3 deletions

View File

@ -112,6 +112,8 @@ void DumpAtomGZ::write_header(bigint ndump)
++unit_count;
gzprintf(gzFp,"ITEM: UNITS\n%s\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 ATOMS\n");

View File

@ -112,6 +112,8 @@ void DumpCustomGZ::write_header(bigint ndump)
++unit_count;
gzprintf(gzFp,"ITEM: UNITS\n%s\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 ATOMS\n");

View File

@ -112,6 +112,8 @@ void DumpLocalGZ::write_header(bigint ndump)
++unit_count;
gzprintf(gzFp,"ITEM: UNITS\n%s\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 ATOMS\n");

View File

@ -87,6 +87,7 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp)
buffer_flag = 0;
padflag = 0;
pbcflag = 0;
time_flag = 0;
unit_flag = 0;
unit_count = 0;
delay_flag = 0;
@ -1123,6 +1124,13 @@ void Dump::modify_params(int narg, char **arg)
}
iarg += 2;
} else if (strcmp(arg[iarg],"time") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal dump_modify command");
if (strcmp(arg[iarg+1],"yes") == 0) time_flag = 1;
else if (strcmp(arg[iarg+1],"no") == 0) time_flag = 0;
else error->all(FLERR,"Illegal dump_modify command");
iarg += 2;
} else if (strcmp(arg[iarg],"units") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal dump_modify command");
if (strcmp(arg[iarg+1],"yes") == 0) unit_flag = 1;
@ -1138,6 +1146,12 @@ void Dump::modify_params(int narg, char **arg)
}
}
/* ---------------------------------------------------------------------- */
double Dump::compute_time()
{
return update->atime + (update->ntimestep - update->atimestep)*update->dt;
}
/* ----------------------------------------------------------------------
return # of bytes of allocated memory
------------------------------------------------------------------------- */

View File

@ -75,6 +75,7 @@ class Dump : protected Pointers {
int sortcol; // 0 to sort on ID, 1-N on columns
int sortcolm1; // sortcol - 1
int sortorder; // ASCEND or DESCEND
int time_flag; // 1 if output accumulated time
int unit_flag; // 1 if dump should contain unit information
int unit_count; // # of times the unit information was written
int delay_flag; // 1 if delay output until delaystep
@ -145,6 +146,7 @@ class Dump : protected Pointers {
virtual int convert_string(int, double *) {return 0;}
virtual void write_data(int, double *) = 0;
void pbc_allocate();
double compute_time();
void sort();
#if defined(LMP_QSORT)

View File

@ -15,9 +15,9 @@
#include <cstring>
#include "domain.h"
#include "atom.h"
#include "update.h"
#include "memory.h"
#include "error.h"
#include "update.h"
using namespace LAMMPS_NS;
@ -213,6 +213,8 @@ void DumpAtom::header_item(bigint ndump)
++unit_count;
fprintf(fp,"ITEM: UNITS\n%s\n",update->unit_style);
}
if (time_flag) fprintf(fp,"ITEM: TIME\n%.16g\n",compute_time());
fprintf(fp,"ITEM: TIMESTEP\n");
fprintf(fp,BIGINT_FORMAT "\n",update->ntimestep);
fprintf(fp,"ITEM: NUMBER OF ATOMS\n");
@ -232,6 +234,8 @@ void DumpAtom::header_item_triclinic(bigint ndump)
++unit_count;
fprintf(fp,"ITEM: UNITS\n%s\n",update->unit_style);
}
if (time_flag) fprintf(fp,"ITEM: TIME\n%.16g\n",compute_time());
fprintf(fp,"ITEM: TIMESTEP\n");
fprintf(fp,BIGINT_FORMAT "\n",update->ntimestep);
fprintf(fp,"ITEM: NUMBER OF ATOMS\n");

View File

@ -20,14 +20,14 @@
#include "region.h"
#include "group.h"
#include "input.h"
#include "variable.h"
#include "update.h"
#include "modify.h"
#include "compute.h"
#include "fix.h"
#include "fix_store.h"
#include "memory.h"
#include "error.h"
#include "update.h"
#include "variable.h"
using namespace LAMMPS_NS;
@ -424,6 +424,8 @@ void DumpCustom::header_item(bigint ndump)
++unit_count;
fprintf(fp,"ITEM: UNITS\n%s\n",update->unit_style);
}
if (time_flag) fprintf(fp,"ITEM: TIME\n%.16g\n",compute_time());
fprintf(fp,"ITEM: TIMESTEP\n");
fprintf(fp,BIGINT_FORMAT "\n",update->ntimestep);
fprintf(fp,"ITEM: NUMBER OF ATOMS\n");
@ -443,6 +445,8 @@ void DumpCustom::header_item_triclinic(bigint ndump)
++unit_count;
fprintf(fp,"ITEM: UNITS\n%s\n",update->unit_style);
}
if (time_flag) fprintf(fp,"ITEM: TIME\n%.16g\n",compute_time());
fprintf(fp,"ITEM: TIMESTEP\n");
fprintf(fp,BIGINT_FORMAT "\n",update->ntimestep);
fprintf(fp,"ITEM: NUMBER OF ATOMS\n");

View File

@ -260,6 +260,8 @@ void DumpLocal::write_header(bigint ndump)
++unit_count;
fprintf(fp,"ITEM: UNITS\n%s\n",update->unit_style);
}
if (time_flag) fprintf(fp,"ITEM: TIME\n%.16g\n",compute_time());
fprintf(fp,"ITEM: TIMESTEP\n");
fprintf(fp,BIGINT_FORMAT "\n",update->ntimestep);
fprintf(fp,"ITEM: NUMBER OF %s\n",label);