写一个非常规态基近场动力学计算复合裂纹的python代码
时间: 2024-03-02 13:26:06 浏览: 103
1DPDpy:一维近场动力学代码
5星 · 资源好评率100%
非常规态基近场动力学(Peridynamics)是一种基于无穷远扰动的连续介质力学模型,可以用于模拟材料的断裂行为。以下是一个用Python编写的基于非常规态基近场动力学模型计算复合裂纹的代码:
```python
import numpy as np
import matplotlib.pyplot as plt
# 定义参数
dx = 0.01
dt = 0.01
L = 1
T = 1
E = 1
nu = 0.3
Gc = 0.1
omega = 0.5
r_c = 0.1
r_a = 0.2
K = E/(3*(1-2*nu))
# 定义函数
def w(x):
return 1 - x*x
def K1(x):
return K*(1 - 2*nu)*w(x)
def K2(x):
return K*nu*w(x)
def K3(x):
return K*(1 - nu)*w(x)
def d(x):
return 2*Gc*(1 - omega)*(1 - x/r_c)**2
def psi(x):
if x > r_a:
return 0
else:
return (1 - x/r_a)**2
# 初始化网格
N = int(L/dx)
U = np.zeros(N)
V = np.zeros(N)
R = np.zeros(N)
H = np.zeros(N)
D = np.zeros(N)
# 定义边界条件
U[0] = 0
U[-1] = 0
# 定义初始断裂
R[N//2] = 1
# 进行时间循环
for t in range(int(T/dt)):
# 计算应力和力
for i in range(1, N-1):
F = 0
for j in range(1, N-1):
if i != j:
x = abs(i-j)*dx
Kx = K1(x) + K2(x) + K3(x)
F += Kx*(U[j] - U[i])
if R[j] > 0:
F += d(x)*psi(R[j])*np.sign(U[j] - U[i])
H[i] = F
S = 0
for j in range(1, N-1):
if i != j:
x = abs(i-j)*dx
Kx = K1(x) + K2(x) + K3(x)
S += Kx*(R[j]/(dx*dx) + psi(R[j])*np.sign(U[j] - U[i]))
D[i] = S
# 更新位移和裂缝
for i in range(1, N-1):
V[i] += (H[i] - D[i])*dt/(rho*dx)
U[i] += V[i]*dt
R[i] += D[i]*dt
# 绘制图像
plt.clf()
plt.plot(np.linspace(0, L, N), U)
plt.plot(np.linspace(0, L, N), R)
plt.xlim(0, L)
plt.ylim(-0.1, 1.1)
plt.title('Time: {:.2f}'.format((t+1)*dt))
plt.xlabel('Position')
plt.ylabel('Displacement/Crack')
plt.legend(['Displacement', 'Crack'])
plt.pause(0.01)
```
阅读全文