clc
clear all

%参考四面体
%顶点1-[1,0,0] 2-[0,1,0] 3-[0,0,1] 4-[0,0,1]

% 算例配置（改波长/材料/边界请编辑 case_config.m）
[phy, cfg] = case_config();

%读取网格
load(cfg.meshMatFile);
mesh.incIndex=findTri(phy.inc,mesh);
mesh.outIndex=findTri(phy.out,mesh);

%矩阵组装
solver.Ai=[];solver.Aj=[];solver.Av=[];
solver.b=zeros(2*mesh.NbrEdge+2*mesh.NbrFace,1);
solver=assembly_equ(phy,mesh,solver);
%出射处理
solver=assembly_out(phy,mesh,solver);
%入射处理
solver=assembly_inc(phy,mesh,solver);
solver.A=sparse(solver.Ai,solver.Aj,solver.Av);

%求解
solver.x=solver.A\solver.b;

%计算电场
triIndex=findTri(4,mesh);
[x,y,normE]=get_ele(triIndex,mesh,solver);
patch(x,y,normE,'EdgeAlpha',0)
colormap jet;
colorbar
max(max(normE))