You are on page 1of 7

MATLAB main code

%Zeeman Final
clear all
% keep in mind to change the parameters in the functions too
mu=4*pi*10^-7; % vacuum magnetic permeability
hbar =(6.63*10^-34)/(2*pi);
I=10/(pi*(0.1)^2);% slowing beam intensity, units mw per cm2
Is=61; % 61mW per cm2 saturation intensity for Ho
s0=I/Is;
Gamma= 2*pi*32*10^6;% transition
k = (2*pi)/(410.5*10^-9);% wavelength used
m = 2.74*10^-25;% Ho mass
kb = 1.38*10^-23;% Boltzmann constant
Delta=-2*pi*670*10^6;% detuning 670MHz
mubohr = 9.274*10^-24;
muprime = mubohr;% our atoms magneton. mubohr is an approximation
T = 1273; %Temperature of Ho vapor in Kelvin
vavg = 2*sqrt(kb*T/m);%Average velocity of Holmium atoms in our effusion beam
amax = hbar*k*Gamma*s0/(2*m*(1+s0));
eff =0.8;%s0/(1+s0); %efficiency
a = eff*amax; %Defines real deceleration
vf=55; % MOT capture velocity
lmin = (vavg^2-vf^2)/(2*a); %Assuming final velocity is zero. This will give us
%the minimum length of our Zeeman slower
%each time we change any of the above constants, we need to change them in
%function forceeqn as well.
Bb = hbar*Delta/muprime; %define biased magnetic field
B0 = hbar*k*vavg/muprime; %define maximum magnetic field
deltaeff=-0.5*Gamma*sqrt((1+s0)*(1-eff)/eff);
%Magnet Properties
Br=1.31;% residual flux density for N42 magnet
R=0.5*0.75*0.0254;% magnet's radius
L=0.625*0.0254;% magnet's length
Volume=pi*(R^2)*L;% magnet's volume
mm=Br*Volume/mu; % magnetic moment
lswitch=0.29;% length at which magnets start to have the opposite polarity
stepmagnet=L;% separation between two magnets
stepx=0.001;
xmin=0.02;
xmax=2;
magn=(xmax-xmin)/stepx;
yi=0;
zmin=0;% starting point of slower
zmax=lmin+L;% ending point of slower
magn1=(zmax-zmin)/stepmagnet;
deltasq=zeros(magn,3);
Xposition=zeros(magn1+1,1);
Btest=zeros(magn1+1,1);
ind=0;
for z=zmin:stepmagnet:zmax
ind=ind+1;
Btheoretical=-0.001-Bb-B0*sqrt(1-2*a*z/(vavg^2))+hbar*deltaeff/muprime;
ind1=0;
zi=z;

if z>=lswitch
mm=-mm;
end
for xi=xmin:stepx:xmax
ind1=ind1+1;
Bt=magnet(mm,0,0,z,xi,0,zi);% we care only about the field on z axis
Bz=Btest(ind)+4*Bt(3);
deltasq(ind1,1)=(Bz-Btheoretical)^2; % this matrix shows how close
%to the theoretical value our positioning is
deltasq(ind1,2)=xi;
deltasq(ind1,3)=Bz;
end
index=find(deltasq(:,1)==min(deltasq(:,1)));% chooses the least error
Xposition(ind)=deltasq(index,2);
xmagnet=deltasq(index,2);
ind3=0;
%the for loop below calculates the magnetic field created in the rest
%region
for zz=zmin:stepmagnet:zmax
ind3=ind3+1;
BB=magnet(mm,0,0,zz,xmagnet,0,z);
Btest(ind3)=Btest(ind3)+4*BB(3);
end
end
% repeat the above procedure to optimize the positioning
for perfection=1:40
[Btest,Xposition]=improving(Btest,Xposition,lswitch,Br,R,L,Bb,B0,deltaeff,muprime,
lmin,zmin,zmax,a,vavg);
end
Xiszero=zeros(magn1+1,1);
Yiszero=zeros(magn1+1,1);
zimin=-0.1;
step=0.001;
zimax=lmin+0.3;
mm=Br*Volume/mu; % magnetic moment
Xposition(1)=0.030;
Xposition(21)=2;
Yposition=Xposition;
Xposition1=Xposition;
Xposition2=Xposition;
Yposition1=Xposition;
Yposition2=Xposition;
%{
% code for adding random error in our magnetic configuration
for index=1:magn1+1
Xposition1(index)=Xposition(index)+random('unif',-0.002,0.002);
Yposition1(index)=Yposition(index)+random('unif',-0.002,0.002);
Xposition2(index)=Xposition(index)+random('unif',-0.002,0.002);
Yposition2(index)=Yposition(index)+random('unif',-0.002,0.002);
end
%}
%up part

