Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Fields on grids: conventions, domains, quadrature and vector calculus

ProblemRepresent electromagnetic fields sampled on surfaces and volumes, in any coordinate system and polarisation basis, and integrate, interpolate, transform and differentiate them consistently
Devised byStandard electromagnetic theory (Maxwell, 1865; Poynting, 1884); Carl Friedrich Gauss (1814), Gaussian quadrature; finite differences on curvilinear grids
AccuracySphere quadrature exact to rounding for band-limited patterns (Gauss-Legendre in ); fourth-order derivatives (tables below); Poynting flux conserved to all digits printed
Cost storage and per-sample operations for samples; interpolation per query for cubic stencils in dimensions
Read firstPreliminaries: complex numbers
APITimeConvention, Medium, Position, PolarizationBasis, RigidTransform, Axis, Domain, HarmonicField, TimeField, physics (plane_wave, poynting, power_through_surface, directivity), overlap_integral

Overview

Antennas, arrays and solvers all produce or consume fields: vectors attached to points of space, at one frequency (complex phasors) or over time. This entry describes how the library holds them. A field is a container of samples on a structured domain: a plane, sphere or cylinder for surfaces, or a box, spherical shell or cylinder for volumes. It carries its quantity (E, H, J, …), its polarisation basis (Cartesian, spherical, cylindrical, or circular), and for phasors the frequency and time convention. Each domain carries quadrature weights with the Jacobian included, so every integral, from radiated power to overlap integrals, is a weighted sum. Fields can be converted between bases, interpolated onto other grids, rotated and translated, and differentiated (gradient, divergence, curl, Laplacians) in their native curvilinear coordinates.

Where it is used

Electromagnetic simulations and measurements produce fields on grids; this entry is how those samples are handled consistently.

  • Antenna and scattering measurements. Near-field scanners record fields over a plane or sphere around an antenna, and integrate them to find power and gain.
  • Simulation post-processing. Output of finite-element and FDTD solvers (field maps, current densities) is integrated, differentiated and converted between coordinate systems and polarisation bases.
  • Education. Visualising a dipole’s field, a waveguide mode or a plane wave on a grid builds intuition for Maxwell’s equations.

History

James Clerk Maxwell’s equations (1865), in Oliver Heaviside’s vector form (1880s), and John Henry Poynting’s theorem on energy flow (1884) are the physics. Two conventions for phasors have coexisted since the start of AC circuit theory. Engineers write , following Charles Steinmetz (1893), and physicists write . Every formula’s signs depend on the choice, and mixing them is a classic source of errors. Carl Friedrich Gauss (1814) devised the quadrature that integrates polynomials of twice the degree of equally many uniformly spaced points. On the sphere, Gauss-Legendre nodes in with uniform azimuth integrate band-limited patterns exactly.

The idea

Conventions

Units are SI, and phasors are peak amplitudes, so time averages carry a factor ½, as in . TimeConvention is either PlusJ, meaning (the default, with outgoing waves ), or MinusI, meaning . Converting between them is complex conjugation, and operations on two fields check that they agree. Spherical angles follow the physics convention: from , from . Far fields are stored with the factor removed, as .

Domains and quadrature

A domain is a product of one-dimensional Axis objects, each with nodes and weights: uniform (trapezoidal), periodic (for azimuth), or Gauss-Legendre. The domain multiplies in the Jacobian, on spheres or in cylinders, so on any of them. For the far-field sphere, Gauss-Legendre nodes in integrate a pattern that is a polynomial in of degree up to exactly, and uniform azimuth samples integrate trigonometric polynomials exactly. A uniform grid in converges only algebraically:

Figure 20.1. Sphere quadrature.

Bases, interpolation and rigid transforms

Every polarisation basis is a position-dependent map to Cartesian components, so a change of basis goes through Cartesian at each sample’s position. The circular basis uses the right- and left-hand components transverse to the system’s reference direction (IEEE handedness). Interpolation by nearest, linear or cubic (four-point Lagrange) stencils is separable over the axes. It wraps periodic axes and continues across the poles of a sphere onto the reflected samples . Vector fields are interpolated in Cartesian components, since and components change sign across a pole. A rotation moves both the sample positions and the vectors. A translation of a far field multiplies it by the phase ramp .

Vector calculus on curvilinear grids

Derivatives along each native axis use five-point Lagrange stencils (fourth order, any spacing; three points on short axes). They combine into Cartesian derivatives through the local frame and scale factors :

applied to the smooth Cartesian components. Gradient, divergence, curl and Laplacians follow. Samples where a scale factor vanishes (the axis of a cylinder, the centre or poles of a sphere) are returned as NaN. Checking Faraday’s law for a plane wave shows the fourth order:

Table 20.1. Convergence of the sampled-field curl check with sampling density.

samplessamples per wavelengthmax ‖∇×E + jωμ₀H‖ ÷ k‖E‖observed ordermax ‖∇·E‖ (V/m²)
6³107.6e-31e-14
11³204.8e-44.03e-14
21³403.0e-54.06e-14
41³801.9e-64.01e-13

The divergence vanishes to rounding because the plane wave’s field is transverse. Surface operators (surface gradient, divergence, curl and the Laplace-Beltrami operator) are provided for plane, sphere and cylinder domains.

Physics on fields

The physics module computes the Poynting vector (or for time-domain fields), the power through a surface, radiation intensity, directivity and wave impedance, and fields from potentials, , (signs per the convention). The overlap integral

measures how well two fields match, as in the coupling of a beam into a mode or of a feed to a reflector. overlap_integral resamples the second field onto the first’s domain and compares them in Cartesian components, so the fields may live on different grids and in different bases.

Algorithm

Integrating a field over its domain: multiply each sample by its weight, the product of the one-dimensional quadrature weights of the axes and the Jacobian at that sample ( on a sphere, in a cylinder), and add them up.

Changing the polarisation basis of a vector field: at each sample, convert the components to Cartesian using the unit vectors of the old basis at that sample’s position; then take the components of the Cartesian vector along the unit vectors of the new basis there.

Interpolating at a point.

  1. Convert the field to Cartesian components, which vary smoothly even where the coordinate unit vectors do not (at the poles).
  2. For each axis, find the stencil of neighbouring grid points (one, two or four) and the Lagrange weights of the point within it. On a periodic axis the stencil wraps round. On a sphere, a stencil that would run past a pole continues on the far side, at .
  3. Sum the products of the weights with the samples over the stencil.
  4. Convert the result back to the requested basis at the point.

Differentiating.

  1. For each native axis, apply the five-point Lagrange derivative stencil along that axis to each Cartesian component.
  2. Combine the per-axis derivatives into Cartesian derivatives through the local frame and the scale factors, by the formula above.
  3. Assemble the gradient, divergence, curl or Laplacian from the Cartesian derivatives.

Implementation

fn cartesian_jacobians<T: FieldScalar>(domain: &Domain, cart: &[[T; 3]]) -> Vec<[[T; 3]; 3]> {
    let n = domain.len();
    let mut out = vec![[[T::zero(); 3]; 3]; n];
    for (flat, jac) in out.iter_mut().enumerate() {
        let idx = domain.unflatten(flat);
        let pos = domain.position(&idx);
        let h = pos.scale_factors(domain.system());
        if h.iter().any(|&v| v.abs() < 1e-300) {
            *jac = [[T::nan(); 3]; 3];
            continue;
        }
        let frame = pos.frame(domain.system());
        for a in 0..domain.axes().len() {
            let mut d = [T::zero(); 3];
            for (neighbour, w) in axis_stencil(domain, &idx, a) {
                let v = cart[neighbour];
                for c in 0..3 {
                    d[c] = d[c] + v[c] * w;
                }
            }
            for c in 0..3 {
                for j in 0..3 {
                    jac[c][j] = jac[c][j] + d[c] * (frame[a][j] / h[a]);
                }
            }
        }
    }
    out
}
  • Fields are shared through Arc<Domain>, so many fields on one grid cost one grid.
  • HarmonicField holds complex phasors; TimeField holds real samples on a uniform time axis, with ∂/∂t and instantaneous Poynting vectors.
  • Quantities carry units, and the physics functions check them (for example that the first argument is an electric field).

In practice

//! Field containers in action: power conservation, Maxwell's equations from vector calculus,
//! basis-independent overlap integrals, and rigid transforms of patterns.
//!
//! Run with `cargo run --release -p lib_jsl_electromagnetics --example fields_demo`.

