In [1]:
%pylab inline
from __future__ import division
from matplotlib.pyplot import plot
import matplotlib.pyplot as plt
import numpy as np
from numpy import sqrt, cos, sin, log, exp
from lmfit import lmfit
matplotlib.rcParams.update({'font.size': 14, 'font.family': 'serif'})


Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

Estimation of the kinetic energy in the supersonic expansion

Estimation of the terminal velocity in a supersonic expansion:

$$v_\infty \approx \sqrt{\frac{2 \langle C_p \rangle}{\langle M\rangle}T_0} \ , $$

where $\langle C_p \rangle$ and $\langle M\rangle$ are the average heat capacity at constant pressure and the molar mass respectively. $T_0$ is the stagnation temperature. For an ideal mixture that is $$v_\infty \approx \sqrt{2 \frac{\sum_i x_i C_{p,i}}{\sum_i x_i M_i} T_0}$$ with the molar fractions of the components $i$. Hence the terminal kinetic energy is $$ E_\infty = \frac 12 m v_\infty^2 .$$


In [2]:
import beam_energy_sim as beam

fig, axes = beam.BeamEnergiesPlot(298, beam.CO)
show(fig)
fig.savefig('CO_Beam_Energies.pdf')



In [3]:
rm -f 'CO_Beam_Energies.pdf'

Trapping/Desorption TOF Simulation


In [4]:
from scipy.signal import fftconvolve
from tof_analysis import Moments

tofdistr = lambda l, alpha, x : (l/x)**4 * exp(- (l/alpha)**2 * (1/x)**2)
decay = lambda k, t : exp(-k*t)
    
def norm_distr(distr_func, args):
    func = lambda x: distr_func(x=x, **args)
    return Moments(func, 0)[0]

def desorb(l, alpha, k):
    normfactor = norm_distr(tofdistr, {'l': l , 'alpha': alpha})
    tof = lambda x: tofdistr(l=l, alpha=alpha, x=x)/normfactor
    t = linspace(0.1, 20, 1000)
    y1 = tof(t)
    y2 = decay(k, t)
    #plot(t, y1, 'b-')
    #plot(t, y2, 'r-')
    y3 = fftconvolve(y1, y2)
    plot(y3[:], 'k-')

In [5]:
desorb(0.5, 0.10, 2)


Simulation of Angular Distributions

The cosine law

The (Knudsen) cosine law states that

the molecular flux $d\mathrm{n}$ across a plane surface element $A$, due to all molecules having velocity vectors with directions within a small solid angle $\mathrm{d}\omega$, whose axis makes an angle $\theta$ with the normal to $A$, is given by the cosine law formula. Hence $$ \mathrm{d}n = \left( \frac{Nv_a}{4} \right) \frac{1}{\pi} A \cos \theta\ \mathrm{d} \omega , $$ where $N$ is the number density of molecules and $v_a = \langle v \rangle$, the average molecular velocity. (Greenwood, Vacuum 67 (2002), 217-222)

In the system of spherical polar co-ordinates the solid angle, $\mathrm{d}\omega$ is given by $$ \mathrm{d}\omega = \sin \theta\ \mathrm{d}\theta \ \mathrm{d}\phi, $$ where $\theta$ and $\phi$ are the polar and azimuthal angle respectively.

Hence, $$ \mathrm{d}n = \left( \frac{NAv_a}{4\pi} \right) \cos \theta\ \sin\theta\ \mathrm{d}\theta \ \mathrm{d}\phi . $$

Since the system is cylindrically symmetric with respect to the normal of the surface element from which the molecules emerge, the probability of finding a molecule within a small solid angle at given polar angle is independent of the azimuthal angle. It can be shown by integration the equation above that $$ f(\phi) = \frac{1}{2\pi} .$$ A distribution of azimuthal angles molecules are scattered into can be generated by assigning $$ \phi = y2\pi $$ with random numbers $y$ drawn from a uniform distribution in the range $(0 < y \leq 1)$.

For the polar angle $\theta$ the situation is more involved. Integration of the cosine law over all $\phi$ yields $$ g(\theta) =\sin 2 \theta .$$ This polar angular-distribution function is shown below. Every point represents a molecule in a total of 100 scattered into angles $\theta$. The distance from the center of 0.9 has no meaning is chosen by means of best visibility. The number of molecules in a range $\theta$, $\theta + \mathrm{d}\theta$ resembles the $\sin 2\theta$ distribution depicted by the solid line.


In [17]:
from helper import SemiPolarPlot
from numpy.random import rand

theta = arcsin(sqrt(rand(100, 1)))

theta2 = linspace(0, pi/2, 200)

fig = figure(1, figsize=(6,9))
fig, ax = SemiPolarPlot(fig)
ax.plot(degrees(theta), [0.9 for _ in theta], 'k.')
ax.plot(degrees(theta-pi/2), [0.9 for _ in theta], 'k.')
ax.plot(degrees(theta2), sin(2*theta2), 'k-')
ax.plot(degrees(theta2-pi/2), sin(2*theta2), 'k-')
show()


From this polar anglar-distribution $g(\theta)$ where the three dimensional angular distribution is integrated over all azimuthal angles the cosine nature is not obvious. In an experiment one must also consider the solid angle $\mathrm{d} \omega$ which itself is a function of $\theta$. Plotting the azimuthal and polar angle-distributions together in a 3D co-ordinate system clarifies the meaning of the cosine law:


In [70]:
from mpl_toolkits.mplot3d import Axes3D

phi = 2*pi*rand(1000, 1)
theta = arcsin(sqrt(rand(1000,1)))

def coslaw3d(theta, phi, view=None):
    fig = plt.figure(1, figsize=(8,8))
    ax = fig.gca(projection='3d')
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    ax.set_xlim((-1,1))
    ax.set_ylim((-1,1))
    ax.set_zlim((-1,1))

    x = sin(theta)*cos(phi)
    y = sin(theta)*sin(phi)
    z = cos(theta)

    if view != None:
        ax.view_init(view[0], view[1])
    molecules = ax.scatter3D(x, y, z)
    return fig, ax

fig, axes = coslaw3d(theta, phi)


In the plot above every point represents a molecule in a total of 1000 emerging from a small surface element located in the origin with the surface normal along $\mathbf{e}_Z$ projected onto a sphere of unit radius.


In [73]:
_,_ = coslaw3d(theta, phi, view=(90,90))


The very same set of points. The plot is rotated to see the points from the top along the surface normal. This is what a detector mounted coplanar to the surface would see: A uniform distribution.


In [74]:
_,_ = coslaw3d(theta, phi, view=(0,90))


Again the same plot lying in the ZX-Plane. Here is it where finally the cosine nature is visible: In the projection through the 3D angular distribution onto a plane perpendicular to the surface (containing the surface normal vector).


In [ ]: