I/O API

Requires JLD2.jl to be loaded.

using PhoXonic
using JLD2  # Required for I/O functions

Functions

PhoXonic.save_bandsFunction
save_bands(filename, bands::BandStructure; compress=false, metadata=Dict())

Save a band structure to a JLD2 file.

Arguments

  • filename: Path to the output file (should end with .jld2)
  • bands: BandStructure object from compute_bands()

Keyword Arguments

  • compress: Enable compression (default: false)
  • metadata: Additional metadata dictionary

Example

using PhoXonic

solver = Solver(TEWave(), geo, (64, 64))
bands = compute_bands(solver, kpath)
save_bands("te_bands.jld2", bands)

Saved Data

The file contains:

  • frequencies: Matrix of frequencies (nkpoints × nbands)
  • kpoints: Vector of k-point coordinates
  • distances: Cumulative distances along k-path
  • labels: High-symmetry point labels and indices
  • metadata: Additional information (version, date, etc.)
source
PhoXonic.load_bandsFunction
load_bands(filename) -> BandStructure

Load a band structure from a JLD2 file.

Arguments

  • filename: Path to the input file

Returns

A BandStructure object.

Example

using PhoXonic

bands = load_bands("te_bands.jld2")
plot_bands(bands)
source
PhoXonic.save_modesFunction
save_modes(filename, modes; k=nothing, frequencies=nothing, compress=false, metadata=Dict())

Save eigenmodes to a JLD2 file.

Arguments

  • filename: Output file path
  • modes: Eigenmode matrix (N × nbands) from solve()

Keyword Arguments

  • k: Wave vector (optional, for reference)
  • frequencies: Corresponding frequencies (optional)
  • compress: Enable compression (default: false, requires CodecZlib.jl)
  • metadata: Additional metadata dictionary

Example

using PhoXonic

ω, modes = solve(solver, k; bands=1:5)
save_modes("modes_at_k.jld2", modes; k=k, frequencies=ω)
source
PhoXonic.load_modesFunction
load_modes(filename) -> NamedTuple

Load eigenmodes from a JLD2 file.

Returns

A NamedTuple with:

  • modes: The eigenmode matrix
  • k: Wave vector (if saved)
  • frequencies: Frequencies (if saved)
  • metadata: Additional metadata
source
PhoXonic.save_epsilonFunction
save_epsilon(filename, solver::Solver; compress=false, metadata=Dict())

Save discretized material arrays to a JLD2 file.

For photonic crystals, saves:

  • epsilon: Dielectric constant
  • epsilon_inv: Inverse dielectric constant
  • mu: Permeability

For phononic crystals, saves:

  • C11, C12, C44: Elastic constants (Voigt notation)
  • rho: Density

Example

using PhoXonic

solver = Solver(TEWave(), geo, (64, 64))
save_epsilon("epsilon.jld2", solver)

# For phononic
solver_ph = Solver(FullElastic(), geo_phononic, (16, 16, 16))
save_epsilon("elastic_constants.jld2", solver_ph)
source
PhoXonic.load_epsilonFunction
load_epsilon(filename) -> NamedTuple

Load discretized material arrays from a JLD2 file.

Returns

A NamedTuple with the material arrays and metadata.

For photonic data: , :ε_inv, , :μ_inv For phononic data: :C11, :C12, :C44, Plus: :resolution, :wave_type, :metadata

source