use lib_jsl_core::constants::em::C0;
use lib_jsl_electromagnetics::algorithms::overlap_integral;
use lib_jsl_electromagnetics::antenna_models::{Antenna, HertzianDipole};
use lib_jsl_electromagnetics::conventions::{C64, Medium, TimeConvention};
use lib_jsl_electromagnetics::coordinates::{PolarizationBasis, RigidTransform};
use lib_jsl_electromagnetics::fields::physics::{peak_directivity, plane_wave, power_through_surface};
use lib_jsl_electromagnetics::fields::{Axis, Domain, Extrapolation, FieldQuantity, HarmonicField, InterpolationMethod};
use std::f64::consts::{PI, TAU};
use std::sync::Arc;

fn main() {
    let f = 3e8; // λ = 1 m
    let conv = TimeConvention::PlusJ;

    // 1. Power conservation: the Poynting flux of a Hertzian dipole's exact near field through a
    //    sphere of any radius equals the far-field radiated power.
    let dipole = HertzianDipole::new(0.05);
    println!("== Hertzian dipole (l = λ/20): power through spheres vs far-field power ==");
    println!("  far-field radiated power  {:.6e} W per A²", dipole.radiated_power(f));
    for r in [0.02, 0.1, 0.5, 2.0, 10.0] {
        let sphere = Arc::new(Domain::sphere(r, Axis::gauss_legendre_polar(12).unwrap(), Axis::periodic(0.0, TAU, 8).unwrap()).unwrap());
        let (e, h) = dipole.near_field_containers(sphere, f, conv).unwrap();
        println!("  r = {r:>5} λ: Poynting flux {:.6e} W", power_through_surface(&e, &h).unwrap());
    }

    // 2. Maxwell's equations from the containers' vector calculus: for a plane wave in a box,
    //    ∇·E = 0 and ∇×E = -jωμ₀H.
    let axis = || Axis::uniform(-0.25, 0.25, 21).unwrap();
    let cube = Arc::new(Domain::cartesian_box(axis(), axis(), axis()).unwrap());
    let (e, h) = plane_wave(cube.clone(), [1.0, 1.0, 0.0], [C64::new(0.0, 0.0), C64::new(0.0, 0.0), C64::new(1.0, 0.0)], C64::new(1.0, 0.0), f, &Medium::VACUUM, conv).unwrap();
    let div = e.divergence().unwrap();
    let curl = e.curl().unwrap().to_basis(PolarizationBasis::CARTESIAN).unwrap();
    let mu0 = lib_jsl_core::constants::em::MU_0;
    let faraday = h.scaled(-conv.time_derivative(TAU * f) * mu0);
    let max_div = div.values().iter().map(|v| v.norm()).fold(0.0, f64::max);
    let max_err = (0..cube.len()).map(|i| (0..3).map(|k| (curl.vector(i)[k] - faraday.vector(i)[k]).norm()).sum::<f64>()).fold(0.0, f64::max);
    println!("\n== plane wave in a 0.5 λ cube (21³ samples) ==");
    println!("  max |∇·E| = {max_div:.2e} V/m²   max |∇×E + jωμ₀H| = {max_err:.2e} V/m² (|∇×E| ≈ {:.1})", TAU * f / C0);

    // 3. Overlap integrals are independent of the basis and grid: Gaussian beam coupling.
    let plane = |n: usize| Arc::new(Domain::plane(Axis::gauss_legendre(-4.0, 4.0, n).unwrap(), Axis::gauss_legendre(-4.0, 4.0, n).unwrap(), 0.0).unwrap());
    let beam = |d: Arc<Domain>, w: f64, x0: f64| HarmonicField::vector_from_fn(d, FieldQuantity::ElectricField, PolarizationBasis::CARTESIAN, f, conv, |p| {
        let [x, y, _] = p.to_cartesian();
        [C64::new((-((x - x0).powi(2) + y * y) / (w * w)).exp(), 0.0), C64::new(0.0, 0.0), C64::new(0.0, 0.0)]
    }).unwrap();
    let reference = beam(plane(50), 1.0, 0.0);
    println!("\n== Gaussian beam coupling (waist 1) against offset copies on a different grid and basis ==");
    for offset in [0.0, 0.5, 1.0, 1.5] {
        let other = beam(plane(70), 1.0, offset).to_basis(PolarizationBasis::CYLINDRICAL).unwrap();
        let o = overlap_integral(&reference, &other, InterpolationMethod::Cubic).unwrap();
        println!("  offset {offset:.1}: efficiency {:.5} (closed form {:.5})", o.efficiency, (-(offset * offset)).exp());
    }

    // 4. Rigid transforms of a far-field pattern: rotation keeps the directivity, translation only
    //    adds a phase ramp.
    let sphere = Arc::new(Domain::far_field_uniform(91, 180).unwrap());
    let pattern = dipole.far_field_pattern(sphere.clone(), f, conv).unwrap();
    let tilted = pattern.transformed(&RigidTransform::rotation_about([1.0, 0.0, 0.0], 0.7), InterpolationMethod::Cubic, Extrapolation::Error).unwrap();
    let moved = pattern.transformed(&RigidTransform::translation([0.25, 0.0, 0.0]), InterpolationMethod::Cubic, Extrapolation::Error).unwrap();
    let along_x = sphere.flatten(&[45, 0]);
    println!("\n== rigid transforms of the dipole pattern ==");
    println!("  peak directivity: original {:.4}, rotated 40° {:.4}", peak_directivity(&pattern).unwrap(), peak_directivity(&tilted).unwrap());
    println!("  translated λ/4 along x: phase change towards +x {:.1}° (expected 90°)", (moved.vector(along_x)[1] / pattern.vector(along_x)[1]).arg().to_degrees());
    let _ = PI;
}
== Hertzian dipole (l = λ/20): power through spheres vs far-field power ==
  far-field radiated power  9.876437e-1 W per A²
  r =  0.02 λ: Poynting flux 9.876437e-1 W
  r =   0.1 λ: Poynting flux 9.876437e-1 W
  r =   0.5 λ: Poynting flux 9.876437e-1 W
  r =     2 λ: Poynting flux 9.876437e-1 W
  r =    10 λ: Poynting flux 9.876437e-1 W
