modernize parsing of Velocities section of data files
This commit is contained in:
@ -1019,21 +1019,21 @@ void AtomVecHybridKokkos::data_atom(double *coord, imageint imagetmp,
|
||||
unpack one line from Velocities section of data file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void AtomVecHybridKokkos::data_vel(int m, char **values)
|
||||
void AtomVecHybridKokkos::data_vel(int m, const std::vector<std::string> &values)
|
||||
{
|
||||
atomKK->sync(Host,V_MASK);
|
||||
|
||||
h_v(m,0) = utils::numeric(FLERR,values[0],true,lmp);
|
||||
h_v(m,1) = utils::numeric(FLERR,values[1],true,lmp);
|
||||
h_v(m,2) = utils::numeric(FLERR,values[2],true,lmp);
|
||||
int ivalue = 1;
|
||||
h_v(m,0) = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
h_v(m,1) = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
h_v(m,2) = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
|
||||
atomKK->modified(Host,V_MASK);
|
||||
|
||||
// each sub-style parses sub-style specific values
|
||||
|
||||
int n = 3;
|
||||
for (int k = 0; k < nstyles; k++)
|
||||
n += styles[k]->data_vel_hybrid(m,&values[n]);
|
||||
ivalue += styles[k]->data_vel_hybrid(m,values,ivalue);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
||||
@ -59,7 +59,7 @@ class AtomVecHybridKokkos : public AtomVecKokkos {
|
||||
void create_atom(int, double *);
|
||||
void data_atom(double *, imageint, const std::vector<std::string> &);
|
||||
int data_atom_hybrid(int, const std::vector<std::string> &, int) {return 0;}
|
||||
void data_vel(int, char **);
|
||||
void data_vel(int, const std::vector<std::string> &);
|
||||
void pack_data(double **);
|
||||
void write_data(FILE *, int, double **);
|
||||
void pack_vel(double **);
|
||||
|
||||
@ -1016,12 +1016,13 @@ void AtomVecKokkos::unpack_reverse(int n, int *list, double *buf)
|
||||
* unpack one line from Velocities section of data file
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
void AtomVecKokkos::data_vel(int m, char **values)
|
||||
void AtomVecKokkos::data_vel(int m, const std::vector<std::string> &values)
|
||||
{
|
||||
double **v = atom->v;
|
||||
v[m][0] = utils::numeric(FLERR,values[0],true,lmp);
|
||||
v[m][1] = utils::numeric(FLERR,values[1],true,lmp);
|
||||
v[m][2] = utils::numeric(FLERR,values[2],true,lmp);
|
||||
int ivalue = 1;
|
||||
v[m][0] = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
v[m][1] = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
v[m][2] = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
|
||||
atomKK->modified(Host,V_MASK);
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ class AtomVecKokkos : public AtomVec {
|
||||
virtual void unpack_comm_vel(int, int, double *);
|
||||
virtual int pack_reverse(int, int, double *);
|
||||
virtual void unpack_reverse(int, int *, double *);
|
||||
virtual void data_vel(int, char **);
|
||||
virtual void data_vel(int, const std::vector<std::string> &);
|
||||
virtual void pack_vel(double **);
|
||||
virtual void write_vel(FILE *, int, double **);
|
||||
|
||||
|
||||
@ -2617,15 +2617,16 @@ int AtomVecSphereKokkos::data_atom_hybrid(int nlocal, const std::vector<std::str
|
||||
unpack one line from Velocities section of data file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void AtomVecSphereKokkos::data_vel(int m, char **values)
|
||||
void AtomVecSphereKokkos::data_vel(int m, const std::vector<std::string> &values)
|
||||
{
|
||||
int ivalue = 1;
|
||||
atomKK->sync(Host,V_MASK|OMEGA_MASK);
|
||||
h_v(m,0) = utils::numeric(FLERR,values[0],true,lmp);
|
||||
h_v(m,1) = utils::numeric(FLERR,values[1],true,lmp);
|
||||
h_v(m,2) = utils::numeric(FLERR,values[2],true,lmp);
|
||||
h_omega(m,0) = utils::numeric(FLERR,values[3],true,lmp);
|
||||
h_omega(m,1) = utils::numeric(FLERR,values[4],true,lmp);
|
||||
h_omega(m,2) = utils::numeric(FLERR,values[5],true,lmp);
|
||||
h_v(m,0) = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
h_v(m,1) = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
h_v(m,2) = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
h_omega(m,0) = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
h_omega(m,1) = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
h_omega(m,2) = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
atomKK->modified(Host,V_MASK|OMEGA_MASK);
|
||||
}
|
||||
|
||||
@ -2633,12 +2634,13 @@ void AtomVecSphereKokkos::data_vel(int m, char **values)
|
||||
unpack hybrid quantities from one line in Velocities section of data file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
int AtomVecSphereKokkos::data_vel_hybrid(int m, char **values)
|
||||
int AtomVecSphereKokkos::data_vel_hybrid(int m, const std::vector<std::string> &values,
|
||||
int offset)
|
||||
{
|
||||
atomKK->sync(Host,OMEGA_MASK);
|
||||
omega[m][0] = utils::numeric(FLERR,values[0],true,lmp);
|
||||
omega[m][1] = utils::numeric(FLERR,values[1],true,lmp);
|
||||
omega[m][2] = utils::numeric(FLERR,values[2],true,lmp);
|
||||
omega[m][0] = utils::numeric(FLERR,values[offset],true,lmp);
|
||||
omega[m][1] = utils::numeric(FLERR,values[offset+1],true,lmp);
|
||||
omega[m][2] = utils::numeric(FLERR,values[offset+2],true,lmp);
|
||||
atomKK->modified(Host,OMEGA_MASK);
|
||||
return 3;
|
||||
}
|
||||
|
||||
@ -60,8 +60,8 @@ class AtomVecSphereKokkos : public AtomVecKokkos {
|
||||
void create_atom(int, double *);
|
||||
void data_atom(double *, imageint, const std::vector<std::string> &);
|
||||
int data_atom_hybrid(int, const std::vector<std::string> &, int);
|
||||
void data_vel(int, char **);
|
||||
int data_vel_hybrid(int, char **);
|
||||
void data_vel(int, const std::vector<std::string> &);
|
||||
int data_vel_hybrid(int, const std::vector<std::string> &, int);
|
||||
void pack_data(double **);
|
||||
int pack_data_hybrid(int, double *);
|
||||
void write_data(FILE *, int, double **);
|
||||
|
||||
19
src/atom.cpp
19
src/atom.cpp
@ -1209,31 +1209,24 @@ void Atom::data_vels(int n, char *buf, tagint id_offset)
|
||||
if (nwords != avec->size_data_vel)
|
||||
error->all(FLERR,"Incorrect velocity format in data file");
|
||||
|
||||
char **values = new char*[nwords];
|
||||
|
||||
// loop over lines of atom velocities
|
||||
// tokenize the line into values
|
||||
// if I own atom tag, unpack its values
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
next = strchr(buf,'\n');
|
||||
*next = '\0';
|
||||
auto values = Tokenizer(utils::trim_comment(buf)).as_vector();
|
||||
if (values.size() != nwords)
|
||||
error->all(FLERR, "Incorrect atom format in data file: {}", utils::trim(buf));
|
||||
|
||||
for (j = 0; j < nwords; j++) {
|
||||
buf += strspn(buf," \t\n\r\f");
|
||||
buf[strcspn(buf," \t\n\r\f")] = '\0';
|
||||
values[j] = buf;
|
||||
buf += strlen(buf)+1;
|
||||
}
|
||||
|
||||
tagdata = ATOTAGINT(values[0]) + id_offset;
|
||||
tagdata = utils::tnumeric(FLERR,values[0],false,lmp) + id_offset;
|
||||
if (tagdata <= 0 || tagdata > map_tag_max)
|
||||
error->one(FLERR,"Invalid atom ID in Velocities section of data file");
|
||||
if ((m = map(tagdata)) >= 0) avec->data_vel(m,&values[1]);
|
||||
if ((m = map(tagdata)) >= 0) avec->data_vel(m,values);
|
||||
|
||||
buf = next + 1;
|
||||
}
|
||||
|
||||
delete [] values;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
||||
@ -1890,18 +1890,18 @@ void AtomVec::write_data(FILE *fp, int n, double **buf)
|
||||
unpack one line from Velocities section of data file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void AtomVec::data_vel(int ilocal, char **values)
|
||||
void AtomVec::data_vel(int ilocal, const std::vector<std::string> &values)
|
||||
{
|
||||
int m,n,datatype,cols;
|
||||
void *pdata;
|
||||
|
||||
double **v = atom->v;
|
||||
v[ilocal][0] = utils::numeric(FLERR,values[0],true,lmp);
|
||||
v[ilocal][1] = utils::numeric(FLERR,values[1],true,lmp);
|
||||
v[ilocal][2] = utils::numeric(FLERR,values[2],true,lmp);
|
||||
int ivalue = 1;
|
||||
v[ilocal][0] = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
v[ilocal][1] = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
v[ilocal][2] = utils::numeric(FLERR,values[ivalue++],true,lmp);
|
||||
|
||||
if (ndata_vel > 2) {
|
||||
int ivalue = 3;
|
||||
for (n = 2; n < ndata_vel; n++) {
|
||||
pdata = mdata_vel.pdata[n];
|
||||
datatype = mdata_vel.datatype[n];
|
||||
|
||||
@ -136,7 +136,7 @@ class AtomVec : protected Pointers {
|
||||
virtual void pack_data_pre(int) {}
|
||||
virtual void pack_data_post(int) {}
|
||||
|
||||
virtual void data_vel(int, char **);
|
||||
virtual void data_vel(int, const std::vector<std::string> &);
|
||||
virtual void pack_vel(double **);
|
||||
virtual void write_vel(FILE *, int, double **);
|
||||
|
||||
@ -167,7 +167,7 @@ class AtomVec : protected Pointers {
|
||||
virtual int pack_border_hybrid(int, int *, double *) { return 0; }
|
||||
virtual int unpack_border_hybrid(int, int, double *) { return 0; }
|
||||
virtual int data_atom_hybrid(int, const std::vector<std::string> &, int) { return 0; }
|
||||
virtual int data_vel_hybrid(int, char **) { return 0; }
|
||||
virtual int data_vel_hybrid(int, const std::vector<std::string> &, int) { return 0; }
|
||||
virtual int pack_data_hybrid(int, double *) { return 0; }
|
||||
virtual int write_data_hybrid(FILE *, double *) { return 0; }
|
||||
virtual int pack_vel_hybrid(int, double *) { return 0; }
|
||||
|
||||
Reference in New Issue
Block a user