Skip to content
Projects

Beamline

The equations of beamtracer.beamline, declared on the code that implements them and checked by the tests.

ApertureGrid

classsource

The apertures of an accelerator grid, each emitting a copy of one beamlet.

slopes
s=−cf+ssteer,c=(cy,cz), f=(fy,fz)\mathbf s = -\frac{\mathbf c}{\mathbf f} + \mathbf s_\mathrm{steer}, \qquad \mathbf c = (c_y, c_z), \ \mathbf f = (f_y, f_z)
rotation
R=I+sin⁡ϑ K+(1−cos⁡ϑ) K2,R x^=(1,sy,sz)∣(1,sy,sz)∣R = I + \sin\vartheta\, K + (1 - \cos\vartheta)\, K^2, \qquad R\, \hat{\mathbf x} = \frac{(1, s_y, s_z)}{|(1, s_y, s_z)|}
copy
x′=R (x−xˉx^)+(xˉ,cy,cz)\mathbf x' = R\, (\mathbf x - \bar x \hat{\mathbf x}) + (\bar x, c_y, c_z)
Assumes
  • KK the cross-product matrix of the unit rotation axis x^×d^\hat{\mathbf x} \times \hat{\mathbf d} (Rodrigues); the identity below a sine of 10−1510^{-15}
  • every aperture carries the whole beamlet power; a flat grid has f=∞f = \infty; xˉ\bar x the mean xx of the beamlet's markers

beamlet_markers

functionsource

The 3D markers of a beamlet traced in 2D, from its crossings of a plane.

power
P=Ize⋅12mv2 (cylindrical),P=Ize⋅12mv2 ℓ (planar, slit length ℓ)P = \frac{I}{z e} \cdot \tfrac12 m v^2 \ \text{(cylindrical)}, \qquad P = \frac{I}{z e} \cdot \tfrac12 m v^2\, \ell \ \text{(planar, slit length } \ell)
states
Ps=P Fs/ncopiesP_s = P\, F_s / n_\mathrm{copies}
copies
cylindrical: rotated about x by φ∼U(0,2π);planar: z∼U(−ℓ/2,ℓ/2)\text{cylindrical: rotated about } x \text{ by } \varphi \sim U(0, 2\pi); \qquad \text{planar: } z \sim U(-\ell/2, \ell/2)
Assumes
  • only the forward crossings of the plane, of one beam species if given; zz the charge the current counts, in e
  • one marker per trajectory and state with a share, repeated copies times

beamline_summary

functionsource

The power balance of a beamline as a dataset.

balance
Pport+∑partsPwall=Pin+W(to a relative 10−9)P_\mathrm{port} + \sum_\mathrm{parts} P_\mathrm{wall} = P_\mathrm{in} + W \quad \text{(to a relative } 10^{-9})
halo
Phalo=∑∣rk−rˉ∣>rhaloPk,rˉ=⟨(y,z)⟩PP_\mathrm{halo} = \sum_{|\mathbf r_k - \bar{\mathbf r}| > r_\mathrm{halo}} P_k, \qquad \bar{\mathbf r} = \langle (y, z) \rangle_P
Assumes
  • the balance is checked, a mismatch raises; WW the work of the fields (RegionResult.work)

Calorimeter

classsource

A flat calorimeter of tiles in the plane x = position, facing the beam.

map
pab=1Aab∑k∈tile abPk[W/m2]p_{ab} = \frac{1}{A_{ab}} \sum_{k \in \text{tile } ab} P_k \quad [\mathrm{W/m^2}]
Assumes
  • the markers drift on straight lines to the face (backwards for one already past it); those outside the face pass by
  • tiles of equal area on the face extent, closed bounds

divergence_from_widths

functionsource

The source width and the divergence from beam widths at several distances.

widths
w2(L)=w02+(Lθ)2w^2(L) = w_0^2 + (L \theta)^2
Assumes
  • linear least squares of w2w^2 on the columns (1,L2)(1, L^2), at least two distances; negative w02w_0^2 or θ2\theta^2 clipped to 0

Duct

classsource

The duct from the end of the traced region to the port.

depth
τ(x)=∑tσtout∫x0xnt dx′,σtout=∑j≠0σt(0→j)\tau(x) = \sum_t \sigma_t^\mathrm{out} \int_{x_0}^{x} n_t\, dx', \qquad \sigma_t^\mathrm{out} = \sum_{j \ne 0} \sigma_t(0 \to j)
birth
τ(xborn)=τ(x0)+ξ vx∣v∣,ξ∼Exp(1)\tau(x_\mathrm{born}) = \tau(x_0) + \xi\, \frac{v_x}{|\mathbf v|}, \qquad \xi \sim \mathrm{Exp}(1)
product
P(j)∝∑tnt(xborn) σtout σt(0→j)P(j) \propto \sum_t n_t(x_\mathrm{born})\, \sigma_t^\mathrm{out}\, \sigma_t(0 \to j)
walls
xend=x0+vxport−x0vx,the first wall crossing of the segment, else the port\mathbf x_\mathrm{end} = \mathbf x_0 + \mathbf v \frac{x_\mathrm{port} - x_0}{v_x}, \qquad \text{the first wall crossing of the segment, else the port}
Assumes
  • neutrals on straight lines along +x+x; a reionized neutral stops where it is born, transitions back to the neutral state are not followed
  • ∫nt ds=∫nt dx ∣v∣/vx\int n_t\, ds = \int n_t\, dx\, |\mathbf v| / v_x along the slanted path; τ\tau tabulated by the trapezoidal rule on 1025 nodes plus the profile points and inverted by linear interpolation
  • the product is drawn with the weights ntσtoutσt(0→j)n_t \sigma_t^\mathrm{out} \sigma_t(0 \to j) as coded; ∝∑tntσt(0→j)\propto \sum_t n_t \sigma_t(0 \to j) would be the rate of each channel, the same for one target
  • walls are simgeometry shapes (simgeometry.crossings.crossings: analytic for boxes, spheres and slanted tubes, sampled otherwise); a marker starting inside a wall stops at once
