properly initialize Atom class member and avoid side effects during write data

This commit is contained in:
Axel Kohlmeyer
2022-09-11 22:11:22 -04:00
parent 34714dba29
commit ed0af32fce
3 changed files with 6 additions and 1 deletions

View File

@ -227,6 +227,7 @@ Atom::Atom(LAMMPS *_lmp) : Pointers(_lmp)
// type labels // type labels
lmap = nullptr; lmap = nullptr;
types_style = NUMERIC;
// custom atom arrays // custom atom arrays

View File

@ -73,7 +73,8 @@ void WriteData::command(int narg, char **arg)
coeffflag = 1; coeffflag = 1;
fixflag = 1; fixflag = 1;
lmapflag = 1; lmapflag = 1;
atom->types_style = Atom::NUMERIC; // store current (default) setting since we may change it.
int types_style = atom->types_style;
int noinit = 0; int noinit = 0;
int iarg = 1; int iarg = 1;
@ -134,6 +135,8 @@ void WriteData::command(int narg, char **arg)
} }
write(file); write(file);
// restore saved setting
atom->types_style = types_style;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------

View File

@ -57,6 +57,7 @@ TEST_F(LabelMapTest, Atoms)
EXPECT_EQ(atom->natoms, 0); EXPECT_EQ(atom->natoms, 0);
EXPECT_EQ(domain->box_exist, 0); EXPECT_EQ(domain->box_exist, 0);
EXPECT_EQ(atom->labelmapflag, 0); EXPECT_EQ(atom->labelmapflag, 0);
EXPECT_EQ(atom->types_style, Atom::NUMERIC);
ASSERT_EQ(atom->lmap, nullptr); ASSERT_EQ(atom->lmap, nullptr);
TEST_FAILURE(".*ERROR: Labelmap command before simulation box is.*", TEST_FAILURE(".*ERROR: Labelmap command before simulation box is.*",
command("labelmap atom 3 C1");); command("labelmap atom 3 C1"););