Skip to main content

lib_jsl_electromagnetics/
antenna_models.rs

1//! Antenna models: analytic far fields, and the derived pattern, power and directivity quantities.
2//!
3//! Every model implements [`Antenna`]. Its required method gives the far field
4//! `(E_θ, E_φ)` with the `e^{-jkr}/r` factor removed, for a unit excitation of the model's kind
5//! ([`Antenna::excitation`]: a terminal current in amperes for wire antennas, the peak aperture
6//! field in V/m for apertures, the edge voltage for patches), in the requested time convention.
7//! Models are defined in their own frame (documented per model); place them with
8//! [`HarmonicField::transformed`] on their pattern containers.
9//!
10//! See the book entry [Antenna models](https://jwkunz.github.io/lib_jsl/book/em-arrays/antennas.html).
11
12pub mod half_wave_dipole;
13pub mod dish;
14pub mod hertzian_dipole;
15pub mod magnetic_loop;
16pub mod patch_antenna;
17
18pub use dish::Dish;
19pub use half_wave_dipole::{Dipole, HalfWaveDipole};
20pub use hertzian_dipole::HertzianDipole;
21pub use magnetic_loop::MagneticLoop;
22pub use patch_antenna::PatchAntenna;
23
24use crate::conventions::{C64, Medium, TimeConvention};
25use crate::coordinates::polarization::PolarizationBasis;
26use crate::fields::domain::Domain;
27use crate::fields::field_container::{FieldQuantity, HarmonicField};
28use lib_jsl_core::ErrorsJSL;
29use std::f64::consts::PI;
30use std::sync::Arc;
31
32/// The physical kind of a model's unit excitation.
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum Excitation {
35    /// A terminal (or reference) current of 1 A peak.
36    Current,
37    /// A peak aperture field of 1 V/m.
38    ApertureField,
39    /// A radiating-edge voltage of 1 V peak.
40    Voltage,
41    /// A dimensionless unit pattern (idealised sources).
42    Normalized,
43}
44
45/// An antenna with an analytic far field.
46pub trait Antenna {
47    /// The far field `[E_θ, E_φ]` in the direction `(θ, φ)` with `e^{-jkr}/r` removed (V), per
48    /// unit excitation, in vacuum.
49    fn far_field(&self, theta: f64, phi: f64, frequency: f64, convention: TimeConvention) -> [C64; 2];
50
51    /// What the unit excitation is.
52    fn excitation(&self) -> Excitation;
53
54    /// The far-field pattern as an electric-field container on a far-field domain (spherical basis).
55    fn far_field_pattern(&self, domain: Arc<Domain>, frequency: f64, convention: TimeConvention) -> Result<HarmonicField, ErrorsJSL> {
56        if !domain.is_far_field() {
57            return Err(ErrorsJSL::InvalidInputRange("Far-field patterns live on the far-field sphere."));
58        }
59        HarmonicField::vector_from_fn(domain, FieldQuantity::ElectricField, PolarizationBasis::SPHERICAL, frequency, convention, |p| {
60            let [et, ep] = self.far_field(p.coords[1], p.coords[2], frequency, convention);
61            [C64::new(0.0, 0.0), et, ep]
62        })
63    }
64
65    /// The `(θ nodes, φ samples)` of the grid used for numerical power integration.
66    fn power_grid(&self, _frequency: f64) -> (usize, usize) {
67        (48, 96)
68    }
69
70    /// The radiated power `∫ |E|² / (2η) dΩ` (W) for a unit excitation.
71    fn radiated_power(&self, frequency: f64) -> f64 {
72        let (nt, np) = self.power_grid(frequency);
73        let d = Domain::far_field_gauss(nt, np).expect("valid grid");
74        let eta = Medium::VACUUM.impedance(TimeConvention::PlusJ).re;
75        d.integrate_fn(|p| {
76            let [a, b] = self.far_field(p.coords[1], p.coords[2], frequency, TimeConvention::PlusJ);
77            (a.norm_sqr() + b.norm_sqr()) / (2.0 * eta)
78        })
79    }
80
81    /// The radiation intensity `U = |E|² / (2η)` (W/sr) for a unit excitation.
82    fn radiation_intensity(&self, theta: f64, phi: f64, frequency: f64) -> f64 {
83        let [a, b] = self.far_field(theta, phi, frequency, TimeConvention::PlusJ);
84        (a.norm_sqr() + b.norm_sqr()) / (2.0 * Medium::VACUUM.impedance(TimeConvention::PlusJ).re)
85    }
86
87    /// The directivity `4π U(θ, φ) / P_rad` in a direction.
88    fn directivity(&self, theta: f64, phi: f64, frequency: f64) -> f64 {
89        4.0 * PI * self.radiation_intensity(theta, phi, frequency) / self.radiated_power(frequency)
90    }
91
92    /// The peak directivity, searched on a half-degree grid.
93    fn peak_directivity(&self, frequency: f64) -> f64 {
94        let p = self.radiated_power(frequency);
95        let mut best: f64 = 0.0;
96        for i in 0..=360 {
97            for j in 0..720 {
98                let (t, f) = (PI * i as f64 / 360.0, PI * j as f64 / 360.0);
99                best = best.max(self.radiation_intensity(t, f, frequency));
100            }
101        }
102        4.0 * PI * best / p
103    }
104
105    /// The radiation resistance `2 P / |I|²` (Ω) referred to the unit excitation current, for
106    /// current-excited models.
107    fn radiation_resistance(&self, frequency: f64) -> Option<f64> {
108        (self.excitation() == Excitation::Current).then(|| 2.0 * self.radiated_power(frequency))
109    }
110
111    /// The pattern scaled so that `|E_θ|² + |E_φ|²` equals the directivity times `efficiency`
112    /// (the gain): the normalisation the array signal models expect.
113    fn gain_pattern(&self, domain: Arc<Domain>, frequency: f64, convention: TimeConvention, efficiency: f64) -> Result<HarmonicField, ErrorsJSL> {
114        let p = self.radiated_power(frequency);
115        if p.is_nan() || p <= 0.0 || !(0.0..=1.0).contains(&efficiency) {
116            return Err(ErrorsJSL::InvalidInputRange("Need a radiating antenna and an efficiency in [0, 1]."));
117        }
118        let eta = Medium::VACUUM.impedance(convention).re;
119        let scale = (4.0 * PI * efficiency / (2.0 * eta * p)).sqrt();
120        Ok(self.far_field_pattern(domain, frequency, convention)?.scaled(C64::new(scale, 0.0)))
121    }
122}
123
124/// An idealised point source radiating equally in every direction with a fixed polarization
125/// `[p_θ, p_φ]` (not physically realisable for all directions at once, but the standard array
126/// model element). Its unit pattern has directivity 1.
127#[derive(Debug, Clone, Copy, PartialEq)]
128pub struct Isotropic {
129    pub polarization: [C64; 2],
130}
131
132impl Isotropic {
133    /// θ̂-polarized.
134    pub fn theta_polarized() -> Self {
135        Isotropic { polarization: [C64::new(1.0, 0.0), C64::new(0.0, 0.0)] }
136    }
137}
138
139impl Antenna for Isotropic {
140    fn far_field(&self, _theta: f64, _phi: f64, _frequency: f64, _convention: TimeConvention) -> [C64; 2] {
141        let n = (self.polarization[0].norm_sqr() + self.polarization[1].norm_sqr()).sqrt().max(1e-300);
142        self.polarization.map(|v| v / n)
143    }
144
145    fn excitation(&self) -> Excitation {
146        Excitation::Normalized
147    }
148}
149
150#[cfg(test)]
151mod tests {
152    use super::*;
153
154    #[test]
155    fn isotropic_source_has_unit_directivity_and_gain_patterns_are_normalised() {
156        let iso = Isotropic::theta_polarized();
157        let f = 1e9;
158        assert!((iso.directivity(0.3, 1.0, f) - 1.0).abs() < 1e-12);
159        assert!((iso.peak_directivity(f) - 1.0).abs() < 1e-12);
160        assert_eq!(iso.radiation_resistance(f), None);
161        let d = Arc::new(Domain::far_field_gauss(8, 16).unwrap());
162        let g = iso.gain_pattern(d.clone(), f, TimeConvention::PlusJ, 0.5).unwrap();
163        assert!(g.norm_squared().iter().all(|v| (v - 0.5).abs() < 1e-12)); // |g|² = efficiency × D
164        assert!((g.integrate_norm_squared() - 2.0 * PI).abs() < 1e-12); // ∫ G dΩ = 4π η
165        assert!(iso.gain_pattern(d.clone(), f, TimeConvention::PlusJ, 1.5).is_err());
166        assert!(iso.far_field_pattern(Arc::new(Domain::plane(crate::fields::domain::Axis::uniform(0.0, 1.0, 2).unwrap(), crate::fields::domain::Axis::uniform(0.0, 1.0, 2).unwrap(), 0.0).unwrap()), f, TimeConvention::PlusJ).is_err());
167    }
168}