Skip to content

Commit ef081f5

Browse files
Expand docstrings with physics explainations
1 parent 0091375 commit ef081f5

File tree

4 files changed

+252
-93
lines changed

4 files changed

+252
-93
lines changed

docs/api/wakefields.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Wakefields
2+
3+
## Resistive Wall Wakefield Classes
4+
5+
::: pmd_beamphysics.wakefields.ResistiveWallWakefield
6+
7+
::: pmd_beamphysics.wakefields.ResistiveWallPseudomode
8+
9+
## Base Classes
10+
11+
::: pmd_beamphysics.wakefields.WakefieldBase
12+
13+
::: pmd_beamphysics.wakefields.PseudomodeWakefield
14+
15+
::: pmd_beamphysics.wakefields.ImpedanceWakefield
16+
17+
::: pmd_beamphysics.wakefields.TabularWakefield
18+
19+
::: pmd_beamphysics.wakefields.Pseudomode
20+
21+
## Low-level Functions
22+
23+
::: pmd_beamphysics.wakefields.longitudinal_impedance_round
24+
25+
::: pmd_beamphysics.wakefields.longitudinal_impedance_flat
26+
27+
::: pmd_beamphysics.wakefields.wakefield_from_impedance
28+
29+
::: pmd_beamphysics.wakefields.wakefield_from_impedance_fft
30+
31+
::: pmd_beamphysics.wakefields.ac_conductivity
32+
33+
::: pmd_beamphysics.wakefields.surface_impedance
34+
35+
::: pmd_beamphysics.wakefields.characteristic_length

mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ nav:
2121
- examples/fields/corrector_modeling.ipynb
2222
- examples/fields/solenoid_modeling.ipynb
2323
- Wakefields:
24-
- examples/wakefields/resistive_wall_wakefield.ipynb
25-
- examples/wakefields/resistive_wall_impedance.ipynb
24+
- examples/wakefields/resistive_wall.ipynb
2625
- Wavefront:
2726
- examples/wavefront/wavefront.ipynb
2827
- examples/wavefront/advanced_drift.ipynb
@@ -34,6 +33,7 @@ nav:
3433
- API:
3534
- Particles: api/particles.md
3635
- Fields: api/fields.md
36+
- Wakefields: api/wakefields.md
3737

3838
theme:
3939
icon:

