✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,代码获取、论文复现及科研仿真合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab完整代码及仿真定制内容点击👇
🔥 内容介绍
磁场在电磁学中扮演着至关重要的角色,广泛应用于电力系统、电子设备和生物医学领域。有限元方法 (FEM) 是一种强大的数值技术,可用于模拟复杂几何形状和材料特性的磁场分布。本文将介绍如何使用 FEM 模拟圆柱电容器、平行板电容器、圆形和矩形金属波导以及二维散射问题的磁场。
有限元方法 (FEM)
FEM 是一种基于变分原理的数值方法,用于求解偏微分方程组。它将求解域划分为一系列称为有限元的较小单元,并在每个单元内使用简单的基函数近似未知场变量。通过最小化变分泛函,可以获得近似解。
圆柱电容器
圆柱电容器由两个同轴圆柱形电极组成,中间填充绝缘材料。FEM 模型可以模拟电极之间的电场和磁场分布。电场由高斯定律求解,而磁场则由安培定律求解。
平行板电容器
平行板电容器由两个平行的导电板组成,中间填充绝缘材料。FEM 模型可以模拟电极之间的电场和磁场分布。电场由高斯定律求解,而磁场则由安培定律求解。
圆形金属波导
圆形金属波导是一种圆柱形波导,用于传输电磁波。FEM 模型可以模拟波导内的电磁场分布。电磁场由麦克斯韦方程组求解。
矩形金属波导
矩形金属波导是一种矩形波导,用于传输电磁波。FEM 模型可以模拟波导内的电磁场分布。电磁场由麦克斯韦方程组求解。
二维散射问题
二维散射问题涉及电磁波在障碍物上散射。FEM 模型可以模拟电磁波在障碍物上的散射过程。电磁场由麦克斯韦方程组求解。
模拟步骤
FEM 模拟磁场的步骤如下:
-
定义几何形状和材料特性。
-
划分求解域为有限元。
-
选择合适的基函数。
-
组装刚度矩阵和载荷向量。
-
求解线性方程组。
-
后处理结果,包括磁场分布、磁通量和磁感应强度。
结论
FEM 是一种强大的工具,可用于模拟各种磁场问题。本文介绍了如何使用 FEM 模拟圆柱电容器、平行板电容器、圆形和矩形金属波导以及二维散射问题的磁场。通过遵循本文中概述的步骤,工程师和研究人员可以准确地预测和分析复杂几何形状和材料特性的磁场分布。
📣 部分代码
x(jj,ii +2) = ((-1)^jj) * (w + Cyl_Rad);
y(jj,ii) = (w + Cyl_Rad + d*(ii-1));
y(jj,ii +2) = (w + Cyl_Rad + d*abs(ii-2));
end
end
c1 = 3*ones(1,9);
c2 = 4*ones(1,9);
gd=[c1 1; % Creates the matrix for the geometry
c2 xC; % Last column consists of the PEC cylinder
x(:,1)' yC;
x(:,2)' Cyl_Rad;
x(:,4)' 1;
x(:,3)' 1;
y(:,1)' 1;
y(:,2)' 1;
y(:,3)' 1;
y(:,4)' 1];
sf = 'R1-R0+R2+R3+R4+R5+R6+R7+R8+R9'; % setting the formula for the geometry
ns = char('R1','R2','R3','R4','R5','R6','R7','R8','R9','R0'); % names of the boundaries
ns = ns'; % converting it to column vector
[dl,bt] = decsg(gd,sf,ns); % creates the geometry
figure
subplot(1,2,1)
pdegplot(dl,'FaceLabels','on'); % plot the resulted geometry
axis equal, axis tight
xlabel('X-axis (m)'),ylabel('Y-axis (m)') % XY-label
title('Geometry & Regions'), hold off
%% ---------- creates the triangularization ------------------------------
refin = 3; % choose the number of refinements you want <---------------------
[p,e,t] = initmesh(dl); % creates the triangularization
for ii = 1:refin
[p,e,t] = refinemesh(dl,p,e,t); % denses the triangular lattice
end
subplot(1,2,2)
pdeplot(p/lambda,e,t); % plot the geometry with the triagualrization
axis equal, axis tight
xlabel('X-axis (\lambda)'),ylabel('Y-axis (\lambda)') % XY-labels
title(['Lattice after ',num2str(refin),' refinement(s)']),hold off
%% Preparations and initializations for the MAIN part
Nn = size(p,2); % total number of nodes
Ne = size(t,2); % total number of elements
Nd = size(e,2); % number of edges - ακμές
node_id = ones(Nn,1); % to identify if a node is KNOWN or UNKNOWN
Ei = zeros(Nn,1); % incident field
Es = zeros(Nn,1); % Scattered Field
% Calculte the incident field Ei in the main computational window
for ie = 1:Ne
n(1:3) = t(1:3,ie);
rg = t(4,ie);
x(1:3) = p(1,n(1:3));
y(1:3) = p(2,n(1:3));
if rg == 9 % the largerest area is alaways at the bottom line
for ii = 1:3
Ei(n(ii)) = Eo * exp(-1i*k0*(x(ii)));
end
end
end
% Boundary conditions
for ii = 1:Nd
if (e(6,ii) == 0 || e(7,ii) == 0 )
for jj = 1:2
% the following IF checks if we are on the boundary of the PEC cylinder or
% the total window
if ( abs( p(1,e(jj,ii)) ) < (Cyl_Rad + w ) && abs( p(2,e(jj,ii)) ) < (Cyl_Rad + w) )
node_id(e(jj,ii)) = 0; % defines the node as known
Es(e(jj,ii)) = - Ei(e(jj,ii)); % defines the Dirichlet condition on the PEC cylider
end
end
end
end
% Re-enumerating the UNKNOWNS !
counter = 0;
index = zeros(Nn,1);
for ii = 1:Nn
if node_id(ii) == 1
counter = counter + 1;
index(ii) = counter; % index for the unknowns
end
end
%% Main - Kernel Calculation of Stiffness and Mass Matrices ------------
Nf = nnz(node_id); % number of uknown variables
Sff = spalloc(Nf,Nf,7*Nf); % initialization of the large Stiff Matrix for system Solutions Sff*X = B
B = zeros(Nf,1);
Aet = spalloc(Nf,Nf,7*Nf);
muxx(1) = mu0; % computational window, the area where field is being
muyy(1) = mu0; % calculated
ezz(1) = e_r*e0;
%
muxx(2) = mu0*llx(1); % left and right X regions with PML
muyy(2) = mu0*llx(2);
ezz(2) = e0* llx(3);
%
muxx(3) = mu0*lly(1); % top and bottom Y regions with PML
muyy(3) = mu0*lly(2);
ezz(3) = e0* lly(3);
%
muxx(4) = mu0*llxy(1); % overlapping xy regions with PML
muyy(4) = mu0*llxy(2);
ezz(4) = e0* llxy(3);
% -------- MAIN LOOP ------------------------------------------------------
S = zeros(3,3);
Te = zeros(3,3);
T = (1/12) * ones(3); % local Mass Matrix is standard !
T = T - (1/12)*eye(3) + (1/6)*eye(3); % Te = Ae* [1/6 1/12 1/12;
% 1/12 1/6 1/12;
% 1/12 1/12 1/6 ];
tic
for ie = 1:Ne
n(1:3) = t(1:3,ie); % n(1:3) are the nodes of every elemnet
rg = t(4,ie); % rg is the region of the element (subdomain number)
x(1:3) = p(1,n(1:3)); % stores the x-coordinate
y(1:3) = p(2,n(1:3)); % stores the y-coordinate
De = det([1 x(1) y(1);1 x(2) y(2);1 x(3) y(3)]); % determinant
Ae = abs(De/2); % element area
b(1) = ( y(2) -y(3) ) / De ; % Coefficients for linea
b(2) = ( y(3) -y(1) ) / De ; % triangular finite elements. For more
b(3) = ( y(1) -y(2) ) / De ; % information on these equations read Tsimboukis'
c(1) = ( x(3) -x(2) ) / De ; % complementary books "Notes on Computational Electromagnetics" pages 83-95
c(2) = ( x(1) -x(3) ) / De ; % and "Energy Methods for E/M Fields" pages 287-308
c(3) = ( x(2) -x(1) ) / De ;
% Calculate the Se & Te for each region Correctly!!
if rg == 9
id = 1;
elseif ( rg == 1 || rg == 2 || rg == 4 || rg == 5 ) % overlapping XY PML region
id = 4;
elseif ( rg == 6 || rg == 7 ) % Y PML region
id = 3;
else%if ( rg == 3 || rg == 8 ) % X PML region
id = 2;
end
% S = zeros(3,3);
Te = ezz(id)*Ae * T; % Calculates Local Mass Matrix
for ii = 1:3
for jj = 1:3 % Calculates Local Stiffness Matrix
S(ii,jj) = (1/muyy(id) * b(ii)*b(jj) + 1/muxx(id) * c(ii)*c(jj))*Ae;
if ( node_id(n(ii)) ~= 0 )
if ( node_id(n(jj)) ~= 0 )
Aet(index(n(ii)) , index(n(jj))) = ...
Aet(index(n(ii)) , index(n(jj))) + S(ii,jj) - (omega^2)*Te(ii,jj);
else
B(index(n(ii))) = B(index(n(ii))) - ( S(ii,jj) - (omega^2)*Te(ii,jj))*Es(n(jj) );
end
end
end
end
end
toc
X = Aet\B; % direct solver
for i =1:Nn
if index(i) ~= 0 % completing the result vector after the system solution
Es(i) = X(index(i)) ; % by creating a total vector including the boundaries
end
end
E = Es+Ei ; % total Electric Field = Scattered and Incident
%% FEM plots
figure
subplot(2,2,1) % plot the real part of the total field
pdeplot(p/lambda,e,t,'XYdata',real(E),'Contour','off')
axis equal; axis tight;
colormap(jet);
hcb = colorbar;
hcb.Label.String = 'V/m';
xlim([x_min x_max]/lambda), ylim([y_min y_max]/lambda) % XY-limits
xlabel('X-axis (\lambda)'), ylabel('Y-axis (\lambda)') % XY-label
title('Real\{E\}')
subplot(2,2,2) % plot the imaginary part of the total field
pdeplot(p/lambda,e,t,'XYdata',imag(E),'Contour','off')
axis equal; axis tight;
colormap(jet);
hcb = colorbar;
hcb.Label.String = 'V/m';
xlim([x_min x_max]/lambda), ylim([y_min y_max]/lambda) % XY-limits
xlabel('X-axis (\lambda)'), ylabel('Y-axis (\lambda)') % XY-label
title('Imag\{E\}')
subplot(2,2,3:4) % plot the magnitude of the total field
pdeplot(p/lambda,e,t,'XYdata',abs(E),'Contour','off')
axis equal; axis tight;
colormap(jet);
hcb = colorbar;
hcb.Label.String = 'V/m';
xlim([x_min x_max]/lambda), ylim([y_min y_max]/lambda) % XY-limits
xlabel('X-axis (\lambda)'), ylabel('Y-axis (\lambda)') % XY-label
title('|E|')
hold off
sg = sgtitle({'Total Electric Field E = E_i + E_s'});
sg.FontName = 'Times';
⛳️ 运行结果
🔗 参考文献
[1] 王洋,王昕.基于J—A模型磁滞回线仿真及有效性研究[J].农业科技与装备, 2011.DOI:CNKI:SUN:NYJD.0.2011-10-023.
[2] 李晓飞,刘连光.基于J-A模型磁滞回线仿真及有效性研究[C]//华北电力大学研究生学术交流年会.华北电力大学, 2007.
🎈 部分理论引用网络文献,若有侵权联系博主删除
🎁 关注我领取海量matlab电子书和数学建模资料
👇 私信完整代码和数据获取及论文数模仿真定制
1 各类智能优化算法改进及应用
生产调度、经济调度、装配线调度、充电优化、车间调度、发车优化、水库调度、三维装箱、物流选址、货位优化、公交排班优化、充电桩布局优化、车间布局优化、集装箱船配载优化、水泵组合优化、解医疗资源分配优化、设施布局优化、可视域基站和无人机选址优化、背包问题、 风电场布局、时隙分配优化、 最佳分布式发电单元分配、多阶段管道维修、 工厂-中心-需求点三级选址问题、 应急生活物质配送中心选址、 基站选址、 道路灯柱布置、 枢纽节点部署、 输电线路台风监测装置、 集装箱船配载优化、 机组优化、 投资优化组合、云服务器组合优化、 天线线性阵列分布优化
2 机器学习和深度学习方面
2.1 bp时序、回归预测和分类
2.2 ENS声神经网络时序、回归预测和分类
2.3 SVM/CNN-SVM/LSSVM/RVM支持向量机系列时序、回归预测和分类
2.4 CNN/TCN卷积神经网络系列时序、回归预测和分类
2.5 ELM/KELM/RELM/DELM极限学习机系列时序、回归预测和分类
2.6 GRU/Bi-GRU/CNN-GRU/CNN-BiGRU门控神经网络时序、回归预测和分类
2.7 ELMAN递归神经网络时序、回归\预测和分类
2.8 LSTM/BiLSTM/CNN-LSTM/CNN-BiLSTM/长短记忆神经网络系列时序、回归预测和分类
2.9 RBF径向基神经网络时序、回归预测和分类