本文已参加「新人创造礼」活动,一起开启创造之路。

前语

依据上篇文章存在的问题(随机纤维生成、截面指使、切开)进行学习收拾

代码

导包与参数

from abaqus import *
from abaqusConstants import *
from caeModules import *
from driverUtils import executeOnCaeStartup
from math import *
import random as rd
# 纤维半径r与基体长度深度
r = 2
w = 50
depth = 5
# 记载纤维中心坐标的列表xy
xy = [[rd.random()*width, rd.random()*width]]
# 两纤维间最小间隔,防止间隔过近导致网格过小
l_min = 2*r+r/4
# 方针纤维体积分数与当时纤维体积分数
# 方针体积分数不宜过大,理论上<0.5或<0.6基本不会犯错
vf = 0.3
vf_curr = 0
# 资料参数(模量泊松比)
E_m = 50
v_m = 0.3
E_f = 273
v_f = 0.2

创建基体并赋予截面

s = mdb.models['Model-1'].ConstrainedSketch(name='__profile__', sheetSize=200.0)
s.rectangle(point1=(0.0, 0.0), point2=(w, w))
p = mdb.models['Model-1'].Part(name='matrix', dimensionality=THREE_D, type=DEFORMABLE_BODY)
p.BaseSolidExtrude(sketch=s, depth=depth)
del mdb.models['Model-1'].sketches['__profile__']
mdb.models['Model-1'].Material(name='Material-matrix')
mdb.models['Model-1'].materials['Material-matrix'].Elastic(table=((E_m, v_m),))
mdb.models['Model-1'].HomogeneousSolidSection(name='Section-matrix', material='Material-matrix', thickness=None)
c = p.cells
cells = c.findAt(((w, w, 0),))
region = regionToolset.Region(cells=cells)
p.SectionAssignment(region=region, sectionName='Section-matrix', offset=0.0, offsetType=MIDDLE_SURFACE, offsetField='', thicknessAssignment=FROM_SECTION)

创建纤维

依据自身不同需求,可以修正纤维坐标生成代码,这里写了一个判别条件不是很简单的,待优化

def judge(cir):
    for curr_cir in xy:
        if (cir[0]-curr_cir[0])**2+(cir[1]-curr_cir[1])**2 < l_min**2:
            return False
        else:
            continue
    return True
def add(cir):
    if judge(cir):
    	# 如果纤维和四边不堆叠,则直接添加
        if cir[0] > r+r/2 and w-cir[0] > r+r/2 and cir[1] > r+r/2 and w-cir[1] > r+r/2:
            xy.append(cir)
        else:
            # 纤维和四边堆叠
            # 其中间隔4个旮旯太近的不要
            if cir[0]**2+cir[1]**2 > 2*r**2 and cir[0]**2+(cir[1]-w)**2 > 2*r**2 and (cir[0]-w)**2+cir[1]**2 > 2*r**2 and (cir[0]-w)**2+(cir[1]-w)**2 > 2*r**2:
		        # 判别落四边上的纤维是否要周期,并添加
                if cir[0] < r:
                    if r-cir[0] > 0.8:
                        if judge([cir[0]+w, cir[1]]):
                            xy.append(cir)
                            xy.append([cir[0]+w, cir[1]])
                if w-cir[0] < r:
                    if r-(w-cir[0]) > 0.8:
                        if judge([cir[0]-w, cir[1]]):
                            xy.append(cir)
                            xy.append([cir[0]-w, cir[1]])
                if cir[1] < r:
                    if r-cir[1] > 0.8:
                        if judge([cir[0], cir[1]+w]):
                            xy.append(cir)
                            xy.append([cir[0], cir[1]+w])
                if w-cir[1] < r:
                    if r-(w-cir[1]) > 0.8:
                        if judge([cir[0], cir[1]-w]):
                            xy.append(cir)
                            xy.append([cir[0], cir[1]-w])
while vf_curr < vf:
    cir = [rd.random()*w, rd.random()*w]
    add(cir)
    vf_curr = len(xy)*math.pi*r**2/w**2
print(vf_curr)
# 以上创建好的纤维的中心坐标都在xy列表里了
# 在s1草图中画圆,拉伸成实体
s1 = mdb.models['Model-1'].ConstrainedSketch(name='__profile__', sheetSize=200.0)
for cir in xy:
	s1.CircleByCenterPerimeter(center=(cir[0], cir[1]), point1=(cir[0]+r, cir[1]))
