IF LOOP IN LIGGGHTS

Submitted by AnjanaKittu on Thu, 11/02/2017 - 02:21

Hi,

I an new to LIGGGHTS and trying to figure out how to create an if loop. I looked at the documentation, but not sure how to proceed.
Here is my current code, not sure if this works.

label shearing1
variable xpos
variable strain_inc equal 0.0
variable max_height equal 0.0377

if ${xpos} < ${max_height}*0.01
#if ${xpos} < ${max_height}*.0025+${strain_inc} then

fix move all move/mesh cad1 linear 1e-04 0.0 0.0
fix move all move botwall linear 1e-04 0.0 0.0

dump dmp all custom 100000 post/ball*.upto1percent id type x #y z ix iy iz vx vy vz fx fy fz omegax omegay omegaz radius
contact forces
compute fc all pair/gran/local id pos vel force force_normal force_tangential history
dump forcechain all local 400000 post/iocforces*.upto1percent c_fc[1] c_fc[2] c_fc[3] c_fc[4] c_fc[5] c_fc[6] c_fc[7] c_fc[8] c_fc[9] c_fc[10] c_fc[11] c_fc[12] c_fc[13]

variable {$strain_inc} + {$max_height}*0.01
label endloop

Any help is appreciated!!

Thank you,
Anjana

paul | Fri, 11/03/2017 - 22:25

Hi,

Your code has a variety of problems. Before adding any complexity by introducing loops etc, I'd suggest getting acquinted your case to run as is using variables, and learning loops by playing around with the print statement.

Things that look weird to me:
- The variable declarations look off, regarding xpos and many positions they are used.
Declaration - variable VARNAME equal VAL
Usage - ${VARNAME} or v_VARNAME
see https://www.cfdem.com/media/DEM/docu/Section_input_script.html

- Adding another dump/fix of the same name in every loop iteration will fail.
Consider doing
dump ...
run ...
undump ...
within a loop.

- General looping:
There is no jumping, which is the way to do loops and (longer) conditionals in LIGGGHTS.
jump is a renamed goto, which can be used in contexts like this:

label LABELNAME
if ... then jump LABELNAME
...
jump this_file_name LABELNAME

is a while loop for example,
see https://www.cfdem.com/media/DEM/docu/jump.html and https://www.cfdem.com/media/DEM/docu/if.html

I hope this gives some introduction to what you could do. The golden approach is to run the code and try to make some sense of the error messages that ensue ;)

Greetings,
Paul