MATLAB启动ABAQUS——优化
MATLAB启动ABAQUS,提取odb,将ABAQUS模型视作MATLAB的一个函数,用于优化分析
inpName = 'Job-1';
workDir = 'G:\CABLE_CON\TEXT2';
runabaqus(workDir,inpName);
% 运行py脚本文件
system(['abaqus viewer noGui=','out_F.py']);
% 载入数据
t=load('F1.txt');
COOR=load('weizi.txt');
%--------------------------------------------------------------------------------------------------------------
function xx=runabaqus(workDir,inpFile)
MatlabPath=pwd();
cd(workDir);
inputFile=['abaqus job=',inpFile];
system(inputFile);
pause(5);
t0=tic;
cd(MatlabPath);
if (exist([workDir,'\',inpFile,'.lck'],'file')==2)
while exist([workDir,'\',inpFile,'.lck'],'file')==2
t=toc(t0);
h=fix(t/3600);
m=fix(mod(t,3600)/60);
sec=fix(mod(mod(t,3600),60));
pause(1);
fprintf('-ABAQUS calculating-\n time costed %d:%d:%d\n',h,m,sec);
end
fprintf('---------ABAQUS complete---------\n time costed %d:%d:%d\n',h,m,sec);
xx=1;
else
fprintf('\n runabaqus error:InpFile submmit failed\n');
xx=0;
end
end
更新迭代采集步数的程序代码
from odbAccess import *
from abaqusConstants import *
from odbMaterial import *
from odbSection import *
import math
将当前步数写到cycle.txt 文件下
f=open('cycle.txt','r')
n=f.read()
f.close()
读取odb文件
odb = openOdb(path=r'G:\CABLE_CON\TEXT2\Job-' + n + '.odb')
取odb文件中最后一个分析步进行数据提取
Step_1=odb.steps['Step-'+n]
region = Step_1.historyRegions['Element ASSEMBLY.1']
xy1=region.historyOutputs['CTF1'].data[300]
s=str(xy1)
s = s.replace("(", "")
s = s.replace(")", "")
disFile=open('F1.txt','w')
disFile.write(s)
disFile.close()
lastFrame=Step_1.frames[-1]
Zuobiao=lastFrame.fieldOutputs['COORD']
Regioncare=odb.rootAssembly.nodeSets['RP']
Coor1=Zuobiao.getSubset(region=Regioncare)
Zuobiao_x=Coor1.values[0].data[0]
Zuobiao_y=Coor1.values[0].data[1]
Zuobiao_z=Coor1.values[0].data[2]
Zhuanjiao=lastFrame.fieldOutputs['UR']
ZJ=Zhuanjiao.getSubset(region=Regioncare)
Zhuanjiao_x=ZJ.values[0].data[0]
Zhuanjiao_y=ZJ.values[0].data[1]
Zhuanjiao_z=ZJ.values[0].data[2]
total=Zuobiao_x,Zuobiao_y,Zuobiao_z,Zhuanjiao_x,Zhuanjiao_y,Zhuanjiao_z
s1=str(total)
s1 = s1.replace("(", "")
s1 = s1.replace(")", "")
disFile=open('weizi.txt','w')
disFile.write(s1)
disFile.close()
# 运行python脚本文件
function a=runpython(workDir,Py_name,cycle)
MatlabPath=pwd();
cd(workDir);
fid1= fopen('cycle.txt','wt');
fprintf(fid1,'%d',cycle);
fclose(fid1);
system(['abaqus viewer noGui=',Py_name]);
cd(MatlabPath);
a=1;
end
查看更多评论 >