Utilities

Helper components for field manipulation and optimization.

Overview

The Utilities module provides:

  • Pad/crop operators for memory-efficient propagation
  • Tilt anchors for off-axis beam tracking
  • Basis projection for reduced-parameter optimization

Examples

Pad and Crop

using FluxOptics

u = ScalarField(ones(ComplexF64, 128, 128), (2.0, 2.0), 1.064)

# Basic padding
u_pad = pad(u.electric, (256, 256))
size(u_pad)
(256, 256)
# Centered padding
offset = ((256-128)÷2, (256-128)÷2)
u_centered = pad(u.electric, (256, 256); offset=offset)

# Cropping back
u_crop = crop(u_centered, (128, 128); offset=offset)
size(u_crop)
(128, 128)

PadCropOperator

# Efficient pad/crop in systems
u = ScalarField(ones(ComplexF64, 128, 128), (2.0, 2.0), 1.064)
u_tmp = zeros(ComplexF64, 256, 256)

pad_op = PadCropOperator(u, u_tmp; store_ref=true)
crop_op = adjoint(pad_op)

# Create source
source = ScalarSource(u)

# Avoid aliasing during propagation
prop = ASProp(set_field_data(u, u_tmp), 1000.0)
system = source |> pad_op |> prop |> crop_op

# Execute system
result = system()
size(result.out)
(128, 128)

Basis Projection

using FluxOptics

u = ScalarField(ones(ComplexF64, 128, 128), (2.0, 2.0), 1.064)
source = ScalarSource(u)

# Polynomial basis
n_basis = 10
basis = make_spatial_basis((x, y, n) -> (x^2 + y^2)^n,
                          (128, 128), (2.0, 2.0), 0:n_basis-1)

# Wrap trainable phase
phase = Phase(u, (x, y) -> 0.0; trainable=true)
wrapper = BasisProjectionWrapper(phase, basis, zeros(n_basis))

propagator = ASProp(u, 500.0)

# Optimize n_basis coefficients instead of 128×128 pixels
system = source |> wrapper |> propagator
result = system()

# Show we're optimizing only n_basis parameters
params = trainable(wrapper)
length(params.proj_coeffs)
10

Key Types

Key Functions

See Also

  • Core for component interface
  • System for component composition

Index