LIGGGHTS 2.3.6 - fix move/mesh linear/variable possible bug

Submitted by wladek on Wed, 08/21/2013 - 17:22

I tried to make one of my mesh accelerating with time, so after digging in documentation I found this fix move/mesh linear/variable, however whatever variable I tried to put I constantly had an error:

"Variable name 1 for fix move/mesh linear/variable does not exist"

an error comes from the file "mesh_mover.cpp" line 112 and it is natural consequence if something goes wrong in lines above.

Correct me if I am wrong but lines 97 to 110 in this file are not quite correct and as it is so, there always something is going wrong.

n = strlen(&var1[2]) + 1;
var1str_ = new char[n];
strcpy(var1str_,&var1[2]);
myvar1_ = input->variable->find(var1str_);

n = strlen(&var1[2]) + 1;
var2str_ = new char[n];
strcpy(var2str_,&var2[2]);
myvar2_ = input->variable->find(var2str_);

n = strlen(&var1[2]) + 1;
var3str_ = new char[n];
strcpy(var3str_,&var3[2]);
myvar3_ = input->variable->find(var3str_);

in first line of code above instead of getting total length of whole "var1" we obtaining length of its 3rd element.
also line 3 above, would copy only one char from "var1" to "var1str_" instead of the whole array, and in consequence "find" in 4th line are not going to find the variable user defined in the script file. Well, unless by chance 3rd element of this variable is the same as name of other variable declared in the script, but this will by confusing and hard to track.

Since the remaining two blocks pasted here looks like copy-pase from the first one, the problem is quite the same.

Replacing the code above with the one below seem to fix the problem

n = strlen(var1) + 1;
var1str_ = new char[n];
strcpy(var1str_,var1);
myvar1_ = input->variable->find(var1str_);

n = strlen(var2) + 1;
var2str_ = new char[n];
strcpy(var2str_,var2);
myvar2_ = input->variable->find(var2str_);

n = strlen(var3) + 1;
var3str_ = new char[n];
strcpy(var3str_,var3);
myvar3_ = input->variable->find(var3str_);

Best Regards,
Rafal

sbateman | Thu, 08/22/2013 - 16:15

"strlen(&var1[2])" finds the length of the string beginning at the third element (i.e., skipping the first two characters). It seems like the linear/variable option is expecting the variable name to be "v_something", with the "v_" at the beginning, just like most other LAMMPS commands that take variables.

richti83's picture

richti83 | Thu, 08/22/2013 - 19:23

sbateman is right, the convention is:
v_ID for variable types
c_ID for computes
f_ID for fixes,
see examples at fix move for details.

fix 2 boundary move variable v_myx v_myy NULL v_VX v_VY NULL

@christoph:
we should update the doc of fix/move/mesh to
linear/variable args =
v_vx,v_vy,v_vz = variables specifying components of velocity vector (velocity units)
and add an example.

fix move all move/mesh mesh cad1 linear/variable v_VX v_VY v_VZ
fix rotate all move/mesh mesh cad1 rotate/variable origin 0 0 0 axis 1 0 0 omega v_Wx

I'm not an associate of DCS GmbH and not a core developer of LIGGGHTS®
ResearchGate | Contact

wladek | Fri, 08/23/2013 - 13:42

I double checked it, and You are right, my mistake.

However there is still one question remaining,

Line:
n = strlen(&var1[2]) + 1;

looks the same in all three blocks pasted above, and variable "n" never change in between, then why even bother repeating this line (e.g. calculating 3 times the same length of var1), unless it should calculate length of each variables (var1, var2, var3) ?

Best Regards,
Rafal

wladek | Fri, 08/23/2013 - 13:58

well, according to my gdb, strcpy doesn't seem to have any problems with copying bigger array to the smaller one, so the code works anyway.

Best regards,
Rafał