Don't store group if initial assignment failed
This commit is contained in:
@ -30,6 +30,7 @@
|
|||||||
#include "region.h"
|
#include "region.h"
|
||||||
#include "tokenizer.h"
|
#include "tokenizer.h"
|
||||||
#include "variable.h"
|
#include "variable.h"
|
||||||
|
#include "exceptions.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -152,12 +153,14 @@ void Group::assign(int narg, char **arg)
|
|||||||
// add a new group if igroup = -1
|
// add a new group if igroup = -1
|
||||||
|
|
||||||
int igroup = find(arg[0]);
|
int igroup = find(arg[0]);
|
||||||
|
bool created = false;
|
||||||
|
|
||||||
if (igroup == -1) {
|
if (igroup == -1) {
|
||||||
if (ngroup == MAX_GROUP) error->all(FLERR,"Too many groups");
|
if (ngroup == MAX_GROUP) error->all(FLERR,"Too many groups");
|
||||||
igroup = find_unused();
|
igroup = find_unused();
|
||||||
names[igroup] = utils::strdup(arg[0]);
|
names[igroup] = utils::strdup(arg[0]);
|
||||||
ngroup++;
|
ngroup++;
|
||||||
|
created = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
double **x = atom->x;
|
double **x = atom->x;
|
||||||
@ -165,6 +168,7 @@ void Group::assign(int narg, char **arg)
|
|||||||
int nlocal = atom->nlocal;
|
int nlocal = atom->nlocal;
|
||||||
int bit = bitmask[igroup];
|
int bit = bitmask[igroup];
|
||||||
|
|
||||||
|
try {
|
||||||
// style = region
|
// style = region
|
||||||
// add to group if atom is in region
|
// add to group if atom is in region
|
||||||
|
|
||||||
@ -509,6 +513,16 @@ void Group::assign(int narg, char **arg)
|
|||||||
|
|
||||||
} else error->all(FLERR,"Illegal group command");
|
} else error->all(FLERR,"Illegal group command");
|
||||||
|
|
||||||
|
} catch (LAMMPSException & e) {
|
||||||
|
// undo created group in case of an error
|
||||||
|
if (created) {
|
||||||
|
delete [] names[igroup];
|
||||||
|
names[igroup] = nullptr;
|
||||||
|
ngroup--;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
// print stats for changed group
|
// print stats for changed group
|
||||||
|
|
||||||
int n;
|
int n;
|
||||||
|
|||||||
@ -297,7 +297,7 @@ TEST_F(GroupTest, Dynamic)
|
|||||||
command("group grow delete");
|
command("group grow delete");
|
||||||
command("variable ramp equal step");
|
command("variable ramp equal step");
|
||||||
END_HIDE_OUTPUT();
|
END_HIDE_OUTPUT();
|
||||||
ASSERT_EQ(group->ngroup, 4);
|
ASSERT_EQ(group->ngroup, 3);
|
||||||
|
|
||||||
TEST_FAILURE(".*ERROR: Group dynamic cannot reference itself.*",
|
TEST_FAILURE(".*ERROR: Group dynamic cannot reference itself.*",
|
||||||
command("group half dynamic half region top"););
|
command("group half dynamic half region top"););
|
||||||
|
|||||||
Reference in New Issue
Block a user