Fields
The ScalarField type and field operations.
Overview
The Fields module provides:
- ScalarField type: Central data structure for optical fields
- Multi-wavelength support: Handle multiple wavelengths simultaneously
- Tilt tracking: Manage off-axis propagation
- Field operations: Power, intensity, phase, normalization
Examples
Creating Fields
using FluxOptics
# Create field from mode
gaussian = Gaussian(20.0)
xv, yv = spatial_vectors(128, 128, 2.0, 2.0)
field_data = gaussian(xv, yv)
u = ScalarField(field_data, (2.0, 2.0), 1.064)
size(u) # Grid dimensions(128, 128)Field Operations
# Power calculation and normalization
P_initial = power(u)[] # Extract scalar from 0-dimensional array
normalize_power!(u, 2.5) # Normalize to 2.5 W
P_normalized = power(u)[]
(P_initial, P_normalized) # Before: ~1.0, After: 2.5(1.0000000000000002, 2.5)# Intensity and phase distributions
I = intensity(u) # 2D array: total intensity
φ = phase(u) # Same size as u: phase at each point
(size(I), size(φ))((128, 128), (128, 128))Field Manipulation
# Copy and fill operations
u_copy = copy(u) # Independent copy
u_tmp = similar(u) # Allocate uninitialized
fill!(u_tmp, 1.0 + 0.0im) # Fill with constant value
# Update field data
new_data = 0.5 .* u.electric
u_new = set_field_data(u, new_data)
power(u_new)[] # Power scaled by 0.5² = 0.250.625Multi-Wavelength Fields
# Multiple wavelengths simultaneously
λs = [0.8, 1.064, 1.55]
data_multi = zeros(ComplexF64, 128, 128, 3)
for (i, λ) in enumerate(λs)
g = Gaussian(20.0)
data_multi[:, :, i] .= g(xv, yv)
end
u_multi = ScalarField(data_multi, (2.0, 2.0), λs)
# Power per wavelength
power(u_multi) # Returns 1×1×3 array1×1×3 Array{Float64, 3}:
[:, :, 1] =
1.0000000000000002
[:, :, 2] =
1.0000000000000002
[:, :, 3] =
1.0000000000000002Field Comparison
# Compare with another mode
hg10 = HermiteGaussian(20.0, 1, 0)
u2 = ScalarField(hg10(xv, yv), (2.0, 2.0), 1.064)
normalize_power!(u2)
# Coupling efficiency (mode overlap)
η = coupling_efficiency(u, u2)
η[] # Overlap between Gaussian and HG102.2757570631919756e-36Field with Tilts
# Off-axis propagation
u_tilted = ScalarField(field_data, (2.0, 2.0), 1.064; tilts=(0.01, 0.005))
is_on_axis(u_tilted) # falsefalseKey Types
ScalarField: Optical field with grid information
Key Functions
Field Construction and Data
ScalarField: Create optical fieldset_field_data: Update field datasimilar: Allocate similar fieldcopy: Copy fieldfill!: Fill field with valuescopyto!: Copy between fieldscollect: Convert to CPU array
Field Properties
Tilts Management
set_field_tilts: Update field tiltsoffset_tilts!: Add tilt offset with phase correctionis_on_axis: Check if field is on-axis
Power and Intensity
power: Calculate field powernormalize_power!: Normalize to target powerintensity: Calculate total intensityphase: Extract phase distribution
Field Comparison
coupling_efficiency: Coupling efficiency between fieldsdot: Field overlap integral
Vectorization
vec: Vectorize into independent ScalarFields
Broadcasting and Indexing
broadcasted: Element-wise operationsgetindex: Access field elementsconj: Complex conjugate