在ABAQUS中为自定义字段输出创建脚本
问题描述:
我想在ABAQUS中创建自定义字段输出。为了概念证明的目的,我想显示从Mohrs圆圈计算出的最大剪切应力,如针对2D外壳所讨论的here。在ABAQUS中为自定义字段输出创建脚本
我有我的代码如下,仅供参考:
from abaqusConstants import *
from odbAccess import *
from math import *
from copy import deepcopy
from caeModules import *
from driverUtils import executeOnCaeStartup
# ******************************************************************************
#Items in this box require student input when changing files
#must input the file path here.
odbPath = "/home/MohrsTest.odb"
odb = session.openOdb(name=odbPath, readOnly=FALSE)
odb = session.odbs[odbPath]
#this will display the instance names. Please choose one to input in line 14.
print odb.rootAssembly.instances.keys()
grout_instance = odb.rootAssembly.instances['SQUARE-1']
# ******************************************************************************
keys = odb.steps.keys()
for key in keys:
step = odb.steps[key]
for frame in step.frames:
print frame.description
Stress = frame.fieldOutputs['S']
#try modifying scalar fields rather than creating new var element by element.
S11=Stress.getScalarField(componentLabel="S11")
S22=Stress.getScalarField(componentLabel="S22")
S12=Stress.getScalarField(componentLabel="S12")
TauMax=((S11+S22)*0.5+sqrt(power((S11-S22)/2, 2)+power(S12, 2)))-((S11+S22)*0.5-sqrt(power((S11-S22)/2, 2)+power(S12, 2)))/2
ThetaP=(atan2(2 * S12, (S11 - S22))/2) * 180/pi
frame.FieldOutput(name='Tau Max', description='Max Tau from Mohrs circle',field=TauMax)
frame.FieldOutput(name='Theta P', description='Thetap as measured ccw from 0 degree',field=Thetap)
odb.save()
odb.close()
# must re - open the output database to see the new custom field output
的Abaqus在尝试计算,因为TAUMAX立即引发错误的“类型错误:需要一个浮动”但是,我尝试使用“工具 - >字段输出 - >从字段创建”,然后在单个帧的cae中创建字段输出。 如果我看重播文件这个动作,我可以看到下面的代码:
s1f1_S = session.odbs['/home/MohrsTest.odb'].steps['Step-1'].frames[1].fieldOutputs['S']
tmpField = (((s1f1_S.getScalarField(componentLabel="S11")+\
s1f1_S.getScalarField(componentLabel="S22"))*0.5+sqrt(power((
s1f1_S.getScalarField(componentLabel="S11")-s1f1_S.getScalarField(
componentLabel="S22"))/2, 2)+power(s1f1_S.getScalarField(
componentLabel="S12"), 2)))-((s1f1_S.getScalarField(componentLabel="S11")+\
s1f1_S.getScalarField(componentLabel="S22"))*0.5-sqrt(power((
s1f1_S.getScalarField(componentLabel="S11")-s1f1_S.getScalarField(
componentLabel="S22"))/2, 2)+power(s1f1_S.getScalarField(
componentLabel="S12"), 2))))/2
因此,在FieldObject明确的数学运算,必须是可行的。为什么我的代码不允许这样做?
我很高兴提供所有.odb和.cae文件供参考和验证。
答
我很肯定本机脚本使用numpy
作为数学函数。但numpy.sqrt
被覆盖时from math import *
。 math.sqrt
无法处理由.getScalarField()
生成的numpy
阵列,并且出现错误。
这也是我的想法,但如果你看到我的第二个代码块,它就是这样。 – User2341
是的,但运行导入'数学'的脚本? –
第二个代码块直接来自ABAQUS重放文件。我很乐意提供整个重放文件,但它不会导入任何不寻常的东西。它有从abaqus进口* ... – User2341