3DEC version 7 to 5.2

Hi 3DEC team/users,
Could someone help me to rewrite the version 7 code to version 5.2?
I am stuck at this command line while looping.

version 7: loop foreach gp block.gp.list
version 5.2: loop foreach gp b_gp (which I tried)

But it seems ‘foreach’ command doesn’t work for version 5.2.

converted version: 5.2 code
group vertex ‘top’ range z 5
group vertex ‘bottom’ range z -5
[global area = 5.0*5.0]
[global length = 10.0]
def zzstress
; compression positive, units MPa
local top_reaction = 0.0
local bottom_reaction = 0.0
loop foreach gp b_gp
if gp_group(gp) = ‘top’
top_reaction = top_reaction - gp_zreaction(gp)
local top_disp = gp_zdis(gp)
endif
if gp_group(gp) = ‘bottom’
bottom_reaction = bottom_reaction + gp_zreaction(gp)
endif
end_loop

Actual code in version 7
block gridpoint group ‘top’ range pos-z 5
block gridpoint group ‘bottom’ range pos-z -5

[global area = 5.0*5.0]
[global length = 10.0]

fish def zzstress
; compression positive, units MPa
local top_reaction = 0.0
local bottom_reaction = 0.0
loop foreach gp block.gp.list
if block.gp.group(gp) = ‘top’
top_reaction = top_reaction - block.gp.force.reaction.z(gp)
local top_disp = block.gp.disp.z(gp)
endif
if block.gp.group(gp) = ‘bottom’
bottom_reaction = bottom_reaction + block.gp.force.reaction.z(gp)
endif
end_loop

1 Like

Yes, in 5.2. there is no foreach, so you have to traverse the linked lists yourself using the _next() functions.

bi=block.head
loop while bi#0

bi=b_next(bi)
endloop

Sure. Will try out this way, Markus.
Many thanks.
Vijay