Utility functions
NonlinearCrystals.all_bidirectionalcrystals — Methodall_bidirectionalcrystals()Return all available subtypes of BidirectionalCrystal defined in the NonlinearCrystals module.
NonlinearCrystals.all_nonlinearcrystals — Methodall_nonlinearcrystals()Return all available subtypes of NonlinearCrystal defined in the NonlinearCrystals module.
NonlinearCrystals.all_unidirectionalcrystals — Methodall_unidirectionalcrystals()Return all available subtypes of UnidirectionalCrystal defined in the NonlinearCrystals module.
NonlinearCrystals.angles_to_vector — Methodangles_to_vector(θ::Angle, ϕ::Angle) -> SVector{3,Float64}Returns a unit direction vector corresponding to spherical angles (θ, ϕ).
NonlinearCrystals.auto_fmt — Methodauto_fmt(x; digits=3, sci_thresh=1e4, inf_thresh=1e10) -> StringFormats 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
NonlinearCrystals.axes_to_θ_ϕ — Methodaxes_to_θ_ϕ(axes::Union{Symbol, Vector{Symbol}}) -> Vector{Tuple{Angle, Angle}}Maps symbolic crystal axes (:X, :Y, :Z) to corresponding spherical direction angles (θ, ϕ).
NonlinearCrystals.bool_permutations — Methodbool_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).
NonlinearCrystals.eigen_2d — Methodeigen_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.
NonlinearCrystals.find_neighbors_within_distance — Methodfind_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.
NonlinearCrystals.find_principal_planes — Methodfind_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.
NonlinearCrystals.shift_lambda_with_freq — Methodshift_lambda_with_freq(lambda::Length, Δω::Frequency) -> LengthApplies a frequency shift Δω to the wavelength λ, using the relation: ω = 2π·c / λ, and then λ' = 2π·c / (ω + Δω) Returns the shifted wavelength.
NonlinearCrystals.sign_switch_fractions — Methodsign_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
NonlinearCrystals.split_on_nan — Methodsplit_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.
NonlinearCrystals.subtypes_in_module — Methodsubtypes_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.
NonlinearCrystals.vector_to_angles — Methodvector_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π)