diff --git a/doc/src/fix_rigid.rst b/doc/src/fix_rigid.rst index a143817303..3811cc2be1 100644 --- a/doc/src/fix_rigid.rst +++ b/doc/src/fix_rigid.rst @@ -64,7 +64,7 @@ Syntax *single* args = none *molecule* args = none *custom* args = *i_propname* or *v_varname* - i_propname = an integer property defined via fix property/atom + i_propname = a custom integer vector defined via fix property/atom v_varname = an atom-style or atomfile-style variable *group* args = N groupID1 groupID2 ... N = # of groups @@ -287,15 +287,16 @@ includes atoms you want to be part of rigid bodies. Bodystyle *custom* is similar to bodystyle *molecule* except that it is more flexible in using other per-atom properties to define the sets -of atoms that form rigid bodies. An integer vector defined by the -:doc:`fix property/atom ` command can be used. Or an -:doc:`atom-style or atomfile-style variable ` can be used; the -floating-point value produced by the variable is rounded to an -integer. As with bodystyle *molecule*\ , each set of atoms in the fix -groups with the same integer value is treated as a different rigid -body. Since fix property/atom vectors and atom-style variables -produce values for all atoms, you should be careful to use a fix group -that only includes atoms you want to be part of rigid bodies. +of atoms that form rigid bodies. A custom per-atom integer vector +defined by the :doc:`fix property/atom ` command +can be used. Or an :doc:`atom-style or atomfile-style variable +` can be used; the floating-point value produced by the +variable is rounded to an integer. As with bodystyle *molecule*\ , +each set of atoms in the fix groups with the same integer value is +treated as a different rigid body. Since fix property/atom custom +vectors and atom-style variables produce values for all atoms, you +should be careful to use a fix group that only includes atoms you want +to be part of rigid bodies. .. note:: diff --git a/src/RIGID/fix_rigid.cpp b/src/RIGID/fix_rigid.cpp index 0d15f22090..5e6f48e2cb 100644 --- a/src/RIGID/fix_rigid.cpp +++ b/src/RIGID/fix_rigid.cpp @@ -129,14 +129,10 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : // determine whether atom-style variable or atom property is used if (strstr(arg[4],"i_") == arg[4]) { - int is_double=0; - int custom_index = atom->find_custom(arg[4]+2,is_double); - if (custom_index == -1) - error->all(FLERR,"Fix rigid custom requires " - "previously defined property/atom"); - else if (is_double) - error->all(FLERR,"Fix rigid custom requires " - "integer-valued property/atom"); + int flag,cols; + int custom_index = atom->find_custom(arg[4]+2,flag,cols); + if (custom_index < 0 || !flag || cols) + error->all(FLERR,"Fix rigid custom requires custom integer vector"); int minval = INT_MAX; int *value = atom->ivector[custom_index]; for (i = 0; i < nlocal; i++) diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index f12c53bf3a..ff31ce9e2a 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -113,15 +113,10 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : // determine whether atom-style variable or atom property is used if (strstr(arg[4],"i_") == arg[4]) { - int is_double=0; - int custom_index = atom->find_custom(arg[4]+2,is_double); - if (custom_index == -1) - error->all(FLERR,"Fix rigid/small custom requires " - "previously defined property/atom"); - else if (is_double) - error->all(FLERR,"Fix rigid/small custom requires " - "integer-valued property/atom"); - + int flag,cols; + int custom_index = atom->find_custom(arg[4]+2,flag,cols); + if (custom_index < 0 || !flag || cols) + error->all(FLERR,"Fix rigid custom requires custom integer vector"); int minval = INT_MAX; int *value = atom->ivector[custom_index]; for (i = 0; i < nlocal; i++) diff --git a/src/USER-REACTION/fix_bond_react.cpp b/src/USER-REACTION/fix_bond_react.cpp index 29aa476148..38760a8c98 100644 --- a/src/USER-REACTION/fix_bond_react.cpp +++ b/src/USER-REACTION/fix_bond_react.cpp @@ -683,8 +683,8 @@ void FixBondReact::post_constructor() // initialize per-atom statted_flags to 1 // (only if not already initialized by restart) if (fix3->restart_reset != 1) { - int flag; - int index = atom->find_custom("statted_tags",flag); + int flag,cols; + int index = atom->find_custom("statted_tags",flag,cols); int *i_statted_tags = atom->ivector[index]; for (int i = 0; i < atom->nlocal; i++) @@ -715,8 +715,8 @@ void FixBondReact::post_constructor() // initialize per-atom statted_tags to 1 // need to correct for smooth restarts - //int flag; - //int index = atom->find_custom(statted_id,flag); + //int flag,cols; + //int index = atom->find_custom(statted_id,flag,cols); //int *i_statted_tags = atom->ivector[index]; //for (int i = 0; i < atom->nlocal; i++) // i_statted_tags[i] = 1; @@ -1021,8 +1021,8 @@ void FixBondReact::far_partner() firstneigh = list->firstneigh; // per-atom property indicating if in bond/react master group - int flag; - int index1 = atom->find_custom("limit_tags",flag); + int flag,cols; + int index1 = atom->find_custom("limit_tags",flag,cols); int *i_limit_tags = atom->ivector[index1]; int i,j; @@ -1108,8 +1108,8 @@ void FixBondReact::close_partner() int *mask = atom->mask; // per-atom property indicating if in bond/react master group - int flag; - int index1 = atom->find_custom("limit_tags",flag); + int flag,cols; + int index1 = atom->find_custom("limit_tags",flag,cols); int *i_limit_tags = atom->ivector[index1]; // loop over special list @@ -1377,8 +1377,8 @@ void FixBondReact::make_a_guess() int nfirst_neighs = onemol_nxspecial[pion][0]; // per-atom property indicating if in bond/react master group - int flag; - int index1 = atom->find_custom("limit_tags",flag); + int flag,cols; + int index1 = atom->find_custom("limit_tags",flag,cols); int *i_limit_tags = atom->ivector[index1]; if (status == GUESSFAIL && avail_guesses == 0) { @@ -2341,17 +2341,17 @@ void FixBondReact::limit_bond(int limit_bond_mode) // we must keep our own list of limited atoms // this will be a new per-atom property! - int flag; - int index1 = atom->find_custom("limit_tags",flag); + int flag,cols; + int index1 = atom->find_custom("limit_tags",flag,cols); int *i_limit_tags = atom->ivector[index1]; int *i_statted_tags; if (stabilization_flag == 1) { - int index2 = atom->find_custom(statted_id,flag); + int index2 = atom->find_custom(statted_id,flag,cols); i_statted_tags = atom->ivector[index2]; } - int index3 = atom->find_custom("react_tags",flag); + int index3 = atom->find_custom("react_tags",flag,cols); int *i_react_tags = atom->ivector[index3]; for (int i = 0; i < temp_limit_num; i++) { @@ -2374,17 +2374,17 @@ void FixBondReact::unlimit_bond() //let's now unlimit in terms of i_limit_tags //we just run through all nlocal, looking for > limit_duration //then we return i_limit_tag to 0 (which removes from dynamic group) - int flag; - int index1 = atom->find_custom("limit_tags",flag); + int flag,cols; + int index1 = atom->find_custom("limit_tags",flag,cols); int *i_limit_tags = atom->ivector[index1]; int *i_statted_tags; if (stabilization_flag == 1) { - int index2 = atom->find_custom(statted_id,flag); + int index2 = atom->find_custom(statted_id,flag,cols); i_statted_tags = atom->ivector[index2]; } - int index3 = atom->find_custom("react_tags",flag); + int index3 = atom->find_custom("react_tags",flag,cols); int *i_react_tags = atom->ivector[index3]; for (int i = 0; i < atom->nlocal; i++) { diff --git a/src/USER-VTK/dump_vtk.cpp b/src/USER-VTK/dump_vtk.cpp index 7f1443c654..b10a8cec41 100644 --- a/src/USER-VTK/dump_vtk.cpp +++ b/src/USER-VTK/dump_vtk.cpp @@ -237,9 +237,15 @@ void DumpVTK::init_style() int icustom; for (int i = 0; i < ncustom; i++) { - icustom = atom->find_custom(id_custom[i],flag_custom[i]); + int flag,cols; + icustom = atom->find_custom(id_custom[i],flag,cols); if (icustom < 0) - error->all(FLERR,"Could not find custom per-atom property ID"); + error->all(FLERR,"Could not find dump vtk atom property name"); + custom[i] = icustom; + if (!flag && !cols) custom_flag[i] = IVEC; + else if (flag && !cols) custom_flag[i] = DVEC; + else if (!flag && cols) custom_flag[i] = IARRAY; + else if (flag && cols) custom_flag[i] = DARRAY; } // set index and check validity of region @@ -1511,6 +1517,7 @@ int DumpVTK::parse_fields(int narg, char **arg) name[Z] = "z"; // customize by adding to if statement + int i; for (int iarg = 5; iarg < narg; iarg++) { i = iarg-5; @@ -1825,49 +1832,67 @@ int DumpVTK::parse_fields(int narg, char **arg) name[ATTRIBUTES+i] = suffix; delete [] suffix; - // custom per-atom floating point value = d_ID + // custom per-atom integer value = i_ID or d_ID + + } else if (strncmp(arg[iarg],"i_",2) == 0 || + strncmp(arg[iarg],"d_",2) == 0) { + int which = 0; + if (arg[iarg][0] == 'd') which = 1; - } else if (strncmp(arg[iarg],"d_",2) == 0) { pack_choice[ATTRIBUTES+i] = &DumpVTK::pack_custom; - vtype[ATTRIBUTES+i] = Dump::DOUBLE; + if (!which) vtype[ATTRIBUTES+i] = Dump::INT; + else vtype[ATTRIBUTES+i] = Dump::DOUBLE; int n = strlen(arg[iarg]); char *suffix = new char[n]; strcpy(suffix,&arg[iarg][2]); argindex[ATTRIBUTES+i] = 0; - int tmp = -1; - n = atom->find_custom(suffix,tmp); - if (n < 0) - error->all(FLERR,"Could not find custom per-atom property ID"); + int flag,cols; + n = atom->find_custom(suffix,flag,cols); + if ((!which && (n < 0 || flag || cols)) || + (which && (n < 0 || !flag || cols))) + error->all(FLERR,"Dump vtk per-atom custom vector does not exist"); - if (tmp != 1) - error->all(FLERR,"Custom per-atom property ID is not floating point"); - - field2index[ATTRIBUTES+i] = add_custom(suffix,1); + field2index[ATTRIBUTES+i] = add_custom(suffix); name[ATTRIBUTES+i] = suffix; delete [] suffix; - // custom per-atom integer value = i_ID + // custom per-atom array = i2_ID or d2_ID, must include bracketed index + + } else if (strncmp(arg[iarg],"i2_",3) == 0 || + strncmp(arg[iarg],"d2_",3) == 0) { + int which = 0; + if (arg[iarg][0] == 'd') which = 1; - } else if (strncmp(arg[iarg],"i_",2) == 0) { pack_choice[ATTRIBUTES+i] = &DumpVTK::pack_custom; - vtype[ATTRIBUTES+i] = Dump::INT; + if (!which) vtype[ATTRIBUTES+i] = Dump::INT; + else vtype[ATTRIBUTES+i] = Dump::DOUBLE; int n = strlen(arg[iarg]); char *suffix = new char[n]; - strcpy(suffix,&arg[iarg][2]); - argindex[ATTRIBUTES+i] = 0; + strcpy(suffix,&arg[iarg][3]); - int tmp = -1; - n = atom->find_custom(suffix,tmp); - if (n < 0) - error->all(FLERR,"Could not find custom per-atom property ID"); + char *ptr = strchr(suffix,'['); + if (ptr) { + if (suffix[strlen(suffix)-1] != ']') + error->all(FLERR,"Invalid attribute in dump custom command"); + suffix[strlen(suffix)-1] = '\0'; + argindex[ATTRIBUTES+i] = utils::inumeric(FLERR,ptr+1,true,lmp); + *ptr = '\0'; + } else error->all(FLERR,"Dump custom per-atom custom array is not indexed"); - if (tmp != 0) - error->all(FLERR,"Custom per-atom property ID is not integer"); + int flag,cols; + n = atom->find_custom(suffix,flag,cols); + + if ((!which && (n < 0 || flag || !cols)) || + (which && (n < 0 || !flag || !cols))) + error->all(FLERR,"Dump vtk per-atom custom array does not exist"); + if (argindex[i] <= 0 || argindex[i] > cols) + error->all(FLERR, + "Dump vtk per-atom custom array is accessed out-of-range"); - field2index[ATTRIBUTES+i] = add_custom(suffix,0); + field2index[i] = add_custom(suffix); name[ATTRIBUTES+i] = suffix; delete [] suffix; @@ -2006,27 +2031,28 @@ int DumpVTK::add_variable(char *id) /* ---------------------------------------------------------------------- add custom atom property to list used by dump - return index of where this property is in list + return index of where this property is in Atom class custom lists if already in list, do not add, just return index, else add to list ------------------------------------------------------------------------- */ -int DumpVTK::add_custom(char *id, int flag) +int DumpVTK::add_custom(char *id) { int icustom; for (icustom = 0; icustom < ncustom; icustom++) - if ((strcmp(id,id_custom[icustom]) == 0) - && (flag == flag_custom[icustom])) break; + if (strcmp(id,id_custom[icustom]) == 0) break; if (icustom < ncustom) return icustom; id_custom = (char **) memory->srealloc(id_custom,(ncustom+1)*sizeof(char *),"dump:id_custom"); - flag_custom = (int *) - memory->srealloc(flag_custom,(ncustom+1)*sizeof(int),"dump:flag_custom"); + + delete [] custom; + custom = new int[ncustom+1]; + delete [] custom_flag; + custom_flag = new int[ncustom+1]; int n = strlen(id) + 1; id_custom[ncustom] = new char[n]; strcpy(id_custom[ncustom],id); - flag_custom[ncustom] = flag; ncustom++; return ncustom-1;