p = mdb.models['Model-1'].Part(name='fiber', dimensionality=THREE_D, 
    type=DEFORMABLE_BODY)
p.BaseSolidExtrude(sketch=s1, depth=depth)
del mdb.models['Model-1'].sketches['__profile__']

为纤维赋予截面

mdb.models['Model-1'].Material(name='Material-fiber')
mdb.models['Model-1'].materials['Material-fiber'].Elastic(table=((E_f, v_f),))
mdb.models['Model-1'].HomogeneousSolidSection(name='Section-fiber', material='Material-fiber', thickness=None)
p = mdb.models['Model-1'].parts['fiber']
c = p.cells
for cir in xy:    
    cells = c.findAt(((cir[0], cir[1], 0.0),))
    region = regionToolset.Region(cells=cells)
    p.SectionAssignment(region=region, sectionName='Section-fiber', offset=0.0, offsetType=MIDDLE_SURFACE, offsetField='', thicknessAssignment=FROM_SECTION)

安装

a = mdb.models['Model-1'].rootAssembly
a.DatumCsysByDefault(CARTESIAN)
p = mdb.models['Model-1'].parts['fiber']
a.Instance(name='fiber-1', part=p, dependent=OFF)
p = mdb.models['Model-1'].parts['matrix']
a.Instance(name='matrix-1', part=p, dependent=OFF)
a.InstanceFromBooleanMerge(name='UDcomp', instances=(a.instances['fiber-1'], a.instances['matrix-1'], ), keepIntersections=ON, originalInstances=SUPPRESS, domain=GEOMETRY)

切开

该文章介绍了选取几何元素的各种方法,这里使用findAt()函数

p = mdb.models['Model-1'].parts['UDcomp']
f, e = p.faces, p.edges
# 经过findAt寻觅画布方位
face = f.findAt(((rd.random()*w, rd.random()*w, depth),))
edge = e.findAt(((w, rd.random()*w, depth),))
# face和edge为GeomSequence object,里面只有一个元素分别为face object、edge object
# 可经过face[0].getCentroid()获取面、边的重心坐标,来观察找到的面、边是否符合要求
t = p.MakeSketchTransform(sketchPlane=face[0], sketchUpEdge=edge[0], 
    sketchPlaneSide=SIDE1, sketchOrientation=RIGHT, origin=(w/2, w/2, 
    depth))
s = mdb.models['Model-1'].ConstrainedSketch(name='__profile__', 
    sheetSize=200, transform=t)
p.projectReferencesOntoSketch(sketch=s, filter=COPLANAR_EDGES)
s.rectangle(point1=(-w/2, -w/2), point2=(w/2, w/2))
s.rectangle(point1=(-w/2-2*r, -w/2-2*r), point2=(w/2+2*r, w/2+2*r))
p.CutExtrude(sketchPlane=face[0], sketchUpEdge=edge[0], sketchPlaneSide=SIDE1, 
    sketchOrientation=RIGHT, sketch=s, flipExtrudeDirection=OFF)
del mdb.models['Model-1'].sketches['__profile__']

mesh

p = mdb.models['Model-1'].parts['UDcomp']
p.seedPart(size=1.0, deviationFactor=0.1, minSizeFactor=0.1)
c = p.cells
pickedRegions = c.getSequenceFromMask(mask=('[#ffffffff #3fffffff ]', ), )
p.setMeshControls(regions=pickedRegions, elemShape=WEDGE)
p.generateMesh()

EasyPBC

## 依然是,需要删除多余的实例,否则报错
a = mdb.models['Model-1'].rootAssembly
a.deleteFeatures(('fiber-1', 'matrix-1', ))
import sys
sys.path.insert(8, r'e:/CAE/abaqus_plugins/EasyPBC V.1.4')
import easypbc
easypbc.feasypbc(part='Model-1', inst='UDcomp-1', meshsens=1E-07, CPU=8, 
    E11=True, E22=True, E33=False, G12=True, G13=False, G23=False, 
    onlyPBC=False, CTE=False, intemp=0, fntemp=100)

作用

随机分布单向长纤维-复合材料RVE模型-abaqus-python二次开发(下)
输出的结果
随机分布单向长纤维-复合材料RVE模型-abaqus-python二次开发(下)