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ù)庫(kù)中提取場(chǎng)變量計(jì)算結(jié)果顽腾。
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.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末聊训,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌腿椎,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,126評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異砾跃,居然都是意外死亡冒滩,警方通過查閱死者的電腦和手機(jī)毕箍,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,254評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門腮鞍,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)值骇,“玉大人,你說我怎么就攤上這事移国≈ù瘢” “怎么了?”我有些...
    開封第一講書人閱讀 152,445評(píng)論 0 341
  • 文/不壞的土叔 我叫張陵迹缀,是天一觀的道長(zhǎng)使碾。 經(jīng)常有香客問我,道長(zhǎng)祝懂,這世上最難降的妖魔是什么票摇? 我笑而不...
    開封第一講書人閱讀 55,185評(píng)論 1 278
  • 正文 為了忘掉前任,我火速辦了婚禮砚蓬,結(jié)果婚禮上矢门,老公的妹妹穿的比我還像新娘。我一直安慰自己灰蛙,他們只是感情好祟剔,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,178評(píng)論 5 371
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著摩梧,像睡著了一般物延。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上仅父,一...
    開封第一講書人閱讀 48,970評(píng)論 1 284
  • 那天叛薯,我揣著相機(jī)與錄音,去河邊找鬼驾霜。 笑死案训,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的粪糙。 我是一名探鬼主播强霎,決...
    沈念sama閱讀 38,276評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼蓉冈!你這毒婦竟也來(lái)了城舞?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,927評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤寞酿,失蹤者是張志新(化名)和其女友劉穎家夺,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體伐弹,經(jīng)...
    沈念sama閱讀 43,400評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡拉馋,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,883評(píng)論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片煌茴。...
    茶點(diǎn)故事閱讀 37,997評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡随闺,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出蔓腐,到底是詐尸還是另有隱情矩乐,我是刑警寧澤,帶...
    沈念sama閱讀 33,646評(píng)論 4 322
  • 正文 年R本政府宣布回论,位于F島的核電站散罕,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏傀蓉。R本人自食惡果不足惜欧漱,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,213評(píng)論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望僚害。 院中可真熱鬧硫椰,春花似錦繁调、人聲如沸萨蚕。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,204評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)岳遥。三九已至,卻和暖如春裕寨,著一層夾襖步出監(jiān)牢的瞬間浩蓉,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,423評(píng)論 1 260
  • 我被黑心中介騙來(lái)泰國(guó)打工宾袜, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留捻艳,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,423評(píng)論 2 352
  • 正文 我出身青樓庆猫,卻偏偏與公主長(zhǎng)得像认轨,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子月培,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,722評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容