# Use of MATLAB for coding, for simulation in FEMM software.

#### dharanimoka

Joined Jan 29, 2018
18
I have recently started using software FEMM to see how the magnetic flux lines flow in the magnetic core and solenoid. Now I want to change the value of current in the solenoid to see how the flux lines changes in the core. But for that I needed to do some coding the the MATLAB, but I am not getting the required simulation results.

I could be writing the sequence of the commands wrong for defining the materials and assigning them in MATLAB.

Can anyone tell me the right seqence of writing the code in MATLAB?

I have enclosed the required simulation result and the one that I have got while using FEMM software. Also the MATLAb code that I have written. The 'C' figure is the one that I need to get, which I did in FEMM software and the 'A' figure is the one that I have got when writing the code in MATLAB.
Code:
close all;
%% start the FEMM software %%

openfemm;
newdocument(0);  %% 0 is for Magnetics problem
path = 'D:\FEMM\Install\femm42\';
% name_fem = 'HW3_first_trial.fem';
% mi_saveas('HW3_first_trial.fem');

%% Defining Problem

mi_probdef(0,'centimeters','planar', 1e-8, 1, 30, (0));  %mi probdef(freq,units,type,precision,depth,minangle,(acsolver))

%% Generate a dot %%

% U - core %
x1 = 0; y1 = 0;
x2 = 0; y2 = 5;
x3 = 5; y3 = 5;
x4 = 5; y4 = 0;

% Inner U Core %
x5 = 1; y5 = 0;
x6 = 1; y6 = 4;
x7 = 4; y7 = 4;
x8 = 4; y8 = 0;

% Iron Slab %
x9 = 0; y9 = -0.2;
x10 = 0; y10 = -1.2;
x11 = 5; y11 = -0.2;
x12 = 5; y12 = -1.2;

% Inner current coil %
x13 = 1.2; y13 = 2.8;
x14 = 1.2; y14 = 3.8;
x15 = 3.8; y15 = 3.8;
x16 = 3.8; y16 = 2.8;

% Outer Current Coil %
x17 = 1.2; y17 = 5.2;
x18 = 1.2; y18 = 6.2;
x19 = 3.8; y19 = 6.2;
x20 = 3.8; y20 = 5.2;

%% Generate a line %%

%% Defining Material Property

%% Defining the Circuit Property

%% Defining Block labels

mi_addblocklabel(0.5,1);  % U Core
mi_addblocklabel(1,-1);  % Iron Slab

%% Assigning materials to labels

% Air
mi_selectlabel(3,2);
mi_setblockprop('Air',0,1,'<None>',0,0,0);
mi_clearselected;

% Inner Coil
mi_selectlabel(2,3);
mi_setblockprop('20 SWG',0,1,'Circuit',0,0,100);
mi_clearselected;

% Outer Coil
mi_selectlabel(2,6);
mi_setblockprop('20 SWG',0,1,'Circuit',0,0,-100);
mi_clearselected;

% U Core
mi_selectlabel(0.5,1);
mi_setblockprop('M-19 Steel',0,1,'<None>',0,0,0);
mi_clearselected;

% Iron Slab
mi_selectlabel(1,-1);
mi_setblockprop('M-19 Steel',0,1,'<None>',0,0,0);
mi_clearselected;

%% Boundary condition
mi_makeABC();

%% Zoom Natural
mi_zoomnatural;

mi_saveas('HW3_first_trial.fem');
mi_analyze;
mi_loadsolution;
Moderator edit: MATLAB code added in place.

#### Attachments

• 34.5 KB Views: 1
• 28.2 KB Views: 2
• 3.1 KB Views: 4