XIAN-FEM-2026June/三维matlab代码/matlab 3D一阶散射问题/main.m

37 lines
839 B
Matlab
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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(mesh.NbrEdge,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);
%导出 A、b与 OpticsFEM3D OutFile 格式一致)
export_ab_matrix(solver);
%求解
solver.x=solver.A\solver.b;
%计算电场
triIndex=findTri(4,mesh);
[x,y,normE]=get_ele2(triIndex,mesh,solver);
patch(x,y,normE,'EdgeAlpha',0)
colormap jet;
colorbar
max(max(normE))