use platform functions for averaging fixes

This commit is contained in:
Axel Kohlmeyer
2021-10-04 18:13:46 -04:00
parent dd2b5b22d4
commit 7cdd82dee2
11 changed files with 106 additions and 113 deletions

View File

@ -36,7 +36,6 @@
#include <cmath>
#include <cstring>
#include <unistd.h>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -260,11 +259,11 @@ FixAveCorrelateLong::FixAveCorrelateLong(LAMMPS * lmp, int narg, char **arg):
fprintf(fp," %s*%s",arg[5+i],arg[5+j]);
fprintf(fp,"\n");
}
filepos = ftell(fp);
filepos = platform::ftell(fp);
}
delete [] title1;
delete [] title2;
delete[] title1;
delete[] title2;
// allocate and initialize memory for calculated values and correlators
@ -319,11 +318,11 @@ FixAveCorrelateLong::FixAveCorrelateLong(LAMMPS * lmp, int narg, char **arg):
FixAveCorrelateLong::~FixAveCorrelateLong()
{
delete [] which;
delete [] argindex;
delete [] value2index;
for (int i = 0; i < nvalues; i++) delete [] ids[i];
delete [] ids;
delete[] which;
delete[] argindex;
delete[] value2index;
for (int i = 0; i < nvalues; i++) delete[] ids[i];
delete[] ids;
memory->destroy(values);
memory->destroy(shift);
@ -467,7 +466,7 @@ void FixAveCorrelateLong::end_of_step()
evaluate();
if (fp && me == 0) {
if (overwrite) fseek(fp,filepos,SEEK_SET);
if (overwrite) platform::fseek(fp,filepos);
fprintf(fp,"# Timestep: " BIGINT_FORMAT "\n", ntimestep);
for (unsigned int i=0;i<npcorr;++i) {
fprintf(fp, "%lg ", t[i]*update->dt*nevery);
@ -478,9 +477,9 @@ void FixAveCorrelateLong::end_of_step()
}
fflush(fp);
if (overwrite) {
long fileend = ftell(fp);
if ((fileend > 0) && (ftruncate(fileno(fp),fileend)))
perror("Error while tuncating output");
bigint fileend = platform::ftell(fp);
if ((fileend > 0) && (platform::ftruncate(fp,fileend)))
error->warning(FLERR,"Error while tuncating output: {}", utils::getsyserror());
}
}

View File

@ -66,7 +66,7 @@ class FixAveCorrelateLong : public Fix {
FILE *fp;
int type, startstep, overwrite;
long filepos;
bigint filepos;
int npair; // number of correlation pairs to calculate
double *values;

View File

@ -29,7 +29,6 @@
#include "variable.h"
#include <cstring>
#include <unistd.h>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -216,23 +215,23 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
iarg += 1;
} else if (strcmp(arg[iarg],"format") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
delete [] format_user;
delete[] format_user;
format_user = utils::strdup(arg[iarg+1]);
format = format_user;
iarg += 2;
} else if (strcmp(arg[iarg],"title1") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
delete [] title1;
delete[] title1;
title1 = utils::strdup(arg[iarg+1]);
iarg += 2;
} else if (strcmp(arg[iarg],"title2") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
delete [] title2;
delete[] title2;
title2 = utils::strdup(arg[iarg+1]);
iarg += 2;
} else if (strcmp(arg[iarg],"title3") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
delete [] title3;
delete[] title3;
title3 = utils::strdup(arg[iarg+1]);
iarg += 2;
} else error->all(FLERR,"Illegal fix ave/chunk command");
@ -348,18 +347,18 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
if (ferror(fp))
error->one(FLERR,"Error writing file header");
filepos = ftell(fp);
filepos = platform::ftell(fp);
}
delete [] title1;
delete [] title2;
delete [] title3;
delete[] title1;
delete[] title2;
delete[] title3;
// if wildcard expansion occurred, free earg memory from expand_args()
// wait to do this until after file comment lines are printed
if (expand) {
for (int i = 0; i < nargnew; i++) delete [] earg[i];
for (int i = 0; i < nargnew; i++) delete[] earg[i];
memory->sfree(earg);
}
@ -407,11 +406,11 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
FixAveChunk::~FixAveChunk()
{
delete [] which;
delete [] argindex;
for (int i = 0; i < nvalues; i++) delete [] ids[i];
delete [] ids;
delete [] value2index;
delete[] which;
delete[] argindex;
for (int i = 0; i < nvalues; i++) delete[] ids[i];
delete[] ids;
delete[] value2index;
if (fp && comm->me == 0) fclose(fp);
@ -438,7 +437,7 @@ FixAveChunk::~FixAveChunk()
}
}
delete [] idchunk;
delete[] idchunk;
which = nullptr;
argindex = nullptr;
ids = nullptr;
@ -941,7 +940,7 @@ void FixAveChunk::end_of_step()
if (fp && comm->me == 0) {
clearerr(fp);
if (overwrite) fseek(fp,filepos,SEEK_SET);
if (overwrite) platform::fseek(fp,filepos);
double count = 0.0;
for (m = 0; m < nchunk; m++) count += count_total[m];
fprintf(fp,BIGINT_FORMAT " %d %g\n",ntimestep,nchunk,count);
@ -1027,9 +1026,9 @@ void FixAveChunk::end_of_step()
fflush(fp);
if (overwrite) {
long fileend = ftell(fp);
if ((fileend > 0) && (ftruncate(fileno(fp),fileend)))
perror("Error while tuncating output");
bigint fileend = platform::ftell(fp);
if ((fileend > 0) && (platform::ftruncate(fp,fileend)))
error->warning(FLERR,"Error while tuncating output: {}", utils::getsyserror());
}
}
}

