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.
211 lines
5.2 KiB
211 lines
5.2 KiB
function mp=Build_RotateSampleOptLimitedPos()
|
|
% Bulid mp obj (contains models and all arguments)
|
|
%% init
|
|
pace=0.5;
|
|
Pst=[0 0 0]-pace*0.51;
|
|
Ped=[12 12 6];
|
|
Ped=FCM_dV.round_Ped(Pst,Ped,pace);
|
|
maxdeep=3;
|
|
order=1;
|
|
viewxy=[-30 30];
|
|
|
|
|
|
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,'/SolidWoks Files/BearingBracket/BearingB.STL'],'init');
|
|
cube1=CSG("Cube","corner",[0 0 0],Ra,[12 12 1]);
|
|
cube2=CSG("Cube","corner",[0 0 5],Ra,[12 12 1]);
|
|
c=cube1+cube2;
|
|
|
|
cyObjs=[];
|
|
|
|
|
|
for i=2:2*2:12
|
|
for j=2:2*2:12
|
|
cy=CSG("Cylinder",[i j 0],Ra,0.5,10);
|
|
cyObjs=[cyObjs cy];
|
|
end
|
|
end
|
|
firstFlg=1;
|
|
cys=[];
|
|
for cy=cyObjs
|
|
if firstFlg==1
|
|
firstFlg=0;
|
|
cys=cy;
|
|
else
|
|
cys=cys+cy;
|
|
end
|
|
end
|
|
%% tmp output
|
|
% c.set_display_args([Pst(1) Pst(2) Pst(3)],Ped,pace/5,'viewxy',viewxy);
|
|
% c.csg2stl('/home/cflin/Documents/MATLAB/MatlabCode/TopCSG/NNew_Data/RotateSample/CSG_plates');
|
|
%
|
|
% cys.set_display_args([Pst(1) Pst(2) Pst(3)],Ped,pace/5,'viewxy',viewxy);
|
|
% cys.csg2stl('/home/cflin/Documents/MATLAB/MatlabCode/TopCSG/NNew_Data/RotateSample/CSG_cylinders');
|
|
%
|
|
limitedCube=CSG("Cube","corner",[0 0 0+0.1],Ra,[12 12 6]+[0 0 -0.1]);
|
|
% limitedCube.set_display_args([Pst(1) Pst(2) Pst(3)],Ped,pace/5,'viewxy',viewxy);
|
|
% limitedCube.csg2stl('/home/cflin/Documents/MATLAB/MatlabCode/TopCSG/NNew_Data/RotateSample/CSG_limitedCube');
|
|
%
|
|
% limitedCys=limitedCube*cys;
|
|
% limitedCys.set_display_args([Pst(1) Pst(2) Pst(3)],Ped,pace/5,'viewxy',viewxy);
|
|
% limitedCys.csg2stl('/home/cflin/Documents/MATLAB/MatlabCode/TopCSG/NNew_Data/RotateSample/CSG_limitedCylinders');
|
|
|
|
c=c+(limitedCube*cys);
|
|
|
|
|
|
|
|
%---------------------------assemble c
|
|
|
|
% show model
|
|
clf;
|
|
c.set_display_args([Pst(1) Pst(2) Pst(3)],Ped,pace/5,'viewxy',viewxy);
|
|
c.display_csg();
|
|
% c.csg2stl('/home/cflin/Documents/MATLAB/MatlabCode/TopCSG/NNew_Data/RotateSample/initModel');
|
|
|
|
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;
|
|
|
|
% DC2d=Line([0 0 0],[CubePed(1) 0 0]);
|
|
DC2d=Rect([0 0 0],[12 12 0],false);
|
|
Dskt=Sketch([0 0 0],[0 0 0],1e-9,DC2d);
|
|
Dirich_csg=CSG();Dirich_csg.init(Dskt);
|
|
Dirich_csg.saveAs('Dir');
|
|
Dirich_csg.judge_func=@(X) abs(X(:,3))< eepsD*0.35;
|
|
%------------------------------------------Neu
|
|
|
|
Ncir=Rect([0 0 0],[12 12 0],false);
|
|
Nskt=Sketch([0 0 6],[0 0 0],1e-9,Ncir);
|
|
Neuman_csg=CSG();
|
|
Neuman_csg.init(Nskt,'Neu');
|
|
Neuman_csg.judge_func=@(X) X(:,1)>0 & X(:,1)<12 & X(:,2)>0 & X(:,2)<12 & abs(X(:,3)-6)<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=12*12;
|
|
relaSD=(S0-Sstd)/Sstd
|
|
|
|
S1=fcmdv.calIntegral_S(Neuman_csg)
|
|
S1std=0.25
|
|
relaSN=(S1-S1std)/S1std
|
|
|
|
%% show model
|
|
clf;
|
|
c.set_display_args([Pst(1) 0 Pst(3)],Ped,pace/2,'viewxy',viewxy);
|
|
c.saveAs('c');
|
|
c.display_csg();
|
|
% c.set_display_args([Pst(1) 0 Pst(3)],Ped,pace/8,'viewxy',viewxy);
|
|
% c.csg2stl('./orgModel');
|
|
|
|
|
|
|
|
%% 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=0;
|
|
mp.isrecord=1;
|
|
mp.frac=1.2;
|
|
mp.maxloop=60;
|
|
mp.interp_eeps=pace/(2^(maxdeep-1));
|
|
mp.interp_eeps=pi/2/200;
|
|
%% save handle here
|
|
for i=1:length(cyObjs)
|
|
mp.handleMap(['cyObj' num2str(i)])=cyObjs(i);
|
|
end
|
|
mp.handleMap('lenObj')=length(cyObjs);
|
|
|
|
%% 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
|
|
x0=[];
|
|
lb=[];
|
|
ub=[];
|
|
for cyObj=cyObjs
|
|
x0=[x0 cyObj.rootH.x cyObj.rootH.y cyObj.rootH.tx cyObj.rootH.ty cyObj.rootH.r];
|
|
lb=[lb 0+cyObj.rootH.r 0+cyObj.rootH.r -pi/3 -pi/3 0.1];
|
|
ub=[ub 12-cyObj.rootH.r 12-cyObj.rootH.r pi/3 pi/3 cyObj.rootH.r*2];
|
|
end
|
|
x0=x0';
|
|
lb=lb';
|
|
ub=ub';
|
|
%---------------------------------end fill
|
|
|
|
mp.handleMap('x0')=x0;
|
|
mp.handleMap('lb')=lb;
|
|
mp.handleMap('ub')=ub;
|
|
mp.handleMap('modify_func')=@modify_c_by_x;
|
|
mp.handleMap('constrast_list')= ...
|
|
{};
|
|
modify_c_by_x(x0,mp);
|
|
|
|
end
|
|
|
|
|
|
function modify_c_by_x(x,mp)
|
|
Len=mp.handleMap('lenObj');
|
|
for i=1:Len
|
|
curObj=mp.handleMap(['cyObj' num2str(i)]);
|
|
curObj.rootH.x=x(5*i-4);
|
|
curObj.rootH.y=x(5*i-3);
|
|
curObj.rootH.tx=x(5*i-2);
|
|
curObj.rootH.ty=x(5*i-1);
|
|
curObj.rootH.r=x(5*i);
|
|
|
|
end
|
|
end
|
|
|
|
function ret=cal_NeuF(X)
|
|
|
|
lenX=size(X,1);
|
|
% 1 N
|
|
coef=(1-sin(vecnorm(X(:,1:2)-[9,9],2,2)./(9*sqrt(2)).*(pi/2))).^8;
|
|
ret=[zeros(lenX,2),ones(lenX,1)*-50*1e3.*coef];
|
|
|
|
end
|
|
|
|
|