示例 1: 超级椭球堆积模拟
超级椭球局部坐标下的形状函数可由下式给出 $$\label{eqsurface} \Big(\big|\frac{x}{r_x}\big|^{\frac{2}{\epsilon_1}} + \big|\frac{y}{r_y}\big|^{\frac{2}{\epsilon_1}}\Big)^{\frac{\epsilon_1}{\epsilon_2}} + \big|\frac{z}{r_z}\big|^{\frac{2}{\epsilon_2}} = 1$$ 其中 $r_x, r_y$ 和 $r_z$ 是超级椭球在x, y, z轴的半长主轴; and $\epsilon_i (i=1,2)$ 是刻画颗粒棱角度的形状参数. $\epsilon_i$ 在 0 到 2 的变化可勾勒出非常丰富的凸超级椭球形状。SudoDEM 生成超级椭球的两个函数可参见如下高亮描述 (see Sec. 5.1.2{reference-type=“ref” reference=“modsuperquadrics”}):
-
NewSuperquadrics2($r_x$, $r_y$, $r_z$, $\epsilon_1$, $\epsilon_2$, mat, rotate, isSphere)
-
NewSuperquadrics_rot2($r_x$, $r_y$, $r_z$, $\epsilon_1$, $\epsilon_2$, mat, $q_w$, $q_x$, $q_y$, $q_z$, isSphere)
这里我们给出了超级椭球在立方体盒子中重力堆积的模拟示例。
|
|
在GUI控制面板中我们可以通过点击 ‘show 3D’ 按钮来显示模拟的可视化场景。在显示模式下选择 ‘Gl1_Superquadrics’ 渲染器来控制颗粒是由线条还是由实体面来渲染(如图), 3.3{reference-type=“ref” reference=“figguidisplay”}.
Figs. 3.4{reference-type=“ref” reference=“figexp11”} - 3.6{reference-type=“ref” reference=“figexp13”} 显示了在不同渲染模式下的超级椭球颗粒。
超级椭球颗粒的属性和类方法展示如下:
-
属性:
-
$r_x$, $r_y$, $r_z$: 浮点型, x, y, 和 z 轴的半长轴。
-
$\epsilon_1$, $\epsilon_2$: 浮点型, 材料参数。
-
isSphere: 布尔值, 颗粒是否是球体.
-
-
类方法:
-
getVolume(): 浮点型, 返回颗粒体积。
-
getrxyz(): 三阶向量, 返回颗粒的三个半长轴。
-
geteps(): 二阶向量, 返回颗粒的形状参数eps1和eps2。
-
如下代码给出了获取索引为100的超级椭球的体积:
volume = O.bodies[100].shape.getVolume()
获取对象所有属性的方法如下:
O.bodies[100].dict()
输出如下:
{'bound': <Aabb instance at 0x56072ec83da0>,
'chain': -1,
'clumpId': -1,
'flags': 3,
'groupMask': 1,
'id': 100,
'iterBorn': 0,
'material': <SuperquadricsMat instance at 0x56072e6ed5f0>,
'shape': <Superquadrics instance at 0x56072ec83b60>,
'state': <State instance at 0x56072ec839e0>,
'timeBorn': 0.0}
我们可以看到对象的属性是以字典的方式被打印出来的。需要提及的是尖括号内的是另一个对象的指针,也就是说我们可以通过dict()方法来进一步获取其对应的属性。例如我们要获取颗粒state的属性,可以通过如下代码:
O.bodies[100].state.dict()
输出如下:
{'angMom': Vector3(0,0,0),
'angVel': Vector3(0,0,0),
'blockedDOFs': 0,
'densityScaling': 1.0,
'inertia': Vector3(0.0045389863901528615,0.007287422614611933,
0.0067053718092146865),
'isDamped': True,
'mass': 3.225715855242557,
'refOri': Quaternion((1,0,0),0),
'refPos': Vector3(0,0,0),
'se3': (Vector3(0,0.8,3),
Quaternion((0.3970010520699211,0.5339678220536823,
-0.7465042060609055),2.1754719537556495)),
'vel': Vector3(0,0,0)}
对于 Shape对象, 它的属性输出可能随着子类的不同而不同。
O.bodies[100].shape.dict()
输出如下:
{'color': Vector3(0.6407663308273844,0.07426042997942327,
0.05872324344642611),
'eps': Vector2(1.3975848801318045,1.5376309088540607),
'eps1': 1.3975848801318045,
'eps2': 1.5376309088540607,
'highlight': False,
'isSphere': False,
'rx': 0.1,
'rxyz': Vector3(0.1,0.06469580193313924,0.07572423080016706),
'ry': 0.06469580193313924,
'rz': 0.07572423080016706,
'wire': False}
这里我们给出了一个例子用来获取所有超级椭球的序号及其位置信息:
for b in O.bodies: # loop all bodies in the simulation
# we have to check if the present body is a superellipsoid or others, e.g., a wall
if isinstance(b.shape, Superquadrics): # if it is a superellipsoid, then to do
pid = b.id # get the id of particle b
pos = b.state.pos # get the position of particle b
print pid, pos