% Constants mu0 =4⋆pi⋆10∧−7; ㅇacuum permeability \% Geometry and dimensions t0 =0.02; Thickness of Omegal b0=0.02;% Width of Omegal ts=0.01;÷ Thickness of Omega2 g=0.001;÷ Air-gap thickness cD=0.05; Distance from Omega2 to Gamma2 10=0.05;÷ Length of the domain c0=0.05; Distance from Omegal to Gammal \% Material properties mu1 =1000; o Relative permeability of Omegal mu2 =1;% Relative permeability of Omega 2 % Boundary conditions A1=0; o Magnetic vector potential at Gammal A2 =1e−3⋆mu; 응 Magnetic vector potential at Gamma2 % Mesh generation nx=50; Number of elements along x-axis ny=50; Number of elements along y-axis hx=10/nx; Element size along x-axis hy=(b0+2⋆g)/ ny; % Element size along y-axis
\% Node and element numbering nodeNum =(i,j)(j−1)⋆(nn+1)+i; elemNum =(i,j)(j−1)⋆nx+i i \% Create nodes and elements nodes =zeros((nx+1)⋆(ny+1),2); elements =zeros(nx⋆ny,4); for j=1:ny+1 for i=1:nx+1 nodes (nodeNum(i,j),:)=[(i−1)⋆hx,(j−1)⋆hy]; end -end for j=1:ny for i=1:nx elements (elemNum (i,j),:)=[nodeNum(i,j),nodeNum(i+1,j),nodeNum(i+1,j+1),nodeNum(i,j+1)]i end -end \% Assemble global stiffness matrix and load vector numNodes =(nx+1)⋆(ny+1);
numElements =nx⋆ny; K= sparse (numNodes, numNodes); F=zeros (numNodes, 1); for e=1 :numElements nodesInElem = elements (e,:); x= nodes (nodesInElem, 1 ); y= nodes (nodesInElem, 2); area =(x(2)−x(1)) * (y(3)−y(2)); Ke=(mu1⋆mu0⋆gradN′∗gradN+mu2⋆mu0∗gradN′∗gradN) *area /2; K (nodesInElem, nodesInElem) =K (nodesInElem, nodesInElem) +Ke; end \% Apply boundary conditions A=zeros (numNodes, 1); A(1:nx+1)=A1;÷ Left boundary (Gamma1) A((ny⋆nx+1):(ny⋆nx+nx+1))=A2;÷ Right boundary (Gamma2) ° Solve the linear system A=K\F; \% Plot magnetic vector potential field lines figure;
contourf(reshape(nodes (:,1), ny+1, nx+1), reshape(nodes (:,2),ny+1,nx+1), reshape(A, ny+1, nx+1), 'LineColor', 'non hold on: quiver (reshape (nodes (:,1), ny+1,nx+1), reshape (nodes (:,2),ny+1,nx+1), reshape (A, ny+1, nx+1), zeros (ny+1, nx+1), xlabel(xx(m)′) ylabel(iy(m)′) title('Magnetic Vector Potential Field Lines'); colorbar; axis equal; ° Compute total magnetic energy in the air-gap energy =0; for e=1: numElements nodesInElem = elements (e,:); x=nodes( nodesInElem, 1 ); y= nodes (nodesInElem, 2); area =(x(2)−x(1))∗(y(3)−y(2)); energy = energy + Ae; end