Matlab & Abaqus & Python

Matlab & Abaqus & Python


1. Operate Abaqus with Matlab

Matlab has a lot of command to run other softwares like dos,system,!,unix, etc. Here we use the command dos as a demo.

[s,w]=dos('abaqus job=1 inp=RW2.inp user=nam_sn-std.obj int','-echo');

In which the command dos means to open the CMD in windows, and the following strings is the command you want to run in the CMD. abaqus is the command to run abaqus command lines. job=1 means you job's name is '1', inp=xxxx is the inp file you want to submit to Abaqus, user is the command you need when you have a user defined subroutine file to add in the job session. The int means that the log information will show on the screen during calculation which is important because you need the command window to remain rolling so that you can run other commands only when the last calculation finishes. -echo means the information will show on the command window of Matlab which will also be stored in the variable 'w'.

Before you start the calculation, several proper .inp files are needed for the stochastic simulation. Here I use Matlab to read the .inp file that have already been built by Abaqus into a 'cell' kind of variable. This 'cell' is large array matrix with string as element. Every line in the file becomes a string element in the array. What's left is to find out which line you need to change and the location of the commands you want to add on. Then write the changed 'cell' into a new file.

Big discovery today, the inp file for the Abaqus command need to be more strict in format than the Abaqus cae, especially no blank lines inside one session. But the Abaqus cae can import the wrong inp file as a model.

2. Operate Python with Matlab

It's the same as the former one, because the dos command can run all the command that runs in the CMD window.

The interesting thing is the Python langurage, the data structure in this langurage is very powerful, the odb file of the Abaqus is also this kind of data structure, that's why Python is very useful in post-processing. Here I use Python to decompose the odb file and take out the displacement and the reaction force.

from odbAccess import *
odb = openOdb(path='Job-mc1.odb')

# 從輸出數(shù)據(jù)庫中提取場變量計算結果。
s2 = odb.steps['Step-2']
Ux1 = s2.historyRegions['Node RW2-1.48'].historyOutputs['U1'].data

Fx1 = s2.historyRegions['Node RW2-1.1'].historyOutputs['RF1'].data

print Ux1
print Fx1

Then the after code are used in Matlab:
[s,w]=dos('abaqus python readdata.py >> temp.txt');
The output of CMD will be stored in the temp.txt file and the last two rows will be the displacement and the force.

A problem pops up, because the data in temp.txt has a format below:

((0.0, -9840.1611328125), (0.0010000000474974513, -10147.7822265625), (0.0020000000949949026, -10139.9453125),...)

Which Matlab can't read, so I use:

tem=strrep(ordata,'(','[');
tem=strrep(tem,')',']');
tem=strrep(tem,'],','];');
U=str2num(tem);

to change the buklet so that Matlab can read it as a matrix.

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容