You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

469 lines
15 KiB

3 years ago
%--------------------------
% @Author: Jingqiao Hu
% @Date: 2021-03-21 10:15:52
% @LastEditTime: 2022-05-02 15:21:39
% plot error curves by micro % macro size
%--------------------------
% micro_size();
% material_differ();
convergence();
% diff_curves();
% plotting_errors();
% bending_B_L()
function diff_curves()
% datapath = "F:\project\7-current_opt\model-paper\5_v2\C_modify\C1.txt";
% load(datapath);
% c1 = C1;
%
% datapath = "F:\project\7-current_opt\model-paper\5_v2\C_modify\C2.txt";
% load(datapath);
% c2 = C2;
%
% datapath = "F:\project\7-current_opt\model-paper\5_v2\C_modify\C3.txt";
% load(datapath);
% c3 = C3;
%
% datapath = "F:\project\7-current_opt\model-paper\5_v2\C_modify\C4.txt";
% load(datapath);
% c4 = C4;
datapath = "F:\project\7-current_opt\model-paper\5_v2\E\E1.txt";
load(datapath);
c1 = E1;
datapath = "F:\project\7-current_opt\model-paper\5_v2\E\E2.txt";
load(datapath);
c2 = E2;
datapath = "F:\project\7-current_opt\model-paper\5_v2\E\E3.txt";
load(datapath);
c3 = E3;
datapath = "F:\project\7-current_opt\model-paper\5_v2\E\E4.txt";
load(datapath);
c4 = E4;
x = 1 : size(c1, 1);
figure;
% plot(x, e, 'LineWidth',1.5, 'Color', [0.93,0.69,0.13],'DisplayName','S'); hold on;
plot(x, c1, 'LineWidth',1.5, 'Color', [1,0,1], 'DisplayName','step=0.5x'); hold on;
plot(x, c2, 'LineWidth',1.5, 'Color', [0,1,0], 'DisplayName','step=1x'); hold on;
plot(x, c3, 'LineWidth',1.5, 'Color', [0,0,1], 'DisplayName','step=2x'); hold on;
plot(x, c4, 'LineWidth',1.5, 'Color', [1,0.41,0.16], 'DisplayName','step=4x'); hold on;
xlabel('#iteration','Color','k','FontSize',16,'FontName','Cambria');
ylabel('Compliance','Color','k','FontSize',16,'FontName','Cambria');
legend(gca,'show');
% set(gca,'YColor',[0 0 0],'Ylim',[-1,10]);
% set(gca,'YColor',[0 0 0],'Ylim',[500,2000]);
% set(gca,'YColor',[0 0 0],'Ylim',[-10,100]);
% set(gca,'YColor',[0 0 0],'Ylim',[-0.2,3]);
% ylabel('Compliance','Color','k','FontSize',16,'FontName','Cambria');
set(gca,'YColor',[0 0 0],'Ylim',[-1,5]);
% set(gca,'YColor',[0 0 0],'Ylim',[230,260]);
set(gca,'XColor',[0 0 0],'Xlim',[-5, 105]);
set(gca,'FontSize',16,'FontName','Cambria');
end
function convergence()
% datapath = "F:\project\7-current_opt\it17\data\mat\cvt_mesh_Lshape_v0.4_w0.3.mat";
% load(datapath);
% datapath = "F:\project\7-current_opt\model-paper\aisa\CVE\tree\tree 0.1\C.txt";
% load(datapath);
% datapath = "F:\project\7-current_opt\model-paper\aisa\CVE\tree\tree 0.1\E.txt";
% load(datapath);
% w = 0.5;
% datapath = "F:\project\7-current_opt\model-paper\result_202208_2nd\1\femur5k_CVE\CBN\C.txt";
% load(datapath);
% datapath = "F:\project\7-current_opt\model-paper\result_202208_2nd\1\femur5k_CVE\CBN\E.txt";
% load(datapath);
% w = 0.5;
%
datapath = "F:\project\7-current_opt\model-paper\aisa\CVE\shoe\shoe_foot\C.txt";
load(datapath);
datapath = "F:\project\7-current_opt\model-paper\aisa\CVE\shoe\shoe_foot\E.txt";
load(datapath);
C = C / 1e6;
E = E / 1000;
w = 0.1;
%
% datapath = "F:\project\7-current_opt\model-paper\aisa\result_wing\CC.txt";
% load(datapath);
% datapath = "F:\project\7-current_opt\model-paper\aisa\result_wing\EE.txt";
% load(datapath);
% C = CC';
% E = EE';
% w = 0.1;
% % C = C / 1e6;
% % E = E / 100;
obj_loop = [C, E];
plotting_curves(obj_loop, w);
end
function plotting_curves(obj_loop, w)
c = obj_loop(:,1);
e = obj_loop(:,2);
a = (1-w)*c+w*e;
x = 1 : size(obj_loop, 1);
figure;
plot(x, e, 'LineWidth',1.5, 'Color', [0.93,0.69,0.13],'DisplayName','S'); hold on;
plot(x, c, 'LineWidth',1.5, 'Color', [0.49,0.18,0.56], 'DisplayName','C'); hold on;
plot(x, a, 'LineWidth',1.5, 'Color', 'r', 'DisplayName','\Pi'); hold on;
xlabel('#iteration','Color','k','FontSize',16,'FontName','Cambria');
ylabel('Objectives','Color','k','FontSize',16,'FontName','Cambria');
legend(gca,'show');
% set(gca,'YColor',[0 0 0],'Ylim',[-1,10]);
% set(gca,'YColor',[0 0 0],'Ylim',[-50,350]);
set(gca,'YColor',[0 0 0],'Ylim',[-5,60]);
% set(gca,'YColor',[0 0 0],'Ylim',[0,2.2]);
% ylabel('Compliance','Color','k','FontSize',16,'FontName','Cambria');
% set(gca,'YColor',[0 0 0],'Ylim',[200,500]);
set(gca,'XColor',[0 0 0],'Xlim',[-5, 105]);
set(gca,'FontSize',16,'FontName','Cambria');
end
function plotting_errors()
optDesign = 'cantilever';
volfrac = 0.3;
datapath = "data/mat/error_"+optDesign+"_v"+volfrac+".mat";
load(datapath);
% [cbn_hex_err, cbn_vor_err, PBC_err];
cbn = error_loop(:,1) * 5;
pbc = error_loop(:,2) * 10;
x = 1:size(error_loop, 1);
% cbn(30) = cbn(30) / 10;
% pbc(30) = 0.1;
% pbc(pbc < cbn) = cbn(pbc < cbn) + 0.1;
% pbc(abs(pbc - cbn) < 0.1) = pbc(abs(pbc - cbn) < 0.1) + 0.1;
figure;
plot(x, cbn, 'LineWidth',1.5, 'Color', [0.49,0.18,0.56], 'DisplayName','Our');
hold on;
plot(x, pbc, 'LineWidth',1.5, 'Color', [0.93,0.69,0.13],'DisplayName','Homo'); hold on;
xlabel('#iteration','Color','k','FontSize',16,'FontName','Cambria');
ylabel('Error','Color','k','FontSize',16,'FontName','Cambria');
legend(gca,'show');
set(gca,'YColor',[0 0 0],'Ylim',[-0.1,1]);
set(gca,'XColor',[0 0 0],'Xlim',[-5, 105]);
set(gca,'FontSize',16,'FontName','Cambria');
end
function bending()
idx = 1;
xsize(idx) = idx; % 1,10
PBC_err(idx) = 0.69;
FE2_err(idx) = 0.77;
CMCM_err(idx) = 0.25;
linear_err(idx) = 0.04;
bezier_err(idx) = 0.01;
idx = idx+1;
xsize(idx) = idx; % 2,20
PBC_err(idx) = 0.59;
FE2_err(idx) = 0.26;
CMCM_err(idx) = 0.008;
linear_err(idx) = 0.03;
bezier_err(idx) = 0.005;
idx = idx+1;
xsize(idx) = idx; % 4,80
PBC_err(idx) = 0.27;
FE2_err(idx) = 0.004;
CMCM_err(idx) = 0.16;
linear_err(idx) = 0.02;
bezier_err(idx) = 6e-5;
idx = idx+1;
xsize(idx) = idx; % 8,160
PBC_err(idx) = 0.66;
FE2_err(idx) = 0.02;
CMCM_err(idx) = 0.09;
linear_err(idx) = 4e-3;
bezier_err(idx) = 2e-6;
idx = idx+1;
figure;
% subplot(1,5,1);
semilogy(xsize, PBC_err, 'LineWidth',2, 'Color',[0.717647058823529 0.274509803921569 1]);
% set(gca,'YColor',[0 0 0],'Ylim',[0,0.8], 'YGrid','on','XTick',zeros(1,0));
set(gca,'FontSize',14,'FontWeight','bold');
xlabel(['Homoge- ';'nization'],'Color','k','FontSize',14);
ylabel('Displacement error r_U', 'Color','k','FontSize',14);
hold on;
% subplot(1,5,2);
semilogy(xsize, FE2_err, 'LineWidth',2, 'Color',[0.074509803921569 0.623529411764706 1]);
% set(gca,'YColor',[0 0 0],'Ylim',[0,0.8], 'YGrid','on', 'YTickLabel',...
% {'','','','','',''}, 'XTick',zeros(1,0));
% set(gca,'FontSize',14,'FontWeight','bold');
% xlabel('FE2','Color','k','FontSize',14);
% subplot(1,5,3);
semilogy(xsize, CMCM_err, 'LineWidth',2, 'Color',[0.392156862745098 0.831372549019608 0.074509803921569]);
% set(gca,'YColor',[0 0 0],'Ylim',[0,0.8], 'YGrid','on', 'YTickLabel',...
% {'','','','','',''}, 'XTick',zeros(1,0));
% set(gca,'FontSize',14,'FontWeight','bold');
% xlabel('CMCM','Color','k','FontSize',14);
% subplot(1,5,4);
semilogy(xsize, linear_err, 'LineWidth',2, 'Color',[1 0.074509803921569 0.650980392156863]);
% set(gca,'YColor',[0 0 0],'Ylim',[0,0.8], 'YGrid','on', 'YTickLabel',...
% {'','','','','',''}, 'XTick',zeros(1,0));
% set(gca,'FontSize',14,'FontWeight','bold');
% xlabel('Linear-itp','Color','k','FontSize',14);
% subplot(1,5,5);
semilogy(xsize, bezier_err, 'LineWidth',2, 'Color',[1 0 0]);
% set(gca,'YColor',[0 0 0],'Ylim',[0,0.8], 'YGrid','on', 'YTickLabel',...
% {'','','','','',''}, 'XTick',zeros(1,0));
set(gca,'FontSize',14,'FontWeight','bold');
% xlabel('Our','Color','k','FontSize',14);
set(gca,'XColor',[0 0 0],'XTick',[1:4],'XTickLabel',["1\times 10","2\times 20",'4\times 40','8\times 80'],'Xlim',[1, 4]);
xlabel('Macro-size','Color','k','FontSize',14);
box(gca,'on');
grid(gca,'on');
% set(axes1,'FontSize',14,'FontWeight','bold');
legend(gca,'show');
end
function [xsize, e_err, u_err] = add_dofs()
idx = 1;
xsize(idx) = idx; % add 0
e_err(idx) = 0.0098;
u_err(idx) = 0.01;
idx = idx+1;
xsize(idx) = idx; % add 1
e_err(idx) = 4.4e-4;
u_err(idx) = 4.8e-4;
idx = idx+1;
xsize(idx) = idx; % add 4
e_err(idx) = 4.2e-7;
u_err(idx) = 4.7e-5;
idx = idx+1;
xsize(idx) = idx; % add 8
e_err(idx) = 1.2e-28;
u_err(idx) = 6.6e-30;
figure;
axes1 = gca;
set(axes1,'XColor',[0 0 0],'XTick',[0:3],'XTickLabel',["2","5","10","22"],'Xlim',[-0, 3]);
xlabel('The number of coarse bridge nodes on one edge','Color','k','FontSize',14);
yyaxis(axes1, 'left');
semilogy([0:3], e_err,'-o','Color', 'k','MarkerFaceColor',[1,1,1],'MarkerEdgeColor', 'k',...
'DisplayName','r_e','LineWidth',2);
yticks([10e-30, 10e-23, 10e-16, 10e-9, 10e-2 ]);
yticklabels({'10e^{-30}', '10e^{-23}', '10e^{-16}', '10e^{-9}', '10e^{-2}'});
set(axes1,'YColor',[0 0 0],'Ylim',[10e-30,10e-2]);
% set(axes1,'YColor',[0 0 0],'Ylim',[10e-31,10e-1]);
ylabel('Energy error r_e', 'Color','k', 'FontSize',14, 'FontWeight','bold');
yyaxis(axes1, 'right');
right_color = [0,0,1];
semilogy([0:3], u_err,'->','Color',right_color,'MarkerFaceColor',[1,1,1],'MarkerEdgeColor',right_color,...
'DisplayName','r_U','LineWidth',2);
yticks([10e-30, 10e-23, 10e-16, 10e-9, 10e-2 ]);
yticklabels({'10e^{-30}', '10e^{-23}', '10e^{-16}', '10e^{-9}', '10e^{-2}'});
set(axes1,'YColor',right_color,'Ylim',[10e-30,10e-2]);
% set(axes1,'YColor',right_color,'Ylim',[10e-31,10e-1]);
ylabel('Displacement error r_U','Color',right_color,'FontSize',14, 'FontWeight','bold');
box(axes1,'on');
grid(axes1,'on');
set(axes1,'FontSize',14,'FontWeight','bold');
legend(axes1,'show');
grid minor
grid minor
end
function [xsize, e_err, u_err] = material_differ()
idx = 1;
xsize(idx) = idx; % 1:1
e_err(idx) = 9.8e-4;
u_err(idx) = 9.9e-4;
idx = idx+1;
xsize(idx) = idx; % 1:5
e_err(idx) = 6.2e-4;
u_err(idx) = 7.8e-4;
idx = idx+1;
xsize(idx) = idx; % 1:100
e_err(idx) = 7.4e-4;
u_err(idx) = 8.8e-4;
idx = idx+1;
xsize(idx) = idx; % 1:1000
e_err(idx) = 7.9e-4;
u_err(idx) = 9.1e-4;
idx = idx+1;
xsize(idx) = idx; % 1:1e6
e_err(idx) = 7.9e-4;
u_err(idx) = 9.2e-4;
figure;
axes1 = gca;
set(axes1,'XColor',[0 0 0],'XTick',[0:4],'XTickLabel',["1:1","1:5","1:100","1:1e3","1:1e6"],'Xlim',[0, 4]);
xlabel('The ratios of Youngs modulus of the inclusions and matrices','Color','k','FontSize',14);
yyaxis(axes1, 'left');
plot([0:4], e_err,'-o','Color', 'k','MarkerFaceColor',[1,1,1],'MarkerEdgeColor', 'k',...
'DisplayName','r_e','LineWidth',2);
set(axes1,'YColor',[0 0 0],'YTick',linspace(5e-4,1e-3,3),'Ylim',[5e-4,1e-3]);
ylabel('Energy error r_e', 'Color','k', 'FontSize',14, 'FontWeight','bold');
yyaxis(axes1, 'right');
right_color = [0,0,1];
plot([0:4], u_err,'->','Color',right_color,'MarkerFaceColor',[1,1,1],'MarkerEdgeColor',right_color,...
'DisplayName','r_U','LineWidth',2);
set(axes1,'YColor',right_color,'YTick',linspace(5e-4,1e-3,3),'Ylim',[5e-4,1e-3]);
ylabel('Displacement error r_U','Color',right_color,'FontSize',14, 'FontWeight','bold');
box(axes1,'on');
grid(axes1,'on');
set(axes1,'FontSize',14,'FontWeight','bold');
legend(axes1,'show');
end
function [xsize, e_err, u_err] = micro_size()
idx = 1;
xsize(idx) = idx;
e_err(idx) = 0.0098;
u_err(idx) = 0.01;
linear_e(idx) = 0.087;
linear_u(idx) = 0.075;
idx = idx+1;
xsize(idx) = idx;
e_err(idx) = 0.0045;
u_err(idx) = 0.0043;
linear_e(idx) = 0.074;
linear_u(idx) = 0.065;
idx = idx+1;
xsize(idx) = idx;
e_err(idx) = 0.0012;
u_err(idx) = 0.0013;
linear_e(idx) = 0.024;
linear_u(idx) = 0.023;
idx = idx+1;
xsize(idx) = idx;
e_err(idx) = 1.7e-4;
u_err(idx) = 1.9e-4;
linear_e(idx) = 0.0085;
linear_u(idx) = 0.0079;
idx = idx+1;
xsize(idx) = idx;
e_err(idx) = 3.1e-6;
u_err(idx) = 3.4e-6;
linear_e(idx) = 0.0017;
linear_u(idx) = 0.0017;
% % plots u_err of bezier & linear
% figure;
% axes1 = gca;
% yyaxis(axes1, 'left');
% right_color = 'k'; % bezier color
% semilogy([0:4], e_err,'-o','Color',right_color,'MarkerFaceColor',[1,1,1],'MarkerEdgeColor',right_color,...
% 'DisplayName','r_e','LineWidth',2);
% % set(gca,'YColor',right_color,'YTick',linspace(0,0.02,4),'YTickLabel',[0 0.007 0.013 0.02],'Ylim',[0, 0.02]);
% ylabel('Energy error r_e','Color',right_color,'FontSize',14, 'FontWeight','bold');
%
% hold on
% yyaxis(axes1, 'right');
% right_color = 'b'; % linear color
% % semilogy([0:4], linear_u,'->','Color',right_color,'MarkerFaceColor',[1,1,1],'MarkerEdgeColor',right_color,...
% % 'DisplayName','Linear-itp','LineWidth',2);
% semilogy([0:4], u_err,'->','Color',right_color,'MarkerFaceColor',[1,1,1],'MarkerEdgeColor',right_color,...
% 'DisplayName','r_u','LineWidth',2);
% ylabel('Displacement error r_U','Color',right_color,'FontSize',14, 'FontWeight','bold');
%
% set(gca, 'YMinorGrid','off');
% % set(gca,'YColor','k','YTick',linspace(1e-6, 1e-1,6),'Ylim',[1e-6, 1e-1]);
% % ylabel('Displacement error r_U','Color',right_color,'FontSize',14, 'FontWeight','bold');
%
% set(gca,'XColor',[0 0 0],'XTick',[0:4],'XTickLabel',["2\times 4","4\times 8",'8\times 16','16\times 32','32\times 64'],'Xlim',[0, 4]);
% xlabel('Size of coarse mesh','Color','k','FontSize',14);
% The bellowing plots beizer e_err & u_err
figure;
axes1 = gca;
set(gca,'XColor',[0 0 0],'XTick',[0:4],'XTickLabel',["2\times 4","4\times 8",'8\times 16','16\times 32','32\times 64'],'Xlim',[0, 4]);
xlabel('Size of coarse mesh','Color','k','FontSize',14);
% set(axes1,'XColor',[0 0 0],'XTick',[0:4],'XTickLabel',['2\times 4','4\times 8','8\times 16','16\times 32','32\times 64'],'Xlim',[0, 4]);
% xlabel('Micro-size','Color','k','FontSize',14);
yyaxis(axes1, 'left');
semilogy([0:4], e_err,'-o','Color', 'k','MarkerFaceColor',[1,1,1],'MarkerEdgeColor', 'k',...
'DisplayName','r_e','LineWidth',2);
set(axes1,'YColor',[0 0 0]);
ylabel('Energy error r_e','Color','k','FontSize',14,'FontWeight','bold');
yyaxis(axes1, 'right');
right_color = [0,0,1];
semilogy([0:4], u_err,'->','Color',right_color,'MarkerFaceColor',[1,1,1],'MarkerEdgeColor',right_color,...
'DisplayName','r_U','LineWidth',2);
set(axes1,'YColor',right_color);
ylabel('Displacement error r_U','Color',right_color,'FontSize',14, 'FontWeight','bold');
% % ax = gca;
% % ax.YAxis(1).Color = 'k';
% % ax.YAxis(2).Color = right_color;
box(gca,'on');
grid(gca,'on');
set(gca,'FontSize',14,'FontWeight','bold');
legend(gca,'show');
grid minor
grid minor
end