add yaml format output for mode scalar
This commit is contained in:
@ -83,6 +83,8 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
int expand = 0;
|
int expand = 0;
|
||||||
char **earg;
|
char **earg;
|
||||||
nvalues = utils::expand_args(FLERR,nvalues,&arg[6],mode,earg,lmp);
|
nvalues = utils::expand_args(FLERR,nvalues,&arg[6],mode,earg,lmp);
|
||||||
|
keyword.resize(nvalues);
|
||||||
|
key2col.clear();
|
||||||
|
|
||||||
if (earg != &arg[6]) expand = 1;
|
if (earg != &arg[6]) expand = 1;
|
||||||
arg = earg;
|
arg = earg;
|
||||||
@ -98,6 +100,8 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
|
|
||||||
for (int i = 0; i < nvalues; i++) {
|
for (int i = 0; i < nvalues; i++) {
|
||||||
ArgInfo argi(arg[i]);
|
ArgInfo argi(arg[i]);
|
||||||
|
keyword[i] = arg[i];
|
||||||
|
key2col[arg[i]] = i;
|
||||||
|
|
||||||
if ((argi.get_type() == ArgInfo::NONE)
|
if ((argi.get_type() == ArgInfo::NONE)
|
||||||
|| (argi.get_type() == ArgInfo::UNKNOWN)
|
|| (argi.get_type() == ArgInfo::UNKNOWN)
|
||||||
@ -269,9 +273,8 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
for (int i = 0; i < nvalues; i++) fprintf(fp," %s",earg[i]);
|
for (int i = 0; i < nvalues; i++) fprintf(fp," %s",earg[i]);
|
||||||
fprintf(fp,"\n");
|
fprintf(fp,"\n");
|
||||||
}
|
}
|
||||||
if (ferror(fp))
|
if (yaml_flag) fputs("---\n",fp);
|
||||||
error->one(FLERR,"Error writing file header");
|
if (ferror(fp)) error->one(FLERR,"Error writing file header: {}", utils::getsyserror());
|
||||||
|
|
||||||
filepos = platform::ftell(fp);
|
filepos = platform::ftell(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,8 +459,10 @@ FixAveTime::~FixAveTime()
|
|||||||
|
|
||||||
delete[] extlist;
|
delete[] extlist;
|
||||||
|
|
||||||
if (fp && me == 0) fclose(fp);
|
if (fp && me == 0) {
|
||||||
|
if (yaml_flag) fputs("...\n", fp);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
memory->destroy(column);
|
memory->destroy(column);
|
||||||
|
|
||||||
delete[] vector;
|
delete[] vector;
|
||||||
@ -669,11 +674,22 @@ void FixAveTime::invoke_scalar(bigint ntimestep)
|
|||||||
if (fp && me == 0) {
|
if (fp && me == 0) {
|
||||||
clearerr(fp);
|
clearerr(fp);
|
||||||
if (overwrite) platform::fseek(fp,filepos);
|
if (overwrite) platform::fseek(fp,filepos);
|
||||||
|
if (yaml_flag) {
|
||||||
|
if (!yaml_header || overwrite) {
|
||||||
|
yaml_header = true;
|
||||||
|
fputs("keywords: ['Step', ", fp);
|
||||||
|
for (auto k : keyword) fmt::print(fp, "'{}', ", k);
|
||||||
|
fputs("]\ndata:\n", fp);
|
||||||
|
}
|
||||||
|
fmt::print(fp, " - [{}, ", ntimestep);
|
||||||
|
for (i = 0; i < nvalues; i++) fmt::print(fp,"{}, ",vector_total[i]/norm);
|
||||||
|
fputs("]\n", fp);
|
||||||
|
} else {
|
||||||
fmt::print(fp,"{}",ntimestep);
|
fmt::print(fp,"{}",ntimestep);
|
||||||
for (i = 0; i < nvalues; i++) fprintf(fp,format,vector_total[i]/norm);
|
for (i = 0; i < nvalues; i++) fprintf(fp,format,vector_total[i]/norm);
|
||||||
fprintf(fp,"\n");
|
fprintf(fp,"\n");
|
||||||
if (ferror(fp)) error->one(FLERR,"Error writing out time averaged data");
|
if (ferror(fp)) error->one(FLERR,"Error writing out time averaged data");
|
||||||
|
}
|
||||||
fflush(fp);
|
fflush(fp);
|
||||||
|
|
||||||
if (overwrite) {
|
if (overwrite) {
|
||||||
@ -994,6 +1010,34 @@ double FixAveTime::compute_array(int i, int j)
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
modify settings
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int FixAveTime::modify_param(int narg, char **arg)
|
||||||
|
{
|
||||||
|
if (strcmp(arg[0], "colname") == 0) {
|
||||||
|
if (narg < 3) utils::missing_cmd_args(FLERR, "fix_modify colname", error);
|
||||||
|
int icol = -1;
|
||||||
|
if (utils::is_integer(arg[1])) {
|
||||||
|
icol = utils::inumeric(FLERR, arg[1], false, lmp);
|
||||||
|
if (icol < 0) icol = keyword.size() + icol + 1;
|
||||||
|
icol--;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
icol = key2col.at(arg[1]);
|
||||||
|
} catch (std::out_of_range &) {
|
||||||
|
icol = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((icol < 0) || (icol >= (int) keyword.size()))
|
||||||
|
error->all(FLERR, "Thermo_modify colname column {} invalid", arg[1]);
|
||||||
|
keyword[icol] = arg[2];
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
parse optional args
|
parse optional args
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
@ -1009,7 +1053,7 @@ void FixAveTime::options(int iarg, int narg, char **arg)
|
|||||||
noff = 0;
|
noff = 0;
|
||||||
offlist = nullptr;
|
offlist = nullptr;
|
||||||
overwrite = 0;
|
overwrite = 0;
|
||||||
yaml_flag = false;
|
yaml_flag = yaml_header = false;
|
||||||
format_user = nullptr;
|
format_user = nullptr;
|
||||||
format = (char *) " %g";
|
format = (char *) " %g";
|
||||||
title1 = nullptr;
|
title1 = nullptr;
|
||||||
|
|||||||
@ -22,6 +22,8 @@ FixStyle(ave/time,FixAveTime);
|
|||||||
|
|
||||||
#include "fix.h"
|
#include "fix.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace LAMMPS_NS {
|
namespace LAMMPS_NS {
|
||||||
|
|
||||||
class FixAveTime : public Fix {
|
class FixAveTime : public Fix {
|
||||||
@ -32,6 +34,7 @@ class FixAveTime : public Fix {
|
|||||||
void init() override;
|
void init() override;
|
||||||
void setup(int) override;
|
void setup(int) override;
|
||||||
void end_of_step() override;
|
void end_of_step() override;
|
||||||
|
int modify_param(int, char **) override;
|
||||||
double compute_scalar() override;
|
double compute_scalar() override;
|
||||||
double compute_vector(int) override;
|
double compute_vector(int) override;
|
||||||
double compute_array(int, int) override;
|
double compute_array(int, int) override;
|
||||||
@ -48,7 +51,7 @@ class FixAveTime : public Fix {
|
|||||||
int any_variable_length;
|
int any_variable_length;
|
||||||
int all_variable_length;
|
int all_variable_length;
|
||||||
int lockforever;
|
int lockforever;
|
||||||
bool yaml_flag;
|
bool yaml_flag, yaml_header;
|
||||||
|
|
||||||
int ave, nwindow, startstep, mode;
|
int ave, nwindow, startstep, mode;
|
||||||
int noff, overwrite;
|
int noff, overwrite;
|
||||||
@ -57,6 +60,9 @@ class FixAveTime : public Fix {
|
|||||||
char *title1, *title2, *title3;
|
char *title1, *title2, *title3;
|
||||||
bigint filepos;
|
bigint filepos;
|
||||||
|
|
||||||
|
std::map<std::string, int> key2col;
|
||||||
|
std::vector<std::string> keyword;
|
||||||
|
|
||||||
int norm, iwindow, window_limit;
|
int norm, iwindow, window_limit;
|
||||||
double *vector;
|
double *vector;
|
||||||
double *vector_total;
|
double *vector_total;
|
||||||
|
|||||||
Reference in New Issue
Block a user