Merge branch 'fix-property-array' of github.com:lammps/lammps into fix-property-array

This commit is contained in:
Steve Plimpton
2021-08-19 09:00:51 -06:00
4 changed files with 45 additions and 48 deletions

View File

@ -1532,15 +1532,12 @@ int DumpCustom::parse_fields(int narg, char **arg)
error->all(FLERR,"Could not find custom per-atom property ID: {}", name); error->all(FLERR,"Could not find custom per-atom property ID: {}", name);
if (argindex[iarg] == 0) { if (argindex[iarg] == 0) {
if (!flag || cols) if (!flag || cols)
error->all(FLERR, error->all(FLERR,"Property double vector for dump custom does not exist");
"Property double vector for dump custom does not exist");
} else { } else {
if (!flag || !cols) if (!flag || !cols)
error->all(FLERR, error->all(FLERR,"Property double array for dump custom does not exist");
"Property double array for dump custom does not exist");
if (argindex[iarg] > atom->dcols[n]) if (argindex[iarg] > atom->dcols[n])
error->all(FLERR, error->all(FLERR,"Dump custom property array is accessed out-of-range");
"Dump custom property array is accessed out-of-range");
} }
field2index[iarg] = add_custom(name,1); field2index[iarg] = add_custom(name,1);

View File

@ -66,8 +66,7 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) :
iarg++; iarg++;
} else if (strcmp(arg[iarg],"q") == 0) { } else if (strcmp(arg[iarg],"q") == 0) {
if (atom->q_flag) if (atom->q_flag)
error->all(FLERR,"Fix property/atom q when atom_style " error->all(FLERR,"Fix property/atom q when atom_style already has charge attribute");
"already has charge attribute");
if (q_flag) if (q_flag)
error->all(FLERR,"Fix property/atom cannot specify q twice"); error->all(FLERR,"Fix property/atom cannot specify q twice");
style[nvalue] = CHARGE; style[nvalue] = CHARGE;
@ -78,8 +77,7 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) :
iarg++; iarg++;
} else if (strcmp(arg[iarg],"rmass") == 0) { } else if (strcmp(arg[iarg],"rmass") == 0) {
if (atom->rmass_flag) if (atom->rmass_flag)
error->all(FLERR,"Fix property/atom rmass when atom_style " error->all(FLERR,"Fix property/atom rmass when atom_style already has rmass attribute");
"already has rmass attribute");
if (rmass_flag) if (rmass_flag)
error->all(FLERR,"Fix property/atom cannot specify rmass twice"); error->all(FLERR,"Fix property/atom cannot specify rmass twice");
style[nvalue] = RMASS; style[nvalue] = RMASS;
@ -93,11 +91,13 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) :
} else if (utils::strmatch(arg[iarg],"^i_")) { } else if (utils::strmatch(arg[iarg],"^i_")) {
style[nvalue] = IVEC; style[nvalue] = IVEC;
int flag,cols; int flag,ncols;
index[nvalue] = atom->find_custom(&arg[iarg][2],flag,cols); index[nvalue] = atom->find_custom(&arg[iarg][2],flag,ncols);
if (index[nvalue] >= 0) if (index[nvalue] >= 0)
error->all(FLERR,"Fix property/atom vector name already exists"); error->all(FLERR,"Fix property/atom vector name already exists");
index[nvalue] = atom->add_custom(&arg[iarg][2],0,0); index[nvalue] = atom->add_custom(&arg[iarg][2],0,0);
cols[nvalue] = 0;
values_peratom++;
nvalue++; nvalue++;
iarg++; iarg++;
@ -108,6 +108,8 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) :
if (index[nvalue] >= 0) if (index[nvalue] >= 0)
error->all(FLERR,"Fix property/atom vector name already exists"); error->all(FLERR,"Fix property/atom vector name already exists");
index[nvalue] = atom->add_custom(&arg[iarg][2],1,0); index[nvalue] = atom->add_custom(&arg[iarg][2],1,0);
cols[nvalue] = 0;
values_peratom++;
nvalue++; nvalue++;
iarg++; iarg++;
@ -252,8 +254,7 @@ void FixPropertyAtom::init()
id_offset is applied to first atomID field if multiple data files are read id_offset is applied to first atomID field if multiple data files are read
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, tagint id_offset)
tagint id_offset)
{ {
int j,k,m,ncol; int j,k,m,ncol;
tagint itag; tagint itag;
@ -278,14 +279,13 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf,
try { try {
ValueTokenizer values(buf); ValueTokenizer values(buf);
if ((int)values.count() != nvalue+1) if ((int)values.count() != values_peratom+1)
error->all(FLERR,"Incorrect format in {} section " error->all(FLERR,"Incorrect format in {} section of data file: {}"
"of data file: {}",keyword,buf); " expected {} and got {}",keyword,buf,values_peratom+1,values.count());
itag = values.next_tagint() + id_offset; itag = values.next_tagint() + id_offset;
if (itag <= 0 || itag > map_tag_max) if (itag <= 0 || itag > map_tag_max)
error->all(FLERR,"Invalid atom ID {} in {} section of " error->all(FLERR,"Invalid atom ID {} in {} section of data file",itag, keyword);
"data file",itag, keyword);
// assign words in line to per-atom vectors // assign words in line to per-atom vectors
@ -301,7 +301,6 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf,
atom->ivector[index[j]][m] = values.next_int(); atom->ivector[index[j]][m] = values.next_int();
} else if (style[j] == DVEC) { } else if (style[j] == DVEC) {
atom->dvector[index[j]][m] = values.next_double(); atom->dvector[index[j]][m] = values.next_double();
// NOTE: Axel please check these lines of array code
} else if (style[j] == IARRAY) { } else if (style[j] == IARRAY) {
ncol = cols[j]; ncol = cols[j];
for (k = 0; k < ncol; k++) for (k = 0; k < ncol; k++)
@ -314,8 +313,7 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf,
} }
} }
} catch (TokenizerException &e) { } catch (TokenizerException &e) {
error->all(FLERR,"Invalid format in {} section of data " error->all(FLERR,"Invalid format in {} section of data file '{}': {}",keyword, buf,e.what());
"file '{}': {}",keyword, buf,e.what());
} }
buf = next + 1; buf = next + 1;
} }

