今天给大家分享的是abqpy库,该库可以独立于Abaqus,在pycharm或者vscode等IDE环境下运行Python脚本,进而建立参数化建模、提交作业、odb文件后处理分析。
该库由同济大学岩土工程博士Hailin Wang开发,主页:
https://hailin.wang/abqpy/en/2024/index.html
主页内提供了一些实例文件辅助用户使用该库:
https://hailin.wang/abqpy/en/2024/tutorials.html
abqpy基于python3编译运行,建议用户安装Abaqus2024版,最后abqpy库使用pip进行安装:pip install abqpy
我以abqpy附带的一个案例为例,展现该库可以从建模到提交作业以及后处理分析,在不用打开Abaqus CAE的前提下一条龙进行有限元分析。
#!/user/bin/python
# -*- coding:UTF-8 -*-
import numpy as np
from abaqus import *
from abaqusConstants import *
from caeModules import *
from driverUtils import *
from odbAccess import *
def run(modulus, poisson=0.2):
executeOnCaeStartup()
# Model
model = mdb.models["Model-1"]
# Part
sketch = model.ConstrainedSketch(name="sketch", sheetSize=1.0)
sketch.rectangle((0, 0), (1, 1))
part = model.Part(name="part", dimensionality=THREE_D, type=DEFORMABLE_BODY)
part.BaseSolidExtrude(sketch=sketch, depth=1)
# Create sets
part.Set(name="set-all", cells=part.cells.findAt(coordinates=((0.5, 0.5, 0.5),)))
part.Set(name="set-bottom", faces=part.faces.findAt(coordinates=((0.5, 0.5, 0.0),)))
part.Set(name="set-top", faces=part.faces.findAt(coordinates=((0.5, 0.5, 1.0),)))
part.Surface(name="surface-top", side1Faces=part.faces.findAt(coordinates=((0.5, 0.5, 1.0),)))
# Assembly
model.rootAssembly.DatumCsysByDefault(CARTESIAN)
model.rootAssembly.Instance(name="instance", part=part, dependent=ON)
# Material
material = model.Material(name="material")
material.Elastic(table=((modulus, poisson),))
material.Density(table=((2500,),))
# Section
model.HomogeneousSolidSection(name="section", material="material", thickness=None)
part.SectionAssignment(region=part.sets["set-all"], sectionName="section")
# Step
step = model.StaticStep(
name="Step-1",
previous="Initial",
description="",
timePeriod=1.0,
timeIncrementationMethod=AUTOMATIC,
maxNumInc=100,
initialInc=0.01,
minInc=0.001,
maxInc=0.1,
)
# Output request
field = model.FieldOutputRequest("F-Output-1", createStepName="Step-1", variables=("S", "E", "U"))
# Boundary condition
bottom_instance = model.rootAssembly.instances["instance"].sets["set-bottom"]
bc = model.DisplacementBC(
name="BC-1", createStepName="Initial", region=bottom_instance, u1=SET, u2=SET, u3=SET, ur1=SET, ur2=SET, ur3=SET
)
# Load
top_instance = model.rootAssembly.instances["instance"].surfaces["surface-top"]
pressure = model.Pressure("pressure", createStepName="Step-1", region=top_instance, magnitude=100)
# Mesh
elem1 = mesh.ElemType(elemCode=C3D8R)
elem2 = mesh.ElemType(elemCode=C3D6)
elem3 = mesh.ElemType(elemCode=C3D4)
part.setElementType(regions=(part.cells,), elemTypes=(elem1, elem2, elem3))
part.seedPart(size=0.1)
part.generateMesh()
# Job
job = mdb.Job(name="Job-1", model="Model-1")
job.writeInput()
# Submit the job
job.submit()
job.waitForCompletion()
mdb.saveAs("compression.cae")
# Open output database
odb = session.openOdb("Job-1.odb")
# Show the output database in viewport
session.viewports["Viewport: 1"].setValues(displayedObject=odb)
# Extract output data
dataList = session.xyDataListFromField(
odb=odb, outputPosition=NODAL, variable=(("U", NODAL, ((COMPONENT, "U3"),)),), nodeSets=("INSTANCE.SET-TOP",)
)
data = np.array(dataList[0])
np.savetxt("data.csv", data, header="time,U3", delimiter=",", comments="")
if __name__ == "__main__":
# E, mu = sys.argv[-1].split(",")
E, mu = 1000, 0.3
run(float(E), float(mu))
在pycharm中运行完成后,可生成Abaqus的一些附带文件以及用户指定输出的位移结果excel文件。
对于Abaqus-Python日常需求量大的小伙伴,该库是个非常不错的效率工具,希望对大家有所帮助,感谢您的阅读。