diff --git a/src/compute.cpp b/src/compute.cpp index dae80ed66e..1ea1767d92 100644 --- a/src/compute.cpp +++ b/src/compute.cpp @@ -68,6 +68,7 @@ Compute::Compute(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) scalar_flag = vector_flag = array_flag = 0; peratom_flag = local_flag = 0; + size_vector_variable = size_array_rows_variable = 0; tempflag = pressflag = peflag = 0; pressatomflag = peatomflag = 0; diff --git a/src/compute.h b/src/compute.h index 0f8d1c8459..325a868f63 100644 --- a/src/compute.h +++ b/src/compute.h @@ -39,6 +39,8 @@ class Compute : protected Pointers { int size_vector; // length of global vector int size_array_rows; // rows in global array int size_array_cols; // columns in global array + int size_vector_variable; // 1 if vec length is unknown in advance + int size_array_rows_variable; // 1 if array rows is unknown in advance int peratom_flag; // 0/1 if compute_peratom() function exists int size_peratom_cols; // 0 = vector, N = columns in peratom array diff --git a/src/domain.cpp b/src/domain.cpp index 7df81f7e61..005678c952 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -471,7 +471,7 @@ void Domain::reset_box() MAX is important since coord - prd < lo can happen when coord = hi if fix deform, remap velocity of fix group atoms by box edge velocities for triclinic, atoms must be in lamda coords (0-1) before pbc is called - image = 10 bits for each dimension + image = 10 or 20 bits for each dimension depending on sizeof(imageint) increment/decrement in wrap-around fashion ------------------------------------------------------------------------- */ diff --git a/src/fix.cpp b/src/fix.cpp index 657d69a918..332e3c8aea 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -69,7 +69,7 @@ Fix::Fix(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) scalar_flag = vector_flag = array_flag = 0; peratom_flag = local_flag = 0; - size_array_rows_variable = 0; + size_vector_variable = size_array_rows_variable = 0; comm_forward = comm_reverse = comm_border = 0; restart_reset = 0; diff --git a/src/fix.h b/src/fix.h index 7adb3a9b4b..b762f99029 100644 --- a/src/fix.h +++ b/src/fix.h @@ -57,7 +57,8 @@ class Fix : protected Pointers { int size_vector; // length of global vector int size_array_rows; // rows in global array int size_array_cols; // columns in global array - int size_array_rows_variable; // 1 if row count is unknown in advance + int size_vector_variable; // 1 if vec length is unknown in advance + int size_array_rows_variable; // 1 if array rows is unknown in advance int global_freq; // frequency s/v data is available at int peratom_flag; // 0/1 if per-atom data is stored diff --git a/src/thermo.cpp b/src/thermo.cpp index b120642cf1..642453fe80 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -860,14 +860,17 @@ void Thermo::parse_fields(char *str) if (argindex1[nfield] > 0 && argindex2[nfield] == 0) { if (modify->compute[n]->vector_flag == 0) error->all(FLERR,"Thermo compute does not compute vector"); - if (argindex1[nfield] > modify->compute[n]->size_vector) + if (argindex1[nfield] > modify->compute[n]->size_vector && + modify->compute[n]->size_vector_variable == 0) error->all(FLERR,"Thermo compute vector is accessed out-of-range"); } if (argindex1[nfield] > 0 && argindex2[nfield] > 0) { if (modify->compute[n]->array_flag == 0) error->all(FLERR,"Thermo compute does not compute array"); - if (argindex1[nfield] > modify->compute[n]->size_array_rows || - argindex2[nfield] > modify->compute[n]->size_array_cols) + if (argindex1[nfield] > modify->compute[n]->size_array_rows && + modify->compute[n]->size_array_rows_variable == 0) + error->all(FLERR,"Thermo compute array is accessed out-of-range"); + if (argindex2[nfield] > modify->compute[n]->size_array_cols) error->all(FLERR,"Thermo compute array is accessed out-of-range"); } @@ -887,16 +890,16 @@ void Thermo::parse_fields(char *str) if (argindex1[nfield] > 0 && argindex2[nfield] == 0) { if (modify->fix[n]->vector_flag == 0) error->all(FLERR,"Thermo fix does not compute vector"); - if (argindex1[nfield] > modify->fix[n]->size_vector) + if (argindex1[nfield] > modify->fix[n]->size_vector && + modify->fix[n]->size_vector_variable == 0) error->all(FLERR,"Thermo fix vector is accessed out-of-range"); } if (argindex1[nfield] > 0 && argindex2[nfield] > 0) { if (modify->fix[n]->array_flag == 0) error->all(FLERR,"Thermo fix does not compute array"); - if (argindex1[nfield] > modify->fix[n]->size_array_rows) { - if (modify->fix[n]->size_array_rows_variable == 0) - error->all(FLERR,"Thermo fix array is accessed out-of-range"); - } + if (argindex1[nfield] > modify->fix[n]->size_array_rows && + modify->fix[n]->size_array_rows_variable == 0) + error->all(FLERR,"Thermo fix array is accessed out-of-range"); if (argindex2[nfield] > modify->fix[n]->size_array_cols) error->all(FLERR,"Thermo fix array is accessed out-of-range"); } @@ -1422,18 +1425,24 @@ void Thermo::compute_compute() int m = field2index[ifield]; Compute *compute = computes[m]; + // check for out-of-range access if vector/array is variable length + if (compute_which[m] == SCALAR) { dvalue = compute->scalar; if (normflag && compute->extscalar) dvalue /= natoms; } else if (compute_which[m] == VECTOR) { - dvalue = compute->vector[argindex1[ifield]-1]; + if (compute->size_vector_variable && argindex1[ifield] > + compute->size_vector) dvalue = 0.0; + else dvalue = compute->vector[argindex1[ifield]-1]; if (normflag) { if (compute->extvector == 0) return; else if (compute->extvector == 1) dvalue /= natoms; else if (compute->extlist[argindex1[ifield]-1]) dvalue /= natoms; } } else { - dvalue = compute->array[argindex1[ifield]-1][argindex2[ifield]-1]; + if (compute->size_array_rows_variable && argindex1[ifield] > + compute->size_array_rows) dvalue = 0.0; + else dvalue = compute->array[argindex1[ifield]-1][argindex2[ifield]-1]; if (normflag && compute->extarray) dvalue /= natoms; } } diff --git a/src/variable.cpp b/src/variable.cpp index 5642ebf852..cf07114ad0 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -1081,7 +1081,8 @@ double Variable::evaluate(char *str, Tree **tree) } else if (nbracket == 1 && compute->vector_flag) { - if (index1 > compute->size_vector) + if (index1 > compute->size_vector && + compute->size_vector_variable == 0) error->all(FLERR,"Variable formula compute vector " "is accessed out-of-range"); if (update->whichflag == 0) { @@ -1093,7 +1094,9 @@ double Variable::evaluate(char *str, Tree **tree) compute->invoked_flag |= INVOKED_VECTOR; } - value1 = compute->vector[index1-1]; + if (compute->size_vector_variable && + index1 > compute->size_vector) value1 = 0.0; + else value1 = compute->vector[index1-1]; if (tree) { Tree *newtree = new Tree(); newtree->type = VALUE; @@ -1107,7 +1110,8 @@ double Variable::evaluate(char *str, Tree **tree) } else if (nbracket == 2 && compute->array_flag) { - if (index1 > compute->size_array_rows) + if (index1 > compute->size_array_rows && + compute->size_array_rows_variable == 0) error->all(FLERR,"Variable formula compute array " "is accessed out-of-range"); if (index2 > compute->size_array_cols) @@ -1122,7 +1126,9 @@ double Variable::evaluate(char *str, Tree **tree) compute->invoked_flag |= INVOKED_ARRAY; } - value1 = compute->array[index1-1][index2-1]; + if (compute->size_array_rows_variable && + index1 > compute->size_array_rows) value1 = 0.0; + else value1 = compute->array[index1-1][index2-1]; if (tree) { Tree *newtree = new Tree(); newtree->type = VALUE; @@ -1295,12 +1301,13 @@ double Variable::evaluate(char *str, Tree **tree) } else if (nbracket == 1 && fix->vector_flag) { - if (index1 > fix->size_vector) - error->all(FLERR, - "Variable formula fix vector is accessed out-of-range"); + if (index1 > fix->size_vector && + fix->size_vector_variable == 0) + error->all(FLERR,"Variable formula fix vector is " + "accessed out-of-range"); if (update->whichflag > 0 && update->ntimestep % fix->global_freq) error->all(FLERR,"Fix in variable not computed at compatible time"); - + value1 = fix->compute_vector(index1-1); if (tree) { Tree *newtree = new Tree(); @@ -1315,11 +1322,10 @@ double Variable::evaluate(char *str, Tree **tree) } else if (nbracket == 2 && fix->array_flag) { - if (index1 > fix->size_array_rows) { - if (fix->size_array_rows_variable == 0) - error->all(FLERR, - "Variable formula fix array is accessed out-of-range"); - } + if (index1 > fix->size_array_rows && + fix->size_array_rows_variable == 0) + error->all(FLERR, + "Variable formula fix array is accessed out-of-range"); if (index2 > fix->size_array_cols) error->all(FLERR, "Variable formula fix array is accessed out-of-range");