type labels: restart support
This commit is contained in:
@ -1991,6 +1991,7 @@ void Atom::add_molecule_atom(Molecule *onemol, int iatom,
|
||||
|
||||
void Atom::add_label_map()
|
||||
{
|
||||
labelmapflag = 1;
|
||||
lmap = new LabelMap(lmp);
|
||||
lmap->natomtypes = ntypes;
|
||||
lmap->nbondtypes = nbondtypes;
|
||||
|
||||
0
src/input.cpp
Normal file → Executable file
0
src/input.cpp
Normal file → Executable file
0
src/input.h
Normal file → Executable file
0
src/input.h
Normal file → Executable file
@ -25,6 +25,7 @@ using namespace LAMMPS_NS;
|
||||
|
||||
LabelMap::LabelMap(LAMMPS *lmp) : Pointers(lmp)
|
||||
{
|
||||
MPI_Comm_rank(world,&me);
|
||||
natomtypes = nbondtypes = nangletypes = 0;
|
||||
ndihedraltypes = nimpropertypes = 0;
|
||||
}
|
||||
@ -50,8 +51,6 @@ LabelMap::~LabelMap()
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
allocate character-based type arrays (labels) of length ntypes
|
||||
always allocated (for both numeric and character-based type modes)
|
||||
initialize label with (a string of) its numeric counterpart
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void LabelMap::allocate_type_labels()
|
||||
@ -59,26 +58,18 @@ void LabelMap::allocate_type_labels()
|
||||
typelabel.resize(natomtypes);
|
||||
lmap2lmap.atom = new int[natomtypes];
|
||||
|
||||
if (force->bond) {
|
||||
btypelabel.resize(nbondtypes);
|
||||
lmap2lmap.bond = new int[nbondtypes];
|
||||
}
|
||||
|
||||
if (force->angle) {
|
||||
atypelabel.resize(nangletypes);
|
||||
lmap2lmap.angle = new int[nangletypes];
|
||||
}
|
||||
|
||||
if (force->dihedral) {
|
||||
dtypelabel.resize(ndihedraltypes);
|
||||
lmap2lmap.dihedral = new int[ndihedraltypes];
|
||||
}
|
||||
|
||||
if (force->improper) {
|
||||
itypelabel.resize(nimpropertypes);
|
||||
lmap2lmap.improper = new int[nimpropertypes];
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
labelmap command in input script
|
||||
@ -251,3 +242,105 @@ void LabelMap::write_data(FILE *fp)
|
||||
fmt::print(fp,"{} {}\n",i+1,itypelabel[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
proc 0 reads from restart file, bcasts
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void LabelMap::read_restart(FILE *fp)
|
||||
{
|
||||
char *charlabel;
|
||||
|
||||
for (int i = 0; i < natomtypes; i++) {
|
||||
charlabel = read_string(fp);
|
||||
typelabel[i] = charlabel;
|
||||
delete [] charlabel;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nbondtypes; i++) {
|
||||
charlabel = read_string(fp);
|
||||
btypelabel[i] = charlabel;
|
||||
delete [] charlabel;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nangletypes; i++) {
|
||||
charlabel = read_string(fp);
|
||||
atypelabel[i] = charlabel;
|
||||
delete [] charlabel;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ndihedraltypes; i++) {
|
||||
charlabel = read_string(fp);
|
||||
dtypelabel[i] = charlabel;
|
||||
delete [] charlabel;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nimpropertypes; i++) {
|
||||
charlabel = read_string(fp);
|
||||
itypelabel[i] = charlabel;
|
||||
delete [] charlabel;
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
proc 0 writes to restart file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void LabelMap::write_restart(FILE *fp)
|
||||
{
|
||||
for (int i = 0; i < natomtypes; i++)
|
||||
write_string(typelabel[i],fp);
|
||||
|
||||
for (int i = 0; i < nbondtypes; i++)
|
||||
write_string(btypelabel[i],fp);
|
||||
|
||||
for (int i = 0; i < nangletypes; i++)
|
||||
write_string(atypelabel[i],fp);
|
||||
|
||||
for (int i = 0; i < ndihedraltypes; i++)
|
||||
write_string(dtypelabel[i],fp);
|
||||
|
||||
for (int i = 0; i < nimpropertypes; i++)
|
||||
write_string(itypelabel[i],fp);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
read a char string (including nullptr) and bcast it
|
||||
str is allocated here, ptr is returned, caller must deallocate
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
char *LabelMap::read_string(FILE *fp)
|
||||
{
|
||||
int n = read_int(fp);
|
||||
if (n < 0) error->all(FLERR,"Illegal size string or corrupt restart");
|
||||
char *value = new char[n];
|
||||
if (me == 0) utils::sfread(FLERR,value,sizeof(char),n,fp,nullptr,error);
|
||||
MPI_Bcast(value,n,MPI_CHAR,0,world);
|
||||
return value;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
write a flag and a C-style char string (including the terminating null
|
||||
byte) into the restart file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void LabelMap::write_string(std::string str, FILE *fp)
|
||||
{
|
||||
const char *cstr = str.c_str();
|
||||
int n = strlen(cstr) + 1;
|
||||
fwrite(&n,sizeof(int),1,fp);
|
||||
fwrite(cstr,sizeof(char),n,fp);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
read an int from restart file and bcast it
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
int LabelMap::read_int(FILE *fp)
|
||||
{
|
||||
int value;
|
||||
if ((me == 0) && (fread(&value,sizeof(int),1,fp) < 1))
|
||||
value = -1;
|
||||
MPI_Bcast(&value,1,MPI_INT,0,world);
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -47,9 +47,19 @@ class LabelMap : protected Pointers {
|
||||
void create_lmap2lmap(class LabelMap *, int); // index mapping between two lmaps
|
||||
int find_or_create(std::string, std::vector<std::string> &, int); // look up type or create new type
|
||||
int find(std::string, std::vector<std::string>, int); // look up type index
|
||||
void write_data(FILE *);
|
||||
|
||||
protected:
|
||||
// input/output for atom class label map
|
||||
|
||||
void write_data(FILE *);
|
||||
void read_restart(FILE *fp);
|
||||
void write_restart(FILE *);
|
||||
|
||||
private:
|
||||
int me;
|
||||
|
||||
char *read_string(FILE *);
|
||||
void write_string(std::string, FILE *);
|
||||
int read_int(FILE *);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ enum{VERSION,SMALLINT,TAGINT,BIGINT,
|
||||
COMM_MODE,COMM_CUTOFF,COMM_VEL,NO_PAIR,
|
||||
EXTRA_BOND_PER_ATOM,EXTRA_ANGLE_PER_ATOM,EXTRA_DIHEDRAL_PER_ATOM,
|
||||
EXTRA_IMPROPER_PER_ATOM,EXTRA_SPECIAL_PER_ATOM,ATOM_MAXSPECIAL,
|
||||
NELLIPSOIDS,NLINES,NTRIS,NBODIES};
|
||||
NELLIPSOIDS,NLINES,NTRIS,NBODIES,LABELMAP};
|
||||
|
||||
#define LB_FACTOR 1.1
|
||||
|
||||
|
||||
0
src/molecule.cpp
Normal file → Executable file
0
src/molecule.cpp
Normal file → Executable file
0
src/molecule.h
Normal file → Executable file
0
src/molecule.h
Normal file → Executable file
@ -441,7 +441,6 @@ void ReadData::command(int narg, char **arg)
|
||||
else n = static_cast<int> (LB_FACTOR * atom->natoms / comm->nprocs);
|
||||
|
||||
atom->allocate_type_arrays();
|
||||
atom->add_label_map();
|
||||
atom->deallocate_topology();
|
||||
|
||||
// allocate atom arrays to N, rounded up by AtomVec->DELTA
|
||||
@ -1975,7 +1974,7 @@ void ReadData::typelabels(std::vector<std::string> &mytypelabel, int myntypes, i
|
||||
char *buf = new char[myntypes*MAXLINE];
|
||||
|
||||
labelflag = 1;
|
||||
atom->labelmapflag = 1;
|
||||
if (atom->labelmapflag == 0) atom->add_label_map();
|
||||
|
||||
int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf);
|
||||
if (eof) error->all(FLERR,"Unexpected end of data file");
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#include "group.h"
|
||||
#include "improper.h"
|
||||
#include "irregular.h"
|
||||
#include "label_map.h"
|
||||
#include "memory.h"
|
||||
#include "modify.h"
|
||||
#include "mpiio.h"
|
||||
@ -929,6 +930,11 @@ void ReadRestart::type_arrays()
|
||||
atom->set_mass(mass);
|
||||
delete [] mass;
|
||||
|
||||
} else if (flag == LABELMAP) {
|
||||
read_int();
|
||||
atom->add_label_map();
|
||||
atom->lmap->read_restart(fp);
|
||||
|
||||
} else error->all(FLERR,
|
||||
"Invalid flag in type arrays section of restart file");
|
||||
|
||||
|
||||
0
src/write_data.cpp
Normal file → Executable file
0
src/write_data.cpp
Normal file → Executable file
0
src/write_data.h
Normal file → Executable file
0
src/write_data.h
Normal file → Executable file
5
src/write_restart.cpp
Normal file → Executable file
5
src/write_restart.cpp
Normal file → Executable file
@ -25,6 +25,7 @@
|
||||
#include "force.h"
|
||||
#include "group.h"
|
||||
#include "improper.h"
|
||||
#include "label_map.h"
|
||||
#include "memory.h"
|
||||
#include "modify.h"
|
||||
#include "mpiio.h"
|
||||
@ -520,6 +521,10 @@ void WriteRestart::header()
|
||||
void WriteRestart::type_arrays()
|
||||
{
|
||||
if (atom->mass) write_double_vec(MASS,atom->ntypes,&atom->mass[1]);
|
||||
if (atom->labelmapflag) {
|
||||
write_int(LABELMAP,atom->labelmapflag);
|
||||
atom->lmap->write_restart(fp);
|
||||
}
|
||||
|
||||
// -1 flag signals end of type arrays
|
||||
|
||||
|
||||
0
src/write_restart.h
Normal file → Executable file
0
src/write_restart.h
Normal file → Executable file
Reference in New Issue
Block a user