Abaqus用python读取.odb文件

1. 示例文件获取

在Abaqus Command 中输入 ,然后会在工作目录中出现viewer_tutorial.odb.

abaqus fetch job=viewer_tutorial

2. 示例代码

按照代码文件,在Abaqus命令行窗口,一行行输入命令。

# ODb commands available
from odbAccess import *
from abaqusConstants import *

# material and section Odb commands available
from odbMaterial import *
from odbSection import *

# opening an output database
odb = openOdb(path=r'C:\AbaqusWorkfile\test_pythonOdb\viewer_tutorial.odb')

# Reading model data

# The root assembly
myAssembly = odb.rootAssembly

# Part instance determine how many instances
for instanceName in odb.rootAssembly.instances.keys():
  print instanceName

# Regions: A Node set  An element set A surface

for NodeSets in odb.rootAssembly.instances[
  'PART-1-1'].nodeSets.keys():
  print 'Node sets = ', NodeSets

# dispaly the nodes sets and the element sets
print 'Node sets = ', odb.rootAssembly.instances[
    'PART-1-1'].nodeSets.keys()
print 'Element sets = ', odb.rootAssembly.instances[
    'PART-1-1'].elementSets.keys()

# ssigns a variable (topNodeSet) to the 'TOP' node set in the PART-1-1 part instance:
topNodeSet = odb.rootAssembly.instances['PART-1-1'].nodeSets['TOP']

# Reading results data
# Steps
for stepName in odb.steps.keys():
  print stepName

step1 = odb.steps.values()[0]
print step1.name
#Frames  the last frame
lastFrame = odb.steps['Step-1'].frames[-1]

# Reading field output data
for fieldName in lastFrame.fieldOutputs.keys():
    print fieldName
for fieldName in lastFrame.fieldOutputs.values():
    print fieldName

# use the following to view all the available field data in a frame:
# For each field output value in the last frame,
# print the name, description, and type members.

for f in lastFrame.fieldOutputs.values():
    print f.name, ':', f.description
    print 'Type: ', f.type
    # For each location value, print the position.
    for loc in f.locations:
        print 'Position:', loc.position
    print
# Results
# COPEN    TARGET/IMPACTOR: Contact opening
# Type:  SCALAR
# Position: NODAL

# CPRESS   TARGET/IMPACTOR: Contact pressure
# Type:  SCALAR
# Position: NODAL

# CSHEAR1  TARGET/IMPACTOR: Frictional shear
# Type:  SCALAR
# Position: NODAL

# CSLIP1   TARGET/IMPACTOR: Relative tangential motion direction 1
# Type:  SCALAR
# Position: NODAL

# LE: Logarithmic strain components
# Type:  TENSOR_2D_PLANAR
# Position: INTEGRATION_POINT

# RF: Reaction force
# Type:  VECTOR
# Position: NODAL

# RM3: Reaction moment
# Type:  SCALAR
# Position: NODAL

# S: Stress components
# Type:  TENSOR_2D_PLANAR
# Position: INTEGRATION_POINT

# U: Spatial displacement
# Type:  VECTOR
# Position: NODAL

# UR3: Rotational displacement
# Type:  SCALAR
# Position: NODAL

displacement = lastFrame.fieldOutputs['U']
fieldValues = displacement.values

mises = lastFrame.fieldOutputs['S']
fieldValues1 = mises.values

# For each displacement value, print the nodeLabel
# and data members.


for v in fieldValues:
    print 'Node = %d U[x] = %6.4f, U[y] = %6.4f' % (v.nodeLabel,
    v.data[0], v.data[1])

for v in fieldValues1:
    print 'Element = %d Mises = %6.4f' % (v.elementLabel, v.mises)

# lists all the members of a particular FieldValue
fieldValues[1].__members__
# The resulting output is
# ['instance', 'elementLabel', 'nodeLabel', 'position',
#  'face', 'integrationPoint', 'sectionPoint',
#  'localCoordSystem', 'type', 'data', 'magnitude',
#  'mises', 'tresca', 'press', 'inv3', 'maxPrincipal',
#  'midPrincipal', 'minPrincipal', 'maxInPlanePrincipal',
#  'minInPlanePrincipal', 'outOfPlanePrincipal']

# Using regions to read a subset of field output data
center = odb.rootAssembly.instances['PART-1-1'].nodeSets['PUNCH']
# get displacement of subset
# The arguments to getSubset are a region, an element type, a position, or section point data
centerDisplacement = displacement.getSubset(region=center)
centerValues = centerDisplacement.values

for v in centerValues:
    print v.nodeLabel, v.data

## another example
topCenter = \
    odb.rootAssembly.instances['PART-1-1'].elementSets['CENT']
stressField = odb.steps['Step-2'].frames[3].fieldOutputs['S']

# The following variable represents the stress at
# integration points for CAX4 elements from the
# element set "CENT."

field = stressField.getSubset(region=topCenter,
                              position=INTEGRATION_POINT, elementType='CAX4')
# position argument  INTEGRATION_POINT NODAL ELEMENT_NODEL CENTROID
fieldValues2 = field.values
for v in fieldValues2:
    print 'Element label = ', v.elementLabel,
    if v.integrationPoint:
        print 'Integration Point = ', v.integrationPoint
    else:
        print
# For each tensor component.
    for component in v.data:

  # Print using a format. The comma at the end of the
  # print statement suppresses the carriage return.

        print 'S = %10.5f' % component,

# After each tuple has printed, print a carriage return.
#     print

## write file and reading history outputdata
from odbAccess import *
step2 = odb.steps['Step-2']
region = step2.historyRegions['Node PART-1-1.1000']
u2Data = region.historyOutputs['U2'].data
dispFile = open('disp.dat', 'w')
for time, u2Disp in u2Data:
    dispFile.write('%10.4E   %10.4E\n' % (time, u2Disp))
else:
    dispFile.close()



3. 我的代码

目的:用python将米勒指数从odb文件中提取出来。

from abaqusConstants import*
from odbAccess import*
import os
from textRepr import*
import numpy as np
myodb = openOdb(path=r'C:\AbaqusWorkfile\FIB\try-model-210601-1.odb')

myFrames = myodb.steps["Step-1"].frames

# ff = (["SDV52"]["SDV65"]["SDV78"]
# ["SDV91"]["SDV104"]["SDV117"])
sdv52field = myFrames[-1].fieldOutputs["SDV52"]


elementSets = odb.rootAssembly.instances['PART-1-1'].elementSets
bb = elementSets.keys()

CRY = []
for a in bb:
    cc = odb.rootAssembly.instances['PART-1-1'].elementSets[a]
    CRY.append(cc)


field = []
for a in CRY:
    dd = sdv52field.getSubset(region=a,
                              position=INTEGRATION_POINT, elementType='C3D8R')
    field.append(dd)

average = []

for a in field:
    fieldValues = a.values
    temp1 = []
    for v in fieldValues:
        temp1 = []
        for value in fieldValues:
            temp1.append(value.data)
    ee = np.mean(temp1)
    average.append(ee)

average = np.array(average)
np.savetxt(r"C:\AbaqusWorkfile\test_pythonOdb\miller.txt", average, fmt="% .10f")

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值