找回密码
 注册
Simdroid-非首页
查看: 2735|回复: 39

[工程实例] 讨论一下如何生成云图

[复制链接]
发表于 2011-11-3 17:31:40 | 显示全部楼层 |阅读模式 来自 江苏南京
本帖最后由 benbenmoon 于 2012-3-8 13:20 编辑

前段时间看到周健老师的一篇论文《颗粒流强度折减法和重力增加法的边坡安全系数研究》  ,里面有几张用pfc做的位移云图非常漂亮,像这张:



后来和同学讨论了半天左边的图例怎么加的,发现只会给球设置不同的颜色,没找到在左边加上标注的方法,这两天群里的POP同学又问起这个事情,想了一下可以用group的方法加标注,用很笨的方法做了一个小算例,算是抛砖引玉,希望大家解读一下上面周老师的方法或者分享一下自己的做法。。。不胜感激

算例很简单,一个1×1的墙围起来的区域内随机生成几个球,在重力下平衡,显示位移云图。。。
最后是个这样的



方法是把不同位移的球放在不同group内,group用位移的范围做名字  然后把几个group分别添加到plot里面(用的plot  add group range group _groupname,开始时候我直接用一句plot add group,虽然都简单,但好像group的排序就经常是乱的 不知道为什么。。。)



命令流如下:
new
set random
;;;;;下面为生成模型;;;;;;;;
gen id 1 70 x 0 1 y 0 1 rad 0.01 0.01
ini rad mul 5
wall id 1 nodes (0 0)(1 0)
wall id 2 nodes (1 0)(1 1)
wall id 3 nodes (1 1)(0 1)
wall id 4 nodes (0 1)(0 0)
prop den 1e3 ks 1e3 kn 1e3
wall prop ks 1e4 kn 1e4
set grav 0 -1
plot add wall black ball blue
p s
cycle 1000
;;;;;上面为生成模型;;;;;;;;

def ququ
    _maxx=0.6     ;最大位移...自己指定(小数点后面要有一位,否则就变整数型了)
    _n=6          ;group的数目...自己指定
    loop n (1,_n)
      _num=0      ;group里面小球的数目
      _min=(_maxx/_n)*(n-1)
      _max=(_maxx/_n)*n
      gnname=string(_min)+'-'+string(_max)      ;group的名字   如图所示很长一串。。。13楼有改进版。。。:gnname=stringfmt(_min,3,1)+'-'+stringfmt(_max,3,1)
      bp=ball_head
      loop while bp # null
        section
          bid=b_id(bp)
          bdip=(b_xdisp(bp)^2+b_ydisp(bp)^2)^0.5
          if bdip>_min
            if bdip<_max  
              _num=_num+1     
              command
                group @gnname range id @bid
              end_command
              exit section
            end_if
          end_if
        end_section
        bp=b_next(bp)
      end_loop  
      gravvv1=urand     ;生成随机颜色用
      gravvv2=urand     ;生成随机颜色用
      gravvv3=urand     ;生成随机颜色用
      if _num # 0       ;如果一个group里面木有小球,后面往plot里面加这个group的时候就会报错。。。所以加了这么个判断语句
        command
          plot add group rgb @gravvv1 @gravvv2 @gravvv3  range group @gnname
        end_command
      end_if
    end_loop
end
ququ



dat文件:



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×

评分

1

查看全部评分

发表于 2011-11-5 09:47:54 | 显示全部楼层 来自 湖南长沙
Simdroid开发平台
我也为这个问题困扰,看到一段代码中这样做的:找出想要生成云图那个量(比如位移)的最大和最小值,然后得到位移的范围(max-min),将其分成N份;用ball的位移值减去min 再除以每份的长度,得到每个ball 所在的区间(1-N中间确定的一个),然后把这个数付给b_color,下面是源代码,从别人那里拷过来的,我也有些地方看不太懂,他是对球体的温度按颜色划分区间,有点复杂
;Contour temperatures
;modified by TW, 13 May 2005
;-------------------------------
def _col_default
  _my_max   = -1.0e20
  _my_min   =  1.0e20
end
;-------------------------------
def _my_colors
; --- First find max and min ball temperature ... 找出最大最小值
  _my_range = _my_max - _my_min
  _max_temp = -1.0e20
  _min_temp =  1.0e20
  _b_pnt = ball_head
  loop while _b_pnt # null   Page 168
    _bid = b_id(_b_pnt)
    _max_temp = max(_max_temp,b_thtemp(_b_pnt))
    _min_temp = min(_min_temp,b_thtemp(_b_pnt))
    _b_pnt = b_next(_b_pnt)
  end_loop
  _min_t = _min_temp
  _max_t = _max_temp
  if _my_range = -2.0e20 then
    _t_range = _max_temp - _min_temp
   else
    _max_temp = _my_max
    _min_temp = _my_min
    _t_range = _max_temp - _min_temp
  endif
  _col_dt = _t_range/40.0   ;将统计范围划分成N=40份
  _min_temp = _min_temp - _col_dt*0.5 ;?这句的作用,求解释
