function [magnetVolume, Br, coilSpan] = getMagnetVolume(initdesignfile,targetPower,targetSpeed,magnetWeight)
motorProps = openMXP(initdesignfile);
[Geometry, Windings, Mesh, Materials, SubdomainProperty] = assembleMXP(initdesignfile,motorProps);
coilSpan = abs(Windings.layout1(1,2)-Windings.layout1(1,3));    % winding coil span
Private = initialization(Geometry,Mesh,Windings,Materials,SubdomainProperty);
speed = targetSpeed*2*pi/60;                                               % RPM to rad/s
nPolePairs = getParampm(motorProps,'Number of pole pairs');                % Number of pole pairs
f1 = speed*nPolePairs/(2*pi);                                              % supply frequency
mu0 = 4*pi*(10.^(-7));                     % permeability of free space
Br=Private.MaterialProperties(6).PM_Br;    % remanence flux density of permanent magnet (corrected with magnet temperature)
mu_pm=Private.MaterialProperties(6).mu;    % relative permeability of permanent magnet 
Hc=Br/(mu0*mu_pm);                         % coercive force of permanent magnet
if ~exist('magnetWeight','var')
    magnetVolume = targetPower*1000/(f1*Br*Hc)*10^9;   % magnet volume in mm^3
else
    massdensity = ReadMaterialData('Magnet',Materials.magnetmaterial,'<Mass Density>');    % magnet mass density in kg/m^3
    magnetVolume = magnetWeight*10^6/massdensity;                                          % magnet volume in mm^3
end