View File

@ -61,7 +61,7 @@ class FixAveChunk : public Fix {
class ComputeChunkAtom *cchunk;
int lockforever;
long filepos;
bigint filepos;
int maxvar;
double *varatom;

View File

@ -30,7 +30,6 @@
#include "variable.h"
#include <cstring>
#include <unistd.h>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -139,17 +138,17 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg):
iarg += 1;
} else if (strcmp(arg[iarg],"title1") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command");
delete [] title1;
delete[] title1;
title1 = utils::strdup(arg[iarg+1]);
iarg += 2;
} else if (strcmp(arg[iarg],"title2") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command");
delete [] title2;
delete[] title2;
title2 = utils::strdup(arg[iarg+1]);
iarg += 2;
} else if (strcmp(arg[iarg],"title3") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command");
delete [] title3;
delete[] title3;
title3 = utils::strdup(arg[iarg+1]);
iarg += 2;
} else error->all(FLERR,"Illegal fix ave/correlate command");
@ -256,18 +255,18 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg):
if (ferror(fp))
error->one(FLERR,"Error writing file header");
filepos = ftell(fp);
filepos = platform::ftell(fp);
}
delete [] title1;
delete [] title2;
delete [] title3;
delete[] title1;
delete[] title2;
delete[] title3;
// if wildcard expansion occurred, free earg memory from expand_args()
// wait to do this until after file comment lines are printed
if (expand) {
for (int i = 0; i < nargnew; i++) delete [] earg[i];
for (int i = 0; i < nargnew; i++) delete[] earg[i];
memory->sfree(earg);
}
@ -312,11 +311,11 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg):
FixAveCorrelate::~FixAveCorrelate()
{
delete [] which;
delete [] argindex;
delete [] value2index;
for (int i = 0; i < nvalues; i++) delete [] ids[i];
delete [] ids;
delete[] which;
delete[] argindex;
delete[] value2index;
for (int i = 0; i < nvalues; i++) delete[] ids[i];
delete[] ids;
memory->destroy(values);
memory->destroy(count);
@ -489,7 +488,7 @@ void FixAveCorrelate::end_of_step()
if (fp && me == 0) {
clearerr(fp);
if (overwrite) fseek(fp,filepos,SEEK_SET);
if (overwrite) platform::fseek(fp,filepos);
fprintf(fp,BIGINT_FORMAT " %d\n",ntimestep,nrepeat);
for (i = 0; i < nrepeat; i++) {
fprintf(fp,"%d %d %d",i+1,i*nevery,count[i]);
@ -507,9 +506,9 @@ void FixAveCorrelate::end_of_step()
fflush(fp);
if (overwrite) {
long fileend = ftell(fp);
if ((fileend > 0) && (ftruncate(fileno(fp),fileend)))
perror("Error while tuncating output");
bigint fileend = platform::ftell(fp);
if ((fileend > 0) && (platform::ftruncate(fp,fileend)))
error->warning(FLERR,"Error while tuncating output: {}", utils::getsyserror());
}
}

View File

@ -44,7 +44,7 @@ class FixAveCorrelate : public Fix {
int type, ave, startstep, overwrite;
double prefactor;
long filepos;
bigint filepos;
int firstindex; // index in values ring of earliest time sample
int lastindex; // index in values ring of latest time sample

View File

@ -25,7 +25,6 @@
#include "variable.h"
#include <cstring>
#include <unistd.h>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -168,7 +167,7 @@ FixAveHisto::FixAveHisto(LAMMPS *lmp, int narg, char **arg) :
// if wildcard expansion occurred, free earg memory from expand_args()
if (expand) {
for (int i = 0; i < nvalues; i++) delete [] earg[i];
for (int i = 0; i < nvalues; i++) delete[] earg[i];
memory->sfree(earg);
}
@ -434,12 +433,12 @@ FixAveHisto::FixAveHisto(LAMMPS *lmp, int narg, char **arg) :
if (ferror(fp))
error->one(FLERR,"Error writing file header");
filepos = ftell(fp);
filepos = platform::ftell(fp);
}
delete [] title1;
delete [] title2;
delete [] title3;
delete[] title1;
delete[] title2;
delete[] title3;
// allocate and initialize memory for averaging
@ -502,18 +501,18 @@ FixAveHisto::FixAveHisto(LAMMPS *lmp, int narg, char **arg) :
FixAveHisto::~FixAveHisto()
{
delete [] which;
delete [] argindex;
delete [] value2index;
for (int i = 0; i < nvalues; i++) delete [] ids[i];
delete [] ids;
delete[] which;
delete[] argindex;
delete[] value2index;
for (int i = 0; i < nvalues; i++) delete[] ids[i];
delete[] ids;
if (fp && me == 0) fclose(fp);
delete [] bin;
delete [] bin_total;
delete [] bin_all;
delete [] coord;
delete[] bin;
delete[] bin_total;
delete[] bin_all;
delete[] coord;
memory->destroy(stats_list);
memory->destroy(bin_list);
memory->destroy(vector);
@ -817,7 +816,7 @@ void FixAveHisto::end_of_step()
if (fp && me == 0) {
clearerr(fp);
if (overwrite) fseek(fp,filepos,SEEK_SET);
if (overwrite) platform::fseek(fp,filepos);
fprintf(fp,BIGINT_FORMAT " %d %g %g %g %g\n",ntimestep,nbins,
stats_total[0],stats_total[1],stats_total[2],stats_total[3]);
if (stats_total[0] != 0.0)
@ -833,9 +832,9 @@ void FixAveHisto::end_of_step()
fflush(fp);
if (overwrite) {
long fileend = ftell(fp);
if ((fileend > 0) && (ftruncate(fileno(fp),fileend)))
perror("Error while tuncating output");
bigint fileend = platform::ftell(fp);
if ((fileend > 0) && (platform::ftruncate(fp,fileend)))
error->warning(FLERR,"Error while tuncating output: {}",utils::getsyserror());
}
}
}
@ -993,17 +992,17 @@ void FixAveHisto::options(int iarg, int narg, char **arg)
iarg += 1;
} else if (strcmp(arg[iarg],"title1") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command");
delete [] title1;
delete[] title1;
title1 = utils::strdup(arg[iarg+1]);
iarg += 2;
} else if (strcmp(arg[iarg],"title2") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command");
delete [] title2;
delete[] title2;
title2 = utils::strdup(arg[iarg+1]);
iarg += 2;
} else if (strcmp(arg[iarg],"title3") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command");
delete [] title3;
delete[] title3;
title3 = utils::strdup(arg[iarg+1]);
iarg += 2;
} else error->all(FLERR,"Illegal fix ave/histo command");

View File

@ -44,7 +44,7 @@ class FixAveHisto : public Fix {
FILE *fp;
double lo, hi, binsize, bininv;
int kind, beyond, overwrite;
long filepos;
bigint filepos;
double stats[4], stats_total[4], stats_all[4];
double **stats_list;

View File

@ -28,8 +28,6 @@
#include "update.h"
#include "variable.h"
#include <unistd.h>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -472,7 +470,7 @@ void FixAveHistoWeight::end_of_step()
if (fp && me == 0) {
clearerr(fp);
if (overwrite) fseek(fp,filepos,SEEK_SET);
if (overwrite) platform::fseek(fp,filepos);
fprintf(fp,BIGINT_FORMAT " %d %g %g %g %g\n",ntimestep,nbins,
stats_total[0],stats_total[1],stats_total[2],stats_total[3]);
if (stats_total[0] != 0.0)
@ -488,9 +486,9 @@ void FixAveHistoWeight::end_of_step()
fflush(fp);
if (overwrite) {
long fileend = ftell(fp);
if ((fileend > 0) && (ftruncate(fileno(fp),fileend)))
perror("Error while tuncating output");
bigint fileend = platform::ftell(fp);
if ((fileend > 0) && (platform::ftruncate(fp,fileend)))
error->warning(FLERR,"Error while tuncating output: {}", utils::getsyserror());
}
}
}

View File

@ -28,7 +28,6 @@
#include "variable.h"
#include <cstring>
#include <unistd.h>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -274,18 +273,18 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
if (ferror(fp))
error->one(FLERR,"Error writing file header");
filepos = ftell(fp);
filepos = platform::ftell(fp);
}
delete [] title1;
delete [] title2;
delete [] title3;
delete[] title1;
delete[] title2;
delete[] title3;
// if wildcard expansion occurred, free earg memory from expand_args()
// wait to do this until after file comment lines are printed
if (expand) {
for (int i = 0; i < nvalues; i++) delete [] earg[i];
for (int i = 0; i < nvalues; i++) delete[] earg[i];
memory->sfree(earg);
}
@ -446,24 +445,24 @@ FixAveTime::~FixAveTime()
}
}
delete [] format_user;
delete[] format_user;
delete [] which;
delete [] argindex;
delete [] value2index;
delete [] offcol;
delete [] varlen;
for (int i = 0; i < nvalues; i++) delete [] ids[i];
delete [] ids;
delete[] which;
delete[] argindex;
delete[] value2index;
delete[] offcol;
delete[] varlen;
for (int i = 0; i < nvalues; i++) delete[] ids[i];
delete[] ids;
delete [] extlist;
delete[] extlist;
if (fp && me == 0) fclose(fp);
memory->destroy(column);
delete [] vector;
delete [] vector_total;
delete[] vector;
delete[] vector_total;
memory->destroy(array);
memory->destroy(array_total);
memory->destroy(array_list);
@ -673,7 +672,7 @@ void FixAveTime::invoke_scalar(bigint ntimestep)
if (fp && me == 0) {
clearerr(fp);
if (overwrite) fseek(fp,filepos,SEEK_SET);
if (overwrite) platform::fseek(fp,filepos);
fprintf(fp,BIGINT_FORMAT,ntimestep);
for (i = 0; i < nvalues; i++) fprintf(fp,format,vector_total[i]/norm);
fprintf(fp,"\n");
@ -683,9 +682,9 @@ void FixAveTime::invoke_scalar(bigint ntimestep)
fflush(fp);
if (overwrite) {
long fileend = ftell(fp);
if ((fileend > 0) && (ftruncate(fileno(fp),fileend)))
perror("Error while tuncating output");
bigint fileend = platform::ftell(fp);
if ((fileend > 0) && (platform::ftruncate(fp,fileend)))
error->warning(FLERR,"Error while tuncating output: {}", utils::getsyserror());
}
}
}
@ -885,7 +884,7 @@ void FixAveTime::invoke_vector(bigint ntimestep)
// output result to file
if (fp && me == 0) {
if (overwrite) fseek(fp,filepos,SEEK_SET);
if (overwrite) platform::fseek(fp,filepos);
fprintf(fp,BIGINT_FORMAT " %d\n",ntimestep,nrows);
for (i = 0; i < nrows; i++) {
fprintf(fp,"%d",i+1);
@ -894,9 +893,9 @@ void FixAveTime::invoke_vector(bigint ntimestep)
}
fflush(fp);
if (overwrite) {
long fileend = ftell(fp);
if ((fileend > 0) && (ftruncate(fileno(fp),fileend)))
perror("Error while tuncating output");
bigint fileend = platform::ftell(fp);
if ((fileend > 0) && (platform::ftruncate(fp,fileend)))
error->warning(FLERR,"Error while tuncating output: {}", utils::getsyserror());
}
}
}
@ -1066,23 +1065,23 @@ void FixAveTime::options(int iarg, int narg, char **arg)
iarg += 1;
} else if (strcmp(arg[iarg],"format") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/time command");
delete [] format_user;
delete[] format_user;
format_user = utils::strdup(arg[iarg+1]);
format = format_user;
iarg += 2;
} else if (strcmp(arg[iarg],"title1") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command");
delete [] title1;
delete[] title1;
title1 = utils::strdup(arg[iarg+1]);
iarg += 2;
} else if (strcmp(arg[iarg],"title2") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command");
delete [] title2;
delete[] title2;
title2 = utils::strdup(arg[iarg+1]);
iarg += 2;
} else if (strcmp(arg[iarg],"title3") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command");
delete [] title3;
delete[] title3;
title3 = utils::strdup(arg[iarg+1]);
iarg += 2;
} else error->all(FLERR,"Illegal fix ave/time command");

View File

@ -54,7 +54,7 @@ class FixAveTime : public Fix {
int *offlist;
char *format, *format_user;
char *title1, *title2, *title3;
long filepos;
bigint filepos;
int norm, iwindow, window_limit;
double *vector;