clc
clear all

%网格获取
model=mphload('demo2.mph');
[~, m2]=mphmeshstats(model);

Nodes=m2.vertex';%节点坐标

Elements=m2.elem{2}+1;
Elements = sort(Elements);%网格索引

domain=m2.elementity{2};%区域

%物理参数
lam0=1;
epsilonr=1;
mur=1;

%矩阵组装
[A,b,EdgesOfElements]=FemAssemble3(Nodes,Elements,domain,lam0,epsilonr,mur);

%求解
Et=linsolve(A,b);

%计算Ex Ey
[Ex,Ey]=GetExEy(Nodes,Elements,EdgesOfElements,Et);

%绘制 网格及场图
% plotTri(Nodes,Elements');
plotEt(Nodes,Elements',Ex,Ey,0.5);


% epsilonrrx=epsilonrr(:,4);
% figure(2)
% subplot(1,2,1);
% h3=trisurf(Elements',Nodes(:,1),Nodes(:,2),real(epsilonrrx));
% shading interp
% set(h3,'edgecolor','black','edgealpha',0);
% view(2); axis equal; axis tight; axis off;
% colorbar;
% colormap jet;
% caxis([min(real(epsilonrrx)) max(real(epsilonrrx))]);
% subplot(1,2,2);
% h3=trisurf(Elements',Nodes(:,1),Nodes(:,2),imag(epsilonrrx));
% shading interp
% set(h3,'edgecolor','black','edgealpha',0);
% view(2); axis equal; axis tight; axis off;
% colorbar;
% colormap jet;
% caxis([min(imag(epsilonrrx)) max(imag(epsilonrrx))]);