Skip to main content

lib_jsl_electromagnetics/antenna_models/
magnetic_loop.rs

1//! The small circular loop (magnetic dipole).
2//!
3//! See the book entry [Antenna models](https://jwkunz.github.io/lib_jsl/book/em-arrays/antennas.html).
4
5use super::{Antenna, Excitation};
6use crate::conventions::{C64, Medium, TimeConvention};
7use crate::coordinates::polarization::PolarizationBasis;
8use crate::coordinates::systems::{CoordinateSystem, Position};
9use crate::fields::domain::Domain;
10use crate::fields::field_container::{FieldQuantity, HarmonicField};
11use lib_jsl_core::ErrorsJSL;
12use lib_jsl_core::constants::em::C0;
13use std::f64::consts::{PI, TAU};
14use std::sync::Arc;
15
16/// A loop of radius `a ≪ λ` in the `xy` plane centred at the origin, `turns` turns, carrying a
17/// uniform current `I` (counter-clockwise about `+z`). It radiates as a magnetic dipole
18/// `m = N π a² I ẑ` (Balanis §5.2), in the `e^{+jωt}` convention:
19/// - `H_r = j k a² N I cos θ / (2 r²) (1 + 1/(jkr)) e^{-jkr}`
20/// - `H_θ = -(ka)² N I sin θ / (4 r) (1 + 1/(jkr) - 1/(kr)²) e^{-jkr}`
21/// - `E_φ = η (ka)² N I sin θ / (4 r) (1 + 1/(jkr)) e^{-jkr}`
22///
23/// Directivity 1.5; radiation resistance `20π² (ka)⁴ N²`.
24#[derive(Debug, Clone, Copy, PartialEq)]
25pub struct MagneticLoop {
26    pub radius: f64,
27    pub turns: u32,
28}
29
30impl MagneticLoop {
31    pub fn new(radius: f64, turns: u32) -> Self {
32        MagneticLoop { radius, turns }
33    }
34
35    /// The exact radiation resistance `20π² (ka)⁴ N²`.
36    pub fn exact_radiation_resistance(&self, frequency: f64) -> f64 {
37        let ka = TAU * frequency / C0 * self.radius;
38        20.0 * PI * PI * ka.powi(4) * f64::from(self.turns).powi(2)
39    }
40
41    /// The exact `(E, H)` at `p` (spherical components) for a unit current.
42    pub fn near_field(&self, p: &Position, frequency: f64, convention: TimeConvention) -> ([C64; 3], [C64; 3]) {
43        let s = p.in_system(CoordinateSystem::Spherical).coords;
44        let (r, theta) = (s[0], s[1]);
45        let k = TAU * frequency / C0;
46        let eta = Medium::VACUUM.impedance(TimeConvention::PlusJ).re;
47        let j = C64::new(0.0, 1.0);
48        let (kr, a2n) = (k * r, self.radius * self.radius * f64::from(self.turns));
49        let phase = (-j * kr).exp();
50        let hr = j * k * a2n * theta.cos() / (2.0 * r * r) * (1.0 + 1.0 / (j * kr)) * phase;
51        let ht = -(k * k * a2n) * theta.sin() / (4.0 * r) * (1.0 + 1.0 / (j * kr) - 1.0 / (kr * kr)) * phase;
52        let ep = eta * k * k * a2n * theta.sin() / (4.0 * r) * (1.0 + 1.0 / (j * kr)) * phase;
53        let conv = |v: C64| TimeConvention::PlusJ.convert(v, convention);
54        let zero = C64::new(0.0, 0.0);
55        ([zero, zero, conv(ep)], [conv(hr), conv(ht), zero])
56    }
57
58    /// The exact `E` and `H` on a spatial domain (spherical basis).
59    pub fn near_field_containers(&self, domain: Arc<Domain>, frequency: f64, convention: TimeConvention) -> Result<(HarmonicField, HarmonicField), ErrorsJSL> {
60        let e = HarmonicField::vector_from_fn(domain.clone(), FieldQuantity::ElectricField, PolarizationBasis::SPHERICAL, frequency, convention, |p| self.near_field(p, frequency, convention).0)?;
61        let h = HarmonicField::vector_from_fn(domain, FieldQuantity::MagneticField, PolarizationBasis::SPHERICAL, frequency, convention, |p| self.near_field(p, frequency, convention).1)?;
62        Ok((e, h))
63    }
64}
65
66impl Antenna for MagneticLoop {
67    fn far_field(&self, theta: f64, _phi: f64, frequency: f64, convention: TimeConvention) -> [C64; 2] {
68        let k = TAU * frequency / C0;
69        let eta = Medium::VACUUM.impedance(TimeConvention::PlusJ).re;
70        let v = eta * k * k * self.radius * self.radius * f64::from(self.turns) * theta.sin() / 4.0;
71        // Real in e^{+jωt}; conjugation leaves it unchanged in the other convention.
72        let _ = convention;
73        [C64::new(0.0, 0.0), C64::new(v, 0.0)]
74    }
75
76    fn excitation(&self) -> Excitation {
77        Excitation::Current
78    }
79
80    fn peak_directivity(&self, _frequency: f64) -> f64 {
81        1.5
82    }
83}
84
85#[cfg(test)]
86mod tests {
87    use super::*;
88    use crate::fields::domain::Axis;
89    use crate::fields::physics::power_through_surface;
90
91    #[test]
92    fn resistance_scales_as_the_fourth_power_and_with_turns_squared() {
93        let f = 1e8;
94        let lambda = C0 / f;
95        let one = MagneticLoop::new(lambda / 50.0, 1);
96        let r1 = one.radiation_resistance(f).unwrap();
97        assert!((r1 - one.exact_radiation_resistance(f)).abs() < 1e-3 * r1);
98        let bigger = MagneticLoop::new(lambda / 25.0, 1);
99        assert!((bigger.radiation_resistance(f).unwrap() / r1 - 16.0).abs() < 1e-6);
100        let coil = MagneticLoop::new(lambda / 50.0, 5);
101        assert!((coil.radiation_resistance(f).unwrap() / r1 - 25.0).abs() < 1e-6);
102        assert!((one.directivity(PI / 2.0, 2.0, f) - 1.5).abs() < 1e-9);
103        // φ-polarized, unlike the electric dipole.
104        let [et, ep] = one.far_field(1.0, 0.0, f, TimeConvention::PlusJ);
105        assert!(et.norm() == 0.0 && ep.norm() > 0.0);
106    }
107
108    #[test]
109    fn near_field_flux_and_duality_with_the_electric_dipole() {
110        let f = 3e8;
111        let lp = MagneticLoop::new(0.02, 1);
112        let p_far = lp.radiated_power(f);
113        for radius in [0.04, 0.5, 3.0] {
114            let sphere = Arc::new(Domain::sphere(radius, Axis::gauss_legendre_polar(12).unwrap(), Axis::periodic(0.0, TAU, 8).unwrap()).unwrap());
115            let (e, h) = lp.near_field_containers(sphere, f, TimeConvention::PlusJ).unwrap();
116            let p = power_through_surface(&e, &h).unwrap();
117            assert!((p - p_far).abs() < 1e-9 * p_far, "r = {radius}");
118        }
119        // Far-field limit of the near field.
120        let k = TAU * f / C0;
121        let r = 1e4;
122        let (e, _) = lp.near_field(&Position::spherical(r, 0.8, 0.0), f, TimeConvention::MinusI);
123        let scaled = e[2] * r * C64::new(0.0, -k * r).exp();
124        assert!((scaled - lp.far_field(0.8, 0.0, f, TimeConvention::MinusI)[1]).norm() < 1e-3 * scaled.norm());
125    }
126}