Skip to main content

lib_jsl_electromagnetics/antenna_models/
hertzian_dipole.rs

1//! The Hertzian (infinitesimal) electric 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 uniform current `I` on a short wire of length `l ≪ λ` along `+z` at the origin.
17///
18/// Exact fields for all `r > 0` (Balanis §4.2), in the `e^{+jωt}` convention:
19/// - `E_r = η I l cos θ / (2π r²) (1 + 1/(jkr)) e^{-jkr}`
20/// - `E_θ = j η k I l sin θ / (4π r) (1 + 1/(jkr) - 1/(kr)²) e^{-jkr}`
21/// - `H_φ = j k I l sin θ / (4π r) (1 + 1/(jkr)) e^{-jkr}`
22///
23/// Directivity 1.5; radiation resistance `80π² (l/λ)²`.
24#[derive(Debug, Clone, Copy, PartialEq)]
25pub struct HertzianDipole {
26    pub length: f64,
27}
28
29impl HertzianDipole {
30    pub fn new(length: f64) -> Self {
31        HertzianDipole { length }
32    }
33
34    /// The exact radiation resistance `80π² (l/λ)²`.
35    pub fn exact_radiation_resistance(&self, frequency: f64) -> f64 {
36        80.0 * PI * PI * (self.length * frequency / C0).powi(2)
37    }
38
39    /// The exact electric and magnetic fields `(E, H)` at `p` (spherical components
40    /// `[r, θ, φ]`) for a unit current.
41    pub fn near_field(&self, p: &Position, frequency: f64, convention: TimeConvention) -> ([C64; 3], [C64; 3]) {
42        let s = p.in_system(CoordinateSystem::Spherical).coords;
43        let (r, theta) = (s[0], s[1]);
44        let k = TAU * frequency / C0;
45        let eta = Medium::VACUUM.impedance(TimeConvention::PlusJ).re;
46        let j = C64::new(0.0, 1.0);
47        let kr = k * r;
48        let phase = (-j * kr).exp();
49        let il = self.length;
50        let er = eta * il * theta.cos() / (TAU * r * r) * (1.0 + 1.0 / (j * kr)) * phase;
51        let et = j * eta * k * il * theta.sin() / (4.0 * PI * r) * (1.0 + 1.0 / (j * kr) - 1.0 / (kr * kr)) * phase;
52        let hp = j * k * il * theta.sin() / (4.0 * PI * 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        ([conv(er), conv(et), zero], [zero, zero, conv(hp)])
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 HertzianDipole {
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        [convention.unit() * (eta * k * self.length * theta.sin() / (4.0 * PI)), C64::new(0.0, 0.0)]
71    }
72
73    fn excitation(&self) -> Excitation {
74        Excitation::Current
75    }
76
77    fn peak_directivity(&self, _frequency: f64) -> f64 {
78        1.5
79    }
80}
81
82#[cfg(test)]
83mod tests {
84    use super::*;
85    use crate::fields::domain::Axis;
86    use crate::fields::physics::power_through_surface;
87
88    #[test]
89    fn textbook_resistance_and_directivity() {
90        let f = 1e9;
91        let d = HertzianDipole::new(0.01 * C0 / f); // l = λ/100
92        let r = d.radiation_resistance(f).unwrap();
93        assert!((r - d.exact_radiation_resistance(f)).abs() < 1e-3 * r, "{r}");
94        assert!((r - 80.0 * PI * PI * 1e-4).abs() < 2e-3 * r); // ≈ 0.079 Ω
95        assert!((d.directivity(PI / 2.0, 0.7, f) - 1.5).abs() < 1e-9);
96        assert!(d.directivity(0.0, 0.0, f).abs() < 1e-12);
97        let generic_peak = Antenna::directivity(&d, PI / 2.0, 0.0, f);
98        assert!((generic_peak - d.peak_directivity(f)).abs() < 1e-9);
99    }
100
101    #[test]
102    fn near_field_power_flux_equals_the_far_field_power_at_any_radius() {
103        let f = 3e8; // λ = 1 m
104        let d = HertzianDipole::new(0.05);
105        let p_far = d.radiated_power(f);
106        for radius in [0.05, 0.3, 4.0] {
107            let sphere = Arc::new(Domain::sphere(radius, Axis::gauss_legendre_polar(12).unwrap(), Axis::periodic(0.0, TAU, 8).unwrap()).unwrap());
108            for conv in [TimeConvention::PlusJ, TimeConvention::MinusI] {
109                let (e, h) = d.near_field_containers(sphere.clone(), f, conv).unwrap();
110                let p = power_through_surface(&e, &h).unwrap();
111                assert!((p - p_far).abs() < 1e-9 * p_far, "r = {radius}: {p} vs {p_far}");
112            }
113        }
114        // Far away, r e^{jkr} E approaches the far-field pattern.
115        let k = TAU * f / C0;
116        let r = 1e4;
117        let (e, _) = d.near_field(&Position::spherical(r, 1.0, 0.0), f, TimeConvention::PlusJ);
118        let scaled = e[1] * r * C64::new(0.0, k * r).exp();
119        assert!((scaled - d.far_field(1.0, 0.0, f, TimeConvention::PlusJ)[0]).norm() < 1e-3 * scaled.norm());
120    }
121}