You are on page 1of 5

Magnet design using MATLAB

SW160131

MATLAB can directly calculate the magnetic properties of a geometry. There is a tool called
“pdetool” that will do most of the work via a graphical interface.

Write “pdetool” at the command prompt.

A graphical interface will open.

Change problem type to “Magnetostatics” (->options->applications)

1. Draw your geometry. In the example a rectangle (R1) is drawn for the complete region to study. In
the example then a rectangle (R2) and an ellipse (E1) were drawn.

2. The next step is to define boundary conditions.

Choose “Boundary mode” and click also “show edge labels”.

By default all edges of the outer geometry (R1) are set to Dirichlet conditions. This is ok if the
complete system is within the drawing. If there are symmetries and only part of the problem is
drawn the boundaries should be set to Neumann conditions.
In the example the right and left edges of R1 are set to Neumann boundary conditions.

Double click on an edge label and change boundary condition.

3. The third step is to set PDE conditions.

Click “PDE mode” and select “show subdomain labels”.

Double click on a label to set conditions.

The R1 region (named “1”) should be air in this case: mu=1, J=0

The R2 region (“2”) should be iron: mu=5000, J=0

The E1 region (“3”) should be an air coil: mu=1, J=1

4. Create a mesh.

Click the big triangle. You will get a rough mesh (see below) with nodes for the calculation. To get
better precision, refine the mesh by clicking the “double triangle”.

5. Solve the problem.

-> solve -> solve PDE


6. Plot and refine the plot.

-> plot ->plot solution

->plot -> parameters

6. Analyze the result of an accelerator magnet.

Plot the magnetic flux density (B). You will see that it is normally high inside the iron. If you want to
see what happens in the gap where the electrons will pass it is more convenient to plot the magnetic
field (H). Remember the relation: B=H, or B=r0H and that r= 5000 for iron.

See also MATLAB help under “Magnetostatics”

7. Analyzing the numerical values.

Save the results by after doing the calculations “export mesh” and “ export solution”. This will create
four parameters in workspace (u and p t e). Where “u” is the vector potential in in each mesh point.
(observe that while the vector potential is described in all three dimensions (xyz) it is only given in
the two dimensions of the defined problem. Take this in mind if calculating the magnetic flux
density.) “pte” describes the mesh and can be translated from triangular mesh to ordinary x-y grid
by “tri2grid”.

Analysis can from here be done by similar components as the following script. (this is for another
geometry than the example. To be refined!)

% save mesh and solution in PDEtool

% Save the solution (u)


% Save the mesh (pte)

x=-60:1:40;
y=0:1:100;
uxy=tri2grid(p,t,u,x,y);

% Plot the potential


figure(1);
mesh(x,y,uxy)

Appendix. The .m file (can be opened in pdetool)


function pdemodel
[pde_fig,ax]=pdeinit;
pdetool('appl_cb',6);
pdetool('snapon','on');
set(ax,'DataAspectRatio',[1 1 1]);
set(ax,'PlotBoxAspectRatio',[1.5 1 1]);
set(ax,'XLim',[-1.5 1.5]);
set(ax,'YLim',[-1 1]);
set(ax,'XTickMode','auto');
set(ax,'YTickMode','auto');
pdetool('gridon','on');

% Geometry description:
pderect([-1 1 0.80000000000000004 -0.80000000000000004],'R1');
pderect([-0.5 0.5 0.60000000000000009 0.20000000000000018],'R2');
pdeellip(0,-0.099999999999999978,0.5,0.099999999999999978,...
0,'E1');
set(findobj(get(pde_fig,'Children'),'Tag','PDEEval'),'String','R1+R2+E1')

% Boundary conditions:
pdetool('changemode',0)
pdesetbd(5,...
'dir',...
1,...
'1',...
'0')
pdesetbd(4,...
'neu',...
1,...
'0',...
'0')
pdesetbd(2,...
'dir',...
1,...
'1',...
'0')
pdesetbd(1,...
'neu',...
1,...
'0',...
'0')

% Mesh generation:
setappdata(pde_fig,'Hgrad',1.3);
setappdata(pde_fig,'refinemethod','regular');
setappdata(pde_fig,'jiggle',char('on','mean',''));
pdetool('initmesh')
pdetool('refine')
% PDE coefficients:
pdeseteq(1,...
'1./(1.0)!1./(5000)!1./(1.0)',...
'0.0!0.0!0.0',...
'0!0!1.0',...
'1.0!1.0!1.0',...
'0:10',...
'0.0',...
'0.0',...
'[0 100]')
setappdata(pde_fig,'currparam',...
['1.0!5000!1.0';...
'0!0!1.0 '])

% Solve parameters:
setappdata(pde_fig,'solveparam',...
char('0','1584','10','pdeadworst',...
'0.5','longest','0','1E-4','','fixed','Inf'))

% Plotflags and user data strings:


setappdata(pde_fig,'plotflags',[1 1 1 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1]);
setappdata(pde_fig,'colstring','');
setappdata(pde_fig,'arrowstring','');
setappdata(pde_fig,'deformstring','');
setappdata(pde_fig,'heightstring','');

% Solve PDE:
pdetool('solve')

You might also like