简体   繁体   English

使用 python 中的 abaqus 运行 abaqus inp 文件

[英]Run abaqus inp file with abaqus from python

I am trying to run abaqus inp file and process it with abaqus from python and get the output.我正在尝试运行 abaqus inp 文件并使用 python 中的 abaqus 处理它并获取输出。 It is not working.它不工作。 How can it be done?怎么做到呢?

import os
import subprocess

inp = 'C:/Users/sel/Desktop/My work/Python Abaqus/New folder (2)/Job-1.inp'
abaqus = r'C:/SIMULIA/Abaqus/Commands/abq6145.bat'
subprocess.Popen("%s %s" % (abaqus, inp))

You can capture stdout and strerr of a subprocess through the run function of the subprocess module by setting the capture_output keyword argument to True .通过将capture_output关键字参数设置为True您可以通过 subprocess 模块的run函数捕获子流程的 stdout 和 strerr 。 This should work.这应该有效。

inp = 'C:/Users/sel/Desktop/My work/Python Abaqus/New folder (2)/Job-1.inp'
abaqus = r'C:/SIMULIA/Abaqus/Commands/abq6145.bat'
cp = subprocess.run([abaqus, inp], capture_output=True)
cp.stdout

You're in the wrong directory and you're not specifying the job correctly.您位于错误的目录中,并且没有正确指定作业。 The correct command line syntax to start solving c:\\temp\\whatever.inp file is:开始解决 c:\\temp\\whatever.inp 文件的正确命令行语法是:

cd \temp
abaqus job=whatever

I think this way might help you:我认为这种方式可能会帮助您:

First, prepare your .inp file (the initial simulation: mySim.inp)首先,准备您的 .inp 文件(初始模拟:mySim.inp)

Second, in a python script (let's call it RunSim.py) write:其次,在 Python 脚本(我们称之为 RunSim.py)中写入:

from subprocess import check_output
check_output("abaqus job=mySim.inp double cpus=4 interactive", shell=True)

You can change cpus depending on your computer.您可以根据您的计算机更改CPU

Third, add also this line:第三,还添加这一行:

check_output("abaqus cae noGUI=odb_reader.py", shell=True)

Forth, in the odb_reader.py, you should write a function to read the odb file and save the result a csv file.第四,在 odb_reader.py 中,您应该编写一个函数来读取 odb 文件并将结果保存为 csv 文件。 If you want to do an optimization, you can then open this csv file in the RunSim,py file and extracted the value that you want as the objective function.如果要进行优化,则可以在 RunSim,py 文件中打开此 csv 文件并提取所需的值作为目标函数。

So if you want to iteratively run RunSim.py file, you may need also to delete the scratch file after each iteration.所以如果你想迭代运行 RunSim.py 文件,你可能还需要在每次迭代后删除临时文件。 You can use this:你可以使用这个:

os.remove("mySim.sim")  

... ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM