lib_jsl_electromagnetics/antenna_models/
patch_antenna.rs1use super::{Antenna, Excitation};
6use crate::conventions::{C64, Medium, TimeConvention};
7use crate::fields::domain::{Axis, Domain};
8use lib_jsl_core::ErrorsJSL;
9use lib_jsl_core::constants::em::C0;
10use lib_jsl_special_functions::bessel_functions_integer::bessel_j_integer;
11use std::f64::consts::{PI, TAU};
12
13#[derive(Debug, Clone, Copy, PartialEq)]
27pub struct PatchAntenna {
28 pub width: f64,
29 pub length: f64,
30 pub height: f64,
31 pub eps_r: f64,
32}
33
34fn sinc(x: f64) -> f64 {
35 if x.abs() < 1e-12 { 1.0 } else { x.sin() / x }
36}
37
38impl PatchAntenna {
39 pub fn new(width: f64, length: f64, height: f64, eps_r: f64) -> Result<Self, ErrorsJSL> {
40 if [width, length, height].iter().any(|v| !(v.is_finite() && *v > 0.0)) || eps_r.is_nan() || eps_r < 1.0 {
41 return Err(ErrorsJSL::InvalidInputRange("Need positive dimensions and eps_r >= 1."));
42 }
43 Ok(PatchAntenna { width, length, height, eps_r })
44 }
45
46 pub fn design(frequency: f64, eps_r: f64, height: f64) -> Result<Self, ErrorsJSL> {
49 let width = C0 / (2.0 * frequency) * (2.0 / (eps_r + 1.0)).sqrt();
50 let probe = PatchAntenna::new(width, 1.0, height, eps_r)?;
51 let length = C0 / (2.0 * frequency * probe.effective_permittivity().sqrt()) - 2.0 * probe.length_extension();
52 PatchAntenna::new(width, length, height, eps_r)
53 }
54
55 pub fn effective_permittivity(&self) -> f64 {
57 (self.eps_r + 1.0) / 2.0 + (self.eps_r - 1.0) / 2.0 / (1.0 + 12.0 * self.height / self.width).sqrt()
58 }
59
60 pub fn length_extension(&self) -> f64 {
62 let e = self.effective_permittivity();
63 let wh = self.width / self.height;
64 0.412 * self.height * (e + 0.3) * (wh + 0.264) / ((e - 0.258) * (wh + 0.8))
65 }
66
67 pub fn effective_length(&self) -> f64 {
69 self.length + 2.0 * self.length_extension()
70 }
71
72 pub fn resonant_frequency(&self) -> f64 {
74 C0 / (2.0 * self.effective_length() * self.effective_permittivity().sqrt())
75 }
76
77 fn slot_integral(&self, frequency: f64, coupled: bool) -> f64 {
78 let k = TAU * frequency / C0;
79 let axis = Axis::gauss_legendre(0.0, PI, 200).expect("valid");
80 axis.values()
81 .iter()
82 .zip(axis.weights())
83 .map(|(&t, &w)| {
84 let c = t.cos();
85 let x = 0.5 * k * self.width * c;
86 let base = if c.abs() < 1e-12 { (0.5 * k * self.width).powi(2) } else { (x.sin() / c).powi(2) };
88 let j0 = if coupled { bessel_j_integer(0, k * self.length * t.sin()) } else { 1.0 };
89 w * base * j0 * t.sin().powi(3)
90 })
91 .sum()
92 }
93
94 pub fn slot_conductance(&self, frequency: f64) -> f64 {
96 self.slot_integral(frequency, false) / (120.0 * PI * PI)
97 }
98
99 pub fn mutual_conductance(&self, frequency: f64) -> f64 {
101 self.slot_integral(frequency, true) / (120.0 * PI * PI)
102 }
103
104 pub fn edge_resistance(&self, frequency: f64) -> f64 {
106 1.0 / (2.0 * (self.slot_conductance(frequency) + self.mutual_conductance(frequency)))
107 }
108
109 pub fn inset_resistance(&self, frequency: f64, inset: f64) -> f64 {
111 self.edge_resistance(frequency) * (PI * inset / self.length).cos().powi(2)
112 }
113
114 pub fn inset_for_resistance(&self, frequency: f64, target: f64) -> Option<f64> {
116 let edge = self.edge_resistance(frequency);
117 (target > 0.0 && target <= edge).then(|| self.length / PI * (target / edge).sqrt().acos())
118 }
119}
120
121impl Antenna for PatchAntenna {
122 fn far_field(&self, theta: f64, phi: f64, frequency: f64, convention: TimeConvention) -> [C64; 2] {
123 if theta > PI / 2.0 {
124 return [C64::new(0.0, 0.0); 2];
125 }
126 let k = TAU * frequency / C0;
127 let (st, ct) = theta.sin_cos();
128 let (sp, cp) = phi.sin_cos();
129 let slot = 2.0 * self.width * sinc(0.5 * k * self.width * st * sp);
130 let array = 2.0 * (0.5 * k * self.effective_length() * st * cp).cos();
131 let j = convention.unit();
132 let common = k / (4.0 * PI) * slot * array;
133 [-j * (common * cp), j * (common * ct * sp)]
134 }
135
136 fn excitation(&self) -> Excitation {
137 Excitation::Voltage
138 }
139
140 fn radiated_power(&self, frequency: f64) -> f64 {
141 let d = Domain::far_field_sphere(Axis::gauss_legendre(0.0, PI / 2.0, 64).expect("valid"), Axis::periodic(0.0, TAU, 128).expect("valid")).expect("valid");
143 let eta = Medium::VACUUM.impedance(TimeConvention::PlusJ).re;
144 d.integrate_fn(|p| {
145 let [a, b] = self.far_field(p.coords[1], p.coords[2], frequency, TimeConvention::PlusJ);
146 (a.norm_sqr() + b.norm_sqr()) / (2.0 * eta)
147 })
148 }
149
150 fn peak_directivity(&self, frequency: f64) -> f64 {
151 self.directivity(0.0, 0.0, frequency)
153 }
154}
155
156#[cfg(test)]
157mod tests {
158 use super::*;
159
160 #[test]
161 fn design_reproduces_the_textbook_example() {
162 let p = PatchAntenna::design(10e9, 2.2, 0.1588e-2).unwrap();
164 assert!((p.width - 1.186e-2).abs() < 0.005e-2, "W = {}", p.width);
165 assert!((p.effective_permittivity() - 1.972).abs() < 0.002);
166 assert!((p.length_extension() - 0.081e-2).abs() < 0.001e-2);
167 assert!((p.length - 0.906e-2).abs() < 0.005e-2, "L = {}", p.length);
168 assert!((p.resonant_frequency() - 10e9).abs() < 1e3);
169 }
170
171 #[test]
172 fn impedance_and_inset_feed() {
173 let f = 10e9;
174 let p = PatchAntenna::design(f, 2.2, 0.1588e-2).unwrap();
175 let (g1, g12) = (p.slot_conductance(f), p.mutual_conductance(f));
176 assert!((g1 - 1.57e-3).abs() < 0.05e-3, "G1 = {g1}"); assert!(g12 > 0.0 && g12 < g1);
178 let edge = p.edge_resistance(f);
179 assert!((150.0..300.0).contains(&edge), "{edge}");
180 let y0 = p.inset_for_resistance(f, 50.0).unwrap();
181 assert!((p.inset_resistance(f, y0) - 50.0).abs() < 1e-9 && y0 > 0.0 && y0 < p.length / 2.0);
182 assert!(p.inset_for_resistance(f, edge * 2.0).is_none());
183 assert!(PatchAntenna::new(1.0, 1.0, 0.0, 2.0).is_err() && PatchAntenna::new(1.0, 1.0, 1.0, 0.5).is_err());
184 }
185
186 #[test]
187 fn pattern_is_broadside_with_the_usual_directivity_and_no_back_radiation() {
188 let f = 10e9;
189 let p = PatchAntenna::design(f, 2.2, 0.1588e-2).unwrap();
190 let d = p.peak_directivity(f);
191 assert!((5.0..9.0).contains(&d), "D = {d} ({:.2} dBi)", 10.0 * d.log10());
192 assert_eq!(p.far_field(2.0, 0.3, f, TimeConvention::PlusJ), [C64::new(0.0, 0.0); 2]);
193 let [et, ep] = p.far_field(PI / 2.0 - 1e-9, 0.0, f, TimeConvention::PlusJ);
196 assert!(et.norm() > 0.0 && ep.norm() < 1e-12);
197 let [_, eph] = p.far_field(PI / 2.0 - 1e-9, PI / 2.0, f, TimeConvention::PlusJ);
198 assert!(eph.norm() < 1e-6 * et.norm());
199 }
200}