References

FieldRegion

classsource

Markers through static electric and magnetic fields, to the walls or an exit plane.

kick
v−=vn−1/2+ηE,η=qΔt2m\mathbf v^- = \mathbf v^{n-1/2} + \eta \mathbf E, \qquad \eta = \frac{q \Delta t}{2m}
rotation
t=ηB,s=2t1+t2,v′=v−+v−×t,v+=v−+v′×s\mathbf t = \eta \mathbf B, \quad \mathbf s = \frac{2\mathbf t}{1 + t^2}, \quad \mathbf v' = \mathbf v^- + \mathbf v^- \times \mathbf t, \quad \mathbf v^+ = \mathbf v^- + \mathbf v' \times \mathbf s
update
vn+1/2=v++ηE,xn+1=xn+vn+1/2Δt,Δt=ℓ∣v∣\mathbf v^{n+1/2} = \mathbf v^+ + \eta \mathbf E, \qquad \mathbf x^{n+1} = \mathbf x^n + \mathbf v^{n+1/2} \Delta t, \qquad \Delta t = \frac{\ell}{|\mathbf v|}
Order
2
Assumes
  • the fields at xn\mathbf x^n; the leapfrog starts from the velocity pushed back half a step; neutrals move straight
  • steps of path length ℓ\ell = step, each tested against the walls and the exit plane as a straight segment, so ℓ\ell must be well below the radius of curvature
  • the rotation is exact for the angle 2arctan⁡∣t∣2 \arctan |\mathbf t| and keeps ∣v∣|\mathbf v| without an electric field
  • the order is in the step, for the position on the Larmor circle
  • a marker keeps its particles per second, so its power follows its kinetic energy, P=P0 ∣v∣2/∣v0∣2P = P_0\,|\mathbf v|^2 / |\mathbf v_0|^2 with the last half-step velocity: the work of the electric field reaches the walls
References
  • J. P. Boris, Proc. Fourth Conf. Numerical Simulation of Plasmas, 3 (1970)

fit_footprint

functionsource

Fit a 2D Gaussian (axes along y and z) to a calorimeter map.

gaussian
p(y,z)=p0exp⁡(−(y−cy)22wy2−(z−cz)22wz2)p(y, z) = p_0 \exp\left(-\frac{(y - c_y)^2}{2 w_y^2} - \frac{(z - c_z)^2}{2 w_z^2}\right)
Assumes
  • an unweighted least-squares fit (scipy.optimize.curve_fit) on the tile centres, started from the map's power-weighted centre and widths and its maximum
  • no bounds and no fallback: a failed fit raises

gaussian_beam

functionsource

A round Gaussian beam along +x, starting in the plane x (m).

sampling
y,z∼N(0,w2),sy,sz∼N(0,θ2),v=v(1,sy,sz)∣(1,sy,sz)∣y, z \sim \mathcal N(0, w^2), \qquad s_y, s_z \sim \mathcal N(0, \theta^2), \qquad \mathbf v = v \frac{(1, s_y, s_z)}{|(1, s_y, s_z)|}
width
w(L)=w2+(Lθ)2w(L) = \sqrt{w^2 + (L \theta)^2}
Assumes
  • a round beam along +x+x; every marker carries P/NP / N

Markers

classsource

Beam markers in 3D.

weight
w=P12m∣v∣2[s−1]w = \frac{P}{\tfrac12 m |\mathbf v|^2} \quad [\mathrm{s^{-1}}]
rms angle
θy,z=⟨(s−⟨s⟩)2⟩P,s=vyvx, vzvx\theta_{y,z} = \sqrt{\left\langle (s - \langle s \rangle)^2 \right\rangle_P}, \qquad s = \frac{v_y}{v_x}, \ \frac{v_z}{v_x}
drift
x←x+v xplane−xvx\mathbf x \leftarrow \mathbf x + \mathbf v\, \frac{x_\mathrm{plane} - x}{v_x}
placed
x′=R (x−x0x^)+o,R=[e^x,e^z×e^x,e^z]\mathbf x' = R\, (\mathbf x - x_0 \hat{\mathbf x}) + \mathbf o, \qquad R = [\hat{\mathbf e}_x, \hat{\mathbf e}_z \times \hat{\mathbf e}_x, \hat{\mathbf e}_z]
Assumes
  • markers are streams of particles on straight lines (no field acts on them outside a FieldRegion); ⟨⋅⟩P\langle\cdot\rangle_P weighted by the power
  • placed: e^x\hat{\mathbf e}_x along direction, e^z\hat{\mathbf e}_z the part of up normal to it
  • the weight (particles per second) is what freeofcharge reads as a neutral beam