; --- Next assign ball color code according to its temp ...
  _b_pnt = ball_head
  loop while _b_pnt # null
    _bid = b_id(_b_pnt)
    _b_cindx = int((b_thtemp(_b_pnt) - _min_temp)/_col_dt) ;循环确定每个ball属于N中的哪一段
    b_color(_b_pnt) = _b_cindx
    _b_pnt = b_next(_b_pnt)
  end_loop
  command
    group _con1 ran color  0 15
    group _con2 ran color  16 31
    group _con3 ran color  32 41
  end_command
end
;-------------------------------
def _chg_cid ; pfc中只能显示16种颜色,为什么分配40份,这不给自己找麻烦吗?求解释
; --- Because we can only display 16 colors per plot item,
;     we must re-assign ball color ids in each group to
;     to reflect this fact ...
  _bpt = ball_head
  loop while _bpt # null
    if b_color(_bpt) > 15 then
      if b_color(_bpt) < 32 then
        b_color(_bpt) = b_color(_bpt) - 16
      endif
    endif
    if b_color(_bpt) > 31 then
      b_color(_bpt) = b_color(_bpt) - 32
    endif
    _bpt = b_next(_bpt)
  end_loop
end
;-------------------------------
def make_tcview
  
  if _tc_tcviewexists = 1 then
    tc_destroy_tcview
  end_if

end
;-------------------------------
def tc_destroy_tcview

  if _tc_tcviewexists = 1 then
    command
      plot cur 0
      plot destroy temp_contour
    end_command
  end_if
  _tc_tcviewexists = 0

end
;-------------------------------   
def makeTempCont

command

  make_tcview
  _col_default
  _my_colors
  _chg_cid
   ;定义了40份颜色
macro c1  'rgb 1.00 0.00 0.00'    ; red
macro c2  'rgb 1.00 0.10 0.00'
macro c3  'rgb 1.00 0.20 0.00'
macro c4  'rgb 1.00 0.30 0.00'
macro c5  'rgb 1.00 0.40 0.00'
macro c6  'rgb 1.00 0.50 0.00'
macro c7  'rgb 1.00 0.60 0.00'
macro c8  'rgb 1.00 0.70 0.00'
macro c9  'rgb 1.00 0.80 0.00'
macro c10 'rgb 1.00 0.90 0.00'
macro c11 'rgb 1.00 1.00 0.00'    ; yellow
macro c12 'rgb 0.90 1.00 0.00'
macro c13 'rgb 0.80 1.00 0.00'
macro c14 'rgb 0.70 1.00 0.00'
macro c15 'rgb 0.60 1.00 0.00'
macro c16 'rgb 0.50 1.00 0.00'
macro c17 'rgb 0.40 1.00 0.00'
macro c18 'rgb 0.30 1.00 0.00'
macro c19 'rgb 0.20 1.00 0.00'
macro c20 'rgb 0.10 1.00 0.00'
macro c21 'rgb 0.00 1.00 0.00'    ; green
macro c22 'rgb 0.00 1.00 0.10'
macro c23 'rgb 0.00 1.00 0.20'
macro c24 'rgb 0.00 1.00 0.30'
macro c25 'rgb 0.00 1.00 0.40'
macro c26 'rgb 0.00 1.00 0.50'
macro c27 'rgb 0.00 1.00 0.60'
macro c28 'rgb 0.00 1.00 0.70'
macro c29 'rgb 0.00 1.00 0.80'
macro c30 'rgb 0.00 1.00 0.90'
macro c31 'rgb 0.00 1.00 1.00'    ; turkoise
macro c32 'rgb 0.00 0.90 1.00'
macro c33 'rgb 0.00 0.80 1.00'
macro c34 'rgb 0.00 0.70 1.00'
macro c35 'rgb 0.00 0.60 1.00'
macro c36 'rgb 0.00 0.50 1.00'
macro c37 'rgb 0.00 0.40 1.00'
macro c38 'rgb 0.00 0.30 1.00'
macro c39 'rgb 0.00 0.20 1.00'
macro c40 'rgb 0.00 0.10 1.00'
macro c41 'rgb 0.00 0.00 1.00'    ; blue

