twpasolver.mathutils module#
Utility functions for mathematical expressions and RF equations.
This module provides a set of utility functions optimized with Numba for high performance. These functions include matrix multiplications, conversions between different parameter representations, and solutions for coupled mode equations used in RF engineering.
- twpasolver.mathutils.matmul_2x2(matrices_a: ndarray[Any, dtype[complex128]], matrices_b: ndarray[Any, dtype[complex128]]) ndarray[Any, dtype[complex128]][source]#
Fast multiplication between arrays of 2x2 matrices.
- Parameters:
matrices_a (ComplexArray) – Array of 2x2 complex matrices.
matrices_b (ComplexArray) – Array of 2x2 complex matrices.
- Returns:
Resultant array of 2x2 complex matrices after multiplication.
- Return type:
ComplexArray
- twpasolver.mathutils.matpow_2x2(matrices_a: ndarray[Any, dtype[complex128]], exponent: int) ndarray[Any, dtype[complex128]][source]#
Fast exponentiation of arrays of 2x2 matrices using recursion.
- Parameters:
matrices_a (ComplexArray) – Array of 2x2 complex matrices.
exponent (int) – Exponent to which matrices are to be raised.
- Returns:
Resultant array of 2x2 complex matrices after exponentiation.
- Return type:
ComplexArray
- twpasolver.mathutils.a2s(abcd: ndarray[Any, dtype[complex128]], Z0: complex | float) ndarray[Any, dtype[complex128]][source]#
Convert arrays of ABCD matrices to arrays of S-parameters.
- twpasolver.mathutils.s2a(spar: ndarray[Any, dtype[complex128]], Z0: complex | float) ndarray[Any, dtype[complex128]][source]#
Convert arrays of S-parameters to arrays of ABCD matrices.
- twpasolver.mathutils.a2z(abcd: ndarray[Any, dtype[complex128]]) ndarray[Any, dtype[complex128]][source]#
Convert arrays of ABCD matrices to arrays of Z-parameters.
- Parameters:
abcd (ComplexArray) – Array of 2x2 ABCD matrices.
- Returns:
Array of 2x2 Z-parameter matrices.
- Return type:
ComplexArray
- twpasolver.mathutils.z2a(z_mat: ndarray[Any, dtype[complex128]]) ndarray[Any, dtype[complex128]][source]#
Convert arrays of Z-parameters to arrays of ABCD matrices.
- Parameters:
z_mat (ComplexArray) – Array of 2x2 Z-parameter matrices.
- Returns:
Array of 2x2 ABCD matrices.
- Return type:
ComplexArray
- twpasolver.mathutils.to_dB(values: ndarray[Any, dtype[float64]] | ndarray[Any, dtype[complex128]]) ndarray[Any, dtype[float64]][source]#
Convert arrays of values to dB.
- Parameters:
values (FloatArray | ComplexArray) – Array of values to be converted to dB.
- Returns:
Array of values in dB.
- Return type:
FloatArray
- twpasolver.mathutils.dBm_to_I(power: float, Z0: float = 50) float[source]#
Convert power from dBm to current in amperes.
- twpasolver.mathutils.I_to_dBm(curr: float, Z0: float = 50) float[source]#
Convert current in amperes to power in dBm.
- twpasolver.mathutils.compute_phase_matching(freqs: ndarray[Any, dtype[float64]], pump_freqs: ndarray[Any, dtype[float64]], k_signal_array: ndarray[Any, dtype[float64]], k_pump_array: ndarray[Any, dtype[float64]], chi: float, gamma_pump_array: ndarray[Any, dtype[complex128]]) Tuple[ndarray[Any, dtype[float64]], ndarray[Any, dtype[float64]], ndarray[Any, dtype[float64]]][source]#
Compute phase matching profiles and triplets for given frequencies.
- Parameters:
freqs (FloatArray) – Array of signal frequencies.
pump_freqs (FloatArray) – Array of pump frequencies.
k_signal_array (FloatArray) – Array of signal wave numbers.
k_pump_array (FloatArray) – Array of pump wave numbers.
chi (float) – Nonlinear coefficient.
gamma_pump_array (ComplexArray) – Array of pump reflection coefficients.
- Returns:
Phase matching profile, frequency triplets, and wave number triplets.
- Return type:
Tuple[FloatArray, FloatArray, FloatArray]