# -*- coding: cp936 -*-
import time
from random import*
from abaqus import*
from abaqusConstants import *
import assembly
import math
import displayGroupMdbToolset as dgm
start_time =time.clock()
def RandomFunc(vf,n,x0,y0,z0):
#### 修改自 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ###########
##
## [二次开发] Python做的改进的随机纤维束模型的程序(2D和3D)by panqingnuaa
## http://forum.simwe.com/thread-1031539-1-1.html
##
##########################################################
#####
######### RandomFunc(vf,n,x0,y0,z0) ###
##
## vf 体积分数;;n 颗粒个数;x0,y0,z0 立方体大小
## R 颗粒半径
## Dis_b 避免与边界相切
## count_w 布点不成功的颗粒个数(体积分数大的时候可能出现)
##
##############
R = x0*y0*z0*vf/n
R = R*0.75/math.pi
R = R**(1.0/3.0)
Dis_b = R/2.0
count_w = 0
dis_ini = 1000.0*(x0**2+y0**2+z0**2)
x=random()*(x0)+R+Dis_b
y=random()*(y0)+R+Dis_b
z=random()*(z0)+R+Dis_b
if (x0-R-Dis_b<x<x0-R+Dis_b)or(x0+R-Dis_b<x<=x0+R+Dis_b):
x=x0-R+Dis_b+random()*2.0*(R-Dis_b)
if (y0-R-Dis_b<y<y0-R+Dis_b)or(y0+R-Dis_b<y<=y0+R+Dis_b):
y=y0-R+Dis_b+random()*2.0*(R-Dis_b)
if (z0-R-Dis_b<z<z0-R+Dis_b)or(z0+R-Dis_b<z<=z0+R+Dis_b):
z=z0-R+Dis_b+random()*2.0*(R-Dis_b)
xyz=[(x,y,z)]
######################### 中心在边界则增加点
if (x>=x0-R+Dis_b):
if(y>=y0-R+Dis_b):
if(z>=z0-R+Dis_b):
xyz.append((x-x0,y,z))
xyz.append((x-x0,y-y0,z))
xyz.append((x-x0,y-y0,z-z0))
xyz.append((x,y-y0,z))
xyz.append((x,y-y0,z-z0))
xyz.append((x,y,z-z0))
xyz.append((x-x0,y,z-z0))
else:
xyz.append((x-x0,y,z))
xyz.append((x-x0,y-y0,z))
xyz.append((x,y-y0,z))
else:
if(z>=z0-R+Dis_b):
xyz.append((x-x0,y,z))
xyz.append((x,y,z-z0))
xyz.append((x-x0,y,z-z0))
else:
xyz.append((x-x0,y,z))
else:
if(y>=y0-R+Dis_b):
if(z>=z0-R+Dis_b):
xyz.append((x,y-y0,z))
xyz.append((x,y-y0,z-z0))
xyz.append((x,y,z-z0))
else:
xyz.append((x,y-y0,z))
else:
if(z>=z0-R+Dis_b):
xyz.append((x,y,z-z0))
######################## 初始点结束,开始后续点
for i in range(n-1):
flag_loop=1
flag_cout = 1
while flag_loop==1:
x=random()*(x0)+R+Dis_b
y=random()*(y0)+R+Dis_b
z=random()*(z0)+R+Dis_b
flag_loop=0
if (x0-R-Dis_b<x<x0-R+Dis_b)or(x0+R-Dis_b<x<=x0+R+Dis_b):
x=x0-R+Dis_b+random()*2.0*(R-Dis_b)
if (y0-R-Dis_b<y<y0-R+Dis_b)or(y0+R-Dis_b<y<=y0+R+Dis_b):
y=y0-R+Dis_b+random()*2.0*(R-Dis_b)
if (z0-R-Dis_b<z<z0-R+Dis_b)or(z0+R-Dis_b<z<=z0+R+Dis_b):
z=z0-R+Dis_b+random()*2.0*(R-Dis_b)
########### 循环标记
flag_x=0
flag_y=0
flag_z=0
################# 面相关标记
flag_xy=0
flag_zx=0
flag_yz=0
flag_xyz=0
############ 线及点相关标记
dist_x=dis_ini
dist_y=dis_ini
dist_z=dis_ini
dist_xy=dis_ini
dist_yz=dis_ini
dist_zx=dis_ini
dist_xyz=dis_ini
distmin=(2*R*1.05)**2
########### 循环比较距离 放置点
distcau = []
distfin = dis_ini
for j in range(len(xyz)):
dist = (x-xyz[j][0])**2 + (y-xyz[j][1])**2 +(z-xyz[j][2])**2
distcau.append(dist)
if (x>=x0-R+Dis_b):
if(y>=y0-R+Dis_b):
if(z>=z0-R+Dis_b):
flag_x=1
flag_y=1
flag_z=1
flag_xy=1
flag_yz=1
flag_zx=1
flag_xyz=1
dist_x = (x-x0-xyz[j][0])**2 + (y-xyz[j][1])**2 +(z-xyz[j][2])**2
dist_y = (x-xyz[j][0])**2 + (y-y0-xyz[j][1])**2 +(z-xyz[j][2])**2
dist_z = (x-xyz[j][0])**2 + (y-xyz[j][1])**2 +(z-z0-xyz[j][2])**2
dist_xyz = (x-x0-xyz[j][0])**2 + (y-y0-xyz[j][1])**2 +(z-z0-xyz[j][2])**2
dist_xy = (x-x0-xyz[j][0])**2 + (y-y0-xyz[j][1])**2 +(z-xyz[j][2])**2
dist_yz = (x-xyz[j][0])**2 + (y-y0-xyz[j][1])**2 +(z-z0-xyz[j][2])**2
dist_zx = (x-x0-xyz[j][0])**2 + (y-xyz[j][1])**2 +(z-z0-xyz[j][2])**2
else:
flag_x=1
flag_y=1
flag_xy=1
dist_x = (x-x0-xyz[j][0])**2 + (y-xyz[j][1])**2 +(z-xyz[j][2])**2
dist_y = (x-xyz[j][0])**2 + (y-y0-xyz[j][1])**2 +(z-xyz[j][2])**2
dist_xy = (x-x0-xyz[j][0])**2 + (y-y0-xyz[j][1])**2 +(z-xyz[j][2])**2
else:
if(z>=z0-R+Dis_b):
flag_x=1
flag_z=1
flag_zx=1
dist_x = (x-x0-xyz[j][0])**2 + (y-xyz[j][1])**2 +(z-xyz[j][2])**2
dist_z = (x-xyz[j][0])**2 + (y-xyz[j][1])**2 +(z-z0-xyz[j][2])**2
dist_zx = (x-x0-xyz[j][0])**2 + (y-xyz[j][1])**2 +(z-z0-xyz[j][2])**2
else:
flag_x=1
dist_x = (x-x0-xyz[j][0])**2 + (y-xyz[j][1])**2 +(z-xyz[j][2])**2
else:
if(y>=y0-R+Dis_b):
if(z>=z0-R+Dis_b):
flag_y=1
flag_z=1
flag_yz=1
dist_y = (x-xyz[j][0])**2 + (y-y0-xyz[j][1])**2 +(z-xyz[j][2])**2
dist_z = (x-xyz[j][0])**2 + (y-xyz[j][1])**2 +(z-z0-xyz[j][2])**2
dist_yz = (x-xyz[j][0])**2 + (y-y0-xyz[j][1])**2 +(z-z0-xyz[j][2])**2
else:
flag_y=1
dist_y = (x-xyz[j][0])**2 + (y-y0-xyz[j][1])**2 +(z-xyz[j][2])**2
else:
if(z>=z0-R+Dis_b):
flag_z=1
dist_z = (x-xyz[j][0])**2 + (y-xyz[j][1])**2 +(z-z0-xyz[j][2])**2
if flag_xyz==1:
distcau.append(dist_xyz)
if flag_xy==1:
distcau.append(dist_xy)
if flag_yz==1:
distcau.append(dist_yz)
if flag_zx==1:
distcau.append(dist_zx)
if flag_x==1:
distcau.append(dist_x)
if flag_y==1:
评论8