macro _bc3 'c9 c8 c7 c6 c5 c4 c3 c2 c1'
macro _bc2 'c25 c24 c23 c22 c21 c20 c19 c18 c17 c16 c15 c14 c13 c12 c11 c10'
macro _bc1 'c41 c40 c39 c38 c37 c36 c35 c34 c33 c32 c31 c30 c29 c28 c27 c26'

   pl cre temp_contour
   pl ad bal _bc1 range group _con1
   pl ad bal _bc2 range group _con2
   pl ad bal _bc3 range group _con3
  endcommand
   
end
ret
回复 2 不支持 0

使用道具 举报

发表于 2014-5-19 18:34:39 | 显示全部楼层 来自 武汉大学
我一般都是把颗粒的信息(应力、变形)等提取出来,放到第三方软件里面出图的
回复 1 不支持 0

使用道具 举报

发表于 2013-9-12 21:25:19 | 显示全部楼层 来自 湖北武汉
根据球体某一参数显示不同颜色,可以在fishlab中很好的显示,fishlab官网上免费下载。只需要将fishlab需要的数据按固定的格式输出即可。
回复 1 不支持 0

使用道具 举报

发表于 2011-12-4 13:30:18 | 显示全部楼层 来自 湖南长沙
bjtushigui 发表于 2011-12-1 11:19
学习中,想画等值线图 郁闷中

画等值线还是用surfer吧,把颗粒的position和你想要作图的信息导出,然后用surfer导入,那个画出来蛮漂亮的。用pfc还得自己编程,麻烦。

评分

1

查看全部评分

回复 1 不支持 0

使用道具 举报

 楼主| 发表于 2011-11-5 12:24:23 | 显示全部楼层 来自 江苏南京
本帖最后由 benbenmoon 于 2011-11-5 12:27 编辑

回复2#
_min_temp = _min_temp - _col_dt*0.5 好像是和_b_cindx = int((b_thtemp(_b_pnt) - _min_temp)/_col_dt)  里面产生区间的范围有关系。。。_min_temp减去_col_dt*0.5那么 b_index=0温度的区间是 [_min-_col_dt*0.5,_min+_col_dt*0.5), _min_temp不减那个的话区间是[_min,_min+ _min_temp]其实我觉得这样也行吧。。。 编这段程序的可能有啥考虑才减的吧。。。不知道为啥。。。

pfc中只能显示16种颜色,为什么分配40份,这不给自己找麻烦吗?求解释/   不是只能显示16种,Because we can only display 16 colors per plot item是说每一个显示项目只有16种。。。他后面就16个16个的加的group。。。
但是这一段:
loop while _bpt # null
    if b_color(_bpt) > 15 then
      if b_color(_bpt) < 32 then
        b_color(_bpt) = b_color(_bpt) - 16 3 I  },
      endif
    endif 。。。。。。
有必要的么?是不是不把c_index都调整到0-15范围内就会出错? 能不能试验一下。。。




这个用c_index来定义的group 比我的方法好。。。 _b_cindx = int((b_thtemp(_b_pnt) - _min_temp)/_col_dt)   这一句最经典!

回复 不支持

使用道具 举报

发表于 2011-11-5 17:20:49 | 显示全部楼层 来自 江苏南京
关于云图实在是没研究过呀。惭愧呀!欢迎各位探讨探讨呀!
回复 不支持

使用道具 举报

发表于 2011-12-1 10:24:10 | 显示全部楼层 来自 陕西西安
学习一下,呵呵
回复 不支持

使用道具 举报

发表于 2011-12-1 10:42:00 | 显示全部楼层 来自 四川成都
学习中~
回复 不支持

使用道具 举报

发表于 2011-12-1 11:19:28 | 显示全部楼层 来自 北京
学习中,想画等值线图 郁闷中
回复 不支持

使用道具 举报

发表于 2011-12-1 18:29:05 | 显示全部楼层 来自 北京
我把上边两个程序整合了一下,请高手指点其中颜色指针与左边位移标注是不是正确对应的? 还有怎么设置标注的小数点后留几位数啊?
def _col_default
_disp_max   = -1.0e20
_disp_min   =  1.0e20
end
def _disp_colors
;找出位移的最大值和最小值
    _col_default
    bp = ball_head
    loop while bp # null
         _bid = b_id(bp)
         bdisp=(b_xdisp(bp)^2+b_ydisp(bp)^2)^0.5
         if bdisp<_disp_min
            _disp_min=bdisp
         end_if
         if bdisp>_disp_max
            _disp_max=bdisp
         end_if   
         bp=b_next(bp)
     end_loop
     command
        print _disp_max
        print _disp_min
     end_command
     _disp_range = _disp_max - _disp_min
     _col_dt=_disp_range/10.0 ;将统计范围划分10份
