141 lines
5.0 KiB
Matlab
141 lines
5.0 KiB
Matlab
function [PBCIndex,origIndex]=findPBCIndex(src,dst,theta,mesh)
|
|
%src+dis=dst
|
|
%EPBCIndex n*3 1-edgeIndedxOfsrc 2-edgeIndexOfdst 3-+-1
|
|
|
|
%查找src和dst的对应tri索引
|
|
tempSrcTriIndex=findTri(src,mesh);%mesh.tri索引
|
|
tempDstTriIndex=findTri(dst,mesh);
|
|
tempSrcTriCoon=mesh.ConnOfTri(tempSrcTriIndex,:);%mesh.connOfTri数据
|
|
tempDstTriCoon=mesh.ConnOfTri(tempDstTriIndex,:);
|
|
|
|
%查找src和dst的对应edge
|
|
tempNbr=length(tempSrcTriCoon);
|
|
tempSrcEdge=zeros(tempNbr*3,1);%src所有mesh.Edge的索引
|
|
tempDstEdge=zeros(tempNbr*3,1);
|
|
for n=1:tempNbr
|
|
if tempSrcTriCoon(n,2)==1 %123
|
|
tempSrcEdge((n-1)*3+1)=mesh.EdgeOfTet(tempSrcTriCoon(n,1),1);
|
|
tempSrcEdge((n-1)*3+2)=mesh.EdgeOfTet(tempSrcTriCoon(n,1),2);
|
|
tempSrcEdge((n-1)*3+3)=mesh.EdgeOfTet(tempSrcTriCoon(n,1),4);
|
|
elseif tempSrcTriCoon(n,2)==2
|
|
tempSrcEdge((n-1)*3+1)=mesh.EdgeOfTet(tempSrcTriCoon(n,1),1);
|
|
tempSrcEdge((n-1)*3+2)=mesh.EdgeOfTet(tempSrcTriCoon(n,1),3);
|
|
tempSrcEdge((n-1)*3+3)=mesh.EdgeOfTet(tempSrcTriCoon(n,1),5);
|
|
elseif tempSrcTriCoon(n,2)==3
|
|
tempSrcEdge((n-1)*3+1)=mesh.EdgeOfTet(tempSrcTriCoon(n,1),2);
|
|
tempSrcEdge((n-1)*3+2)=mesh.EdgeOfTet(tempSrcTriCoon(n,1),3);
|
|
tempSrcEdge((n-1)*3+3)=mesh.EdgeOfTet(tempSrcTriCoon(n,1),6);
|
|
elseif tempSrcTriCoon(n,2)==4
|
|
tempSrcEdge((n-1)*3+1)=mesh.EdgeOfTet(tempSrcTriCoon(n,1),4);
|
|
tempSrcEdge((n-1)*3+2)=mesh.EdgeOfTet(tempSrcTriCoon(n,1),5);
|
|
tempSrcEdge((n-1)*3+3)=mesh.EdgeOfTet(tempSrcTriCoon(n,1),6);
|
|
end
|
|
|
|
if tempDstTriCoon(n,2)==1 %123
|
|
tempDstEdge((n-1)*3+1)=mesh.EdgeOfTet(tempDstTriCoon(n,1),1);
|
|
tempDstEdge((n-1)*3+2)=mesh.EdgeOfTet(tempDstTriCoon(n,1),2);
|
|
tempDstEdge((n-1)*3+3)=mesh.EdgeOfTet(tempDstTriCoon(n,1),4);
|
|
elseif tempDstTriCoon(n,2)==2
|
|
tempDstEdge((n-1)*3+1)=mesh.EdgeOfTet(tempDstTriCoon(n,1),1);
|
|
tempDstEdge((n-1)*3+2)=mesh.EdgeOfTet(tempDstTriCoon(n,1),3);
|
|
tempDstEdge((n-1)*3+3)=mesh.EdgeOfTet(tempDstTriCoon(n,1),5);
|
|
elseif tempDstTriCoon(n,2)==3
|
|
tempDstEdge((n-1)*3+1)=mesh.EdgeOfTet(tempDstTriCoon(n,1),2);
|
|
tempDstEdge((n-1)*3+2)=mesh.EdgeOfTet(tempDstTriCoon(n,1),3);
|
|
tempDstEdge((n-1)*3+3)=mesh.EdgeOfTet(tempDstTriCoon(n,1),6);
|
|
elseif tempDstTriCoon(n,2)==4
|
|
tempDstEdge((n-1)*3+1)=mesh.EdgeOfTet(tempDstTriCoon(n,1),4);
|
|
tempDstEdge((n-1)*3+2)=mesh.EdgeOfTet(tempDstTriCoon(n,1),5);
|
|
tempDstEdge((n-1)*3+3)=mesh.EdgeOfTet(tempDstTriCoon(n,1),6);
|
|
end
|
|
end
|
|
%去重
|
|
[SrcEdge,~,~]=unique(tempSrcEdge);%src边mesh.edge索引
|
|
[DstEdge,~,~]=unique(tempDstEdge);
|
|
|
|
%查找edge对应
|
|
nbrPBC=length(SrcEdge);
|
|
PBCIndex=zeros(nbrPBC,3);
|
|
PBCIndex(:,1)=SrcEdge;
|
|
%双循环 对比边的顶点
|
|
traMat=[cos(theta) -sin(theta) 0;
|
|
sin(theta) cos(theta) 0;
|
|
0 0 1];
|
|
dl=0.01;
|
|
err=dl*0.00005;
|
|
for i=1:nbrPBC
|
|
for j=1:nbrPBC
|
|
%边的顶点坐标
|
|
vertex1=mesh.Vertex(mesh.Edge(SrcEdge(i),1),:)';
|
|
vertex2=mesh.Vertex(mesh.Edge(SrcEdge(i),2),:)';
|
|
vertex3=mesh.Vertex(mesh.Edge(DstEdge(j),1),:);
|
|
vertex4=mesh.Vertex(mesh.Edge(DstEdge(j),2),:);
|
|
vertex3=traMat*(vertex3');
|
|
vertex4=traMat*(vertex4');
|
|
|
|
%边的顶点坐标差
|
|
l1=abs(norm(vertex1-vertex3));
|
|
l2=abs(norm(vertex2-vertex4));
|
|
|
|
if ((l1+l2)<err)
|
|
PBCIndex(i,2)=DstEdge(j);
|
|
PBCIndex(i,3)=1;
|
|
break;
|
|
else
|
|
continue;
|
|
end
|
|
end
|
|
end
|
|
EPBCIndex=PBCIndex;
|
|
|
|
%查找src和dst对应的face
|
|
tempSrcFace=zeros(tempNbr,1);%src所有mesh.Edge的索引
|
|
tempDstFace=zeros(tempNbr,1);
|
|
for n=1:tempNbr
|
|
tempSrcFace(n)=mesh.FaceOfTet(tempSrcTriCoon(n,1),tempSrcTriCoon(n,2));
|
|
tempDstFace(n)=mesh.FaceOfTet(tempDstTriCoon(n,1),tempDstTriCoon(n,2));
|
|
end
|
|
FPBCIndex=zeros(tempNbr,3);
|
|
%双循环确定对应关系
|
|
for i=1:tempNbr
|
|
for j=1:tempNbr
|
|
vertex1=mesh.Vertex(mesh.Face(tempSrcFace(i),1),:);
|
|
vertex2=mesh.Vertex(mesh.Face(tempSrcFace(i),2),:);
|
|
vertex3=mesh.Vertex(mesh.Face(tempSrcFace(i),3),:);
|
|
tempVertex1=(vertex1+vertex2+vertex3)'/3;
|
|
|
|
vertex4=mesh.Vertex(mesh.Face(tempDstFace(j),1),:);
|
|
vertex5=mesh.Vertex(mesh.Face(tempDstFace(j),2),:);
|
|
vertex6=mesh.Vertex(mesh.Face(tempDstFace(j),3),:);
|
|
tempVertex2=(vertex4+vertex5+vertex6)/3;
|
|
tempVertex2=traMat*(tempVertex2');
|
|
|
|
if (norm(tempVertex1-tempVertex2)<err)
|
|
FPBCIndex(i,1)=tempSrcFace(i);
|
|
FPBCIndex(i,2)=tempDstFace(j);
|
|
FPBCIndex(i,3)=1;
|
|
break;
|
|
else
|
|
continue;
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
EPBCIndex1=EPBCIndex;
|
|
EPBCIndex2=EPBCIndex;
|
|
EPBCIndex2(:,1:2)=EPBCIndex2(:,1:2)+mesh.NbrEdge;
|
|
FPBCIndex1=FPBCIndex;
|
|
FPBCIndex1(:,1:2)=FPBCIndex1(:,1:2)+mesh.NbrEdge*2;
|
|
FPBCIndex2=FPBCIndex;
|
|
FPBCIndex2(:,1:2)=FPBCIndex2(:,1:2)+mesh.NbrEdge*2+mesh.NbrFace;
|
|
|
|
PBCIndex=[EPBCIndex1;EPBCIndex2;FPBCIndex1;FPBCIndex2];
|
|
tempIndex=find(PBCIndex(:,1)==PBCIndex(:,2));
|
|
Index=1:length(PBCIndex);
|
|
Index(tempIndex)=[];
|
|
|
|
origIndex=PBCIndex(tempIndex,1);
|
|
PBCIndex=PBCIndex(Index,:);
|
|
|
|
end |