【问题标题】:Creating a script for a custom field output in ABAQUS在 ABAQUS 中为自定义字段输出创建脚本
【发布时间】:2017-07-04 19:37:12
【问题描述】:

我想在 ABAQUS 中创建一个自定义字段输出。出于概念证明的目的,我想显示从莫尔圆计算得出的最大剪应力,正如 here 对 2D 壳所讨论的那样。

下面有我的代码供参考:

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 文件以供参考和验证。

【问题讨论】:

    标签: python scripting abaqus


    【解决方案1】:

    我很确定原生 Abaqus/CAE 脚本使用 numpy 来处理数学函数。但是当您执行from math import * 时,numpy.sqrt 会被math.sqrt 覆盖。 math.sqrt 无法处理.getScalarField() 生成的numpy 数组,会报错。

    【讨论】:

    • 这也是我的想法,但如果你看到我的第二个代码块,它就是这样做的。
    • 第二个代码块直接来自 ABAQUS 重放文件。我很高兴提供整个重播文件,但它不会导入任何不寻常的东西。它有 from abaqus import *...
    • 我也认为我在代码中尝试了 numpy 的平方根,但它仍然坏了,我可以回去检查一下
    • 您是否尝试过在脚本中不导入math
    • 在您的代码中 S11 是一个 FieldOutput 对象。这意味着您正在使用专有的 Abaqus 对象,而不是使用 numpy 数组或简单的 Python 数组。默认情况下,Abaqus Python 在全局命名空间中为此类对象提供了一些数学函数。如果您导入任何具有相同名称的函数的模块,在您的情况下,数学,在全局命名空间中这些将被覆盖并且您的脚本将失败。标准数学函数适用于不在 FieldOutput 对象上的数字。
    猜你喜欢
    • 2023-01-07
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2022-06-11
    • 1970-01-01
    • 1970-01-01
    • 2019-12-16
    • 2016-04-16
    相关资源
    最近更新 更多