BB=Bside(Xposition1,Yiszero,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax);
B1=BB;
%right part
BB=Bside(Xiszero,Yposition1,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax);
B2=BB;
%down part
BB=Bside(-Xposition2,Yiszero,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax);
B3=BB;
%left part
BB=Bside(Xiszero,-Yposition2,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax);
B4=BB;
Btotal=B1+B2+B3+B4;
Z0=[0]; % initial position at the oven which is at the origin
VV=[];
ZZ=[];
alpha=sqrt(2*kb*T/m); % parameter for the effusion distribution
%oven is 33.5cm behind the slower and MOT is 24.5cm after the slower
vround=fix(vavg); % the number is truncated instead of rounded
vfast=vround+1;% the biggest velocity we can capture
for v0=1:vfast+50
Vb=[v0 -5];
[V,Z]=ode45(@forceeqn,Vb,Z0);
if v0==vround
vv=V;
zz=Z;
end
LL=find(imag(Z)==0);% process to exclude imaginary positions
Z=Z(LL);
V=V(LL);
ZV=[Z,V];% matrix with positions and velocities of particle
VV=[VV;V];
ZZ=[ZZ;Z];
M=find(ZV(:,2)<=55&ZV(:,2)>=20);% atoms which do not make it to the MOT
if numel(M)~=0
N=ZV(M);
maxim=max(N(:,1));
if maxim<lmin-0.005
vlow=v0;
elseif maxim>=lmin-0.005&maxim<=lmin+0.005
vmax=v0;
end
end
end
figure (1)
hold all
grid on
plot(ZZ,VV,'.')
vlow=60;
poplow=intfun(0,vlow,T,m);
poptrap=intfun(vlow,vmax,T,m);% anything that travels with less than 35 m/s
%at the end of the slower, it will not make it to the MOT
popfast=intfun(vmax,10000,T,m);
poptotal=poplow+poptrap+popfast; % has to be the same with the population
%defined in the distribution function which is 10^7

poplow/poptotal
poptrap/poptotal
popfast/poptotal
figure(2)
hold all
errorB=0;%-0.003*sin(60*z);
Bfun1=errorB+hbar*(-Delta-k*vv+deltaeff)/muprime;
syms z
Bfun=-errorB-Bb-B0*sqrt(1-2*a*z/(vavg^2))+hbar*deltaeff/muprime; % define magnetic
profile
Z=(zimin:step:zimax);
plot(Z,Btotal,'.')
ezplot(Bfun,[zimin,zimax])
grid on
BBoffaxis=Boffaxis(Xposition,Yposition,lswitch,stepmagnet,mm,step,zimin,zimax,zmin
,zmax,0.3);% magnetic field 0.30m away from slower
figure(100)% magnetic field 0.3m away from the slower
plot(Z,BBoffaxis)
grid on
offsetmin=0.001;
offsetmax=0.005;
ind=0;
%magnetic field if the atomic beam is not centered right
for offset=offsetmin:0.002:offsetmax
ind=ind+1;
Xposition2=Xposition+offset;
Yposition1=Yposition;
Yposition2=Yposition;
BB=Bside(Xposition1,Yiszero,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax);
B1=BB;
%right part
BB=Bside(Xiszero,Yposition1,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax);
B2=BB;
%down part
BB=Bside(Xposition2,Yiszero,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax);
B3=BB;
%left part
BB=Bside(Xiszero,Yposition2,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax);
B4=BB;
Boffaxistotalx=B1+B2+B3+B4;
figure(ind+10)
grid on
Functions I created used in the above code
Magnetic dipole
function B=magnet(mm,x,y,z,xi,yi,zi)
mu=4*pi*10^-7; % vacuum magnetic permeability
r=sqrt((x-xi)^2+(y-yi)^2+(z-zi)^2);
Bx=(mm*mu/(4*pi))*(3*(x-xi)*(z-zi))/(r^5);
By=(mm*mu/(4*pi))*(3*(y-yi)*(z-zi))/(r^5);
Bz=(mm*mu/(4*pi))*((2*((z-zi)^2)-((x-xi)^2)-((y-yi)^2))/(r^5));

B=[Bx,By,Bz];
Magnetic field of one row of magnets
function
BB=Bside(Xposition,Yposition,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax)
magn=(zimax-zimin)/step;
BB=zeros(magn+1,3);
Bm=zeros(magn+1,3);
indz=0;
mstable=mm;
for z=zmin:stepmagnet:zmax
indz=indz+1;
xi=Xposition(indz);
yi=Yposition(indz);
if Xposition(indz)==2
mm=0;
else
mm=mstable;
end
if z>=lswitch
mm=-mm;
end
ind=0;
for zi=zimin:step:zimax
ind=ind+1;
Btransfer=magnet(mm,0,0,zi,xi,yi,z);
Bm(ind,1)=Btransfer(1);
Bm(ind,2)=Btransfer(2);
Bm(ind,3)=Btransfer(3);
end
BB=BB+Bm;
end
Optimization
function
[Btest,Xposition]=improving(Btest,Xposition,lswitch,Br,R,L,Bb,B0,deltaeff,muprime,
lmin,zmin,zmax,a,vavg)
%this is a function to correct our setup and find the optimum location for
%the magnets
mu=4*pi*10^-7; % vacuum magnetic permeability
hbar =(6.63*10^-34)/(2*pi);
%Magnet Properties
Volume=pi*(R^2)*L;
mm=Br*Volume/mu; % magnetic moment
mstable=mm;
stepmagnet=L;
%Slower dimensions
stepx=0.0001;
xmin=0.02;
xmax=2;
magn=(xmax-xmin)/stepx;
deltasq=zeros(magn,3);
ind=0;
for z=zmin:stepmagnet:zmax
ind=ind+1;
ind4=0;

