From 8d53cd1e5d1538deb0597f2010e5ce267c67e35c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 30 Dec 2021 19:02:52 -0500 Subject: [PATCH] modernize parsing of Velocities section of data files --- src/KOKKOS/atom_vec_hybrid_kokkos.cpp | 12 ++++++------ src/KOKKOS/atom_vec_hybrid_kokkos.h | 2 +- src/KOKKOS/atom_vec_kokkos.cpp | 9 +++++---- src/KOKKOS/atom_vec_kokkos.h | 2 +- src/KOKKOS/atom_vec_sphere_kokkos.cpp | 24 +++++++++++++----------- src/KOKKOS/atom_vec_sphere_kokkos.h | 4 ++-- src/atom.cpp | 19 ++++++------------- src/atom_vec.cpp | 10 +++++----- src/atom_vec.h | 4 ++-- 9 files changed, 41 insertions(+), 45 deletions(-) diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp index 60ee9cc04c..22ce80478c 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp @@ -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 &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); } /* ---------------------------------------------------------------------- diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.h b/src/KOKKOS/atom_vec_hybrid_kokkos.h index 17e27ca0b6..567b98695f 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.h +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.h @@ -59,7 +59,7 @@ class AtomVecHybridKokkos : public AtomVecKokkos { void create_atom(int, double *); void data_atom(double *, imageint, const std::vector &); int data_atom_hybrid(int, const std::vector &, int) {return 0;} - void data_vel(int, char **); + void data_vel(int, const std::vector &); void pack_data(double **); void write_data(FILE *, int, double **); void pack_vel(double **); diff --git a/src/KOKKOS/atom_vec_kokkos.cpp b/src/KOKKOS/atom_vec_kokkos.cpp index 1255712a21..931cd8d8f4 100644 --- a/src/KOKKOS/atom_vec_kokkos.cpp +++ b/src/KOKKOS/atom_vec_kokkos.cpp @@ -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 &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); } diff --git a/src/KOKKOS/atom_vec_kokkos.h b/src/KOKKOS/atom_vec_kokkos.h index c596d80e94..20dd41dd75 100644 --- a/src/KOKKOS/atom_vec_kokkos.h +++ b/src/KOKKOS/atom_vec_kokkos.h @@ -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 &); virtual void pack_vel(double **); virtual void write_vel(FILE *, int, double **); diff --git a/src/KOKKOS/atom_vec_sphere_kokkos.cpp b/src/KOKKOS/atom_vec_sphere_kokkos.cpp index 61a33d99ae..0b722e8563 100644 --- a/src/KOKKOS/atom_vec_sphere_kokkos.cpp +++ b/src/KOKKOS/atom_vec_sphere_kokkos.cpp @@ -2617,15 +2617,16 @@ int AtomVecSphereKokkos::data_atom_hybrid(int nlocal, const std::vector &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 &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; } diff --git a/src/KOKKOS/atom_vec_sphere_kokkos.h b/src/KOKKOS/atom_vec_sphere_kokkos.h index 79ece5ca83..a9ba4baa24 100644 --- a/src/KOKKOS/atom_vec_sphere_kokkos.h +++ b/src/KOKKOS/atom_vec_sphere_kokkos.h @@ -60,8 +60,8 @@ class AtomVecSphereKokkos : public AtomVecKokkos { void create_atom(int, double *); void data_atom(double *, imageint, const std::vector &); int data_atom_hybrid(int, const std::vector &, int); - void data_vel(int, char **); - int data_vel_hybrid(int, char **); + void data_vel(int, const std::vector &); + int data_vel_hybrid(int, const std::vector &, int); void pack_data(double **); int pack_data_hybrid(int, double *); void write_data(FILE *, int, double **); diff --git a/src/atom.cpp b/src/atom.cpp index 438dcd4870..ae0968aa61 100644 --- a/src/atom.cpp +++ b/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; } /* ---------------------------------------------------------------------- diff --git a/src/atom_vec.cpp b/src/atom_vec.cpp index f80d25b706..aa646ecabb 100644 --- a/src/atom_vec.cpp +++ b/src/atom_vec.cpp @@ -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 &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]; diff --git a/src/atom_vec.h b/src/atom_vec.h index cb27a11519..57ca96e6e4 100644 --- a/src/atom_vec.h +++ b/src/atom_vec.h @@ -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 &); 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 &, int) { return 0; } - virtual int data_vel_hybrid(int, char **) { return 0; } + virtual int data_vel_hybrid(int, const std::vector &, 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; }