lib_jsl_electromagnetics/antenna_models/
dish.rs1use super::{Antenna, Excitation};
6use crate::conventions::{C64, Medium, TimeConvention};
7use lib_jsl_core::constants::em::C0;
8use lib_jsl_special_functions::bessel_functions_integer::bessel_j_integer;
9use std::f64::consts::{PI, TAU};
10
11#[derive(Debug, Clone, Copy, PartialEq)]
21pub struct Dish {
22 pub diameter: f64,
23 pub taper: u32,
24}
25
26impl Dish {
27 pub fn new(diameter: f64) -> Self {
29 Dish { diameter, taper: 0 }
30 }
31
32 pub fn with_taper(diameter: f64, taper: u32) -> Self {
34 Dish { diameter, taper }
35 }
36
37 pub fn aperture_efficiency(&self) -> f64 {
39 let p = f64::from(self.taper);
40 (2.0 * p + 1.0) / ((p + 1.0) * (p + 1.0))
41 }
42
43 pub fn boresight_directivity(&self, frequency: f64) -> f64 {
45 (PI * self.diameter * frequency / C0).powi(2) * self.aperture_efficiency()
46 }
47
48 pub fn half_power_beamwidth(&self, frequency: f64) -> f64 {
50 let peak = self.radiation_intensity(0.0, 0.0, frequency);
51 let (mut lo, mut hi) = (0.0, PI / 2.0);
52 let first_null = 3.8317 / (TAU * frequency / C0 * self.diameter / 2.0);
54 hi = f64::min(hi, first_null * (1.0 + f64::from(self.taper)));
55 for _ in 0..100 {
56 let mid = 0.5 * (lo + hi);
57 if self.radiation_intensity(mid, 0.0, frequency) > 0.5 * peak {
58 lo = mid;
59 } else {
60 hi = mid;
61 }
62 }
63 2.0 * lo
64 }
65}
66
67impl Antenna for Dish {
68 fn far_field(&self, theta: f64, phi: f64, frequency: f64, convention: TimeConvention) -> [C64; 2] {
69 let k = TAU * frequency / C0;
70 let a = self.diameter / 2.0;
71 let u = k * a * theta.sin();
72 let p = self.taper as i32;
73 let factorial: f64 = (1..=self.taper).map(f64::from).product();
74 let lambda = if u.abs() < 1e-6 { 1.0 / (2.0 * (f64::from(self.taper) + 1.0)) } else { 2f64.powi(p) * factorial * bessel_j_integer(p + 1, u) / u.powi(p + 1) };
76 let amplitude = convention.unit() * (k * a * a * lambda * (1.0 + theta.cos()) / 2.0);
77 [amplitude * phi.sin(), amplitude * phi.cos()]
78 }
79
80 fn excitation(&self) -> Excitation {
81 Excitation::ApertureField
82 }
83
84 fn radiated_power(&self, _frequency: f64) -> f64 {
85 let a = self.diameter / 2.0;
86 let eta = Medium::VACUUM.impedance(TimeConvention::PlusJ).re;
87 PI * a * a / (2.0 * eta * (2.0 * f64::from(self.taper) + 1.0))
88 }
89
90 fn peak_directivity(&self, frequency: f64) -> f64 {
91 self.boresight_directivity(frequency)
92 }
93}
94
95#[cfg(test)]
96mod tests {
97 use super::*;
98 use crate::fields::domain::{Axis, Domain};
99 use crate::fields::physics::radiated_power;
100 use std::sync::Arc;
101
102 #[test]
103 fn boresight_directivity_matches_the_aperture_formula() {
104 let f = 10e9;
105 let lambda = C0 / f;
106 for taper in [0, 1, 2] {
107 let dish = Dish::with_taper(10.0 * lambda, taper);
108 let d = dish.directivity(0.0, 0.0, f);
109 assert!((d - dish.boresight_directivity(f)).abs() < 1e-9 * d, "taper {taper}");
110 }
111 assert!((Dish::new(1.0).aperture_efficiency() - 1.0).abs() < 1e-15);
112 assert!((Dish::with_taper(1.0, 1).aperture_efficiency() - 0.75).abs() < 1e-15);
113 assert!((Dish::new(10.0 * lambda).boresight_directivity(f) - 986.96).abs() < 0.01);
115 }
116
117 #[test]
118 fn analytic_power_agrees_with_the_far_field_integral_and_tapers_widen_the_beam() {
119 let f = 10e9;
120 let lambda = C0 / f;
121 let dish = Dish::with_taper(4.0 * lambda, 1);
122 let d = Arc::new(Domain::far_field_sphere(Axis::gauss_legendre_polar(160).unwrap(), Axis::periodic(0.0, TAU, 16).unwrap()).unwrap());
124 let e = dish.far_field_pattern(d, f, TimeConvention::PlusJ).unwrap();
125 let numeric = radiated_power(&e, &crate::conventions::Medium::VACUUM).unwrap();
126 assert!((numeric - dish.radiated_power(f)).abs() < 0.03 * numeric, "{numeric} vs {}", dish.radiated_power(f));
128 let uniform = Dish::new(20.0 * lambda);
130 let hpbw = uniform.half_power_beamwidth(f);
131 assert!((hpbw - 1.029 * lambda / (20.0 * lambda)).abs() < 2e-3 * hpbw.max(1.0), "{hpbw}");
132 assert!(Dish::with_taper(20.0 * lambda, 2).half_power_beamwidth(f) > hpbw);
133 let [et, ep] = uniform.far_field(0.01, PI / 2.0, f, TimeConvention::PlusJ);
135 assert!(et.norm() > 0.0 && ep.norm() < 1e-12 * et.norm());
136 }
137}