52 lines
1.5 KiB
Matlab
52 lines
1.5 KiB
Matlab
function solver=assembly_pbc_double(mesh,solver)
|
|
|
|
%查找src和dst中重复值
|
|
tempSrc=sort([mesh.PBCIndex(:,1);mesh.PBCIndex2(:,1)]);
|
|
tbl = tabulate(tempSrc);%返回三列数组,第一列为数值,第二列为重复次数
|
|
ovSrcIndex=find(tbl(:,2)>1);
|
|
tempDst=sort([mesh.PBCIndex(:,2);mesh.PBCIndex2(:,2)]);
|
|
tbl2 = tabulate(tempDst);%返回三列数组,第一列为数值,第二列为重复次数
|
|
ovDstIndex = tbl2(find(tbl2(:,2)>1), 1);
|
|
|
|
%确定最终PBCIndex数目
|
|
nbr1=length(ovDstIndex);
|
|
nbr2=length(mesh.PBCIndex);
|
|
nbr3=length(mesh.PBCIndex2);
|
|
nbr=nbr2+nbr3-nbr1;
|
|
PBCIndex=zeros(nbr,3);
|
|
|
|
|
|
%在dst2中查找ovDstIndex对应的src2/dst1
|
|
[~,index1]=ismember(ovDstIndex,mesh.PBCIndex2(:,2));%PBC2去除的数据
|
|
index2=mesh.PBCIndex2(index1,1);%src2/dst1
|
|
%在dst1中查找src2/dst1
|
|
[~,index3]=ismember(index2,mesh.PBCIndex(:,2));%PBC1去除的数据
|
|
index4=mesh.PBCIndex(index3,1);%src1
|
|
%存储二次bloch节点数据
|
|
PBCIndex(1:nbr1,1)=index4;
|
|
PBCIndex(1:nbr1,2)=ovDstIndex;
|
|
PBCIndex(1:nbr1,3)=mesh.PBCIndex2(index1,3).*mesh.PBCIndex(index3,3);
|
|
|
|
%存储PBC1
|
|
tempindex=1:nbr2;
|
|
tempindex(index3)=[];
|
|
PBCIndex(nbr1+1:nbr2,:)=mesh.PBCIndex(tempindex,:);
|
|
tempindex=1:nbr3;
|
|
tempindex(index1)=[];
|
|
PBCIndex(nbr2+1:end,:)=mesh.PBCIndex2(tempindex,:);
|
|
|
|
P=speye(solver.dof);
|
|
phi=PBCIndex(:,3);
|
|
phi(1:nbr1)=mesh.PBCphi*mesh.PBCphi2.*phi(1:nbr1);
|
|
phi(nbr1+1:nbr2)=mesh.PBCphi.*phi(nbr1+1:nbr2);
|
|
phi(nbr2+1:end,:)=mesh.PBCphi2.*phi(nbr2+1:end,:);
|
|
nbrPBC=length(phi);
|
|
for i=1:nbrPBC
|
|
P(PBCIndex(i,2),PBCIndex(i,1))=phi(i);
|
|
end
|
|
P(:,PBCIndex(:,2))=[];
|
|
|
|
solver.P=P;
|
|
|
|
end
|