end

xmagnet=Xposition(ind);
mm=mstable;
if z>=lswitch
mm=-mm;
end
%the for loop below removes the contribution of the magnet at the
%current position z.
for zz=zmin:stepmagnet:zmax
ind4=ind4+1;
BB=magnet(mm,0,0,zz,xmagnet,0,z);
Btest(ind4)=Btest(ind4)-4*BB(3);
end
Btheoretical=-0.001-Bb-B0*sqrt(1-2*a*z/(vavg^2))+hbar*deltaeff/muprime;
ind1=0;
zi=z;
for xi=xmin:stepx:xmax
ind1=ind1+1;
Bt=magnet(mm,0,0,z,xi,0,zi);% we care only about the field on z axis
Bz=Btest(ind)+4*Bt(3);
deltasq(ind1,1)=(Bz-Btheoretical)^2;
deltasq(ind1,2)=xi;
deltasq(ind1,3)=Bz;
end
index=find(deltasq(:,1)==min(deltasq(:,1)));
Xposition(ind)=deltasq(index,2);
xmagnet=deltasq(index,2);
ind3=0;
for zz=zmin:stepmagnet:zmax
ind3=ind3+1;
BB=magnet(mm,0,0,zz,xmagnet,0,z);
Btest(ind3)=Btest(ind3)+4*BB(3);
end

Force equation
function dz=forceeqn(v,z)
%constants
hbar =(6.63*10^-34)/(2*pi);
I=10/(pi*(0.1)^2);% slowing beam intensity, units mw per cm2
Is=61; % 61mW per cm2 saturation intensity for Ho
s0=I/Is;
Gamma= 2*pi*32*10^6;% transition
k = (2*pi)/(410.5*10^-9);% wavelength used
m = 2.74*10^-25;% Ho mass
kb = 1.38*10^-23;% Boltzmann constant
Delta=-2*pi*670*10^6;% detuning
mubohr = 9.274*10^-24;
muprime = mubohr;% our atoms magneton. mubohr is an approximation
T = 1273; %Temperature of Ho vapor in Kelvin
vavg = 2*sqrt(kb*T/m);%Average velocity of Holmium atoms in our effusion beam
amax = hbar*k*Gamma*s0/(2*m*(1+s0));
eff =0.8;%s0/(1+s0); %efficiency
a = eff*amax; %Defines real deceleration
vf=55; % MOT capture velocity
lmin = (vavg^2-vf^2)/(2*a); %Assuming final velocity is zero. This will give us
%the minimum length of our Zeeman slower

Bb = hbar*Delta/muprime; %define biased magnetic field


B0 = hbar*k*vavg/muprime; %define maximum magnetic field
deltaeff=-0.5*Gamma*sqrt((1+s0)*(1-eff)/eff);
errorB=0;%-0.003*sin(60*z);
%B=errorB+hbar*(-Delta-k*v+deltaeff)/muprime;
B=-errorB-Bb-B0*sqrt(1-2*a*z/(vavg^2))+hbar*deltaeff/muprime; % define magnetic
profile
dz=-(((1+s0+(4*(Delta+k*v+muprime*B/hbar)^2)/Gamma^2))*m*v)/(hbar*0.5*k*Gamma*s0);
plot(Z,Boffaxistotalx)%magnetic field when i have an x offset
Xposition1=Xposition+offset;
Xposition2=Xposition-offset;
Yposition1=Yposition-offset;
Yposition2=Yposition+offset;
BB=Bside(Xposition1,Yiszero,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax);
B1=BB;
%right part
BB=Bside(Xiszero,Yposition1,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax);
B2=BB;
%down part
BB=Bside(Xposition2,Yiszero,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax);
B3=BB;
%left part
BB=Bside(Xiszero,Yposition2,lswitch,stepmagnet,mm,step,zimin,zimax,zmin,zmax);
B4=BB;
Boffaxistotaly=B1+B2+B3+B4;
figure(20+ind)
ezplot(Bfun,[zimin,zimax])
plot(Z,Boffaxistotaly)%magnetic field when i have an x and y offset
grid on
end
%}

You might also like