haiiliin / abqpy

Type Hints for Abaqus/Python Scripting
https://haiiliin.github.io/abqpy/
MIT License
199 stars 34 forks source link

如何做到像教程一样直接在VScode运行python脚本 #5589

Closed rookie-coder99 closed 5 months ago

rookie-coder99 commented 7 months ago

Describe the bug 我复制了教程中compress的代码直接在vscode中运行但是出现了报错。

from abaqus import *
from abaqusConstants import *
from caeModules import *
from driverUtils import *

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=((1000, 0.2),))
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()

# Save abaqus model
mdb.saveAs("compression.cae")

Screenshots image

haiiliin commented 7 months ago

这是因为你的当前工作路径和脚本路径不在一个盘导致的,可以使用cd命令将工作路径切换到脚本所在盘符,或者在Vscode打开脚本所在文件夹后再运行脚本

rookie-coder99 commented 7 months ago

image 我已经切换到文件所在路径,执行abaqus出现问题,但在cmd下执行'abaqus'是正常的

rookie-coder99 commented 7 months ago

image 我已经切换到文件所在路径,执行abaqus出现问题,但在cmd下执行'abaqus'是正常的

同时我做了测试,如果是以管理员身份打开vscode,在终端运行abaqus能够正常运行,但是打开到工作目录,再次运行又会出现上述报错

haiiliin commented 5 months ago

请将 abqpy 更新到 20**.7.3 版本