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()
|
void Atom::add_label_map()
|
||||||
{
|
{
|
||||||
|
labelmapflag = 1;
|
||||||
lmap = new LabelMap(lmp);
|
lmap = new LabelMap(lmp);
|
||||||
lmap->natomtypes = ntypes;
|
lmap->natomtypes = ntypes;
|
||||||
lmap->nbondtypes = nbondtypes;
|
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)
|
LabelMap::LabelMap(LAMMPS *lmp) : Pointers(lmp)
|
||||||
{
|
{
|
||||||
|
MPI_Comm_rank(world,&me);
|
||||||
natomtypes = nbondtypes = nangletypes = 0;
|
natomtypes = nbondtypes = nangletypes = 0;
|
||||||
ndihedraltypes = nimpropertypes = 0;
|
ndihedraltypes = nimpropertypes = 0;
|
||||||
}
|
}
|
||||||
@ -50,8 +51,6 @@ LabelMap::~LabelMap()
|
|||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
allocate character-based type arrays (labels) of length ntypes
|
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()
|
void LabelMap::allocate_type_labels()
|
||||||
@ -59,25 +58,17 @@ void LabelMap::allocate_type_labels()
|
|||||||
typelabel.resize(natomtypes);
|
typelabel.resize(natomtypes);
|
||||||
lmap2lmap.atom = new int[natomtypes];
|
lmap2lmap.atom = new int[natomtypes];
|
||||||
|
|
||||||
if (force->bond) {
|
btypelabel.resize(nbondtypes);
|
||||||
btypelabel.resize(nbondtypes);
|
lmap2lmap.bond = new int[nbondtypes];
|
||||||
lmap2lmap.bond = new int[nbondtypes];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (force->angle) {
|
atypelabel.resize(nangletypes);
|
||||||
atypelabel.resize(nangletypes);
|
lmap2lmap.angle = new int[nangletypes];
|
||||||
lmap2lmap.angle = new int[nangletypes];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (force->dihedral) {
|
dtypelabel.resize(ndihedraltypes);
|
||||||
dtypelabel.resize(ndihedraltypes);
|
lmap2lmap.dihedral = new int[ndihedraltypes];
|
||||||
lmap2lmap.dihedral = new int[ndihedraltypes];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (force->improper) {
|
itypelabel.resize(nimpropertypes);
|
||||||
itypelabel.resize(nimpropertypes);
|
lmap2lmap.improper = new int[nimpropertypes];
|
||||||
lmap2lmap.improper = new int[nimpropertypes];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
@ -251,3 +242,105 @@ void LabelMap::write_data(FILE *fp)
|
|||||||
fmt::print(fp,"{} {}\n",i+1,itypelabel[i]);
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@ -43,13 +43,23 @@ class LabelMap : protected Pointers {
|
|||||||
|
|
||||||
void allocate_type_labels();
|
void allocate_type_labels();
|
||||||
void modify_lmap(int, char **);
|
void modify_lmap(int, char **);
|
||||||
void merge_lmap(class LabelMap *, int); // copy another lmap into this one
|
void merge_lmap(class LabelMap *, int); // copy another lmap into this one
|
||||||
void create_lmap2lmap(class LabelMap *, int); // index mapping between two lmaps
|
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_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
|
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,
|
COMM_MODE,COMM_CUTOFF,COMM_VEL,NO_PAIR,
|
||||||
EXTRA_BOND_PER_ATOM,EXTRA_ANGLE_PER_ATOM,EXTRA_DIHEDRAL_PER_ATOM,
|
EXTRA_BOND_PER_ATOM,EXTRA_ANGLE_PER_ATOM,EXTRA_DIHEDRAL_PER_ATOM,
|
||||||
EXTRA_IMPROPER_PER_ATOM,EXTRA_SPECIAL_PER_ATOM,ATOM_MAXSPECIAL,
|
EXTRA_IMPROPER_PER_ATOM,EXTRA_SPECIAL_PER_ATOM,ATOM_MAXSPECIAL,
|
||||||
NELLIPSOIDS,NLINES,NTRIS,NBODIES};
|
NELLIPSOIDS,NLINES,NTRIS,NBODIES,LABELMAP};
|
||||||
|
|
||||||
#define LB_FACTOR 1.1
|
#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);
|
else n = static_cast<int> (LB_FACTOR * atom->natoms / comm->nprocs);
|
||||||
|
|
||||||
atom->allocate_type_arrays();
|
atom->allocate_type_arrays();
|
||||||
atom->add_label_map();
|
|
||||||
atom->deallocate_topology();
|
atom->deallocate_topology();
|
||||||
|
|
||||||
// allocate atom arrays to N, rounded up by AtomVec->DELTA
|
// 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];
|
char *buf = new char[myntypes*MAXLINE];
|
||||||
|
|
||||||
labelflag = 1;
|
labelflag = 1;
|
||||||
atom->labelmapflag = 1;
|
if (atom->labelmapflag == 0) atom->add_label_map();
|
||||||
|
|
||||||
int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf);
|
int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf);
|
||||||
if (eof) error->all(FLERR,"Unexpected end of data file");
|
if (eof) error->all(FLERR,"Unexpected end of data file");
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "improper.h"
|
#include "improper.h"
|
||||||
#include "irregular.h"
|
#include "irregular.h"
|
||||||
|
#include "label_map.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "modify.h"
|
#include "modify.h"
|
||||||
#include "mpiio.h"
|
#include "mpiio.h"
|
||||||
@ -929,6 +930,11 @@ void ReadRestart::type_arrays()
|
|||||||
atom->set_mass(mass);
|
atom->set_mass(mass);
|
||||||
delete [] mass;
|
delete [] mass;
|
||||||
|
|
||||||
|
} else if (flag == LABELMAP) {
|
||||||
|
read_int();
|
||||||
|
atom->add_label_map();
|
||||||
|
atom->lmap->read_restart(fp);
|
||||||
|
|
||||||
} else error->all(FLERR,
|
} else error->all(FLERR,
|
||||||
"Invalid flag in type arrays section of restart file");
|
"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 "force.h"
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "improper.h"
|
#include "improper.h"
|
||||||
|
#include "label_map.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "modify.h"
|
#include "modify.h"
|
||||||
#include "mpiio.h"
|
#include "mpiio.h"
|
||||||
@ -520,6 +521,10 @@ void WriteRestart::header()
|
|||||||
void WriteRestart::type_arrays()
|
void WriteRestart::type_arrays()
|
||||||
{
|
{
|
||||||
if (atom->mass) write_double_vec(MASS,atom->ntypes,&atom->mass[1]);
|
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
|
// -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