View File

@ -627,36 +627,32 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
} }
} }
} }
}
// expansion will take place // expansion will take place
if (expandflag) { if (expandflag) {
// expand wild card string to nlo/nhi numbers // expand wild card string to nlo/nhi numbers
utils::bounds(file, line, wc, 1, nmax, nlo, nhi, lmp->error); utils::bounds(file, line, wc, 1, nmax, nlo, nhi, lmp->error);
if (newarg + nhi - nlo + 1 > maxarg) { if (newarg + nhi - nlo + 1 > maxarg) {
maxarg += nhi - nlo + 1; maxarg += nhi - nlo + 1;
earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg"); earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg");
} }
for (int index = nlo; index <= nhi; index++) { for (int index = nlo; index <= nhi; index++) {
// assemble and duplicate expanded string earg[newarg] = utils::strdup(fmt::format("{}2_{}[{}]{}", word[0], id, index, tail));
if (word[1] == '2')
earg[newarg] = utils::strdup(fmt::format("{}2_{}[{}]{}", word[0], id, index, tail));
else
earg[newarg] = utils::strdup(fmt::format("{}_{}[{}]{}", word[0], id, index, tail));
newarg++;
}
} else {
// no expansion: duplicate original string
if (newarg == maxarg) {
maxarg++;
earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg");
}
earg[newarg] = utils::strdup(word);
newarg++; newarg++;
} }
} else {
// no expansion: duplicate original string
if (newarg == maxarg) {
maxarg++;
earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg");
}
earg[newarg] = utils::strdup(word);
newarg++;
} }
} }

View File

@ -4648,7 +4648,8 @@ TEST_F(AtomStyleTest, property_atom)
command("pair_style zero 4.0"); command("pair_style zero 4.0");
command("units real"); command("units real");
command("atom_modify map array"); command("atom_modify map array");
command("fix props all property/atom i_one d_two mol d_three q rmass ghost yes"); command("fix props all property/atom i_one d_two mol d_three q rmass "
"i2_four 2 d2_five 3 ghost yes");
command("read_data test_atom_styles.data fix props NULL Properties"); command("read_data test_atom_styles.data fix props NULL Properties");
command("pair_coeff * *"); command("pair_coeff * *");
END_HIDE_OUTPUT(); END_HIDE_OUTPUT();
@ -4737,7 +4738,8 @@ TEST_F(AtomStyleTest, property_atom)
command("clear"); command("clear");
ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic"));
command("read_restart test_atom_styles.restart"); command("read_restart test_atom_styles.restart");
command("fix props all property/atom i_one d_two mol d_three q rmass ghost yes"); command("fix props all property/atom i_one d_two mol d_three q rmass "
"i2_four 2 d2_five 3 ghost yes");
END_HIDE_OUTPUT(); END_HIDE_OUTPUT();
expected.natoms = 2; expected.natoms = 2;
expected.nlocal = 2; expected.nlocal = 2;
@ -4749,7 +4751,11 @@ TEST_F(AtomStyleTest, property_atom)
expected.has_mass_setflag = true; expected.has_mass_setflag = true;
expected.has_sametag = true; expected.has_sametag = true;
expected.has_extra = true; expected.has_extra = true;
expected.nextra_store = 7; expected.has_ivname = true;
expected.has_dvname = true;
expected.has_ianame = true;
expected.has_daname = true;
expected.nextra_store = 12;
ASSERT_ATOM_STATE_EQ(lmp->atom, expected); ASSERT_ATOM_STATE_EQ(lmp->atom, expected);
ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_NE(lmp->atom->avec, nullptr);