求救:固有频率最大为目标,体积比为约束
固有频率最大为目标,体积比为约束,在一个矩形设计域里4个角固定,设计加速度弹性梁和质量块的最优结构拓扑形式。程序请教热心高手看看我 哪儿有错% use save command to conserve x and m varibles
function husttopoptzcjzcj(nelx,nely,volfrac,penal,rmin)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%penal is penalization factor
% INITIALIZE
m=1;
x(1:nely,1:nelx,m) = volfrac;
loop = 0;
change = 1.;
% START ITERATION
while change > 0.01
loop = loop + 1;
% FE-ANALYSIS
=FE(nelx,nely,x,penal,m); %% 表示质量矩阵的逆矩阵与刚度矩阵乘积,即报告书中矩阵
% OBJECTIVE FUNCTION AND SENSITIVITY ANALYSIS
= lk;
= zl;
c1=0;
c2=0;
c=0;
for ely = 1:nely
for elx = 1:nelx
n1 = (nely+1)*(elx-1)+ely;
n2 = (nely+1)* elx +ely;
Ue = U(,);
= maxtr(Ue); %%调用程序求特征值mt和特征向量my
c1 = x(ely,elx,m)^penal*my'*KE*my;
c2 =x(ely,elx,m)*my'*ME*my;
c= c+c1/c2; %%目标函数
dc(ely,elx) = -penal*x(ely,elx,m)^(penal-1)*my'*KE*my + c*my'*ME*my; %%%敏度分析,后一项“+”“-”还不确定
end
end
% FILTERING OF SENSITIVITIES
= check(nelx,nely,rmin,x,dc,m);
% DESIGN UPDATE BY THE OPTIMALITY CRITERIA METHOD
= OC(nelx,nely,x,volfrac,dc,m);
% PRINT RESULTS
change = max(max(abs(x(:,:,m+1)-x(:,:,m))));
disp([' It.: ' sprintf('%4i',loop) ' Obj.: ' sprintf('%10.4f',c) ...
' Vol.: ' sprintf('%6.3f',sum(sum(x(:,:,m+1)))/(nelx*nely)) ...
' ch.: ' sprintf('%6.3f',change )])
% PLOT DENSITIES
colormap(gray); imagesc(-x(:,:,m+1));axis equal; axis tight; axis off;pause(1e-6);
xc(m)=c; xdc(:,:,m)=dc;
xchange(m)=change; xvol(m)=sum(sum(x(:,:,m+1)))/(nelx*nely);
m=m+1;
if loop >= 200
break;
end
end
save xmdata x xc xdc m xchange xvol;
%%%%%%%%%% OPTIMALITY CRITERIA UPDATE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function =OC(nelx,nely,x,volfrac,dc,m)
l1 = 0; l2 = 100000; move = 0.2;
while (l2-l1 > 1e-4)
lmid = 0.5*(l2+l1);
x(:,:,m+1) = max(0.001,max(x(:,:,m)-move,min(1.,min(x(:,:,m)+move,x(:,:,m).*((-dc./lmid).^0.5)))));%%%%sqrt=0.5 is damping coefficient
if sum(sum(x(:,:,m+1))) - volfrac*nelx*nely > 0
l1 = lmid;
else
l2 = lmid;
end
end
%%%%%%%%%% MESH-INDEPENDENCY FILTER %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function =check(nelx,nely,rmin,x,dc,m)
dcn=zeros(nely,nelx);
for i = 1:nelx
for j = 1:nely
sum=0.0;
for k = max(i-floor(rmin),1):min(i+floor(rmin),nelx)
for l = max(j-floor(rmin),1):min(j+floor(rmin),nely)
fac = rmin-sqrt((i-k)^2+(j-l)^2); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%rimn is filter radius
sum = sum+max(0,fac);
dcn(j,i) = dcn(j,i) + max(0,fac)*x(l,k,m)*dc(l,k);
end
end
dcn(j,i) = dcn(j,i)/(x(j,i,m)*sum);
end
end
%%%%%%%%%% FE-ANALYSIS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function =FE(nelx,nely,x,penal,m)
= lk;
= zl;
K = sparse(2*(nelx+1)*(nely+1), 2*(nelx+1)*(nely+1));
M = sparse(2*(nely+1)*(nelx+1), 2*(nelx+1)*(nely+1));
U = zeros( 2*(nely+1)*(nelx+1),2*(nely+1)*(nelx+1));
for elx = 1:nelx
for ely = 1:nely
n1 = (nely+1)*(elx-1)+ely;
n2 = (nely+1)* elx +ely;
edof = ;
K(edof,edof) = K(edof,edof) + x(ely,elx,m)^penal*KE;%%刚度矩阵
M(edof,edof) = M(edof,edof) + x(ely,elx,m)*ME; %%质量矩阵
end
end
% DEFINE LOADS AND SUPPORTS (HALF MBB-BEAM)
d1=union(,[((nely+1)*2-1):((nely+1)*2)]);
d2=union([(nelx*2*(nely+1)+1):(nelx*2*(nely+1)+2)],[((nely+1)*(nelx+1)*2-1):(nely+1)*(nelx+1)*2]);
fixeddofs=union(d1,d2);%%%固定约束四角点
alldofs = ;%%全约束
freedofs = setdiff(alldofs,fixeddofs);%%自由
% SOLVING
U(freedofs,:) = M(freedofs,freedofs) \ K(freedofs,:)%%源程序中U表示位移, 现在表示质量矩阵的逆矩阵与刚度矩阵乘积,即报告书中矩阵
U(fixeddofs,:)= 0; %%四角固定,不知道刚度矩阵k和质量矩阵m在约束点是多少,如果是位移可以设置为0
%%%%%%%%%% ELEMENT STIFFNESS MATRIX %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function =lk
E = 1.;
nu = 0.3;
k=[ 1/2-nu/6 1/8+nu/8 -1/4-nu/12 -1/8+3*nu/8 ...
-1/4+nu/12 -1/8-nu/8nu/6 1/8-3*nu/8];
KE = E/(1-nu^2)*[ k(1) k(2) k(3) k(4) k(5) k(6) k(7) k(8)
k(2) k(1) k(8) k(7) k(6) k(5) k(4) k(3)
k(3) k(8) k(1) k(6) k(7) k(4) k(5) k(2)
k(4) k(7) k(6) k(1) k(8) k(3) k(2) k(5)
k(5) k(6) k(7) k(8) k(1) k(2) k(3) k(4)
k(6) k(5) k(4) k(3) k(2) k(1) k(8) k(7)
k(7) k(4) k(5) k(2) k(3) k(8) k(1) k(6)
k(8) k(3) k(2) k(5) k(4) k(7) k(6) k(1)];
%%%%%%%%%% Mass STIFFNESS MATRIX 质量矩阵%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function =zl
r=1.;
w=;
ME=r/9*[ w(1) w(2) w(3) w(4) w(5) w(6) w(7) w(8)
w(2) w(1) w(2) w(3) w(4) w(5) w(6) w(7)
w(3) w(2) w(1) w(2) w(3) w(4) w(5) w(6)
w(4) w(3) w(2) w(1) w(2) w(3) w(4) w(5)
w(5) w(4) w(3) w(2) w(1) w(2) w(3) w(4)
w(6) w(5) w(4) w(3) w(2) w(1) w(2) w(3)
w(7) w(6) w(5) w(4) w(3) w(2) w(1) w(2)
w(8) w(7) w(6) w(5) w(4) w(3) w(2) w(1)];
%%%%%%%%%% Eigenvalues and Eigenvectors求特征值和特征向量%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function = maxtr(Ue)
n=length(Ue);
x0=diag(ones(n));
k=1;
x=Ue*x0;
while norm(x-x0)>0.0001
k=k+1;
q=x;
y=x/maxnorm(x);
x=Ue*y;
x0=q;
end
mt=maxnorm(x);
my=y;
%%%%%%%%%% Eigenvalues and Eigenvectors求特征值和特征向量(求取数列中模最大分量)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
functiont= maxnorm(Ue)
n=length(Ue);
t=0;
fori=1:n
if abs(Ue(i)/max(abs(Ue)))>=1
t=Ue(i);
end
end
有搞拓扑优化的同学可以加我多交流:扣扣:358939206 楼主能否简略说明一下问题:
1 “固有频率最大” 指那阶固有频率最大?
2 目标函数是什么?单目标还是多目标?
3 设计变量是什么?网格厚度/材料密度?
4 采用的是0-1规划,还是有二次规划?
5 敏度分析怎么做的? “固有频率最大” ,,不理解 {:{39}:} 这样别人想帮也帮不到你的
页:
[1]