Abaqus Python 将关键字插入.inp 文件的命令

Abaqus Python Command to insert keyword to the .inp file

提出这个问题的整个 objective 源于尝试对线性约束方程的创建进行多处理 (http://abaqus.software.polimi.it/v6.14/books/usb/default.htm?startat=pt08ch35s02aus129.html#usb-cni-pequation) in Abaqus/CAE for applying periodic boundary conditions to a meshed model. Since my model has over a million elements and I need to perform a Monte Carlo simulation of 1000 such models, I would like to parallelize the procedure for which I haven't found a solution due to the licensing and multi-threading restrictions associated with Abaqus/CAE. Some discussions on this here:

我目前正在尝试使用创建的节点集在 Abaqus 之外执行方程式定义,因为我知道输入文件的方程式语法。

** Constraint: <name>
*Equation
<dof>
<set1>, <dof>, <coefficient1>.
<set2>, <dof>, <coefficient2>.
<set3>, <dof>, <coefficient3>.

e.g.
** Constraint: Corner_c1_Constraint-1-pair1
*Equation
3
All-1.c1_Node-1, 1, 1.
All-1.c5_Node-1, 1, -1.
RefPoint-3.SetRefPoint3, 1, -1.

除了直接将这些行写入 .inp 文件之外,我还可以将这些命令作为一个单独的文件写入,然后 link 使用

将其写入模型的 .inp 文件
*EQUATION, INPUT=file_name

我正在寻找 Abaqus Python 命令来将上述关键字写入 .inp 文件,而不是自己指定方程式约束。 上面的用户指南 linked 指示通过 GUI 进行指定,但我无法在我的 Abaqus CAE 2018 版本中执行此操作。

Abaqus/CAE 用法:
交互模块:创建约束:方程:将光标悬停在数据上时单击鼠标按钮 3 table,然后 select 从文件中读取。

所以我正在寻找脚本参考手册中的命令来执行此操作。有解析输入文件的命令(http://abaqus.software.polimi.it/v6.14/books/ker/pt01ch24.html),但没有直接写入输入文件而不是通过脚本执行的命令。我知道我可以将其硬编码到输入文件中,但我想要执行的大量模拟调用了可能的每一点自动化。我已经尝试使用适当的算法和 numpy 数组优化代码,但预处理本身需要数小时才能处理一个模型。

p.s。这是我第一次 post 关于 SO - 所以我不确定这个问题是否以适当的格式表达。希望对实际问题的任何答案或对 Abaqus/CAE 中预处理步骤并行化的预期结果的任何其他解决方案表示赞赏。

您正在查找 KeywordBlock 对象。这允许您将任何内容(关键字、评论等)作为格式化字符串写入输入文件。我相信这种方法比需要您自己以编程方式编写输入文件(或更新现有文件)的替代方法更不容易出错。

KeywordBlock 对象是在程序集级别创建部件实例时创建的。它使用相应的关键字存储您在 CAE 中所做的一切。

请注意,您对 KeywordBlock 对象所做的任何更改都将在写入时同步到作业输入文件,但不会更新 CAE 模型数据库。因此,例如,如果您使用 KeywordBlock 来存储约束方程的关键字,则约束定义将不会显示在 CAE 模型树中。 Mdb 的其余部分不知道它们的存在。

如您所知,必须将关键字写入输入文件的适当部分。例如,*equation 关键字可以在零件、零件实例或装配级别定义(请参阅关键字参考手册)。当您将关键字存储在 KeywordBlock 对象中时,也必须考虑这一点(不幸的是,它不会自动神奇地将您的关键字放在正确的位置!)。一个副作用是写入 KeywordBlock 并不总是安全的——也就是说,只要它可能与通过 CAE GUI 进行的后续更改发生冲突。我相信 Abaqus 文档建议您在最后一步添加关键字。

基本上,阅读 KeywordBlock 对象,找到正确的位置,然后 insert 您的新关键字。以下是帮助您入门的示例片段:

partname = "Part-1"
model = mdb.models["Model-1"]
modelkwb = model.keywordBlock
assembly = model.rootAssembly

if assembly.isOutOfDate:
    assembly.regenerate()

# Synch edits to modelkwb with those made in the model. We don't need
# access to *nodes and *elements as they would appear in the inp file,
# so set the storeNodesAndElements arg to False.
modelkwb.synchVersions(storeNodesAndElements=False)

# Search the modelkwb for the desired insertion point. In this example, 
# we are looking for a line that indicates we are beginning the Part-Level 
# block for the specific Part we are interested in. If it is found, we 
# break the loop, storing the line number, and then write our keywords
# using the insert method (which actually inserts just below the specified
# line number, fyi). 
line_num = 0
for n, line in enumerate(modelkwb.sieBlocks):
    if line.replace(" ","").lower() == "*part,name={0}".format(partname.lower()):
        line_num = n
        break
if line_num:
    kwds = "your keyword as a string here (may be multiple lines)..."
    modelkwb.insert(position=line_num, text=kwds)
else:
    e = ("Error: Part '{}' was not found".format(partname),
         "in the Model KeywordBlock.")
    raise Exception(" ".join(e))