请帮我写一段模拟单轴压缩的yade程序
时间: 2024-02-27 20:56:36 浏览: 215
好的,以下是一个模拟单轴压缩的yade程序:
``` python
# -*- coding: utf-8 -*-
from yade import pack, utils, plot
from yade import ymport, export
from numpy import *
# 定义材料参数
Young = 1e7
Poisson = 0.2
frictionAngle = radians(30)
cohesion = 1e4
# 定义模拟参数
dt = 1e-5
endTime = 0.002
tolerance = 1e-4
gravity = (0, 0, -9.81)
# 创建颗粒
sp = pack.SpherePack()
sp.makeCloud((-0.05, -0.05, 0), (0.05, 0.05, 0), 0.01, periodic=False)
sp.toSimulation()
# 模拟设置
O.dt = dt
O.engines = [
ForceResetter(),
InsertionSortCollider([Bo1_Sphere_Aabb()]),
InteractionLoop(
[Ig2_Sphere_Sphere_ScGeom6D()],
[Ip2_FrictMat_FrictMat_FrictPhys()],
[
Law2_ScGeom_FrictPhys(
young=Young,
poisson=Poisson,
frictionAngle=frictionAngle,
cohesion=cohesion,
)
],
),
PyRunner(command='addWall()', iterPeriod=1),
PyRunner(command='applyLoad()', iterPeriod=1),
NewtonIntegrator(damping=0.4),
TranslationEngine(),
Gravity(gravity),
]
# 添加墙体
def addWall():
walls = O.bodies.append(
utils.wall(
O.interactionDetection.boundingBox(),
thickness=0.001,
wallMask=15,
)
)
for w in walls:
w.state.blockedDOFs = 'xyzXYZ'
# 加载应力
def applyLoad():
for b in O.bodies:
if b.state.pos[2] < -0.0001:
b.state.vel[2] = -1e-5
O.pause()
# 运行模拟
while O.time < endTime:
O.run(1)
plot.saveDataTxt('compress_data.txt', vars=['O.totalStrain[2]', 'O.totalStress[2]'])
```
这个程序使用了Yade库,首先定义了材料参数和模拟参数。然后创建了一个球形颗粒堆,并设置了模拟引擎和墙体。在每次迭代中,程序会检测是否需要加载应力并运行模拟,最后将压缩数据写入文本文件中。
注意,这个程序只是一个简单的示例,可能需要根据具体需求进行一些修改。
阅读全文