pmd_beamphysics/wakefields/base.py

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ def convolve_density(
127127
128128
This computes the causal wake potential:
129129
130-
.. math::
131-
132-
V(z_i) = \\sum_{j>i} Q_j \\cdot W(z_j - z_i) + \\frac{1}{2} Q_i \\cdot W(0)
130+
$$V(z_i) = \\sum_{j>i} Q_j \\cdot W(z_j - z_i) + \\frac{1}{2} Q_i \\cdot W(0)$$
133131
134132
where only particles ahead (larger z index) contribute to the wake
135133
felt by each particle. This is mathematically a correlation, not
@@ -342,69 +340,57 @@ def impedance(self, k: np.ndarray | float) -> np.ndarray | complex:
342340
343341
For a pseudomode wakefield defined for z ≤ 0:
344342
345-
.. math::
346-
347-
W(z) = A \\cdot e^{dz} \\cdot \\sin(k_0 z + \\phi)
343+
$$W(z) = A \\cdot e^{dz} \\cdot \\sin(k_0 z + \\phi)$$
348344
349345
The impedance is defined as:
350346
351-
.. math::
352-
353-
Z(k) = \\frac{1}{c} \\int_{-\\infty}^{0} W(z) \\cdot e^{-ikz} \\, dz
347+
$$Z(k) = \\frac{1}{c} \\int_{-\\infty}^{0} W(z) \\cdot e^{-ikz} \\, dz$$
354348
355349
**Derivation:**
356350
357351
Substituting the wakefield:
358352
359-
.. math::
360-
361-
Z(k) = \\frac{A}{c} \\int_{-\\infty}^{0} e^{dz} \\sin(k_0 z + \\phi) e^{-ikz} \\, dz
362-
363-
Using :math:`\\sin(\\theta) = \\frac{e^{i\\theta} - e^{-i\\theta}}{2i}`:
364-
365-
.. math::
353+
$$Z(k) = \\frac{A}{c} \\int_{-\\infty}^{0} e^{dz} \\sin(k_0 z + \\phi) e^{-ikz} \\, dz$$
366354
367-
Z(k) = \\frac{A}{2ic} \\left[
368-
e^{i\\phi} \\int_{-\\infty}^{0} e^{(d + i(k_0 - k))z} dz
369-
- e^{-i\\phi} \\int_{-\\infty}^{0} e^{(d - i(k_0 + k))z} dz
370-
\\right]
355+
Using $\\sin(\\theta) = \\frac{e^{i\\theta} - e^{-i\\theta}}{2i}$:
371356
372-
Since :math:`d > 0`, both integrals converge:
357+
$$Z(k) = \\frac{A}{2ic} \\left[
358+
e^{i\\phi} \\int_{-\\infty}^{0} e^{(d + i(k_0 - k))z} dz
359+
- e^{-i\\phi} \\int_{-\\infty}^{0} e^{(d - i(k_0 + k))z} dz
360+
\\right]$$
373361
374-
.. math::
362+
Since $d > 0$, both integrals converge:
375363
376-
\\int_{-\\infty}^{0} e^{az} dz = \\frac{1}{a} \\quad \\text{for } \\text{Re}(a) > 0
364+
$$\\int_{-\\infty}^{0} e^{az} dz = \\frac{1}{a} \\quad \\text{for } \\text{Re}(a) > 0$$
377365
378366
Evaluating:
379367
380-
.. math::
381-
382-
Z(k) = \\frac{A}{2ic} \\left[
383-
\\frac{e^{i\\phi}}{d + i(k_0 - k)}
384-
- \\frac{e^{-i\\phi}}{d - i(k_0 + k)}
385-
\\right]
368+
$$Z(k) = \\frac{A}{2ic} \\left[
369+
\\frac{e^{i\\phi}}{d + i(k_0 - k)}
370+
- \\frac{e^{-i\\phi}}{d - i(k_0 + k)}
371+
\\right]$$
386372
387373
**Mathematica verification:**
388374
389-
.. code-block:: mathematica
390-
391-
(* Define the wakefield and compute impedance numerically *)
392-
W[z_, A_, d_, k0_, phi_] := A Exp[d z] Sin[k0 z + phi]
375+
```mathematica
376+
(* Define the wakefield and compute impedance numerically *)
377+
W[z_, A_, d_, k0_, phi_] := A Exp[d z] Sin[k0 z + phi]
393378
394-
(* Analytical result *)
395-
Zanalytic[k_, A_, d_, k0_, phi_] :=
396-
A/(2 I c) (Exp[I phi]/(d + I (k0 - k)) - Exp[-I phi]/(d - I (k0 + k)))
379+
(* Analytical result *)
380+
Zanalytic[k_, A_, d_, k0_, phi_] :=
381+
A/(2 I c) (Exp[I phi]/(d + I (k0 - k)) - Exp[-I phi]/(d - I (k0 + k)))
397382
398-
(* Numerical integration (should match) *)
399-
Znumeric[k_, A_, d_, k0_, phi_] :=
400-
1/c NIntegrate[W[z, A, d, k0, phi] Exp[-I k z], {z, -Infinity, 0}]
383+
(* Numerical integration (should match) *)
384+
Znumeric[k_, A_, d_, k0_, phi_] :=
385+
1/c NIntegrate[W[z, A, d, k0, phi] Exp[-I k z], {z, -Infinity, 0}]
401386
402-
(* Test with sample values *)
403-
c = 299792458;
404-
{A, d, k0, phi} = {1*^15, 1*^4, 1*^5, Pi/4};
405-
ktest = 5*^4;
406-
{Zanalytic[ktest, A, d, k0, phi], Znumeric[ktest, A, d, k0, phi]}
407-
(* Both should give the same complex number *)
387+
(* Test with sample values *)
388+
c = 299792458;
389+
{A, d, k0, phi} = {1*^15, 1*^4, 1*^5, Pi/4};
390+
ktest = 5*^4;
391+
{Zanalytic[ktest, A, d, k0, phi], Znumeric[ktest, A, d, k0, phi]}
392+
(* Both should give the same complex number *)
393+
```
408394
409395
Parameters
410396
----------
@@ -455,9 +441,7 @@ class PseudomodeWakefield(WakefieldBase):
455441
456442
Models the longitudinal wakefield as:
457443
458-
.. math::
459-
460-
W(z) = \\sum_i A_i \\cdot e^{d_i \\cdot z} \\cdot \\sin(k_i \\cdot z + \\phi_i)
444+
$$W(z) = \\sum_i A_i \\cdot e^{d_i \\cdot z} \\cdot \\sin(k_i \\cdot z + \\phi_i)$$
461445
462446
This form is used to approximate short-range wakefields such as the
463447
resistive wall wake.
@@ -852,17 +836,14 @@ class ImpedanceWakefield(WakefieldBase):
852836
853837
Notes
854838
-----
855-
The impedance Z(k) is related to the wakefield W(z) by:
839+
The wakefield W(z) is defined for z ≤ 0 (trailing particles), with W(z) = 0
840+
for z > 0 (causality). The impedance Z(k) is related to the wakefield by:
856841
857-
.. math::
858-
859-
Z(k) = \\frac{1}{c} \\int_0^{\\infty} W(z) e^{-ikz} dz
842+
$$Z(k) = \\frac{1}{c} \\int_{-\\infty}^{0} W(z) e^{-ikz} dz$$
860843
861844
And the inverse:
862845
863-
.. math::
864-
865-
W(z) = \\frac{2c}{\\pi} \\int_0^{\\infty} \\text{Re}[Z(k)] \\cos(kz) dk
846+
$$W(z) = \\frac{2c}{\\pi} \\int_0^{\\infty} \\text{Re}[Z(k)] \\cos(kz) dk \\quad (z \\le 0)$$
866847
867848
Examples
868849
--------

0 commit comments

Comments
 (0)