consolidate per-atom property fixes into one

This commit is contained in:
jrgissing
2018-02-21 23:20:17 -07:00
parent 38ce56f252
commit a8eb3ff77f
2 changed files with 90 additions and 139 deletions

View File

@ -63,8 +63,6 @@ Fix(lmp, narg, arg)
{ {
fix1 = NULL; fix1 = NULL;
fix2 = NULL; fix2 = NULL;
fix3 = NULL;
fix4 = NULL;
if (narg < 8) error->all(FLERR,"Illegal fix bond/react command 0.0"); if (narg < 8) error->all(FLERR,"Illegal fix bond/react command 0.0");
@ -284,9 +282,6 @@ Fix(lmp, narg, arg)
id_fix1 = NULL; id_fix1 = NULL;
id_fix2 = NULL; id_fix2 = NULL;
id_fix3 = NULL;
id_fix4 = NULL;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -354,12 +349,6 @@ FixBondReact::~FixBondReact()
if (id_fix2 == NULL && modify->nfix) modify->delete_fix(id_fix2); if (id_fix2 == NULL && modify->nfix) modify->delete_fix(id_fix2);
delete [] id_fix2; delete [] id_fix2;
if (id_fix3 == NULL && modify->nfix) modify->delete_fix(id_fix3);
delete [] id_fix3;
if (id_fix4 == NULL && modify->nfix) modify->delete_fix(id_fix4);
delete [] id_fix4;
delete [] guess_branch; delete [] guess_branch;
delete [] pioneer_count; delete [] pioneer_count;
@ -385,139 +374,103 @@ it will have the name 'i_limit_tags' and will be intitialized to 0 (not in group
void FixBondReact::post_constructor() void FixBondReact::post_constructor()
{ {
//let's add the limit_tags per-atom property fix //let's add the limit_tags per-atom property fix
//these are recently reacted atoms being relaxed int len = strlen("per_atom_props") + 1;
int len = strlen("limit_tags") + 1; id_fix2 = new char[len];
id_fix2 = new char[len]; strcpy(id_fix2,"per_atom_props");
strcpy(id_fix2,"limit_tags"); //note: this is purposefully same as property 'name'
int ifix = modify->find_fix(id_fix2); int ifix = modify->find_fix(id_fix2);
if (ifix == -1) { if (ifix == -1) {
char **newarg = new char*[6]; char **newarg = new char*[8];
newarg[0] = (char *) "limit_tags"; newarg[0] = (char *) "per_atom_props";
newarg[1] = (char *) "all"; // group ID is ignored newarg[1] = (char *) "all"; // group ID is ignored
newarg[2] = (char *) "property/atom"; newarg[2] = (char *) "property/atom";
newarg[3] = (char *) "i_limit_tags"; newarg[3] = (char *) "i_limit_tags";
newarg[4] = (char *) "ghost"; newarg[4] = (char *) "i_statted_tags";
newarg[5] = (char *) "yes"; newarg[5] = (char *) "i_react_tags";
modify->add_fix(6,newarg); newarg[6] = (char *) "ghost";
fix2 = modify->fix[modify->nfix-1]; newarg[7] = (char *) "yes";
delete [] newarg; modify->add_fix(8,newarg);
} fix2 = modify->fix[modify->nfix-1];
delete [] newarg;
}
// per-atom properties already initialized to zero (not in group) // limit_tags: these are recently reacted atoms being relaxed
// let's do it anyway for clarity // per-atom properties already initialized to zero (not in group)
int flag; // let's do it anyway for clarity
int index = atom->find_custom(id_fix2,flag); int flag;
int *i_limit_tags = atom->ivector[index]; int index = atom->find_custom("limit_tags",flag); //here's where error would happen
int *i_limit_tags = atom->ivector[index];
for (int i = 0; i < atom->nlocal; i++) for (int i = 0; i < atom->nlocal; i++)
i_limit_tags[i] = 0; i_limit_tags[i] = 0;
// create master_group if not already existing // create master_group if not already existing
if (group->find(master_group) == -1) { if (group->find(master_group) == -1) {
group->find_or_create(master_group); group->find_or_create(master_group);
char **newarg;
newarg = new char*[5];
newarg[0] = master_group;
newarg[1] = (char *) "dynamic";
newarg[2] = (char *) "all";
newarg[3] = (char *) "property";
newarg[4] = (char *) "limit_tags";
group->assign(5,newarg);
delete [] newarg;
}
// on to statted_tags (system-wide thermostat)
// intialize per-atom statted_flags to 1
index = atom->find_custom("statted_tags",flag);
int *i_statted_tags = atom->ivector[index];
for (int i = 0; i < atom->nlocal; i++)
i_statted_tags[i] = 1;
if (stabilization_flag == 1) {
// create exclude_group if not already existing
if (group->find(exclude_group) == -1) {
group->find_or_create(exclude_group);
char **newarg; char **newarg;
newarg = new char*[5]; newarg = new char*[5];
newarg[0] = master_group; newarg[0] = exclude_group;
newarg[1] = (char *) "dynamic"; newarg[1] = (char *) "dynamic";
newarg[2] = (char *) "all"; newarg[2] = (char *) "all";
newarg[3] = (char *) "property"; newarg[3] = (char *) "property";
newarg[4] = (char *) "limit_tags"; newarg[4] = (char *) "statted_tags";
group->assign(5,newarg); group->assign(5,newarg);
delete [] newarg; delete [] newarg;
} }
//let's add the statted_tags per-atom property fix // let's create a new nve/limit fix to limit newly reacted atoms
//this are atoms subjec to the system-wide thermostat len = strlen("bond_react_MASTER_nve_limit") + 1;
len = strlen("statted_tags") + 1; id_fix1 = new char[len];
id_fix3 = new char[len]; strcpy(id_fix1,"bond_react_MASTER_nve_limit");
strcpy(id_fix3,"statted_tags"); //note: this is purposefully same as property 'name'
ifix = modify->find_fix(id_fix1);
ifix = modify->find_fix(id_fix3);
if (ifix == -1) { if (ifix == -1) {
char **newarg = new char*[6]; char **newarg = new char*[4];
newarg[0] = (char *) "statted_tags"; newarg[0] = id_fix1;
newarg[1] = (char *) "all"; // group ID is ignored newarg[1] = master_group;
newarg[2] = (char *) "property/atom"; newarg[2] = (char *) "nve/limit";
newarg[3] = (char *) "i_statted_tags"; newarg[3] = nve_limit_xmax;
newarg[4] = (char *) "ghost"; modify->add_fix(4,newarg);
newarg[5] = (char *) "yes"; fix1 = modify->fix[modify->nfix-1];
modify->add_fix(6,newarg);
fix3 = modify->fix[modify->nfix-1];
delete [] newarg; delete [] newarg;
} }
//intialize per-atom statted_flags to 1 }
index = atom->find_custom(id_fix3,flag);
int *i_statted_tags = atom->ivector[index];
for (int i = 0; i < atom->nlocal; i++) //react_tags: this per-atom property is the ID of the 'react' argument which recently caused atom to react
i_statted_tags[i] = 1; //so that atoms which wander between processors may be released to global thermostat at the proper time
if (stabilization_flag == 1) { //per-atom values initalized to 0
index = atom->find_custom("react_tags",flag);
int *i_react_tags = atom->ivector[index];
// create exclude_group if not already existing for (int i = 0; i < atom->nlocal; i++)
if (group->find(exclude_group) == -1) { i_react_tags[i] = 0;
group->find_or_create(exclude_group);
char **newarg;
newarg = new char*[5];
newarg[0] = exclude_group;
newarg[1] = (char *) "dynamic";
newarg[2] = (char *) "all";
newarg[3] = (char *) "property";
newarg[4] = (char *) "statted_tags";
group->assign(5,newarg);
delete [] newarg;
}
// let's create a new nve/limit fix to limit newly reacted atoms
len = strlen("bond_react_MASTER_nve_limit") + 1;
id_fix1 = new char[len];
strcpy(id_fix1,"bond_react_MASTER_nve_limit");
ifix = modify->find_fix(id_fix1);
if (ifix == -1) {
char **newarg = new char*[4];
newarg[0] = id_fix1;
newarg[1] = master_group;
newarg[2] = (char *) "nve/limit";
newarg[3] = nve_limit_xmax;
modify->add_fix(4,newarg);
fix1 = modify->fix[modify->nfix-1];
delete [] newarg;
}
}
//let's add the react_tags per-atom property fix
//this per-atom property is the ID of the 'react' argument which recently caused atom to react
//so that atoms which wander between processors may be released to global thermostat at the proper time
len = strlen("react_tags") + 1;
id_fix4 = new char[len];
strcpy(id_fix4,"react_tags"); //note: this is purposefully same as property 'name'
ifix = modify->find_fix(id_fix4);
if (ifix == -1) { //ifix
char **newarg = new char*[6];
newarg[0] = (char *) "react_tags";
newarg[1] = (char *) "all"; // group ID is ignored
newarg[2] = (char *) "property/atom";
newarg[3] = (char *) "i_react_tags";
newarg[4] = (char *) "ghost";
newarg[5] = (char *) "yes";
modify->add_fix(6,newarg);
fix4 = modify->fix[modify->nfix-1];
delete [] newarg;
}
//per-atom values initalized to 0
index = atom->find_custom(id_fix4,flag);
int *i_react_tags = atom->ivector[index];
for (int i = 0; i < atom->nlocal; i++)
i_react_tags[i] = 0;
// currently must redefine dynamic groups so they are updated at proper time // currently must redefine dynamic groups so they are updated at proper time
// -> should double check as to why // -> should double check as to why
@ -679,7 +632,7 @@ void FixBondReact::post_integrate()
// per-atom property indicating if in bond/react master group // per-atom property indicating if in bond/react master group
int flag; int flag;
int index1 = atom->find_custom(id_fix2,flag); int index1 = atom->find_custom("limit_tags",flag);
int *i_limit_tags = atom->ivector[index1]; int *i_limit_tags = atom->ivector[index1];
int i,j; int i,j;
@ -1077,7 +1030,7 @@ void FixBondReact::make_a_guess()
// per-atom property indicating if in bond/react master group // per-atom property indicating if in bond/react master group
int flag; int flag;
int index1 = atom->find_custom(id_fix2,flag); int index1 = atom->find_custom("limit_tags",flag);
int *i_limit_tags = atom->ivector[index1]; int *i_limit_tags = atom->ivector[index1];
if (status == GUESSFAIL && avail_guesses == 0) { if (status == GUESSFAIL && avail_guesses == 0) {
@ -1696,13 +1649,13 @@ void FixBondReact::limit_bond(int limit_bond_mode)
// this will be a new per-atom property! // this will be a new per-atom property!
int flag; int flag;
int index1 = atom->find_custom(id_fix2,flag); int index1 = atom->find_custom("limit_tags",flag);
int *i_limit_tags = atom->ivector[index1]; int *i_limit_tags = atom->ivector[index1];
int index2 = atom->find_custom(id_fix3,flag); int index2 = atom->find_custom("statted_tags",flag);
int *i_statted_tags = atom->ivector[index2]; int *i_statted_tags = atom->ivector[index2];
int index3 = atom->find_custom(id_fix4,flag); int index3 = atom->find_custom("react_tags",flag);
int *i_react_tags = atom->ivector[index3]; int *i_react_tags = atom->ivector[index3];
for (int i = 0; i < temp_limit_num; i++) { for (int i = 0; i < temp_limit_num; i++) {
@ -1725,15 +1678,15 @@ void FixBondReact::unlimit_bond()
{ {
//let's now unlimit in terms of i_limit_tags //let's now unlimit in terms of i_limit_tags
//we just run through all nlocal, looking for > limit_duration //we just run through all nlocal, looking for > limit_duration
//then we return i_limit_tag to -1 (which removes from dynamic group) //then we return i_limit_tag to 0 (which removes from dynamic group)
int flag; int flag;
int index1 = atom->find_custom(id_fix2,flag); int index1 = atom->find_custom("limit_tags",flag);
int *i_limit_tags = atom->ivector[index1]; int *i_limit_tags = atom->ivector[index1];
int index2 = atom->find_custom(id_fix3,flag); // statted_tags int index2 = atom->find_custom("statted_tags",flag);
int *i_statted_tags = atom->ivector[index2]; int *i_statted_tags = atom->ivector[index2];
int index3 = atom->find_custom(id_fix4,flag); // statted_tags int index3 = atom->find_custom("react_tags",flag);
int *i_react_tags = atom->ivector[index3]; int *i_react_tags = atom->ivector[index3];
int num2unlimit = 0; int num2unlimit = 0;

View File

@ -75,10 +75,10 @@ class FixBondReact : public Fix {
class Molecule *onemol; // pre-reacted molecule template class Molecule *onemol; // pre-reacted molecule template
class Molecule *twomol; // post-reacted molecule template class Molecule *twomol; // post-reacted molecule template
Fix *fix1; // used to relax reaction sites Fix *fix1; // nve/limit used to relax reaction sites
Fix *fix2; // used to indicate relaxing atoms Fix *fix2; // properties/atom used to indicate 1) indicate relaxing atoms
Fix *fix3; // used to indicate system-wide thermostat // 2) system-wide thermostat
Fix *fix4; // indicates to which 'react' atom belongs // 3) to which 'react' atom belongs
class RanMars **random; class RanMars **random;
class NeighList *list; class NeighList *list;
@ -86,9 +86,7 @@ class FixBondReact : public Fix {
int *limit_duration; // indicates how long to relax int *limit_duration; // indicates how long to relax
char *nve_limit_xmax; // indicates max distance allowed to move when relaxing char *nve_limit_xmax; // indicates max distance allowed to move when relaxing
char *id_fix1; // id of internally created fix nve/limit char *id_fix1; // id of internally created fix nve/limit
char *id_fix2; // id of internally created fix per-atom property (recently reacted) char *id_fix2; // id of internally created fix per-atom properties
char *id_fix3; // id of internally created fix per-atom property (system-wide thermostat)
char *id_fix4; // id of internally created fix per-atom property (ID of 'react' argument)
char *master_group; // group containing relaxing atoms from all fix rxns char *master_group; // group containing relaxing atoms from all fix rxns
char *exclude_group; // group for system-wide thermostat char *exclude_group; // group for system-wide thermostat