when using "write_data" with "noinit" and "pair ij" generate missing pair coeffs by calling Pair::init_one()

This commit is contained in:
Axel Kohlmeyer
2024-08-06 06:17:44 -04:00
parent 494660700a
commit 543ceaaf89
2 changed files with 42 additions and 37 deletions

View File

@ -42,11 +42,7 @@ enum{ELLIPSOID,LINE,TRIANGLE,BODY}; // also in AtomVecHybrid
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
WriteData::WriteData(LAMMPS *lmp) : Command(lmp) WriteData::WriteData(LAMMPS *lmp) : Command(lmp) {}
{
MPI_Comm_rank(world,&me);
MPI_Comm_size(world,&nprocs);
}
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
called as write_data command in input script called as write_data command in input script
@ -74,12 +70,12 @@ void WriteData::command(int narg, char **arg)
fixflag = 1; fixflag = 1;
triclinic_general = 0; triclinic_general = 0;
lmapflag = 1; lmapflag = 1;
noinitflag = 0;
// store current (default) setting since we may change it // store current (default) setting since we may change it
int domain_triclinic_general = domain->triclinic_general; int domain_triclinic_general = domain->triclinic_general;
int types_style = atom->types_style; int types_style = atom->types_style;
int noinit = 0;
int iarg = 1; int iarg = 1;
while (iarg < narg) { while (iarg < narg) {
@ -90,7 +86,7 @@ void WriteData::command(int narg, char **arg)
else error->all(FLERR,"Unknown write_data pair option: {}", arg[iarg+1]); else error->all(FLERR,"Unknown write_data pair option: {}", arg[iarg+1]);
iarg += 2; iarg += 2;
} else if (strcmp(arg[iarg],"noinit") == 0) { } else if (strcmp(arg[iarg],"noinit") == 0) {
noinit = 1; noinitflag = 1;
iarg++; iarg++;
} else if (strcmp(arg[iarg],"nocoeff") == 0) { } else if (strcmp(arg[iarg],"nocoeff") == 0) {
coeffflag = 0; coeffflag = 0;
@ -130,7 +126,7 @@ void WriteData::command(int narg, char **arg)
// pair->init() can fail due to various unset values: // pair->init() can fail due to various unset values:
// e.g. pair hybrid coeffs, dpd ghost-atom velocity setting // e.g. pair hybrid coeffs, dpd ghost-atom velocity setting
if (noinit == 0) { if (noinitflag == 0) {
if (comm->me == 0) utils::logmesg(lmp,"System init for write_data ...\n"); if (comm->me == 0) utils::logmesg(lmp,"System init for write_data ...\n");
lmp->init(); lmp->init();
@ -206,7 +202,7 @@ void WriteData::write(const std::string &file)
// open data file // open data file
if (me == 0) { if (comm->me == 0) {
fp = fopen(file.c_str(),"w"); fp = fopen(file.c_str(),"w");
if (fp == nullptr) if (fp == nullptr)
error->one(FLERR,"Cannot open data file {}: {}", file, utils::getsyserror()); error->one(FLERR,"Cannot open data file {}: {}", file, utils::getsyserror());
@ -215,7 +211,7 @@ void WriteData::write(const std::string &file)
// proc 0 writes header, ntype-length arrays, force fields // proc 0 writes header, ntype-length arrays, force fields
// label map must come before coeffs // label map must come before coeffs
if (me == 0) { if (comm->me == 0) {
header(); header();
if (lmapflag && atom->labelmapflag) atom->lmap->write_data(fp); if (lmapflag && atom->labelmapflag) atom->lmap->write_data(fp);
type_arrays(); type_arrays();
@ -234,7 +230,7 @@ void WriteData::write(const std::string &file)
if (atom->tag_enable) { if (atom->tag_enable) {
if (natoms) velocities(); if (natoms) velocities();
} else { } else {
if (me == 0) if (comm->me == 0)
error->warning(FLERR, "Not writing Velocities section of data file without atom IDs"); error->warning(FLERR, "Not writing Velocities section of data file without atom IDs");
} }
@ -269,7 +265,7 @@ void WriteData::write(const std::string &file)
// close data file // close data file
if (me == 0) fclose(fp); if (comm->me == 0) fclose(fp);
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -370,6 +366,15 @@ void WriteData::force_fields()
fmt::print(fp,"\nPair Coeffs # {}\n\n", force->pair_style); fmt::print(fp,"\nPair Coeffs # {}\n\n", force->pair_style);
force->pair->write_data(fp); force->pair->write_data(fp);
} else if (pairflag == IJ) { } else if (pairflag == IJ) {
// try computing mixed pair coeffs in case we skipped lmp->init()
// this block of code is currently only accessed from LAMMPS-GUI's restart inspector
if (force->pair->allocated && noinitflag) {
if (comm->me == 0) error->warning(FLERR,"Computing missing pair coeffs from mixing");
for (int i=1; i < atom->ntypes; ++i)
for (int j=i; j <=atom->ntypes; ++j)
if (!force->pair->setflag[i][j])
force->pair->init_one(i, j);
}
fmt::print(fp,"\nPairIJ Coeffs # {}\n\n", force->pair_style); fmt::print(fp,"\nPairIJ Coeffs # {}\n\n", force->pair_style);
force->pair->write_data_all(fp); force->pair->write_data_all(fp);
} }
@ -407,7 +412,7 @@ void WriteData::atoms()
MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world); MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world);
double **buf; double **buf;
if (me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf"); if (comm->me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf");
else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf"); else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf");
// pack my atom data into buf // pack my atom data into buf
@ -420,12 +425,12 @@ void WriteData::atoms()
int tmp,recvrow; int tmp,recvrow;
if (me == 0) { if (comm->me == 0) {
MPI_Status status; MPI_Status status;
MPI_Request request; MPI_Request request;
fmt::print(fp,"\nAtoms # {}\n\n",atom->atom_style); fmt::print(fp,"\nAtoms # {}\n\n",atom->atom_style);
for (int iproc = 0; iproc < nprocs; iproc++) { for (int iproc = 0; iproc < comm->nprocs; iproc++) {
if (iproc) { if (iproc) {
MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_DOUBLE,iproc,0,world,&request); MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_DOUBLE,iproc,0,world,&request);
MPI_Send(&tmp,0,MPI_INT,iproc,0,world); MPI_Send(&tmp,0,MPI_INT,iproc,0,world);
@ -460,7 +465,7 @@ void WriteData::velocities()
MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world); MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world);
double **buf; double **buf;
if (me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf"); if (comm->me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf");
else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf"); else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf");
// pack my velocity data into buf // pack my velocity data into buf
@ -473,12 +478,12 @@ void WriteData::velocities()
int tmp,recvrow; int tmp,recvrow;
if (me == 0) { if (comm->me == 0) {
MPI_Status status; MPI_Status status;
MPI_Request request; MPI_Request request;
fputs("\nVelocities\n\n",fp); fputs("\nVelocities\n\n",fp);
for (int iproc = 0; iproc < nprocs; iproc++) { for (int iproc = 0; iproc < comm->nprocs; iproc++) {
if (iproc) { if (iproc) {
MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_DOUBLE,iproc,0,world,&request); MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_DOUBLE,iproc,0,world,&request);
MPI_Send(&tmp,0,MPI_INT,iproc,0,world); MPI_Send(&tmp,0,MPI_INT,iproc,0,world);
@ -513,7 +518,7 @@ void WriteData::bonds()
MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world); MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world);
tagint **buf; tagint **buf;
if (me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf"); if (comm->me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf");
else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf"); else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf");
// pack my bond data into buf // pack my bond data into buf
@ -527,12 +532,12 @@ void WriteData::bonds()
int tmp,recvrow; int tmp,recvrow;
int index = 1; int index = 1;
if (me == 0) { if (comm->me == 0) {
MPI_Status status; MPI_Status status;
MPI_Request request; MPI_Request request;
fputs("\nBonds\n\n",fp); fputs("\nBonds\n\n",fp);
for (int iproc = 0; iproc < nprocs; iproc++) { for (int iproc = 0; iproc < comm->nprocs; iproc++) {
if (iproc) { if (iproc) {
MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_LMP_TAGINT,iproc,0,world,&request); MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_LMP_TAGINT,iproc,0,world,&request);
MPI_Send(&tmp,0,MPI_INT,iproc,0,world); MPI_Send(&tmp,0,MPI_INT,iproc,0,world);
@ -568,7 +573,7 @@ void WriteData::angles()
MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world); MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world);
tagint **buf; tagint **buf;
if (me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf"); if (comm->me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf");
else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf"); else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf");
// pack my angle data into buf // pack my angle data into buf
@ -582,12 +587,12 @@ void WriteData::angles()
int tmp,recvrow; int tmp,recvrow;
int index = 1; int index = 1;
if (me == 0) { if (comm->me == 0) {
MPI_Status status; MPI_Status status;
MPI_Request request; MPI_Request request;
fputs("\nAngles\n\n",fp); fputs("\nAngles\n\n",fp);
for (int iproc = 0; iproc < nprocs; iproc++) { for (int iproc = 0; iproc < comm->nprocs; iproc++) {
if (iproc) { if (iproc) {
MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_LMP_TAGINT,iproc,0,world,&request); MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_LMP_TAGINT,iproc,0,world,&request);
MPI_Send(&tmp,0,MPI_INT,iproc,0,world); MPI_Send(&tmp,0,MPI_INT,iproc,0,world);
@ -623,7 +628,7 @@ void WriteData::dihedrals()
MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world); MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world);
tagint **buf; tagint **buf;
if (me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf"); if (comm->me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf");
else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf"); else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf");
// pack my dihedral data into buf // pack my dihedral data into buf
@ -637,12 +642,12 @@ void WriteData::dihedrals()
int tmp,recvrow; int tmp,recvrow;
int index = 1; int index = 1;
if (me == 0) { if (comm->me == 0) {
MPI_Status status; MPI_Status status;
MPI_Request request; MPI_Request request;
fputs("\nDihedrals\n\n",fp); fputs("\nDihedrals\n\n",fp);
for (int iproc = 0; iproc < nprocs; iproc++) { for (int iproc = 0; iproc < comm->nprocs; iproc++) {
if (iproc) { if (iproc) {
MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_LMP_TAGINT,iproc,0,world,&request); MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_LMP_TAGINT,iproc,0,world,&request);
MPI_Send(&tmp,0,MPI_INT,iproc,0,world); MPI_Send(&tmp,0,MPI_INT,iproc,0,world);
@ -678,7 +683,7 @@ void WriteData::impropers()
MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world); MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world);
tagint **buf; tagint **buf;
if (me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf"); if (comm->me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf");
else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf"); else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf");
// pack my improper data into buf // pack my improper data into buf
@ -692,12 +697,12 @@ void WriteData::impropers()
int tmp,recvrow; int tmp,recvrow;
int index = 1; int index = 1;
if (me == 0) { if (comm->me == 0) {
MPI_Status status; MPI_Status status;
MPI_Request request; MPI_Request request;
fputs("\nImpropers\n\n",fp); fputs("\nImpropers\n\n",fp);
for (int iproc = 0; iproc < nprocs; iproc++) { for (int iproc = 0; iproc < comm->nprocs; iproc++) {
if (iproc) { if (iproc) {
MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_LMP_TAGINT,iproc,0,world,&request); MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_LMP_TAGINT,iproc,0,world,&request);
MPI_Send(&tmp,0,MPI_INT,iproc,0,world); MPI_Send(&tmp,0,MPI_INT,iproc,0,world);
@ -733,7 +738,7 @@ void WriteData::bonus(int flag)
MPI_Allreduce(&nvalues,&maxvalues,1,MPI_INT,MPI_MAX,world); MPI_Allreduce(&nvalues,&maxvalues,1,MPI_INT,MPI_MAX,world);
double *buf = nullptr; double *buf = nullptr;
if (me == 0) memory->create(buf,MAX(1,maxvalues),"write_data:buf"); if (comm->me == 0) memory->create(buf,MAX(1,maxvalues),"write_data:buf");
else memory->create(buf,MAX(1,nvalues),"write_data:buf"); else memory->create(buf,MAX(1,nvalues),"write_data:buf");
// pack my bonus data into buf // pack my bonus data into buf
@ -746,7 +751,7 @@ void WriteData::bonus(int flag)
int tmp; int tmp;
if (me == 0) { if (comm->me == 0) {
MPI_Status status; MPI_Status status;
MPI_Request request; MPI_Request request;
@ -755,7 +760,7 @@ void WriteData::bonus(int flag)
if (flag == TRIANGLE) fputs("\nTriangles\n\n",fp); if (flag == TRIANGLE) fputs("\nTriangles\n\n",fp);
if (flag == BODY) fputs("\nBodies\n\n",fp); if (flag == BODY) fputs("\nBodies\n\n",fp);
for (int iproc = 0; iproc < nprocs; iproc++) { for (int iproc = 0; iproc < comm->nprocs; iproc++) {
if (iproc) { if (iproc) {
MPI_Irecv(buf,maxvalues,MPI_DOUBLE,iproc,0,world,&request); MPI_Irecv(buf,maxvalues,MPI_DOUBLE,iproc,0,world,&request);
MPI_Send(&tmp,0,MPI_INT,iproc,0,world); MPI_Send(&tmp,0,MPI_INT,iproc,0,world);
@ -789,7 +794,7 @@ void WriteData::fix(Fix *ifix, int mth)
MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world); MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world);
double **buf; double **buf;
if (me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf"); if (comm->me == 0) memory->create(buf,MAX(1,maxrow),ncol,"write_data:buf");
else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf"); else memory->create(buf,MAX(1,sendrow),ncol,"write_data:buf");
// pack my fix data into buf // pack my fix data into buf
@ -803,12 +808,12 @@ void WriteData::fix(Fix *ifix, int mth)
int tmp,recvrow; int tmp,recvrow;
int index = 1; int index = 1;
if (me == 0) { if (comm->me == 0) {
MPI_Status status; MPI_Status status;
MPI_Request request; MPI_Request request;
ifix->write_data_section_keyword(mth,fp); ifix->write_data_section_keyword(mth,fp);
for (int iproc = 0; iproc < nprocs; iproc++) { for (int iproc = 0; iproc < comm->nprocs; iproc++) {
if (iproc) { if (iproc) {
MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_DOUBLE,iproc,0,world,&request); MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_DOUBLE,iproc,0,world,&request);
MPI_Send(&tmp,0,MPI_INT,iproc,0,world); MPI_Send(&tmp,0,MPI_INT,iproc,0,world);

View File

@ -31,12 +31,12 @@ class WriteData : public Command {
void write(const std::string &); void write(const std::string &);
private: private:
int me, nprocs;
int pairflag; int pairflag;
int coeffflag; int coeffflag;
int fixflag; int fixflag;
int triclinic_general; int triclinic_general;
int lmapflag; int lmapflag;
int noinitflag;
FILE *fp; FILE *fp;
bigint nbonds_local, nbonds; bigint nbonds_local, nbonds;
bigint nangles_local, nangles; bigint nangles_local, nangles;