2016-05-06 34 views
1

我將材質建模爲連接材質點(代理)的彈簧(鏈接)的網格。使用定向鏈接來對作用於重要點的力量進行總結(使用link-heading)。但是,我想使用無向鏈接來提高速度(將鏈接數減少一半)。問題是獲得力矢量的正確方向,並以計算有效的方式計算力矢量(即,每次迭代只計算一次鏈接)用無向鏈接替換定向鏈接

使用定向鏈接(此代碼工作但具有必需數量的鏈接):

directed-links-breed [springs spring] 
springs-own [Fx Fy] 

ask springs [let deformation (link-length - natural-length) ;stretch is positive 
      let mag-force k * deformation 
       ;;direction of force vector is easy with directed link 
      set Fx mag-force * (sin link-heading) 
      set Fy mag-force * (cos link-heading)] 

;;sum x and y components of force vectors acting on material points 
ask material-points [set sigmaFx sum [Fx] of my-out-springs 
        set sigmaFy sum [Fy] of my-out-springs] 

我嘗試使用非定向鏈接:

undirected-links-breed [springs spring] 
springs-own [Fx Fy force] 

ask springs [let deformation (link-length - natural-length) ;stretch is positive 
      set force k * deformation] 

;;sum x and y components of force vectors acting on material points 
;;use of other-end since the link-heading does not necessarily give the correct direction of the force 
ask material-points [ask my-springs [set Fx force * sin towards other-end 
            set Fy force * cos towards other-end] 

使用這種方法與無向的聯繫,我得到一個錯誤:「你不能朝一個鏈接環境中使用,因爲對是代理/ patch-only「,避風港'但尚未找到解決辦法。此外,這種方法會導致每個彈簧(鏈接)每次迭代計算兩次力分量(一次是朝向end1的方向,另一次是朝着end2的方向),因此這可能不是使用有向鏈接的速度改進。

有人可以推薦一個更具計算效率的方式來做到這一點,最好有無向鏈接?

+0

你可以存儲,計算力的時間,並要求每個代理,如果時間不是當前的時間,只計算。然後,你可以說一些問題的材料點[用[最後計算時間!=滴答] [....]]問我的溫泉。你的模擬運行緩慢嗎? – mattsap

回答

0

請嘗試使用我自己。你也想,如果需要使用一些錯誤檢查:

ask material-points [ 
    ask my-springs 
    [ 
     if any? link-neighbors 
     [ 
     let neighbor other-end 
     if [distance neighbor] of myself != 0 
     [ 
      set Fx force * sin [towards neighbor] of myself 
     ] 
     ] 
    ] 
    ]