我正在将材料建模为连接材料点(代理)的弹簧(链接)网格。使用有向链接对作用于材料点的力进行求和是向前的(使用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]
将这种方法与无向链接一起使用时,我收到一条错误“你不能在链接上下文中使用,因为只有代理/补丁”,并且还没有找到解决方法。此外,该方法将使每个弹簧(链接)每次迭代计算两次力分量(一次朝向end1的方向,然后再朝向end2的方向),因此这可能不是使用有向链接的速度的改进。 / p>
有人可以推荐一种计算效率更高的方法,最好使用无向链接吗?
答案 0 :(得分: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
]
]
]
]