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.
 
 
 

262 lines
7.6 KiB

function mp= Build_Feria()
% Bulid mp obj (contains models and all arguments)
%% init
pace=3.33;
Pst=[-140 -40 -10]-pace*0.52;
Ped=[30 40 10];
Ped=FCM_dV.round_Ped(Pst,Ped,pace);
maxdeep=4;
order=2;
viewxy=[0 60];
Shape.accessThreshold(pace/maxdeep/2/2/2);%
Oa=[0 0 0];
Ra=[0 0 0];
rvec=(Ped-Pst)/pace
num_cells=rvec(1)*rvec(2)*rvec(3)
fprintf("num_cells: %.0f\n",num_cells);% show num of cells
%% add SS lib & python path
additon_path=pwd;
if count(py.sys.path,additon_path) == 0
insert(py.sys.path,int32(0),additon_path);
end
%% assemble c0
c=CSG("STL",[pwd,'/asset/SolidWoks Files/Feria/stp1.STL'],'init');
cir_up_2d=Circle([-63.6,-117.95,0],140);
cir_down_2d=Circle([-45.17 -67.23 0],70);
cir_left_2d=Circle([-105 0 0],40);
cir_right_2d=Circle([0 0 0],40);
cir1_2d=Circle([-63.36 17.05 0],5);
cir2_2d=Circle([-42.30 15.36 0],5);
cir3_2d=Circle([-44.33 7.76 0],5);
cir4_2d=Circle([-60.43 6.20 0],5);
line1_2d=Line([0 0 0],[1 1 0]);
obs1=Observer(line1_2d);
obs1.modify_line_poins_by_circle1(cir1_2d,1);
cir1_2d.addlistener('propChanged',@obs1.modify_line_poins_by_circle1);
line2_2d=Line([0 0 0],[1 1 0]);
obs2=Observer(line2_2d);
obs2.modify_line_poins_by_circle2(cir2_2d,1);
cir2_2d.addlistener('propChanged',@obs2.modify_line_poins_by_circle2);
line3_2d=Line([0 0 0],[1 1 0]);
obs3=Observer(line3_2d);
obs3.modify_line_poins_by_circle3(cir3_2d,1);
cir3_2d.addlistener('propChanged',@obs3.modify_line_poins_by_circle3);
line4_2d=Line([0 0 0],[1 1 0]);
obs4=Observer(line4_2d);
obs4.modify_line_poins_by_circle4(cir4_2d,1);
cir4_2d.addlistener('propChanged',@obs4.modify_line_poins_by_circle4);
tmp_csg=(cir_up_2d-cir_down_2d-cir_left_2d-cir_right_2d)*(line1_2d*line2_2d*line3_2d*line4_2d)+...
(cir1_2d+cir2_2d+cir3_2d+cir4_2d);
% tmp_csg=cir_right_2d;
skt=Sketch([0 0 -10],Ra,20,tmp_csg);
neg_skt=CSG();neg_skt.init(skt,'neg');
neg_skt.set_display_args(Pst,Ped,pace/2,'viewxy',viewxy);
neg_skt.display_csg();
c=c-neg_skt;
V0=1;
% time and calculate Volume
tic
fcmv=FCM_V(Pst,Ped,pace,maxdeep,order,@c.calSF,@(X) ones(size(X,1),1));% |||1 dV
V0=fcmv.calIntegral_V();
fprintf('V0: %f ,Time: %f\n',V0,toc);
%% build Dirichlet/Neumann boundary
eepsD=1e-1;
eepsN=1e-1;
Dc1=Circle([-105 0 0],15);
Dc2=Circle([-105 0 0],15-eps);
Dcube1=Rect([-109 14.46 0],[-101 20.73 0],false);
Dcube2=Rect([-109 14.46 0],[-101 20.73 0],false);
Dcskt=(Dc1-Dc2)+(Dcube1-Dcube2);
skt=Sketch([0 0 -10],Ra,10*2,Dcskt);
Dirich_csg=CSG();
Dirich_csg.init(skt,'Dir');
Dirich_csg.judge_func=@(X) abs(vecnorm(X(:,1:2)-[-105 0],2,2)-15)<eepsD | (X(:,1)>=-109-eepsD & X(:,1)<=-101+eepsD & X(:,2)<20.73+eepsD & X(:,2)>14.46-eepsD);
%------------------------------------------Neu
Nc1=Circle(Oa,10);
Nc2=Circle(Oa,10-eps);
Ncskt=(Nc1-Nc2);
skt=Sketch([0 0 -10],Ra,10*2,Ncskt);
Neuman_csg=CSG();
Neuman_csg.init(skt,'Neu');
Neuman_csg.judge_func=@(X) abs(vecnorm(X(:,1:2)-[0 0],2,2)-10)<eepsN;
Neuman_csg.fdv=@cal_NeuF;
fcmdv=FCM_dV(Pst,Ped,pace,maxdeep,order,@c.calSDF,@(X) ones(size(X,1),1));% |||1 dV
S0=fcmdv.calIntegral_S(Dirich_csg)
Sstd=1723+160+125.39*2;
relaSD=(S0-Sstd)/Sstd
S1=fcmdv.calIntegral_S(Neuman_csg)
S1std=2*pi*10*20;
relaSN=(S1-S1std)/S1std
%% show model
clf;
% c=(CSG("NULL")*Dirich_csg)+c;
c.set_display_args(Pst,Ped,pace/2,'viewxy',viewxy);
c.saveAs('c');
c.display_csg();
%% init mp(save handle)
mp=ModelPlus(Pst,Ped,pace,order,maxdeep);
mp.c=c;
mp.Dirich_csg=Dirich_csg;
mp.Neuman_csg=Neuman_csg;
mp.V0=V0;
mp.viewxy=viewxy;
mp.E=2e11*1e-3;
mp.u=0.3;
if 1 && order<3
saveKeH=SaveKe(mp,@compute_B_in_local,mp.pace,mp.order,mp);
mp.saveKe=saveKeH;
end
%% set args here
mp.fixedDir=1;
mp.fixedNeu=1;
mp.iscontrast=1;
mp.isrecord=1;
mp.frac=0.9;
mp.maxloop=100;
mp.interp_eeps=3.33/4;
%% save handle here
mp.handleMap('cir1')=cir1_2d;
mp.handleMap('cir2')=cir2_2d;
mp.handleMap('cir3')=cir3_2d;
mp.handleMap('cir4')=cir4_2d;
mp.handleMap('cir_up')=cir_up_2d;
mp.handleMap('cir_down')=cir_down_2d;
mp.handleMap('cir_left')=cir_left_2d;
mp.handleMap('cir_right')=cir_right_2d;
%% init fmt
tic
fmt=FeatureMappingTable(c,Pst,Ped,pace);
fmt.reflash_table();
tini=toc;
mp.recorder.time_maintain_fmt(end+1)=tini;
mp.fmt=fmt;
fprintf('num_node: %f\n',mp.id_cnt);
%% init x
% cir_up_2d=Circle([-63.6,-117.95,0],140);
% cir_down_2d=Circle([-45.17 -67.23 0],70);
% cir_left_2d=Circle([-105 0 0],40);
% cir_right_2d=Circle([0 0 0],40);
% cir1_2d=Circle([-63.36 17.05 0],5);
% cir2_2d=Circle([-42.30 15.36 0],5);
% cir3_2d=Circle([-44.33 7.76 0],5);
% cir4_2d=Circle([-60.43 6.20 0],5);
x0=[-63.36 17.05 5 -42.30 15.36 5 -44.33 7.76 5 -60.43 6.20 5 140 70 40 40]';
lb=[-100 10 1 -50 10 1 -50 -30 1 -100 -30 1 110 60 30 20]';
ub=[-50 40 20 0 40 20 0 10 20 -50 10 20 155 100 50 50]';
mp.handleMap('x0')=x0;
mp.handleMap('lb')=lb;
mp.handleMap('ub')=ub;
mp.handleMap('modify_func')=@modify_c_by_x;
mp.handleMap('constrast_list')= ...
{@constrast1_left @constrast1_up @constrast2_up @constrast2_right...
@constrast3_right @constrast3_down @constrast4_down @constrast4_left};
modify_c_by_x(x0,mp)
end
function modify_c_by_x(x,mp)
for i=1:4
cur_str=['cir' num2str(i)];
cur_h=mp.handleMap(cur_str);
cur_h.Oa=[x(3*i-2:3*i-1)' 0];
cur_h.set_property('r',x(3*i),false);
end
cur_h=mp.handleMap('cir_up');
cur_h.set_property('r',x(13),false);
cur_h=mp.handleMap('cir_down');
cur_h.set_property('r',x(14),false);
cur_h=mp.handleMap('cir_left');
cur_h.set_property('r',x(15),false);
cur_h=mp.handleMap('cir_right');
cur_h.set_property('r',x(16),false);
end
function ret=cal_NeuF(X)
r=10;
h=20;
Or=[0 0];
fx_vec=[-100 0 0]/h*1e3*2/pi/r;
fy_vec=[0 200 0]/h*1e3*2/pi/r;
unit_fx=fx_vec(1:2)./norm(fx_vec(1:2));
unit_fy=fy_vec(1:2)./norm(fy_vec(1:2));
vec_X=X(:,1:2)-Or;
unit_X=vec_X./vecnorm(vec_X,2,2);
the_cos_x=unit_X*unit_fx';
the_cos_y=unit_X*unit_fy';
the_cos_x(the_cos_x<0)=0;
the_cos_y(the_cos_y<0)=0;
ret=unit_X.*(the_cos_x.*abs(fx_vec(1))+ the_cos_y.*abs(fy_vec(2)));
ret=[ret,zeros(size(ret,1),1)];
end
function val=constrast1_left(x)
val=norm(x(1:2)'-Observer.cir_left(1:2))-x(3)-x(15);
end
function val=constrast1_up(x)
val=norm(x(1:2)'-Observer.cir_up(1:2))+x(3)-x(13);
end
function val=constrast2_up(x)
val=norm(x(4:5)'-Observer.cir_up(1:2))+x(6)-x(13);
end
function val=constrast2_right(x)
val=norm(x(4:5)'-Observer.cir_right(1:2))-x(6)-x(16);
end
function val=constrast3_right(x)
val=norm(x(7:8)'-Observer.cir_right(1:2))-x(9)-x(16);
end
function val=constrast3_down(x)
val=norm(x(7:8)'-Observer.cir_down(1:2))-x(9)-x(14);
end
function val=constrast4_down(x)
val=norm(x(10:11)'-Observer.cir_down(1:2))-x(12)-x(14);
end
function val=constrast4_left(x)
val=norm(x(10:11)'-Observer.cir_left(1:2))-x(12)-x(15);
end