Utility functions

NonlinearCrystals.auto_fmtMethod
auto_fmt(x; digits=3, sci_thresh=1e4, inf_thresh=1e10) -> String

Formats a numeric value x into a compact string:

  • Uses scientific notation for large/small values
  • Displays "Inf" or "NaN" for extreme cases
  • Controls decimal digits via digits
source
NonlinearCrystals.axes_to_θ_ϕMethod
axes_to_θ_ϕ(axes::Union{Symbol, Vector{Symbol}}) -> Vector{Tuple{Angle, Angle}}

Maps symbolic crystal axes (:X, :Y, :Z) to corresponding spherical direction angles (θ, ϕ).

source
NonlinearCrystals.bool_permutationsMethod
bool_permutations(val1, val2, n) -> Vector{NTuple{n, Any}}

Returns all 2^n permutations of val1 and val2 in an n-element tuple. Useful for enumerating polarization combinations (e.g., :hi / :lo).

source
NonlinearCrystals.eigen_2dMethod
eigen_2d(A::AbstractMatrix) -> (eigenvalues::Vector, eigenvectors::SMatrix{2,2})

Returns sorted real eigenvalues and their corresponding orthonormal eigenvectors for a 2×2 matrix A. In comparison with the eigen implementation in Julia's base, this minimal implementation is compatible with ForwardDiff.jl.

source
NonlinearCrystals.find_neighbors_within_distanceMethod
find_neighbors_within_distance(all_x, all_y, d) -> (indices_within_d, dists_within_d)

Given two vectors all_x and all_y representing 2D point coordinates, and a scalar distance d (with units), this function identifies all neighboring points within distance d of each point using a k-d tree.

source
NonlinearCrystals.find_principal_planesMethod
find_principal_planes(θ::Angle, ϕ::Angle; angle_tol=0.1u"°") -> (Symbol, Symbol)

Returns up to two principal planes (:XY, :XZ, :YZ) to which the vector (θ, ϕ) is approximately aligned. Principal planes are defined as those orthogonal to the X, Y, or Z axes, within the given angular tolerance angle_tol.

source
NonlinearCrystals.shift_lambda_with_freqMethod
shift_lambda_with_freq(lambda::Length, Δω::Frequency) -> Length

Applies a frequency shift Δω to the wavelength λ, using the relation: ω = 2π·c / λ, and then λ' = 2π·c / (ω + Δω) Returns the shifted wavelength.

source
NonlinearCrystals.sign_switch_fractionsMethod
sign_switch_fractions(vec::Vector) -> (switch_indices, fractions, segment_signs)

Given a vector of values, detects all zero crossings (i.e., sign changes), and returns:

  • indices of sign flips
  • linear interpolation fractions where zero-crossings occur
  • sign of each segment between crossings
source
NonlinearCrystals.split_on_nanMethod
split_on_nan(x::Vector, y::Vector) -> (Vector{Vector}, Vector{Vector})

Splits two paired vectors into subsegments at NaN positions. Each returned segment pair contains only valid (non-NaN) values.

source
NonlinearCrystals.subtypes_in_moduleMethod
subtypes_in_module(mod::Module, T; recurse=false) -> Vector{T}

Returns a list of all objects in module mod that are subtypes of type T.

If recurse=true, submodules will also be searched recursively. Useful for dynamically collecting types defined under a module namespace.

source
NonlinearCrystals.vector_to_anglesMethod
vector_to_angles(v::AbstractVector{<:Number}) -> (θ::Angle, ϕ::Angle)

Converts a 3D unit vector v to spherical coordinates:

  • θ (polar angle): 0 to π
  • ϕ (azimuthal angle): normalized to [0, 2π)
source