这里介绍一个常用的对试样变形观察的方法——方格染色。这个方法的逻辑很简单,对试样错位染色就可以了。这里介绍一下代码结构。代码由两部分组成,第一部分是编写函数读写试样的尺寸范围。
def sousuoFanweilocal xyMinMax=array.create(2,2)local x_min=1e100local y_min=1e100local x_max=-1e100local y_max=-1e100loop foreach bp ball.listif x_min>ball.pos.x(bp)-ball.radius(bp) thenx_min=ball.pos.x(bp)-ball.radius(bp)endifif x_max<ball.pos.x(bp) ball.radius(bp) thenx_max=ball.pos.x(bp) ball.radius(bp)endifif y_min>ball.pos.y(bp)-ball.radius(bp) theny_min=ball.pos.y(bp)-ball.radius(bp)endifif y_max<ball.pos.y(bp) ball.radius(bp) theny_max=ball.pos.y(bp) ball.radius(bp)endifendloop=x_min=x_max=y_min=y_maxsousuoFanwei=xyMinMaxend
这部分代码逻辑很简单,就是比较储存尺寸范围的值和颗粒实际值。这里注意,最小值对比的是颗粒位置减去颗粒的半径,最大值对比的是颗粒位置加上颗粒的半径。最后将这个储存在一个2阶数组里面,之后返回给函数值。
第二部分就是染色方法,这里可以更改横向和纵向的方块数目,用户可以自己更改。首先执行sousuoFanwei函数得到尺寸范围,之后根据数目计算每个方格的宽和高。这里实现错位的逻辑也不难,就是看纵向和横向第几个方块,假设是横向第n个和纵向第m个,如果n m是偶数,就定义为gg1这个group,如果是奇数,就定义为gg2这个group,为了不打乱之前模型可能存在的group,这里都在slot 5位置上进行定义。
def ranselocal xy_min_max=sousuoFanweilocal NWidth=20.0 ;横向方块数目local NHeight=15.0;纵向数目local stepwidth=(xy_min_max(1,2)-xy_min_max(1,1))/NWidthlocal stepheight=(xy_min_max(2,2)-xy_min_max(2,1))/NHeightloop local n (1,NWidth)local minwidth=xy_min_max(1,1) stepwidth*(n-1)loop local m (1,NHeight)local minheight=xy_min_max(2,1) stepheight*(m-1)if (n m)/2-(n m)/2.0=0 thencommandball group gg1 slot 5 range x [minwidth] [minwidth stepwidth] ...y [minheight] [minheight stepheight]endcommandelsecommandball group gg2 slot 5 range x [minwidth] [minwidth stepwidth] ...y [minheight] [minheight stepheight]endcommandendifendloopendloopend
只需要运行ranse函数就可以了,效果图如下:

这样对于土体变形的观察是非常直观的,这里给出之前使用的案例,就比较能够直观看出剪切面的位置了。