;判断球的位移在哪个范围内
     bp = ball_head
     loop while bp # null
          _bid = b_id(bp)
          bdisp=(b_xdisp(bp)^2+b_ydisp(bp)^2)^0.5
          _b_cindx = int((bdisp - _disp_min)/_col_dt) ;循环确定每个ball属于N中的哪一段
          b_color(bp) = _b_cindx
          bp=b_next(bp)
     end_loop
end
_disp_colors
def group_ball
    _n=10
    loop n (1,_n)
      m=n-1
      _min=_col_dt*(n-1)+_disp_min
      _max=_col_dt*n +_disp_min     
      gnname=string(_min)+'-'+string(_max)      ;group的名字
      command
          group @gnname range color m n
      end_command
    end_loop
end
group_ball
plot group
回复 不支持

使用道具 举报

发表于 2011-12-6 10:05:10 | 显示全部楼层 来自 甘肃兰州
虚心学习
回复 不支持

使用道具 举报

发表于 2011-12-6 16:15:33 | 显示全部楼层 来自 浙江杭州
楼主发的论文里的图是怎么做出来的啊,貌似不是GROUP做的!
回复 不支持

使用道具 举报

发表于 2012-2-12 21:33:38 | 显示全部楼层 来自 江苏南京
ccb137731 发表于 2011-11-5 17:20
关于云图实在是没研究过呀。惭愧呀!欢迎各位探讨探讨呀!

请教版主 如何控制view中显示的小数的位数啊?
回复 不支持

使用道具 举报

 楼主| 发表于 2012-2-12 22:14:06 | 显示全部楼层 来自 江苏南京
本帖最后由 benbenmoon 于 2012-2-12 22:15 编辑
morningsun613 发表于 2012-2-12 21:33
请教版主 如何控制view中显示的小数的位数啊?

之前我也想过这个问题  不处理一下太丑了  刚才找到函数在群里说了的。。。
用的那个stringfmt( g, pre, wid )函数把_min和_max改一下 比如改成   gnname=stringfmt(_min,3,1)+'-'+stringfmt(_max,3,1)


试了一下 pre可以理解为有效数字的位数 但是没高清楚那个wid是什么意思  下面是stringfmt函数的解释

stringfmt( g, pre, wid )
converts to a string. If g is already of type string, then the
function simply returns g as its value. If g is int, then a
character string will be returned with width wid. If g is
float, then a character string will be returned with width
wid and precision pre.
回复 不支持

使用道具 举报

发表于 2012-2-13 10:14:00 | 显示全部楼层 来自 江苏南京
benbenmoon 发表于 2012-2-12 22:14
之前我也想过这个问题  不处理一下太丑了  刚才找到函数在群里说了的。。。
用的那个stringfmt( g, pre, w ...

这一部分解释在手册的哪一部分啊?我看的时候貌似错过了。。。
回复 不支持

使用道具 举报

 楼主| 发表于 2012-2-13 11:08:20 | 显示全部楼层 来自 江苏南京
morningsun613 发表于 2012-2-13 10:14
这一部分解释在手册的哪一部分啊?我看的时候貌似错过了。。。

fish reference
回复 不支持

使用道具 举报

发表于 2012-2-14 10:53:53 | 显示全部楼层 来自 江苏南京
benbenmoon 发表于 2012-2-13 16:39
fish reference ( P2d215  P78-80)

谢谢!
回复 不支持

使用道具 举报

发表于 2012-2-13 13:32:48 | 显示全部楼层 来自 江苏南京
benbenmoon 发表于 2012-2-13 11:08
fish reference

请问你是用的3.1版的吗?我找了这章没有stringfmt()这个函数啊。。。能告诉我具体在哪页吗?
回复 不支持

使用道具 举报

 楼主| 发表于 2012-2-13 16:39:01 | 显示全部楼层 来自 江苏南京
morningsun613 发表于 2012-2-13 13:32
请问你是用的3.1版的吗?我找了这章没有stringfmt()这个函数啊。。。能告诉我具体在哪页吗?
...

fish reference ( P2d215  P78-80)
回复 不支持

使用道具 举报

发表于 2012-2-14 07:52:30 | 显示全部楼层 来自 大连理工大学
看了,有所收获
回复 不支持

使用道具 举报

发表于 2012-2-14 19:38:41 | 显示全部楼层 来自 大连理工大学
受教了,非常感谢大家的分享
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-4-18 14:35 , Processed in 0.051275 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表