== plane wave in a 0.5 λ cube (21³ samples) ==
  max |∇·E| = 5.78e-14 V/m²   max |∇×E + jωμ₀H| = 2.71e-4 V/m² (|∇×E| ≈ 6.3)
== Gaussian beam coupling (waist 1) against offset copies on a different grid and basis ==
  offset 0.0: efficiency 1.00000 (closed form 1.00000)
  offset 0.5: efficiency 0.77883 (closed form 0.77880)
  offset 1.0: efficiency 0.36794 (closed form 0.36788)
  offset 1.5: efficiency 0.10542 (closed form 0.10540)
== rigid transforms of the dipole pattern ==
  peak directivity: original 1.5000, rotated 40° 1.5001
  translated λ/4 along x: phase change towards +x 90.1° (expected 90°)

The exact near field of a Hertzian dipole carries the same power through a sphere of radius , deep in the reactive near field, as through one of . The Gaussian beams’ coupling is reproduced across different grids and bases to the interpolation’s accuracy.

Strengths

  • One container for every field, with the convention, quantity and basis attached; integrals and derivatives in native coordinates.
  • Exact quadrature on the far-field sphere; consistent interpolation across poles and periodic axes.

Weaknesses

  • Structured grids only; no unstructured meshes or adaptive refinement.
  • Finite differences need several samples per wavelength (20 for accuracy above).

Exercises

  1. Show that converting a phasor field between and is complex conjugation, and find how the curl equation changes.
  2. Show that Gauss-Legendre nodes in with uniform azimuths integrate every spherical harmonic of degree below exactly.
  3. Derive the divergence in spherical coordinates from the formula for above.
  4. Show that the Poynting flux of the dipole’s exact near field through a sphere is independent of the radius.
  5. Compute the overlap of two Gaussian beams of different waists, and check it against overlap_integral.
Hints and answers
  1. If , the phasor in the other convention is the complex conjugate. becomes .
  2. A degree- spherical harmonic is : the uniform azimuth rule integrates exactly for , and the product of factors in is a polynomial of degree at most ; with Gauss-Legendre nodes that is exact up to degree .
  3. In spherical coordinates, , which follows from the scale factors in the general divergence formula.
  4. The time-averaged Poynting flux through a closed surface equals the power radiated by the source (lossless medium), independent of the surface; the exact near field includes reactive terms that average to zero over a period.
  5. The overlap of two Gaussian beams of waists at a common plane is for aligned beams with matched curvature.

Further reading

  • C. A. Balanis, Advanced Engineering Electromagnetics, 2nd ed., Wiley, 2012, chapters 1–6.
  • J. D. Jackson, Classical Electrodynamics, 3rd ed., Wiley, 1999, chapters 6–7.
  • P. J. Davis and P. Rabinowitz, Methods of Numerical Integration, 2nd ed., Academic Press, 1984.
  • B. Fornberg, “Generation of finite difference formulas on arbitrarily spaced grids”, Mathematics of Computation 51 (1988) 699–706.