From 1b7bc36505f66cfa2ccf257febd5b240b31310d8 Mon Sep 17 00:00:00 2001 From: Tim Bernhard Date: Sun, 10 Mar 2024 12:56:33 +0100 Subject: [PATCH] Fix variables compatibility with chunk arrays When using variables with chunk computes that produce arrays (such as `compute chunk/atom`) the compute will not have set `size_array_rows` to the appropriate value before it has ever been called and will therefore incorrectly have thrown the error "Variable formula compute array is zero length". --- src/variable.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/variable.cpp b/src/variable.cpp index 8124d9c4a1..2bde0e5adb 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -1657,10 +1657,6 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) if (!compute->array_flag) print_var_error(FLERR,"Mismatched compute in variable formula",ivar); - if (compute->size_array_rows == 0) - print_var_error(FLERR,"Variable formula compute array is zero length",ivar); - if (index1 > compute->size_array_cols) - print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); if (!compute->is_initialized()) print_var_error(FLERR,"Variable formula compute cannot be invoked before " "initialization by a run",ivar); @@ -1668,6 +1664,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) compute->compute_array(); compute->invoked_flag |= Compute::INVOKED_ARRAY; } + if (compute->size_array_rows == 0) + print_var_error(FLERR,"Variable formula compute array is zero length",ivar); + if (index1 > compute->size_array_cols) + print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); auto newtree = new Tree(); newtree->type = VECTORARRAY;