add yaml format output for mode scalar

This commit is contained in:
Axel Kohlmeyer
2022-04-28 07:46:47 -04:00
parent 09ed718c14
commit 2f71c96bde
2 changed files with 62 additions and 12 deletions

View File

@ -83,6 +83,8 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
int expand = 0;
char **earg;
nvalues = utils::expand_args(FLERR,nvalues,&arg[6],mode,earg,lmp);
keyword.resize(nvalues);
key2col.clear();
if (earg != &arg[6]) expand = 1;
arg = earg;
@ -98,6 +100,8 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
for (int i = 0; i < nvalues; i++) {
ArgInfo argi(arg[i]);
keyword[i] = arg[i];
key2col[arg[i]] = i;
if ((argi.get_type() == ArgInfo::NONE)
|| (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]);
fprintf(fp,"\n");
}
if (ferror(fp))
error->one(FLERR,"Error writing file header");
if (yaml_flag) fputs("---\n",fp);
if (ferror(fp)) error->one(FLERR,"Error writing file header: {}", utils::getsyserror());
filepos = platform::ftell(fp);
}
@ -456,8 +459,10 @@ FixAveTime::~FixAveTime()
delete[] extlist;
if (fp && me == 0) fclose(fp);
if (fp && me == 0) {
if (yaml_flag) fputs("...\n", fp);
fclose(fp);
}
memory->destroy(column);
delete[] vector;
@ -669,11 +674,22 @@ void FixAveTime::invoke_scalar(bigint ntimestep)
if (fp && me == 0) {
clearerr(fp);
if (overwrite) platform::fseek(fp,filepos);
fmt::print(fp,"{}",ntimestep);
for (i = 0; i < nvalues; i++) fprintf(fp,format,vector_total[i]/norm);
fprintf(fp,"\n");
if (ferror(fp)) error->one(FLERR,"Error writing out time averaged data");
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);
for (i = 0; i < nvalues; i++) fprintf(fp,format,vector_total[i]/norm);
fprintf(fp,"\n");
if (ferror(fp)) error->one(FLERR,"Error writing out time averaged data");
}
fflush(fp);
if (overwrite) {
@ -994,6 +1010,34 @@ double FixAveTime::compute_array(int i, int j)
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
------------------------------------------------------------------------- */
@ -1009,7 +1053,7 @@ void FixAveTime::options(int iarg, int narg, char **arg)
noff = 0;
offlist = nullptr;
overwrite = 0;
yaml_flag = false;
yaml_flag = yaml_header = false;
format_user = nullptr;
format = (char *) " %g";
title1 = nullptr;

View File

@ -22,6 +22,8 @@ FixStyle(ave/time,FixAveTime);
#include "fix.h"
#include <map>
namespace LAMMPS_NS {
class FixAveTime : public Fix {
@ -32,6 +34,7 @@ class FixAveTime : public Fix {
void init() override;
void setup(int) override;
void end_of_step() override;
int modify_param(int, char **) override;
double compute_scalar() override;
double compute_vector(int) override;
double compute_array(int, int) override;
@ -48,7 +51,7 @@ class FixAveTime : public Fix {
int any_variable_length;
int all_variable_length;
int lockforever;
bool yaml_flag;
bool yaml_flag, yaml_header;
int ave, nwindow, startstep, mode;
int noff, overwrite;
@ -57,6 +60,9 @@ class FixAveTime : public Fix {
char *title1, *title2, *title3;
bigint filepos;
std::map<std::string, int> key2col;
std::vector<std::string> keyword;
int norm, iwindow, window_limit;
double *vector;
double *vector_total;