Sources, Quadrature & Performance
Ion–Neutral Source Rates & Float32 Usage
Exosphere.jl provides @inline, zero-allocation source-rate kernels for hybrid-PIC and kinetic/fluid plasma solvers:
photoionization_rate(nu_photo, neutral_n, atten = 1.0)computes .charge_exchange_rate(sigma_cx, ion_n, neutral_n, v_rel)computes .
Single-component profiles (ExponentialProfile, PowerLawProfile, ChamberlainProfile) also accept FT = Float32 for low-memory and GPU-kernel evaluations:
using Exosphere
exp32 = ExponentialProfile(10.0f0, 1.0f0, 0.5f0; FT = Float32)
n32 = neutral_density(exp32, 1.5f0)
q32 = photoionization_rate(1.0f-6, n32, 0.8f0)
cx32 = charge_exchange_rate(2.0f-19, 5.0f0, n32, 4.0f5)
println("n32 = ", n32, " (", typeof(n32), ")")
println("q32 = ", q32, " (", typeof(q32), ")")
println("cx32 = ", cx32, " (", typeof(cx32), ")")n32 = 3.6787944 (Float32)
q32 = 2.9430355e-6 (Float32)
cx32 = 1.4715178e-12 (Float32)Adaptive Octree Dual-Cell Box Quadrature
When computing cell-integrated neutral column densities sumN and EUV-attenuated production weights sumNA on Cartesian or AMR grids near a planetary obstacle, integrate_exosphere_box! recursively refines each axis-aligned box (c, h) around exo.center up to depth 8:
Interior cull: Boxes fully inside the inner sphere (
) immediately return0.0.Adaptive splitting: Boxes are subdivided into 8 octants (or 4 quadrants when one axis has
for 2D simulations) whenever in the exterior, or if the box straddles .Sub-cell boundary volume fraction: Straddling leaf cells estimate the exterior fraction using a SIMD-vectorized
(3D) or (2D) midpoint lattice against. Finite-cell
correction: Non-straddling leaf cells multiply each component's density by with , preserving exact exponential cell averages across coarse cells without extra quadrature points.
using Exosphere
using StaticArrays
o_comp = NeutralComponentCode(:exponential, 100.0, 0.2, 0.0, 0.01, "O")
h_comp = NeutralComponentCode(:powerlaw, 10.0, 0.0, 2.0, 0.01, "H")
od = OpticalDepth(; cross_sections = [0.05, 0.01], solar_dir = (1.0, 0.0, 0.0), chapman = true)
exo = build_exosphere_model(; planet_radius = 1.0, components = [o_comp, h_comp], optical_depth = od)
sumN = zeros(n_components(exo))
sumNA = zeros(n_components(exo))
# Exterior 3D box
vol_3d = integrate_exosphere_box!(sumN, sumNA, exo, SVector(1.5, 0.0, 0.0), SVector(0.2, 0.2, 0.2), 0, 1.0)
println("3D exterior vol = ", round(vol_3d; sigdigits = 4),
", sumN = ", round.(sumN; sigdigits = 4), ", sumNA = ", round.(sumNA; sigdigits = 4))
# Boundary-straddling 2D cell (h[3] = 0.0)
fill!(sumN, 0.0)
fill!(sumNA, 0.0)
area_2d = integrate_exosphere_box!(sumN, sumNA, exo, SVector(1.05, 0.1, 0.0), SVector(0.4, 0.4, 0.0), 0, 1.0)
println("2D straddle area = ", round(area_2d; sigdigits = 4),
", sumN = ", round.(sumN; sigdigits = 4), ", sumNA = ", round.(sumNA; sigdigits = 4))3D exterior vol = 0.008, sumN = [0.06844, 0.03566], sumNA = [0.06356, 0.03312]
2D straddle area = 0.1044, sumN = [5.96, 0.8324], sumNA = [3.525, 0.5079]Planetary Exosphere EUV Example
The standalone script examples/planetary_exosphere_euv.jl visualizes a 3-component Mars-like exosphere (O exponential, H power-law, He Chamberlain) with Chapman EUV attenuation (solar_dir = (+1, 0, 0)):

To run the example locally and save the figure:
julia --project=/path/to/env-with-CairoMakie examples/planetary_exosphere_euv.jlPerformance Benchmarks
The benchmark/benchmarks.jl suite tracks profile evaluations, shadow/optical-depth/Chapman attenuation, batched photoionization, and 2D/3D adaptive box quadrature using BenchmarkTools.jl and AirspeedVelocity.jl:
cd Exosphere.jl && benchpkg Exosphere --rev=main,dirty